-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fcb2b4b OS-556. Introduce CapabilityField component and enhance CapabilityCard 45f1df4 OSN-556. Refactor CapabilityCard component 0c47662 OSN-569 Refactor URL handling in InitializeContainer to streamline query parameter management
- Loading branch information
Showing
8 changed files
with
193 additions
and
230 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
74 changes: 74 additions & 0 deletions
74
ngui/ui/src/components/CapabilityField/CapabilityField.tsx
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,74 @@ | ||
import { Box } from "@mui/material"; | ||
import { FormControl, FormHelperText } from "@mui/material"; | ||
import { Controller, useFormContext } from "react-hook-form"; | ||
import { useIntl } from "react-intl"; | ||
import CapabilityCard from "components/CapabilityCard"; | ||
import { SPACING_2 } from "utils/layouts"; | ||
|
||
type FieldNames = { | ||
capability: string; | ||
capabilityMl: string; | ||
capabilityFin: string; | ||
}; | ||
|
||
type CapabilityFieldProps = { | ||
fieldNames: FieldNames; | ||
margin?: "none" | "normal" | "dense"; | ||
fullWidth?: boolean; | ||
}; | ||
|
||
const CapabilityField = ({ fieldNames, margin, fullWidth }: CapabilityFieldProps) => { | ||
const intl = useIntl(); | ||
const { | ||
control, | ||
formState: { errors } | ||
} = useFormContext(); | ||
|
||
return ( | ||
<FormControl margin={margin} fullWidth={fullWidth}> | ||
<Controller | ||
control={control} | ||
name={fieldNames.capability} | ||
rules={{ | ||
validate: { | ||
atLeastOne: (value) => { | ||
if (value[fieldNames.capabilityMl] || value[fieldNames.capabilityFin]) { | ||
return true; | ||
} | ||
return intl.formatMessage({ id: "applyOptscaleCapabilityError" }); | ||
} | ||
} | ||
}} | ||
render={({ field: { value, onChange } }) => ( | ||
<Box display="flex" gap={SPACING_2} flexWrap="wrap"> | ||
<CapabilityCard | ||
capability="finops" | ||
checked={value[fieldNames.capabilityFin]} | ||
onChange={(checked) => { | ||
onChange({ ...value, [fieldNames.capabilityFin]: checked }); | ||
}} | ||
sx={{ | ||
flexGrow: 1, | ||
flexBasis: "200px" | ||
}} | ||
/> | ||
<CapabilityCard | ||
capability="mlops" | ||
checked={value[fieldNames.capabilityMl]} | ||
onChange={(checked) => { | ||
onChange({ ...value, [fieldNames.capabilityMl]: checked }); | ||
}} | ||
sx={{ | ||
flexGrow: 1, | ||
flexBasis: "200px" | ||
}} | ||
/> | ||
</Box> | ||
)} | ||
/> | ||
{!!errors[fieldNames.capability] && <FormHelperText error>{errors?.[fieldNames.capability]?.message}</FormHelperText>} | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export default CapabilityField; |
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,3 @@ | ||
import CapabilityField from "./CapabilityField"; | ||
|
||
export default CapabilityField; |
12 changes: 11 additions & 1 deletion
12
ngui/ui/src/components/ContentBackdropLoader/ContentBackdropLoader.tsx
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
70 changes: 11 additions & 59 deletions
70
ngui/ui/src/components/forms/CapabilityForm/FormElements/CapabilityField.tsx
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,63 +1,15 @@ | ||
import { Box } from "@mui/material"; | ||
import { FormControl, FormHelperText } from "@mui/material"; | ||
import { Controller, useFormContext } from "react-hook-form"; | ||
import { useIntl } from "react-intl"; | ||
import CapabilityCard from "components/CapabilityCard"; | ||
import CapabilityFieldComponent from "components/CapabilityField"; | ||
import { FIELD_NAMES } from "../constants"; | ||
import { FormValues } from "../types"; | ||
|
||
const CapabilityField = () => { | ||
const intl = useIntl(); | ||
const { | ||
control, | ||
formState: { errors } | ||
} = useFormContext<FormValues>(); | ||
|
||
return ( | ||
<FormControl margin="none"> | ||
<Controller | ||
control={control} | ||
name={FIELD_NAMES.CAPABILITY} | ||
rules={{ | ||
validate: { | ||
atLeastOne: (value) => { | ||
if (value[FIELD_NAMES.CAPABILITY_ML] || value[FIELD_NAMES.CAPABILITY_FIN]) { | ||
return true; | ||
} | ||
return intl.formatMessage({ id: "applyOptscaleCapabilityError" }); | ||
} | ||
} | ||
}} | ||
render={({ field: { value, onChange } }) => ( | ||
<Box | ||
display="grid" | ||
gridTemplateColumns={{ | ||
xs: "1fr", | ||
sm: "repeat(2, 1fr)" | ||
}} | ||
columnGap={4} | ||
rowGap={2} | ||
> | ||
<CapabilityCard | ||
capability="finops" | ||
checked={value[FIELD_NAMES.CAPABILITY_FIN]} | ||
onChange={(_, checked) => { | ||
onChange({ ...value, [FIELD_NAMES.CAPABILITY_FIN]: checked }); | ||
}} | ||
/> | ||
<CapabilityCard | ||
capability="mlops" | ||
checked={value[FIELD_NAMES.CAPABILITY_ML]} | ||
onChange={(_, checked) => { | ||
onChange({ ...value, [FIELD_NAMES.CAPABILITY_ML]: checked }); | ||
}} | ||
/> | ||
</Box> | ||
)} | ||
/> | ||
{!!errors[FIELD_NAMES.CAPABILITY] && <FormHelperText error>{errors[FIELD_NAMES.CAPABILITY]?.message}</FormHelperText>} | ||
</FormControl> | ||
); | ||
}; | ||
const CapabilityField = () => ( | ||
<CapabilityFieldComponent | ||
fieldNames={{ | ||
capability: FIELD_NAMES.CAPABILITY, | ||
capabilityMl: FIELD_NAMES.CAPABILITY_ML, | ||
capabilityFin: FIELD_NAMES.CAPABILITY_FIN | ||
}} | ||
margin="none" | ||
/> | ||
); | ||
|
||
export default CapabilityField; |
69 changes: 11 additions & 58 deletions
69
ngui/ui/src/components/forms/CreateOrganizationForm/FormElements/CapabilityField.tsx
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,62 +1,15 @@ | ||
import { Box, FormHelperText, FormControl } from "@mui/material"; | ||
import { Controller, useFormContext } from "react-hook-form"; | ||
import { useIntl } from "react-intl"; | ||
import CapabilityCard from "components/CapabilityCard"; | ||
import CapabilityFieldComponent from "components/CapabilityField"; | ||
import { FIELD_NAMES } from "../constants"; | ||
import { FormValues } from "../types"; | ||
|
||
const CapabilityField = () => { | ||
const intl = useIntl(); | ||
const { | ||
control, | ||
formState: { errors } | ||
} = useFormContext<FormValues>(); | ||
|
||
return ( | ||
<FormControl fullWidth> | ||
<Controller | ||
control={control} | ||
name={FIELD_NAMES.CAPABILITY} | ||
rules={{ | ||
validate: { | ||
atLeastOne: (value) => { | ||
if (value[FIELD_NAMES.CAPABILITY_ML] || value[FIELD_NAMES.CAPABILITY_FIN]) { | ||
return true; | ||
} | ||
return intl.formatMessage({ id: "applyOptscaleCapabilityError" }); | ||
} | ||
} | ||
}} | ||
render={({ field: { value, onChange } }) => ( | ||
<Box | ||
display="grid" | ||
gridTemplateColumns={{ | ||
xs: "1fr", | ||
lg: "repeat(2, 1fr)" | ||
}} | ||
columnGap={4} | ||
rowGap={2} | ||
> | ||
<CapabilityCard | ||
capability="finops" | ||
checked={value[FIELD_NAMES.CAPABILITY_FIN]} | ||
onChange={(_, checked) => { | ||
onChange({ ...value, [FIELD_NAMES.CAPABILITY_FIN]: checked }); | ||
}} | ||
/> | ||
<CapabilityCard | ||
capability="mlops" | ||
checked={value[FIELD_NAMES.CAPABILITY_ML]} | ||
onChange={(_, checked) => { | ||
onChange({ ...value, [FIELD_NAMES.CAPABILITY_ML]: checked }); | ||
}} | ||
/> | ||
</Box> | ||
)} | ||
/> | ||
{!!errors[FIELD_NAMES.CAPABILITY] && <FormHelperText error>{errors[FIELD_NAMES.CAPABILITY]?.message}</FormHelperText>} | ||
</FormControl> | ||
); | ||
}; | ||
const CapabilityField = () => ( | ||
<CapabilityFieldComponent | ||
fieldNames={{ | ||
capability: FIELD_NAMES.CAPABILITY, | ||
capabilityMl: FIELD_NAMES.CAPABILITY_ML, | ||
capabilityFin: FIELD_NAMES.CAPABILITY_FIN | ||
}} | ||
fullWidth | ||
/> | ||
); | ||
|
||
export default CapabilityField; |
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.