@bevel-software/platform-core-frontend 0.22.0 → 0.24.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.
Files changed (45) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +2 -0
  3. package/src/core/registry.ts +83 -0
  4. package/src/lib/api.ts +49 -0
  5. package/src/modules/access/api.ts +6 -4
  6. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +89 -1
  7. package/src/modules/admin/components/UserAccountsPage.tsx +93 -5
  8. package/src/modules/auth/components/LoginScreen.tsx +3 -0
  9. package/src/modules/auth/services/account.api.ts +26 -3
  10. package/src/modules/change-requests/components/BranchFilePreview.tsx +7 -1
  11. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +89 -10
  12. package/src/modules/git/__tests__/HistoryVersionPreview.test.tsx +479 -0
  13. package/src/modules/git/components/FileHistoryPanel.tsx +52 -65
  14. package/src/modules/git/components/HistoryVersionPreview.tsx +410 -0
  15. package/src/modules/layout/__tests__/ReadOnlyBanner.test.tsx +157 -0
  16. package/src/modules/layout/components/ReadOnlyBanner.tsx +96 -0
  17. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +296 -0
  18. package/src/modules/setup/__tests__/setup.repository.test.tsx +114 -24
  19. package/src/modules/setup/__tests__/setup.test.tsx +5 -3
  20. package/src/modules/setup/components/SetupScreen.tsx +187 -46
  21. package/src/modules/setup/services/setup.api.ts +78 -3
  22. package/src/modules/workspace/components/FileExplorer.tsx +140 -12
  23. package/src/modules/workspace/components/FileViewer.tsx +11 -1
  24. package/src/modules/workspace/components/TreeActionConfirm.tsx +5 -7
  25. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +603 -29
  26. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +23 -6
  27. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +41 -8
  28. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +20 -5
  29. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +39 -16
  30. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +27 -7
  31. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +20 -5
  32. package/src/modules/workspace/components/renderers/RetryReadButton.tsx +37 -0
  33. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +20 -5
  34. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +186 -7
  35. package/src/modules/workspace/components/renderers/__tests__/readPane.test.tsx +59 -0
  36. package/src/modules/workspace/components/renderers/htmlSandbox.ts +80 -20
  37. package/src/modules/workspace/components/renderers/index.ts +6 -1
  38. package/src/modules/workspace/components/renderers/readPane.ts +22 -0
  39. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +50 -9
  40. package/src/modules/workspace/components/renderers/useReadRetry.ts +27 -0
  41. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +79 -0
  42. package/src/modules/workspace/routing/kb-routes.ts +25 -10
  43. package/src/modules/workspace/services/workspace.api.ts +22 -1
  44. package/src/shared/markdown/__tests__/hrefs.test.ts +111 -0
  45. package/src/shared/markdown/hrefs.ts +80 -4
@@ -21,7 +21,7 @@ vi.mock('../../settings/services/github-facade.api', () => ({
21
21
  }));
22
22
 
23
23
  import { SetupScreen } from '../components/SetupScreen';
24
- import { SettingsProblems, type GitMode, type RepositoryStatus, type SettingStatus } from '../services/setup.api';
24
+ import { RepositoryChangeNeedsConfirmation, SettingsProblems, type GitMode, type RepositoryStatus, type SettingStatus } from '../services/setup.api';
25
25
 
26
26
  const KB = 'knowledge-base' as const;
