-
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
Signed-off-by: Nkeiruka <[email protected]>
- Loading branch information
Showing
7 changed files
with
257 additions
and
23 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,23 @@ | ||
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 { LxdClusterMember } from "types/cluster"; | ||
|
||
export const useSettings = (): UseQueryResult<LxdSettings> => { | ||
return useQuery({ | ||
queryKey: [queryKeys.settings], | ||
queryFn: fetchSettings, | ||
queryFn: () => fetchSettings(), | ||
}); | ||
}; | ||
|
||
export const useClusteredSettings = ( | ||
memberNames: LxdClusterMember[], | ||
): UseQueryResult<LXDSettingOnClusterMember[]> => { | ||
return useQuery({ | ||
queryKey: [queryKeys.settings, queryKeys.cluster], | ||
queryFn: () => fetchSettingsFromClusterMembers(memberNames), | ||
enabled: memberNames.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,85 @@ | ||
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; | ||
readonly?: boolean; | ||
} | ||
|
||
const ClusteredSettingFormInput: FC<Props> = ({ | ||
initialValue, | ||
configField, | ||
onSubmit, | ||
onCancel, | ||
readonly = false, | ||
}) => { | ||
const [value, setValue] = useState<ClusterSpecificValues>(initialValue); | ||
|
||
const { data: clusterMembers = [] } = useClusterMembers(); | ||
const memberNames = clusterMembers.map((member) => member.server_name); | ||
|
||
const canBeReset = | ||
JSON.stringify(configField.default) !== JSON.stringify(value); | ||
|
||
const resetToDefault = () => { | ||
setValue({}); | ||
}; | ||
|
||
return ( | ||
<Form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
onSubmit(value); | ||
}} | ||
> | ||
<ClusterSpecificInput | ||
aria-label={configField.key} | ||
classname="input-wrapper" | ||
id={getConfigId(configField.key)} | ||
values={value} | ||
isReadOnly={readonly} | ||
onChange={(value) => setValue(value)} | ||
memberNames={memberNames} | ||
disabled={readonly} | ||
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" | ||
onClick={resetToDefault} | ||
hasIcon | ||
> | ||
<Icon name="restart" className="flip-horizontally" /> | ||
<span>Reset to default</span> | ||
</Button> | ||
)} | ||
</> | ||
)} | ||
</Form> | ||
); | ||
}; | ||
|
||
export default ClusteredSettingFormInput; |
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
Oops, something went wrong.