Repository navigation
refactor(site/src/pages/AgentsPage): extract switch and conflict alert components #32371
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
Changes from all commits
10f4a82
b22679b
d45f7d8
ec58cac
a5016bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { Alert, AlertDescription } from "#/components/Alert/Alert"; | ||
| import { Button } from "#/components/Button/Button"; | ||
|
|
||
| type ProjectEditConflictAlertProps = { | ||
| /** Explains what changed and what each action does. */ | ||
| readonly children: React.ReactNode; | ||
| readonly disabled: boolean; | ||
| readonly onKeepDraft: () => void; | ||
| readonly onLoadLatest: () => void; | ||
| readonly loadLatestButtonRef?: React.Ref<HTMLButtonElement>; | ||
| }; | ||
|
|
||
| /** | ||
| * Warns that a project setting changed elsewhere while its editor was open, | ||
| * and asks whether to keep the draft or load the latest value. | ||
| */ | ||
| export const ProjectEditConflictAlert: React.FC< | ||
| ProjectEditConflictAlertProps | ||
|
Comment on lines
+17
to
+18
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.
In this revision, AGENTS.md reference: site/AGENTS.md:L58-L59 Useful? React with 👍 / 👎. |
||
| > = ({ | ||
| children, | ||
| disabled, | ||
| onKeepDraft, | ||
| onLoadLatest, | ||
| loadLatestButtonRef, | ||
| }) => ( | ||
| <Alert | ||
| severity="warning" | ||
| actions={ | ||
| <> | ||
| <Button | ||
| type="button" | ||
| size="sm" | ||
| variant="outline" | ||
| disabled={disabled} | ||
| onClick={onKeepDraft} | ||
| > | ||
| Keep my draft | ||
| </Button> | ||
| <Button | ||
| ref={loadLatestButtonRef} | ||
| type="button" | ||
| size="sm" | ||
| disabled={disabled} | ||
| onClick={onLoadLatest} | ||
| > | ||
| Load latest | ||
| </Button> | ||
| </> | ||
| } | ||
| > | ||
| <AlertDescription>{children}</AlertDescription> | ||
| </Alert> | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { useId } from "react"; | ||
| import { Label } from "#/components/Label/Label"; | ||
| import { Switch } from "#/components/Switch/Switch"; | ||
|
|
||
| type SettingSwitchProps = { | ||
| readonly label: string; | ||
| /** Described to assistive technology as the switch's description. */ | ||
| readonly description: React.ReactNode; | ||
| readonly checked: boolean; | ||
| readonly disabled: boolean; | ||
| readonly onCheckedChange: (checked: boolean) => void; | ||
| }; | ||
|
|
||
| /** A labeled switch for one setting, with the description below its label. */ | ||
|
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.
The AGENTS.md reference: site/AGENTS.md:L9-L10 Useful? React with 👍 / 👎. |
||
| export const SettingSwitch: React.FC<SettingSwitchProps> = ({ | ||
| label, | ||
| description, | ||
| checked, | ||
| disabled, | ||
| onCheckedChange, | ||
| }) => { | ||
| const switchId = useId(); | ||
| const descriptionId = useId(); | ||
| return ( | ||
| <div className="flex items-start justify-between gap-4"> | ||
| <div className="flex flex-col gap-1"> | ||
| <Label htmlFor={switchId}>{label}</Label> | ||
| <div | ||
| id={descriptionId} | ||
| className="flex flex-col gap-1 text-xs text-content-secondary" | ||
| > | ||
| {description} | ||
| </div> | ||
| </div> | ||
| <Switch | ||
| id={switchId} | ||
| aria-describedby={descriptionId} | ||
| checked={checked} | ||
| disabled={disabled} | ||
| onCheckedChange={onCheckedChange} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
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 JSDoc paraphrases the component name and the two visibly labeled actions without documenting a non-obvious invariant. Replace it with a substantive contract if the component remains exported, or remove it along with the premature extraction.
AGENTS.md reference: site/AGENTS.md:L9-L10
Useful? React with 👍 / 👎.