27
27
  const setting = (key: string, extra: Partial<SettingStatus> = {}): SettingStatus => ({
@@ -242,41 +242,81 @@ describe('SetupScreen: moving a deployment to another repository', () => {
242
242
  expect(screen.queryByTestId('moves-repository')).toBeNull();
243
243
  });
244
244
 
245
- const moveButton = () => screen.getByRole('button', { name: 'Save and move' });
246
- const agree = () => userEvent.click(screen.getByRole('checkbox', { name: /Move this deployment from/ }));
245
+ /** The server's refusal of a save that moves, until the admin has answered. */
246
+ const asksFirst = (openChangeRequests = 0, to: GitMode = 'managed') =>
247
+ api.saveSettings.mockImplementation(async (_settings: unknown, confirm?: string) => {
248
+ if (!confirm) throw new RepositoryChangeNeedsConfirmation(openChangeRequests, 'token', to);
249
+ return {
250
+ ...saved(to, true),
251
+ repositoryChange: { choice: confirm, closedChangeRequests: confirm === 'close' ? openChangeRequests : 0 },
252
+ };
253
+ });
254
+ const question = () => screen.findByTestId('repository-change-confirm');
255
+ const confirmMove = () => userEvent.click(screen.getByRole('button', { name: 'Move the deployment' }));
247
256
 
248
257
  /**
249
258
  * The tab is the choice, and the tab is a screen above the button. An
250
259
  * admin who opens another way to read about it, changes a sign-in field
251
260
  * and saves must not have moved the deployment to an empty repository.
261
+ * The server refuses that save, and the screen puts the question.
252
262
  */
253
263
  it('does not move on a save the admin was not asked about', async () => {
254
- api.saveSettings.mockResolvedValue({ ...saved('token', true), repository: offering('token', 'managed') });
264
+ asksFirst();
255
265
  show({ configured: true, variant: 'settings' });
256
266
  await userEvent.click(tab('Managed for you'));
257
267
  await userEvent.type(screen.getByLabelText('Knowledge folder', { exact: false }), 'Docs');
268
+ await save();
258
269
 
259
270
  // Asked at the button, naming what is left and what is moved to.
260
- const asked = screen.getByTestId('confirm-move');
261
- expect(asked).toHaveTextContent('Move this deployment from “Address and token” to “Managed for you”');
271
+ const asked = await question();
272
+ expect(asked).toHaveTextContent('Move this deployment from “Address and token” to “Managed for you”?');
262
273
  expect(asked).toHaveTextContent('Nothing is deleted');
263
- expect(screen.queryByRole('button', { name: 'Save and continue' })).toBeNull();
264
- expect(moveButton()).toBeDisabled();
265
- await userEvent.click(moveButton());
266
- expect(api.saveSettings).not.toHaveBeenCalled();
274
+ expect(asked).toHaveTextContent('with no restart');
275
+ // One refused attempt, and the save button waits for the answer.
276
+ expect(api.saveSettings).toHaveBeenCalledTimes(1);
277
+ expect(screen.getByRole('button', { name: 'Save and continue' })).toBeDisabled();
267
278
  });
268
279
 
269
280
  it('sends the move once the admin has said yes, and nothing of the repository it leaves', async () => {
270
- api.saveSettings.mockResolvedValue({ ...saved('token', true), restartRequired: true, repository: offering('token', 'managed') });
281
+ asksFirst();
271
282
  show({ configured: true, variant: 'settings' });
272
283
  await userEvent.click(tab('Managed for you'));
273
- await agree();
274
- await userEvent.click(moveButton());
275
- await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'managed' }));
284
+ await save();
285
+ await question();
286
+ await confirmMove();
287
+ await waitFor(() => expect(api.saveSettings).toHaveBeenLastCalledWith({ gitMode: 'managed' }, 'keep', 0));
276
288
  expect(api.testConnection).not.toHaveBeenCalled();
289
+ // Moved on the save: said so, with no restart owed.
290
+ expect(await screen.findByTestId('repository-changed')).toHaveTextContent('now works on the new repository');
277
291
  });
278
292
 
