#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Redesign the workbench add-files CTA (#8381)
EthanHealy01a10717407bec
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex a42128df23..cbad6c6a68 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -4588,7 +4588,6 @@ viewInViewer = "View in Viewer"closeFile = "Close file"[fileEditor]-addFiles = "Add Files"closedFile = "Closed {{name}}"couldNotSave = "Could not save {{name}}"filesAdded_one = "Added {{count}} file"@@ -4605,6 +4604,11 @@ saveFailed = "Save failed"unpinnedFile = "Unpinned {{name}}"unzipping = "Unzipping {{name}}"+[fileEditor.addCard]+dropHint = "or drop files anywhere"+fromComputer = "Upload from computer"+moreOptions = "More upload options"+[fileEditor.unzip]error = "Error unzipping {{name}}"extracted_one = "Extracted {{count}} file from {{name}}"diff --git a/frontend/editor/src/core/components/fileEditor/AddFileCard.module.css b/frontend/editor/src/core/components/fileEditor/AddFileCard.module.cssnew file mode 100644index 0000000000..8372dfc80d--- /dev/null+++ b/frontend/editor/src/core/components/fileEditor/AddFileCard.module.css@@ -0,0 +1,83 @@+/* Same footprint as FileEditorThumbnail: a 260px card whose page starts 36px+ down (10px padding + the 26px toolchain bar), so the two line up. */+.cell {+ width: 260px;+ max-width: 100%;+ margin: 0 auto;+ padding: 36px 10px 12px;+ display: flex;+ flex-direction: column;+ align-items: center;+ user-select: none;+}++/* Fixed rather than an aspect-ratio: each thumbnail derives its own aspect from+ its PDF, so there is no single page shape to copy. */+.card {+ position: relative;+ width: 240px;+ max-width: 100%;+ height: 284px;+ /* The extra bottom padding lifts the group a touch: centred exactly, the+ solid buttons make it read as sitting low. */+ padding: 0 20px 12px;+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ gap: 24px;+ border-radius: 12px;+ border: 1px solid var(--c-border-subtle);+ background: var(--c-surface);+ box-shadow: var(--shadow-md);+ transition:+ border-color 0.15s ease,+ background 0.15s ease;+ /* Secondary buttons fill with this; matching the card makes them read as+ outlines in both themes, where light mode's raised white would not. */+ --c-btn-secondary: var(--c-surface);+}++/* The surrounding Dropzone sets data-accept while files are dragged over it. */+:global([data-accept]) .card {+ border-color: var(--c-primary);+ background: var(--c-primary-subtle);+}++.more {+ position: absolute;+ top: 8px;+ right: 8px;+}++.controls {+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: 14px;+ width: 100%;+}++.actions {+ display: flex;+ flex-direction: column;+ gap: 8px;+ width: 100%;+}++.buttonWrap {+ display: flex;+ flex-direction: column;+}++.hint {+ font-size: 12px;+ color: var(--c-text-subtle);+ text-align: center;+}++@media (prefers-reduced-motion: reduce) {+ .card {+ transition: none;+ }+}diff --git a/frontend/editor/src/core/components/fileEditor/AddFileCard.test.tsx b/frontend/editor/src/core/components/fileEditor/AddFileCard.test.tsxnew file mode 100644index 0000000000..1100dc8804--- /dev/null+++ b/frontend/editor/src/core/components/fileEditor/AddFileCard.test.tsx@@ -0,0 +1,146 @@+import { beforeEach, describe, expect, test, vi } from "vitest";+import { render, screen, waitFor } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { MantineProvider } from "@mantine/core";+import AddFileCard from "@app/components/fileEditor/AddFileCard";++const mocks = vi.hoisted(() => ({+ openFilesModal: vi.fn(),+ openFilesFromDisk: vi.fn(),+ openFolderCreation: vi.fn(),+ config: { enableMobileScanner: true } as { enableMobileScanner: boolean },+ signedIn: true,+ canCreateFolders: true,+}));++vi.mock("react-i18next", () => ({+ initReactI18next: { type: "3rdParty", init: vi.fn() },+ useTranslation: () => ({+ t: (key: string, fallback?: string) => fallback ?? key,+ }),+}));+vi.mock("@app/contexts/FilesModalContext", () => ({+ useFilesModalContext: () => ({ openFilesModal: mocks.openFilesModal }),+}));+vi.mock("@app/contexts/AppConfigContext", () => ({+ useAppConfig: () => ({ config: mocks.config }),+}));+vi.mock("@app/hooks/useIsMobile", () => ({ useIsPhone: () => false }));+vi.mock("@app/hooks/useProcessingFolderCreation", () => ({+ useProcessingFolderCreation: () => ({+ open: mocks.canCreateFolders ? mocks.openFolderCreation : undefined,+ dialog: null,+ }),+}));+vi.mock("@app/components/policies/usePoliciesEnabled", () => ({+ usePoliciesEnabled: () => mocks.signedIn,+}));+vi.mock("@app/services/openFilesFromDisk", () => ({+ openFilesFromDisk: mocks.openFilesFromDisk,+}));+vi.mock("@app/components/shared/MobileUploadModal", () => ({+ default: ({ opened }: { opened: boolean }) =>+ opened ? <div>mobile upload modal</div> : null,+}));+vi.mock("@app/ui/Logo", () => ({ Logo: () => null }));++function renderCard(onFilesSelected = vi.fn()) {+ render(+ // Test env drops Mantine's transitions and portals, so the menu opens+ // synchronously instead of racing the timeout under a loaded CI run.+ <MantineProvider env="test">+ <AddFileCard onFilesSelected={onFilesSelected} />+ </MantineProvider>,+ );+ return onFilesSelected;+}++async function openMoreOptions() {+ await userEvent.click(+ screen.getByRole("button", { name: "More upload options" }),+ );+}++describe("AddFileCard", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ mocks.config = { enableMobileScanner: true };+ mocks.signedIn = true;+ mocks.canCreateFolders = true;+ });++ test("Add Files opens the file library", async () => {+ renderCard();+ await userEvent.click(screen.getByRole("button", { name: "Add Files" }));+ expect(mocks.openFilesModal).toHaveBeenCalledTimes(1);+ expect(mocks.openFilesFromDisk).not.toHaveBeenCalled();+ });++ test("the computer upload hands picked files to the workbench", async () => {+ const picked = [new File(["%PDF"], "a.pdf")];+ mocks.openFilesFromDisk.mockResolvedValue(picked);+ const onFilesSelected = renderCard();++ await openMoreOptions();+ await userEvent.click(+ await screen.findByRole("menuitem", { name: "Upload from computer" }),+ );++ await waitFor(() => expect(onFilesSelected).toHaveBeenCalledWith(picked));+ expect(mocks.openFilesModal).not.toHaveBeenCalled();+ });++ test("the menu trigger carries the menu's state", async () => {+ renderCard();+ await openMoreOptions();+ expect(+ screen+ .getByRole("button", { name: "More upload options" })+ .getAttribute("aria-expanded"),+ ).toBe("true");+ });++ test("the mobile upload opens the mobile upload modal", async () => {+ renderCard();+ await openMoreOptions();+ await userEvent.click(+ await screen.findByRole("menuitem", { name: "Upload from Mobile" }),+ );+ expect(screen.getByText("mobile upload modal")).toBeTruthy();+ });++ test("leaves mobile upload out of the menu when the scanner is off", async () => {+ mocks.config = { enableMobileScanner: false };+ renderCard();+ await openMoreOptions();+ await screen.findByRole("menuitem", { name: "Upload from computer" });+ expect(+ screen.queryByRole("menuitem", { name: "Upload from Mobile" }),+ ).toBeNull();+ });++ test("hides Process a folder in builds without processing", () => {+ mocks.canCreateFolders = false;+ renderCard();+ expect(+ screen.queryByRole("button", { name: "processingFolders.setup.title" }),+ ).toBeNull();+ });++ test("disables Process a folder when signed out", () => {+ mocks.signedIn = false;+ renderCard();+ const folder = screen.getByRole("button", {+ name: "processingFolders.setup.title",+ }) as HTMLButtonElement;+ expect(folder.disabled).toBe(true);+ });++ test("Process a folder opens the folder setup", async () => {+ renderCard();+ await userEvent.click(+ screen.getByRole("button", { name: "processingFolders.setup.title" }),+ );+ expect(mocks.openFolderCreation).toHaveBeenCalledTimes(1);+ });+});diff --git a/frontend/editor/src/core/components/fileEditor/AddFileCard.tsx b/frontend/editor/src/core/components/fileEditor/AddFileCard.tsxindex 696b47cd02..b647077f4f 100644--- a/frontend/editor/src/core/components/fileEditor/AddFileCard.tsx+++ b/frontend/editor/src/core/components/fileEditor/AddFileCard.tsx@@ -1,81 +1,155 @@-import React from "react";-import { Group } from "@mantine/core";-import { Button } from "@app/ui/Button";+import React, { useRef, useState } from "react";+import { Menu, Tooltip } from "@mantine/core";import { useTranslation } from "react-i18next";import { useFilesModalContext } from "@app/contexts/FilesModalContext";-import { Wordmark } from "@app/components/shared/Wordmark";-import styles from "@app/components/fileEditor/FileEditor.module.css";+import { useAppConfig } from "@app/contexts/AppConfigContext";import { useFileActionTerminology } from "@app/hooks/useFileActionTerminology";+import { useIsPhone } from "@app/hooks/useIsMobile";+import { useProcessingFolderCreation } from "@app/hooks/useProcessingFolderCreation";+import { usePoliciesEnabled } from "@app/components/policies/usePoliciesEnabled";+import MobileUploadModal from "@app/components/shared/MobileUploadModal";+import { openFilesFromDisk } from "@app/services/openFilesFromDisk";+import { ActionIcon } from "@app/ui/ActionIcon";+import { Button } from "@app/ui/Button";import { Icon } from "@app/ui/Icon";+import { Logo } from "@app/ui/Logo";+import styles from "@app/components/fileEditor/AddFileCard.module.css";-const AddFileCard = () => {+interface AddFileCardProps {+ /** Receives files from the computer and mobile sources; the library adds its own. */+ onFilesSelected: (files: File[]) => void;+}++/**+ * The workbench's standing "add files" slot in the thumbnail grid. Add Files+ * opens the file library; the overflow menu holds the direct computer and+ * mobile uploads. Drops are handled by the surrounding workbench Dropzone,+ * whose drag state this card reflects.+ */+const AddFileCard = ({ onFilesSelected }: AddFileCardProps) => {const { t } = useTranslation();- const { openFilesModal } = useFilesModalContext();const terminology = useFileActionTerminology();+ const { openFilesModal } = useFilesModalContext();+ const { config } = useAppConfig();+ const isPhone = useIsPhone();+ const folderCreation = useProcessingFolderCreation();+ const signedIn = usePoliciesEnabled();+ const fileInputRef = useRef<HTMLInputElement | null>(null);+ const [mobileUploadOpen, setMobileUploadOpen] = useState(false);+ const moreOptionsLabel = t(+ "fileEditor.addCard.moreOptions",+ "More upload options",+ );- const handleCardClick = () => {- openFilesModal();+ const openComputerFiles = async () => {+ const files = await openFilesFromDisk({+ multiple: true,+ onFallbackOpen: () => fileInputRef.current?.click(),+ });+ if (files.length > 0) onFilesSelected(files);};- const handleOpenFilesModal = (e: React.MouseEvent) => {- e.stopPropagation();- openFilesModal();+ const handleFallbackSelect = (event: React.ChangeEvent<HTMLInputElement>) => {+ const files = Array.from(event.target.files ?? []);+ if (files.length > 0) onFilesSelected(files);+ event.target.value = "";};return (- <div- className={`${styles.addFileCard} select-none flex flex-col transition-all relative cursor-pointer`}- tabIndex={0}- role="button"- aria-label={t("fileEditor.addFiles", "Add files")}- onClick={handleCardClick}- onKeyDown={(e) => {- if (e.key === "Enter" || e.key === " ") {- e.preventDefault();- handleCardClick();- }- }}- >- <div className={styles.addFileContent}>- <Group gap="xs" align="center">- <Wordmark- alt="Stirling PDF"- muted- style={{ height: "2.2rem", width: "auto" }}- />- </Group>+ <div className={styles.cell}>+ <div className={styles.card} data-testid="add-file-card">+ <div className={styles.more}>+ <Menu position="bottom-end" withinPortal>+ {/* Tooltip outside the target: inside it, Mantine forwards the+ menu's aria-expanded/haspopup onto the tooltip element. */}+ <Tooltip label={moreOptionsLabel} withArrow>+ <Menu.Target>+ <ActionIcon+ variant="tertiary"+ accent="neutral"+ size="sm"+ aria-label={moreOptionsLabel}+ >+ <Icon name="ellipsis" size="1.1rem" />+ </ActionIcon>+ </Menu.Target>+ </Tooltip>+ <Menu.Dropdown>+ <Menu.Item+ leftSection={<Icon name="upload" size="1rem" />}+ onClick={() => void openComputerFiles()}+ >+ {t("fileEditor.addCard.fromComputer", "Upload from computer")}+ </Menu.Item>+ {config?.enableMobileScanner && !isPhone && (+ <Menu.Item+ leftSection={<Icon name="qr-code" size="1rem" />}+ onClick={() => setMobileUploadOpen(true)}+ >+ {terminology.mobileUpload}+ </Menu.Item>+ )}+ </Menu.Dropdown>+ </Menu>+ </div>- <Button- variant="tertiary"- style={{- backgroundColor: "var(--landing-button-bg)",- color: "var(--c-accent-fg)",- border: "1px solid var(--landing-button-border)",- borderRadius: "2rem",- height: "38px",- paddingLeft: "1rem",- paddingRight: "1rem",- width: "100%",- marginTop: "0.8rem",- marginBottom: "0.8rem",- }}- onClick={handleOpenFilesModal}- >- <Icon name="plus" size="1.5rem" className="text-[var(--c-primary)]" />- <span>{terminology.addFiles}</span>- </Button>+ <Logo variant="iconOnly" iconHeight="2.75rem" />- <span- style={{- fontSize: ".8rem",- textAlign: "center",- marginTop: "0.5rem",- color: "var(--c-text-muted)",- }}- >- {terminology.dropFilesHere}- </span>+ <div className={styles.controls}>+ <div className={styles.actions}>+ <Button+ fat+ fullWidth+ leftSection={<Icon name="plus" size="1rem" />}+ onClick={() => openFilesModal()}+ >+ {terminology.addFiles}+ </Button>+ {folderCreation.open && (+ <Tooltip+ label={t(+ "processingFolders.setup.signInRequired",+ "Sign in to set up folder processing",+ )}+ disabled={signedIn}+ withArrow+ >+ {/* Wrapper keeps the tooltip on hover while the button is+ disabled, since a disabled button takes no pointer events. */}+ <span className={styles.buttonWrap}>+ <Button+ fat+ fullWidth+ variant="secondary"+ disabled={!signedIn}+ leftSection={<Icon name="folder-plus" size="1rem" />}+ onClick={() => folderCreation.open?.()}+ >+ {t("processingFolders.setup.title")}+ </Button>+ </span>+ </Tooltip>+ )}+ </div>+ <div className={styles.hint}>+ {t("fileEditor.addCard.dropHint", "or drop files anywhere")}+ </div>+ </div></div>++ <input+ ref={fileInputRef}+ type="file"+ multiple+ onChange={handleFallbackSelect}+ style={{ display: "none" }}+ />+ <MobileUploadModal+ opened={mobileUploadOpen}+ onClose={() => setMobileUploadOpen(false)}+ onFilesReceived={onFilesSelected}+ />+ {folderCreation.dialog}</div>);};diff --git a/frontend/editor/src/core/components/fileEditor/FileEditor.module.css b/frontend/editor/src/core/components/fileEditor/FileEditor.module.cssindex 410ade863b..6e4b149a91 100644--- a/frontend/editor/src/core/components/fileEditor/FileEditor.module.css+++ b/frontend/editor/src/core/components/fileEditor/FileEditor.module.css@@ -319,80 +319,3 @@:global([data-mantine-color-scheme="dark"]) .meta {color: var(--c-text-muted); /* subtitle text */}--/* =========================- Add File Card Styles- ========================= */--.addFileCard {- /* Fill the same slot a portrait page thumbnail does. Height: the 310px- .thumbWrap minus the always-reserved 26px toolchain bar (22px + 4px) that- sits above the page. Width: the file card's 260px minus its 10px side- padding. Offset 36px down (that padding-top + the bar) so the two line up.- A fixed size rather than an aspect-ratio, because each thumbnail derives- --thumb-aspect from its own PDF's page dimensions. */- height: calc(310px - 26px);- width: calc(260px - 20px);- max-width: 100%;- margin: 36px auto auto;- background: var(--c-surface);- border: 1px solid var(--c-border-subtle);- border-radius: 0.625rem;- box-shadow: var(--shadow-md);- cursor: pointer;- transition:- box-shadow 0.18s ease,- transform 0.2s ease,- border-color 0.18s ease;- overflow: hidden;-}--.addFileCard:hover {- box-shadow: var(--shadow-lg);- transform: translateY(-1px);- border-color: var(--c-primary);-}--.addFileCard:focus-visible {- outline: 2px solid var(--c-primary);- outline-offset: 2px;-}--.addFileContent {- flex: 1;- display: flex;- flex-direction: column;- align-items: center;- justify-content: center;- padding: 1.5rem 1rem;- gap: 0.5rem;-}--.addFileIcon {- display: flex;- align-items: center;- justify-content: center;- width: 5rem;- height: 5rem;- border-radius: 50%;- background: var(--bg-subtle);- transition: background-color 0.18s ease;-}--.addFileCard:hover .addFileIcon {- background: var(--color-blue-50);-}--.addFileText {- font-weight: 500;- transition: color 0.18s ease;-}--.addFileCard:hover .addFileText {- color: var(--c-text);-}--.addFileSubtext {- font-size: 0.875rem;- opacity: 0.8;-}diff --git a/frontend/editor/src/core/components/fileEditor/FileEditor.tsx b/frontend/editor/src/core/components/fileEditor/FileEditor.tsxindex 25d2141bd3..a7bd00607f 100644--- a/frontend/editor/src/core/components/fileEditor/FileEditor.tsx+++ b/frontend/editor/src/core/components/fileEditor/FileEditor.tsx@@ -390,7 +390,9 @@ const FileEditor = ({<Box p="md">{activeStirlingFileStubs.length === 0 ? (<Center h="60vh">- <AddFileCard />+ <AddFileCard+ onFilesSelected={(files) => void handleFileUpload(files)}+ /></Center>) : (<div@@ -403,7 +405,10 @@ const FileEditor = ({}}>{activeStirlingFileStubs.length > 0 && (- <AddFileCard key="add-file-card" />+ <AddFileCard+ key="add-file-card"+ onFilesSelected={(files) => void handleFileUpload(files)}+ />)}{activeStirlingFileStubs.map((record, index) => {