-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate radio buttons to Ant Design #5681
Open
jpople
wants to merge
6
commits into
main
Choose a base branch
from
jpople/hj-223/migrate-radio-buttons
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc5c36e
migrate radio buttons
jpople 1f17cf1
fix broken import
jpople e6749c0
comment out console log etc.
jpople e2b0185
fix test
jpople b731651
Merge branch 'main' into jpople/hj-223/migrate-radio-buttons
jpople ede125a
adjust delete report button spacing
jpople File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
115 changes: 115 additions & 0 deletions
115
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,115 @@ | ||
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 htmlFor={props.id || props.name}>{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 htmlFor={props.id || props.name}>{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>; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just commenting this out for now to make ESLint happy for CI purposes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry about that |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This label doesn't actually tie to any form elements, so we should just leave off the
htmlFor
altogether. It's mostly a decorative label.