279
293
  it('asks again for another move: a yes to one is not a yes to the next', async () => {
294
+ asksFirst();
295
+ render(
296
+ <SetupScreen
297
+ settings={settingsOf(true)}
298
+ onSaved={() => {}}
299
+ variant="settings"
300
+ repository={{ mode: 'token', chosen: 'token', modes: ['managed', 'github-app', 'token'] }}
301
+ />,
302
+ );
303
+ await userEvent.click(tab('Managed for you'));
304
+ await save();
305
+ await question();
306
+ await confirmMove();
307
+ await screen.findByTestId('repository-changed');
308
+ expect(api.saveSettings).toHaveBeenCalledTimes(2);
309
+
310
+ // Another move, after a yes: its save carries no answer, and is asked.
311
+ await userEvent.click(tab('Address and token'));
312
+ await save();
313
+ await question();
314
+ expect(api.saveSettings).toHaveBeenCalledTimes(3);
315
+ expect(api.saveSettings.mock.calls[2]).toHaveLength(1);
316
+ });
317
+
318
+ it('takes the question down when another tab is opened: it was about another move', async () => {
319
+ asksFirst();
280
320
  render(
281
321
  <SetupScreen
282
322
  settings={settingsOf(true)}
@@ -286,11 +326,56 @@ describe('SetupScreen: moving a deployment to another repository', () => {
286
326
  />,
287
327
  );
288
328
  await userEvent.click(tab('Managed for you'));
289
- await agree();
290
- expect(moveButton()).toBeEnabled();
329
+ await save();
330
+ await question();
291
331
  await userEvent.click(tab('GitHub'));
292
- expect(screen.getByRole('checkbox', { name: /to “GitHub”/ })).not.toBeChecked();
293
- expect(moveButton()).toBeDisabled();
332
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
333
+ expect(api.saveSettings).toHaveBeenCalledTimes(1);
334
+ });
335
+
336
+ it('closes the open change requests when the admin picks that, and says so', async () => {
337
+ asksFirst(2);
338
+ show({ configured: true, variant: 'settings' });
339
+ await userEvent.click(tab('Managed for you'));
340
+ await save();
341
+ await question();
342
+ await userEvent.click(screen.getByRole('radio', { name: /Close them as/ }));
343
+ await confirmMove();
344
+ await waitFor(() => expect(api.saveSettings).toHaveBeenLastCalledWith({ gitMode: 'managed' }, 'close', 2));
345
+ expect(await screen.findByTestId('repository-changed')).toHaveTextContent(
346
+ '2 change requests were closed as “repository replaced”.',
347
+ );
348
+ });
349
+
350
+ it('asks again when the count of open change requests changed while the question stood', async () => {
351
+ let open = 0;
352
+ api.saveSettings.mockImplementation(async (_settings: unknown, confirm?: string, seen?: number) => {
353
+ if (!confirm || seen !== open) throw new RepositoryChangeNeedsConfirmation(open, 'token', 'managed');
354
+ return { ...saved('managed', true), repositoryChange: { choice: confirm, closedChangeRequests: 0 } };
355
+ });
356
+ show({ configured: true, variant: 'settings' });
357
+ await userEvent.click(tab('Managed for you'));
358
+ await save();
359
+ await question();
360
+ expect(screen.queryAllByRole('radio')).toEqual([]);
361
+
362
+ // A request is opened before the admin answers.
363
+ open = 1;
364
+ await confirmMove();
365
+ await waitFor(() => expect(screen.getByTestId('repository-change-confirm')).toHaveTextContent('There is 1 open change request.'));
366
+ expect(screen.queryByTestId('repository-changed')).toBeNull();
367
+ });
368
+
369
+ it('cancelling leaves the deployment where it is', async () => {
370
+ asksFirst(2);
371
+ show({ configured: true, variant: 'settings' });
372
+ await userEvent.click(tab('Managed for you'));
373
+ await save();
374
+ expect(await question()).toHaveTextContent('There are 2 open change requests.');
375
+ await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
376
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
377
+ expect(api.saveSettings).toHaveBeenCalledTimes(1);
378
+ expect(screen.getByRole('button', { name: 'Save and continue' })).toBeEnabled();
294
379
  });
295
380
 
296
381
  it('asks nothing of a save that stays where the deployment is', async () => {
@@ -298,10 +383,10 @@ describe('SetupScreen: moving a deployment to another repository', () => {
298
383
  show({ configured: true, variant: 'settings' });
299
384
  await userEvent.click(tab('Managed for you'));
300
385
  await userEvent.click(tab('Address and token'));
301
- expect(screen.queryByTestId('confirm-move')).toBeNull();
302
386
  await userEvent.type(screen.getByLabelText('Knowledge folder', { exact: false }), 'Docs');
303
387
  await save();
304
388
  await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ knowledgeBaseDir: 'Docs' }));
389
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
305
390
  });
306
391
 
307
392
  it('asks nothing on a deployment that has no repository to leave', async () => {
@@ -309,14 +394,19 @@ describe('SetupScreen: moving a deployment to another repository', () => {
309
394
  show();
310
395
  await userEvent.click(tab('Address and token'));
311
396
  expect(screen.queryByTestId('moves-repository')).toBeNull();
312
- expect(screen.queryByTestId('confirm-move')).toBeNull();
313
397
  await userEvent.click(tab('Managed for you'));
314
398
  await save();
315
399
  await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'managed' }));
400
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
316
401
  });
317
402
  });
318
403
 
