@bevel-software/platform-core-frontend 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/registry.ts +51 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/auth/components/LoginScreen.tsx +4 -1
- package/src/modules/auth/services/account.api.ts +28 -1
- package/src/modules/auth/services/sso.ts +1 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
- package/src/modules/onboarding/components/InviteButton.tsx +35 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +89 -0
- package/src/modules/onboarding/invite-emails.ts +175 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +324 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
3
3
|
import { RetryReadButton } from './RetryReadButton';
|
|
4
4
|
import { useReadRetry } from './useReadRetry';
|
|
5
5
|
import { useImageRevision } from '../../hooks/useImageRevision';
|
|
6
|
-
import {
|
|
7
|
-
import { rawFileUrl } from '../../services/workspace.api';
|
|
6
|
+
import { useRendererRawRead } from './rendererRawRead';
|
|
8
7
|
import type { FileRendererProps } from './types';
|
|
9
8
|
|
|
10
9
|
/** How the read of one image ended. */
|
|
@@ -33,28 +32,21 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
|
|
|
33
32
|
*/
|
|
34
33
|
const revision = useImageRevision(workspaceId);
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* that is not what changed.
|
|
35
|
+
* Where the picture's bytes come from — the workspace raw route under the
|
|
36
|
+
* session in the app, the surface's own route in an embed. It folds the
|
|
37
|
+
* save this viewer is bound to in itself, so a version pane needs nothing
|
|
38
|
+
* extra here.
|
|
41
39
|
*/
|
|
42
|
-
const
|
|
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;
|
|
40
|
+
const rawRead = useRendererRawRead();
|
|
50
41
|
/**
|
|
51
42
|
* The cache key of a WORKING-TREE read, and nothing else. Folding the
|
|
52
43
|
* revision into a version read would not just waste a request: a teammate
|
|
53
44
|
* saving the file while a past save is on screen would bump it, the read
|
|
54
45
|
* 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.
|
|
46
|
+
* back to "Loading image…" for bytes that cannot have changed. Which kind
|
|
47
|
+
* of read this is belongs to the raw source, so that is what is asked.
|
|
56
48
|
*/
|
|
57
|
-
const revisionKey =
|
|
49
|
+
const revisionKey = rawRead?.pinnedToVersion ? null : revision;
|
|
58
50
|
// Blob and failure in ONE value, so the cleanup that drops the old blob
|
|
59
51
|
// drops the old failure with it — a second `useState` would need a reset in
|
|
60
52
|
// the effect body, which costs a cascading render on every path change.
|
|
@@ -63,20 +55,12 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
|
|
|
63
55
|
const { attempt, retry } = useReadRetry();
|
|
64
56
|
|
|
65
57
|
useEffect(() => {
|
|
66
|
-
if (!
|
|
58
|
+
if (!rawRead) return;
|
|
67
59
|
|
|
68
60
|
let revoked = false;
|
|
69
61
|
(async () => {
|
|
70
62
|
try {
|
|
71
|
-
const res = await
|
|
72
|
-
rawFileUrl(
|
|
73
|
-
workspaceId,
|
|
74
|
-
filePath,
|
|
75
|
-
versionRef === null
|
|
76
|
-
? { version: revisionKey ?? undefined }
|
|
77
|
-
: { ref: versionRef, side: versionSide },
|
|
78
|
-
),
|
|
79
|
-
);
|
|
63
|
+
const res = await rawRead.fetch(filePath, { version: revisionKey ?? undefined });
|
|
80
64
|
if (revoked) return;
|
|
81
65
|
if (!res.ok) {
|
|
82
66
|
setRead({ objectUrl: null, error: `Couldn't load this image (HTTP ${res.status}).` });
|
|
@@ -99,7 +83,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
|
|
|
99
83
|
return prev === NOT_READ ? prev : NOT_READ;
|
|
100
84
|
});
|
|
101
85
|
};
|
|
102
|
-
}, [
|
|
86
|
+
}, [rawRead, filePath, revisionKey, attempt]);
|
|
103
87
|
|
|
104
88
|
if (read.error) {
|
|
105
89
|
return (
|
|
@@ -115,6 +115,13 @@ interface KbMarkdownViewProps {
|
|
|
115
115
|
* images render as plain `<img>` tags. See `KbImage` in the pipeline.
|
|
116
116
|
*/
|
|
117
117
|
resolveImage?: KbImageResolver;
|
|
118
|
+
/**
|
|
119
|
+
* Which links `onOpenFile` gets — see `linkPolicy` in the pipeline. The
|
|
120
|
+
* app leaves external destinations to the browser; a surface inside
|
|
121
|
+
* somebody else's frame takes every one of them, because a plain anchor
|
|
122
|
+
* there navigates the frame rather than opening a tab.
|
|
123
|
+
*/
|
|
124
|
+
linkPolicy?: 'browser' | 'surface';
|
|
118
125
|
/** Optional container ref (used by the file viewer for deep-link scroll). */
|
|
119
126
|
containerRef?: Ref<HTMLDivElement>;
|
|
120
127
|
/**
|
|
@@ -139,7 +146,7 @@ interface KbMarkdownViewProps {
|
|
|
139
146
|
* frontmatter panel, with navigation injected via `onOpenFile` so it carries no
|
|
140
147
|
* dependency on workspace routing or context.
|
|
141
148
|
*/
|
|
142
|
-
export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, resolveImage, containerRef, scroll = true, className }: KbMarkdownViewProps) {
|
|
149
|
+
export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, resolveImage, linkPolicy, containerRef, scroll = true, className }: KbMarkdownViewProps) {
|
|
143
150
|
const { data: frontmatter, body } = useMemo(() => parseFrontmatter(source), [source]);
|
|
144
151
|
// CommonMark rejects unescaped spaces in link destinations, so a KB link like
|
|
145
152
|
// `[Foo](Some File.md)` would render as plain text. Wrap space-bearing
|
|
@@ -147,7 +154,7 @@ export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink,
|
|
|
147
154
|
// rule covers an image's `` tail.
|
|
148
155
|
const normalizedBody = useMemo(() => escapeSpacesInLinkDestinations(body), [body]);
|
|
149
156
|
|
|
150
|
-
const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink, resolveImage });
|
|
157
|
+
const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink, resolveImage, linkPolicy });
|
|
151
158
|
|
|
152
159
|
return (
|
|
153
160
|
<div
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useCanonicalFileUrl,
|
|
9
9
|
} from '../../routing/kb-routes';
|
|
10
10
|
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
11
|
+
import { useRendererSurface } from './rendererSurface';
|
|
11
12
|
import { WorkspaceContext } from '../../state/workspace.context';
|
|
12
13
|
import { markdownLinkForPaste } from '../../utils/pasteLink';
|
|
13
14
|
import { useWorkspaceImageResolver } from '../../hooks/useWorkspaceImageResolver';
|
|
@@ -166,6 +167,8 @@ export function MarkdownRenderer({
|
|
|
166
167
|
// new picture.
|
|
167
168
|
const workspaceId = useRendererWorkspaceId();
|
|
168
169
|
const resolveImage = useWorkspaceImageResolver(workspaceId, filePath);
|
|
170
|
+
// Whether this renderer is mounted outside the app — see `linkPolicy` below.
|
|
171
|
+
const surface = useRendererSurface();
|
|
169
172
|
|
|
170
173
|
const save = useCallback(async (): Promise<boolean> => {
|
|
171
174
|
if (readOnly || value === savedValue) return true;
|
|
@@ -266,6 +269,11 @@ export function MarkdownRenderer({
|
|
|
266
269
|
onOpenNodeId={openNodeId}
|
|
267
270
|
headingLink={headingLink}
|
|
268
271
|
resolveImage={resolveImage}
|
|
272
|
+
// On a renderer surface (the embed) EVERY outgoing link is the
|
|
273
|
+
// surface's to open: there is no `allow-popups` inside a host's
|
|
274
|
+
// frame, so a plain `target="_blank"` anchor navigates the frame
|
|
275
|
+
// away instead of opening a tab. In the app the browser keeps them.
|
|
276
|
+
linkPolicy={surface ? 'surface' : 'browser'}
|
|
269
277
|
containerRef={scrollContainerRef}
|
|
270
278
|
// The document column scrolls; this view does not. See the prop's
|
|
271
279
|
// docstring — the embed and the library dialog keep the default.
|
|
@@ -4,11 +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 { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
|
|
8
7
|
import { RetryReadButton } from './RetryReadButton';
|
|
9
8
|
import { useReadRetry } from './useReadRetry';
|
|
10
|
-
import {
|
|
11
|
-
import { rawFileUrl } from '../../services/workspace.api';
|
|
9
|
+
import { useRendererRawRead } from './rendererRawRead';
|
|
12
10
|
import { DownloadFileButton } from './DownloadFileButton';
|
|
13
11
|
import type { FileRendererProps } from './types';
|
|
14
12
|
|
|
@@ -38,16 +36,15 @@ GlobalWorkerOptions.workerSrc = pdfWorkerUrl;
|
|
|
38
36
|
* `onSave` / `onValueChange` / `readOnly`.
|
|
39
37
|
*/
|
|
40
38
|
export function PdfRenderer({ filePath }: FileRendererProps) {
|
|
41
|
-
const workspaceId = useRendererWorkspaceId();
|
|
42
|
-
/** A past save, when Version history mounted this; null = the working tree. */
|
|
43
|
-
const fileRef = useRendererFileRef();
|
|
44
39
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* a
|
|
40
|
+
* Where this file's bytes come from. In the app that is the workspace raw
|
|
41
|
+
* route under the session, for the workspace this viewer is pointed at and
|
|
42
|
+
* the save it is bound to; on a renderer surface (the embed) it is that
|
|
43
|
+
* surface's own route, with its own credential. Null until there is a
|
|
44
|
+
* workspace to read from — the same "nothing to read yet" the guard in the
|
|
45
|
+
* effect below has always had.
|
|
48
46
|
*/
|
|
49
|
-
const
|
|
50
|
-
const versionSide = fileRef?.side;
|
|
47
|
+
const rawRead = useRendererRawRead();
|
|
51
48
|
const { attempt, retry } = useReadRetry();
|
|
52
49
|
const [doc, setDoc] = useState<PDFDocumentProxy | null>(null);
|
|
53
50
|
const [pageNumber, setPageNumber] = useState(1);
|
|
@@ -75,23 +72,21 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
|
|
|
75
72
|
const [width, setWidth] = useState(0);
|
|
76
73
|
|
|
77
74
|
useEffect(() => {
|
|
78
|
-
// Reset stale state from a prior filePath /
|
|
79
|
-
// the new load —
|
|
80
|
-
//
|
|
75
|
+
// Reset stale state from a prior filePath / raw source before starting
|
|
76
|
+
// the new load — teardown (no source at all) included. The rendered-page
|
|
77
|
+
// ref dies with its document (task.destroy frees the pages).
|
|
81
78
|
setDoc(null);
|
|
82
79
|
setPageNumber(1);
|
|
83
80
|
setError(null);
|
|
84
81
|
renderedPageRef.current = null;
|
|
85
82
|
|
|
86
|
-
if (!
|
|
83
|
+
if (!rawRead) return;
|
|
87
84
|
|
|
88
85
|
let cancelled = false;
|
|
89
86
|
let loadingTask: PDFDocumentLoadingTask | null = null;
|
|
90
87
|
(async () => {
|
|
91
88
|
try {
|
|
92
|
-
const res = await
|
|
93
|
-
rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
|
|
94
|
-
);
|
|
89
|
+
const res = await rawRead.fetch(filePath);
|
|
95
90
|
if (cancelled) return;
|
|
96
91
|
if (!res.ok) {
|
|
97
92
|
setError(`Failed to load PDF (HTTP ${res.status})`);
|
|
@@ -140,7 +135,7 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
|
|
|
140
135
|
loadingTask?.destroy().catch(() => {});
|
|
141
136
|
loadingTaskRef.current = null;
|
|
142
137
|
};
|
|
143
|
-
}, [
|
|
138
|
+
}, [rawRead, filePath, attempt]);
|
|
144
139
|
|
|
145
140
|
// Track the page column's width so the canvas re-renders to fit it. The
|
|
146
141
|
// container only mounts once the document is loaded, hence the `doc` dep.
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { Presentation } from 'lucide-react';
|
|
3
|
-
import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
|
|
4
3
|
import { RetryReadButton } from './RetryReadButton';
|
|
5
4
|
import { useReadRetry } from './useReadRetry';
|
|
6
|
-
import {
|
|
7
|
-
import { rawFileUrl } from '../../services/workspace.api';
|
|
5
|
+
import { useRendererRawRead } from './rendererRawRead';
|
|
8
6
|
import { DownloadFileButton } from './DownloadFileButton';
|
|
9
7
|
import { extractPptxOutline, type PptxSlide } from './pptxOutline';
|
|
10
8
|
import { readBodyCapped } from './readBodyCapped';
|
|
@@ -50,16 +48,15 @@ const MAX_ARCHIVE_BYTES = 200 * 1024 * 1024;
|
|
|
50
48
|
const MAX_LINES_PER_SLIDE = 500;
|
|
51
49
|
|
|
52
50
|
export function PptxRenderer({ filePath }: FileRendererProps) {
|
|
53
|
-
const workspaceId = useRendererWorkspaceId();
|
|
54
|
-
/** A past save, when Version history mounted this; null = the working tree. */
|
|
55
|
-
const fileRef = useRendererFileRef();
|
|
56
51
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* a
|
|
52
|
+
* Where this file's bytes come from. In the app that is the workspace raw
|
|
53
|
+
* route under the session, for the workspace this viewer is pointed at and
|
|
54
|
+
* the save it is bound to; on a renderer surface (the embed) it is that
|
|
55
|
+
* surface's own route, with its own credential. Null until there is a
|
|
56
|
+
* workspace to read from — the same "nothing to read yet" the guard in the
|
|
57
|
+
* effect below has always had.
|
|
60
58
|
*/
|
|
61
|
-
const
|
|
62
|
-
const versionSide = fileRef?.side;
|
|
59
|
+
const rawRead = useRendererRawRead();
|
|
63
60
|
const { attempt, retry } = useReadRetry();
|
|
64
61
|
const [slides, setSlides] = useState<PptxSlide[] | null>(null);
|
|
65
62
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -67,7 +64,7 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
|
|
|
67
64
|
useEffect(() => {
|
|
68
65
|
setSlides(null);
|
|
69
66
|
setError(null);
|
|
70
|
-
if (!
|
|
67
|
+
if (!rawRead) return;
|
|
71
68
|
|
|
72
69
|
let cancelled = false;
|
|
73
70
|
// `cancelled` only stops this effect from PUBLISHING; the request itself
|
|
@@ -76,10 +73,7 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
|
|
|
76
73
|
const abort = new AbortController();
|
|
77
74
|
(async () => {
|
|
78
75
|
try {
|
|
79
|
-
const res = await
|
|
80
|
-
rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
|
|
81
|
-
{ signal: abort.signal },
|
|
82
|
-
);
|
|
76
|
+
const res = await rawRead.fetch(filePath, { signal: abort.signal });
|
|
83
77
|
if (cancelled) return;
|
|
84
78
|
if (!res.ok) {
|
|
85
79
|
setError(`Failed to load presentation (HTTP ${res.status})`);
|
|
@@ -109,7 +103,7 @@ export function PptxRenderer({ filePath }: FileRendererProps) {
|
|
|
109
103
|
cancelled = true;
|
|
110
104
|
abort.abort();
|
|
111
105
|
};
|
|
112
|
-
}, [
|
|
106
|
+
}, [rawRead, filePath, attempt]);
|
|
113
107
|
|
|
114
108
|
if (error) {
|
|
115
109
|
return (
|
|
@@ -3,11 +3,12 @@ import { parse as parseYaml } from 'yaml';
|
|
|
3
3
|
import { extractFrontmatter } from '@bevel-software/platform-shared';
|
|
4
4
|
import type { FileRendererProps, RendererSaveState } from './types';
|
|
5
5
|
import { authFetch } from '../../../../lib/api';
|
|
6
|
-
import { Surface } from '../../../../shared/components';
|
|
6
|
+
import { Surface, useConfirm } from '../../../../shared/components';
|
|
7
7
|
import { Markdown } from '../../../../shared/markdown/Markdown';
|
|
8
8
|
import { ToolForm } from './ToolForm';
|
|
9
9
|
import { ToolSecretsPanel } from '../../../secrets-vault/components/ToolSecretsPanel';
|
|
10
10
|
import { listToolSecrets, type ToolSecrets } from '../../../secrets-vault/services/tool-secrets.api';
|
|
11
|
+
import { useRendererSurface } from './rendererSurface';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Whether the Form view can render this file: THE TOOL IS THE FRONTMATTER, so
|
|
@@ -103,6 +104,7 @@ export function ToolRenderer({
|
|
|
103
104
|
readOnly = false,
|
|
104
105
|
}: FileRendererProps) {
|
|
105
106
|
const [value, setValue] = useState(content);
|
|
107
|
+
const confirm = useConfirm();
|
|
106
108
|
const [savedValue, setSavedValue] = useState(savedContent ?? content);
|
|
107
109
|
const [saveState, setSaveState] = useState<RendererSaveState>('idle');
|
|
108
110
|
const [saveError, setSaveError] = useState<string | null>(null);
|
|
@@ -118,6 +120,15 @@ export function ToolRenderer({
|
|
|
118
120
|
|
|
119
121
|
const dirty = !readOnly && value !== savedValue;
|
|
120
122
|
|
|
123
|
+
// The three panels on the right — the Secrets Vault palette, this tool's
|
|
124
|
+
// secrets and the live Preview — act under the SIGNED-IN SESSION: they
|
|
125
|
+
// read the caller's vault and run the manual through the app's API. On a
|
|
126
|
+
// renderer surface (the embed, in a chat or an Atlassian panel) there is
|
|
127
|
+
// no session, only the embed token, which none of those routes take. So
|
|
128
|
+
// they are not drawn there, and their requests are not made: the file is
|
|
129
|
+
// still read and edited as text, and the rest belongs to the app.
|
|
130
|
+
const surface = useRendererSurface();
|
|
131
|
+
|
|
121
132
|
useEffect(() => {
|
|
122
133
|
setValue(content);
|
|
123
134
|
setSavedValue(savedContent ?? content);
|
|
@@ -143,6 +154,7 @@ export function ToolRenderer({
|
|
|
143
154
|
|
|
144
155
|
// Load the caller's Secrets Vault keys for the insert palette.
|
|
145
156
|
useEffect(() => {
|
|
157
|
+
if (surface) return;
|
|
146
158
|
let cancelled = false;
|
|
147
159
|
(async () => {
|
|
148
160
|
try {
|
|
@@ -157,7 +169,7 @@ export function ToolRenderer({
|
|
|
157
169
|
return () => {
|
|
158
170
|
cancelled = true;
|
|
159
171
|
};
|
|
160
|
-
}, []);
|
|
172
|
+
}, [surface]);
|
|
161
173
|
|
|
162
174
|
// Load THIS tool's declared variables + their config status (for the per-tool
|
|
163
175
|
// secrets panel). Matched from the default-branch catalog by file path (with a
|
|
@@ -184,8 +196,9 @@ export function ToolRenderer({
|
|
|
184
196
|
}, [filePath]);
|
|
185
197
|
|
|
186
198
|
useEffect(() => {
|
|
199
|
+
if (surface) return;
|
|
187
200
|
void loadToolSecrets();
|
|
188
|
-
}, [loadToolSecrets]);
|
|
201
|
+
}, [loadToolSecrets, surface]);
|
|
189
202
|
|
|
190
203
|
const save = useCallback(async (): Promise<boolean> => {
|
|
191
204
|
if (readOnly || value === savedValue) return true;
|
|
@@ -322,6 +335,9 @@ export function ToolRenderer({
|
|
|
322
335
|
)}
|
|
323
336
|
</div>
|
|
324
337
|
|
|
338
|
+
{/* On a surface the aside holds the scaffolds at most, so a read-only
|
|
339
|
+
embedded view draws no empty column beside the document. */}
|
|
340
|
+
{!(surface && readOnly) && (
|
|
325
341
|
<aside className="flex w-72 shrink-0 flex-col gap-4 overflow-y-auto p-3">
|
|
326
342
|
{!readOnly && (
|
|
327
343
|
<section>
|
|
@@ -330,10 +346,17 @@ export function ToolRenderer({
|
|
|
330
346
|
{(['inline', 'http', 'mcp'] as const).map((t) => (
|
|
331
347
|
<button
|
|
332
348
|
key={t}
|
|
333
|
-
onClick={() => {
|
|
334
|
-
if (
|
|
335
|
-
|
|
349
|
+
onClick={async () => {
|
|
350
|
+
if (value.trim()) {
|
|
351
|
+
const { confirmed } = await confirm({
|
|
352
|
+
title: 'Replace with scaffold',
|
|
353
|
+
message: 'Replace the file contents with this scaffold?',
|
|
354
|
+
confirmLabel: 'Replace',
|
|
355
|
+
destructive: true,
|
|
356
|
+
});
|
|
357
|
+
if (!confirmed) return;
|
|
336
358
|
}
|
|
359
|
+
updateValue(SCAFFOLDS[t]);
|
|
337
360
|
}}
|
|
338
361
|
className="rounded-xs bg-sunken px-2 py-1 text-meta text-ink-muted hover:bg-hover"
|
|
339
362
|
>
|
|
@@ -344,7 +367,7 @@ export function ToolRenderer({
|
|
|
344
367
|
</section>
|
|
345
368
|
)}
|
|
346
369
|
|
|
347
|
-
{!readOnly && (
|
|
370
|
+
{!readOnly && !surface && (
|
|
348
371
|
<section>
|
|
349
372
|
<h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Secret variables</h3>
|
|
350
373
|
{secretKeys.length === 0 ? (
|
|
@@ -368,6 +391,7 @@ export function ToolRenderer({
|
|
|
368
391
|
</section>
|
|
369
392
|
)}
|
|
370
393
|
|
|
394
|
+
{!surface && (
|
|
371
395
|
<section>
|
|
372
396
|
<h3 className="mb-1 text-meta font-semibold uppercase tracking-wide text-ink-faint">Secrets for this tool</h3>
|
|
373
397
|
{toolSecrets ? (
|
|
@@ -379,7 +403,9 @@ export function ToolRenderer({
|
|
|
379
403
|
</p>
|
|
380
404
|
)}
|
|
381
405
|
</section>
|
|
406
|
+
)}
|
|
382
407
|
|
|
408
|
+
{!surface && (
|
|
383
409
|
<section>
|
|
384
410
|
<div className="mb-1 flex items-center gap-2">
|
|
385
411
|
<h3 className="text-meta font-semibold uppercase tracking-wide text-ink-faint">Preview</h3>
|
|
@@ -416,7 +442,9 @@ export function ToolRenderer({
|
|
|
416
442
|
</div>
|
|
417
443
|
)}
|
|
418
444
|
</section>
|
|
445
|
+
)}
|
|
419
446
|
</aside>
|
|
447
|
+
)}
|
|
420
448
|
</Surface>
|
|
421
449
|
);
|
|
422
450
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import * as XLSX from 'xlsx';
|
|
3
|
-
import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
|
|
4
3
|
import { RetryReadButton } from './RetryReadButton';
|
|
5
4
|
import { useReadRetry } from './useReadRetry';
|
|
6
|
-
import {
|
|
7
|
-
import { rawFileUrl } from '../../services/workspace.api';
|
|
5
|
+
import { useRendererRawRead } from './rendererRawRead';
|
|
8
6
|
import { DownloadFileButton } from './DownloadFileButton';
|
|
9
7
|
import { readBodyCapped } from './readBodyCapped';
|
|
10
8
|
import type { FileRendererProps } from './types';
|
|
@@ -98,16 +96,15 @@ interface SheetView {
|
|
|
98
96
|
* as raw serial numbers / decimals.
|
|
99
97
|
*/
|
|
100
98
|
export function XlsxRenderer({ filePath }: FileRendererProps) {
|
|
101
|
-
const workspaceId = useRendererWorkspaceId();
|
|
102
|
-
/** A past save, when Version history mounted this; null = the working tree. */
|
|
103
|
-
const fileRef = useRendererFileRef();
|
|
104
99
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* a
|
|
100
|
+
* Where this file's bytes come from. In the app that is the workspace raw
|
|
101
|
+
* route under the session, for the workspace this viewer is pointed at and
|
|
102
|
+
* the save it is bound to; on a renderer surface (the embed) it is that
|
|
103
|
+
* surface's own route, with its own credential. Null until there is a
|
|
104
|
+
* workspace to read from — the same "nothing to read yet" the guard in the
|
|
105
|
+
* effect below has always had.
|
|
108
106
|
*/
|
|
109
|
-
const
|
|
110
|
-
const versionSide = fileRef?.side;
|
|
107
|
+
const rawRead = useRendererRawRead();
|
|
111
108
|
const { attempt, retry } = useReadRetry();
|
|
112
109
|
const [workbook, setWorkbook] = useState<XLSX.WorkBook | null>(null);
|
|
113
110
|
const [activeSheet, setActiveSheet] = useState(0);
|
|
@@ -117,7 +114,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
|
|
|
117
114
|
setWorkbook(null);
|
|
118
115
|
setActiveSheet(0);
|
|
119
116
|
setError(null);
|
|
120
|
-
if (!
|
|
117
|
+
if (!rawRead) return;
|
|
121
118
|
|
|
122
119
|
let cancelled = false;
|
|
123
120
|
// Cleanup ABORTS, not just flags: flipping `cancelled` alone left an
|
|
@@ -125,10 +122,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
|
|
|
125
122
|
const controller = new AbortController();
|
|
126
123
|
(async () => {
|
|
127
124
|
try {
|
|
128
|
-
const res = await
|
|
129
|
-
rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
|
|
130
|
-
{ signal: controller.signal },
|
|
131
|
-
);
|
|
125
|
+
const res = await rawRead.fetch(filePath, { signal: controller.signal });
|
|
132
126
|
if (cancelled) return;
|
|
133
127
|
if (!res.ok) {
|
|
134
128
|
setError(`Failed to load spreadsheet (HTTP ${res.status})`);
|
|
@@ -177,7 +171,7 @@ export function XlsxRenderer({ filePath }: FileRendererProps) {
|
|
|
177
171
|
cancelled = true;
|
|
178
172
|
controller.abort();
|
|
179
173
|
};
|
|
180
|
-
}, [
|
|
174
|
+
}, [rawRead, filePath, attempt]);
|
|
181
175
|
|
|
182
176
|
// Convert ONLY the sheet on screen, when it is on screen. `XLSX.read` has
|
|
183
177
|
// already materialized every cell (SheetJS has no partial parse), but
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import {
|
|
4
|
+
WorkspaceContext,
|
|
5
|
+
type WorkspaceContextValue,
|
|
6
|
+
} from '../../../state/workspace.context';
|
|
7
|
+
import { ConfirmProvider } from '../../../../../shared/components';
|
|
8
|
+
|
|
9
|
+
const apiMock = vi.hoisted(() => ({ authFetch: vi.fn() }));
|
|
10
|
+
vi.mock('../../../../../lib/api', () => ({ authFetch: apiMock.authFetch }));
|
|
11
|
+
|
|
12
|
+
import { EmailRenderer } from '../EmailRenderer';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Opening a link inside an email asks first, showing the real address — in
|
|
16
|
+
* the app's own dialog, which the browser cannot silence.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const URL = 'https://example.com/offer?id=7';
|
|
20
|
+
const EML = new TextEncoder().encode(
|
|
21
|
+
[
|
|
22
|
+
'From: Ada <ada@example.com>',
|
|
23
|
+
'Subject: Offer',
|
|
24
|
+
'MIME-Version: 1.0',
|
|
25
|
+
'Content-Type: text/html; charset=utf-8',
|
|
26
|
+
'',
|
|
27
|
+
`<p>See <a href="${URL}">our offer</a>.</p>`,
|
|
28
|
+
'',
|
|
29
|
+
].join('\r\n'),
|
|
30
|
+
).buffer as ArrayBuffer;
|
|
31
|
+
|
|
32
|
+
let openSpy: MockInstance<Window['open']>;
|
|
33
|
+
let confirmSpy: MockInstance<Window['confirm']>;
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
apiMock.authFetch.mockReset();
|
|
36
|
+
apiMock.authFetch.mockResolvedValue({ ok: true, arrayBuffer: async () => EML });
|
|
37
|
+
openSpy = vi.spyOn(window, 'open').mockReturnValue(null);
|
|
38
|
+
// The browser's dialogs suppressed: never the thing that answers.
|
|
39
|
+
confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
expect(confirmSpy).not.toHaveBeenCalled();
|
|
43
|
+
vi.restoreAllMocks();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
async function clickOpen() {
|
|
47
|
+
render(
|
|
48
|
+
<ConfirmProvider>
|
|
49
|
+
<WorkspaceContext.Provider value={{ workspaceId: 'ws-1' } as unknown as WorkspaceContextValue}>
|
|
50
|
+
<EmailRenderer filePath="Inbox/offer.eml" content="" onSave={async () => {}} />
|
|
51
|
+
</WorkspaceContext.Provider>
|
|
52
|
+
</ConfirmProvider>,
|
|
53
|
+
);
|
|
54
|
+
fireEvent.click(await screen.findByTitle('Open in a new tab'));
|
|
55
|
+
return screen.findByRole('dialog');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('a link in an email', () => {
|
|
59
|
+
it("asks with today's question and the address; Cancel opens nothing", async () => {
|
|
60
|
+
const dialog = await clickOpen();
|
|
61
|
+
expect(dialog.textContent).toContain(`Open this link?\n\n${URL}`);
|
|
62
|
+
expect(within(dialog).queryByText("Don't ask again")).toBeNull();
|
|
63
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
|
64
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
65
|
+
expect(openSpy).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Open opens it in a new tab', async () => {
|
|
69
|
+
const dialog = await clickOpen();
|
|
70
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Open' }));
|
|
71
|
+
await waitFor(() => expect(openSpy).toHaveBeenCalledWith(URL, '_blank', 'noopener,noreferrer'));
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import { ToolRenderer } from '../ToolRenderer';
|
|
4
|
+
import { ConfirmProvider } from '../../../../../shared/components';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* "Replace with scaffold" over a file that already has contents asks first —
|
|
8
|
+
* in the app's own dialog, which the browser cannot silence. Without it, a
|
|
9
|
+
* suppressed built-in confirm answered "no" and the button did nothing.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
vi.stubGlobal(
|
|
14
|
+
'fetch',
|
|
15
|
+
vi.fn(async () => ({ ok: true, status: 200, json: async () => ({ secrets: [], tools: [] }) })),
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
vi.unstubAllGlobals();
|
|
21
|
+
vi.restoreAllMocks();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function renderTool(content: string) {
|
|
25
|
+
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
|
|
26
|
+
render(
|
|
27
|
+
<ConfirmProvider>
|
|
28
|
+
<ToolRenderer content={content} filePath="Tools/my_tool.tool" onSave={async () => undefined} />
|
|
29
|
+
</ConfirmProvider>,
|
|
30
|
+
);
|
|
31
|
+
const textarea = () => document.querySelector('textarea') as HTMLTextAreaElement;
|
|
32
|
+
return { confirmSpy, textarea };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('the .tool scaffold', () => {
|
|
36
|
+
it("asks with today's question; Cancel keeps the contents", async () => {
|
|
37
|
+
const { confirmSpy, textarea } = renderTool('not: [a manual');
|
|
38
|
+
fireEvent.click(screen.getByRole('button', { name: 'http' }));
|
|
39
|
+
const dialog = await screen.findByRole('dialog');
|
|
40
|
+
expect(dialog.textContent).toContain('Replace the file contents with this scaffold?');
|
|
41
|
+
expect(within(dialog).queryByText("Don't ask again")).toBeNull();
|
|
42
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
|
43
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
44
|
+
expect(textarea().value).toBe('not: [a manual');
|
|
45
|
+
expect(confirmSpy).not.toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('Replace puts the scaffold in, even with the browser\'s dialogs suppressed', async () => {
|
|
49
|
+
const { confirmSpy, textarea } = renderTool('not: [a manual');
|
|
50
|
+
fireEvent.click(screen.getByRole('button', { name: 'http' }));
|
|
51
|
+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Replace' }));
|
|
52
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
53
|
+
await waitFor(() => expect(textarea().value).toContain('type: http'));
|
|
54
|
+
expect(confirmSpy).not.toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('an empty file takes the scaffold without a question, as today', async () => {
|
|
58
|
+
renderTool('');
|
|
59
|
+
fireEvent.click(screen.getByRole('button', { name: 'inline' }));
|
|
60
|
+
// An empty file opens in the form view; the scaffold makes it unsaved.
|
|
61
|
+
expect(await screen.findByText('● unsaved')).toBeInTheDocument();
|
|
62
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
});
|