Skip to content

Commit 44b2ccd

Browse files
committed
fix: address Copilot review round 19 — empty-string const in the web required gate
hasMissingRequiredFields treated every empty string as missing, so a required field the schema pins to `""` — rendered read-only, and seeded with the only value it accepts — left Execute and Open App permanently disabled. It now matches the TUI check: an empty string counts as supplied when the property's own `const` pins it there, and an ordinary blank required string still does not. Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 36cf58f commit 44b2ccd

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎clients/web/src/utils/jsonUtils.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,28 @@ describe("root composition (#2123)", () => {
488488
).toBe(values);
489489
});
490490

491+
it("accepts an empty string a const pins the field to", () => {
492+
// Rendered read-only, so treating the seeded value as missing would
493+
// disable submit on a value the user cannot change.
494+
const pinnedEmpty: InspectorFormSchema = {
495+
type: "object",
496+
properties: { kind: { type: "string", const: "" } },
497+
required: ["kind"],
498+
};
499+
expect(hasMissingRequiredFields(pinnedEmpty, { kind: "" })).toBe(false);
500+
// An ordinary required string is still missing when left blank.
501+
expect(
502+
hasMissingRequiredFields(
503+
{
504+
type: "object",
505+
properties: { kind: { type: "string" } },
506+
required: ["kind"],
507+
},
508+
{ kind: "" },
509+
),
510+
).toBe(true);
511+
});
512+
491513
it("blocks submission while no branch is satisfied", () => {
492514
expect(hasMissingRequiredFields(UNION, {})).toBe(true);
493515
expect(hasMissingRequiredFields(UNION, { kind: "email" })).toBe(true);

‎clients/web/src/utils/jsonUtils.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,13 @@ function hasMissingIn(
292292
const fieldSchema = properties[field];
293293
return fieldSchema === undefined ? true : !admitsNull(fieldSchema);
294294
}
295-
return value === undefined || value === "";
295+
if (value === "") {
296+
// A schema may pin a field to the empty string, and the form renders such
297+
// a field read-only — so reporting the seeded value as missing would
298+
// disable submit on a value the user cannot change (#2123).
299+
return properties[field]?.const !== "";
300+
}
301+
return value === undefined;
296302
});
297303
}
298304

0 commit comments

Comments
 (0)