-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [WD-19015] CMS Server Config for maas.machine (#1097)
## Done - Introduced MaasMachineSettingFormInput.tsx Fixes [list issues/bugs if needed] - Maas Machine Setting. - Storage.*volume settings. - .*_address settings. ## QA 1. Run the LXD-UI: - On the demo server via the link posted by @webteam-app below. This is only available for PRs created by collaborators of the repo. Ask @mas-who or @edlerd for access. - With a local copy of this branch, [build and run as described in the docs](../CONTRIBUTING.md#setting-up-for-development). 2. Perform the following QA steps: - [PENDING] ## Screenshots  
- Loading branch information
Showing
9 changed files
with
295 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { queryKeys } from "util/queryKeys"; | ||
import { fetchSettings } from "api/server"; | ||
import type { LxdSettings } from "types/server"; | ||
import { fetchSettingsFromClusterMembers, fetchSettings } from "api/server"; | ||
import type { LXDSettingOnClusterMember, LxdSettings } from "types/server"; | ||
import { UseQueryResult } from "@tanstack/react-query"; | ||
import { useClusterMembers } from "./useClusterMembers"; | ||
|
||
export const useSettings = (): UseQueryResult<LxdSettings> => { | ||
return useQuery({ | ||
queryKey: [queryKeys.settings], | ||
queryFn: fetchSettings, | ||
queryFn: () => fetchSettings(), | ||
}); | ||
}; | ||
|
||
export const useClusteredSettings = (): UseQueryResult< | ||
LXDSettingOnClusterMember[] | ||
> => { | ||
const { data: clusterMembers = [] } = useClusterMembers(); | ||
|
||
return useQuery({ | ||
queryKey: [queryKeys.settings, queryKeys.cluster], | ||
queryFn: () => fetchSettingsFromClusterMembers(clusterMembers), | ||
enabled: clusterMembers.length > 0, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { FC, useState } from "react"; | ||
import { Button, Form, Icon } from "@canonical/react-components"; | ||
import type { ConfigField } from "types/config"; | ||
import { getConfigId } from "./SettingForm"; | ||
import ConfigFieldDescription from "pages/settings/ConfigFieldDescription"; | ||
import ClusterSpecificInput from "components/forms/ClusterSpecificInput"; | ||
import { useClusterMembers } from "context/useClusterMembers"; | ||
import { ClusterSpecificValues } from "components/ClusterSpecificSelect"; | ||
|
||
interface Props { | ||
initialValue: ClusterSpecificValues; | ||
configField: ConfigField; | ||
onSubmit: (newValue: ClusterSpecificValues) => void; | ||
onCancel: () => void; | ||
disableReason?: string; | ||
readonly?: boolean; | ||
toggleReadOnly?: () => void; | ||
} | ||
|
||
const ClusteredSettingFormInput: FC<Props> = ({ | ||
disableReason, | ||
initialValue, | ||
configField, | ||
onSubmit, | ||
onCancel, | ||
readonly = false, | ||
toggleReadOnly, | ||
}) => { | ||
const [value, setValue] = useState<ClusterSpecificValues>(initialValue); | ||
|
||
const { data: clusterMembers = [] } = useClusterMembers(); | ||
const memberNames = clusterMembers.map((member) => member.server_name); | ||
|
||
const canBeReset = Object.values(value).some( | ||
(v) => v !== configField.default, | ||
); | ||
|
||
const resetToDefault = () => { | ||
const defaultValues: { [key: string]: string } = {}; | ||
memberNames.forEach((name) => { | ||
defaultValues[name] = configField.default; | ||
}); | ||
setValue(defaultValues); | ||
}; | ||
|
||
return ( | ||
<Form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
onSubmit(value); | ||
}} | ||
> | ||
<ClusterSpecificInput | ||
aria-label={configField.key} | ||
disableReason={disableReason} | ||
id={getConfigId(configField.key)} | ||
values={value} | ||
isReadOnly={readonly} | ||
onChange={(value) => setValue(value)} | ||
memberNames={memberNames} | ||
toggleReadOnly={toggleReadOnly} | ||
helpText={ | ||
<ConfigFieldDescription | ||
description={configField.longdesc} | ||
className="p-form-help-text" | ||
/> | ||
} | ||
/> | ||
{!readonly && ( | ||
<> | ||
<Button appearance="base" onClick={onCancel}> | ||
Cancel | ||
</Button> | ||
<Button appearance="positive" type="submit"> | ||
Save | ||
</Button> | ||
{canBeReset && ( | ||
<Button | ||
className="reset-button" | ||
appearance="base" | ||
type="button" | ||
onClick={resetToDefault} | ||
hasIcon | ||
> | ||
<Icon name="restart" className="flip-horizontally" /> | ||
<span>Reset to default</span> | ||
</Button> | ||
)} | ||
</> | ||
)} | ||
</Form> | ||
); | ||
}; | ||
|
||
export default ClusteredSettingFormInput; |
Oops, something went wrong.