feat(web): add shell-first runbook UI and mock demo (#2)
Add notebook parameters, literal highlighted scripts, copy helpers, streamed runs, host-key confirmation, artifacts, conditional notes, login and optimistic Markdown editing. Keep the temporary core renderer isolated to mock mode. Use React and Vite for the UI, react-markdown for safe Markdown rendering, highlight.js for shell syntax, and CodeMirror 6 for Markdown editing. Add Testing Library, jsdom and Vitest for component and event-state coverage. Validate pnpm install, root typecheck and test (29 web tests, 1 server test), plus normal and mock web builds. Core contracts remain unchanged; real backend execution awaits the parallel core/server implementations.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import type { HostInfo, Notebook, ParamValues } from "@shellbook/core";
|
||||
|
||||
export function ParamsForm({
|
||||
notebook,
|
||||
values,
|
||||
errors,
|
||||
hosts,
|
||||
onChange,
|
||||
}: {
|
||||
notebook: Notebook;
|
||||
values: ParamValues;
|
||||
errors: Record<string, string>;
|
||||
hosts: HostInfo[];
|
||||
onChange(name: string, value: string): void;
|
||||
}) {
|
||||
return (
|
||||
<form
|
||||
className="params"
|
||||
aria-label="Notebook parameters"
|
||||
onSubmit={(e) => e.preventDefault()}
|
||||
>
|
||||
{notebook.params.map((param) => {
|
||||
const id = `param-${param.name}`;
|
||||
const common = {
|
||||
id,
|
||||
required: param.required,
|
||||
value: values[param.name] ?? "",
|
||||
"aria-labelledby": `${id}-label`,
|
||||
"aria-invalid": !!errors[param.name],
|
||||
"aria-describedby": errors[param.name] ? `${id}-error` : undefined,
|
||||
onChange: (
|
||||
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
||||
) => onChange(param.name, e.target.value),
|
||||
};
|
||||
return (
|
||||
<label key={param.name} htmlFor={id}>
|
||||
<span id={`${id}-label`}>
|
||||
{param.label ?? param.name}
|
||||
{param.required && <b title="Required"> *</b>}
|
||||
</span>
|
||||
{param.type === "host" || param.type === "choice" ? (
|
||||
<select {...common}>
|
||||
<option value="">Select…</option>
|
||||
{(param.type === "host"
|
||||
? hosts.map((h) => h.name)
|
||||
: (param.options ?? [])
|
||||
).map((option) => (
|
||||
<option key={option}>{option}</option>
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
<input
|
||||
{...common}
|
||||
type={param.type === "secret" ? "password" : "text"}
|
||||
autoComplete={param.type === "secret" ? "new-password" : "off"}
|
||||
spellCheck={false}
|
||||
/>
|
||||
)}
|
||||
{errors[param.name] && (
|
||||
<small id={`${id}-error`} className="error">
|
||||
{errors[param.name]}
|
||||
</small>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user