-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate radio buttons to Ant Design (#5681)
- Loading branch information
Showing
10 changed files
with
186 additions
and
171 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
113 changes: 113 additions & 0 deletions
113
clients/admin-ui/src/features/common/form/ControlledRadioGroup.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,113 @@ | ||
import type { AntRadioGroupProps as RadioGroupProps } from "fidesui"; | ||
import { | ||
AntFlex as Flex, | ||
AntRadio as Radio, | ||
FormControl, | ||
Grid, | ||
RadioChangeEvent, | ||
Text, | ||
} from "fidesui"; | ||
import { useField } from "formik"; | ||
|
||
import type { StringField } from "~/features/common/form/inputs"; | ||
import { ErrorMessage, Label, Option } from "~/features/common/form/inputs"; | ||
import QuestionTooltip from "~/features/common/QuestionTooltip"; | ||
|
||
interface ControlledRadioGroupProps extends RadioGroupProps { | ||
label?: string; | ||
options: Option[]; | ||
layout?: "inline" | "stacked"; | ||
defaultFirstSelected?: boolean; | ||
} | ||
|
||
const ControlledRadioGroup = ({ | ||
label, | ||
options, | ||
layout, | ||
defaultFirstSelected = true, | ||
...props | ||
}: ControlledRadioGroupProps & StringField) => { | ||
const [initialField, meta] = useField(props); | ||
const field = { ...initialField, value: initialField.value ?? "" }; | ||
const isInvalid = !!(meta.touched && meta.error); | ||
const defaultSelected = defaultFirstSelected ? options[0] : undefined; | ||
const selected = | ||
options.find((o) => o.value === field.value) ?? defaultSelected; | ||
|
||
const handleChange = (e: RadioChangeEvent) => { | ||
field.onChange(props.name)(e.target.value); | ||
}; | ||
|
||
if (layout === "stacked") { | ||
return ( | ||
<FormControl isInvalid={isInvalid}> | ||
<Flex className="w-fit"> | ||
{label ? <Label>{label}</Label> : null} | ||
<Radio.Group | ||
onChange={handleChange} | ||
value={selected?.value} | ||
data-testid={`input-${field.name}`} | ||
> | ||
<Flex className="flex-col gap-3"> | ||
{options.map( | ||
({ value, label: optionLabel, tooltip: optionTooltip }) => ( | ||
<Radio | ||
key={value} | ||
value={value} | ||
data-testid={`option-${value}`} | ||
> | ||
<Flex className="items-center gap-2"> | ||
<Text fontSize="sm" fontWeight="medium"> | ||
{optionLabel} | ||
</Text> | ||
{optionTooltip ? ( | ||
<QuestionTooltip label={optionTooltip} /> | ||
) : null} | ||
</Flex> | ||
</Radio> | ||
), | ||
)} | ||
</Flex> | ||
</Radio.Group> | ||
</Flex> | ||
<ErrorMessage | ||
isInvalid={isInvalid} | ||
message={meta.error} | ||
fieldName={field.name} | ||
/> | ||
</FormControl> | ||
); | ||
} | ||
|
||
return ( | ||
<FormControl isInvalid={isInvalid}> | ||
<Grid templateColumns="1fr 3fr"> | ||
<Label>{label}</Label> | ||
<Radio.Group | ||
onChange={handleChange} | ||
value={selected?.value} | ||
data-testid={`input-${field.name}`} | ||
> | ||
<Flex> | ||
{options.map((o) => ( | ||
<Radio | ||
key={o.value} | ||
value={o.value} | ||
data-testid={`option-${o.value}`} | ||
> | ||
{o.label} | ||
</Radio> | ||
))} | ||
</Flex> | ||
</Radio.Group> | ||
</Grid> | ||
<ErrorMessage | ||
isInvalid={isInvalid} | ||
message={meta.error} | ||
fieldName={field.name} | ||
/> | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export default ControlledRadioGroup; |
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
22 changes: 12 additions & 10 deletions
22
...scovery-and-detection/action-center/tables/cells/DiscoveredSystemAggregateActionsCell.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,14 +1,16 @@ | ||
import { AntFlex as Flex } from "fidesui"; | ||
|
||
import { MonitorSystemAggregate } from "../../types"; | ||
// import { MonitorSystemAggregate } from "../../types"; | ||
|
||
interface DiscoveredSystemActionsCellProps { | ||
system: MonitorSystemAggregate; | ||
} | ||
// interface DiscoveredSystemActionsCellProps { | ||
// system: MonitorSystemAggregate; | ||
// } | ||
|
||
export const DiscoveredSystemActionsCell = ({ | ||
system, | ||
}: DiscoveredSystemActionsCellProps) => { | ||
console.log(system); | ||
return <Flex> </Flex>; | ||
}; | ||
export const DiscoveredSystemActionsCell = () => | ||
// { | ||
// system, | ||
// }: DiscoveredSystemActionsCellProps, | ||
{ | ||
// console.log(system); | ||
return <Flex> </Flex>; | ||
}; |
Oops, something went wrong.