Skip to content

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

Clean up PDF Library actions (#7943)

Anthony Stirlingbfb82676ef66
diff --git a/frontend/editor/src/core/components/shared/FileSidebar.css b/frontend/editor/src/core/components/shared/FileSidebar.css
index 46a847f1ff..45367adb8f 100644
--- a/frontend/editor/src/core/components/shared/FileSidebar.css
+++ b/frontend/editor/src/core/components/shared/FileSidebar.css
@@ -516,6 +516,11 @@
font-weight: 600;
letter-spacing: -0.01em;
color: var(--c-text);
+ /* A longer translation truncates rather than wrapping the row onto two lines. */
+ min-width: 0;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
}
/* Slim "Adding files… X/Y" progress row shown during a bulk drop's pre-scan,
@@ -552,12 +557,16 @@
color: var(--c-text-subtle);
}
-.file-sidebar-section-btn {
+/* Chained to the Mantine class to beat its inline `--ai-size` sizing (36px for
+ `md`): four controls that wide leave no room for the section label. */
+.file-sidebar-section-btn.mantine-ActionIcon-root {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
+ min-width: 24px;
+ min-height: 24px;
border: none;
background: transparent;
border-radius: 4px;
@@ -571,12 +580,12 @@
opacity 0.12s ease;
}
-.file-sidebar-section-btn:focus-visible {
+.file-sidebar-section-btn.mantine-ActionIcon-root:focus-visible {
outline: 2px solid var(--c-primary);
outline-offset: 1px;
}
-.file-sidebar-section-btn:hover {
+.file-sidebar-section-btn.mantine-ActionIcon-root:hover {
background-color: var(--c-hover);
color: var(--c-text);
}
@@ -591,9 +600,15 @@
pointer-events: auto;
}
+/* Whichever add control comes first takes the gap, so the pair stays together
+ at the end of the header row. */
+.file-sidebar-section-btn-drive,
.file-sidebar-section-btn-add {
margin-left: auto;
}
+.file-sidebar-section-btn-drive + .file-sidebar-section-btn-add {
+ margin-left: 0;
+}
/* ---- Sidebar content fade (for collapsed state) ---- */
/* Elements are conditionally rendered so use animation (not transition) to fade in from 0.
diff --git a/frontend/editor/src/core/components/shared/FileSidebar.tsx b/frontend/editor/src/core/components/shared/FileSidebar.tsx
index d1e9a763d2..c15428a184 100644
--- a/frontend/editor/src/core/components/shared/FileSidebar.tsx
+++ b/frontend/editor/src/core/components/shared/FileSidebar.tsx
@@ -98,6 +98,8 @@ export interface FileSidebarProps {
accountHoisted?: boolean;
/** Override the Open-from-computer handler (e.g. upload to /files folder). */
onUploadFiles?: (files: File[]) => void | Promise<void>;
+ /** Publishes the sidebar's picker so the quick navigation rail can reuse it. */
+ onRegisterOpenFromComputer?: (open: (() => void) | null) => void;
/** Override the Google Drive handler. */
onPickGoogleDriveFiles?: (files: File[]) => void | Promise<void>;
/** Action rows inserted under Open-from-computer (New folder, Refresh). A
@@ -189,6 +191,7 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
onOpenSettings,
accountHoisted = false,
onUploadFiles,
+ onRegisterOpenFromComputer,
onPickGoogleDriveFiles,
extraActions,
},
@@ -811,6 +814,12 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
[ingestFiles],
);
+ useEffect(() => {
+ if (!onRegisterOpenFromComputer) return;
+ onRegisterOpenFromComputer(() => nativeFileInputRef.current?.click());
+ return () => onRegisterOpenFromComputer(null);
+ }, [onRegisterOpenFromComputer]);
+
// Native OS file drop onto the sidebar - mirrors the workbench drop zone.
// Only react to OS file drags ("Files" type); internal element drags (e.g.
// watched-folder file moves) set their own dataTransfer keys and must pass
@@ -989,70 +998,62 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
onToggleCollapse={onToggleCollapse}
/>
- {/* Box 1 — top controls (open / my files / cloud). No title. File
- search lives in the global super search (top bar), not here. */}
- <NavSurface className="file-sidebar-controls">
- {/* Hidden native file input - kept outside the !collapsed gate so
- the "Open from computer" row below (always rendered) can fire
- it in either sidebar state without a silent no-op. */}
- <input
- ref={nativeFileInputRef}
- type="file"
- multiple
- // No `accept` filter - this picker feeds the global workspace,
- // not a specific tool, so users may legitimately upload PNGs,
- // ZIPs, etc. for the convert/merge/extract tools to handle.
- style={{ display: "none" }}
- onChange={handleNativeFilePick}
- data-testid="file-input"
- />
- {/* Open from Computer + My Files + Google Drive */}
- {/* Tooltips only fire when collapsed - when expanded the visible
- text label below already identifies each row, so a tooltip
- would just flash a duplicate. Distinct icons (UploadFile for
- "Open from computer" vs FolderOpen for "File library") so the
- collapsed rail isn't two identical folder icons either. */}
- <Tooltip
- label={t("fileSidebar.openFromComputer", "Open from computer")}
- position="right"
- withinPortal
- disabled={!collapsed}
- >
- <div
- className="file-sidebar-action-row"
- // `files-button` is the long-standing upload entry-point
- // testid: click + setInputFiles on `file-input` above. Tour
- // anchor lives here too - the tour now spotlights the native
- // picker shortcut rather than the old modal.
- data-testid="files-button"
- data-tour="files-button"
- onClick={() => {
- // "Open from computer" goes straight to the native OS file
- // picker. The full file manager (recent + drives + folders)
- // is reachable via "File library" below.
- nativeFileInputRef.current?.click();
- }}
- role="button"
- tabIndex={0}
- aria-label={t(
- "fileSidebar.openFromComputer",
- "Open from computer",
- )}
- onKeyDown={(e) => {
- if (e.key === "Enter" || e.key === " ") {
- e.preventDefault();
- nativeFileInputRef.current?.click();
- }
- }}
+ <input
+ ref={nativeFileInputRef}
+ type="file"
+ multiple
+ // No `accept` filter - this picker feeds the global workspace,
+ // not a specific tool, so users may legitimately upload PNGs,
+ // ZIPs, etc. for the convert/merge/extract tools to handle.
+ style={{ display: "none" }}
+ onChange={handleNativeFilePick}
+ data-testid="file-input"
+ />
+
+ {/* Global actions live in quick navigation while expanded. Library-only
+ actions still belong here; the collapsed rail retains all controls. */}
+ <NavSurface
+ className="file-sidebar-controls"
+ hidden={!collapsed && !extraActions?.length}
+ >
+ {collapsed && (
+ <Tooltip
+ label={t("fileSidebar.openFromComputer", "Open from computer")}
+ position="right"
+ withinPortal
+ disabled={!collapsed}
>
- <Icon name="file-up" className="file-sidebar-action-icon" />
- {!collapsed && (
- <span className="file-sidebar-action-label sidebar-content-fade">
- {t("fileSidebar.openFromComputer", "Open from computer")}
- </span>
- )}
- </div>
- </Tooltip>
+ <div
+ className="file-sidebar-action-row"
+ data-testid="files-rail-button"
+ onClick={() => {
+ // "Open from computer" goes straight to the native OS file
+ // picker. The full file manager (recent + drives + folders)
+ // is reachable via "File library" below.
+ nativeFileInputRef.current?.click();
+ }}
+ role="button"
+ tabIndex={0}
+ aria-label={t(
+ "fileSidebar.openFromComputer",
+ "Open from computer",
+ )}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" || e.key === " ") {
+ e.preventDefault();
+ nativeFileInputRef.current?.click();
+ }
+ }}
+ >
+ <Icon name="file-up" className="file-sidebar-action-icon" />
+ {!collapsed && (
+ <span className="file-sidebar-action-label sidebar-content-fade">
+ {t("fileSidebar.openFromComputer", "Open from computer")}
+ </span>
+ )}
+ </div>
+ </Tooltip>
+ )}
{extraActions?.map((action) => (
<React.Fragment key={action.label}>
@@ -1110,7 +1111,7 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
</React.Fragment>
))}
- {!shouldHideGoogleDrive && (
+ {collapsed && !shouldHideGoogleDrive && (
<Tooltip
label={
!isGoogleDriveEnabled
@@ -1164,7 +1165,7 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
)}
{/* Watched Folders entry */}
- {WATCHED_FOLDERS_ENABLED && (
+ {collapsed && WATCHED_FOLDERS_ENABLED && (
<div
className="file-sidebar-action-row"
data-testid="watchedFolders-button"
@@ -1227,9 +1228,28 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
>
<Icon name="maximize-2" size={"1rem"} />
</ActionIcon>
+ {isGoogleDriveEnabled && (
+ <ActionIcon
+ variant="quiet"
+ className="file-sidebar-section-btn file-sidebar-section-btn-drive"
+ onClick={handleGoogleDriveClick}
+ title={t(
+ "fileSidebar.googleDrive",
+ "Open from Google Drive",
+ )}
+ aria-label={t(
+ "fileSidebar.googleDrive",
+ "Open from Google Drive",
+ )}
+ data-testid="google-drive-button"
+ >
+ <Icon name="googledrive" size={16} />
+ </ActionIcon>
+ )}
<ActionIcon
variant="quiet"
className="file-sidebar-section-btn file-sidebar-section-btn-add"
+ data-testid="pdf-library-add-files"
onClick={() => nativeFileInputRef.current?.click()}
title={t("fileSidebar.addFiles", "Add files")}
aria-label={t("fileSidebar.addFiles", "Add files")}
diff --git a/frontend/editor/src/core/components/shared/quickNav/QuickNavHostBridge.tsx b/frontend/editor/src/core/components/shared/quickNav/QuickNavHostBridge.tsx
index 32e1f79198..f18e02ac52 100644
--- a/frontend/editor/src/core/components/shared/quickNav/QuickNavHostBridge.tsx
+++ b/frontend/editor/src/core/components/shared/quickNav/QuickNavHostBridge.tsx
@@ -26,6 +26,8 @@ export interface QuickNavHostBridgeProps {
onShowFileLibrary?: () => void;
/** Merged over the reasons worked out here, for what only the app can see. */
toolReasons?: QuickNavToolReasons;
+ /** Absent where there is no file workspace to open into, which drops the rail entry. */
+ onOpenFromComputer?: () => void;
}
/** Registers with the rail what only the app can see, and owns the notifications panel. */
@@ -39,6 +41,7 @@ export function QuickNavHostBridge({
onShowFileLibrary,
onGoToDefaultState,
toolReasons,
+ onOpenFromComputer,
}: QuickNavHostBridgeProps) {
useSyncQuickNavAccount();
const notificationsAvailable = useNotificationsAvailable();
@@ -72,6 +75,7 @@ export function QuickNavHostBridge({
setReaderMode: onSetReaderMode,
showFileLibrary: onShowFileLibrary,
goToDefaultState: onGoToDefaultState,
+ openFromComputer: onOpenFromComputer,
toggleNotifications: () => setNotificationsOpen((open) => !open),
onBrandFlourish: brandFlourish.trigger,
},
diff --git a/frontend/editor/src/core/components/shared/quickNav/QuickNavRailBase.tsx b/frontend/editor/src/core/components/shared/quickNav/QuickNavRailBase.tsx
index bc1cb082b9..8d06a377b2 100644
--- a/frontend/editor/src/core/components/shared/quickNav/QuickNavRailBase.tsx
+++ b/frontend/editor/src/core/components/shared/quickNav/QuickNavRailBase.tsx
@@ -24,6 +24,8 @@ export interface QuickNavEntry {
badgeTone?: "danger" | "warning";
/** Stable hook for tests and tours. */
testId?: string;
+ /** Stable guided-tour anchor when it differs from the test hook. */
+ tourId?: string;
onClick: () => void;
}
@@ -46,6 +48,7 @@ export function RailButton({
expanded,
controls,
testId,
+ tourId,
onClick,
}: Omit<QuickNavEntry, "id">) {
return (
@@ -53,6 +56,7 @@ export function RailButton({
content={disabled && reason ? `${label} — ${reason}` : label}
position="right"
arrow
+ containerStyle={{ pointerEvents: "none" }}
>
<button
type="button"
@@ -66,6 +70,7 @@ export function RailButton({
// aria-disabled, not `disabled`: stays focusable, so its tooltip is reachable.
aria-disabled={disabled || undefined}
data-testid={testId}
+ data-tour={tourId}
onClick={disabled ? undefined : onClick}
>
{icon}
diff --git a/frontend/editor/src/core/components/shared/quickNav/QuickNavRailHost.tsx b/frontend/editor/src/core/components/shared/quickNav/QuickNavRailHost.tsx
index a0038538bc..b3d8c107d6 100644
--- a/frontend/editor/src/core/components/shared/quickNav/QuickNavRailHost.tsx
+++ b/frontend/editor/src/core/components/shared/quickNav/QuickNavRailHost.tsx
@@ -134,11 +134,24 @@ export function QuickNavRailHost() {
];
const within: QuickNavEntry[] = [
+ ...(!host?.hasOpenFromComputer
+ ? []
+ : [
+ {
+ id: "openFromComputer",
+ label: t("fileSidebar.openFromComputer", "Open from computer"),
+ icon: <Icon name="file-up" size={SIZE} />,
+ testId: "files-button",
+ tourId: "files-button",
+ onClick: () => host?.actions.current?.openFromComputer?.(),
+ },
+ ]),
{
id: "files",
label: t("fileSidebar.myFiles", "File library"),
icon: <Icon name="folder" size={SIZE} />,
current: Boolean(host?.fileLibrary),
+ testId: "my-files-button",
// Through the app where possible: the library is a view, not a route. From the
// processor there is no editor to ask, so the path carries it and HomePage seeds
// the view on arrival. Unwrapped: setting the view runs the app's own
diff --git a/frontend/editor/src/core/contexts/QuickNavHostContext.tsx b/frontend/editor/src/core/contexts/QuickNavHostContext.tsx
index b37f3f9b96..a62ab3fca6 100644
--- a/frontend/editor/src/core/contexts/QuickNavHostContext.tsx
+++ b/frontend/editor/src/core/contexts/QuickNavHostContext.tsx
@@ -30,6 +30,8 @@ export interface QuickNavViewData {
notificationsOpen: boolean;
/** Translated; absent means usable. */
toolReasons: QuickNavToolReasons;
+ /** Mirrors `openFromComputer`, which lives in a ref and so cannot trigger a render. */
+ hasOpenFromComputer: boolean;
}
export interface QuickNavHostActions {
@@ -40,6 +42,7 @@ export interface QuickNavHostActions {
toggleNotifications?: () => void;
goToDefaultState?: () => void;
requestNavigation?: (go: () => void) => void;
+ openFromComputer?: () => void;
/**
* Absent unless the app says the hidden novelty features are enabled, which
* is the only gate the rail gets - see useBrandFlourish. `originRect` is the
@@ -69,6 +72,7 @@ const EMPTY_VIEW: QuickNavViewData = {
fileLibrary: false,
activeTool: null,
notificationsOpen: false,
+ hasOpenFromComputer: false,
};
function sameReasons(
@@ -101,6 +105,7 @@ export function QuickNavHostProvider({ children }: { children: ReactNode }) {
activeTool: next.activeTool ?? null,
notificationsOpen: next.notificationsOpen ?? false,
toolReasons: next.toolReasons ?? prev.toolReasons,
+ hasOpenFromComputer: next.hasOpenFromComputer ?? false,
};
const unchanged =
merged.appMounted === prev.appMounted &&
@@ -108,6 +113,7 @@ export function QuickNavHostProvider({ children }: { children: ReactNode }) {
merged.fileLibrary === prev.fileLibrary &&
merged.activeTool === prev.activeTool &&
merged.notificationsOpen === prev.notificationsOpen &&
+ merged.hasOpenFromComputer === prev.hasOpenFromComputer &&
// Compared by value: the object is rebuilt every render.
sameReasons(merged.toolReasons, prev.toolReasons);
return unchanged ? prev : merged;
@@ -169,6 +175,7 @@ export function useRegisterQuickNavView(
notificationsOpen,
toolReasons,
} = data;
+ const hasOpenFromComputer = Boolean(actions.openFromComputer);
useEffect(() => {
setViewData?.({
readerMode,
@@ -176,6 +183,7 @@ export function useRegisterQuickNavView(
activeTool,
notificationsOpen,
toolReasons,
+ hasOpenFromComputer,
});
}, [
setViewData,
@@ -184,6 +192,7 @@ export function useRegisterQuickNavView(
activeTool,
notificationsOpen,
toolReasons,
+ hasOpenFromComputer,
]);
const setActions = host?.setActions;
diff --git a/frontend/editor/src/core/pages/HomePage.tsx b/frontend/editor/src/core/pages/HomePage.tsx
index 46b92e6298..fb114c2ab8 100644
--- a/frontend/editor/src/core/pages/HomePage.tsx
+++ b/frontend/editor/src/core/pages/HomePage.tsx
@@ -321,6 +321,14 @@ export default function HomePage() {
});
}, []);
+ const openFromComputerRef = useRef<(() => void) | null>(null);
+ const registerOpenFromComputer = useCallback((open: (() => void) | null) => {
+ openFromComputerRef.current = open;
+ }, []);
+ const openFromComputer = useCallback(() => {
+ openFromComputerRef.current?.();
+ }, []);
+
const [showSwipeHint, setShowSwipeHint] = useState(
() => !readSwipeHintSeen(),
);
@@ -483,6 +491,9 @@ export default function HomePage() {
activeTool={selectedToolKey}
onShowFileLibrary={() => actions.setWorkbench("myFiles")}
toolReasons={quickNavToolReasons}
+ onOpenFromComputer={
+ navigationState.workbench === "myFiles" ? undefined : openFromComputer
+ }
/>
<FilesPageProvider>
{isMobile ? (
@@ -657,6 +668,7 @@ export default function HomePage() {
collapsed={fileSidebarCollapsed}
onToggleCollapse={handleSidebarToggle}
onOpenSettings={openSettings}
+ onRegisterOpenFromComputer={registerOpenFromComputer}
/>
</div>
<Workbench />
diff --git a/frontend/editor/src/core/tests/stubbed/pdf-library-cleanup.spec.ts b/frontend/editor/src/core/tests/stubbed/pdf-library-cleanup.spec.ts
new file mode 100644
index 0000000000..a0e1a9364f
--- /dev/null
+++ b/frontend/editor/src/core/tests/stubbed/pdf-library-cleanup.spec.ts
@@ -0,0 +1,79 @@
+import { test, expect } from "@app/tests/helpers/stub-test-base";
+import type { Page, Route } from "@playwright/test";
+import path from "path";
+
+const FIXTURES_DIR = path.join(import.meta.dirname, "../test-fixtures");
+const SAMPLE_PDF = path.join(FIXTURES_DIR, "sample.pdf");
+const sidebar = '[data-sidebar="file-sidebar"]';
+
+/** Last-registered-wins over the fixture's app-config stub. */
+async function stubGoogleDriveConfigured(page: Page): Promise<void> {
+ await page.route("**/api/v1/config/app-config", (route: Route) =>
+ route.fulfill({
+ json: {
+ enableLogin: false,
+ isAdmin: false,
+ languages: ["en-US"],
+ defaultLocale: "en-US",
+ googleDriveEnabled: true,
+ googleDriveClientId: "stub-client-id",
+ googleDriveApiKey: "stub-api-key",
+ googleDriveAppId: "stub-app-id",
+ },
+ }),
+ );
+}
+
+test.describe("PDF Library cleanup", () => {
+ test("keeps the File library action in quick navigation instead of duplicating it", async ({
+ page,
+ }) => {
+ await page.goto("/editor");
+ await expect(
+ page.locator(sidebar).getByTestId("my-files-button"),
+ ).toHaveCount(0);
+
+ await page.getByTestId("my-files-button").click();
+ await expect(page).toHaveURL(/\/files(?:$|[/?#])/);
+ });
+
+ test("opens computer files through quick navigation using the shared picker", async ({
+ page,
+ }) => {
+ await page.goto("/editor");
+
+ const chooser = page.waitForEvent("filechooser");
+ await page.getByTestId("files-button").click();
+ await (await chooser).setFiles(SAMPLE_PDF);
+
+ await expect(page.locator(".file-sidebar-file-item").first()).toBeVisible({
+ timeout: 10_000,
+ });
+ });
+
+ test("hides the Google Drive button when Drive is not configured", async ({
+ page,
+ }) => {
+ await page.goto("/editor");
+ await expect(page.getByTestId("pdf-library-add-files")).toBeVisible();
+ await expect(page.getByTestId("google-drive-button")).toHaveCount(0);
+ });
+
+ test("shows the Google Drive button beside the add button", async ({
+ page,
+ }) => {
+ await stubGoogleDriveConfigured(page);
+ await page.goto("/editor");
+ const drive = page.getByTestId("google-drive-button");
+ await expect(drive).toBeVisible();
+
+ const driveBox = await drive.boundingBox();
+ const addBox = await page
+ .getByTestId("pdf-library-add-files")
+ .boundingBox();
+ expect(driveBox).not.toBeNull();
+ expect(addBox).not.toBeNull();
+ expect(driveBox!.y).toBeCloseTo(addBox!.y, 0);
+ expect(addBox!.x - (driveBox!.x + driveBox!.width)).toBeLessThan(12);
+ });
+});