Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

file details action buttons improvements (#8002)

EthanHealy017958d1ea2a9e
diff --git a/frontend/editor/src/core/components/filesPage/FileDetailsActions.tsx b/frontend/editor/src/core/components/filesPage/FileDetailsActions.tsx
new file mode 100644
index 0000000000..a46fc71d3a
--- /dev/null
+++ b/frontend/editor/src/core/components/filesPage/FileDetailsActions.tsx
@@ -0,0 +1,155 @@
+import { Menu, Tooltip } from "@mantine/core";
+import { useTranslation } from "react-i18next";
+import { Button } from "@app/ui/Button";
+import { ActionIcon } from "@app/ui/ActionIcon";
+import { Icon } from "@app/ui/Icon";
+import { FileId } from "@app/types/file";
+import { StirlingFileStub } from "@app/types/fileContext";
+
+export interface FileDetailsActionsProps {
+ selectedFileIds: FileId[];
+ /** The only selected file, or null for a multi-selection. */
+ single: StirlingFileStub | null;
+ fileCount: number;
+ /** Selected files with no server copy yet; empty hides Save to server. */
+ localOnlyFiles: StirlingFileStub[];
+ sharingEnabled: boolean;
+ downloading: boolean;
+ onDownload: () => void;
+ onAddToWorkspace: (fileIds: FileId[]) => void;
+ onMove: (fileIds: FileId[]) => void;
+ onRemove: (fileIds: FileId[]) => void;
+ onSaveToServer?: (files: StirlingFileStub[]) => void;
+ /** When set, Save to server renders disabled with this tooltip (storage off). */
+ saveToServerDisabledReason?: string | null;
+ onShare: () => void;
+}
+
+const ICON_SIZE = 20;
+const MENU_ICON_SIZE = "1.1rem";
+
+/**
+ * The details panel's action row: one primary CTA, download, and everything
+ * else behind an overflow menu.
+ */
+export function FileDetailsActions({
+ selectedFileIds,
+ single,
+ fileCount,
+ localOnlyFiles,
+ sharingEnabled,
+ downloading,
+ onDownload,
+ onAddToWorkspace,
+ onMove,
+ onRemove,
+ onSaveToServer,
+ saveToServerDisabledReason,
+ onShare,
+}: FileDetailsActionsProps) {
+ const { t } = useTranslation();
+
+ const addLabel =
+ fileCount === 1
+ ? t("filesPage.addToWorkspace", "Add to workspace")
+ : t("filesPage.addToWorkspaceCount", "Add {{count}} to workspace", {
+ count: fileCount,
+ });
+ const downloadLabel = single
+ ? t("filesPage.download", "Download")
+ : t("filesPage.downloadAll", "Download all");
+ const showSaveToServer = Boolean(onSaveToServer) && localOnlyFiles.length > 0;
+ const saveToServerDisabled = Boolean(saveToServerDisabledReason);
+
+ return (
+ <div className="files-page-details-actions">
+ <div className="files-page-details-actions-row">
+ <Button
+ style={{ flex: 1 }}
+ leftSection={<Icon name="external-link" size={ICON_SIZE} />}
+ onClick={() => onAddToWorkspace(selectedFileIds)}
+ >
+ {addLabel}
+ </Button>
+ <Tooltip label={downloadLabel} withinPortal>
+ <ActionIcon
+ variant="secondary"
+ loading={downloading}
+ onClick={onDownload}
+ aria-label={downloadLabel}
+ >
+ <Icon name="download" size={ICON_SIZE} />
+ </ActionIcon>
+ </Tooltip>
+ <Menu shadow="md" width={230} position="top-end" withinPortal>
+ <Menu.Target>
+ <ActionIcon
+ variant="secondary"
+ aria-label={t("filesPage.bulkActions", "Actions")}
+ >
+ <Icon name="ellipsis-vertical" size={ICON_SIZE} />
+ </ActionIcon>
+ </Menu.Target>
+ <Menu.Dropdown>
+ {/* Share is single-file only. When sharing is disabled in server
+ config (storage.sharing.enabled=false) the item stays listed but
+ disabled, so the feature is discoverable rather than absent. */}
+ {single && (
+ <Tooltip
+ label={t(
+ "filesPage.shareDisabledHint",
+ "File sharing isn't enabled on this server. Ask your admin to enable it.",
+ )}
+ disabled={sharingEnabled}
+ withinPortal
+ multiline
+ w={260}
+ >
+ <Menu.Item
+ leftSection={<Icon name="link" size={MENU_ICON_SIZE} />}
+ disabled={!sharingEnabled}
+ onClick={onShare}
+ >
+ {t("filesPage.shareManage", "Manage sharing")}
+ </Menu.Item>
+ </Tooltip>
+ )}
+ <Menu.Item
+ leftSection={<Icon name="folder-input" size={MENU_ICON_SIZE} />}
+ onClick={() => onMove(selectedFileIds)}
+ >
+ {t("filesPage.moveTo", "Move to…")}
+ </Menu.Item>
+ {showSaveToServer && (
+ <Tooltip
+ label={saveToServerDisabledReason}
+ disabled={!saveToServerDisabled}
+ withinPortal
+ multiline
+ w={260}
+ >
+ <Menu.Item
+ leftSection={
+ <Icon name="cloud-upload" size={MENU_ICON_SIZE} />
+ }
+ disabled={saveToServerDisabled}
+ onClick={() => onSaveToServer?.(localOnlyFiles)}
+ >
+ {t("filesPage.saveToServer", "Save to server")}
+ </Menu.Item>
+ </Tooltip>
+ )}
+ <Menu.Divider />
+ <Menu.Item
+ color="red"
+ leftSection={<Icon name="trash" size={MENU_ICON_SIZE} />}
+ onClick={() => onRemove(selectedFileIds)}
+ >
+ {t("filesPage.remove", "Delete")}
+ </Menu.Item>
+ </Menu.Dropdown>
+ </Menu>
+ </div>
+ </div>
+ );
+}
diff --git a/frontend/editor/src/core/components/filesPage/FileDetailsPanel.tsx b/frontend/editor/src/core/components/filesPage/FileDetailsPanel.tsx
index 6acc8cc448..05c186265b 100644
--- a/frontend/editor/src/core/components/filesPage/FileDetailsPanel.tsx
+++ b/frontend/editor/src/core/components/filesPage/FileDetailsPanel.tsx
@@ -22,6 +22,8 @@ import {
VersionTimeline,
DetailField,
} from "@app/components/filesPage/VersionTimeline";
+import { FileDetailsActions } from "@app/components/filesPage/FileDetailsActions";
+import "@app/components/filesPage/FilesPage.css";
interface FileDetailsPanelProps {
selectedFileIds: FileId[];
@@ -393,98 +395,21 @@ export function FileDetailsPanel({
)}
</div>
- <div className="files-page-details-actions">
- <Button
- leftSection={<Icon name="external-link" size={20} />}
- onClick={() => onAddToWorkspace(selectedFileIds)}
- >
- {files.length === 1
- ? t("filesPage.addToWorkspace", "Add to workspace")
- : t("filesPage.addToWorkspaceCount", "Add {{count}} to workspace", {
- count: files.length,
- })}
- </Button>
- <Button
- leftSection={<Icon name="download" size={20} />}
- variant="secondary"
- onClick={handleDownload}
- loading={downloading}
- >
- {single
- ? t("filesPage.download", "Download")
- : t("filesPage.downloadAll", "Download all")}
- </Button>
- {/* Share is single-file only. When sharing is disabled in
- server config (storage.sharing.enabled=false) we still
- render the button - disabled with an explanatory tooltip -
- so users discover the feature exists and know how to
- enable it, rather than wondering why "share" is missing
- from the action stack on their build. */}
- {single && (
- <Tooltip
- label={t(
- "filesPage.shareDisabledHint",
- "File sharing isn't enabled on this server. Ask your admin to enable it.",
- )}
- disabled={sharingEnabled}
- withinPortal
- multiline
- w={260}
- >
- <Button
- leftSection={<Icon name="link" size={20} />}
- variant="secondary"
- disabled={!sharingEnabled}
- onClick={() => setShareModalOpen(true)}
- style={{
- // Keep tooltip hoverable while button is disabled.
- pointerEvents: sharingEnabled ? undefined : "auto",
- }}
- >
- {t("filesPage.shareManage", "Manage sharing")}
- </Button>
- </Tooltip>
- )}
- <Button
- leftSection={<Icon name="folder-input" size={20} />}
- variant="secondary"
- onClick={() => onMove(selectedFileIds)}
- >
- {t("filesPage.moveTo", "Move to…")}
- </Button>
- {/* Save to server; shown when any selected file is local-only. When
- storage is off it stays visible but disabled with a tooltip (same
- treatment as Manage sharing above). */}
- {onSaveToServer && localOnlyFiles.length > 0 && (
- <Tooltip
- label={saveToServerDisabledReason}
- disabled={!saveToServerDisabledReason}
- withinPortal
- multiline
- w={260}
- >
- <Button
- leftSection={<Icon name="cloud-upload" size={20} />}
- variant="secondary"
- disabled={Boolean(saveToServerDisabledReason)}
- onClick={() => onSaveToServer(localOnlyFiles)}
- style={{
- // Keep tooltip hoverable while button is disabled.
- pointerEvents: saveToServerDisabledReason ? "auto" : undefined,
- }}
- >
- {t("filesPage.saveToServer", "Save to server")}
- </Button>
- </Tooltip>
- )}
- <Button
- leftSection={<Icon name="trash" size={20} />}
- accent="danger"
- onClick={() => onRemove(selectedFileIds)}
- >
- {t("filesPage.remove", "Delete")}
- </Button>
- </div>
+ <FileDetailsActions
+ selectedFileIds={selectedFileIds}
+ single={single}
+ fileCount={files.length}
+ localOnlyFiles={localOnlyFiles}
+ sharingEnabled={sharingEnabled}
+ downloading={downloading}
+ onDownload={handleDownload}
+ onAddToWorkspace={onAddToWorkspace}
+ onMove={onMove}
+ onRemove={onRemove}
+ onSaveToServer={onSaveToServer}
+ saveToServerDisabledReason={saveToServerDisabledReason}
+ onShare={() => setShareModalOpen(true)}
+ />
{/* Single panel-level mount; gated on sharingEnabled. */}
{single && sharingEnabled && (
<ShareManagementModal
diff --git a/frontend/editor/src/core/components/filesPage/FilesPage.css b/frontend/editor/src/core/components/filesPage/FilesPage.css
index b5c16949d9..6bb961e6fc 100644
--- a/frontend/editor/src/core/components/filesPage/FilesPage.css
+++ b/frontend/editor/src/core/components/filesPage/FilesPage.css
@@ -1008,6 +1008,19 @@
background: var(--c-bg-raised);
}
+.files-page-details-actions-row {
+ display: flex;
+ align-items: stretch;
+ gap: 0.4rem;
+}
+
+/* The panel is narrow enough that "Add {{count}} to workspace" wraps to two
+ lines. ActionIcon is square by default, so without this the icons keep their
+ own height and the row stops sharing a baseline. */
+.files-page-details-actions-row .mantine-ActionIcon-root {
+ height: auto;
+}
+
/* Collapsible "File info" header (size/type/dates). */
.files-page-details-collapse-toggle {
display: flex;
diff --git a/frontend/editor/src/core/tests/stubbed/files-page.spec.ts b/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
index fb0128c144..33590d6e1d 100644
--- a/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
@@ -285,13 +285,17 @@ test.describe("Files page", () => {
.locator(".files-page-card:not(.is-folder)")
.filter({ hasText: "local-a.pdf" })
.click();
- // Two entry points share the name; use .first() for strict mode.
await expect(
- page.getByRole("button", { name: /^Save to server$/i }).first(),
+ page.getByRole("button", { name: /^Save to server$/i }),
).toBeVisible();
+ // The details panel's copy lives behind its overflow menu.
+ await page
+ .locator(".files-page-details-actions-row")
+ .getByRole("button", { name: /^Actions$/i })
+ .click();
await expect(
- page.getByRole("button", { name: /^Save to server$/i }),
- ).toHaveCount(2);
+ page.getByRole("menuitem", { name: /^Save to server$/i }),
+ ).toBeVisible();
});
test("Save to server hidden when ONLY cloud files selected", async ({
@@ -357,16 +361,21 @@ test.describe("Files page", () => {
.locator(".files-page-card:not(.is-folder)")
.filter({ hasText: "local-a.pdf" })
.click();
- const saveButtons = page.getByRole("button", {
+ const toolbarSave = page.getByRole("button", {
name: /^Save to server$/i,
});
- // Present (toolbar + details panel) and every instance disabled.
- const count = await saveButtons.count();
- expect(count).toBeGreaterThan(0);
- for (let i = 0; i < count; i += 1) {
- await expect(saveButtons.nth(i)).toBeVisible();
- await expect(saveButtons.nth(i)).toBeDisabled();
- }
+ await expect(toolbarSave).toBeVisible();
+ await expect(toolbarSave).toBeDisabled();
+
+ await page
+ .locator(".files-page-details-actions-row")
+ .getByRole("button", { name: /^Actions$/i })
+ .click();
+ const panelSave = page.getByRole("menuitem", {
+ name: /^Save to server$/i,
+ });
+ await expect(panelSave).toBeVisible();
+ await expect(panelSave).toBeDisabled();
});
test("per-file kebab Save to server is disabled (not hidden) when storage off", async ({