feat: add temporal context and contextual help
This commit is contained in:
@@ -17,6 +17,11 @@ assert(
|
||||
"/docs?type=admin&context=campaign.review-send",
|
||||
"context references retain the requested audience projection"
|
||||
);
|
||||
assert(
|
||||
documentationHelpHref({ contextId: "calendar.field.title", fallbackContextId: "calendar.page", moduleId: "calendar" }) ===
|
||||
"/docs?type=user&context=calendar.field.title&fallback_context=calendar.page&module=calendar",
|
||||
"focused controls retain their page and module documentation fallback"
|
||||
);
|
||||
assert(
|
||||
documentationHelpHref({ topicId: "topic", anchorId: "details" }) ===
|
||||
"/docs?type=user&topic=topic#details",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { helpContextForPathname } from "../src/utils/helpContext";
|
||||
import { helpContextForPathname, helpQueryForContext } from "../src/utils/helpContext";
|
||||
import type { PlatformWebModule } from "../src/types";
|
||||
|
||||
function assertEqual(actual: string, expected: string, message: string): void {
|
||||
if (actual !== expected) throw new Error(`${message}: expected ${expected}, got ${actual}`);
|
||||
@@ -16,3 +17,65 @@ assertEqual(
|
||||
"campaign.attachments",
|
||||
"Campaign attachment context"
|
||||
);
|
||||
assertEqual(helpContextForPathname("/address-book").id, "addresses.page", "Address book context");
|
||||
|
||||
const modules: PlatformWebModule[] = [
|
||||
{
|
||||
id: "calendar",
|
||||
label: "Calendar",
|
||||
version: "1",
|
||||
routes: [{ path: "/calendar", surfaceId: "calendar.page", render: () => null }],
|
||||
viewSurfaces: [{ id: "calendar.page", moduleId: "calendar", kind: "route", label: "Calendar" }],
|
||||
helpContexts: [{
|
||||
id: "calendar.page",
|
||||
topic_id: "calendar.manage-calendars-and-events",
|
||||
title: "Use calendars and events",
|
||||
documentation_types: ["user"]
|
||||
}]
|
||||
},
|
||||
{
|
||||
id: "cases",
|
||||
label: "Cases",
|
||||
version: "1",
|
||||
routes: [
|
||||
{ path: "/cases", surfaceId: "cases.list", render: () => null },
|
||||
{ path: "/cases/:caseId", surfaceId: "cases.detail", render: () => null }
|
||||
],
|
||||
viewSurfaces: [
|
||||
{ id: "cases.list", moduleId: "cases", kind: "route", label: "Cases" },
|
||||
{ id: "cases.detail", moduleId: "cases", kind: "route", label: "Case details" }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: "admin",
|
||||
label: "Administration",
|
||||
version: "1",
|
||||
viewSurfaces: [
|
||||
{ id: "admin.section.system-modules", moduleId: "admin", kind: "section", label: "Modules" }
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
assertEqual(helpContextForPathname("/calendar", "", modules).id, "calendar.page", "Contributed route context");
|
||||
if (!helpQueryForContext(helpContextForPathname("/calendar", "", modules)).includes("topic=calendar.manage-calendars-and-events")) {
|
||||
throw new Error("Declared route help context did not resolve its documentation topic");
|
||||
}
|
||||
assertEqual(helpContextForPathname("/cases/case-1", "", modules).id, "cases.detail", "Dynamic route context");
|
||||
assertEqual(
|
||||
helpContextForPathname("/admin", "?section=system-modules", modules).id,
|
||||
"admin.section.system-modules",
|
||||
"Contributed admin section context"
|
||||
);
|
||||
assertEqual(helpContextForPathname("/future-module").id, "future-module.page", "Unknown route fallback context");
|
||||
|
||||
const focusedContextQuery = helpQueryForContext({
|
||||
id: "calendar.field.title",
|
||||
title: "Title",
|
||||
route: "/calendar",
|
||||
kind: "field",
|
||||
moduleId: "calendar",
|
||||
parentId: "calendar.page"
|
||||
});
|
||||
if (!focusedContextQuery.includes("context=calendar.field.title")) throw new Error("Focused context query is missing the control context");
|
||||
if (!focusedContextQuery.includes("fallback_context=calendar.page")) throw new Error("Focused context query is missing the page fallback");
|
||||
if (!focusedContextQuery.includes("module=calendar")) throw new Error("Focused context query is missing the owning module");
|
||||
|
||||
Reference in New Issue
Block a user