36 lines
2.3 KiB
TypeScript
36 lines
2.3 KiB
TypeScript
// Browser-only fixture. Real components, in-memory API, no production services.
|
|
import React, { useState } from "react";
|
|
import { createRoot } from "react-dom/client";
|
|
import Management from "../../src/components/Management";
|
|
import ImportDialog from "../../src/components/ImportDialog";
|
|
import { api } from "../../src/lib/api";
|
|
import { useI18n, setLang } from "../../src/lib/i18n";
|
|
import { defaultProductProfiles, validateProductProfiles } from "@bbbug/shared/product_profiles";
|
|
import "../../src/styles.css";
|
|
|
|
let saved = defaultProductProfiles();
|
|
let lastRequest: unknown = null;
|
|
api.adminProductProfiles = async () => structuredClone(saved);
|
|
api.productProfiles = async () => ({ ...structuredClone(saved), profiles: structuredClone(saved.profiles.filter((p) => p.enabled)) });
|
|
api.saveProductProfiles = async (config) => {
|
|
if (config.revision !== saved.revision) throw new Error("Configuration changed. Reload before saving.");
|
|
saved = { revision: saved.revision + 1, profiles: validateProductProfiles(config.profiles) };
|
|
return structuredClone(saved);
|
|
};
|
|
api.clustersList = async () => ({ clusters: ["default"] });
|
|
api.import = async (...args) => { lastRequest = args; return { added: [], skipped: [{ link: "local fixture", reason: JSON.stringify(args) }] }; };
|
|
api.createFeature = async (input) => { lastRequest = input; throw new Error(`Local fixture only: ${JSON.stringify(input)}`); };
|
|
setLang("zh");
|
|
function Fixture() {
|
|
const [open, setOpen] = useState(false);
|
|
const [request, setRequest] = useState<unknown>(null);
|
|
const { lang } = useI18n();
|
|
return <main style={{ maxWidth: 1120, padding: 24, margin: "0 auto" }}>
|
|
<header style={{ display: "flex", gap: 12, alignItems: "center", marginBottom: 20 }}><h2 style={{ marginRight: "auto" }}>Streamline</h2><span>Local UI fixture</span><button onClick={() => setLang(lang === "zh" ? "en" : "zh")}>中 / EN</button><button className="primary" onClick={() => setOpen(true)}>创建任务</button><button onClick={() => setRequest(lastRequest)}>检查请求</button></header>
|
|
<Management supers={[]} admins={[]} onSave={async () => {}} nodes={[]} initialTab="products" />
|
|
<ImportDialog open={open} onClose={() => setOpen(false)} />
|
|
{request != null && <pre>{JSON.stringify(request, null, 2)}</pre>}
|
|
</main>;
|
|
}
|
|
createRoot(document.getElementById("root")!).render(<Fixture />);
|