feat(housekeeping): compose operations workspace
This commit is contained in:
1 parent
5574e601bb
commit
85ad0452d3
22 files changed
+1240
-87
No files matched your search
@@ -44,6 +44,7 @@ export default async function HousekeepingPreviewRoutePage({
|
||||
return handler.render({
|
||||
context,
|
||||
match,
|
||||
surface: "preview",
|
||||
...(searchParams ? { searchParams: await searchParams } : {}),
|
||||
});
|
||||
}
|
||||
+92
-13
@@ -1,27 +1,106 @@
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { satisfiesCapability } from "@/features/housekeeping/foundation/capability-context";
|
||||
import { buildHousekeepingNavigation } from "@/features/housekeeping/foundation/navigation";
|
||||
import { createHousekeepingRegistry } from "@/features/housekeeping/foundation/registry";
|
||||
import { toHousekeepingHref } from "@/features/housekeeping/foundation/routing/href";
|
||||
import { matchHousekeepingRoute } from "@/features/housekeeping/foundation/routing/match-route";
|
||||
import { getHousekeepingCapabilityContext } from "@/features/housekeeping/foundation/server-capability-context";
|
||||
import { HousekeepingShell } from "@/features/housekeeping/foundation/shell/housekeeping-shell";
|
||||
import { HOUSEKEEPING_MANIFESTS } from "@/features/housekeeping/manifests";
|
||||
import { HOUSEKEEPING_ROUTE_HANDLERS } from "@/features/housekeeping/route-handlers";
|
||||
|
||||
const MESSAGE_PREFIX = "pages.housekeeping.";
|
||||
|
||||
function namespaceKey(key: string): string {
|
||||
if (!key.startsWith(MESSAGE_PREFIX)) {
|
||||
throw new Error(`invalid housekeeping message key: ${key}`);
|
||||
}
|
||||
return key.slice(MESSAGE_PREFIX.length);
|
||||
}
|
||||
|
||||
export default async function HousekeepingPreviewRootPage() {
|
||||
const context = await getHousekeepingCapabilityContext();
|
||||
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
|
||||
const operations = registry.domains.find(
|
||||
(domain) => domain.id === "operations",
|
||||
);
|
||||
const route = operations?.routes.find(
|
||||
(entry) => entry.id === "operations.workspace",
|
||||
);
|
||||
const match = matchHousekeepingRoute(registry, "/ase");
|
||||
const handler = HOUSEKEEPING_ROUTE_HANDLERS.find(
|
||||
(entry) => entry.routeId === "operations.workspace",
|
||||
);
|
||||
const canOpenWorkspace =
|
||||
operations !== undefined &&
|
||||
route !== undefined &&
|
||||
match !== null &&
|
||||
handler !== undefined &&
|
||||
satisfiesCapability(context, operations.capability) &&
|
||||
satisfiesCapability(context, route.capability);
|
||||
|
||||
for (const domain of registry.domains) {
|
||||
if (!satisfiesCapability(context, domain.capability)) continue;
|
||||
|
||||
const route = domain.routes.find((entry) =>
|
||||
satisfiesCapability(context, entry.capability),
|
||||
);
|
||||
if (!route) continue;
|
||||
|
||||
const previewHref = toHousekeepingHref(route.href, "preview");
|
||||
redirect(
|
||||
previewHref === "/ase-next" ? "/ase-next/operations" : previewHref,
|
||||
);
|
||||
if (!canOpenWorkspace) {
|
||||
for (const domain of registry.domains) {
|
||||
if (domain.id === "operations") continue;
|
||||
if (!satisfiesCapability(context, domain.capability)) continue;
|
||||
const fallback = domain.routes.find((entry) =>
|
||||
satisfiesCapability(context, entry.capability),
|
||||
);
|
||||
if (fallback) redirect(toHousekeepingHref(fallback.href, "preview"));
|
||||
}
|
||||
notFound();
|
||||
}
|
||||
if (
|
||||
!operations ||
|
||||
!route ||
|
||||
!match ||
|
||||
!handler ||
|
||||
!satisfiesCapability(context, operations.capability) ||
|
||||
!satisfiesCapability(context, route.capability)
|
||||
) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
notFound();
|
||||
const translate = await getTranslations("pages.housekeeping");
|
||||
const navigation = buildHousekeepingNavigation(
|
||||
registry,
|
||||
context,
|
||||
"preview",
|
||||
(key) => translate(namespaceKey(key) as never),
|
||||
);
|
||||
const workspace = await handler.render({
|
||||
context,
|
||||
match,
|
||||
surface: "preview",
|
||||
});
|
||||
|
||||
return (
|
||||
<HousekeepingShell
|
||||
actor={context.actor}
|
||||
activeDomainId="operations"
|
||||
domains={navigation}
|
||||
labels={{
|
||||
skipToContent: translate("navigation.skipToContent"),
|
||||
primaryNavigation: translate("navigation.primary"),
|
||||
contextualNavigation: translate("navigation.contextual"),
|
||||
command: translate("preview.commandDisabled"),
|
||||
preview: translate("preview.badge"),
|
||||
backToSite: translate("preview.backToSite"),
|
||||
commandDeck: {
|
||||
placeholder: translate("commandDeck.placeholder"),
|
||||
navigation: translate("commandDeck.navigation"),
|
||||
commands: translate("commandDeck.commands"),
|
||||
entities: translate("commandDeck.entities"),
|
||||
loading: translate("commandDeck.loading"),
|
||||
empty: translate("commandDeck.empty"),
|
||||
partial: translate("commandDeck.partial"),
|
||||
close: translate("commandDeck.close"),
|
||||
},
|
||||
}}
|
||||
surface="preview"
|
||||
>
|
||||
{workspace}
|
||||
</HousekeepingShell>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user