120 lines
3.4 KiB
TypeScript
120 lines
3.4 KiB
TypeScript
import { useMemo } from "react";
|
|
import { createMemoryRouter, Outlet, RouterProvider } from "react-router";
|
|
|
|
import CommandPaletteDialog from "./CommandPaletteDialog";
|
|
|
|
const rootData = {
|
|
csrf: "visual-csrf",
|
|
appConfiguration: { app: { features: {} } },
|
|
};
|
|
|
|
const appData = {
|
|
currentTenant: { id: "tenant-1", slug: "acme", name: "HiveGrid Demo" },
|
|
permissions: ["search.use", "crm.read_all", "projects.read_all"],
|
|
user: { id: "user-1", email: "visual@example.test", firstName: "Visual", lastName: "Fixture" },
|
|
myTenants: [],
|
|
allRoles: [],
|
|
myGroups: [],
|
|
isSuperUser: false,
|
|
isSuperAdmin: false,
|
|
onboardingSession: null,
|
|
};
|
|
|
|
/** Deterministic real-component fixture for the R-P11a interim pixel baseline. */
|
|
export function SpotlightSearchVisualFixture() {
|
|
const router = useMemo(
|
|
() =>
|
|
createMemoryRouter(
|
|
[
|
|
{
|
|
id: "root",
|
|
path: "/",
|
|
loader: () => rootData,
|
|
element: <Outlet />,
|
|
children: [
|
|
{
|
|
id: "routes/app.$tenant",
|
|
path: ":tenant",
|
|
loader: () => appData,
|
|
element: <Outlet />,
|
|
children: [
|
|
{
|
|
index: true,
|
|
element: <CommandPaletteDialog actions={[]} layout="app" open setOpen={() => undefined} />,
|
|
},
|
|
{
|
|
path: "search/api",
|
|
loader: ({ request }) => buildSearchResponse(request),
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
{ initialEntries: ["/acme"] }
|
|
),
|
|
[]
|
|
);
|
|
|
|
return <RouterProvider router={router} />;
|
|
}
|
|
|
|
function buildSearchResponse(request: Request) {
|
|
const url = new URL(request.url);
|
|
const query = url.searchParams.get("q")?.trim() ?? "";
|
|
const requestedEntityTypes = url.searchParams.getAll("type");
|
|
const limit = Number(url.searchParams.get("limit") ?? 20);
|
|
const requestId = url.searchParams.get("requestId");
|
|
|
|
return {
|
|
query,
|
|
requestedEntityTypes,
|
|
requestId,
|
|
requestKey: `${encodeURIComponent(query)}|${requestedEntityTypes.join(",") || "*"}|${limit}`,
|
|
results: query
|
|
? [
|
|
{
|
|
id: "contact-1",
|
|
entityType: "contact",
|
|
title: "Solaris GmbH",
|
|
subtitle: "info@solaris.test",
|
|
href: "/acme/contacts/contact-1",
|
|
permissionSubject: "crm.read_all",
|
|
updatedAt: null,
|
|
},
|
|
{
|
|
id: "project-1",
|
|
entityType: "project",
|
|
title: "Solardach Musterstraße",
|
|
subtitle: "P-100",
|
|
href: "/acme/projects/project-1",
|
|
permissionSubject: "projects.read_all",
|
|
updatedAt: null,
|
|
},
|
|
]
|
|
: [],
|
|
recentSearches: query
|
|
? []
|
|
: [
|
|
{
|
|
id: "recent-1",
|
|
queryText: "Wärmepumpe",
|
|
entityTypes: ["project", "task"],
|
|
resultCount: 4,
|
|
createdAt: "2026-07-12T08:00:00.000Z",
|
|
},
|
|
],
|
|
hiddenEntityTypes: ["lead", "file", "task", "user"],
|
|
latencyHint: "Suchindex-Aktualisierungen können bis zu 10 Sekunden dauern.",
|
|
} satisfies {
|
|
query: string;
|
|
requestedEntityTypes: string[];
|
|
requestId: string | null;
|
|
requestKey: string;
|
|
results: unknown[];
|
|
recentSearches: unknown[];
|
|
hiddenEntityTypes: string[];
|
|
latencyHint: string;
|
|
};
|
|
}
|