@bevel-software/platform-core-frontend 0.27.0 → 0.28.1

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.
Files changed (42) hide show
  1. package/package.json +2 -2
  2. package/src/core/ProductName.tsx +4 -4
  3. package/src/core/__tests__/ProductName.test.tsx +46 -0
  4. package/src/core/maker-url.ts +30 -0
  5. package/src/core/registry.ts +27 -0
  6. package/src/lib/__tests__/latest-request.test.ts +48 -0
  7. package/src/lib/latest-request.ts +45 -0
  8. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  9. package/src/modules/access/api.ts +19 -3
  10. package/src/modules/access/components/ManageAccessDialog.tsx +60 -7
  11. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  12. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  13. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  14. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  15. package/src/modules/admin/services/roles.api.ts +14 -1
  16. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  17. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  18. package/src/modules/auth/components/LoginScreen.tsx +100 -75
  19. package/src/modules/auth/services/account.api.ts +31 -2
  20. package/src/modules/auth/services/sso.ts +29 -8
  21. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  22. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  23. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +56 -1
  24. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +538 -81
  25. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +543 -124
  26. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  27. package/src/modules/onboarding/components/GetStartedColumn.tsx +30 -11
  28. package/src/modules/onboarding/components/InviteButton.tsx +119 -15
  29. package/src/modules/onboarding/components/InviteDialog.tsx +392 -75
  30. package/src/modules/onboarding/first-page-prompt.ts +34 -0
  31. package/src/modules/onboarding/invite-emails.ts +171 -33
  32. package/src/modules/onboarding/state/invite-dialog.context.ts +7 -4
  33. package/src/modules/onboarding/state/invite-dialog.tsx +12 -4
  34. package/src/modules/toolbar/commands/actions.tsx +10 -4
  35. package/src/modules/toolbar/commands/useCommandActions.ts +5 -3
  36. package/src/modules/toolbar/components/AppSwitcher.tsx +19 -0
  37. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +46 -1
  38. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +34 -2
  39. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  40. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  41. package/src/modules/workspace/hooks/useCreatePage.ts +118 -28
  42. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
@@ -20,6 +20,40 @@ export function firstPagePromptFor(pack: { firstPagePrompt: string } | null | un
20
20
  return pack?.firstPagePrompt.trim() || FIRST_PAGE_PROMPT;
21
21
  }
22
22
 
23
+ /**
24
+ * Where a request names the Knowledge folder as the place to write: "in
25
+ * Knowledge", any case — the generic request's "write a page in Knowledge"
26
+ * and every built-in pack's "fill in the … page in Knowledge". Not a path
27
+ * already ("in Knowledge/Sales").
28
+ */
29
+ const IN_KNOWLEDGE = /\bin knowledge\b(?!\/)/gi;
30
+
31
+ /**
32
+ * What may follow "in Knowledge" when it is not the folder: "knowledge
33
+ * base", or a name that only starts with it ("Knowledge Management").
34
+ * Case-sensitive on purpose — " about our company" is the folder.
35
+ */
36
+ const NOT_THE_FOLDER = /^ (?:base\b|[A-Z])/;
37
+
38
+ /**
39
+ * The request pointed at `folder` — the path below the Knowledge folder New
40
+ * page would write in (`Sales`, `Sales/Team`) — so an agent writing as the
41
+ * person tries where they may write rather than the top, where they may not.
42
+ * No folder (the top of Knowledge) leaves the request as it is. The request's
43
+ * own "in Knowledge" becomes "in Knowledge/<folder>", in the request's own
44
+ * casing, so it names one place; one that never says where the page goes
45
+ * gets the place as a sentence of its own.
46
+ */
47
+ export function firstPagePromptInFolder(prompt: string, folder: string | null): string {
48
+ if (!folder) return prompt;
49
+ for (const match of prompt.matchAll(IN_KNOWLEDGE)) {
50
+ const end = match.index + match[0].length;
51
+ if (NOT_THE_FOLDER.test(prompt.slice(end))) continue;
52
+ return `${prompt.slice(0, end)}/${folder}${prompt.slice(end)}`;
53
+ }
54
+ return `${prompt} Save it in Knowledge/${folder}.`;
55
+ }
56
+
23
57
  /** A new Claude chat with `prompt` typed into it (claude.ai's `q` parameter prefills; the person still sends). */
