@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
@@ -6,7 +6,9 @@ import { useEffect, useState } from 'react';
6
6
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
7
  // @ts-expect-error — mammoth ships no .d.ts
8
8
  import mammoth from 'mammoth/mammoth.browser.js';
9
- import { useRendererWorkspaceId } from './rendererWorkspace';
9
+ import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
10
+ import { RetryReadButton } from './RetryReadButton';
11
+ import { useReadRetry } from './useReadRetry';
10
12
  import { authFetch } from '../../../../lib/api';
11
13
  import { rawFileUrl } from '../../services/workspace.api';
12
14
  import { sanitizeDocxHtml } from './sanitizeDocxHtml';
@@ -32,6 +34,16 @@ import type { FileRendererProps } from './types';
32
34
  */
33
35
  export function DocxRenderer({ filePath }: FileRendererProps) {
34
36
  const workspaceId = useRendererWorkspaceId();
37
+ /** A past save, when Version history mounted this; null = the working tree. */
38
+ const fileRef = useRendererFileRef();
39
+ /**
40
+ * The save as PRIMITIVES, hoisted out of the object so the read effect can
41
+ * depend on exactly what it reads. Depending on `fileRef` itself would put
42
+ * a context object in the dependency list.
43
+ */
44
+ const versionRef = fileRef?.ref ?? null;
45
+ const versionSide = fileRef?.side;
46
+ const { attempt, retry } = useReadRetry();
35
47
  const [html, setHtml] = useState<string | null>(null);
36
48
  const [error, setError] = useState<string | null>(null);
37
49
 
@@ -43,7 +55,9 @@ export function DocxRenderer({ filePath }: FileRendererProps) {
43
55
  let cancelled = false;
44
56
  (async () => {
45
57
  try {
46
- const res = await authFetch(rawFileUrl(workspaceId, filePath));
58
+ const res = await authFetch(
59
+ rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
60
+ );
47
61
  if (cancelled) return;
48
62
  if (!res.ok) {
49
63
  setError(`Failed to load Word document (HTTP ${res.status})`);
@@ -65,14 +79,17 @@ export function DocxRenderer({ filePath }: FileRendererProps) {
65
79
  return () => {
66
80
  cancelled = true;
67
81
  };
68
- }, [workspaceId, filePath]);
82
+ }, [workspaceId, filePath, versionRef, versionSide, attempt]);
69
83
 
70
84
  if (error) {
71
85
  return (
72
86
  <div className="flex min-h-40 flex-col items-center justify-center gap-3 text-center">
73
- <p className="text-sm text-danger">{error}</p>
74
- {/* The conversion failed; the bytes may still open fine in Word. */}
75
- <DownloadFileButton filePath={filePath} />
87
+ <p role="alert" className="text-sm text-danger">{error}</p>
88
+ <div className="flex items-center gap-2">
89
+ <RetryReadButton onRetry={retry} />
90
+ {/* The conversion failed; the bytes may still open fine in Word. */}
91
+ <DownloadFileButton filePath={filePath} />
92
+ </div>
76
93
  </div>
77
94
  );
78
95
  }
@@ -1,7 +1,7 @@
1
1
  import { createContext, useCallback, useContext, useState } from 'react';
2
2
  import { Download } from 'lucide-react';
3
3
  import { Button } from '../../../../shared/components';
4
- import { useRendererWorkspaceId } from './rendererWorkspace';
4
+ import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
5
5
  import { rawFileUrl } from '../../services/workspace.api';
6
6
  import { downloadViaBlob } from './downloadFile';
7
7
 
@@ -29,6 +29,7 @@ export function DownloadFileButton({
29
29
  filePath,
30
30
  size = 'tiny',
31
31
  label = 'Download',
32
+ pending = false,
32
33
  }: {
33
34
  filePath: string;
34
35
  /** `sm` where the download is the page's main affordance (pptx outline). */
@@ -40,20 +41,49 @@ export function DownloadFileButton({
40
41
  * and which branch they come from is the whole question.
41
42
  */
42
43
  label?: string;
44
+ /**
45
+ * WHICH bytes this button is for is not settled yet.
46
+ *
47
+ * Only Version history sets it, and only because the save it shows may be
48
+ * the one that DELETED the file — in which case "this version" is the side
49
+ * BEFORE the save, which is known only once the patch has come back. A click
50
+ * before then would ask for the after side of a deleting save and get a 404
51
+ * for a version the reader can see listed. Idle for a fraction of a second
52
+ * is the honest answer; a wrong download is not.
53
+ */
54
+ pending?: boolean;
43
55
  }) {
44
56
  const workspaceId = useRendererWorkspaceId();
57
+ /**
58
+ * A past save, when Version history mounted this. "Download this version"
59
+ * has to deliver the bytes of THAT save — for the save that deleted the
60
+ * file, the ones just before it — and the whole of that is which URL the
61
+ * download reads, under the same `download:` verb as any other.
62
+ */
63
+ const fileRef = useRendererFileRef();
64
+ /**
65
+ * The save as PRIMITIVES, hoisted out of the object so the read effect can
66
+ * depend on exactly what it reads. Depending on `fileRef` itself would put
67
+ * a context object in the dependency list.
68
+ */
69
+ const versionRef = fileRef?.ref ?? null;
70
+ const versionSide = fileRef?.side;
45
71
  const canDownload = useContext(CanDownloadContext);
46
72
  const [busy, setBusy] = useState(false);
47
73
  const [error, setError] = useState<string | null>(null);
48
74
  const fileName = filePath.slice(filePath.lastIndexOf('/') + 1);
49
75
 
50
76
  const handleDownload = useCallback(async () => {
51
- if (!workspaceId || busy) return;
77
+ if (!workspaceId || busy || pending) return;
52
78
  setBusy(true);
53
79
  setError(null);
54
80
  try {
55
81
  const outcome = await downloadViaBlob(
56
- rawFileUrl(workspaceId, filePath, { download: true }),
82
+ rawFileUrl(workspaceId, filePath, {
83
+ download: true,
84
+ ref: versionRef,
85
+ side: versionSide,
86
+ }),
57
87
  fileName,
58
88
  );
59
89
  if (!outcome.ok) {
@@ -66,7 +96,7 @@ export function DownloadFileButton({
66
96
  } finally {
67
97
  setBusy(false);
68
98
  }
69
- }, [workspaceId, busy, filePath, fileName]);
99
+ }, [workspaceId, busy, pending, filePath, fileName, versionRef, versionSide]);
70
100
 
71
101
  return (
72
102
  <span className="inline-flex items-center gap-2">
@@ -80,10 +110,13 @@ export function DownloadFileButton({
80
110
  size={size}
81
111
  leadingIcon={<Download size={size === 'sm' ? 14 : 12} />}
82
112
  onClick={() => void handleDownload()}
83
- // Disabled only on a hard "no" — while the lookup is in flight the
84
- // button stays optimistic, mirroring the editor; a wrong guess is
85
- // still caught by the backend's own gate on the raw endpoint.
86
- disabled={busy || canDownload === false}
113
+ // Disabled on a hard "no" about PERMISSION — while that lookup is in
114
+ // flight the button stays optimistic, mirroring the editor; a wrong
115
+ // guess is still caught by the backend's own gate on the raw endpoint.
116
+ // `pending` is a different kind of unknown: not who may have the
117
+ // bytes, but which bytes, and guessing there downloads the wrong file
118
+ // (or nothing at all).
119
+ disabled={busy || pending || canDownload === false}
87
120
  title={
88
121
  canDownload === false
89
122
  ? 'You do not have download permission for this file.'
@@ -1,6 +1,8 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { Check, Copy, ExternalLink, Mail, Paperclip } from 'lucide-react';
3
- import { useRendererWorkspaceId } from './rendererWorkspace';
3
+ import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
4
+ import { RetryReadButton } from './RetryReadButton';
5
+ import { useReadRetry } from './useReadRetry';
4
6
  import { authFetch } from '../../../../lib/api';
5
7
  import { rawFileUrl } from '../../services/workspace.api';
6
8
  import { copyToClipboard } from '../../../../lib/clipboard';
@@ -40,6 +42,16 @@ import type { FileRendererProps } from './types';
40
42
  */
41
43
  export function EmailRenderer({ filePath }: FileRendererProps) {
42
44
  const workspaceId = useRendererWorkspaceId();
45
+ /** A past save, when Version history mounted this; null = the working tree. */
46
+ const fileRef = useRendererFileRef();
47
+ /**
48
+ * The save as PRIMITIVES, hoisted out of the object so the read effect can
49
+ * depend on exactly what it reads. Depending on `fileRef` itself would put
50
+ * a context object in the dependency list.
51
+ */
52
+ const versionRef = fileRef?.ref ?? null;
53
+ const versionSide = fileRef?.side;
54
+ const { attempt, retry } = useReadRetry();
43
55
  const [view, setView] = useState<EmailMessageView | null>(null);
44
56
  // The sender's own markup, made safe to show. Rebuilt only when the message
45
57
  // changes — the sanitize + inline pass walks the whole body.
@@ -61,7 +73,7 @@ export function EmailRenderer({ filePath }: FileRendererProps) {
61
73
  (async () => {
62
74
  try {
63
75
  const res = await authFetch(
64
- rawFileUrl(workspaceId, filePath),
76
+ rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
65
77
  { signal: controller.signal },
66
78
  );
67
79
  if (cancelled) return;
@@ -97,13 +109,16 @@ export function EmailRenderer({ filePath }: FileRendererProps) {
97
109
  cancelled = true;
98
110
  controller.abort();
99
111
  };
100
- }, [workspaceId, filePath]);
112
+ }, [workspaceId, filePath, versionRef, versionSide, attempt]);
101
113
 
102
114
  if (error) {
103
115
  return (
104
116
  <div className="flex min-h-40 flex-col items-center justify-center gap-3 p-6 text-center">
105
- <p className="text-ui text-danger">{error}</p>
106
- <DownloadFileButton filePath={filePath} />
117
+ <p role="alert" className="text-ui text-danger">{error}</p>
118
+ <div className="flex items-center gap-2">
119
+ <RetryReadButton onRetry={retry} />
120
+ <DownloadFileButton filePath={filePath} />
121
+ </div>
107
122
  </div>
108
123
  );
109
124
  }
@@ -1,6 +1,7 @@
1
1
  import { useState, useEffect } from 'react';
2
- import { Button } from '../../../../shared/components';
3
- import { useRendererWorkspaceId } from './rendererWorkspace';
2
+ import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
3
+ import { RetryReadButton } from './RetryReadButton';
4
+ import { useReadRetry } from './useReadRetry';
4
5
  import { useImageRevision } from '../../hooks/useImageRevision';
5
6
  import { authFetch } from '../../../../lib/api';
6
7
  import { rawFileUrl } from '../../services/workspace.api';
@@ -31,19 +32,35 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
31
32
  * its author may still be pushing to while a reviewer looks at it.
32
33
  */
33
34
  const revision = useImageRevision(workspaceId);
35
+ /**
36
+ * A past save, when Version history mounted this. The revision above is
37
+ * then deliberately NOT folded in: the bytes at a commit cannot change, so
38
+ * `&v=` would only defeat the browser cache, and the revision bumps on every
39
+ * save of the file — which for a version pane means a re-read of a version
40
+ * that is not what changed.
41
+ */
42
+ const fileRef = useRendererFileRef();
43
+ /**
44
+ * The save as PRIMITIVES, hoisted out of the object so the read effect can
45
+ * depend on exactly what it reads. Depending on `fileRef` itself would put
46
+ * a context object in the dependency list.
47
+ */
48
+ const versionRef = fileRef?.ref ?? null;
49
+ const versionSide = fileRef?.side;
50
+ /**
51
+ * The cache key of a WORKING-TREE read, and nothing else. Folding the
52
+ * revision into a version read would not just waste a request: a teammate
53
+ * saving the file while a past save is on screen would bump it, the read
54
+ * effect would re-run, and the picture the reader is looking at would blink
55
+ * back to "Loading image…" for bytes that cannot have changed.
56
+ */
57
+ const revisionKey = versionRef === null ? revision : null;
34
58
  // Blob and failure in ONE value, so the cleanup that drops the old blob
35
59
  // drops the old failure with it — a second `useState` would need a reset in
36
60
  // the effect body, which costs a cascading render on every path change.
37
61
  const [read, setRead] = useState<ImageRead>(NOT_READ);
38
- /**
39
- * Bumped by Try again, and a dependency of the read below — which is the
40
- * whole mechanism. A failure whose `workspaceId`, path and revision are all
41
- * unchanged has nothing to re-trigger the effect, so a dropped connection or
42
- * a 502 was terminal until the pane remounted; a reviewer with a dialog open
43
- * had no way back to the picture. Automatic recovery on a path or revision
44
- * change is untouched: those change the deps by themselves.
45
- */
46
- const [attempt, setAttempt] = useState(0);
62
+ /** Bumped by Try again, and a dependency of the read below — see the hook. */
63
+ const { attempt, retry } = useReadRetry();
47
64
 
48
65
  useEffect(() => {
49
66
  if (!workspaceId) return;
@@ -51,7 +68,15 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
51
68
  let revoked = false;
52
69
  (async () => {
53
70
  try {
54
- const res = await authFetch(rawFileUrl(workspaceId, filePath, { version: revision }));
71
+ const res = await authFetch(
72
+ rawFileUrl(
73
+ workspaceId,
74
+ filePath,
75
+ versionRef === null
76
+ ? { version: revisionKey ?? undefined }
77
+ : { ref: versionRef, side: versionSide },
78
+ ),
79
+ );
55
80
  if (revoked) return;
56
81
  if (!res.ok) {
57
82
  setRead({ objectUrl: null, error: `Couldn't load this image (HTTP ${res.status}).` });
@@ -74,7 +99,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
74
99
  return prev === NOT_READ ? prev : NOT_READ;
75
100
  });
76
101
  };
77
- }, [workspaceId, filePath, revision, attempt]);
102
+ }, [workspaceId, filePath, revisionKey, versionRef, versionSide, attempt]);
78
103
 
79
104
  if (read.error) {
80
105
  return (
@@ -82,9 +107,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
82
107
  <p role="alert" className="text-detail text-danger">
83
108
  {read.error}
84
109
  </p>
85
- <Button variant="outline" size="tiny" onClick={() => setAttempt((n) => n + 1)}>
86
- Try again
87
- </Button>
110
+ <RetryReadButton onRetry={retry} />
88
111
  </div>
89
112
  );
90
113
  }
@@ -4,7 +4,9 @@ import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist';
4
4
  import type { PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
5
5
  import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
6
6
  import { Button } from '../../../../shared/components';
7
- import { useRendererWorkspaceId } from './rendererWorkspace';
7
+ import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
8
+ import { RetryReadButton } from './RetryReadButton';
9
+ import { useReadRetry } from './useReadRetry';
8
10
  import { authFetch } from '../../../../lib/api';
9
11
  import { rawFileUrl } from '../../services/workspace.api';
10
12
  import { DownloadFileButton } from './DownloadFileButton';
@@ -37,6 +39,16 @@ GlobalWorkerOptions.workerSrc = pdfWorkerUrl;
37
39
  */
38
40
  export function PdfRenderer({ filePath }: FileRendererProps) {
39
41
  const workspaceId = useRendererWorkspaceId();
42
+ /** A past save, when Version history mounted this; null = the working tree. */
43
+ const fileRef = useRendererFileRef();
44
+ /**
45
+ * The save as PRIMITIVES, hoisted out of the object so the read effect can
46
+ * depend on exactly what it reads. Depending on `fileRef` itself would put
47
+ * a context object in the dependency list.
48
+ */
49
+ const versionRef = fileRef?.ref ?? null;
50
+ const versionSide = fileRef?.side;
51
+ const { attempt, retry } = useReadRetry();
40
52
  const [doc, setDoc] = useState<PDFDocumentProxy | null>(null);
41
53
  const [pageNumber, setPageNumber] = useState(1);
42
54
  const [error, setError] = useState<string | null>(null);
@@ -77,7 +89,9 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
77
89
  let loadingTask: PDFDocumentLoadingTask | null = null;
78
90
  (async () => {
79
91
  try {
80
- const res = await authFetch(rawFileUrl(workspaceId, filePath));
92
+ const res = await authFetch(
93
+ rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
94
+ );
81
95
  if (cancelled) return;
82
96
  if (!res.ok) {
83
97
  setError(`Failed to load PDF (HTTP ${res.status})`);
@@ -126,7 +140,7 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
126
140
  loadingTask?.destroy().catch(() => {});
127
141
  loadingTaskRef.current = null;
128
142
  };
129
- }, [workspaceId, filePath]);
143
+ }, [workspaceId, filePath, versionRef, versionSide, attempt]);
130
144
 
131
145
  // Track the page column's width so the canvas re-renders to fit it. The
132
146
  // container only mounts once the document is loaded, hence the `doc` dep.
@@ -248,10 +262,16 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
248
262
  if (error) {
249
263
  return (
250
264
  <div className="flex h-full flex-col items-center justify-center gap-3 p-6 text-center">
251
- <p className="text-ui text-danger">{error}</p>
252
- {/* The rendering failed; the bytes may still be perfectly good to
253
- someone with a desktop viewer. */}
254
- <DownloadFileButton filePath={filePath} />
265
+ <p role="alert" className="text-ui text-danger">{error}</p>
266
+ <div className="flex items-center gap-2">
267
+ {/* A failed READ is worth another go; a failed PARSE is not, but the
268
+ two are one error state here and offering the retry is cheaper
269
+ than a third. */}
270
+ <RetryReadButton onRetry={retry} />
271
+ {/* The rendering failed; the bytes may still be perfectly good to
272
+ someone with a desktop viewer. */}
273
+ <DownloadFileButton filePath={filePath} />
274
+ </div>
255
275
  </div>
256
276
  );
257
277
  }
@@ -1,6 +1,8 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { Presentation } from 'lucide-react';
3
- import { useRendererWorkspaceId } from './rendererWorkspace';
3
+ import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
4
+ import { RetryReadButton } from './RetryReadButton';
5
+ import { useReadRetry } from './useReadRetry';
4
6
  import { authFetch } from '../../../../lib/api';
5
7
  import { rawFileUrl } from '../../services/workspace.api';
6
8
  import { DownloadFileButton } from './DownloadFileButton';
@@ -49,6 +51,16 @@ const MAX_LINES_PER_SLIDE = 500;
49
51
 
50
52
  export function PptxRenderer({ filePath }: FileRendererProps) {
51
53
  const workspaceId = useRendererWorkspaceId();
54
+ /** A past save, when Version history mounted this; null = the working tree. */
55
+ const fileRef = useRendererFileRef();
56
+ /**
57
+ * The save as PRIMITIVES, hoisted out of the object so the read effect can
58
+ * depend on exactly what it reads. Depending on `fileRef` itself would put
59
+ * a context object in the dependency list.
60
+ */
61
+ const versionRef = fileRef?.ref ?? null;
62
+ const versionSide = fileRef?.side;
63
+ const { attempt, retry } = useReadRetry();
52
64
  const [slides, setSlides] = useState<PptxSlide[] | null>(null);
53
65
  const [error, setError] = useState<string | null>(null);
54
66
 
@@ -65,7 +77,7 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
65
77
  (async () => {
66
78
  try {
67
79
  const res = await authFetch(
68
- rawFileUrl(workspaceId, filePath),
80
+ rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
69
81
  { signal: abort.signal },
70
82
  );
71
83
  if (cancelled) return;
@@ -97,13 +109,16 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
97
109
  cancelled = true;
98
110
  abort.abort();
99
111
  };
100
- }, [workspaceId, filePath]);
112
+ }, [workspaceId, filePath, versionRef, versionSide, attempt]);
101
113
 
102
114
  if (error) {
103
115
  return (
104
116
  <div className="flex min-h-40 flex-col items-center justify-center gap-3 p-6 text-center">
105
- <p className="text-ui text-danger">{error}</p>
106
- <DownloadFileButton filePath={filePath} />
117
+ <p role="alert" className="text-ui text-danger">{error}</p>
118
+ <div className="flex items-center gap-2">
119
+ <RetryReadButton onRetry={retry} />
120
+ <DownloadFileButton filePath={filePath} />
121
+ </div>
107
122
  </div>
108
123
  );
109
124
  }
@@ -0,0 +1,37 @@
1
+ import { Button } from '../../../../shared/components';
2
+ import { READ_PANE_SELECTOR } from './readPane';
3
+
4
+ /**
5
+ * The button beside a viewer's own error message — see {@link useReadRetry}
6
+ * for what it re-triggers.
7
+ *
8
+ * Its own component so the wording is one string across every viewer: a reader
9
+ * who has learned what "Try again" does in one pane should not meet "Retry"
10
+ * in the next.
11
+ *
12
+ * It also hands keyboard focus on, because pressing it UNMOUNTS it: every
13
+ * byte-reading viewer returns its error block as its whole output, so the
14
+ * retry replaces that block with the viewer's loading state and then the
15
+ * document. Focus would fall to `document.body`, and in a pane that is part
16
+ * of a larger surface — Version history's version pane, the change-request
17
+ * dialog — the next Tab would start again from the top of the page. There is
18
+ * nothing inside the viewer that survives the swap to hand focus TO, so the
19
+ * destination is the host pane's own region, which it names by spreading
20
+ * `READ_PANE`. The move happens before the state change, while this button is
21
+ * still on screen, so no frame is ever painted with focus on the body; a pane
22
+ * that names no region keeps today's behaviour.
23
+ */
24
+ export function RetryReadButton({ onRetry }: { onRetry: () => void }) {
25
+ return (
26
+ <Button
27
+ variant="outline"
28
+ size="tiny"
29
+ onClick={(e) => {
30
+ e.currentTarget.closest<HTMLElement>(READ_PANE_SELECTOR)?.focus();
31
+ onRetry();
32
+ }}
33
+ >
34
+ Try again
35
+ </Button>
36
+ );
37
+ }
@@ -1,6 +1,8 @@
1
1
  import { useEffect, useMemo, useState } from 'react';
2
2
  import * as XLSX from 'xlsx';
3
- import { useRendererWorkspaceId } from './rendererWorkspace';
3
+ import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
4
+ import { RetryReadButton } from './RetryReadButton';
5
+ import { useReadRetry } from './useReadRetry';
4
6
  import { authFetch } from '../../../../lib/api';
5
7
  import { rawFileUrl } from '../../services/workspace.api';
6
8
  import { DownloadFileButton } from './DownloadFileButton';
@@ -97,6 +99,16 @@ interface SheetView {
97
99
  */
98
100
  export function XlsxRenderer({ filePath }: FileRendererProps) {
99
101
  const workspaceId = useRendererWorkspaceId();
102
+ /** A past save, when Version history mounted this; null = the working tree. */
103
+ const fileRef = useRendererFileRef();
104
+ /**
105
+ * The save as PRIMITIVES, hoisted out of the object so the read effect can
106
+ * depend on exactly what it reads. Depending on `fileRef` itself would put
107
+ * a context object in the dependency list.
108
+ */
109
+ const versionRef = fileRef?.ref ?? null;
110
+ const versionSide = fileRef?.side;
111
+ const { attempt, retry } = useReadRetry();
100
112
  const [workbook, setWorkbook] = useState<XLSX.WorkBook | null>(null);
101
113
  const [activeSheet, setActiveSheet] = useState(0);
102
114
  const [error, setError] = useState<string | null>(null);
@@ -114,7 +126,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
114
126
  (async () => {
115
127
  try {
116
128
  const res = await authFetch(
117
- rawFileUrl(workspaceId, filePath),
129
+ rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
118
130
  { signal: controller.signal },
119
131
  );
120
132
  if (cancelled) return;
@@ -165,7 +177,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
165
177
  cancelled = true;
166
178
  controller.abort();
167
179
  };
168
- }, [workspaceId, filePath]);
180
+ }, [workspaceId, filePath, versionRef, versionSide, attempt]);
169
181
 
170
182
  // Convert ONLY the sheet on screen, when it is on screen. `XLSX.read` has
171
183
  // already materialized every cell (SheetJS has no partial parse), but
@@ -211,8 +223,11 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
211
223
  if (error) {
212
224
  return (
213
225
  <div className="flex h-full flex-col items-center justify-center gap-3 text-center">
214
- <p className="text-sm text-danger">{error}</p>
215
- <DownloadFileButton filePath={filePath} />
226
+ <p role="alert" className="text-sm text-danger">{error}</p>
227
+ <div className="flex items-center gap-2">
228
+ <RetryReadButton onRetry={retry} />
229
+ <DownloadFileButton filePath={filePath} />
230
+ </div>
216
231
  </div>
217
232
  );
218
233
  }