From cec27a27ea231d7ed599a990f00fa50513b06f34 Mon Sep 17 00:00:00 2001 From: Jerred Shepherd Date: Wed, 25 Nov 2026 20:00:26 -0800 Subject: [PATCH 1/2] feat(flags): edit flags in Monaco with registry-driven JSON validation Why The operator UI edited every variant as one single-line input, so JSON values such as delivery-enabled-environments were a long array crammed into a text field, and nothing told the operator a value was invalid until the server refused the save with a generic error. The value registry now describes every managed variant's decoded type, so the editor can validate against the same source of truth as the server. What - Form / JSON toggle (console-ui Tabs) over one shared draft. Switching modes never loses an edit; unparsed JSON text survives a round trip to Form. - JSON mode runs Monaco: boolean flags edit their whole object against a JSON Schema derived from FlagValueSchema with type and key fixed by `const`; json-encoded variants edit their decoded, pretty-printed value against the key's entry in flag-value-schemas.generated.json and are saved canonically via encodeVariantValue; number/string variants edit a JSON literal. json-encoded variants open in JSON mode by default. - Form mode keeps typed controls: number input for number encodings, a text area for JSON text, a text field otherwise. Unmanaged keys are shown as plain text with a notice that the server rejects writes to them. - validateVariantValue issues are listed live by JSON Pointer path and disable Review; JSON parse and schema errors also block Review and show as Monaco squiggles. useApplyFlag returns a typed `invalid` result for the server's 400 issues, which are listed against the value until it changes. - The review dialog and conflict banner use a read-only Monaco DiffEditor (side by side when wide, inline when narrow) of decoded values for json variants and the flag JSON otherwise. The dialog focuses Cancel natively and keeps Esc; "Load their version" is unchanged. - Monaco 0.57 is bundled locally and lazy-loaded (React.lazy) with only the JSON language, its worker and the base editor worker; no CDN loader. Its theme is built from the console-ui --ui-* tokens and --ui-font-mono at theme time and follows the theme store live. - README Operator section documents editing modes, validation and saving. Bundle (vite build, minified / gzip) - Entry index.js: 548.41 / 172.52 kB before, 595.06 / 183.54 kB after (the registry, generated JSON Schemas and editor code). - Lazy, first editor or diff only: runtime 3,927.53 / 1,004.57 kB, jsonMode 40.13 / 11.22 kB, runtime CSS 186.01 / 27.36 kB, json.worker 433.16 kB, editor.worker 303.82 kB. Monaco 0.57's JSON worker client imports the standard editor contributions, so trimming below editor.main saves little JS. It still drops every basic-language chunk and the TS, CSS and HTML services and workers (about 8.7 MB of worker output). Verification - bunx turbo run build typecheck test lint --filter=@shepherdjerred/flags: 10/10 tasks, 57 tests passed (model unit tests plus jsdom render tests with a textarea stand-in for the lazy Monaco module). - bunx lefthook run pre-commit on explicitly staged paths: passed. - Rendered locally (Flags server plus operator proxy, PinchTab) in dark and light at 1440px and 600px: pretty-printed delivery-enabled-environments, a schema squiggle with hover message and blocked Review, a boolean flag in JSON mode, the review DiffEditor (inline at 600px), a live theme toggle re-theming Monaco, and an end-to-end save storing compact canonical JSON. No console errors or uncaught exceptions, and the JSON worker loaded. - Not run: CI, deployment, or the live Flags deployment. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011u9pQnKWrycqkZxjQrvL4Q --- bun.lock | 1 + packages/flags/README.md | 46 +- packages/flags/package.json | 7 +- packages/flags/src/client/api.ts | 24 ++ packages/flags/src/client/app.tsx | 6 +- packages/flags/src/client/code.tsx | 52 +++ packages/flags/src/client/conflict-banner.tsx | 39 +- packages/flags/src/client/editor.tsx | 405 ++++++++++-------- packages/flags/src/client/fields.tsx | 220 ++++++++++ packages/flags/src/client/model.test.ts | 165 +++++++ packages/flags/src/client/model.ts | 217 ++++++++++ .../flags/src/client/monaco/diff-view.tsx | 69 +++ .../flags/src/client/monaco/json-editor.tsx | 109 +++++ packages/flags/src/client/monaco/runtime.ts | 187 ++++++++ packages/flags/src/client/render.test.tsx | 375 +++++++++++++++- packages/flags/src/client/styles.css | 115 ++++- packages/flags/src/client/theme-context.ts | 12 + 17 files changed, 1792 insertions(+), 257 deletions(-) create mode 100644 packages/flags/src/client/code.tsx create mode 100644 packages/flags/src/client/fields.tsx create mode 100644 packages/flags/src/client/monaco/diff-view.tsx create mode 100644 packages/flags/src/client/monaco/json-editor.tsx create mode 100644 packages/flags/src/client/monaco/runtime.ts create mode 100644 packages/flags/src/client/theme-context.ts diff --git a/bun.lock b/bun.lock index 658138e428e..6a68ac3c5fd 100644 --- a/bun.lock +++ b/bun.lock @@ -1133,6 +1133,7 @@ "eslint": "^10.7.0", "jsdom": "^31.0.1", "lucide-react": "^1.14.0", + "monaco-editor": "^0.57.0", "react": "19.3.1", "react-dom": "19.3.1", "react-router": "8.4.0", diff --git a/packages/flags/README.md b/packages/flags/README.md index c8c44d19674..98d737f0839 100644 --- a/packages/flags/README.md +++ b/packages/flags/README.md @@ -103,8 +103,48 @@ document. While another deployment loads, the previous table stays on screen, dimmed and `aria-busy`, under the new deployment's header. The tab title names the open flag and deployment, e.g. `dares_enabled · scout/prod · Flags`. -"Review save" opens a dialog with the stored flag before and the draft after; -Save writes that revision. A conflicting write is left unchanged: a warning -above the form shows the other value beside the draft, with a button to load it. +### Editing modes + +The editor has a Form / JSON toggle over one draft. Switching modes never loses +an edit: the JSON text is rebuilt from the draft only when the form changed it, +so text that does not parse yet is still there when you switch back. + +- **Form** shows typed controls: a boolean flag's default and segments; a + variant's stored string in a number field (`number` encoding), a wrapping + text area (`json` encoding), or a text field (`string` encoding). +- **JSON** edits in Monaco. A boolean flag is edited as its whole object, with + `type` and `key` fixed by the schema. A `json`-encoded variant is edited as + its decoded value, pretty-printed (an array, not a one-line string), and + saved compactly with object defaults filled in. `number` and `string` + variants are edited as a JSON number or string literal. + +`json`-encoded variants open in JSON mode; everything else opens in Form mode. +A variant whose key is not in the value registry is shown as plain text with a +notice that the server rejects writes to unmanaged keys. + +Monaco is bundled locally with only its JSON language and loads, with its two +workers, the first time an editor or diff is shown. The flag table never loads +it. Its colours and monospace font come from the `console-ui` tokens of the +current theme. + +### Validation + +JSON mode validates as you type against a JSON Schema. For variants this is +`flag-value-schemas.generated.json` from `@shepherdjerred/feature-flags`. For +boolean flags it is the flag schema (`src/schema.ts`). Schema errors show as +squiggles with hover messages. The draft is also checked against the registry's +Zod schema, the same check the server runs. Its issues are listed under the +editor by JSON Pointer path. Review stays disabled while the JSON does not parse +or the value fails the registry. If the server still refuses a save with +`400 invalid flag values`, its issues are listed the same way until the draft +changes. + +### Saving + +"Review save" opens a dialog with a read-only Monaco diff of the stored value +against the draft: side by side when there is room, inline when narrow. +`json`-encoded variants are diffed as their decoded values. Save writes that +revision. A conflicting write is left unchanged: a warning above the form diffs +their flag against the draft, with a button to load theirs. `toolkit flags` is the command surface. See `packages/toolkit/README.md`. diff --git a/packages/flags/package.json b/packages/flags/package.json index 3cb20ede71e..f743fdf0daa 100644 --- a/packages/flags/package.json +++ b/packages/flags/package.json @@ -24,16 +24,17 @@ "@shepherdjerred/console-ui": "workspace:*", "@shepherdjerred/eslint-config": "workspace:*", "@shepherdjerred/ops-model": "workspace:*", - "@types/bun": "1.4.5", - "@typescript/native": "npm:typescript@7.0.2", - "@vitest/coverage-istanbul": "5.0.5", "@tanstack/react-query": "^5.101.2", + "@types/bun": "1.4.5", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", + "@typescript/native": "npm:typescript@7.0.2", "@vitejs/plugin-react": "^6.0.1", + "@vitest/coverage-istanbul": "5.0.5", "eslint": "^10.7.0", "jsdom": "^31.0.1", "lucide-react": "^1.14.0", + "monaco-editor": "^0.57.0", "react": "19.3.1", "react-dom": "19.3.1", "react-router": "8.4.0", diff --git a/packages/flags/src/client/api.ts b/packages/flags/src/client/api.ts index 46b754a7cec..39b67b7800a 100644 --- a/packages/flags/src/client/api.ts +++ b/packages/flags/src/client/api.ts @@ -7,6 +7,7 @@ import { } from "@tanstack/react-query"; import { z } from "zod"; import type { FlagValue } from "@shepherdjerred/feature-flags/evaluate.ts"; +import type { FlagValueKeyIssue } from "@shepherdjerred/feature-flags/flag-write-validation.ts"; import { FlagValueSchema } from "@shepherdjerred/flags/schema.ts"; const DeploymentSummarySchema = z.strictObject({ @@ -27,6 +28,14 @@ const ConflictSchema = z.strictObject({ flags: z.array(FlagValueSchema), }); +/** The 400 a write gets when a value fails its registry schema (see `README.md`). */ +const InvalidValuesSchema = z.strictObject({ + error: z.string(), + issues: z.array( + z.strictObject({ key: z.string(), path: z.string(), message: z.string() }), + ), +}); + export type DeploymentDocument = z.infer; export type ApplyResult = @@ -35,6 +44,11 @@ export type ApplyResult = readonly kind: "conflict"; readonly revision: number; readonly flags: readonly FlagValue[]; + } + | { + readonly kind: "invalid"; + readonly error: string; + readonly issues: readonly FlagValueKeyIssue[]; }; async function readJson(response: Response): Promise { @@ -131,6 +145,16 @@ export function useApplyFlag(catalog: string, stage: string) { flags: conflict.flags, }; } + if (response.status === 400) { + const invalid = InvalidValuesSchema.safeParse(body); + if (invalid.success) { + return { + kind: "invalid", + error: invalid.data.error, + issues: invalid.data.issues, + }; + } + } if (!response.ok) throw new Error(errorMessage(body, response.status)); const saved = z.strictObject({ revision: z.number().int() }).parse(body); return { kind: "saved", revision: saved.revision }; diff --git a/packages/flags/src/client/app.tsx b/packages/flags/src/client/app.tsx index dd0fcc1e305..820bfa893fa 100644 --- a/packages/flags/src/client/app.tsx +++ b/packages/flags/src/client/app.tsx @@ -25,6 +25,7 @@ import { type Route, } from "./model.ts"; import { DeploymentPicker, DeploymentSidebar } from "./sidebar.tsx"; +import { ThemeContext } from "./theme-context.ts"; /** The deployment and flag the URL names; undefined on pages outside a deployment. */ function useDeploymentRoute(): Route | undefined { @@ -218,5 +219,8 @@ const PAGES: RouteObject[] = [ /** Client-side routes: links and the picker navigate without reloading the page. */ export function App({ theme }: { theme: ThemeStore }) { - return useRoutes([{ element: , children: PAGES }]); + const page = useRoutes([ + { element: , children: PAGES }, + ]); + return {page}; } diff --git a/packages/flags/src/client/code.tsx b/packages/flags/src/client/code.tsx new file mode 100644 index 00000000000..d369bb01c7d --- /dev/null +++ b/packages/flags/src/client/code.tsx @@ -0,0 +1,52 @@ +import { lazy, Suspense } from "react"; + +export type JsonEditorProps = { + /** The text shown. Changing it from outside replaces the editor's text. */ + readonly value: string; + readonly onChange: (text: string) => void; + /** JSON Schema the text is validated against, as squiggles and hovers. */ + readonly schema: Record; + /** Unique per edited flag, e.g. `scout/prod/key`; names the Monaco model. */ + readonly modelPath: string; + readonly label: string; + /** Id of the element listing the draft's issues. */ + readonly describedBy?: string | undefined; + readonly invalid: boolean; +}; + +export type DiffViewProps = { + readonly original: string; + readonly modified: string; + /** Names both sides, e.g. `{ original: "Stored", modified: "Draft" }`. */ + readonly labels: { readonly original: string; readonly modified: string }; +}; + +// Monaco is several hundred kilobytes; these chunks load the first time an +// editor or diff is shown, never for the flag table. +const MonacoJsonEditor = lazy(() => import("./monaco/json-editor.tsx")); +const MonacoDiffView = lazy(() => import("./monaco/diff-view.tsx")); + +/** The text, unstyled by Monaco, while the editor chunk loads. */ +function Loading({ text }: { text: string }) { + return ( +
+      {text}
+    
+ ); +} + +export function JsonEditor(props: JsonEditorProps): React.JSX.Element { + return ( + }> + + + ); +} + +export function DiffView(props: DiffViewProps): React.JSX.Element { + return ( + }> + + + ); +} diff --git a/packages/flags/src/client/conflict-banner.tsx b/packages/flags/src/client/conflict-banner.tsx index bbe74d82041..21be320e622 100644 --- a/packages/flags/src/client/conflict-banner.tsx +++ b/packages/flags/src/client/conflict-banner.tsx @@ -1,7 +1,8 @@ import { TriangleAlertIcon } from "lucide-react"; import { Button } from "@shepherdjerred/console-ui"; import type { FlagValue } from "@shepherdjerred/feature-flags/evaluate.ts"; -import { flagText } from "./model.ts"; +import { DiffView } from "./code.tsx"; +import { reviewText } from "./model.ts"; export type ConflictBannerProps = { /** The revision another write landed at. */ @@ -12,7 +13,7 @@ export type ConflictBannerProps = { readonly onLoadTheirs: () => void; }; -/** Warns that a save was not applied and shows both versions side by side. */ +/** Warns that a save was not applied and diffs their flag against the draft. */ export function ConflictBanner({ revision, theirs, @@ -32,24 +33,22 @@ export function ConflictBanner({

Another write landed at revision {revision}. This save was not applied.

-
-
-

Their flag

-
-            {theirs === undefined
-              ? "This flag is gone from their document."
-              : flagText(theirs)}
-          
-
-
-

Your draft

-
{flagText(draft)}
-
-
- {theirs === undefined ? null : ( - + {theirs === undefined ? ( +

This flag is gone from their document.

+ ) : ( + <> +

+ Their flag (before) against your draft (after). +

+ + + )} ); diff --git a/packages/flags/src/client/editor.tsx b/packages/flags/src/client/editor.tsx index 79b7c726047..e9b94188feb 100644 --- a/packages/flags/src/client/editor.tsx +++ b/packages/flags/src/client/editor.tsx @@ -1,29 +1,54 @@ -import { useRef, useState, type SubmitEvent } from "react"; -import { ArrowLeftIcon, PlusIcon, Trash2Icon } from "lucide-react"; +import { useId, useRef, useState, type SubmitEvent } from "react"; +import { ArrowLeftIcon } from "lucide-react"; import { Link } from "react-router"; import { z } from "zod"; -import { Button, Chip, Field, IconButton } from "@shepherdjerred/console-ui"; -import type { - BooleanFlagValue, - FlagValue, - VariantFlagValue, -} from "@shepherdjerred/feature-flags/evaluate.ts"; +import { Button, Tabs } from "@shepherdjerred/console-ui"; +import type { FlagValue } from "@shepherdjerred/feature-flags/evaluate.ts"; +import type { VariantEncoding } from "@shepherdjerred/feature-flags/flag-value-spec.ts"; import { ConflictBanner } from "./conflict-banner.tsx"; +import { DiffView, JsonEditor } from "./code.tsx"; import { useApplyFlag, type DeploymentDocument } from "./api.ts"; +import { BooleanFields, VariantFields } from "./fields.tsx"; import { - addConstraint, - addSegment, + applyJsonText, + defaultEditMode, draftError, - flagText, - removeConstraint, - removeSegment, + issuePathLabel, + issuesForKey, + jsonSchemaFor, + jsonText, + reviewText, sameFlag, - setBooleanDefault, - setConstraintField, - setSegmentResult, - setVariantValue, + valueIssues, + valueKind, + type EditMode, + type EditorIssue, + type ValueKind, } from "./model.ts"; +const MODES = [ + { value: "form", label: "Form" }, + { value: "json", label: "JSON" }, +] as const; + +/** + * The JSON-mode text and what it says. `forDraft` is the draft the text + * describes: while it is still the draft, switching modes keeps the text + * (even unparseable text); once the form changes the draft, the text is + * rebuilt from it. + */ +type JsonState = { + readonly text: string; + readonly forDraft: FlagValue | undefined; + readonly issues: readonly EditorIssue[]; +}; + +/** The server's 400 issues for a submitted draft; shown until the draft changes. */ +type ServerIssues = { + readonly forDraft: FlagValue; + readonly issues: readonly EditorIssue[]; +}; + export function Editor({ catalog, stage, @@ -42,14 +67,27 @@ export function Editor({ const [draft, setDraft] = useState(stored); const [baseFlag, setBaseFlag] = useState(stored); const [revision, setRevision] = useState(document.revision); + const [mode, setMode] = useState(() => + stored === undefined ? "form" : defaultEditMode(stored), + ); + const [json, setJson] = useState(() => ({ + text: stored === undefined ? "" : jsonText(stored), + forDraft: stored, + issues: [], + })); + const [serverIssues, setServerIssues] = useState( + undefined, + ); const [error, setError] = useState(undefined); const [conflict, setConflict] = useState< | { readonly revision: number; readonly flag: FlagValue | undefined } | undefined >(undefined); const [saved, setSaved] = useState(false); + const [reviewing, setReviewing] = useState(false); const dialogRef = useRef(null); const saving = useRef(false); + const issuesId = useId(); const apply = useApplyFlag(catalog, stage); if (stored === undefined || draft === undefined || baseFlag === undefined) { @@ -59,9 +97,46 @@ export function Editor({ return

Stored flag {flagKey} changed type.

; } + const kind = valueKind(draft); + const textIssues = mode === "json" ? json.issues : []; + // While the JSON text does not parse, the draft is its last good value, so + // only the text's own issues apply. + const registryIssues = textIssues.length > 0 ? [] : valueIssues(draft); + const refused = serverIssues?.forDraft === draft ? serverIssues.issues : []; + const issues = [...textIssues, ...registryIssues, ...refused]; + const blocked = textIssues.length > 0 || registryIssues.length > 0; + const modelPath = [catalog, stage, flagKey] + .map((segment) => encodeURIComponent(segment)) + .join("/"); + + function edit(next: FlagValue) { + setDraft(next); + setSaved(false); + } + + function chooseMode(next: EditMode) { + if (draft === undefined) return; + if (next === "json" && json.forDraft !== draft) { + setJson({ text: jsonText(draft), forDraft: draft, issues: [] }); + } + setMode(next); + } + + function editJson(text: string) { + if (draft === undefined) return; + const result = applyJsonText(draft, text); + if (result.ok) { + edit(result.flag); + setJson({ text, forDraft: result.flag, issues: [] }); + } else { + setJson({ text, forDraft: draft, issues: result.issues }); + setSaved(false); + } + } + function review(event: SubmitEvent) { event.preventDefault(); - if (draft === undefined) return; + if (draft === undefined || blocked) return; const problem = draftError(draft); if (problem !== undefined) { setError(problem); @@ -73,7 +148,10 @@ export function Editor({ } setError(undefined); const dialog = dialogRef.current; - if (dialog !== null && !dialog.open) dialog.showModal(); + if (dialog !== null && !dialog.open) { + setReviewing(true); + dialog.showModal(); + } } function confirmSave() { @@ -101,7 +179,18 @@ export function Editor({ }); return; } + if (result.kind === "invalid") { + setSaved(false); + setServerIssues({ + forDraft: flag, + issues: issuesForKey(result.issues, flag.key), + }); + setError(`The server refused this value: ${result.error}`); + return; + } setConflict(undefined); + setServerIssues(undefined); + setError(undefined); setRevision(result.revision); setBaseFlag(flag); setSaved(true); @@ -117,12 +206,20 @@ export function Editor({ if (conflict?.flag === undefined) return; setDraft(conflict.flag); setBaseFlag(conflict.flag); + setJson({ + text: jsonText(conflict.flag), + forDraft: conflict.flag, + issues: [], + }); setRevision(conflict.revision); setConflict(undefined); + setServerIssues(undefined); setSaved(false); setError(undefined); } + const describedBy = issues.length === 0 ? undefined : issuesId; + return (
@@ -134,7 +231,7 @@ export function Editor({ {flagKey}

- {draft.type} flag · Revision {revision} + {kindLabel(kind)} · Revision {revision}

{conflict === undefined ? null : ( @@ -145,12 +242,46 @@ export function Editor({ onLoadTheirs={loadTheirs} /> )} + {kind.kind === "unmanaged" ? ( +

+ This key is not in the value registry, so its value is shown as plain + text. The server rejects writes to unmanaged keys. +

+ ) : null}
- {draft.type === "boolean" ? ( - +
+ +
+ {mode === "json" ? ( +
+ {jsonLabel(kind)} + +
+ ) : draft.type === "boolean" ? ( + ) : ( - + )} + {error === undefined ? null : (

{error} @@ -162,7 +293,12 @@ export function Editor({

) : null}
-
@@ -171,22 +307,34 @@ export function Editor({ ref={dialogRef} className="fl-dialog" aria-labelledby="save-title" + onClose={() => { + setReviewing(false); + }} >

Save {flagKey}

-
-
-

Before

-
{flagText(baseFlag)}
-
-
-

After

-
{flagText(draft)}
-
-
+

+ The value stored at revision {revision} (before) against your draft + (after). +

+ {reviewing ? ( + + ) : null}
- - -
- - ))} -
- -
- - - ); +const JSON_LABELS: Readonly> = { + json: "Value JSON", + number: "Value (JSON number)", + string: "Value (JSON string)", +}; + +/** Unmanaged variants are plain strings to the editor. */ +function encodingOf(kind: ValueKind): VariantEncoding { + return kind.kind === "managed" ? kind.encoding : "string"; +} + +function kindLabel(kind: ValueKind): string { + return kind.kind === "boolean" + ? "boolean flag" + : `variant flag · ${kind.kind === "managed" ? kind.encoding : "unmanaged"}`; } -function VariantFields({ - flag, - onChange, +function jsonLabel(kind: ValueKind): string { + return kind.kind === "boolean" ? "Flag JSON" : JSON_LABELS[encodingOf(kind)]; +} + +/** The draft's problems, one per path, kept live so screen readers hear changes. */ +function IssueList({ + id, + issues, }: { - flag: VariantFlagValue; - onChange: (flag: VariantFlagValue) => void; + id: string; + issues: readonly EditorIssue[]; }) { return ( - - {(control) => ( - { - onChange(setVariantValue(flag, event.target.value)); - }} - /> - )} - +
    + {issues.map((issue, index) => ( +
  • + {issuePathLabel(issue.path)} + {issue.message} +
  • + ))} +
); } diff --git a/packages/flags/src/client/fields.tsx b/packages/flags/src/client/fields.tsx new file mode 100644 index 00000000000..936e26747ca --- /dev/null +++ b/packages/flags/src/client/fields.tsx @@ -0,0 +1,220 @@ +import { PlusIcon, Trash2Icon } from "lucide-react"; +import { Button, Chip, Field, IconButton } from "@shepherdjerred/console-ui"; +import type { + BooleanFlagValue, + VariantFlagValue, +} from "@shepherdjerred/feature-flags/evaluate.ts"; +import { + addConstraint, + addSegment, + removeConstraint, + removeSegment, + setBooleanDefault, + setConstraintField, + setSegmentResult, + setVariantValue, + type ValueKind, +} from "./model.ts"; + +/* + * The Form mode's controls: a boolean flag's default and segments, and a + * variant's stored string in a control that fits its encoding. + */ + +export function BooleanFields({ + flag, + onChange, +}: { + flag: BooleanFlagValue; + onChange: (flag: BooleanFlagValue) => void; +}) { + return ( + <> +
+ Default + +
+
+ Segments + {flag.rollouts.length === 0 ? ( +

No segments.

+ ) : null} + {flag.rollouts.map((rollout, rolloutIndex) => ( +
+ Segment {rolloutIndex + 1} +

+ {rollout.constraints.map((constraint, constraintIndex) => ( + + ))} +

+ {rollout.constraints.map((constraint, constraintIndex) => ( +
+ + {(control) => ( + { + onChange( + setConstraintField(flag, { + rolloutIndex, + constraintIndex, + field: "property", + value: event.target.value, + }), + ); + }} + /> + )} + + + {(control) => ( + { + onChange( + setConstraintField(flag, { + rolloutIndex, + constraintIndex, + field: "value", + value: event.target.value, + }), + ); + }} + /> + )} + + { + onChange( + removeConstraint(flag, rolloutIndex, constraintIndex), + ); + }} + /> +
+ ))} + +
+ + +
+
+ ))} +
+ +
+
+ + ); +} + +/** + * The stored string in a typed control: a number field for `number` + * encodings, a wrapping text area for JSON text, a text field otherwise. + */ +export function VariantFields({ + flag, + kind, + onChange, + describedBy, + invalid, +}: { + flag: VariantFlagValue; + kind: ValueKind; + onChange: (flag: VariantFlagValue) => void; + describedBy: string | undefined; + invalid: boolean; +}) { + const encoding = kind.kind === "managed" ? kind.encoding : "string"; + const label = encoding === "json" ? "Value (stored JSON text)" : "Value"; + return ( + + {(control) => { + const props = { + ...control, + "aria-describedby": describedBy, + "aria-invalid": invalid ? true : undefined, + value: flag.value, + spellCheck: false, + }; + if (encoding === "json") { + return ( +