Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(drive): missing file operations from entity detail file menu (#6805)

dev-rbe4ac4e6e4fca
diff --git a/apps/web/src/components/entity-detail/EntityDetail.tsx b/apps/web/src/components/entity-detail/EntityDetail.tsx
index 48c9f31ac9..5bb2e0fcee 100644
--- a/apps/web/src/components/entity-detail/EntityDetail.tsx
+++ b/apps/web/src/components/entity-detail/EntityDetail.tsx
@@ -1,26 +1,48 @@
-import { CanvasDetail } from '@app/features/drive-view/views/CanvasDetail';
-import { CodeDetail } from '@app/features/drive-view/views/CodeDetail';
-import { ImageDetail } from '@app/features/drive-view/views/ImageDetail';
-import { MarkdownDetail } from '@app/features/drive-view/views/MarkdownDetail';
-import { PdfDetail } from '@app/features/drive-view/views/PdfDetail';
-import { UnknownDetail } from '@app/features/drive-view/views/UnknownDetail';
-import { VideoDetail } from '@app/features/drive-view/views/VideoDetail';
+import {
+ CanvasDetail,
+ type CanvasDetailContext,
+} from '@app/features/drive-view/views/CanvasDetail';
+import {
+ CodeDetail,
+ type CodeDetailContext,
+} from '@app/features/drive-view/views/CodeDetail';
+import {
+ ImageDetail,
+ type ImageDetailContext,
+} from '@app/features/drive-view/views/ImageDetail';
+import {
+ MarkdownDetail,
+ type MarkdownDetailContext,
+} from '@app/features/drive-view/views/MarkdownDetail';
+import {
+ PdfDetail,
+ type PdfDetailContext,
+} from '@app/features/drive-view/views/PdfDetail';
+import {
+ UnknownDetail,
+ type UnknownDetailContext,
+} from '@app/features/drive-view/views/UnknownDetail';
+import {
+ VideoDetail,
+ type VideoDetailContext,
+} from '@app/features/drive-view/views/VideoDetail';
import type { MarkdownDocumentKind } from '@block-md/types';
import { useGlobalBlockOrchestrator } from '@components/app/GlobalAppState';
import { PreviewPanel } from '@components/app/PreviewPanel';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
import type { BlockAlias, BlockName } from '@core/block';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
-import type { AccessLevel } from '@service-storage/generated/schemas/accessLevel';
-import type { DocumentMetadata } from '@service-storage/generated/schemas/documentMetadata';
import { type JSX, Match, Switch } from 'solid-js';
import type { EntityDetailTarget } from './EntityDetailNavigationStack';
-export type EntityDetailContext = {
- documentMetadata: DocumentMetadata;
- userAccessLevel: AccessLevel;
- blockType: BlockName | BlockAlias;
-};
+export type EntityDetailContext =
+ | MarkdownDetailContext
+ | CodeDetailContext
+ | CanvasDetailContext
+ | ImageDetailContext
+ | VideoDetailContext
+ | PdfDetailContext
+ | UnknownDetailContext;
export type EntityDetailProps = {
target: EntityDetailTarget;
@@ -82,15 +104,8 @@ export function EntityDetail(props: EntityDetailProps) {
const documentTarget = () =>
props.target.type === 'document' ? props.target : undefined;
const blockType = () => entityDetailBlockType(props.target);
- const renderChildren = (
- documentMetadata: DocumentMetadata,
- userAccessLevel: AccessLevel
- ) =>
- props.children?.({
- documentMetadata,
- userAccessLevel,
- blockType: blockType()!,
- });
+ const renderChildren = (context: EntityDetailContext) =>
+ props.children?.(context);
return (
<Switch>
@@ -112,12 +127,7 @@ export function EntityDetail(props: EntityDetailProps) {
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {(context) =>
- renderChildren(
- context.data.metadata,
- context.data.userAccessLevel
- )
- }
+ {(context) => <>{renderChildren(context)}</>}
</MarkdownDetail>
)}
</Match>
@@ -127,12 +137,7 @@ export function EntityDetail(props: EntityDetailProps) {
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {(context) =>
- renderChildren(
- context.data.documentMetadata,
- context.data.userAccessLevel
- )
- }
+ {(context) => <>{renderChildren(context)}</>}
</CodeDetail>
</Match>
<Match when={blockType() === 'canvas'}>
@@ -141,12 +146,7 @@ export function EntityDetail(props: EntityDetailProps) {
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {(context) =>
- renderChildren(
- context.data.documentMetadata,
- context.data.userAccessLevel
- )
- }
+ {(context) => <>{renderChildren(context)}</>}
</CanvasDetail>
</Match>
<Match when={blockType() === 'image'}>
@@ -155,12 +155,7 @@ export function EntityDetail(props: EntityDetailProps) {
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {(context) =>
- renderChildren(
- context.data.documentMetadata,
- context.data.userAccessLevel
- )
- }
+ {(context) => <>{renderChildren(context)}</>}
</ImageDetail>
</Match>
<Match when={blockType() === 'video'}>
@@ -169,12 +164,7 @@ export function EntityDetail(props: EntityDetailProps) {
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {(context) =>
- renderChildren(
- context.data.documentMetadata,
- context.data.userAccessLevel
- )
- }
+ {(context) => <>{renderChildren(context)}</>}
</VideoDetail>
</Match>
<Match when={blockType() === 'pdf'}>
@@ -183,12 +173,7 @@ export function EntityDetail(props: EntityDetailProps) {
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {(context) =>
- renderChildren(
- context.data.documentMetadata,
- context.data.userAccessLevel
- )
- }
+ {(context) => <>{renderChildren(context)}</>}
</PdfDetail>
</Match>
<Match when={blockType() === 'unknown'}>
@@ -197,12 +182,7 @@ export function EntityDetail(props: EntityDetailProps) {
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {(context) =>
- renderChildren(
- context.data.documentMetadata,
- context.data.userAccessLevel
- )
- }
+ {(context) => <>{renderChildren(context)}</>}
</UnknownDetail>
</Match>
<Match when={true}>
diff --git a/apps/web/src/features/block-pdf/component/TopBar.tsx b/apps/web/src/features/block-pdf/component/TopBar.tsx
index b449a695aa..f3d964a052 100644
--- a/apps/web/src/features/block-pdf/component/TopBar.tsx
+++ b/apps/web/src/features/block-pdf/component/TopBar.tsx
@@ -5,8 +5,11 @@ import {
} from '@app/features/chat/ChatWithAgentButton';
import { useHasModificationData } from '@block-pdf/signal/save';
import { useHasComments } from '@block-pdf/store/comments/commentStore';
-import { doPrint } from '@block-pdf/util/printUtil';
-import { exportPdf } from '@block-pdf/websocket/export';
+import {
+ downloadDocxDocument,
+ downloadPdfDocument,
+ printPdfDocument,
+} from '@block-pdf/util/pdf-file-actions';
import type { BlockTool } from '@components/app/ResponsiveBlockToolbar';
import {
ResponsiveBlockToolbar,
@@ -30,15 +33,10 @@ import {
} from '@core/component/TopBar/ShareButton';
import { blockMetadataSignal } from '@core/signal/load';
import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';
-import { platformFetch } from '@core/util/platformFetch';
-import { downloadFile } from '@filesystem/download';
import DownloadIcon from '@phosphor/download-simple.svg';
import Printer from '@phosphor/printer.svg';
import IconShared from '@phosphor/share.svg';
-import {
- blockNameToItemType,
- storageServiceClient,
-} from '@service-storage/client';
+import { blockNameToItemType } from '@service-storage/itemType';
import { createCallback } from '@solid-primitives/rootless';
import { usePdfDocument } from '../context/pdf-document-context';
import { LocationType, useCreateShareUrl } from '../signal/location';
@@ -68,83 +66,36 @@ export function TopBar() {
toast.success('Link copied to clipboard');
};
- const printFile = createCallback(async () => {
- if (!isAuth()) return openLoginModal();
-
- const proxy = documentProxy();
- if (!proxy) return;
-
- const data = (await proxy.getData()) as Uint8Array<ArrayBuffer>;
- const blob = new Blob([data], { type: 'application/pdf' });
-
- return doPrint(blob);
+ const fileActionAuth = () => ({
+ isAuthenticated: !!isAuth(),
+ openLogin: openLoginModal,
});
- const download = createCallback(async () => {
- if (!isAuth()) return openLoginModal();
-
- const proxy = documentProxy();
- if (!proxy) return toast.failure('Unable to download file');
-
- const data = (await proxy.getData()) as Uint8Array<ArrayBuffer>;
- const blob = new Blob([data], { type: 'application/pdf' });
-
- const fileNameWithExtension = `${fileName()}.pdf`;
-
- try {
- // No need to export if there are no modifications
- // comments are outside of the modification data so handled separately
- if (!hasModificationData() && hasComments() === false)
- return downloadFile(blob, fileNameWithExtension);
-
- // Attempt to export and download
- const exportFile = await exportPdf({
- documentId,
- fileName: fileName(),
- });
- downloadFile(exportFile, fileNameWithExtension);
- } catch (_) {
- try {
- downloadFile(blob, fileNameWithExtension);
- } catch (_) {
- toast.failure('Unable to download file');
- }
- }
- });
-
- const downloadDocx = createCallback(async () => {
- if (!isAuth()) return openLoginModal();
-
- const data = await storageServiceClient.exportDocument({ documentId });
- if (data.isErr()) {
- return toast.failure('Unable to download file');
- }
-
- const fileNameWithExtension = `${fileName()}.docx`;
-
- try {
- // Fetch the file from the presigned URL
- const response = await platformFetch(data.value.presigned_url);
- if (!response.ok) {
- throw new Error(`HTTP error! status: ${response.status}`);
- }
-
- // Get the file data as array buffer
- const arrayBuffer = await response.arrayBuffer();
-
- // Create blob with proper MIME type for DOCX
- const blob = new Blob([arrayBuffer], {
- type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- });
+ const printFile = createCallback(() =>
+ printPdfDocument({
+ ...fileActionAuth(),
+ documentProxy: documentProxy(),
+ })
+ );
- downloadFile(blob, fileNameWithExtension);
+ const download = createCallback(() =>
+ downloadPdfDocument({
+ ...fileActionAuth(),
+ documentProxy: documentProxy(),
+ hasModifications: hasModificationData(),
+ hasComments: hasComments(),
+ documentId,
+ fileName: fileName(),
+ })
+ );
- toast.success('File downloaded successfully');
- } catch (error) {
- console.error('Download failed:', error);
- toast.failure('Failed to download file');
- }
- });
+ const downloadDocx = createCallback(() =>
+ downloadDocxDocument({
+ ...fileActionAuth(),
+ documentId,
+ fileName: fileName(),
+ })
+ );
const ops: FileOperation[] = [
{ op: 'rename' },
diff --git a/apps/web/src/features/block-pdf/queries/export-docx.ts b/apps/web/src/features/block-pdf/queries/export-docx.ts
new file mode 100644
index 0000000000..d7aa12462a
--- /dev/null
+++ b/apps/web/src/features/block-pdf/queries/export-docx.ts
@@ -0,0 +1,16 @@
+import { platformFetch } from '@core/util/platformFetch';
+import { storageServiceClient } from '@service-storage/client';
+
+export async function fetchExportedDocx(documentId: string): Promise<Blob> {
+ const result = await storageServiceClient.exportDocument({ documentId });
+ if (result.isErr()) throw result.error;
+
+ const response = await platformFetch(result.value.presigned_url);
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+
+ return new Blob([await response.arrayBuffer()], {
+ type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ });
+}
diff --git a/apps/web/src/features/block-pdf/util/pdf-file-actions.ts b/apps/web/src/features/block-pdf/util/pdf-file-actions.ts
new file mode 100644
index 0000000000..692a10e346
--- /dev/null
+++ b/apps/web/src/features/block-pdf/util/pdf-file-actions.ts
@@ -0,0 +1,85 @@
+import { toast } from '@core/component/Toast/Toast';
+import { downloadFile } from '@filesystem/download';
+import type { PDFDocumentProxy } from 'pdfjs-dist/types/src/display/api';
+import { fetchExportedDocx } from '../queries/export-docx';
+import { exportPdf } from '../websocket/export';
+import { doPrint } from './printUtil';
+
+type PdfFileActionAuth = {
+ isAuthenticated: boolean;
+ openLogin: () => void;
+};
+
+function requireAuth(auth: PdfFileActionAuth) {
+ if (auth.isAuthenticated) return true;
+ auth.openLogin();
+ return false;
+}
+
+async function pdfBytes(proxy: PDFDocumentProxy) {
+ const data = (await proxy.getData()) as Uint8Array<ArrayBuffer>;
+ return new Blob([data], { type: 'application/pdf' });
+}
+
+export async function printPdfDocument(
+ auth: PdfFileActionAuth & { documentProxy: PDFDocumentProxy | undefined }
+) {
+ if (!requireAuth(auth)) return;
+ const proxy = auth.documentProxy;
+ if (!proxy) return;
+ return doPrint(await pdfBytes(proxy));
+}
+
+export async function downloadPdfDocument(
+ auth: PdfFileActionAuth & {
+ documentProxy: PDFDocumentProxy | undefined;
+ hasModifications: boolean;
+ hasComments: boolean;
+ documentId: string;
+ fileName: string;
+ }
+) {
+ if (!requireAuth(auth)) return;
+
+ const proxy = auth.documentProxy;
+ if (!proxy) return toast.failure('Unable to download file');
+
+ const blob = await pdfBytes(proxy);
+ const fileNameWithExtension = `${auth.fileName}.pdf`;
+
+ try {
+ // No need to export if there are no modifications.
+ // Comments live outside the modification data, so they are handled separately.
+ if (!auth.hasModifications && !auth.hasComments)
+ return downloadFile(blob, fileNameWithExtension);
+
+ const exportFile = await exportPdf({
+ documentId: auth.documentId,
+ fileName: auth.fileName,
+ });
+ downloadFile(exportFile, fileNameWithExtension);
+ } catch (_) {
+ try {
+ downloadFile(blob, fileNameWithExtension);
+ } catch (_) {
+ toast.failure('Unable to download file');
+ }
+ }
+}
+
+export async function downloadDocxDocument(
+ auth: PdfFileActionAuth & { documentId: string; fileName: string }
+) {
+ if (!requireAuth(auth)) return;
+
+ const fileNameWithExtension = `${auth.fileName}.docx`;
+
+ try {
+ const blob = await fetchExportedDocx(auth.documentId);
+ downloadFile(blob, fileNameWithExtension);
+ toast.success('File downloaded successfully');
+ } catch (error) {
+ console.error('Download failed:', error);
+ toast.failure('Failed to download file');
+ }
+}
diff --git a/apps/web/src/features/drive-view/components/DriveDetailView.tsx b/apps/web/src/features/drive-view/components/DriveDetailView.tsx
index 579650e70f..e81b7added 100644
--- a/apps/web/src/features/drive-view/components/DriveDetailView.tsx
+++ b/apps/web/src/features/drive-view/components/DriveDetailView.tsx
@@ -172,30 +172,33 @@ function StackEntityDetail(props: {
</Show>
}
>
- {(context) => (
- <FileDetailBreadcrumbItem
- value={props.entry.value}
- metadata={props.entry.data}
- order={props.order}
- documentMetadata={context.documentMetadata}
- userAccessLevel={context.userAccessLevel}
- blockType={context.blockType}
- fallbackName={props.entry.data.fallbackName}
- onClose={navigationStack.pop}
- onDuplicate={(id, name) => {
- const target = props.entry.data;
- if (target.type !== 'document') return;
- navigationStack.navigate(
- entityDetailTarget.document({
- id,
- fileType: target.fileType,
- subType: target.subType,
- fallbackName: name,
- })
- );
- }}
- />
- )}
+ {(context) => {
+ return (
+ <FileDetailBreadcrumbItem
+ value={props.entry.value}
+ metadata={props.entry.data}
+ order={props.order}
+ documentMetadata={context.documentMetadata}
+ userAccessLevel={context.userAccessLevel}
+ blockType={entityDetailBlockType(props.entry.data)!}
+ operations={context.operations}
+ fallbackName={props.entry.data.fallbackName}
+ onClose={navigationStack.pop}
+ onDuplicate={(id, name) => {
+ const target = props.entry.data;
+ if (target.type !== 'document') return;
+ navigationStack.navigate(
+ entityDetailTarget.document({
+ id,
+ fileType: target.fileType,
+ subType: target.subType,
+ fallbackName: name,
+ })
+ );
+ }}
+ />
+ );
+ }}
</EntityDetail>
</Match>
</Switch>
diff --git a/apps/web/src/features/drive-view/components/FileDetailBreadcrumbItem.tsx b/apps/web/src/features/drive-view/components/FileDetailBreadcrumbItem.tsx
index 99a1be33fe..b0ccc5489e 100644
--- a/apps/web/src/features/drive-view/components/FileDetailBreadcrumbItem.tsx
+++ b/apps/web/src/features/drive-view/components/FileDetailBreadcrumbItem.tsx
@@ -10,13 +10,6 @@ import { buildEntityData } from '@entity';
import type { AccessLevel } from '@service-storage/generated/schemas/accessLevel';
import type { DocumentMetadata } from '@service-storage/generated/schemas/documentMetadata';
-const fileOperations: FileOperation[] = [
- { op: 'copy' },
- { op: 'rename' },
- { op: 'moveToProject' },
- { op: 'delete' },
-];
-
export function FileDetailBreadcrumbItem(props: {
value: string;
metadata: unknown;
@@ -25,10 +18,18 @@ export function FileDetailBreadcrumbItem(props: {
userAccessLevel: AccessLevel;
blockType: BlockName | BlockAlias;
fallbackName?: string;
+ operations?: FileOperation[];
onClose: () => void;
onDuplicate: (id: string, name: string) => void;
}) {
const panel = useSplitPanelOrThrow();
+ const fileOperations = (): FileOperation[] => [
+ { op: 'copy' },
+ { op: 'rename' },
+ { op: 'moveToProject' },
+ ...(props.operations ?? []),
+ { op: 'delete' },
+ ];
const documentId = () => props.documentMetadata.documentId;
const documentName = () =>
props.documentMetadata.documentName ?? props.fallbackName ?? 'Untitled';
@@ -73,7 +74,7 @@ export function FileDetailBreadcrumbItem(props: {
id={documentId()}
itemType="document"
name={documentName()}
- ops={fileOperations}
+ ops={fileOperations()}
entityKind={props.blockType}
permissions={getPermissions(props.userAccessLevel)}
onDuplicate={(id) => props.onDuplicate(id, documentName())}
diff --git a/apps/web/src/features/drive-view/components/file-detail-operations.tsx b/apps/web/src/features/drive-view/components/file-detail-operations.tsx
new file mode 100644
index 0000000000..e4a7afda33
--- /dev/null
+++ b/apps/web/src/features/drive-view/components/file-detail-operations.tsx
@@ -0,0 +1,11 @@
+import type { FileOperation } from '@components/app/split-layout/components/SplitFileMenu';
+import DownloadSimple from '@phosphor/download-simple.svg';
+
+export function downloadFileOperation(action: () => void): FileOperation {
+ return {
+ group: 'file',
+ label: 'Download',
+ icon: DownloadSimple,
+ action,
+ };
+}
diff --git a/apps/web/src/features/drive-view/util/document-download-name.ts b/apps/web/src/features/drive-view/util/document-download-name.ts
new file mode 100644
index 0000000000..b5ac2226b5
--- /dev/null
+++ b/apps/web/src/features/drive-view/util/document-download-name.ts
@@ -0,0 +1,15 @@
+import { formatDocumentName } from '@service-storage/util/filename';
+
+export function documentDownloadName(
+ metadata: {
+ documentName?: string | null;
+ fileType?: string | null;
+ },
+ fallback = 'download'
+) {
+ return formatDocumentName(
+ metadata.documentName || fallback,
+ metadata.fileType,
+ { caseInsensitiveSuffix: true }
+ );
+}
diff --git a/apps/web/src/features/drive-view/util/download-with-progress.tsx b/apps/web/src/features/drive-view/util/download-with-progress.tsx
new file mode 100644
index 0000000000..7ab1fd6739
--- /dev/null
+++ b/apps/web/src/features/drive-view/util/download-with-progress.tsx
@@ -0,0 +1,76 @@
+import { toast } from '@core/component/Toast/Toast';
+import { downloadFile } from '@filesystem/download';
+import Spinner from '@phosphor/spinner.svg';
+import type { FetchProgress } from '@service-storage/util/fetchPresigned';
+import { createSignal } from 'solid-js';
+
+const SIZE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB'];
+
+function formatBytes(bytes: number): string {
+ if (bytes <= 0) return '0 B';
+ const exp = Math.min(
+ Math.floor(Math.log(bytes) / Math.log(1024)),
+ SIZE_UNITS.length - 1
+ );
+ const value = bytes / 1024 ** exp;
+ const decimals = exp === 0 || value >= 100 ? 0 : value >= 10 ? 1 : 2;
+ return `${value.toFixed(decimals)} ${SIZE_UNITS[exp]}`;
+}
+
+function DownloadProgressBar(props: { progress: FetchProgress }) {
+ const hasTotal = () => props.progress.total > 0;
+ const percent = () =>
+ hasTotal()
+ ? Math.min(
+ 100,
+ Math.round((props.progress.loaded / props.progress.total) * 100)
+ )
+ : 0;
+
+ return (
+ <div class="space-y-1">
+ <div class="h-1 w-full overflow-hidden rounded-full bg-edge">
+ <div
+ class="h-full bg-accent transition-[width] duration-150 ease-linear"
+ classList={{ 'animate-pulse w-full': !hasTotal() }}
+ style={hasTotal() ? { width: `${percent()}%` } : undefined}
+ />
+ </div>
+ <div class="text-xs text-ink-extra-muted">
+ {hasTotal() ? `${percent()}% — ` : ''}
+ {formatBytes(props.progress.loaded)}
+ {hasTotal() ? ` of ${formatBytes(props.progress.total)}` : ''}
+ </div>
+ </div>
+ );
+}
+
+export async function downloadWithProgress(
+ fileName: string,
+ load: (onProgress: (progress: FetchProgress) => void) => Promise<Blob>
+) {
+ const [progress, setProgress] = createSignal<FetchProgress>({
+ loaded: 0,
+ total: 0,
+ });
+ const toastId = toast.custom(
+ {
+ title: `Downloading ${fileName}`,
+ icon: () => <Spinner class="size-5 animate-spin text-accent" />,
+ color: 'var(--color-accent)',
+ content: () => <DownloadProgressBar progress={progress()} />,
+ },
+ { persistent: true }
+ );
+
+ try {
+ const blob = await load(setProgress);
+ downloadFile(blob, fileName);
+ toast.dismiss(toastId);
+ toast.success(`Downloaded ${fileName}`);
+ } catch (error) {
+ toast.dismiss(toastId);
+ console.error('error downloading file', error);
+ toast.failure('Error downloading file');
+ }
+}
diff --git a/apps/web/src/features/drive-view/util/file-detail-context.ts b/apps/web/src/features/drive-view/util/file-detail-context.ts
new file mode 100644
index 0000000000..f4c31ba476
--- /dev/null
+++ b/apps/web/src/features/drive-view/util/file-detail-context.ts
@@ -0,0 +1,10 @@
+import type { FileOperation } from '@components/app/split-layout/components/SplitFileMenu';
+import type { AccessLevel } from '@service-storage/generated/schemas/accessLevel';
+import type { DocumentMetadata } from '@service-storage/generated/schemas/documentMetadata';
+
+export type FileDetailContext<T> = {
+ data: T;
+ documentMetadata: DocumentMetadata;
+ userAccessLevel: AccessLevel;
+ operations?: FileOperation[];
+};
diff --git a/apps/web/src/features/drive-view/views/CanvasDetail.tsx b/apps/web/src/features/drive-view/views/CanvasDetail.tsx
index 876c7ce67f..304bb96e71 100644
--- a/apps/web/src/features/drive-view/views/CanvasDetail.tsx
+++ b/apps/web/src/features/drive-view/views/CanvasDetail.tsx
@@ -1,10 +1,13 @@
+import { useAnalytics } from '@app/lib/analytics/analytics-context';
import { CanvasDocument } from '@block-canvas/component/CanvasDocument';
+import { useCanvasDocument } from '@block-canvas/context/canvas-document-context';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
import {
getPermissions,
hasPermissions,
Permissions,
} from '@core/component/SharePermissions';
+import { downloadFile } from '@filesystem/download';
import { useSearchParams } from '@solidjs/router';
import type { JSX } from 'solid-js';
import {
@@ -12,14 +15,48 @@ import {
FileDetailLoadGate,
type FileDetailShareProps,
} from '../components/FileDetail';
+import { downloadFileOperation } from '../components/file-detail-operations';
import {
type CanvasDocumentData,
loadCanvasDocument,
} from '../queries/canvas-document';
+import { documentDownloadName } from '../util/document-download-name';
+import type { FileDetailContext } from '../util/file-detail-context';
-export type CanvasDetailContext = {
+export type CanvasDetailContext = FileDetailContext<CanvasDocumentData>;
+
+function CanvasDetailContent(props: {
data: CanvasDocumentData;
-};
+ children?: (context: CanvasDetailContext) => JSX.Element;
+ content: JSX.Element;
+}) {
+ const analytics = useAnalytics();
+ const [savedFile] = useCanvasDocument().state.signals.currentSavedFile;
+ const downloadName = documentDownloadName(
+ props.data.documentMetadata,
+ 'Unknown Filename'
+ );
+ const operations = [
+ downloadFileOperation(() => {
+ downloadFile(savedFile() ?? props.data.file, downloadName);
+ analytics.track('download', { blockType: 'canvas' });
+ }),
+ ];
+
+ return (
+ <>
+ {props.children?.({
+ data: props.data,
+ documentMetadata: props.data.documentMetadata,
+ userAccessLevel: props.data.userAccessLevel,
+ operations,
+ })}
+ <div class="flex size-full min-h-0 min-w-0 flex-col overflow-hidden">
+ {props.content}
+ </div>
+ </>
+ );
+}
export function CanvasDetailDocument(
props: FileDetailShareProps & {
@@ -45,7 +82,6 @@ export function CanvasDetailDocument(
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {props.children?.({ data: props.data })}
<CanvasDocument
documentId={props.documentId}
file={props.data.file}
@@ -55,9 +91,11 @@ export function CanvasDetailDocument(
locationParams={searchParams}
>
{(content) => (
- <div class="flex size-full min-h-0 min-w-0 flex-col overflow-hidden">
- {content}
- </div>
+ <CanvasDetailContent
+ data={props.data}
+ children={props.children}
+ content={content}
+ />
)}
</CanvasDocument>
</FileDetailLayout>
diff --git a/apps/web/src/features/drive-view/views/CodeDetail.tsx b/apps/web/src/features/drive-view/views/CodeDetail.tsx
index 9a769c3a21..aa75b3e6be 100644
--- a/apps/web/src/features/drive-view/views/CodeDetail.tsx
+++ b/apps/web/src/features/drive-view/views/CodeDetail.tsx
@@ -1,38 +1,47 @@
+import { useAnalytics } from '@app/lib/analytics/analytics-context';
import {
type CodeBlockMode,
CodeContent,
} from '@block-code/component/CodeContent';
import { CodeModeControl } from '@block-code/component/CodeModeControl';
import { isHtmlFileType } from '@block-code/util/fileMode';
+import { downloadFile } from '@filesystem/download';
import { Rerun } from '@solid-primitives/keyed';
-import { createSignal, type JSX, Show } from 'solid-js';
+import {
+ type Accessor,
+ createSignal,
+ type JSX,
+ type Setter,
+ Show,
+} from 'solid-js';
import {
FileDetailLayout,
FileDetailLoadGate,
type FileDetailShareProps,
} from '../components/FileDetail';
+import { downloadFileOperation } from '../components/file-detail-operations';
import {
type CodeDocumentData,
loadCodeDocument,
saveCodeDocument,
} from '../queries/code-document';
+import { documentDownloadName } from '../util/document-download-name';
+import type { FileDetailContext } from '../util/file-detail-context';
-export type CodeDetailContext = {
- data: CodeDocumentData;
-};
+export type CodeDetailContext = FileDetailContext<CodeDocumentData>;
function CodeDetailContent(props: {
documentId: string;
data: CodeDocumentData;
+ text: Accessor<string>;
+ onTextChange: Setter<string>;
}) {
const documentId = props.documentId;
- const initialText = props.data.text;
const fileType = props.data.documentMetadata.fileType;
const readOnly =
props.data.userAccessLevel !== 'owner' &&
props.data.userAccessLevel !== 'edit';
const isHtmlFile = isHtmlFileType(fileType);
- const [text, setText] = createSignal(initialText);
const [mode, setMode] = createSignal<CodeBlockMode>(
isHtmlFile ? 'render' : 'code'
);
@@ -46,11 +55,11 @@ function CodeDetailContent(props: {
</Show>
<div class="relative min-h-0 min-w-0 flex-1 overflow-hidden">
<CodeContent
- text={text()}
+ text={props.text()}
fileType={fileType}
readOnly={readOnly}
mode={mode()}
- onTextChange={setText}
+ onTextChange={props.onTextChange}
onSave={(nextText) => saveCodeDocument(documentId, nextText)}
/>
</div>
@@ -58,6 +67,41 @@ function CodeDetailContent(props: {
);
}
+function CodeDetailSession(props: {
+ documentId: string;
+ data: CodeDocumentData;
+ children?: (context: CodeDetailContext) => JSX.Element;
+}) {
+ const analytics = useAnalytics();
+ const [text, setText] = createSignal(props.data.text);
+ const operations = [
+ downloadFileOperation(() => {
+ downloadFile(
+ new Blob([text() ?? ''], { type: 'text/plain' }),
+ documentDownloadName(props.data.documentMetadata)
+ );
+ analytics.track('download', { blockType: 'code' });
+ }),
+ ];
+
+ return (
+ <>
+ {props.children?.({
+ data: props.data,
+ documentMetadata: props.data.documentMetadata,
+ userAccessLevel: props.data.userAccessLevel,
+ operations,
+ })}
+ <CodeDetailContent
+ documentId={props.documentId}
+ data={props.data}
+ text={text}
+ onTextChange={setText}
+ />
+ </>
+ );
+}
+
export function CodeDetailDocument(
props: FileDetailShareProps & {
documentId: string;
@@ -79,14 +123,17 @@ export function CodeDetailDocument(
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {props.children?.({ data: props.data })}
<Rerun
on={() =>
`${props.documentId}:${props.data.documentMetadata.documentVersionId}`
}
>
{() => (
- <CodeDetailContent documentId={props.documentId} data={props.data} />
+ <CodeDetailSession
+ documentId={props.documentId}
+ data={props.data}
+ children={props.children}
+ />
)}
</Rerun>
</FileDetailLayout>
diff --git a/apps/web/src/features/drive-view/views/ImageDetail.tsx b/apps/web/src/features/drive-view/views/ImageDetail.tsx
index 928db7ce08..d988fea296 100644
--- a/apps/web/src/features/drive-view/views/ImageDetail.tsx
+++ b/apps/web/src/features/drive-view/views/ImageDetail.tsx
@@ -1,18 +1,20 @@
import { ImageContent } from '@block-image/component/ImageContent';
+import { downloadFile } from '@filesystem/download';
import type { JSX } from 'solid-js';
import {
FileDetailLayout,
FileDetailLoadGate,
type FileDetailShareProps,
} from '../components/FileDetail';
+import { downloadFileOperation } from '../components/file-detail-operations';
import {
type ImageDocumentData,
loadImageDocument,
} from '../queries/image-document';
+import { documentDownloadName } from '../util/document-download-name';
+import type { FileDetailContext } from '../util/file-detail-context';
-export type ImageDetailContext = {
- data: ImageDocumentData;
-};
+export type ImageDetailContext = FileDetailContext<ImageDocumentData>;
export function ImageDetailDocument(
props: FileDetailShareProps & {
@@ -21,6 +23,15 @@ export function ImageDetailDocument(
children?: (context: ImageDetailContext) => JSX.Element;
}
) {
+ const operations = [
+ downloadFileOperation(() => {
+ downloadFile(
+ props.data.file,
+ documentDownloadName(props.data.documentMetadata)
+ );
+ }),
+ ];
+
return (
<FileDetailLayout
documentId={props.documentId}
@@ -30,7 +41,12 @@ export function ImageDetailDocument(
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {props.children?.({ data: props.data })}
+ {props.children?.({
+ data: props.data,
+ documentMetadata: props.data.documentMetadata,
+ userAccessLevel: props.data.userAccessLevel,
+ operations,
+ })}
<ImageContent
file={props.data.file}
alt={props.data.documentMetadata.documentName || 'Image'}
diff --git a/apps/web/src/features/drive-view/views/MarkdownDetail.tsx b/apps/web/src/features/drive-view/views/MarkdownDetail.tsx
index ecb7fa7118..950c1ccbc8 100644
--- a/apps/web/src/features/drive-view/views/MarkdownDetail.tsx
+++ b/apps/web/src/features/drive-view/views/MarkdownDetail.tsx
@@ -28,10 +28,9 @@ import {
Suspense,
Switch,
} from 'solid-js';
+import type { FileDetailContext } from '../util/file-detail-context';
-export type MarkdownDetailContext = {
- data: MarkdownDocumentData;
-};
+export type MarkdownDetailContext = FileDetailContext<MarkdownDocumentData>;
export type MarkdownDetailProps = {
documentId: string;
@@ -102,7 +101,11 @@ function MarkdownDetailContent(props: {
onShareOpenChange={props.onShareOpenChange}
>
<OldOverlay />
- {props.children?.({ data: props.data })}
+ {props.children?.({
+ data: props.data,
+ documentMetadata: props.data.metadata,
+ userAccessLevel: props.data.userAccessLevel,
+ })}
<SidePanel.Layout headerToggle={false}>
<Show when={ENABLE_MARKDOWN_SIDE_PANEL}>
<MarkdownSidePanelSections />
diff --git a/apps/web/src/features/drive-view/views/PdfDetail.tsx b/apps/web/src/features/drive-view/views/PdfDetail.tsx
index 62b48630bc..2ca88da1be 100644
--- a/apps/web/src/features/drive-view/views/PdfDetail.tsx
+++ b/apps/web/src/features/drive-view/views/PdfDetail.tsx
@@ -12,11 +12,23 @@ import {
type LocationSearchParams,
URL_PARAMS,
} from '@block-pdf/signal/location';
+import { useHasModificationData } from '@block-pdf/signal/save';
+import { useHasComments } from '@block-pdf/store/comments/commentStore';
+import {
+ downloadDocxDocument,
+ downloadPdfDocument,
+ printPdfDocument,
+} from '@block-pdf/util/pdf-file-actions';
+import type { FileOperation } from '@components/app/split-layout/components/SplitFileMenu';
+import { useIsAuthenticated } from '@core/auth';
import {
getPermissions,
hasPermissions,
Permissions,
} from '@core/component/SharePermissions';
+import { openLoginModal } from '@core/component/TopBar/LoginButton';
+import DownloadIcon from '@phosphor/download-simple.svg';
+import Printer from '@phosphor/printer.svg';
import { useSearchParams } from '@solidjs/router';
import type { JSX } from 'solid-js';
import { Show } from 'solid-js';
@@ -26,16 +38,76 @@ import {
type FileDetailShareProps,
} from '../components/FileDetail';
import { loadPdfDocument, type PdfDocumentData } from '../queries/pdf-document';
+import type { FileDetailContext } from '../util/file-detail-context';
-export type PdfDetailContext = {
- data: PdfDocumentData;
-};
+export type PdfDetailContext = FileDetailContext<PdfDocumentData>;
-function PdfDetailContent() {
+function PdfDetailContent(props: {
+ data: PdfDocumentData;
+ children?: (context: PdfDetailContext) => JSX.Element;
+}) {
+ const isAuth = useIsAuthenticated();
const pdf = usePdfDocument();
+ const hasModificationData = useHasModificationData();
+ const hasComments = useHasComments();
+ const fileName =
+ props.data.documentMetadata.documentName ?? 'Unknown Filename';
+ const auth = () => ({
+ isAuthenticated: !!isAuth(),
+ openLogin: openLoginModal,
+ });
+ const operations: FileOperation[] = [
+ {
+ label: 'Print',
+ icon: Printer,
+ action: () => {
+ void printPdfDocument({
+ ...auth(),
+ documentProxy: pdf.documentProxy(),
+ });
+ },
+ },
+ {
+ group: 'file',
+ label: 'Download',
+ icon: DownloadIcon,
+ action: () => {
+ void downloadPdfDocument({
+ ...auth(),
+ documentProxy: pdf.documentProxy(),
+ hasModifications: hasModificationData(),
+ hasComments: hasComments(),
+ documentId: pdf.documentId(),
+ fileName,
+ });
+ },
+ },
+ ...(props.data.documentMetadata.fileType === 'docx'
+ ? [
+ {
+ group: 'file' as const,
+ label: 'Download DOCX',
+ icon: DownloadIcon,
+ action: () => {
+ void downloadDocxDocument({
+ ...auth(),
+ documentId: pdf.documentId(),
+ fileName,
+ });
+ },
+ },
+ ]
+ : []),
+ ];
return (
<>
+ {props.children?.({
+ data: props.data,
+ documentMetadata: props.data.documentMetadata,
+ userAccessLevel: props.data.userAccessLevel,
+ operations,
+ })}
<Show when={pdf.documentProxy()}>
<div class="flex min-h-11 shrink-0 items-center gap-2 border-edge-muted border-b px-2">
<PdfToolbarControls />
@@ -77,7 +149,6 @@ export function PdfDetailDocument(
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {props.children?.({ data: props.data })}
<PdfDocument
documentId={props.documentId}
documentVersionId={props.data.documentMetadata.documentVersionId}
@@ -95,7 +166,7 @@ export function PdfDetailDocument(
}}
locationParams={getLocationParams(searchParams)}
>
- <PdfDetailContent />
+ <PdfDetailContent data={props.data} children={props.children} />
</PdfDocument>
</FileDetailLayout>
);
diff --git a/apps/web/src/features/drive-view/views/UnknownDetail.tsx b/apps/web/src/features/drive-view/views/UnknownDetail.tsx
index 889088935f..79e85448da 100644
--- a/apps/web/src/features/drive-view/views/UnknownDetail.tsx
+++ b/apps/web/src/features/drive-view/views/UnknownDetail.tsx
@@ -1,22 +1,22 @@
import { UnknownContent } from '@block-unknown/component/UnknownContent';
import { toast } from '@core/component/Toast/Toast';
import { downloadFile } from '@filesystem/download';
-import { formatDocumentName } from '@service-storage/util/filename';
import { createSignal, type JSX } from 'solid-js';
import {
FileDetailLayout,
FileDetailLoadGate,
type FileDetailShareProps,
} from '../components/FileDetail';
+import { downloadFileOperation } from '../components/file-detail-operations';
import { getFileDocumentBlob } from '../queries/file-document';
import {
loadUnknownDocument,
type UnknownDocumentData,
} from '../queries/unknown-document';
+import { documentDownloadName } from '../util/document-download-name';
+import type { FileDetailContext } from '../util/file-detail-context';
-export type UnknownDetailContext = {
- data: UnknownDocumentData;
-};
+export type UnknownDetailContext = FileDetailContext<UnknownDocumentData>;
export function UnknownDetailDocument(
props: FileDetailShareProps & {
@@ -31,12 +31,7 @@ export function UnknownDetailDocument(
props.onShareOpenChange?.(open);
if (props.shareOpen === undefined) setLocalShareOpen(open);
};
- const downloadName = () =>
- formatDocumentName(
- props.data.documentMetadata.documentName || 'download',
- props.data.documentMetadata.fileType,
- { caseInsensitiveSuffix: true }
- );
+ const downloadName = () => documentDownloadName(props.data.documentMetadata);
const downloadDocument = async () => {
try {
@@ -50,6 +45,7 @@ export function UnknownDetailDocument(
toast.failure('Error downloading file');
}
};
+ const operations = [downloadFileOperation(() => void downloadDocument())];
return (
<FileDetailLayout
@@ -61,7 +57,12 @@ export function UnknownDetailDocument(
shareOpen={shareOpen()}
onShareOpenChange={setShareOpen}
>
- {props.children?.({ data: props.data })}
+ {props.children?.({
+ data: props.data,
+ documentMetadata: props.data.documentMetadata,
+ userAccessLevel: props.data.userAccessLevel,
+ operations,
+ })}
<UnknownContent
fileName={props.data.documentMetadata.documentName}
onShare={() => setShareOpen(true)}
diff --git a/apps/web/src/features/drive-view/views/VideoDetail.tsx b/apps/web/src/features/drive-view/views/VideoDetail.tsx
index 134240a162..34f8b547ee 100644
--- a/apps/web/src/features/drive-view/views/VideoDetail.tsx
+++ b/apps/web/src/features/drive-view/views/VideoDetail.tsx
@@ -5,14 +5,17 @@ import {
FileDetailLoadGate,
type FileDetailShareProps,
} from '../components/FileDetail';
+import { downloadFileOperation } from '../components/file-detail-operations';
+import { getFileDocumentBlob } from '../queries/file-document';
import {
loadVideoDocument,
type VideoDocumentData,
} from '../queries/video-document';
+import { documentDownloadName } from '../util/document-download-name';
+import { downloadWithProgress } from '../util/download-with-progress';
+import type { FileDetailContext } from '../util/file-detail-context';
-export type VideoDetailContext = {
- data: VideoDocumentData;
-};
+export type VideoDetailContext = FileDetailContext<VideoDocumentData>;
export function VideoDetailDocument(
props: FileDetailShareProps & {
@@ -21,6 +24,21 @@ export function VideoDetailDocument(
children?: (context: VideoDetailContext) => JSX.Element;
}
) {
+ const operations = [
+ downloadFileOperation(() => {
+ const fileName = documentDownloadName(props.data.documentMetadata);
+ void downloadWithProgress(fileName, (onProgress) =>
+ getFileDocumentBlob(
+ {
+ documentId: props.documentId,
+ documentVersionId: props.data.documentMetadata.documentVersionId,
+ },
+ { onProgress }
+ )
+ );
+ }),
+ ];
+
return (
<FileDetailLayout
documentId={props.documentId}
@@ -31,7 +49,12 @@ export function VideoDetailDocument(
shareOpen={props.shareOpen}
onShareOpenChange={props.onShareOpenChange}
>
- {props.children?.({ data: props.data })}
+ {props.children?.({
+ data: props.data,
+ documentMetadata: props.data.documentMetadata,
+ userAccessLevel: props.data.userAccessLevel,
+ operations,
+ })}
<VideoContent
videoUrl={props.data.videoUrl}
fileType={props.data.documentMetadata.fileType}
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 8238599efa..14b0aa57b2 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -537,7 +537,12 @@ Recent uses the viewer's own interaction order and does not offer a sort overrid
The New menu and drag/drop uploads target the selected folder. File rows retain
selection and context menus; ordinary folder clicks and Enter browse inside Drive,
while Markdown, code/CSV, image, video, PDF/DOCX, canvas, and unrecognized file
-clicks and Enter replace the list with a breadcrumbed detail. Choose the current location
+clicks and Enter replace the list with a breadcrumbed detail. Those detail
+menus include Duplicate, Rename, Move to folder, and Delete. Code, CSV, image,
+video, canvas, PDF, DOCX, and unrecognized files also include Download. PDF
+details include Print, and DOCX files include Download DOCX. Markdown details
+use the document menu, which already includes Download. Spreadsheets keep the
+editor's Import and export menu for Excel and CSV downloads. Choose the current location
breadcrumb to return to the list; choosing an ancestor file drops newer detail
entries. Opening a list row or sidebar favorite starts a new detail path; only
navigation originating inside a detail appends to that path. Cmd/Ctrl-clicking a