Skip to content

Commit 9d074c3

Browse files
committed
refactor(ui): drop the reset-to-default icon from settings rows
The schema-driven config form and the hand-written settings pages each rendered their own circular "Reset to default" icon button next to any overridden row. It was persistent chrome on a surface that is already dense, and every affected control can reach its default directly. Deletes both implementations (`renderRestoreDefaultButton`, `renderSettingsDefaultState`) and the callback chains that existed only to feed them. The "Default: x" / "Using default: x" descriptions stay.
1 parent adf5c67 commit 9d074c3

33 files changed

Lines changed: 319 additions & 1079 deletions

‎ui/src/components/config-form-collection-defaults.browser.test.ts‎

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Control UI tests cover collection default provenance and restore behavior.
1+
// Control UI tests cover collection default provenance and editing behavior.
22
import { render } from "lit";
33
import { describe, expect, it, vi } from "vitest";
44
import { renderArray, renderObject } from "./config-form.node.collection.ts";
@@ -13,15 +13,8 @@ function expectElement<T extends Element>(element: T | null | undefined, label:
1313
return element;
1414
}
1515

16-
function resetButton(container: ParentNode): HTMLButtonElement {
17-
return expectElement(
18-
container.querySelector<HTMLButtonElement>("button[aria-label='Reset to default']"),
19-
"reset to default button",
20-
);
21-
}
22-
2316
describe("config form collection defaults", () => {
24-
it("shows and restores optional JSON defaults without authoring the inherited value", () => {
17+
it("shows and clears optional JSON defaults without authoring the inherited value", () => {
2518
const container = document.createElement("div");
2619
const onPatch = vi.fn();
2720
const schema = {
@@ -43,9 +36,13 @@ describe("config form collection defaults", () => {
4336
);
4437

4538
expect(container.textContent).toContain('Default: {"mode":"balanced"}');
46-
expectElement(container.querySelector<HTMLTextAreaElement>("textarea"), "explicit JSON").value =
47-
'{\n "mode": "custom"\n}';
48-
resetButton(container).click();
39+
const textarea = expectElement(
40+
container.querySelector<HTMLTextAreaElement>("textarea"),
41+
"explicit JSON",
42+
);
43+
expect(textarea.value).toBe('{\n "mode": "custom"\n}');
44+
textarea.value = "";
45+
textarea.dispatchEvent(new Event("change", { bubbles: true }));
4946
expect(onPatch).toHaveBeenCalledWith(["payload"], undefined);
5047

5148
onPatch.mockClear();
@@ -63,15 +60,14 @@ describe("config form collection defaults", () => {
6360
);
6461

6562
expect(container.textContent).toContain('Using default: {"mode":"balanced"}');
66-
expectElement(
67-
container.querySelector<HTMLTextAreaElement>("textarea"),
68-
"inherited JSON",
69-
).value = '{\n "mode": "balanced"\n}';
70-
expect(container.querySelector("button[aria-label='Reset to default']")).toBeNull();
63+
expect(
64+
expectElement(container.querySelector<HTMLTextAreaElement>("textarea"), "inherited JSON")
65+
.value,
66+
).toBe('{\n "mode": "balanced"\n}');
7167
expect(onPatch).not.toHaveBeenCalled();
7268
});
7369

74-
it("shows optional array defaults and keeps rejected restores in the DOM", () => {
70+
it("shows optional array defaults and authors inherited items without dropping siblings", () => {
7571
const container = document.createElement("div");
7672
const onPatch = vi.fn(() => false);
7773
const schema = {
@@ -98,13 +94,10 @@ describe("config form collection defaults", () => {
9894

9995
expect(container.textContent).toContain('Default: ["a","b"]');
10096
expect(container.textContent).toContain("1 item");
101-
expectElement(container.querySelector<HTMLInputElement>("input"), "explicit array item").value =
102-
"custom";
103-
resetButton(container).click();
104-
expect(onPatch).toHaveBeenCalledWith(["values"], undefined);
105-
expect(container.textContent).toContain("1 item");
106-
expectElement(container.querySelector<HTMLInputElement>("input"), "rejected array item").value =
107-
"custom";
97+
expect(
98+
expectElement(container.querySelector<HTMLInputElement>("input"), "explicit array item")
99+
.value,
100+
).toBe("custom");
108101

109102
onPatch.mockClear();
110103
render(
@@ -128,7 +121,6 @@ describe("config form collection defaults", () => {
128121
const inheritedInputs = Array.from(container.querySelectorAll<HTMLInputElement>("input"));
129122
expect(inheritedInputs.map((input) => input.value)).toEqual(["", ""]);
130123
expect(inheritedInputs.map((input) => input.placeholder)).toEqual(["Default: a", "Default: b"]);
131-
expect(container.querySelector("button[aria-label='Reset to default']")).toBeNull();
132124
expect(onPatch).not.toHaveBeenCalled();
133125

134126
inheritedInputs[1]!.value = "custom";
@@ -193,7 +185,7 @@ describe("config form collection defaults", () => {
193185
);
194186
});
195187

196-
it("conceals sensitive collection defaults and disables restore until revealed", () => {
188+
it("conceals sensitive collection defaults", () => {
197189
const container = document.createElement("div");
198190
const onPatch = vi.fn();
199191
const hints = {
@@ -224,7 +216,6 @@ describe("config form collection defaults", () => {
224216
);
225217

226218
expect(container.textContent).not.toContain("default-secret");
227-
expect(resetButton(container).disabled).toBe(true);
228219

229220
render(
230221
renderArray(
@@ -249,10 +240,9 @@ describe("config form collection defaults", () => {
249240
);
250241

251242
expect(container.textContent).not.toContain("default-token");
252-
expect(resetButton(container).disabled).toBe(true);
253243
});
254244

255-
it("shows and restores a top-level object default without nesting the section", () => {
245+
it("shows a top-level object default without nesting the section", () => {
256246
const container = document.createElement("div");
257247
const onPatch = vi.fn();
258248
const onRemove = vi.fn();
@@ -284,8 +274,6 @@ describe("config form collection defaults", () => {
284274

285275
expect(container.textContent).toContain('Default: {"mode":"balanced"}');
286276
expect(container.querySelector("details")).toBeNull();
287-
resetButton(container).click();
288-
expect(onRemove).toHaveBeenCalledWith(["settings"]);
289277
expect(onPatch).not.toHaveBeenCalled();
290278

291279
onPatch.mockClear();
@@ -309,7 +297,6 @@ describe("config form collection defaults", () => {
309297

310298
expect(container.textContent).toContain('Using default: {"mode":"balanced"}');
311299
expect(container.querySelector("details")).toBeNull();
312-
expect(container.querySelector("button[aria-label='Reset to default']")).toBeNull();
313300
expect(
314301
expectElement(container.querySelector<HTMLInputElement>("input"), "inherited mode")
315302
.placeholder,
@@ -344,11 +331,10 @@ describe("config form collection defaults", () => {
344331
);
345332

346333
expect(container.textContent).not.toContain("default-secret");
347-
expect(resetButton(container).disabled).toBe(true);
348334
expect(container.querySelector("details")).toBeNull();
349335
});
350336

351-
it("removes an optional object as one value and keeps inherited children inherited", () => {
337+
it("keeps optional object children inherited until edited", () => {
352338
const container = document.createElement("div");
353339
const onPatch = vi.fn();
354340
const onRemove = vi.fn();
@@ -395,8 +381,6 @@ describe("config form collection defaults", () => {
395381
"explicit profile object",
396382
);
397383
expect(profile.textContent).toContain('Default: {"enabled":true,"mode":"balanced"}');
398-
resetButton(profile).click();
399-
expect(onRemove).toHaveBeenCalledWith(["settings", "profile"]);
400384
expect(onPatch).not.toHaveBeenCalled();
401385

402386
onRemove.mockClear();
@@ -444,7 +428,6 @@ describe("config form collection defaults", () => {
444428
expectElement(modeRow.querySelector<HTMLInputElement>("input"), "inherited mode input")
445429
.placeholder,
446430
).toBe("Default: balanced");
447-
expect(inheritedProfile.querySelector("button[aria-label='Reset to default']")).toBeNull();
448431
expect(onRemove).not.toHaveBeenCalled();
449432

450433
const modeInput = expectElement(
@@ -458,47 +441,4 @@ describe("config form collection defaults", () => {
458441
mode: "custom",
459442
});
460443
});
461-
462-
it("deep-clones required collection defaults before restoring them", () => {
463-
const container = document.createElement("div");
464-
const onPatch = vi.fn();
465-
const schemaDefault = { nested: { enabled: true } };
466-
467-
render(
468-
renderObject(
469-
{
470-
schema: {
471-
type: "object",
472-
title: "Required object",
473-
default: schemaDefault,
474-
properties: {
475-
nested: {
476-
type: "object",
477-
properties: {
478-
enabled: { type: "boolean" },
479-
},
480-
},
481-
},
482-
},
483-
value: { nested: { enabled: false } },
484-
path: ["settings", "requiredObject"],
485-
hints: {},
486-
unsupported: new Set(),
487-
disabled: false,
488-
isRequired: true,
489-
onPatch,
490-
},
491-
renderNode,
492-
),
493-
container,
494-
);
495-
496-
resetButton(container).click();
497-
expect(onPatch).toHaveBeenCalledWith(["settings", "requiredObject"], schemaDefault);
498-
const restored = onPatch.mock.calls[0]?.[1] as typeof schemaDefault;
499-
expect(restored).not.toBe(schemaDefault);
500-
expect(restored.nested).not.toBe(schemaDefault.nested);
501-
restored.nested.enabled = false;
502-
expect(schemaDefault.nested.enabled).toBe(true);
503-
});
504444
});

‎ui/src/components/config-form-scalar-integrity.browser.test.ts‎

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ describe("config form scalar integrity", () => {
217217
expect(textInput.value).toBe("");
218218
expect(textInput.placeholder).toBe("Default: balanced");
219219
expect(container.textContent).toContain("Using default: balanced");
220-
expect(container.querySelector("button[aria-label='Reset to default']")).toBeNull();
221220
expect(onPatch).not.toHaveBeenCalled();
222221
expect(onRemove).not.toHaveBeenCalled();
223222

@@ -252,7 +251,27 @@ describe("config form scalar integrity", () => {
252251
expect(onPatch).toHaveBeenLastCalledWith(["retries"], 4);
253252
});
254253

255-
it("restores scalar and select defaults by removing optional overrides", () => {
254+
it("shows the default description without a reset button on an overridden row", () => {
255+
const container = document.createElement("div");
256+
render(
257+
renderTextInput({
258+
schema: { type: "string", default: "balanced" },
259+
value: "custom",
260+
path: ["mode"],
261+
hints: {},
262+
unsupported: new Set(),
263+
disabled: false,
264+
inputType: "text",
265+
onPatch: vi.fn(),
266+
}),
267+
container,
268+
);
269+
270+
expect(container.textContent).toContain("Default: balanced");
271+
expect(container.querySelector("button[aria-label='Reset to default']")).toBeNull();
272+
});
273+
274+
it("restores scalar and select defaults through clearing and default selection", () => {
256275
const container = document.createElement("div");
257276
const onPatch = vi.fn();
258277
const onRemove = vi.fn();
@@ -271,14 +290,16 @@ describe("config form scalar integrity", () => {
271290
container,
272291
);
273292
expect(container.textContent).toContain("Default: 3");
274-
expectElement(
275-
container.querySelector<HTMLButtonElement>("button[aria-label='Reset to default']"),
276-
"number reset",
277-
).click();
278-
expect(onRemove).toHaveBeenCalledWith(["retries"]);
279-
expect(onPatch).not.toHaveBeenCalled();
293+
const numberInput = expectElement(
294+
container.querySelector<HTMLInputElement>("input[type='number']"),
295+
"number input",
296+
);
297+
numberInput.value = "";
298+
numberInput.dispatchEvent(new Event("input", { bubbles: true }));
299+
expect(onPatch).toHaveBeenCalledWith(["retries"], undefined);
300+
expect(onRemove).not.toHaveBeenCalled();
280301

281-
onRemove.mockClear();
302+
onPatch.mockClear();
282303
render(
283304
renderSelect({
284305
schema: { type: "string", default: "balanced" },
@@ -712,7 +733,7 @@ describe("config form scalar integrity", () => {
712733
},
713734
);
714735

715-
it("keeps restore disabled while a sensitive value is concealed", () => {
736+
it("conceals the default description while a sensitive value is concealed", () => {
716737
const container = document.createElement("div");
717738

718739
render(
@@ -731,11 +752,6 @@ describe("config form scalar integrity", () => {
731752
container,
732753
);
733754

734-
const reset = expectElement(
735-
container.querySelector<HTMLButtonElement>("button[aria-label='Reset to default']"),
736-
"concealed sensitive reset",
737-
);
738-
expect(reset.disabled).toBe(true);
739755
expect(container.textContent).not.toContain("inherited");
740756
});
741757

‎ui/src/components/config-form.node.collection.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
getSensitiveRenderState,
3939
isAnySchema,
4040
jsonValue,
41-
renderCollectionDefaultPresentation,
41+
renderCollectionDefaultDescription,
4242
renderFlatDefaultRow,
4343
renderFieldRow,
4444
renderJsonTextareaControl,
@@ -98,7 +98,7 @@ export function renderObject(
9898
fallback && typeof fallback === "object" && !Array.isArray(fallback)
9999
? (fallback as Record<string, unknown>)
100100
: {};
101-
const defaultPresentation = renderCollectionDefaultPresentation(params, fallback);
101+
const defaultDescription = renderCollectionDefaultDescription(params, fallback);
102102
const entries = objectPropertyKeys(schema)
103103
.map((key) => [key, objectPropertySchema(schema, key)] as const)
104104
.filter((entry): entry is readonly [string, ConfigNodeRenderParams["schema"]] =>
@@ -197,7 +197,7 @@ export function renderObject(
197197
// Top-level objects and label-less contexts emit rows directly into the
198198
// surrounding settings-group so row dividers stay sibling-driven.
199199
if (path.length === 1 || params.showLabel === false) {
200-
return html`${path.length === 1 ? renderFlatDefaultRow(defaultPresentation) : nothing}${fields}`;
200+
return html`${path.length === 1 ? renderFlatDefaultRow(defaultDescription) : nothing}${fields}`;
201201
}
202202

203203
// Nested objects get collapsible treatment as an indented sub-block.
@@ -208,12 +208,11 @@ export function renderObject(
208208
<span class="settings-row__title">${label}</span>
209209
${help ? html`<span class="settings-row__desc">${help}</span>` : nothing}
210210
${schema.default !== undefined
211-
? html`<span class="settings-row__desc">${defaultPresentation.description}</span>`
211+
? html`<span class="settings-row__desc">${defaultDescription}</span>`
212212
: nothing}
213213
${renderTags(tags)}
214214
</div>
215215
<div class="settings-row__control">
216-
${defaultPresentation.action}
217216
<span class="settings-row__chevron cfg-object__chevron">${icons.chevronDown}</span>
218217
</div>
219218
</summary>
@@ -272,7 +271,7 @@ export function renderArray(
272271
: Array.isArray(schema.default)
273272
? schema.default
274273
: UNSET_ARRAY_SOURCE_IDENTITY;
275-
const defaultPresentation = renderCollectionDefaultPresentation(params, arrayValue);
274+
const defaultDescription = renderCollectionDefaultDescription(params, arrayValue);
276275
const rowIdentities = rowIdentitiesForArray(arrayValue);
277276
const {
278277
minItems: minimumItems,
@@ -356,7 +355,7 @@ export function renderArray(
356355
? html`<span class="settings-row__desc">${help}</span>`
357356
: nothing}
358357
${showHeaderMeta && schema.default !== undefined
359-
? html`<span class="settings-row__desc">${defaultPresentation.description}</span>`
358+
? html`<span class="settings-row__desc">${defaultDescription}</span>`
360359
: nothing}
361360
${renderTags(tags)}
362361
</div>
@@ -366,7 +365,6 @@ export function renderArray(
366365
count: String(arrayValue.length),
367366
})}</span
368367
>
369-
${defaultPresentation.action}
370368
<button
371369
type="button"
372370
class="btn btn--sm"

0 commit comments

Comments
 (0)