Skip to content

Commit 49f51e1

Browse files
tsukaskamaria-rcks
andauthored
fix(web): allow adding the displayed provider accent color (#25014)
Co-authored-by: tsukaska <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 87c33c8 commit 49f51e1

3 files changed

Lines changed: 133 additions & 2 deletions

File tree

‎apps/web/src/components/settings/AddProviderInstanceDialog.environment.browser.test.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,26 @@ describe("AddProviderInstanceDialog environment routing", () => {
170170
});
171171
});
172172

173+
it("includes the explicitly added default accent color when creating a provider", async () => {
174+
setup();
175+
await using _screen = await render(dialog());
176+
await click("Show more");
177+
await click("Use Kilo Code");
178+
await act(async () =>
179+
document
180+
.querySelector<HTMLButtonElement>('button[aria-label="Add accent color for Kilo Code"]')!
181+
.click(),
182+
);
183+
await click("Add color");
184+
await click("Continue to sign-in");
185+
186+
expect(settingsHooks.mutate).toHaveBeenCalledWith({
187+
operation: "create",
188+
instanceId: "acpRegistry_kilo_code",
189+
instance: expect.objectContaining({ accentColor: "#2563eb" }),
190+
});
191+
});
192+
173193
it("keeps fx and the ACP Registry under Show more", async () => {
174194
setup();
175195
await using _screen = await render(dialog());

‎apps/web/src/components/settings/ProviderAccentColorPicker.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ function ProviderCustomColorPanel(props: {
1414
readonly value: string;
1515
readonly onPreview: (value: string) => void;
1616
readonly onCommit: (value: string) => void;
17+
readonly showAddButton: boolean;
1718
}) {
1819
const { onCommit, onPreview } = props;
1920
const [hsv, setHsv] = useState(() => hexToHsv(props.value));
2021
const currentColor = hsvToHex(hsv.h, hsv.s, hsv.v);
2122
const [hexDraft, setHexDraft] = useState<string | null>(null);
23+
const [syncedValue, setSyncedValue] = useState(props.value);
24+
if (syncedValue !== props.value) {
25+
setSyncedValue(props.value);
26+
if (currentColor !== props.value.toLowerCase()) {
27+
setHsv(hexToHsv(props.value));
28+
setHexDraft(null);
29+
}
30+
}
2231
// Pointer drags only preview and commit once on release, so a drag writes
2332
// settings once instead of on every pointer move. Keyboard steps commit
2433
// immediately because they have no release to wait for. Holds the latest
@@ -80,6 +89,15 @@ function ProviderCustomColorPanel(props: {
8089
aria-label="Custom hex accent color"
8190
spellCheck={false}
8291
/>
92+
{props.showAddButton ? (
93+
<PopoverClose
94+
render={
95+
<Button type="button" size="compact" onClick={() => onCommit(currentColor)}>
96+
Add color
97+
</Button>
98+
}
99+
/>
100+
) : null}
83101
</div>
84102
</div>
85103
);
@@ -123,6 +141,7 @@ function ProviderCustomColorPicker(props: {
123141
value={normalized ?? FALLBACK_ACCENT_COLOR}
124142
onPreview={props.onPreview}
125143
onCommit={props.onCommit}
144+
showAddButton={!normalized}
126145
/>
127146
{normalized ? (
128147
<div className="border-t border-border/60 p-1">

‎apps/web/src/components/settings/colorPickers.browser.test.tsx‎

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, vi } from "vite-plus/test";
2-
import { userEvent } from "vite-plus/test/browser";
2+
import { page, userEvent } from "vite-plus/test/browser";
33

44
import { useState, type ReactNode } from "react";
55

@@ -124,6 +124,89 @@ async function renderAccentPicker(value: string) {
124124
}
125125

126126
describe("provider accent color picker", () => {
127+
it("leaves the optional color unset when the preview is dismissed", async () => {
128+
const onCommit = vi.fn();
129+
await using _screen = await renderPicker(
130+
<ProviderAccentColorPicker
131+
displayName="Example provider"
132+
value={undefined}
133+
onCommit={onCommit}
134+
/>,
135+
);
136+
137+
await open("Add accent color for Example provider");
138+
expect(byLabel<HTMLInputElement>("Custom hex accent color").value).toBe("#2563eb");
139+
expect(onCommit).not.toHaveBeenCalled();
140+
await userEvent.keyboard("{Escape}");
141+
expect(onCommit).not.toHaveBeenCalled();
142+
});
143+
144+
it("adds the displayed default without adjusting a color control", async () => {
145+
const onCommit = vi.fn();
146+
await using screen = await renderPicker(
147+
<ProviderAccentColorPicker
148+
displayName="Example provider"
149+
value={undefined}
150+
onCommit={onCommit}
151+
/>,
152+
);
153+
154+
await open("Add accent color for Example provider");
155+
await userEvent.click(page.getByRole("button", { name: "Add color", exact: true }));
156+
157+
expect(onCommit).toHaveBeenCalledExactlyOnceWith("#2563eb");
158+
await expect
159+
.element(screen.getByRole("button", { name: "Change accent color for Example provider" }))
160+
.toBeVisible();
161+
await vi.waitFor(() =>
162+
expect(document.querySelector('[aria-label="Custom hex accent color"]')).toBeNull(),
163+
);
164+
});
165+
166+
it("lets keyboard users add the displayed default", async () => {
167+
const onCommit = vi.fn();
168+
await using screen = await renderPicker(
169+
<ProviderAccentColorPicker
170+
displayName="Example provider"
171+
value={undefined}
172+
onCommit={onCommit}
173+
/>,
174+
);
175+
176+
await open("Add accent color for Example provider");
177+
await act(async () => byLabel("Accent color saturation").focus());
178+
await userEvent.tab();
179+
await userEvent.tab();
180+
await userEvent.tab();
181+
await userEvent.tab();
182+
await userEvent.keyboard("{Enter}");
183+
184+
expect(onCommit).toHaveBeenCalledExactlyOnceWith("#2563eb");
185+
await expect
186+
.element(screen.getByRole("button", { name: "Change accent color for Example provider" }))
187+
.toBeVisible();
188+
});
189+
190+
it("keeps live color editing and allows clearing back to unset", async () => {
191+
const onCommit = vi.fn();
192+
await using screen = await renderPicker(
193+
<ProviderAccentColorPicker
194+
displayName="Example provider"
195+
value="#ff0000"
196+
onCommit={onCommit}
197+
/>,
198+
);
199+
200+
await open("Change accent color for Example provider");
201+
await press(HUE, "ArrowRight", true);
202+
expect(onCommit).toHaveBeenLastCalledWith("#ff2a00");
203+
await userEvent.click(page.getByRole("button", { name: "Clear color", exact: true }));
204+
expect(onCommit).toHaveBeenLastCalledWith("");
205+
await expect
206+
.element(screen.getByRole("button", { name: "Add accent color for Example provider" }))
207+
.toBeVisible();
208+
});
209+
127210
it("commits a drag that is still in progress when the popover closes", async () => {
128211
await using screen = await renderAccentPicker("#ff0000");
129212

@@ -145,6 +228,9 @@ describe("provider accent color picker", () => {
145228
await userEvent.fill(byLabel("Custom hex accent color"), "#ff0000");
146229

147230
expect(screen.onCommit).toHaveBeenLastCalledWith("#ff0000");
231+
await userEvent.fill(byLabel("Custom hex accent color"), "#00FF00");
232+
await screen.echo("#00FF00");
233+
expect(byLabel<HTMLInputElement>("Custom hex accent color").value).toBe("#00FF00");
148234
});
149235

150236
it("shows the saved color again when it is reverted outside the picker", async () => {
@@ -155,6 +241,12 @@ describe("provider accent color picker", () => {
155241
await screen.echo("#00ff00");
156242
await screen.echo("#ff0000");
157243

158-
expect(byLabel("Change accent color for Codex").style.backgroundColor).toBe("rgb(255, 0, 0)");
244+
expect(byLabel<HTMLInputElement>("Custom hex accent color").value).toBe("#ff0000");
245+
await screen.echo("");
246+
expect(byLabel<HTMLInputElement>("Custom hex accent color").value).toBe("#2563eb");
247+
await userEvent.click(page.getByRole("button", { name: "Add color", exact: true }));
248+
expect(screen.onCommit).toHaveBeenLastCalledWith("#2563eb");
249+
250+
expect(byLabel("Change accent color for Codex").style.backgroundColor).toBe("rgb(37, 99, 235)");
159251
});
160252
});

0 commit comments

Comments
 (0)