feat(web): collapsible parameter form and groups (#13)
The parameter form and each included notebook group collapse; the choice is remembered in the browser. Collapsed, the form lists only missing required values and values changed from their default as chips that open their field, and counts untouched defaults, so it stays one line.
This commit is contained in:
@@ -45,6 +45,7 @@ import { ChatPanel } from "./ChatPanel";
|
|||||||
import { parseRoute, routeHash } from "./route";
|
import { parseRoute, routeHash } from "./route";
|
||||||
import { recallValues, rememberValues } from "./paramMemory";
|
import { recallValues, rememberValues } from "./paramMemory";
|
||||||
import { Dialog } from "./ui";
|
import { Dialog } from "./ui";
|
||||||
|
import { readFlag, writeFlag } from "./uiPrefs";
|
||||||
const TerminalSlot = lazy(() =>
|
const TerminalSlot = lazy(() =>
|
||||||
import("./TerminalSlot").then((module) => ({ default: module.TerminalSlot })),
|
import("./TerminalSlot").then((module) => ({ default: module.TerminalSlot })),
|
||||||
);
|
);
|
||||||
@@ -88,6 +89,7 @@ export function App({ api }: { api: Api }) {
|
|||||||
const [edit, setEdit] = useState(false);
|
const [edit, setEdit] = useState(false);
|
||||||
const [terminal, setTerminal] = useState(false);
|
const [terminal, setTerminal] = useState(false);
|
||||||
const [chat, setChat] = useState(false);
|
const [chat, setChat] = useState(false);
|
||||||
|
const [paramsOpen, setParamsOpen] = useState(() => readFlag("params-open", true));
|
||||||
const [terminalOpened, setTerminalOpened] = useState(false);
|
const [terminalOpened, setTerminalOpened] = useState(false);
|
||||||
const [conflict, setConflict] = useState(false);
|
const [conflict, setConflict] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
@@ -583,13 +585,18 @@ export function App({ api }: { api: Api }) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{notebook && (
|
{notebook && (
|
||||||
<div className="notebook-layout">
|
<div className={`notebook-layout${paramsOpen ? "" : " params-collapsed"}`}>
|
||||||
<ParamsForm
|
<ParamsForm
|
||||||
notebook={notebook}
|
notebook={notebook}
|
||||||
values={resolved.values}
|
values={resolved.values}
|
||||||
errors={resolved.errors}
|
errors={resolved.errors}
|
||||||
hosts={hosts}
|
hosts={hosts}
|
||||||
groups={groups}
|
groups={groups}
|
||||||
|
open={paramsOpen}
|
||||||
|
onToggle={(next) => {
|
||||||
|
writeFlag("params-open", next);
|
||||||
|
setParamsOpen(next);
|
||||||
|
}}
|
||||||
onChange={(name, value) => changeValues({ ...values, [name]: value })}
|
onChange={(name, value) => changeValues({ ...values, [name]: value })}
|
||||||
onReset={() => changeValues({})}
|
onReset={() => changeValues({})}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+122
-31
@@ -1,5 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import type { HostInfo, Notebook, ParamDef, ParamValues } from "@shellbook/core";
|
import type { HostInfo, Notebook, ParamDef, ParamValues } from "@shellbook/core";
|
||||||
|
import { readFlag, writeFlag } from "./uiPrefs";
|
||||||
|
|
||||||
/** An included notebook (`::use`) whose parameters the form shows as a group. */
|
/** An included notebook (`::use`) whose parameters the form shows as a group. */
|
||||||
export interface ParamGroup {
|
export interface ParamGroup {
|
||||||
@@ -7,12 +8,16 @@ export interface ParamGroup {
|
|||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const groupFlag = (title: string) => `params-group:${title}`;
|
||||||
|
|
||||||
export function ParamsForm({
|
export function ParamsForm({
|
||||||
notebook,
|
notebook,
|
||||||
values,
|
values,
|
||||||
errors,
|
errors,
|
||||||
hosts,
|
hosts,
|
||||||
groups = [],
|
groups = [],
|
||||||
|
open = true,
|
||||||
|
onToggle,
|
||||||
onChange,
|
onChange,
|
||||||
onReset,
|
onReset,
|
||||||
}: {
|
}: {
|
||||||
@@ -22,14 +27,88 @@ export function ParamsForm({
|
|||||||
hosts: HostInfo[];
|
hosts: HostInfo[];
|
||||||
/** Active included notebooks; parameters of inactive ones are hidden. */
|
/** Active included notebooks; parameters of inactive ones are hidden. */
|
||||||
groups?: ParamGroup[];
|
groups?: ParamGroup[];
|
||||||
|
/** Collapsed, the form shows a one-line summary of the values instead of the fields. */
|
||||||
|
open?: boolean;
|
||||||
|
onToggle?(open: boolean): void;
|
||||||
onChange(name: string, value: string): void;
|
onChange(name: string, value: string): void;
|
||||||
/** Clears the values typed for this notebook. */
|
/** Clears the values typed for this notebook. */
|
||||||
onReset?(): void;
|
onReset?(): void;
|
||||||
}) {
|
}) {
|
||||||
const [open, setOpen] = useState(true);
|
// Group collapse choices are remembered per included notebook title.
|
||||||
|
const [groupOpen, setGroupOpen] = useState<Record<string, boolean>>({});
|
||||||
|
const isGroupOpen = (title: string) => groupOpen[title] ?? readFlag(groupFlag(title), true);
|
||||||
|
const toggleGroup = (title: string, next: boolean) => {
|
||||||
|
writeFlag(groupFlag(title), next);
|
||||||
|
setGroupOpen((current) => ({ ...current, [title]: next }));
|
||||||
|
};
|
||||||
|
// A summary chip opens its field and moves focus there once it is rendered.
|
||||||
|
const [focus, setFocus] = useState<string>();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!focus) return;
|
||||||
|
document.getElementById(`param-${focus}`)?.focus();
|
||||||
|
setFocus(undefined);
|
||||||
|
}, [focus]);
|
||||||
|
|
||||||
|
const top = notebook.params.filter((param) => !param.scope);
|
||||||
|
const grouped = groups
|
||||||
|
.map((group) => ({ group, params: notebook.params.filter((param) => param.scope === group.scope) }))
|
||||||
|
.filter((entry) => entry.params.length);
|
||||||
|
const shown = [...top, ...grouped.flatMap((entry) => entry.params)];
|
||||||
|
if (!shown.length) return null;
|
||||||
|
const missingOf = (params: ParamDef[]) =>
|
||||||
|
params.filter((param) => param.required && !values[param.name]).length;
|
||||||
|
const missing = missingOf(shown);
|
||||||
|
const labelOf = (param: ParamDef) =>
|
||||||
|
param.label ?? (param.scope ? param.name.slice(param.scope.length + 1) : param.name);
|
||||||
|
|
||||||
|
const reveal = (param: ParamDef) => {
|
||||||
|
if (!open) onToggle?.(true);
|
||||||
|
const group = grouped.find((entry) => entry.group.scope === param.scope);
|
||||||
|
if (group && !isGroupOpen(group.group.title)) toggleGroup(group.group.title, true);
|
||||||
|
setFocus(param.name);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* What needs attention: missing required values and values changed from their default,
|
||||||
|
* each a button that opens its field. Untouched defaults are only counted.
|
||||||
|
*/
|
||||||
|
const summary = (params: ParamDef[], expand: () => void) => {
|
||||||
|
const listed = params.filter((param) =>
|
||||||
|
values[param.name] ? values[param.name] !== param.default : param.required,
|
||||||
|
);
|
||||||
|
const defaults = params.filter((param) => values[param.name] && values[param.name] === param.default).length;
|
||||||
|
if (!listed.length && !defaults) return null;
|
||||||
|
return (
|
||||||
|
<span className="param-summary">
|
||||||
|
{listed.map((param) => {
|
||||||
|
const value = values[param.name];
|
||||||
|
const label = labelOf(param);
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={param.name}
|
||||||
|
type="button"
|
||||||
|
className={`param-chip${value ? "" : " pending"}${errors[param.name] && value ? " invalid" : ""}`}
|
||||||
|
title={`${label}: ${errors[param.name] ?? "edit"}`}
|
||||||
|
onClick={() => reveal(param)}
|
||||||
|
>
|
||||||
|
<span className="param-chip-label">{label}</span>
|
||||||
|
<span className="param-chip-value">
|
||||||
|
{!value ? "missing" : param.type === "secret" ? "••••" : value}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{defaults > 0 && (
|
||||||
|
<button type="button" className="link param-defaults" onClick={expand}>
|
||||||
|
{listed.length ? "+ " : ""}
|
||||||
|
{defaults} at default
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const field = (param: ParamDef) => {
|
const field = (param: ParamDef) => {
|
||||||
const id = `param-${param.name}`;
|
const id = `param-${param.name}`;
|
||||||
const local = param.scope ? param.name.slice(param.scope.length + 1) : param.name;
|
|
||||||
const common = {
|
const common = {
|
||||||
id,
|
id,
|
||||||
required: param.required,
|
required: param.required,
|
||||||
@@ -45,8 +124,8 @@ export function ParamsForm({
|
|||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<label key={param.name} htmlFor={id}>
|
<label key={param.name} htmlFor={id}>
|
||||||
<span id={`${id}-label`}>
|
<span id={`${id}-label`} title={labelOf(param)}>
|
||||||
{param.label ?? local}
|
{labelOf(param)}
|
||||||
{param.required && <b title="Required"> *</b>}
|
{param.required && <b title="Required"> *</b>}
|
||||||
</span>
|
</span>
|
||||||
{param.type === "host" || param.type === "choice" ? (
|
{param.type === "host" || param.type === "choice" ? (
|
||||||
@@ -76,47 +155,59 @@ export function ParamsForm({
|
|||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const shown = [
|
|
||||||
...notebook.params.filter((param) => !param.scope),
|
|
||||||
...groups.flatMap((group) => notebook.params.filter((param) => param.scope === group.scope)),
|
|
||||||
];
|
|
||||||
const missing = shown.filter((param) => param.required && !values[param.name]).length;
|
|
||||||
if (!shown.length) return null;
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
className="params"
|
className={`params${open ? "" : " collapsed"}`}
|
||||||
aria-label="Notebook parameters"
|
aria-label="Notebook parameters"
|
||||||
onSubmit={(e) => e.preventDefault()}
|
onSubmit={(e) => e.preventDefault()}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
<h2>Parameters</h2>
|
<h2>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="params-toggle"
|
||||||
|
aria-expanded={open}
|
||||||
|
title={open ? "Collapse parameters" : "Expand parameters"}
|
||||||
|
onClick={() => onToggle?.(!open)}
|
||||||
|
>
|
||||||
|
<span className="caret" aria-hidden="true">{open ? "▾" : "▸"}</span>
|
||||||
|
Parameters
|
||||||
|
</button>
|
||||||
|
</h2>
|
||||||
<small className={missing ? "pending" : "ok"}>
|
<small className={missing ? "pending" : "ok"}>
|
||||||
{missing ? `${missing} required missing` : "All required set"}
|
{missing ? `${missing} required missing` : "All required set"}
|
||||||
</small>
|
</small>
|
||||||
|
{!open && summary(shown, () => onToggle?.(true))}
|
||||||
{onReset && open && (
|
{onReset && open && (
|
||||||
<button type="button" className="link" onClick={onReset}>
|
<button type="button" className="link" onClick={onReset}>
|
||||||
Reset
|
Reset
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="link"
|
|
||||||
aria-expanded={open}
|
|
||||||
onClick={() => setOpen(!open)}
|
|
||||||
>
|
|
||||||
{open ? "Hide" : "Show"}
|
|
||||||
</button>
|
|
||||||
</header>
|
</header>
|
||||||
{open && notebook.params.filter((param) => !param.scope).map(field)}
|
{open && top.map(field)}
|
||||||
{open && groups.map((group) => {
|
{open &&
|
||||||
const params = notebook.params.filter((param) => param.scope === group.scope);
|
grouped.map(({ group, params }) => {
|
||||||
return params.length ? (
|
const expanded = isGroupOpen(group.title);
|
||||||
<fieldset key={group.scope}>
|
const groupMissing = missingOf(params);
|
||||||
<legend>{group.title}</legend>
|
return (
|
||||||
{params.map(field)}
|
<fieldset key={group.scope} className={expanded ? "" : "collapsed"} aria-label={group.title}>
|
||||||
</fieldset>
|
<legend>
|
||||||
) : null;
|
<button
|
||||||
})}
|
type="button"
|
||||||
|
className="params-toggle"
|
||||||
|
aria-expanded={expanded}
|
||||||
|
onClick={() => toggleGroup(group.title, !expanded)}
|
||||||
|
>
|
||||||
|
<span className="caret" aria-hidden="true">{expanded ? "▾" : "▸"}</span>
|
||||||
|
{group.title}
|
||||||
|
{groupMissing > 0 && <small className="pending"> · {groupMissing} missing</small>}
|
||||||
|
</button>
|
||||||
|
</legend>
|
||||||
|
{expanded ? params.map(field) : summary(params, () => toggleGroup(group.title, true))}
|
||||||
|
</fieldset>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+97
-9
@@ -492,8 +492,31 @@ nav[aria-label="Main navigation"] button[aria-current="page"] {
|
|||||||
}
|
}
|
||||||
.params > header {
|
.params > header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: baseline;
|
align-items: center;
|
||||||
gap: 10px;
|
flex-wrap: wrap;
|
||||||
|
gap: 6px 10px;
|
||||||
|
}
|
||||||
|
.params > header > .link {
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
.params-toggle {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
padding: 2px 0;
|
||||||
|
color: var(--text);
|
||||||
|
font: inherit;
|
||||||
|
letter-spacing: inherit;
|
||||||
|
text-transform: inherit;
|
||||||
|
}
|
||||||
|
.params-toggle:hover {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
.params-toggle .caret {
|
||||||
|
width: 10px;
|
||||||
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
.params > header h2 {
|
.params > header h2 {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
@@ -501,13 +524,69 @@ nav[aria-label="Main navigation"] button[aria-current="page"] {
|
|||||||
letter-spacing: 0.6px;
|
letter-spacing: 0.6px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
.params > header small {
|
.params > header > small {
|
||||||
flex: 1;
|
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
.params > header small.pending {
|
.params small.pending {
|
||||||
color: var(--warn);
|
color: var(--warn);
|
||||||
}
|
}
|
||||||
|
.params.collapsed {
|
||||||
|
padding-top: 8px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
/* Collapsed: a one-line summary of the values, each opening its field. */
|
||||||
|
.param-summary {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.params fieldset > .param-summary {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
.param-chip {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 6px;
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 2px 9px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--code);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.param-chip:hover {
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
.param-chip-label {
|
||||||
|
color: var(--muted);
|
||||||
|
max-width: 16ch;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.param-chip-value {
|
||||||
|
font-family: "Cascadia Code", Consolas, ui-monospace, monospace;
|
||||||
|
max-width: 22ch;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.param-chip.pending {
|
||||||
|
border-color: var(--warn);
|
||||||
|
}
|
||||||
|
.param-chip.pending .param-chip-value {
|
||||||
|
color: var(--warn);
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
.param-chip.invalid {
|
||||||
|
border-color: var(--danger);
|
||||||
|
}
|
||||||
|
.param-defaults {
|
||||||
|
align-self: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
.params label {
|
.params label {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -517,6 +596,9 @@ nav[aria-label="Main navigation"] button[aria-current="page"] {
|
|||||||
}
|
}
|
||||||
.params label > span {
|
.params label > span {
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
.params b {
|
.params b {
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
@@ -530,22 +612,28 @@ nav[aria-label="Main navigation"] button[aria-current="page"] {
|
|||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
padding: 6px 12px 12px;
|
padding: 6px 12px 12px;
|
||||||
}
|
}
|
||||||
|
.params fieldset.collapsed {
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
.params legend {
|
.params legend {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
}
|
}
|
||||||
|
.params legend small {
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
@container (min-width: 1000px) {
|
@container (min-width: 1000px) {
|
||||||
.notebook-layout {
|
.notebook-layout:not(.params-collapsed) {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(0, 1fr) 300px;
|
grid-template-columns: minmax(0, 1fr) 300px;
|
||||||
align-items: start;
|
align-items: start;
|
||||||
}
|
}
|
||||||
.notebook-layout > .notebook {
|
.notebook-layout:not(.params-collapsed) > .notebook {
|
||||||
grid-column: 1;
|
grid-column: 1;
|
||||||
grid-row: 1;
|
grid-row: 1;
|
||||||
}
|
}
|
||||||
.notebook-layout > .params {
|
.notebook-layout:not(.params-collapsed) > .params {
|
||||||
grid-column: 2;
|
grid-column: 2;
|
||||||
grid-row: 1;
|
grid-row: 1;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
@@ -557,7 +645,7 @@ nav[aria-label="Main navigation"] button[aria-current="page"] {
|
|||||||
border-left: 1px solid var(--line);
|
border-left: 1px solid var(--line);
|
||||||
min-height: calc(100vh - var(--topbar));
|
min-height: calc(100vh - var(--topbar));
|
||||||
}
|
}
|
||||||
.notebook-layout > .params fieldset {
|
.notebook-layout:not(.params-collapsed) > .params fieldset {
|
||||||
grid-template-columns: minmax(0, 1fr);
|
grid-template-columns: minmax(0, 1fr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,25 @@ it("adds the created container to Hosts and feeds it into the parent's steps", a
|
|||||||
expect(screen.getByRole("button", { name: "Run all checks" })).toBeEnabled();
|
expect(screen.getByRole("button", { name: "Run all checks" })).toBeEnabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("collapses an included group to a remembered summary whose chips open the field", async () => {
|
||||||
|
const { api } = harness();
|
||||||
|
const view = render(<App api={api} />);
|
||||||
|
fireEvent.change(await screen.findByLabelText("target"), { target: { value: "lxc" } });
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: "LXC container (ct) · 1 missing", expanded: true }));
|
||||||
|
const group = screen.getByRole("group", { name: "LXC container (ct)" });
|
||||||
|
expect(within(group).queryByLabelText("proxmox *")).not.toBeInTheDocument();
|
||||||
|
// Untouched defaults are only counted; what needs attention is listed.
|
||||||
|
expect(within(group).queryByRole("button", { name: /hostname/ })).not.toBeInTheDocument();
|
||||||
|
expect(within(group).getByRole("button", { name: "+ 1 at default" })).toBeInTheDocument();
|
||||||
|
view.unmount();
|
||||||
|
render(<App api={harness().api} />);
|
||||||
|
fireEvent.change(await screen.findByLabelText("target"), { target: { value: "lxc" } });
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: /proxmox.*missing/ }));
|
||||||
|
await waitFor(() => expect(screen.getByLabelText("proxmox *")).toHaveFocus());
|
||||||
|
// The rest of the form was never collapsed.
|
||||||
|
expect(screen.getByLabelText("target")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("reloads when an included notebook changes", async () => {
|
it("reloads when an included notebook changes", async () => {
|
||||||
const { api, emit } = harness();
|
const { api, emit } = harness();
|
||||||
render(<App api={api} />);
|
render(<App api={api} />);
|
||||||
|
|||||||
@@ -102,6 +102,21 @@ it("opens the notebook named in the URL, keeps typed values across reloads and s
|
|||||||
await waitFor(() => expect(location.hash).toBe("#/hosts"));
|
await waitFor(() => expect(location.hash).toBe("#/hosts"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("collapses the parameter form to a remembered summary whose chips open their field", async () => {
|
||||||
|
const view = render(<App api={api()} />);
|
||||||
|
fireEvent.change(await screen.findByLabelText("Target server *"), { target: { value: "staging" } });
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: "Parameters", expanded: true }));
|
||||||
|
expect(screen.queryByLabelText("Target server *")).not.toBeInTheDocument();
|
||||||
|
expect(screen.getByRole("button", { name: /Target server.*staging/ })).toBeInTheDocument();
|
||||||
|
view.unmount();
|
||||||
|
render(<App api={api()} />);
|
||||||
|
const chip = await screen.findByRole("button", { name: /Target server.*staging/ });
|
||||||
|
expect(screen.getByRole("button", { name: "Parameters", expanded: false })).toBeInTheDocument();
|
||||||
|
fireEvent.click(chip);
|
||||||
|
await waitFor(() => expect(screen.getByLabelText("Target server *")).toHaveFocus());
|
||||||
|
expect(screen.getByRole("button", { name: "Parameters", expanded: true })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("saves the draft with Ctrl+S", async () => {
|
it("saves the draft with Ctrl+S", async () => {
|
||||||
const live = api();
|
const live = api();
|
||||||
render(<App api={live} />);
|
render(<App api={live} />);
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Per-browser layout preferences (collapsed panels and the like). Never holds data that
|
||||||
|
* must persist reliably; storage may be missing or blocked, which falls back to defaults.
|
||||||
|
*/
|
||||||
|
const key = (name: string) => `shellbook:ui:${name}`;
|
||||||
|
|
||||||
|
export function readFlag(name: string, fallback: boolean): boolean {
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem(key(name));
|
||||||
|
return stored === null ? fallback : stored === "1";
|
||||||
|
} catch {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeFlag(name: string, value: boolean): void {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(key(name), value ? "1" : "0");
|
||||||
|
} catch {
|
||||||
|
// Unavailable storage only means the choice lasts for this page.
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user