@bevel-software/platform-core-frontend 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ProductName.test.tsx +46 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/maker-url.ts +30 -0
- package/src/core/registry.ts +78 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/lib/__tests__/latest-request.test.ts +48 -0
- package/src/lib/latest-request.ts +45 -0
- package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/api.ts +19 -3
- package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
- package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
- package/src/modules/admin/services/roles.api.ts +14 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
- package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
- package/src/modules/auth/components/LoginScreen.tsx +101 -73
- package/src/modules/auth/services/account.api.ts +59 -3
- package/src/modules/auth/services/sso.ts +30 -10
- package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
- package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
- package/src/modules/onboarding/components/InviteButton.tsx +139 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +123 -0
- package/src/modules/onboarding/invite-emails.ts +313 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +330 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
- package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import { InviteDialog } from '../components/InviteDialog';
|
|
3
|
+
import { InviteDialogContext } from './invite-dialog.context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hosts the invite dialog for everything below it (see
|
|
7
|
+
* `invite-dialog.context.ts` for what it shares). Mounted in `AppChrome`, so
|
|
8
|
+
* the dialog renders INSIDE the registry's providers — the `inviteExtras`
|
|
9
|
+
* slot it carries may read state a distribution provides there.
|
|
10
|
+
*
|
|
11
|
+
* The dialog only mounts while open, so the provider costs nothing — and
|
|
12
|
+
* reads nothing, not even the admin verdict — until somebody asks for it.
|
|
13
|
+
*/
|
|
14
|
+
export function InviteDialogProvider({ children }: { children: ReactNode }) {
|
|
15
|
+
// While open, the addresses the dialog starts with; null while closed. An
|
|
16
|
+
// open while already open keeps the dialog as it is.
|
|
17
|
+
const [openWith, setOpenWith] = useState<string[] | null>(null);
|
|
18
|
+
const [invitedRevision, setInvitedRevision] = useState(0);
|
|
19
|
+
// Also wired straight to onClick handlers, so `options` may be a click
|
|
20
|
+
// event: only an array of addresses counts.
|
|
21
|
+
const open = useCallback((options?: { emails?: string[] }) => {
|
|
22
|
+
const emails = options?.emails;
|
|
23
|
+
setOpenWith((current) => current ?? (Array.isArray(emails) ? emails : []));
|
|
24
|
+
}, []);
|
|
25
|
+
const value = useMemo(() => ({ open, invitedRevision }), [open, invitedRevision]);
|
|
26
|
+
return (
|
|
27
|
+
<InviteDialogContext.Provider value={value}>
|
|
28
|
+
{children}
|
|
29
|
+
{openWith && (
|
|
30
|
+
<InviteDialog
|
|
31
|
+
open
|
|
32
|
+
initialEmails={openWith}
|
|
33
|
+
onClose={() => setOpenWith(null)}
|
|
34
|
+
onInvited={() => setInvitedRevision((r) => r + 1)}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
</InviteDialogContext.Provider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -16,70 +16,97 @@ import { authFetch } from '../../../lib/api';
|
|
|
16
16
|
* absent field must never resurrect the welcome flow for an account that
|
|
17
17
|
* finished it.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* One client-side piece around the server truth: `doneLocally`, an
|
|
20
|
+
* optimistic session override. The auth context's user object is a snapshot
|
|
21
|
+
* from sign-in; after POSTing we don't refetch it, we just remember the
|
|
22
|
+
* answer. A failed POST logs and DROPS the override at once, so the pill
|
|
23
|
+
* comes back immediately rather than reappearing at the next sign-in with no
|
|
24
|
+
* account of why it left.
|
|
20
25
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* at once, so the pill comes back immediately rather than reappearing at
|
|
25
|
-
* the next sign-in with no account of why it left.
|
|
26
|
-
* - `welcomed` (localStorage, per account) — "the welcome page was shown
|
|
27
|
-
* once". The auto-redirect there happens on the FIRST sign-in only;
|
|
28
|
-
* the pill, not the router, is the standing reminder. Per-browser by
|
|
29
|
-
* nature, which is fine: being greeted once per new machine is a welcome,
|
|
30
|
-
* not a bug.
|
|
26
|
+
* Nothing here sends anyone to the welcome page. `/` lands on Knowledge for
|
|
27
|
+
* everyone (see `RootLanding`); the pill and the Get set up list are the
|
|
28
|
+
* reminder, and the page is theirs to open.
|
|
31
29
|
*/
|
|
32
30
|
|
|
33
|
-
const WELCOMED_PREFIX = 'bevel.onboarding.welcomed.';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The storage key holding "this account has seen the welcome page", keyed by
|
|
37
|
-
* lower-cased email so `Juan@…` and `juan@…` are one person rather than two
|
|
38
|
-
* greetings.
|
|
39
|
-
*/
|
|
40
|
-
const welcomedKey = (email: string) => `${WELCOMED_PREFIX}${email.toLowerCase()}`;
|
|
41
|
-
|
|
42
31
|
const doneLocally = new Set<string>();
|
|
43
|
-
|
|
32
|
+
/** Full storage keys set this session — see {@link setFlag}. */
|
|
33
|
+
const flagsLocally = new Set<string>();
|
|
44
34
|
const listeners = new Set<() => void>();
|
|
35
|
+
/** Bumped when ANOTHER tab changes one of the notes below — see {@link onStorage}. */
|
|
36
|
+
let storageVersion = 0;
|
|
45
37
|
|
|
46
38
|
/** Tell every mounted `useOnboarding` that the overrides above moved. */
|
|
47
39
|
function emit(): void {
|
|
48
40
|
listeners.forEach((l) => l());
|
|
49
41
|
}
|
|
50
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Another tab raised (or cleared) one of the notes. `setFlag` only wakes this
|
|
45
|
+
* tab's listeners, and the browser tells the OTHER tabs through `storage` —
|
|
46
|
+
* so a guide read, or a column closed, in one tab reaches every tab already
|
|
47
|
+
* open, rather than waiting for their next reload. A `null` key is the whole
|
|
48
|
+
* storage cleared.
|
|
49
|
+
*/
|
|
50
|
+
function onStorage(event: StorageEvent): void {
|
|
51
|
+
const { key } = event;
|
|
52
|
+
if (key !== null && !FLAG_PREFIXES.some((prefix) => key.startsWith(prefix))) return;
|
|
53
|
+
storageVersion++;
|
|
54
|
+
emit();
|
|
55
|
+
}
|
|
56
|
+
|
|
51
57
|
/**
|
|
52
58
|
* The `useSyncExternalStore` half of the subscription: register a listener and
|
|
53
59
|
* hand back its unsubscribe, so a hook that unmounts stops being notified.
|
|
60
|
+
* The window's `storage` listener lives exactly as long as there is somebody
|
|
61
|
+
* to tell.
|
|
54
62
|
*/
|
|
55
63
|
function subscribe(listener: () => void): () => void {
|
|
64
|
+
if (listeners.size === 0) window.addEventListener('storage', onStorage);
|
|
56
65
|
listeners.add(listener);
|
|
57
|
-
return () =>
|
|
66
|
+
return () => {
|
|
67
|
+
listeners.delete(listener);
|
|
68
|
+
if (listeners.size === 0) window.removeEventListener('storage', onStorage);
|
|
69
|
+
};
|
|
58
70
|
}
|
|
59
71
|
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
/**
|
|
73
|
+
* The "Get set up" column's per-account notes: the starter guide has been
|
|
74
|
+
* opened, the command menu has been opened, the column was dismissed, and its
|
|
75
|
+
* "You're set up" was seen and closed. All per-browser conveniences, not server truth, so they live beside
|
|
76
|
+
* the session override and wake the same listeners, through one tiny flag
|
|
77
|
+
* pair rather than a hand-written copy of the read/write/try-catch dance per
|
|
78
|
+
* note.
|
|
79
|
+
*/
|
|
80
|
+
const READ_GUIDE_PREFIX = 'bevel.onboarding.readGuide.';
|
|
81
|
+
const COMMAND_MENU_PREFIX = 'bevel.onboarding.commandMenuOpened.';
|
|
82
|
+
const SETUP_DISMISSED_PREFIX = 'bevel.onboarding.setupDismissed.';
|
|
83
|
+
const SETUP_COMPLETE_PREFIX = 'bevel.onboarding.setupCompleteClosed.';
|
|
84
|
+
const FLAG_PREFIXES = [READ_GUIDE_PREFIX, COMMAND_MENU_PREFIX, SETUP_DISMISSED_PREFIX, SETUP_COMPLETE_PREFIX];
|
|
85
|
+
|
|
86
|
+
/** Storage is best-effort: private-mode Safari throws, and a lost flag costs
|
|
87
|
+
* one extra row on screen, not a failure. */
|
|
88
|
+
function hasFlag(key: string): boolean {
|
|
89
|
+
if (flagsLocally.has(key)) return true;
|
|
64
90
|
try {
|
|
65
|
-
return window.localStorage.getItem(
|
|
91
|
+
return window.localStorage.getItem(key) === '1';
|
|
66
92
|
} catch {
|
|
67
93
|
return false;
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
96
|
|
|
71
97
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* touching storage or waking
|
|
98
|
+
* Raise a one-way flag. Remembered in memory as well as storage so a browser
|
|
99
|
+
* that refuses the write still honours it for the rest of the session.
|
|
100
|
+
* Idempotent: a raised flag returns without touching storage or waking
|
|
101
|
+
* listeners.
|
|
75
102
|
*/
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
103
|
+
function setFlag(key: string): void {
|
|
104
|
+
if (hasFlag(key)) return;
|
|
105
|
+
flagsLocally.add(key);
|
|
79
106
|
try {
|
|
80
|
-
window.localStorage.setItem(
|
|
107
|
+
window.localStorage.setItem(key, '1');
|
|
81
108
|
} catch {
|
|
82
|
-
/*
|
|
109
|
+
/* held in memory for this session */
|
|
83
110
|
}
|
|
84
111
|
emit();
|
|
85
112
|
}
|
|
@@ -123,42 +150,39 @@ export function markOnboardingDone(userId: string, email: string): void {
|
|
|
123
150
|
}
|
|
124
151
|
|
|
125
152
|
/**
|
|
126
|
-
* Test seam: forget the session overrides and the
|
|
153
|
+
* Test seam: forget the session overrides and the per-browser notes.
|
|
127
154
|
*
|
|
128
|
-
* Scans storage by PREFIX rather than walking `
|
|
129
|
-
* set is not a record of what is in storage. `
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* next "greets ONCE" assertion would then read "already welcomed" and fail on
|
|
134
|
-
* a state no test put there.
|
|
155
|
+
* Scans storage by PREFIX rather than walking `flagsLocally`, because that
|
|
156
|
+
* set is not a record of what is in storage. `setFlag` returns early when the
|
|
157
|
+
* key is already there, so a flag raised by an earlier test file — or by an
|
|
158
|
+
* earlier run against the same jsdom `localStorage` — never enters the set,
|
|
159
|
+
* and its key would survive a reset that only knew about the set.
|
|
135
160
|
*/
|
|
136
161
|
export function resetOnboardingForTests(): void {
|
|
137
162
|
try {
|
|
138
163
|
for (const key of Object.keys(window.localStorage)) {
|
|
139
|
-
if (key.startsWith(
|
|
164
|
+
if (FLAG_PREFIXES.some((prefix) => key.startsWith(prefix))) window.localStorage.removeItem(key);
|
|
140
165
|
}
|
|
141
166
|
} catch {
|
|
142
167
|
/* ignore */
|
|
143
168
|
}
|
|
144
169
|
doneLocally.clear();
|
|
145
|
-
|
|
170
|
+
flagsLocally.clear();
|
|
146
171
|
emit();
|
|
147
172
|
}
|
|
148
173
|
|
|
149
174
|
export interface OnboardingController {
|
|
150
175
|
/** The reminder is alive: the server says onboarding is not done. */
|
|
151
176
|
showPill: boolean;
|
|
152
|
-
/** First sign-in, still unanswered: drives the ONE-TIME redirect to the welcome page. */
|
|
153
|
-
shouldWelcome: boolean;
|
|
154
|
-
markWelcomed(): void;
|
|
155
177
|
markDone(): void;
|
|
156
178
|
}
|
|
157
179
|
|
|
180
|
+
/** The subscription's version counter: every override and note, in this tab or another, changes it. */
|
|
181
|
+
const snapshot = () => `${doneLocally.size}:${flagsLocally.size}:${storageVersion}`;
|
|
182
|
+
const serverSnapshot = () => '0:0:0';
|
|
183
|
+
|
|
158
184
|
const SIGNED_OUT: OnboardingController = {
|
|
159
185
|
showPill: false,
|
|
160
|
-
shouldWelcome: false,
|
|
161
|
-
markWelcomed: () => {},
|
|
162
186
|
markDone: () => {},
|
|
163
187
|
};
|
|
164
188
|
|
|
@@ -172,20 +196,70 @@ const SIGNED_OUT: OnboardingController = {
|
|
|
172
196
|
export function useOnboarding(): OnboardingController {
|
|
173
197
|
const auth = useContext(AuthContext);
|
|
174
198
|
const user = auth?.user ?? null;
|
|
175
|
-
// The subscription's version counter: overrides and
|
|
176
|
-
|
|
177
|
-
useSyncExternalStore(
|
|
178
|
-
subscribe,
|
|
179
|
-
() => `${doneLocally.size}:${welcomedLocally.size}`,
|
|
180
|
-
() => '0:0',
|
|
181
|
-
);
|
|
199
|
+
// The subscription's version counter: overrides and notes change under it. The snapshot is a cheap string so identity comparison is exact.
|
|
200
|
+
useSyncExternalStore(subscribe, snapshot, serverSnapshot);
|
|
182
201
|
if (!user) return SIGNED_OUT;
|
|
183
202
|
const email = user.email;
|
|
184
203
|
const done = user.onboardingDone !== false || doneLocally.has(email);
|
|
185
204
|
return {
|
|
186
205
|
showPill: !done,
|
|
187
|
-
shouldWelcome: !done && !hasBeenWelcomed(email),
|
|
188
|
-
markWelcomed: () => markWelcomed(email),
|
|
189
206
|
markDone: () => markOnboardingDone(user.id, email),
|
|
190
207
|
};
|
|
191
208
|
}
|
|
209
|
+
|
|
210
|
+
export interface SetupChecklistState {
|
|
211
|
+
/** The starter guide ("How to get started") has been opened on this browser. */
|
|
212
|
+
readGuide: boolean;
|
|
213
|
+
/** The command menu (Ctrl/⌘K) has been opened on this browser, by any route. */
|
|
214
|
+
openedCommandMenu: boolean;
|
|
215
|
+
/** The person closed the "Get set up" column; it stays closed. */
|
|
216
|
+
dismissed: boolean;
|
|
217
|
+
/**
|
|
218
|
+
* The person closed the column's "You're set up" — the list was finished
|
|
219
|
+
* and celebrated, and the column is gone for good.
|
|
220
|
+
*/
|
|
221
|
+
completionClosed: boolean;
|
|
222
|
+
markGuideRead(): void;
|
|
223
|
+
markCommandMenuOpened(): void;
|
|
224
|
+
dismiss(): void;
|
|
225
|
+
closeCompletion(): void;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const NO_CHECKLIST: SetupChecklistState = {
|
|
229
|
+
readGuide: false,
|
|
230
|
+
openedCommandMenu: false,
|
|
231
|
+
dismissed: false,
|
|
232
|
+
completionClosed: false,
|
|
233
|
+
markGuideRead: () => {},
|
|
234
|
+
markCommandMenuOpened: () => {},
|
|
235
|
+
dismiss: () => {},
|
|
236
|
+
closeCompletion: () => {},
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The client-side half of the "Get set up" column: the tick the server has no
|
|
241
|
+
* field for, and the column's two ways of going away. Keyed by lower-cased email, so `Juan@…` and `juan@…` are
|
|
242
|
+
* one person, and tolerant of a missing auth provider for the same reason
|
|
243
|
+
* {@link useOnboarding} is.
|
|
244
|
+
*/
|
|
245
|
+
export function useSetupChecklist(): SetupChecklistState {
|
|
246
|
+
const auth = useContext(AuthContext);
|
|
247
|
+
const user = auth?.user ?? null;
|
|
248
|
+
useSyncExternalStore(subscribe, snapshot, serverSnapshot);
|
|
249
|
+
if (!user) return NO_CHECKLIST;
|
|
250
|
+
const email = user.email.toLowerCase();
|
|
251
|
+
const readKey = `${READ_GUIDE_PREFIX}${email}`;
|
|
252
|
+
const commandMenuKey = `${COMMAND_MENU_PREFIX}${email}`;
|
|
253
|
+
const dismissedKey = `${SETUP_DISMISSED_PREFIX}${email}`;
|
|
254
|
+
const completeKey = `${SETUP_COMPLETE_PREFIX}${email}`;
|
|
255
|
+
return {
|
|
256
|
+
readGuide: hasFlag(readKey),
|
|
257
|
+
openedCommandMenu: hasFlag(commandMenuKey),
|
|
258
|
+
dismissed: hasFlag(dismissedKey),
|
|
259
|
+
completionClosed: hasFlag(completeKey),
|
|
260
|
+
markGuideRead: () => setFlag(readKey),
|
|
261
|
+
markCommandMenuOpened: () => setFlag(commandMenuKey),
|
|
262
|
+
dismiss: () => setFlag(dismissedKey),
|
|
263
|
+
closeCompletion: () => setFlag(completeKey),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useSyncExternalStore } from 'react';
|
|
2
|
+
import { AuthContext } from '../../auth/state/auth.context';
|
|
3
|
+
import {
|
|
4
|
+
StarterPackApiError,
|
|
5
|
+
chooseStarterPack,
|
|
6
|
+
fetchStarterPacks,
|
|
7
|
+
type StarterPackApplied,
|
|
8
|
+
type StarterPacksAnswer,
|
|
9
|
+
} from '../services/starter-packs.api';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The starter-pack answer, shared by the two places that read it: the
|
|
13
|
+
* knowledge base's empty state (which asks "What does your team do?" while it
|
|
14
|
+
* is offered) and the Get set up list (whose first-page prompt follows the
|
|
15
|
+
* pack that was chosen). One request per signed-in user per page load, and a
|
|
16
|
+
* choice made in one is seen by the other at once, without asking the server
|
|
17
|
+
* twice.
|
|
18
|
+
*
|
|
19
|
+
* Kept PER SIGNED-IN USER — the store hangs off the auth context's user
|
|
20
|
+
* object, which the session holds for as long as that person is signed in
|
|
21
|
+
* — so a tab that switches accounts never shows one person's answer to the
|
|
22
|
+
* next, and a fresh session starts from nothing. A failed request is
|
|
23
|
+
* remembered as nothing known: the card stays away and the generic prompt
|
|
24
|
+
* stands, which is what the app did before there were packs.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface Store {
|
|
28
|
+
answer: StarterPacksAnswer | null;
|
|
29
|
+
/** The first request has come back, either way. */
|
|
30
|
+
settled: boolean;
|
|
31
|
+
inFlight: Promise<void> | null;
|
|
32
|
+
/** Asked for again while a request was out: one more request follows it. */
|
|
33
|
+
again: boolean;
|
|
34
|
+
version: number;
|
|
35
|
+
listeners: Set<() => void>;
|
|
36
|
+
subscribe(listener: () => void): () => void;
|
|
37
|
+
snapshot(): number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const stores = new WeakMap<object, Store>();
|
|
41
|
+
|
|
42
|
+
function storeFor(user: object): Store {
|
|
43
|
+
const found = stores.get(user);
|
|
44
|
+
if (found) return found;
|
|
45
|
+
const store: Store = {
|
|
46
|
+
answer: null,
|
|
47
|
+
settled: false,
|
|
48
|
+
inFlight: null,
|
|
49
|
+
again: false,
|
|
50
|
+
version: 0,
|
|
51
|
+
listeners: new Set(),
|
|
52
|
+
subscribe(listener) {
|
|
53
|
+
store.listeners.add(listener);
|
|
54
|
+
return () => store.listeners.delete(listener);
|
|
55
|
+
},
|
|
56
|
+
snapshot: () => store.version,
|
|
57
|
+
};
|
|
58
|
+
stores.set(user, store);
|
|
59
|
+
return store;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function remember(store: Store, answer: StarterPacksAnswer | null): void {
|
|
63
|
+
store.answer = answer;
|
|
64
|
+
store.settled = true;
|
|
65
|
+
store.version++;
|
|
66
|
+
store.listeners.forEach((l) => l());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The answer, requested once: concurrent first reads (the viewer's and the column's) share one request. */
|
|
70
|
+
function load(store: Store): Promise<void> {
|
|
71
|
+
if (store.inFlight) return store.inFlight;
|
|
72
|
+
const request = fetchStarterPacks()
|
|
73
|
+
.then(
|
|
74
|
+
(answer) => remember(store, answer),
|
|
75
|
+
() => {
|
|
76
|
+
if (!store.settled) remember(store, null);
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
.finally(() => {
|
|
80
|
+
store.inFlight = null;
|
|
81
|
+
if (store.again) {
|
|
82
|
+
store.again = false;
|
|
83
|
+
void load(store);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
store.inFlight = request;
|
|
87
|
+
return request;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Ask again, because something changed (a page filled in, a choice made):
|
|
92
|
+
* a request already out may have been answered before the change, so one
|
|
93
|
+
* more follows it, and whoever asked waits for the one that saw the change.
|
|
94
|
+
*/
|
|
95
|
+
function refresh(store: Store): Promise<void> {
|
|
96
|
+
if (!store.inFlight) return load(store);
|
|
97
|
+
store.again = true;
|
|
98
|
+
return store.inFlight.then(() => store.inFlight ?? Promise.resolve());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const nobody = {
|
|
102
|
+
subscribe: () => () => {},
|
|
103
|
+
snapshot: () => 0,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export interface StarterPacksState {
|
|
107
|
+
/** The server's answer; null until it arrives, or when it could not be had. */
|
|
108
|
+
answer: StarterPacksAnswer | null;
|
|
109
|
+
/** The first request has come back, either way — or there is no account to ask for. */
|
|
110
|
+
settled: boolean;
|
|
111
|
+
/** Ask again — after the tree changed under a chosen pack's pages, say. */
|
|
112
|
+
reload(): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Answer the question (a pack's id, or `none`); resolves to what was added,
|
|
115
|
+
* and the answer is re-read. `settle` runs after the server answered and
|
|
116
|
+
* BEFORE the shared answer changes under its readers: for what must be in
|
|
117
|
+
* place by then (the tree, with the pack's pages in it). Its failure is
|
|
118
|
+
* not the choice's.
|
|
119
|
+
*/
|
|
120
|
+
choose(id: string, settle?: (applied: StarterPackApplied) => Promise<unknown>): Promise<StarterPackApplied>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function useStarterPacks({ enabled = true }: { enabled?: boolean } = {}): StarterPacksState {
|
|
124
|
+
const auth = useContext(AuthContext);
|
|
125
|
+
const user = auth?.user ?? null;
|
|
126
|
+
const store = user ? storeFor(user) : null;
|
|
127
|
+
useSyncExternalStore(store?.subscribe ?? nobody.subscribe, store?.snapshot ?? nobody.snapshot, nobody.snapshot);
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (!enabled || !store || store.settled) return;
|
|
131
|
+
void load(store);
|
|
132
|
+
}, [enabled, store]);
|
|
133
|
+
|
|
134
|
+
const reload = useCallback(async () => {
|
|
135
|
+
if (store) await refresh(store);
|
|
136
|
+
}, [store]);
|
|
137
|
+
|
|
138
|
+
const choose = useCallback(
|
|
139
|
+
async (id: string, settle?: (applied: StarterPackApplied) => Promise<unknown>) => {
|
|
140
|
+
let applied: StarterPackApplied;
|
|
141
|
+
try {
|
|
142
|
+
applied = await chooseStarterPack(id);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
// Refused because the question is no longer asked — answered in
|
|
145
|
+
// another tab, say: the answer is read again, so the card goes. A
|
|
146
|
+
// lock refusal wears the same status; its re-read finds the offer
|
|
147
|
+
// still standing, and the card stays to say so.
|
|
148
|
+
if (err instanceof StarterPackApiError && err.status === 409 && store) await refresh(store);
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
151
|
+
if (settle) await settle(applied).catch(() => null);
|
|
152
|
+
if (store) {
|
|
153
|
+
// The question is answered whatever the re-read says: never show it
|
|
154
|
+
// again on the strength of a request that failed.
|
|
155
|
+
if (store.answer) remember(store, { ...store.answer, offered: false, chosen: id });
|
|
156
|
+
await refresh(store);
|
|
157
|
+
}
|
|
158
|
+
return applied;
|
|
159
|
+
},
|
|
160
|
+
[store],
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
answer: store?.answer ?? null,
|
|
165
|
+
settled: !store || store.settled,
|
|
166
|
+
reload,
|
|
167
|
+
choose,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -19,8 +19,9 @@ import { useAppRegistry, type AdminMenuItem } from '../../core/registry';
|
|
|
19
19
|
* Connected apps, feedback, LLM configuration, …) is registry-contributed —
|
|
20
20
|
* see the enterprise shell's `adminMenuItems`. The `order` values interleave
|
|
21
21
|
* the two lists to reproduce the historical row order. In THIS repo the
|
|
22
|
-
* registry is empty (`makeRegistry({})`), so the menu is these
|
|
23
|
-
*
|
|
22
|
+
* registry is empty (`makeRegistry({})`), so the menu is these rows plus the
|
|
23
|
+
* core modules' own action rows the shell merges in (git's "Ask before
|
|
24
|
+
* deleting branches", while it applies); the enterprise app gets all thirteen.
|
|
24
25
|
*
|
|
25
26
|
* Skills & Tools is deliberately NOT here. It is an APP (see `CORE_APPS` in
|
|
26
27
|
* CoreAppShell), and apps belong to the app switcher — which already lists it
|
|
@@ -32,7 +33,11 @@ import { useAppRegistry, type AdminMenuItem } from '../../core/registry';
|
|
|
32
33
|
* to one. The closures said the same thing twice — where the row goes, and how
|
|
33
34
|
* to go there — and only the second half was legible to anything that was not
|
|
34
35
|
* a click. The `dialog` and `onSelect` contracts on {@link AdminMenuItem} stay
|
|
35
|
-
* fully supported for registry
|
|
36
|
+
* fully supported for rows that arrive through the registry — and not every
|
|
37
|
+
* such row is the enterprise shell's: `CoreAppShell` merges core modules' own
|
|
38
|
+
* action rows into `registry.adminMenuItems` (git's "Ask before deleting
|
|
39
|
+
* branches", an `onSelect` row with no `path`, which therefore never reaches
|
|
40
|
+
* the settings nav).
|
|
36
41
|
*/
|
|
37
42
|
export const CORE_MENU_ITEMS: AdminMenuItem[] = [
|
|
38
43
|
{
|