Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
*/
Comment on lines +13 to +16

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the restating conflict-alert description

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 👍 / 👎.

export const ProjectEditConflictAlert: React.FC<
ProjectEditConflictAlertProps
Comment on lines +17 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the one-off conflict alert at its use site

In this revision, ProjectEditConflictAlert is used only by ProjectInstructionsDialog, so its callbacks, ref, and content now cross a file boundary without established reuse. Keep the alert inline until the additional editor that needs this abstraction lands.

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
Expand Up @@ -15,6 +15,7 @@ import {
} from "#/components/Dialog/Dialog";
import { Spinner } from "#/components/Spinner/Spinner";
import { sanitizePromptText } from "#/utils/invisibleUnicode";
import { ProjectEditConflictAlert } from "./ProjectEditConflictAlert";

type ProjectInstructionsDialogProps = {
readonly open: boolean;
Expand Down Expand Up @@ -140,40 +141,19 @@ const ProjectInstructionsForm: React.FC<ProjectInstructionsFormProps> = ({
autoFocus
/>
{hasConflict && (
<Alert
severity="warning"
actions={
<div className="flex gap-2">
<Button
type="button"
size="sm"
variant="outline"
disabled={isBusy}
onClick={() => setBaseInstructions(instructions)}
>
Keep my draft
</Button>
<Button
ref={loadLatestButtonRef}
type="button"
size="sm"
disabled={isBusy}
onClick={() => {
setBaseInstructions(instructions);
setDraft(instructions);
onResetErrors();
}}
>
Load latest
</Button>
</div>
}
<ProjectEditConflictAlert
disabled={isBusy}
loadLatestButtonRef={loadLatestButtonRef}
onKeepDraft={() => setBaseInstructions(instructions)}
onLoadLatest={() => {
setBaseInstructions(instructions);
setDraft(instructions);
onResetErrors();
}}
>
<AlertDescription>
Someone else changed these instructions while you were editing.
Load the latest version, or keep your draft to replace it.
</AlertDescription>
</Alert>
Someone else changed these instructions while you were editing. Load
the latest version, or keep your draft to replace it.
</ProjectEditConflictAlert>
)}
<InvisibleCharactersAlert text={draft} />
{Boolean(error) && (
Expand Down
44 changes: 44 additions & 0 deletions site/src/pages/AgentsPage/components/SettingSwitch.tsx
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. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the switch's non-obvious contract

The SettingSwitch JSDoc only repeats the component name and narrates its layout. Rewrite it around the meaningful accessibility contract, such as associating the description through aria-describedby, so the required export documentation adds information.

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>
);
};
42 changes: 3 additions & 39 deletions site/src/pages/AgentsPage/components/SkillEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { FormField } from "#/components/FormField/FormField";
import { Input } from "#/components/Input/Input";
import { Label } from "#/components/Label/Label";
import { Spinner } from "#/components/Spinner/Spinner";
import { Switch } from "#/components/Switch/Switch";
import { formatKiB } from "#/utils/fileSize";
import {
countCharacters,
Expand All @@ -36,6 +35,7 @@ import {
type SkillFormValues,
tryParseSkillMarkdown,
} from "../utils/skills";
import { SettingSwitch } from "./SettingSwitch";

export type SkillErrorDisplay = {
message: string;
Expand Down Expand Up @@ -596,7 +596,7 @@ export const SkillEditorProjectSettings: React.FC = () => {
const { form, readOnly, isBusy } = useSkillEditorContext();
return (
<>
<SkillSettingSwitch
<SettingSwitch
label="Show as action"
description="Adds a button above the composer in this project's chats that inserts the skill."
checked={form.values.action ?? false}
Expand All @@ -606,7 +606,7 @@ export const SkillEditorProjectSettings: React.FC = () => {
}
/>
{form.values.action && <SkillEditorDisplayNameField />}
<SkillSettingSwitch
<SettingSwitch
label="Agents can use it automatically"
description="When off, agents use the skill only when someone invokes it."
checked={form.values.modelInvocable ?? true}
Expand Down Expand Up @@ -637,42 +637,6 @@ const SkillEditorDisplayNameField: React.FC = () => {
);
};

type SkillSettingSwitchProps = {
label: string;
description: string;
checked: boolean;
disabled: boolean;
onCheckedChange: (checked: boolean) => void;
};

const SkillSettingSwitch: React.FC<SkillSettingSwitchProps> = ({
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>
<p id={descriptionId} className="m-0 text-xs text-content-secondary">
{description}
</p>
</div>
<Switch
id={switchId}
aria-describedby={descriptionId}
checked={checked}
disabled={disabled}
onCheckedChange={onCheckedChange}
/>
</div>
);
};

type SkillEditorSubmitButtonProps = {
children: React.ReactNode;
};
Expand Down
Loading