319
- describe('SetupScreen: between a move and the restart it owes', () => {
404
+ /**
405
+ * A confirmed move takes effect on its save, so this state is not one a move
406
+ * leaves behind any more. It is still one a server can report (a way chosen
407
+ * that it has not put in effect), and the screen must read it truthfully.
408
+ */
409
+ describe('SetupScreen: a way chosen that is not in effect yet', () => {
320
410
  it('opens on the way chosen, and says the deployment is still on the one it has', () => {
321
411
  show({ configured: true, mode: 'token', chosen: 'managed', variant: 'settings' });
322
412
  expect(tab('Managed for you')).toHaveAttribute('aria-selected', 'true');
@@ -325,7 +415,7 @@ describe('SetupScreen: between a move and the restart it owes', () => {
325
415
  expect(pending).toHaveTextContent('still working on “Address and token”');
326
416
  // The move was made: it is not offered again, and not asked about again.
327
417
  expect(screen.queryByTestId('moves-repository')).toBeNull();
328
- expect(screen.queryByTestId('confirm-move')).toBeNull();
418
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
329
419
  });
330
420
 
331
421
  it('does not send the move a second time with a save about something else', async () => {
@@ -341,7 +431,7 @@ describe('SetupScreen: between a move and the restart it owes', () => {
341
431
  show({ configured: true, mode: 'token', chosen: 'managed', variant: 'settings' });
342
432
  await userEvent.click(tab('Address and token'));
343
433
  expect(screen.getByTestId('move-taken-back')).toHaveTextContent('Saving takes the move back');
344
- expect(screen.queryByTestId('confirm-move')).toBeNull();
434
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
345
435
  await save();
346
436
  await waitFor(() => expect(api.saveSettings).toHaveBeenCalledWith({ gitMode: 'token' }));
347
437
  });
@@ -362,7 +452,7 @@ describe('SetupScreen: a way chosen by the environment', () => {
362
452
  expect(screen.getByTestId('repository-pinned')).toHaveTextContent('Set by the GIT_MODE environment variable');
363
453
  await userEvent.click(tab('Address and token'));
364
454
  expect(tab('Managed for you')).toHaveAttribute('aria-selected', 'true');
365
- expect(screen.queryByTestId('confirm-move')).toBeNull();
455
+ expect(screen.queryByTestId('repository-change-confirm')).toBeNull();
366
456
  });
367
457
 
368
458
  it('says nothing of the kind when the admin chose', () => {
@@ -298,11 +298,13 @@ describe('SetupScreen', () => {
298
298
  await userEvent.click(screen.getByRole('button', { name: 'Save and continue' }));
299
299
 
300
300
  await waitFor(() => expect(api.testConnection).toHaveBeenCalled());
301
- expect(await screen.findByRole('alert')).toHaveTextContent(/Not saved/);
301
+ // The refusal carries the host's OWN words: "fix the connection above" on
302
+ // its own leaves an admin rereading a form that looks perfectly correct.
303
+ const refusal = await screen.findByRole('alert');
304
+ expect(refusal).toHaveTextContent(/Not saved/);
305
+ expect(refusal).toHaveTextContent('No repository at that URL — or the token cannot see it.');
302
306
  expect(api.saveSettings).not.toHaveBeenCalled();
303
307
  expect(reload).not.toHaveBeenCalled();
304
- // And the host's own words are on screen, not just the refusal.
305
- expect(screen.getByText(/No repository at that URL/)).toBeInTheDocument();
306
308
  });
307
309
 
308
310
  /**
@@ -20,6 +20,7 @@ import {
20
20
  testConnection,
21
21
  KbInitFailed,
22
22
  testOidc,
23
+ RepositoryChangeNeedsConfirmation,
23
24
  SettingsProblems,
24
25
  type ConnectionTest,
25
26
  type KbInitFailure,
@@ -27,6 +28,8 @@ import {
27
28
  type OidcTest,
28
29
  type OidcVerification,
29
30
  type GitMode,
31
+ type RepositoryChangeChoice,
32
+ type RepositoryChangeResult,
30
33
  type RepositoryStatus,
31
34
  type SettingStatus,
32
35
  type SyncNowResult,
@@ -473,6 +476,31 @@ export function SetupScreen({
473
476
  setInitFailure(kbInit);
474
477
  }
475
478
  }
479
+ /**
480
+ * The move to another repository the server has REFUSED until it is
481
+ * confirmed: how many change requests were open at that moment, and the
482
+ * way left and the way moved to when the server tells them apart. Null
483
+ * when there is nothing to confirm.
484
+ *
485
+ * THE ONE QUESTION A MOVE IS ASKED, whichever kind it is: another address,
486
+ * another repository on GitHub, another way of having one. The server
487
+ * decides what is a move, so the screen does not guess at it beforehand.
488
+ *
489
+ * Nothing was saved and nothing was destroyed while this stands: the answer
490
+ * is a decision only the admin can make, and the draft is kept exactly as
491
+ * typed so the confirmed save re-sends it.
492
+ */
493
+ const [repositoryChange, setRepositoryChange] = useState<{
494
+ openChangeRequests: number;
495
+ from?: GitMode;
496
+ to?: GitMode;
497
+ /** The move the question was asked about, so it is not shown for another one. */
498
+ target: string;
499
+ } | null>(null);
500
+ /** What to do with the open change requests. Keeping them is the safe default: nothing closes by hesitating. */
501
+ const [changeChoice, setChangeChoice] = useState<RepositoryChangeChoice>('keep');
502
+ /** What the save that changed the repository did, so the screen can say so afterwards. */
503
+ const [repositoryChanged, setRepositoryChanged] = useState<RepositoryChangeResult | null>(null);
476
504
  const [retrying, setRetrying] = useState(false);
477
505
  const [syncing, setSyncing] = useState(false);
478
506
  /** What the last "Sync now" from THIS page came back with (a failure to ask is `error`). */
@@ -558,8 +586,9 @@ export function SetupScreen({
558
586
  * thing drawn.
559
587
  *
560
588
  * Two ways are told apart: the one IN EFFECT, which the running
561
- * deployment is on, and the one chosen, which a restart puts in effect.
562
- * They differ between a move and the restart the move owes.
589
+ * deployment is on, and the one chosen. A move takes effect on the save
590
+ * that confirms it, so they differ only where the server reports a choice
591
+ * it has not put in effect, which a restart then does.
563
592
  */
564
593
  const inEffect = repository?.mode ?? null;
565
594
  const chosen = repository ? (repository.chosen ?? repository.mode) : null;
@@ -577,26 +606,27 @@ export function SetupScreen({
577
606
  repository ? ((Object.keys(TAB_KEYS) as GitMode[]).find((mode) => TAB_KEYS[mode].includes(key)) ?? null) : null;
578
607
  /** Whether the repository is reached by an address and a token: the fields, the test, the proof. */
579
608
  const byAddress = !repository || gitTab === 'token';
580
- /** A move was saved and the restart it owes has not happened: the deployment is still on the way it was. */
609
+ /** A way was chosen that the server has not put in effect: the deployment is still on the way it was. */
581
610
  const movePending = inEffect !== null && chosen !== inEffect;
582
611
  /**
583
612
  * Saving NOW would choose another way than the one chosen, on a deployment
584
- * that has a repository: a move, or a move taken back. This is what is
585
- * asked about at the button, where the decision is made; an open tab is
586
- * not a decision.
613
+ * that has a repository: a move, or a move taken back. Said on the tab
614
+ * before the button is pressed; the question itself is the server's, asked
615
+ * when the save arrives, because an open tab is not a decision.
587
616
  */
588
617
  const savingMoves = inEffect !== null && gitTab !== chosen;
589
- const movingTo = GIT_MODE_LABEL[gitTab];
590
618
  const movingFrom = inEffect ? GIT_MODE_LABEL[inEffect] : '';
591
- /** A save that moves the deployment away from the way in effect. Taking a move back is not one. */
592
- const mustConfirmMove = savingMoves && gitTab !== inEffect;
593
619
  /**
594
- * The way the admin said yes to moving TO. Held as the way and not as a
595
- * yes, so a yes given to one move is not a yes to another: opening a
596
- * third tab asks again.
620
+ * What a move is a move TO, as far as the screen can tell: the tab, and
621
+ * the address or the repository on GitHub typed on it.
622
+ */
623
+ const moveTarget = [gitTab, draft.kbRepoUrl ?? '', draft.githubRepository ?? ''].join('\n');
624
+ /**
625
+ * The question, while it is still about the move on screen. A yes to one
626
+ * move is not a yes to another: another tab, another address or another
627
+ * repository on GitHub is another move, and the next save asks afresh.
597
628
  */
598
- const [moveConfirmed, setMoveConfirmed] = useState<GitMode | null>(null);
599
- const moveIsConfirmed = moveConfirmed === gitTab;
629
+ const moveAsked = repositoryChange?.target === moveTarget ? repositoryChange : null;
600
630
 
601
631
  /**
602
632
  * What a save sends about the repository, given what was typed: the way
@@ -1052,6 +1082,16 @@ export function SetupScreen({
1052
1082
 
1053
1083
  async function submit(e: FormEvent) {
1054
1084
  e.preventDefault();
1085
+ await saveNow();
1086
+ }
1087
+
1088
+ /**
1089
+ * Store the draft. Called by the form, and again by the repository-change
1090
+ * confirmation with the decision the admin made — the SAME path, so a
1091
+ * confirmed save proves the connection and fills in the branch fields
1092
+ * exactly as an ordinary one does.
1093
+ */
1094
+ async function saveNow(confirmRepositoryChange?: RepositoryChangeChoice) {
1055
1095
  // A save during a sign-in check would clear the draft the check is about.
1056
1096
  if (saving || retrying || oidcTesting) return;
1057
1097
  setSaving(true);
@@ -1061,6 +1101,7 @@ export function SetupScreen({
1061
1101
  // attempt supersedes it — leaving it up put "Saved what you filled in, but
1062
1102
  // this deployment still needs…" directly above this attempt's "Not saved."
1063
1103
  setStillMissing([]);
1104
+ setRepositoryChanged(null);
1064
1105
  try {
1065
1106
  let payload = chosenRepository(draft);
1066
1107
  /** What the host said this time, or null when it could not be asked. */
@@ -1093,13 +1134,18 @@ export function SetupScreen({
1093
1134
  // Includes a probe the server REFUSED (a 4xx comes back as a
1094
1135
  // rejection, not a throw) — that is an answer about these values.
1095
1136
  if (proven && !proven.ok) {
1096
- setError(
1137
+ // THE SERVER'S OWN WORDS FIRST. The sentences below say that the
1138
+ // save did not happen; only the host knows WHY — "there is no
1139
+ // repository at that address", "the host rejected the credentials".
1140
+ // Replacing that with a generic sentence is how an admin is left
1141
+ // reading "fix the connection" with no idea what is wrong with it.
1142
+ const refusal =
1097
1143
  proven.outcome === 'read-only'
1098
1144
  ? 'Not saved. The token can read the repository but cannot write to it — grant it write access and test again.'
1099
1145
  : variant === 'setup'
1100
1146
  ? 'Not saved. Nothing behind this screen works until the repository answers, and it did not — fix the connection above and test it again.'
1101
- : 'Not saved. The repository did not answer with those details — fix the connection above and test it again.',
1102
- );
1147
+ : 'Not saved. The repository did not answer with those details — fix the connection above and test it again.';
1148
+ setError(proven.error ? `${refusal} The server said: ${proven.error}` : refusal);
1103
1149
  return;
1104
1150
  }
1105
1151
  }
@@ -1119,11 +1165,19 @@ export function SetupScreen({
1119
1165
  ) {
1120
1166
  await probe();
1121
1167
  }
1122
- const result = await saveSettings(payload);
1168
+ // An ordinary save is sent exactly as it always was — one argument, and
1169
+ // no `confirmRepositoryChange` in the body. Only the save that answers
1170
+ // the repository-change confirmation carries the answer.
1171
+ const result = confirmRepositoryChange
1172
+ ? await saveSettings(payload, confirmRepositoryChange, moveAsked?.openChangeRequests)
1173
+ : await saveSettings(payload);
1123
1174
  // A save while a failure stands re-ran the initialization, and it held.
1124
1175
  setClearedFailure(initFailure);
1125
1176
  setInitFailure(null);
1126
1177
  setRestartRequired(result.restartRequired);
1178
+ // The confirmation was answered — and the answer went through.
1179
+ setRepositoryChange(null);
1180
+ setRepositoryChanged(result.repositoryChange ?? null);
1127
1181
  setDraft({});
1128
1182
  if (result.oidcVerification) setLatest(result.oidcVerification);
1129
1183
  // A save can succeed and STILL leave the deployment unusable: a blank
@@ -1165,6 +1219,11 @@ export function SetupScreen({
1165
1219
  } catch (err) {
1166
1220
  if (err instanceof SettingsProblems) {
1167
1221
  showProblems(err.problems);
1222
+ } else if (err instanceof RepositoryChangeNeedsConfirmation) {
1223
+ // NOT an error: nothing was saved and nothing was destroyed. The
1224
+ // draft stays exactly as typed — the confirmed save re-sends it.
1225
+ setRepositoryChange({ openChangeRequests: err.openChangeRequests, from: err.from, to: err.to, target: moveTarget });
1226
+ setChangeChoice('keep');
1168
1227
  } else if (err instanceof KbInitFailed) {
1169
1228
  // The values ARE stored — only the initialization failed. The form
1170
1229
  // shows what was saved, and the banner says what to fix and retries
@@ -1172,6 +1231,14 @@ export function SetupScreen({
1172
1231
  setClearedFailure(null);
1173
1232
  setInitFailure(err.kbInit);
1174
1233
  setDraft({});
1234
+ // The confirmation was ANSWERED — the address is stored; it is the
1235
+ // initialization that failed, and the banner above owns the retry.
1236
+ // Left standing, it would offer Replace for a change that already
1237
+ // happened, over a draft this line has just cleared: a second click
1238
+ // would re-send the stored address, change nothing, and swallow the
1239
+ // "requests closed" outcome for good.
1240
+ setRepositoryChange(null);
1241
+ setChangeChoice('keep');
1175
1242
  onSaved();
1176
1243
  } else setError(err instanceof Error ? err.message : 'Could not save these settings.');
1177
1244
  } finally {
@@ -1386,6 +1453,23 @@ export function SetupScreen({
1386
1453
  </Banner>
1387
1454
  )}
1388
1455
 
1456
+ {/* What the save that moved the deployment actually did. */}
1457
+ {repositoryChanged && (
1458
+ <Banner tone="ok" role="status" className="mt-6" data-testid="repository-changed">
1459
+ <p>
1460
+ Saved. This deployment now works on the new repository.
1461
+ </p>
1462
+ {repositoryChanged.choice === 'close' && repositoryChanged.closedChangeRequests > 0 && (
1463
+ <p className="mt-1">
1464
+ {repositoryChanged.closedChangeRequests === 1
1465
+ ? '1 change request was closed as “repository replaced”.'
1466
+ : `${repositoryChanged.closedChangeRequests} change requests were closed as “repository replaced”.`}{' '}
1467
+ Nothing was deleted.
1468
+ </p>
1469
+ )}
1470
+ </Banner>
1471
+ )}
1472
+
1389
1473
  {error && (
1390
1474
  <Banner tone="danger" role="alert" className="mt-6">
1391
1475
  {error}
@@ -1580,7 +1664,8 @@ export function SetupScreen({
1580
1664
  <Banner tone="wait" role="status" data-testid="moves-repository">
1581
1665
  Saving moves this deployment to another repository, which starts without what the
1582
1666
  current one holds. Nothing is deleted: the current repository is left as it is, and
1583
- this deployment&rsquo;s working copies of it are set aside at the next restart.
1667
+ this deployment&rsquo;s working copies of it are set aside. You are asked to confirm
1668
+ before anything moves.
1584
1669
  </Banner>
1585
1670
  )}
1586
1671
  {repositoryTabs && savingMoves && gitTab === inEffect && (
@@ -1773,32 +1858,87 @@ export function SetupScreen({
1773
1858
  that they are present, not that they work — and open the app onto
1774
1859
  a repository it cannot reach, which reads as a broken product
1775
1860
  rather than a wrong token. */}
1776
- {/* ASKED WHERE THE DECISION IS MADE. The tab is the choice, and the
1777
- tab is a screen above this button: an admin who opened another
1778
- way to read about it, then changed something else and saved,
1779
- would have moved the deployment to an empty repository. So a
1780
- save that moves is a save the admin has said yes to, here,
1781
- naming what is left and what is moved to. */}
1782
- {mustConfirmMove && (
1783
- <Surface tone="sunken" radius="md" className="mt-10 p-4" data-testid="confirm-move">
1784
- <label className="flex items-start gap-2.5 text-detail text-ink">
1785
- <input
1786
- type="checkbox"
1787
- className="mt-0.5"
1788
- checked={moveConfirmed === gitTab}
1789
- onChange={(e) => setMoveConfirmed(e.target.checked ? gitTab : null)}
1790
- />
1791
- <span>
1792
- Move this deployment from &ldquo;{movingFrom}&rdquo; to &ldquo;{movingTo}&rdquo;.
1793
- <span className="mt-1 block text-meta text-ink-muted">
1794
- It starts on a repository without what the current one holds. Nothing is deleted, and the move takes
1795
- effect when the deployment is restarted.
1796
- </span>
1797
- </span>
1798
- </label>
1799
- </Surface>
1861
+ {/* ASKED WHERE THE DECISION IS MADE, AND ASKED ONCE. The tab is the
1862
+ choice, and the tab is a screen above this button: an admin who
1863
+ opened another way to read about it, then changed something else
1864
+ and saved, would have moved the deployment to an empty
1865
+ repository. So the server refuses a save that moves until the
1866
+ admin has said yes, and the question is put here, naming what is
1867
+ left and what is moved to. Nothing is stored and nothing is set
1868
+ aside while it stands; the draft is still on screen, and
1869
+ answering re-sends it. */}
1870
+ {moveAsked && (
1871
+ <Banner tone="wait" role="alert" className="mt-10" data-testid="repository-change-confirm">
1872
+ <p className="font-semibold">
1873
+ {moveAsked.from && moveAsked.to && moveAsked.from !== moveAsked.to
1874
+ ? `Move this deployment from “${GIT_MODE_LABEL[moveAsked.from]}” to “${GIT_MODE_LABEL[moveAsked.to]}”?`
1875
+ : 'Move this deployment to another repository?'}
1876
+ </p>
1877
+ <p className="mt-1">
1878
+ The move happens as soon as you confirm, with no restart. Unless the new repository holds the
1879
+ same history, every working copy on this server stops being used and is cloned fresh from the
1880
+ new repository. Anything committed here and not
1881
+ yet pushed from this server goes out of the app with it. Nothing is deleted, but it is only
1882
+ recoverable from the
1883
+ <code className="mx-1">replaced-working-copies</code>
1884
+ folder on the server, by hand.
1885
+ </p>
1886
+ {moveAsked.openChangeRequests > 0 && (
1887
+ <fieldset className="mt-3">
1888
+ <legend className="font-semibold">
1889
+ {moveAsked.openChangeRequests === 1
1890
+ ? 'There is 1 open change request.'
1891
+ : `There are ${moveAsked.openChangeRequests} open change requests.`}
1892
+ </legend>
1893
+ <label className="mt-1 flex items-start gap-2">
1894
+ <input
1895
+ type="radio"
1896
+ name="repository-change-requests"
1897
+ className="mt-1"
1898
+ checked={changeChoice === 'keep'}
1899
+ onChange={() => setChangeChoice('keep')}
1900
+ />
1901
+ <span>Keep them open: the same repository only moved.</span>
1902
+ </label>
1903
+ <label className="mt-1 flex items-start gap-2">
1904
+ <input
1905
+ type="radio"
1906
+ name="repository-change-requests"
1907
+ className="mt-1"
1908
+ checked={changeChoice === 'close'}
1909
+ onChange={() => setChangeChoice('close')}
1910
+ />
1911
+ <span>
1912
+ Close them as “repository replaced”: this is a different repository and their
1913
+ branches are not in it. Nothing is deleted, and the file locks held on those
1914
+ branches are released.
1915
+ </span>
1916
+ </label>
1917
+ </fieldset>
1918
+ )}
1919
+ <div className="mt-3 flex gap-2">
1920
+ <Button
1921
+ type="button"
1922
+ size="sm"
1923
+ onClick={() => void saveNow(moveAsked.openChangeRequests > 0 ? changeChoice : 'keep')}
1924
+ // The same things that stop a save: a click must never do nothing.
1925
+ disabled={saving || testing || retrying || oidcTesting}
1926
+ >
1927
+ {saving ? 'Moving…' : 'Move the deployment'}
1928
+ </Button>
1929
+ <Button
1930
+ type="button"
1931
+ variant="outline"
1932
+ size="sm"
1933
+ onClick={() => setRepositoryChange(null)}
1934
+ disabled={saving || testing}
1935
+ >
1936
+ Cancel
1937
+ </Button>
1938
+ </div>
1939
+ </Banner>
1800
1940
  )}
1801
- <div className={`${mustConfirmMove ? 'mt-4' : 'mt-10'} flex flex-wrap items-center justify-end gap-3`}>
1941
+ <div className={`${moveAsked ? 'mt-4' : 'mt-10'} flex flex-wrap items-center justify-end gap-3`}>
1802
1942
  {connectionRejected && (
1803
1943
  // Before the button in the DOM so the reason is read first, and
1804
1944
  // so `justify-end` leaves the button itself at the right edge.
@@ -1815,12 +1955,13 @@ export function SetupScreen({
1815
1955
  type="submit"
1816
1956
  form="setup-settings-form"
1817
1957
  variant="primary"
1818
- disabled={saving || testing || retrying || oidcTesting || connectionRejected || (mustConfirmMove && !moveIsConfirmed)}
1958
+ // While the question stands, its own buttons are the way on.
1959
+ disabled={saving || testing || retrying || oidcTesting || connectionRejected || moveAsked !== null}
1819
1960
  // Described by the refusal, so a reader who lands on a button
1820
1961
  // that will not move is told why rather than left guessing.
1821
1962
  aria-describedby={connectionRejected ? 'connection-refusal' : undefined}
1822
1963
  >
1823
- {saving ? 'Saving…' : mustConfirmMove ? 'Save and move' : 'Save and continue'}
1964
+ {saving ? 'Saving…' : 'Save and continue'}
1824
1965
  </Button>
1825
1966
  </div>
1826
1967