24
58
  export function claudePromptUrl(prompt: string): string {
25
59
  return `https://claude.ai/new?q=${encodeURIComponent(prompt)}`;
@@ -47,13 +47,25 @@ const ADMIN_ROLE = 'admin';
47
47
 
48
48
  /** What became of one address. */
49
49
  export type InviteOutcome =
50
- | { email: string; status: 'created'; role: InviteRole; roleError?: string }
50
+ /**
51
+ * `passwordSet`: the account was created with the starting password.
52
+ * `notified`: how the deployment told the person of the invite (`'email'`
53
+ * from the cloud's mail, say), as the server's listeners answered; absent
54
+ * when nobody did and the admin hands over the link themselves.
55
+ */
56
+ | { email: string; status: 'created'; role: InviteRole; roleError?: string; passwordSet?: boolean; notified?: string[] }
51
57
  /**
52
58
  * Already had an account. Invited as Admin, they are made one too:
53
59
  * `promoted` when this call did it, `alreadyAdmin` when they were one.
54
60
  * `deactivated`: the account is switched off and cannot sign in until an
55
61
  * admin switches it back on. Inviting does not do that — switching on asks
56
- * the deployment for a seat, and is the User accounts page's decision.
62
+ * the deployment for a seat, and is the User accounts page's decision —
63
+ * and leaves it entirely unchanged: no password, and no Admin role either.
64
+ *
65
+ * With a starting password: `passwordSet` when the account had none and
66
+ * now has it, `hasOwnPassword` when it already had one (never replaced),
67
+ * `passwordError` when setting it failed — the account is then left
68
+ * exactly as it was, Admin promotion included.
57
69
  */
58
70
  | {
59
71
  email: string;
@@ -62,19 +74,65 @@ export type InviteOutcome =
62
74
  alreadyAdmin?: boolean;
63
75
  roleError?: string;
64
76
  deactivated?: boolean;
77
+ passwordSet?: boolean;
78
+ hasOwnPassword?: boolean;
79
+ passwordError?: string;
65
80
  }
66
81
  /** The deployment's admission rules had no place for the account (a seat limit, say). */
67
82
  | { email: string; status: 'no-seat'; message: string }
68
83
  | { email: string; status: 'error'; message: string };
69
84
 
70
- /** The address now has an account it can sign in to — new, or already there and switched on. */
71
- export function isInvited(outcome: InviteOutcome): boolean {
72
- return outcome.status === 'created' || (outcome.status === 'existing' && !outcome.deactivated);
85
+ /**
86
+ * What a send came to: one outcome per address, or — when a starting
87
+ * password was given and the account list could not be read — nothing sent
88
+ * at all (see {@link sendInvites}).
89
+ */
90
+ export type InviteResult =
91
+ | { status: 'sent'; outcomes: InviteOutcome[] }
92
+ | { status: 'accounts-unreadable' };
93
+
94
+ /**
95
+ * The address now has an account it can sign in to — new, or already there
96
+ * and switched on. One whose starting password could not be set still can
97
+ * when the deployment has single sign-on (`sso`).
98
+ */
99
+ export function isInvited(outcome: InviteOutcome, sso = false): boolean {
100
+ return (
101
+ outcome.status === 'created' ||
102
+ (outcome.status === 'existing' && !outcome.deactivated && (!outcome.passwordError || sso))
103
+ );
104
+ }
105
+
106
+ /** The account now signs in with the starting password the admin typed. */
107
+ export function gotPassword(outcome: InviteOutcome): boolean {
108
+ return (outcome.status === 'created' || outcome.status === 'existing') && Boolean(outcome.passwordSet);
109
+ }
110
+
111
+ /** The deployment emailed this person the invite itself, so the admin need not send them the link. */
112
+ export function wasEmailed(outcome: InviteOutcome): boolean {
113
+ return outcome.status === 'created' && (outcome.notified?.includes('email') ?? false);
114
+ }
115
+
116
+ /** One row of the account list, as much of it as inviting needs. */
117
+ interface ListedAccount {
118
+ email: string;
119
+ deactivatedAt?: string | null;
120
+ hasPassword?: boolean;
121
+ /** The deployment admin signs in with the environment password, hash or not. */
122
+ isEnvAdmin?: boolean;
123
+ }
124
+
125
+ /** The server refused a promotion because the account is switched off (`addMember`'s `ifActive`). */
126
+ function isSwitchedOff(err: unknown): boolean {
127
+ return (err as { kind?: unknown } | null)?.kind === 'deactivated';
73
128
  }
74
129
 
75
130
  /**
76
- * Invite each address: an account with no password, waiting for that
77
- * person's first single sign-on (`POST /api/admin/accounts`).
131
+ * Invite each address (`POST /api/admin/accounts`): an account with the
132
+ * starting password when the admin gave one, and otherwise with none — then
133
+ * the person signs in with single sign-on, or not at all until someone sets
134
+ * a password, which is why the dialog asks for one on a deployment without
135
+ * single sign-on.
78
136
  *
79
137
  * One at a time, not in parallel. Each create asks the deployment's admission
80
138
  * rules for a place, and a host that sells seats answers from a count —
@@ -84,10 +142,20 @@ export function isInvited(outcome: InviteOutcome): boolean {
84
142
  * The create endpoint is an upsert, so it cannot say "this person was already
85
143
  * here". The account list read first can, and an address already on it is
86
144
  * not created again: re-creating is not free (it asks for a seat again, and
87
- * a full plan refuses somebody who already HAS one). A list that cannot be
88
- * read just means every address is treated as new. The list holds
145
+ * a full plan refuses somebody who already HAS one). The list holds
89
146
  * switched-off accounts too, and those are reported as such rather than as
90
- * able to sign in.
147
+ * able to sign in, and never written.
148
+ *
149
+ * A starting password is sent with `keepExistingPassword`: the server gives
150
+ * it only to a new account or a switched-on one with no password, testing
151
+ * and writing in one statement, and says whether it did. So someone's own
152
+ * password is never replaced, even one set after the list was read. The list
153
+ * still decides what each row says, and an account it shows with a password
154
+ * (or the deployment admin, who signs in with the environment's) is not
155
+ * written at all. A list that cannot be read stops a send with a password
156
+ * before any write: the rows could not say who already had an account.
157
+ * Without a password an unreadable list just means every address is treated
158
+ * as new, as before.
91
159
  *
92
160
  * Only a refusal the server marks as an admission refusal
93
161
  * (`kind: 'admission'`) is "no seat left". Any other is an error in the
@@ -95,31 +163,45 @@ export function isInvited(outcome: InviteOutcome): boolean {
95
163
  * admin verdict gone stale in another tab.
96
164
  *
97
165
  * "Admin" is a role membership, not an account property, so it is a second
98
- * write after the create. Somebody who already had an account is made an
166
+ * write after the account's. Somebody who already had an account is made an
99
167
  * Admin too when invited as one: the admin asked for that person to be an
100
168
  * Admin, and that they could already sign in does not change the request.
169
+ * A switched-off account is the exception: it is left unchanged, so it is
170
+ * not made an Admin either. The list says who was switched off when it was
171
+ * read; the promotion itself is sent `ifActive`, so the server refuses one
172
+ * switched off since, at the write, and the row says "switched off".
101
173
  * The roster is read first so an existing Admin (including one the server
102
174
  * configuration fixes) is reported as such rather than written again. A
103
175
  * refused promotion leaves the account standing as it was and says so on
104
176
  * the row.
177
+ *
178
+ * The password goes to the server and nowhere else: no outcome carries it.
105
179
  */
106
180
  export async function sendInvites(
107
181
  emails: string[],
108
182
  role: InviteRole,
109
183
  api: {
110
- listAccounts(): Promise<{ email: string; deactivatedAt?: string | null }[]>;
111
- createAccount(email: string, name: string): Promise<void>;
112
- addMember(canonical: string, email: string): Promise<unknown>;
184
+ listAccounts(): Promise<ListedAccount[]>;
185
+ createAccount(
186
+ email: string,
187
+ name: string,
188
+ password?: string,
189
+ options?: { keepExistingPassword?: boolean },
190
+ ): Promise<{ passwordSet?: boolean; deactivated?: boolean; notified?: string[] } | void>;
191
+ addMember(canonical: string, email: string, options?: { ifActive?: boolean }): Promise<unknown>;
113
192
  fetchRoles(): Promise<{ canonical: string; members: string[]; fixedMembers?: string[] }[]>;
114
193
  },
115
- ): Promise<InviteOutcome[]> {
116
- /** Every address with an account, and whether that account is switched off. Unreadable means none known. */
117
- let existing: Map<string, boolean> | null = null;
194
+ options: { password?: string } = {},
195
+ ): Promise<InviteResult> {
196
+ const password = options.password || undefined;
197
+ /** Every address with an account. Unreadable means none known. */
198
+ let existing: Map<string, ListedAccount> | null = null;
118
199
  try {
119
- existing = new Map((await api.listAccounts()).map((a) => [a.email.toLowerCase(), Boolean(a.deactivatedAt)]));
200
+ existing = new Map((await api.listAccounts()).map((a) => [a.email.toLowerCase(), a]));
120
201
  } catch {
121
202
  existing = null;
122
203
  }
204
+ if (!existing && password) return { status: 'accounts-unreadable' };
123
205
  /** Who is an Admin already; asked only when someone is to be made one. Unreadable means unknown. */
124
206
  let admins: Set<string> | null = null;
125
207
  if (role === 'admin') {
@@ -132,25 +214,67 @@ export async function sendInvites(
132
214
  }
133
215
  const outcomes: InviteOutcome[] = [];
134
216
  for (const email of emails) {
135
- if (existing?.has(email.toLowerCase())) {
136
- const off = existing.get(email.toLowerCase()) ? { deactivated: true } : {};
137
- if (role !== 'admin') {
138
- outcomes.push({ email, status: 'existing', ...off });
217
+ const account = existing?.get(email.toLowerCase());
218
+ if (account) {
219
+ let off: { deactivated?: true } = account.deactivatedAt ? { deactivated: true } : {};
220
+ const ownPassword = Boolean(account.hasPassword || account.isEnvAdmin);
221
+ let passwordFlags: { passwordSet?: boolean; hasOwnPassword?: boolean } = {};
222
+ if (password && !account.deactivatedAt) {
223
+ if (ownPassword) {
224
+ passwordFlags = { hasOwnPassword: true };
225
+ } else {
226
+ try {
227
+ const reply = await api.createAccount(email, '', password, { keepExistingPassword: true });
228
+ // Not set: since the list was read it was switched off, or got a password of its own.
229
+ if (reply?.passwordSet !== false) passwordFlags = { passwordSet: true };
230
+ else if (reply.deactivated) off = { deactivated: true };
231
+ else passwordFlags = { hasOwnPassword: true };
232
+ } catch (err) {
233
+ const passwordError = err instanceof Error ? err.message : 'Could not set the password';
234
+ outcomes.push({ email, status: 'existing', passwordError });
235
+ continue;
236
+ }
237
+ }
238
+ } else if (ownPassword && !account.deactivatedAt) {
239
+ passwordFlags = { hasOwnPassword: true };
240
+ }
241
+ const base = { email, status: 'existing' as const, ...off, ...passwordFlags };
242
+ if (role !== 'admin' || off.deactivated) {
243
+ outcomes.push(base);
139
244
  } else if (admins?.has(email.toLowerCase())) {
140
- outcomes.push({ email, status: 'existing', alreadyAdmin: true, ...off });
245
+ outcomes.push({ ...base, alreadyAdmin: true });
141
246
  } else {
142
247
  try {
143
- await api.addMember(ADMIN_ROLE, email);
144
- outcomes.push({ email, status: 'existing', promoted: true, ...off });
248
+ await api.addMember(ADMIN_ROLE, email, { ifActive: true });
249
+ outcomes.push({ ...base, promoted: true });
145
250
  } catch (err) {
251
+ if (isSwitchedOff(err)) {
252
+ outcomes.push({ ...base, deactivated: true });
253
+ continue;
254
+ }
146
255
  const roleError = err instanceof Error ? err.message : 'Could not make them an admin';
147
- outcomes.push({ email, status: 'existing', roleError, ...off });
256
+ outcomes.push({ ...base, roleError });
148
257
  }
149
258
  }
150
259
  continue;
151
260
  }
261
+ let created: { passwordSet?: boolean; notified?: string[] } = {};
262
+ /**
263
+ * Not on the list, but there by the time of the write — with its own
264
+ * password, or switched off — and left as it was.
265
+ */
266
+ let appeared: { hasOwnPassword: true } | { deactivated: true } | null = null;
267
+ /** How the deployment told the person, when its listeners did (a new account only). */
268
+ const told = (reply: { notified?: string[] } | void): { notified?: string[] } =>
269
+ reply?.notified && reply.notified.length > 0 ? { notified: reply.notified } : {};
152
270
  try {
153
- await api.createAccount(email, '');
271
+ if (password) {
272
+ const reply = await api.createAccount(email, '', password, { keepExistingPassword: true });
273
+ if (reply?.passwordSet === false) appeared = reply.deactivated ? { deactivated: true } : { hasOwnPassword: true };
274
+ else created = { passwordSet: true, ...told(reply) };
275
+ } else {
276
+ created = told(await api.createAccount(email, ''));
277
+ }
154
278
  } catch (err) {
155
279
  const message = err instanceof Error ? err.message : 'Could not create account';
156
280
  const kind = (err as { kind?: unknown } | null)?.kind;
@@ -159,17 +283,31 @@ export async function sendInvites(
159
283
  );
160
284
  continue;
161
285
  }
162
- if (role !== 'admin') {
163
- outcomes.push({ email, status: 'created', role });
286
+ if (role !== 'admin' || (appeared && 'deactivated' in appeared)) {
287
+ outcomes.push(
288
+ appeared ? { email, status: 'existing', ...appeared } : { email, status: 'created', role, ...created },
289
+ );
164
290
  continue;
165
291
  }
166
292
  try {
167
- await api.addMember(ADMIN_ROLE, email);
168
- outcomes.push({ email, status: 'created', role: 'admin' });
293
+ await api.addMember(ADMIN_ROLE, email, { ifActive: true });
294
+ outcomes.push(
295
+ appeared
296
+ ? { email, status: 'existing', ...appeared, promoted: true }
297
+ : { email, status: 'created', role: 'admin', ...created },
298
+ );
169
299
  } catch (err) {
300
+ if (isSwitchedOff(err)) {
301
+ outcomes.push({ email, status: 'existing', deactivated: true });
302
+ continue;
303
+ }
170
304
  const roleError = err instanceof Error ? err.message : 'Could not make them an admin';
171
- outcomes.push({ email, status: 'created', role: 'member', roleError });
305
+ outcomes.push(
306
+ appeared
307
+ ? { email, status: 'existing', ...appeared, roleError }
308
+ : { email, status: 'created', role: 'member', roleError, ...created },
309
+ );
172
310
  }
173
311
  }
174
- return outcomes;
312
+ return { status: 'sent', outcomes };
175
313
  }
@@ -9,14 +9,17 @@ import { createContext, useContext } from 'react';
9
9
  * What the invite entry points share: a way to open THE invite dialog, and a
10
10
  * counter that moves every time it invited somebody.
11
11
  *
12
- * Two places open it — the toolbar's Invite button and the "Get set up"
13
- * column — and they must open the same dialog rather than one each, or the
14
- * column's "Invite your team" would tick from one and not the other. The
12
+ * Several places open it — the toolbar's Invite button, the "Get set up"
13
+ * column, User accounts' "Invite new users" row and Manage access's Invite
14
+ * on a person with no account — and they must open the same dialog rather
15
+ * than one each, or the column's "Invite your team" would tick from one and
16
+ * not the other. The
15
17
  * counter is how the column hears about it: it re-reads the account list
16
18
  * when `invitedRevision` moves instead of polling for a change it caused.
17
19
  */
18
20
  export interface InviteDialogController {
19
- open(): void;
21
+ /** `emails` fills in the address field (Manage access's Invite). */
22
+ open(options?: { emails?: string[] }): void;
20
23
  invitedRevision: number;
21
24
  }
22
25
 
@@ -12,17 +12,25 @@ import { InviteDialogContext } from './invite-dialog.context';
12
12
  * reads nothing, not even the admin verdict — until somebody asks for it.
13
13
  */
14
14
  export function InviteDialogProvider({ children }: { children: ReactNode }) {
15
- const [isOpen, setIsOpen] = useState(false);
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);
16
18
  const [invitedRevision, setInvitedRevision] = useState(0);
17
- const open = useCallback(() => setIsOpen(true), []);
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
+ }, []);
18
25
  const value = useMemo(() => ({ open, invitedRevision }), [open, invitedRevision]);
19
26
  return (
20
27
  <InviteDialogContext.Provider value={value}>
21
28
  {children}
22
- {isOpen && (
29
+ {openWith && (
23
30
  <InviteDialog
24
31
  open
25
- onClose={() => setIsOpen(false)}
32
+ initialEmails={openWith}
33
+ onClose={() => setOpenWith(null)}
26
34
  onInvited={() => setInvitedRevision((r) => r + 1)}
27
35
  />
28
36
  )}
@@ -41,11 +41,13 @@ export interface CommandContext {
41
41
  /** THE invite dialog, or null where none is mounted. */
42
42
  invite: InviteDialogController | null;
43
43
  /**
44
- * Create an untitled page in the Knowledge folder and open it for editing
45
- * (`useCreatePage`); null until the workspace knows where that folder is.
44
+ * Create an untitled page in a Knowledge folder the person may write and
45
+ * open it for editing (`useCreatePage`); null until the workspace knows
46
+ * where that is, and for someone who may write no Knowledge folder.
47
+ * Resolves with null when a refused write found nowhere left to write.
46
48
  * Rejects with a message ready to show.
47
49
  */
48
- createPage: (() => Promise<string>) | null;
50
+ createPage: (() => Promise<string | null>) | null;
49
51
  /** The connect-your-agent onboarding is still open for this person. */
50
52
  onboardingPending: boolean;
51
53
  }
@@ -111,7 +113,11 @@ const EDIT_PAGE: CommandAction = {
111
113
  },
112
114
  };
113
115
 
114
- /** Admins only, like the toolbar's Invite button: creating accounts is an admin act. */
116
+ /**
117
+ * Admins only: creating accounts is an admin act. The toolbar's Invite shows to
118
+ * everyone and tells a non-admin whom to ask; a command menu entry that only
119
+ * answers "ask an admin" would be noise in a list of things you can do.
120
+ */
115
121
  const INVITE: CommandAction = {
116
122
  id: 'invite',
117
123
  label: 'Invite people',
@@ -28,7 +28,7 @@ export function useCommandContext(): CommandContext {
28
28
  const editablePage = useEditablePage();
29
29
  const { openWorkspacePath } = useFileNav();
30
30
  const invite = useInviteDialog();
31
- const { knowledgeRoot, createPage } = useCreatePage();
31
+ const { knowledgeRoot, createPage, pageFolder } = useCreatePage();
32
32
  const { showPill } = useOnboarding();
33
33
  return useMemo(
34
34
  () => ({
@@ -40,10 +40,12 @@ export function useCommandContext(): CommandContext {
40
40
  editablePage,
41
41
  openWorkspacePath,
42
42
  invite,
43
- createPage: knowledgeRoot ? createPage : null,
43
+ // Not offered to someone who may write no Knowledge folder, nor before
44
+ // that is known; the C shortcut only runs commands that are offered.
45
+ createPage: knowledgeRoot && pageFolder ? createPage : null,
44
46
  onboardingPending: showPill,
45
47
  }),
46
- [navigate, user, isAdmin, activeAppId, openFilePath, editablePage, openWorkspacePath, invite, knowledgeRoot, createPage, showPill],
48
+ [navigate, user, isAdmin, activeAppId, openFilePath, editablePage, openWorkspacePath, invite, knowledgeRoot, pageFolder, createPage, showPill],
47
49
  );
48
50
  }
49
51
 
@@ -6,6 +6,7 @@ import { useMediaQuery } from '../../layout/hooks/useMediaQuery';
6
6
  import { TOOLBAR_STACK_QUERY } from '../../layout/breakpoints';
7
7
  import { cn } from '../../../lib/utils';
8
8
  import { PRODUCT_NAME, ProductName } from '../../../core/ProductName';
9
+ import { useMakerLinkLabel, useMakerUrl } from '../../../core/maker-url';
9
10
 
10
11
  const MENU_ID = 'app-switcher-menu';
11
12
 
@@ -116,6 +117,8 @@ function AppToggle({ apps, activeId }: SwitcherProps) {
116
117
  */
117
118
  function AppMenu({ apps, activeId }: SwitcherProps) {
118
119
  const navigate = useNavigate();
120
+ const makerUrl = useMakerUrl();
121
+ const makerLabel = useMakerLinkLabel(PRODUCT_NAME);
119
122
  const [open, setOpen] = useState(false);
120
123
  const ref = useRef<HTMLDivElement>(null);
121
124
  const buttonRef = useRef<HTMLButtonElement>(null);
@@ -208,6 +211,22 @@ function AppMenu({ apps, activeId }: SwitcherProps) {
208
211
  </span>
209
212
  </button>
210
213
  ))}
214
+ {/* The maker's link, which the trigger cannot carry: a link inside a
215
+ button is not allowed. On a compact toolbar this is the only way
216
+ from a page in the app to the maker's site, or to wherever the
217
+ registry sends it, such as the hosted cloud's Impressum, under
218
+ the registry's own label for it when it names one. */}
219
+ <div role="separator" className="my-1 border-t border-line" />
220
+ <a
221
+ role="menuitem"
222
+ href={makerUrl}
223
+ target="_blank"
224
+ rel="noopener noreferrer"
225
+ onClick={close}
226
+ className="block px-3 py-2 text-xs text-ink-muted hover:bg-hover hover:text-ink"
227
+ >
228
+ {makerLabel}
229
+ </a>
211
230
  </div>
212
231
  )}
213
232
  </div>
@@ -70,8 +70,16 @@ function renderSwitcher(opts?: {
70
70
  /** Registry apps past the two core ones. */
71
71
  extraApps?: AppDef[];
72
72
  shellActiveId?: string;
73
+ /** Where the maker's name leads, as a distribution sets it. */
74
+ makerLink?: string;
75
+ /** What the menu's entry for that place says, as a distribution sets it. */
76
+ makerLinkLabel?: string;
73
77
  }) {
74
- const registry = makeRegistry({ apps: [...coreLikeApps, ...(opts?.extraApps ?? [])] });
78
+ const registry = makeRegistry({
79
+ apps: [...coreLikeApps, ...(opts?.extraApps ?? [])],
80
+ ...(opts?.makerLink !== undefined ? { makerLink: opts.makerLink } : {}),
81
+ ...(opts?.makerLinkLabel !== undefined ? { makerLinkLabel: opts.makerLinkLabel } : {}),
82
+ });
75
83
  const tree = (
76
84
  <MemoryRouter initialEntries={[opts?.path ?? '/']}>
77
85
  <AppSwitcher />
@@ -187,6 +195,40 @@ describe('AppSwitcher as a segmented toggle (few apps, wide toolbar)', () => {
187
195
  expect(screen.queryByRole('navigation', { name: 'Apps' })).not.toBeInTheDocument();
188
196
  expect(screen.getByRole('button', { name: 'Switch app' })).toHaveTextContent('Knowledge');
189
197
  });
198
+
199
+ // The trigger holds the name as text, since a link cannot sit inside a
200
+ // button, so the menu carries the link: without it a page in the app on a
201
+ // phone would have no way to where the registry sends the maker's name,
202
+ // which for the hosted cloud is its Impressum.
203
+ it("links the maker's name at the foot of the compact menu, where the registry says", async () => {
204
+ setViewportWidth(600);
205
+ renderSwitcher({ path: '/workspace', makerLink: '/impressum' });
206
+ await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
207
+ const link = within(screen.getByRole('menu')).getByRole('menuitem', { name: 'Hexis by Bevel' });
208
+ expect(link).toHaveAttribute('href', '/impressum');
209
+ expect(link).toHaveAttribute('target', '_blank');
210
+ });
211
+
212
+ // The hosted cloud's Impressum must be recognisable as one from a page in
213
+ // the app, not only behind the maker's name.
214
+ it("names the maker's link in the compact menu as the registry says", async () => {
215
+ setViewportWidth(600);
216
+ renderSwitcher({ path: '/workspace', makerLink: '/impressum', makerLinkLabel: 'Impressum' });
217
+ await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
218
+ const link = within(screen.getByRole('menu')).getByRole('menuitem', { name: 'Impressum' });
219
+ expect(link).toHaveAttribute('href', '/impressum');
220
+ expect(within(screen.getByRole('menu')).queryByRole('menuitem', { name: 'Hexis by Bevel' })).toBeNull();
221
+ });
222
+
223
+ it("names it after the product when the registry's label is blank, as when it is absent", async () => {
224
+ setViewportWidth(600);
225
+ renderSwitcher({ path: '/workspace', makerLink: '/impressum', makerLinkLabel: ' ' });
226
+ await userEvent.click(screen.getByRole('button', { name: 'Switch app' }));
227
+ expect(within(screen.getByRole('menu')).getByRole('menuitem', { name: 'Hexis by Bevel' })).toHaveAttribute(
228
+ 'href',
229
+ '/impressum',
230
+ );
231
+ });
190
232
  });
191
233
 
192
234
  /**
@@ -268,7 +310,10 @@ describe('AppSwitcher as a menu (more than three apps)', () => {
268
310
  expect.stringContaining('Skills & Tools'),
269
311
  expect.stringContaining('Assistant'),
270
312
  expect.stringContaining('Insights'),
313
+ // Then the maker's link, to the maker's site unless the registry says otherwise.
314
+ 'Hexis by Bevel',
271
315
  ]);
316
+ expect(items.at(-1)).toHaveAttribute('href', 'https://bevel.software');
272
317
  });
273
318
 
274
319
  it('marks the app matching the current location as current', async () => {
@@ -43,9 +43,16 @@ vi.mock('../../../library/services/plugins.api', async (importOriginal) => ({
43
43
  }));
44
44
  // New page's own naming and retrying is `useCreatePage`'s, pinned by the Get
45
45
  // set up column's suite; here it is the command that calls it.
46
- const createPage = vi.hoisted(() => vi.fn<() => Promise<string>>());
46
+ const createPage = vi.hoisted(() => vi.fn<() => Promise<string | null>>());
47
+ // Where New page would write; null for someone who may write no Knowledge folder.
48
+ const pageTarget = vi.hoisted(() => ({ folder: 'knowledge-base/KnowledgeBase' as string | null }));
47
49
  vi.mock('../../../workspace/hooks/useCreatePage', () => ({
48
- useCreatePage: () => ({ knowledgeRoot: 'knowledge-base/KnowledgeBase', createPage }),
50
+ useCreatePage: () => ({
51
+ knowledgeRoot: 'knowledge-base/KnowledgeBase',
52
+ createPage,
53
+ pageFolder: pageTarget.folder,
54
+ pageFolderSettled: true,
55
+ }),
49
56
  }));
50
57
  // The onboarding write is not what these tests are about.
51
58
  vi.mock('../../../../lib/api', () => ({ authFetch: vi.fn(async () => ({ ok: true, status: 200 })) }));
@@ -170,6 +177,7 @@ beforeEach(() => {
170
177
  publishEditablePage(null);
171
178
  inviteOpen.mockReset();
172
179
  createPage.mockReset().mockResolvedValue('knowledge-base/KnowledgeBase/Untitled.md');
180
+ pageTarget.folder = 'knowledge-base/KnowledgeBase';
173
181
  api.listSkills.mockReset().mockResolvedValue([
174
182
  { name: 'pricing-calculator', description: '', path: 'Plugins/GTM/skills/pricing-calculator' },
175
183
  ]);
@@ -674,6 +682,30 @@ describe('SearchPalette: single-key shortcuts', () => {
674
682
  expect(screen.queryByRole('combobox')).toBeNull();
675
683
  });
676
684
 
685
+ it('C does nothing, and the menu offers no New page, for someone who may write no Knowledge folder', async () => {
686
+ pageTarget.folder = null;
687
+ const user = userEvent.setup();
688
+ renderPalette();
689
+ press('c');
690
+ expect(createPage).not.toHaveBeenCalled();
691
+ expect(screen.queryByRole('combobox')).toBeNull();
692
+ await user.click(trigger());
693
+ expect(screen.queryByRole('option', { name: /^New page/ })).toBeNull();
694
+ await user.type(input(), 'new page');
695
+ expect(screen.queryByRole('option', { name: /^New page/ })).toBeNull();
696
+ });
697
+
698
+ it('closes quietly when a refused write found nowhere left to write', async () => {
699
+ createPage.mockResolvedValue(null);
700
+ const user = userEvent.setup();
701
+ renderPalette();
702
+ await user.click(trigger());
703
+ await user.click(screen.getByRole('option', { name: /^New page/ }));
704
+ expect(createPage).toHaveBeenCalledTimes(1);
705
+ expect(screen.queryByRole('combobox')).toBeNull();
706
+ expect(screen.queryByRole('alert')).toBeNull();
707
+ });
708
+
677
709
  it('G then K goes to Knowledge, G then S to Skills & Tools', () => {
678
710
  renderPalette();
679
711
  press('g');