mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-12-01 00:27:17 +00:00
## Summary Improves the web UI's React Doctor audit score by separating reusable helpers from React component modules, tightening effect/state ownership, and extracting real component boundaries in the install wizard, stage activity view, run-files diff browser, RunDetail route, and Runs workspace. The branch removes the previously deferred RunDetail and Runs giant-component diagnostics without changing RunDetail UX, route contracts, action ordering, or Runs workspace behavior. | Metric | Main baseline | Initial PR | Current PR | |--------|---------------|------------|------------| | React Doctor score | 63 | 71 | 99 | | React Doctor errors | 123 | 0 | 0 | | React Doctor warnings | 241 | 163 | 3 | | React Doctor diagnostics | 364 | 163 | 3 | ## Changes - Moves exported helper logic out of component files so Fast Refresh/component-export rules no longer dominate the audit. - Adds a targeted React Doctor config exception for React Router route modules, where non-component exports like route metadata are intentional. - Refactors low-risk state/effect patterns: keyed interview question state, reducer-backed editable run title state, event-owned preview opening, route-keyed insights editor initialization, refresh timer ownership, and selection/derived list cleanup. - Reworks `InstallApp` around an install reducer, a controller hook for install lifecycle state, and focused wizard step components for LLM, server, object-store, sandbox, and GitHub setup. - Moves `RunStages` selected-stage activity into a keyed boundary for panel/debug detail state while preserving stage activity filters across navigation. - Extracts the `RunFiles` loaded diff-browser view from route/query coordination so the route owns data/URL state and the loaded view owns rendering. - Splits `RunDetail` into route-local header, actions, tab shell, docked controls, model, and lifecycle-toast modules; the actions menu now uses grouped descriptors instead of a large boolean/callback prop matrix. - Extracts Runs workspace preference ownership into `useRunsWorkspacePreferences` and moves toolbar rendering into `RunsToolbar`, leaving the route focused on data, DnD state, filtering, and view selection. - Guards `InsightsEditor` query execution with a latest-run id and timeout cleanup so stale or unmounted mock query runs cannot overwrite newer results. - Adds regression coverage for archived-run deletion from RunDetail and stale-result handling in InsightsEditor. - Improves semantic/accessibility coverage with labeled controls, native meter/section semantics, decorative status dots, and clearer unavailable copy. - Removes dead UI code and applies local suppressions only where the rule is a documented false positive or an intentional imperative integration boundary. ## Remaining React Doctor warnings Current score is 99 with 0 errors and 3 warnings. The remaining warnings are intentionally left for separate judgment rather than mechanical churn: - `prefer-useReducer` (3): `AutomationsNew`, `InsightsEditor`, and `CreateSecretForm` need reducers only if they encode real coupled transitions, not simple field setters. ## Verification - `cd apps/fabro-web && bun test app/routes/run-detail.test.ts` -> `22 pass`, `0 fail` - `cd apps/fabro-web && bun test app/routes/insights-editor.test.tsx app/routes/runs.preferences.test.tsx` -> `7 pass`, `0 fail` - `cd apps/fabro-web && bun run typecheck` - `cd apps/fabro-web && bun test --isolate` -> `490 pass`, `0 fail` - `cd apps/fabro-web && bunx react-doctor@latest --full --json > /tmp/fabro-react-doctor-runs-insights.json` -> score `99`, `0` errors, `3` warnings - Earlier branch verification also included `cd apps/fabro-web && bun run build` - `git diff --check` --- [](https://github.com/EveryInc/compound-engineering-plugin) 🤖 Generated with GPT-5 (context not reported, default reasoning) via [Codex](https://openai.com/codex)
247 lines
7.1 KiB
TypeScript
247 lines
7.1 KiB
TypeScript
import { useState, type ReactNode } from "react";
|
|
import { Link, useNavigate, useSearchParams } from "react-router";
|
|
import { useSWRConfig } from "swr";
|
|
import { ChevronRightIcon, ChevronDownIcon } from "@heroicons/react/20/solid";
|
|
import { SecretType } from "@qltysh/fabro-api-client";
|
|
|
|
import { ApiError, apiData, secretsApi } from "../lib/api-client";
|
|
import { queryKeys } from "../lib/query-keys";
|
|
import { Panel, Row } from "../components/settings-panel";
|
|
import {
|
|
ErrorMessage,
|
|
INPUT_CLASS,
|
|
PRIMARY_BUTTON_CLASS,
|
|
SECONDARY_BUTTON_CLASS,
|
|
} from "../components/ui";
|
|
import { useToast } from "../components/toast";
|
|
|
|
export function meta() {
|
|
return [{ title: "New secret — Fabro" }];
|
|
}
|
|
|
|
// The create form only offers Token and File. OAuth secrets are written by
|
|
// provider sign-in flows, never typed by hand.
|
|
function isFormType(
|
|
value: string,
|
|
): value is typeof SecretType.TOKEN | typeof SecretType.FILE {
|
|
return value === SecretType.TOKEN || value === SecretType.FILE;
|
|
}
|
|
|
|
export default function SettingsSecretsNew() {
|
|
return (
|
|
<div className="space-y-6">
|
|
<PageHeader />
|
|
<CreateSecretForm />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PageHeader() {
|
|
return (
|
|
<nav className="flex items-center gap-1 text-sm text-fg-muted">
|
|
<Link to="/settings/secrets" className="text-fg-3 hover:text-fg">
|
|
Secrets
|
|
</Link>
|
|
<ChevronRightIcon className="size-3" aria-hidden="true" />
|
|
<span>New secret</span>
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
function CreateSecretForm() {
|
|
const navigate = useNavigate();
|
|
const [searchParams] = useSearchParams();
|
|
const { mutate } = useSWRConfig();
|
|
const toast = useToast();
|
|
const [type, setType] = useState<typeof SecretType.TOKEN | typeof SecretType.FILE>(
|
|
SecretType.TOKEN,
|
|
);
|
|
const [name, setName] = useState(() => searchParams.get("name") ?? "");
|
|
const [value, setValue] = useState("");
|
|
const [description, setDescription] = useState("");
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const isFile = type === SecretType.FILE;
|
|
const nameLabel = isFile ? "Destination path" : "Name";
|
|
const nameHelp = isFile
|
|
? "Absolute path where the file is written inside the run sandbox."
|
|
: "Environment variable name exposed to runs (letters, digits, underscores).";
|
|
const namePlaceholder = isFile ? "/home/fabro/.netrc" : "OPENAI_API_KEY";
|
|
const canSubmit = name.trim() !== "" && value !== "" && !submitting;
|
|
|
|
async function onSubmit(event: React.FormEvent) {
|
|
event.preventDefault();
|
|
if (!canSubmit) return;
|
|
setSubmitting(true);
|
|
setError(null);
|
|
const trimmedName = name.trim();
|
|
try {
|
|
await apiData(() =>
|
|
secretsApi.createSecret({
|
|
name: trimmedName,
|
|
value,
|
|
type,
|
|
description: description.trim() || undefined,
|
|
}),
|
|
);
|
|
await mutate(queryKeys.secrets.list());
|
|
toast.push({ message: `Secret “${trimmedName}” saved.` });
|
|
navigate("/settings/secrets");
|
|
} catch (cause) {
|
|
setError(
|
|
cause instanceof ApiError && cause.message
|
|
? cause.message
|
|
: "Couldn't save the secret. Please try again.",
|
|
);
|
|
setSubmitting(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={onSubmit} className="space-y-6">
|
|
<Panel title="Secret">
|
|
<Row title={<Label required>Type</Label>} help="Tokens are exposed as environment variables; files are written to a path inside the sandbox.">
|
|
<SelectInput
|
|
name="type"
|
|
value={type}
|
|
onChange={(next) => {
|
|
if (isFormType(next)) setType(next);
|
|
}}
|
|
options={[
|
|
{ value: SecretType.TOKEN, label: "Token (environment variable)" },
|
|
{ value: SecretType.FILE, label: "File" },
|
|
]}
|
|
/>
|
|
</Row>
|
|
<Row title={<Label required>{nameLabel}</Label>} help={nameHelp}>
|
|
<input
|
|
type="text"
|
|
name="name"
|
|
aria-label={nameLabel}
|
|
value={name}
|
|
onChange={(event) => setName(event.target.value)}
|
|
placeholder={namePlaceholder}
|
|
autoComplete="off"
|
|
spellCheck={false}
|
|
className={`${INPUT_CLASS} font-mono`}
|
|
/>
|
|
</Row>
|
|
<Row
|
|
title={<Label required>Value</Label>}
|
|
help="Stored as-is and never shown again. Replace or delete it later if it needs to change."
|
|
>
|
|
<textarea
|
|
name="value"
|
|
aria-label="Secret value"
|
|
value={value}
|
|
onChange={(event) => setValue(event.target.value)}
|
|
rows={isFile ? 6 : 2}
|
|
autoComplete="off"
|
|
spellCheck={false}
|
|
className={`${INPUT_CLASS} resize-y font-mono`}
|
|
/>
|
|
</Row>
|
|
<Row title={<Label optional>Description</Label>} help="Helps operators recognize what this secret is for.">
|
|
<input
|
|
type="text"
|
|
name="description"
|
|
aria-label="Secret description"
|
|
value={description}
|
|
onChange={(event) => setDescription(event.target.value)}
|
|
className={INPUT_CLASS}
|
|
/>
|
|
</Row>
|
|
</Panel>
|
|
|
|
{error ? <ErrorMessage message={error} /> : null}
|
|
|
|
<FormFooter
|
|
submitting={submitting}
|
|
canSubmit={canSubmit}
|
|
onCancel={() => navigate("/settings/secrets")}
|
|
/>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function Label({
|
|
children,
|
|
required,
|
|
optional,
|
|
}: {
|
|
children: ReactNode;
|
|
required?: boolean;
|
|
optional?: boolean;
|
|
}) {
|
|
return (
|
|
<span className="inline-flex items-baseline gap-1.5">
|
|
<span>{children}</span>
|
|
{required ? (
|
|
<span aria-label="required" className="text-coral">
|
|
*
|
|
</span>
|
|
) : null}
|
|
{optional ? <span className="text-xs font-normal text-fg-muted">Optional</span> : null}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function SelectInput({
|
|
name,
|
|
value,
|
|
onChange,
|
|
options,
|
|
}: {
|
|
name: string;
|
|
value: string;
|
|
onChange: (next: string) => void;
|
|
options: ReadonlyArray<{ value: string; label: string }>;
|
|
}) {
|
|
return (
|
|
<div className="relative">
|
|
<select
|
|
name={name}
|
|
value={value}
|
|
onChange={(e) => onChange(e.target.value)}
|
|
className={`${INPUT_CLASS} appearance-none pr-9`}
|
|
>
|
|
{options.map((option) => (
|
|
<option key={option.value} value={option.value}>
|
|
{option.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<ChevronDownIcon
|
|
className="pointer-events-none absolute right-3 top-1/2 size-4 -translate-y-1/2 text-fg-muted"
|
|
aria-hidden="true"
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function FormFooter({
|
|
submitting,
|
|
canSubmit,
|
|
onCancel,
|
|
}: {
|
|
submitting: boolean;
|
|
canSubmit: boolean;
|
|
onCancel: () => void;
|
|
}) {
|
|
return (
|
|
<div className="flex items-center justify-end gap-3 pt-2">
|
|
<button
|
|
type="button"
|
|
onClick={onCancel}
|
|
disabled={submitting}
|
|
className={SECONDARY_BUTTON_CLASS}
|
|
>
|
|
Cancel
|
|
</button>
|
|
<button type="submit" disabled={!canSubmit} className={PRIMARY_BUTTON_CLASS}>
|
|
{submitting ? "Saving…" : "Save secret"}
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|