mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 13:26:04 -06:00
fix(ui): route default resets through removal
This commit is contained in:
@@ -194,6 +194,7 @@ describe("config form collection defaults", () => {
|
||||
it("shows and restores a top-level object default without nesting the section", () => {
|
||||
const container = document.createElement("div");
|
||||
const onPatch = vi.fn();
|
||||
const onRemove = vi.fn();
|
||||
const schema = {
|
||||
type: "object" as const,
|
||||
title: "Settings",
|
||||
@@ -213,6 +214,7 @@ describe("config form collection defaults", () => {
|
||||
unsupported: new Set(),
|
||||
disabled: false,
|
||||
onPatch,
|
||||
onRemove,
|
||||
},
|
||||
renderNode,
|
||||
),
|
||||
@@ -222,9 +224,11 @@ describe("config form collection defaults", () => {
|
||||
expect(container.textContent).toContain('Default: {"mode":"balanced"}');
|
||||
expect(container.querySelector("details")).toBeNull();
|
||||
resetButton(container).click();
|
||||
expect(onPatch).toHaveBeenCalledWith(["settings"], undefined);
|
||||
expect(onRemove).toHaveBeenCalledWith(["settings"]);
|
||||
expect(onPatch).not.toHaveBeenCalled();
|
||||
|
||||
onPatch.mockClear();
|
||||
onRemove.mockClear();
|
||||
render(
|
||||
renderObject(
|
||||
{
|
||||
@@ -235,6 +239,7 @@ describe("config form collection defaults", () => {
|
||||
unsupported: new Set(),
|
||||
disabled: false,
|
||||
onPatch,
|
||||
onRemove,
|
||||
},
|
||||
renderNode,
|
||||
),
|
||||
@@ -249,6 +254,7 @@ describe("config form collection defaults", () => {
|
||||
.placeholder,
|
||||
).toBe("Default: balanced");
|
||||
expect(onPatch).not.toHaveBeenCalled();
|
||||
expect(onRemove).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("conceals a sensitive top-level object default", () => {
|
||||
|
||||
@@ -231,9 +231,10 @@ describe("config form scalar integrity", () => {
|
||||
container.querySelector<HTMLButtonElement>("button[aria-label='Reset to default']"),
|
||||
"number reset",
|
||||
).click();
|
||||
expect(onPatch).toHaveBeenCalledWith(["retries"], undefined);
|
||||
expect(onRemove).not.toHaveBeenCalled();
|
||||
expect(onRemove).toHaveBeenCalledWith(["retries"]);
|
||||
expect(onPatch).not.toHaveBeenCalled();
|
||||
|
||||
onRemove.mockClear();
|
||||
render(
|
||||
renderSelect({
|
||||
schema: { type: "string", default: "balanced" },
|
||||
@@ -257,7 +258,8 @@ describe("config form scalar integrity", () => {
|
||||
expect(select.selectedOptions[0]?.textContent?.trim()).toBe("fast");
|
||||
select.value = "__unset__";
|
||||
select.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
expect(onPatch).toHaveBeenCalledWith(["mode"], undefined);
|
||||
expect(onRemove).toHaveBeenCalledWith(["mode"]);
|
||||
expect(onPatch).not.toHaveBeenCalled();
|
||||
|
||||
render(
|
||||
renderSelect({
|
||||
|
||||
@@ -494,7 +494,9 @@ export function renderSelect(
|
||||
const accepted =
|
||||
params.isRequired && schema.default !== undefined
|
||||
? onPatch(path, structuredClone(schema.default))
|
||||
: onPatch(path, undefined);
|
||||
: params.onRemove
|
||||
? params.onRemove(path)
|
||||
: onPatch(path, undefined);
|
||||
if (accepted === false) {
|
||||
target.value = selectedValue;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ export function renderSchemaDefaultDescription(
|
||||
export function renderRestoreDefaultButton(
|
||||
params: Pick<
|
||||
ConfigNodeRenderParams,
|
||||
"schema" | "value" | "path" | "disabled" | "isRequired" | "onPatch"
|
||||
"schema" | "value" | "path" | "disabled" | "isRequired" | "onPatch" | "onRemove"
|
||||
>,
|
||||
): TemplateResult | typeof nothing {
|
||||
if (params.schema.default === undefined || params.value === undefined) {
|
||||
@@ -305,6 +305,10 @@ export function renderRestoreDefaultButton(
|
||||
params.onPatch(params.path, structuredClone(params.schema.default));
|
||||
return;
|
||||
}
|
||||
if (params.onRemove) {
|
||||
params.onRemove(params.path);
|
||||
return;
|
||||
}
|
||||
params.onPatch(params.path, undefined);
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user