Skip to content

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

File library Ui fixes and tweaks (#8044)

Reece Browne1f38ca7f0fc6
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.toml
index 9a172630a3..452feaeb42 100644
--- a/frontend/editor/public/locales/en-US/translation.toml
+++ b/frontend/editor/public/locales/en-US/translation.toml
@@ -4525,6 +4525,7 @@ breadcrumbsOverflow = "Show parent folders"
bulkActions = "Actions"
cancel = "Cancel"
classification = "Classification"
+clearSelection = "Clear selection"
closeDetails = "Close details"
create = "Create"
cycleBlocked = "Can't move a folder into one of its own subfolders."
@@ -4564,6 +4565,7 @@ folder = "Folder"
folderItems_one = "{{count}} item"
folderItems_other = "{{count}} items"
folderMenu = "Folder actions"
+folderSettings = "Folder settings"
inPath = "in {{path}}"
inWorkspace = "Open"
inWorkspaceAria = "Already in workspace"
@@ -4586,7 +4588,7 @@ offlineNoFolderEdits = "Server folder sync unavailable - folder changes are disa
open = "Open"
openVersionInWorkspace = "Open in workspace"
originFilter = "Filter by source"
-refresh = "Refresh from server"
+refresh = "Refresh"
remove = "Delete"
removeLocalFolder = "Unmount from Stirling"
removeVersion = "Remove this version"
@@ -4597,7 +4599,6 @@ save = "Save"
saveToServer = "Save to server"
saveToServerDisabledHint = "Saving to the server isn't enabled on this server. Ask your admin to enable it."
selectAll = "Select all"
-selectAllHint = "Click to select all. Tip: hold Ctrl (or Cmd) to add files one at a time, Shift to select a range."
selectedCount = "{{count}} selected"
selectFile = "Select file {{name}}"
serverFolderNeedsConnection = "Sign in to Stirling Cloud or connect a self-hosted server to use server folders."
@@ -4624,6 +4625,8 @@ viewVersionHistory = "Version journey ({{count}})"
[filesPage.appearance]
colour = "Color"
+done = "Done"
+edit = "Appearance..."
icon = "Icon"
title = "Appearance"
useColour = "Use color {{c}}"
@@ -4632,6 +4635,7 @@ useColour = "Use color {{c}}"
modified = "Modified"
name = "Name"
size = "Size"
+status = "Status"
type = "Type"
[filesPage.deleteScope]
@@ -4829,13 +4833,6 @@ server = "Server error during folder sync."
[filesPage.tabName]
local = "Local"
-[filesPage.tabs]
-all = "All"
-ariaLabel = "File views"
-recent = "Recent"
-shared = "Shared with me"
-sharedByMe = "Shared by me"
-
[filesPage.treeMenu]
actions = "Folder actions for {{name}}"
delete = "Delete folder"
diff --git a/frontend/editor/src/core/components/filesPage/FileGrid.tsx b/frontend/editor/src/core/components/filesPage/FileGrid.tsx
index 039dd8b5fe..d7de52671d 100644
--- a/frontend/editor/src/core/components/filesPage/FileGrid.tsx
+++ b/frontend/editor/src/core/components/filesPage/FileGrid.tsx
@@ -16,10 +16,7 @@ import {
import type { DiskFileEntry } from "@app/services/localFolderContents";
import { usePolicyFileBadges } from "@app/hooks/usePolicyFileBadges";
import { useServerProcessingBlock } from "@app/hooks/useServerProcessingBlock";
-import {
- useProcessingFolders,
- type ProcessingFolderState,
-} from "@app/hooks/useProcessingFolders";
+import { useProcessingFolders } from "@app/hooks/useProcessingFolders";
import {
useVirtualFileRows,
rowHeightPx,
@@ -34,14 +31,13 @@ import {
import { useDropTarget } from "@app/components/filesPage/useDropTarget";
import { getFileOrigin } from "@app/components/filesPage/fileOrigin";
import { FileOriginBadge } from "@app/components/filesPage/FileOriginBadge";
-import { FolderListRow } from "@app/components/filesPage/FolderListRow";
import { FolderProcessingTag } from "@app/components/filesPage/FolderProcessingTag";
import { FolderOriginBadge } from "@app/components/filesPage/FolderOriginBadge";
import { DiskLinkBadge } from "@app/components/filesPage/DiskLinkBadge";
import { FolderThumbnail } from "@app/components/filesPage/FolderThumbnail";
import { useProcessingFolderCounts } from "@app/components/filesPage/processingFolderCounts";
import { findFolderIcon } from "@app/components/filesPage/folderIcons";
-import { FolderAppearancePicker } from "@app/components/filesPage/FolderAppearancePicker";
+import { FolderMenu } from "@app/components/filesPage/FolderMenu";
import {
useLazyThumbnail,
useDiskThumbnail,
@@ -143,6 +139,11 @@ interface FileGridProps {
* so no item needs a context subscription that memoization would then fight.
*/
onActionError?: (message: string) => void;
+ /**
+ * What acts on the current selection, built by the page that owns the
+ * handlers. Rendered in the list's column header, which grid view lacks.
+ */
+ selectionActions?: React.ReactNode;
}
/**
@@ -728,283 +729,88 @@ const FolderCard = React.memo(function FolderCard({
)}
</div>
<div className="files-page-card-actions">
- <Menu shadow="md" position="bottom-end" withinPortal>
- <Menu.Target>
- <ActionIcon
- ref={kebabRef}
- size="sm"
- onClick={(e) => e.stopPropagation()}
- aria-label={t("filesPage.folderMenu", "Folder actions")}
- >
- <Icon name="ellipsis-vertical" size={20} />
- </ActionIcon>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item
- leftSection={<Icon name="external-link" size={20} />}
- onClick={onOpen}
- >
- {t("filesPage.open", "Open")}
- </Menu.Item>
- {editsHidden && (
- <ProcessingMenuItems
- processing={processing}
- disabled={Boolean(processingBlock)}
- disabledHint={processingBlock ?? undefined}
- onRun={() => void runProcessing("process folder now")}
- onStop={() => void stopProcessing("pause processing folder")}
- onStart={() => actions.startProcessing(folder)}
- onResume={() => void resumeProcessing("resume processing")}
- onRevertAll={
- kind === "local"
- ? () => actions.requestRevertAll(folder)
- : undefined
- }
- onEdit={() => actions.startProcessing(folder)}
- onRemove={() =>
- void removeProcessing("remove processing folder")
- }
- />
- )}
- {/* Only a mount root can be removed; a subdirectory is the
- disk's, and the app never deletes directories. */}
- {editsHidden && folder.parentFolderId === null && (
- <Menu.Item
- color="red"
- leftSection={<Icon name="trash" size={20} />}
- onClick={() => actions.deleteFolder(folder)}
- >
- {t("filesPage.removeLocalFolder", "Unmount from Stirling")}
- </Menu.Item>
- )}
- {!editsHidden && (
- <>
- <Menu.Item
- leftSection={<Icon name="file-pen" size={20} />}
- onClick={() => actions.renameFolder(folder)}
- disabled={editsDisabled}
- title={editsDisabled ? offlineHint : undefined}
- >
- {t("filesPage.rename", "Rename")}
- </Menu.Item>
- <Menu.Divider />
- <Menu.Label>
- {t("filesPage.appearance.title", "Appearance")}
- </Menu.Label>
- <FolderAppearancePicker
- folder={folder}
- onChange={(appearance) =>
- actions.changeFolderAppearance(folder.id, appearance)
- }
- disabled={editsDisabled}
- />
- <Menu.Divider />
- <ProcessingMenuItems
- processing={processing}
- continuous={kind === "virtual"}
- disabled={editsDisabled || Boolean(processingBlock)}
- disabledHint={processingBlock ?? offlineHint}
- onRun={() => void runProcessing("process folder now")}
- onStop={() => void stopProcessing("pause processing folder")}
- onStart={() => actions.startProcessing(folder)}
- onResume={() => void resumeProcessing("resume processing")}
- onEdit={() => actions.startProcessing(folder)}
- onRemove={() =>
- void removeProcessing("remove processing folder")
- }
- />
- <Menu.Divider />
- <Menu.Item
- color="red"
- leftSection={<Icon name="trash" size={20} />}
- onClick={() => actions.deleteFolder(folder)}
- disabled={editsDisabled}
- title={editsDisabled ? offlineHint : undefined}
- >
- {t("filesPage.deleteFolder", "Delete folder")}
- </Menu.Item>
- </>
- )}
- </Menu.Dropdown>
- </Menu>
+ <FolderMenu
+ folder={folder}
+ processing={processing}
+ continuous={kind === "virtual"}
+ isMount={editsHidden}
+ canUnmount={folder.parentFolderId === null}
+ editsDisabled={editsDisabled}
+ editsDisabledHint={offlineHint}
+ processingBlock={processingBlock}
+ variant="kebab"
+ triggerRef={kebabRef}
+ onOpen={onOpen}
+ onStartProcessing={() => actions.startProcessing(folder)}
+ onRunProcessing={() => void runProcessing("process folder now")}
+ onStopProcessing={() =>
+ void stopProcessing("pause processing folder")
+ }
+ onResumeProcessing={() => void resumeProcessing("resume processing")}
+ onRemoveProcessing={() =>
+ void removeProcessing("remove processing folder")
+ }
+ onEditProcessing={() => actions.startProcessing(folder)}
+ onRevertAll={
+ kind === "local"
+ ? () => actions.requestRevertAll(folder)
+ : undefined
+ }
+ onRename={() => actions.renameFolder(folder)}
+ onChangeAppearance={(appearance) =>
+ actions.changeFolderAppearance(folder.id, appearance)
+ }
+ onDelete={() => actions.deleteFolder(folder)}
+ />
</div>
</div>
);
});
/**
- * A working folder's live per-state counts, wherever the folder is drawn. `compact`
- * is the list's shape: the same numbers on one line, in a row that may not change
- * height.
+ * A working folder's live per-state counts. The row variant clips, so the states
+ * worth acting on come first and the title repeats the whole breakdown.
*/
function ProcessingFolderStats({
recordId,
listFiles,
- compact = false,
+ variant = "card",
}: {
recordId: string;
listFiles: (recordId: string) => Promise<{ state: string }[]>;
- compact?: boolean;
+ variant?: "card" | "row";
}) {
const { t } = useTranslation();
const counts = useProcessingFolderCounts(recordId, listFiles);
if (!counts) return null;
- const parts = (
- [
- ["done", t("filesPage.diskState.done", "Ready")],
- ["processing", t("filesPage.diskState.processing", "Processing")],
- ["failed", t("filesPage.diskState.failed", "Failed")],
- ["waiting", t("filesPage.diskState.waiting", "Queued")],
- ] as const
- ).filter(([state]) => (counts[state] ?? 0) > 0);
+ const labels = {
+ done: t("filesPage.diskState.done", "Ready"),
+ processing: t("filesPage.diskState.processing", "Processing"),
+ failed: t("filesPage.diskState.failed", "Failed"),
+ waiting: t("filesPage.diskState.waiting", "Queued"),
+ } as const;
+ const order =
+ variant === "row"
+ ? (["failed", "done", "processing", "waiting"] as const)
+ : (["done", "processing", "failed", "waiting"] as const);
+ const parts = order.filter((state) => (counts[state] ?? 0) > 0);
if (parts.length === 0) return null;
return (
<div
- className={`files-page-folder-stats${compact ? " is-compact" : ""}`}
+ className={`files-page-folder-stats${variant === "row" ? " is-row" : ""}`}
title={parts
- .map(([state, label]) => `${counts[state]} ${label}`)
+ .map((state) => `${counts[state]} ${labels[state]}`)
.join(" · ")}
>
- {parts.map(([state, label]) => (
+ {parts.map((state) => (
<span key={state} className={`files-page-folder-stat is-${state}`}>
- {counts[state]} {compact ? "" : label}
+ {counts[state]} {labels[state]}
</span>
))}
</div>
);
}
-/**
- * The processing entries of a folder's action menu, carried by every folder kind including
- * mounts, whose other edit actions are hidden. `continuous` marks a folder whose engine
- * processes arrivals on its own, where an explicit "process now" would have nothing to do.
- */
-export function ProcessingMenuItems({
- processing,
- continuous = false,
- disabled,
- disabledHint,
- onRun,
- onStop,
- onStart,
- onResume,
- onRemove,
- onEdit,
- onRevertAll,
-}: {
- processing: ProcessingFolderState | undefined;
- continuous?: boolean;
- disabled: boolean;
- disabledHint?: string;
- onRun: () => void;
- onStop: () => void;
- onStart: () => void;
- onResume: () => void;
- onRemove: () => void;
- /** Open the setup dialog seeded from the existing record; absent hides Edit. */
- onEdit?: () => void;
- /** Restore every archived original in the folder; absent hides the entry. */
- onRevertAll?: () => void;
-}) {
- const { t } = useTranslation();
- const heading = (
- <Menu.Label>{t("filesPage.processing.section", "Processing")}</Menu.Label>
- );
- if (!processing) {
- return (
- <>
- {heading}
- <Menu.Item
- leftSection={<Icon name="workflow" size={20} />}
- onClick={onStart}
- disabled={disabled}
- title={disabled ? disabledHint : undefined}
- >
- {t("filesPage.processing.start", "Process files in this folder...")}
- </Menu.Item>
- </>
- );
- }
- if (!processing.enabled) {
- // Paused, not gone: the pair kept its history, so resuming never re-runs
- // what was already done. Removing is the destructive option, named as such.
- return (
- <>
- {heading}
- <Menu.Item
- leftSection={<Icon name="play" size={20} />}
- onClick={onResume}
- disabled={disabled}
- title={disabled ? disabledHint : undefined}
- >
- {t("filesPage.processing.resume", "Resume processing")}
- </Menu.Item>
- {onEdit && (
- <Menu.Item
- leftSection={<Icon name="sliders-horizontal" size={20} />}
- onClick={onEdit}
- disabled={disabled}
- title={disabled ? disabledHint : undefined}
- >
- {t("filesPage.processing.edit", "Edit processing...")}
- </Menu.Item>
- )}
- {onRevertAll && (
- <Menu.Item
- leftSection={<Icon name="rotate-ccw-clock" size={20} />}
- onClick={onRevertAll}
- disabled={disabled}
- title={disabled ? disabledHint : undefined}
- >
- {t("filesPage.processing.restoreAll", "Restore all originals")}
- </Menu.Item>
- )}
- <Menu.Item
- color="red"
- leftSection={<Icon name="workflow" size={20} />}
- onClick={onRemove}
- disabled={disabled}
- title={disabled ? disabledHint : undefined}
- >
- {t("filesPage.processing.remove", "Remove processing")}
- </Menu.Item>
- </>
- );
- }
- return (
- <>
- {heading}
- {!continuous && (
- <Menu.Item
- leftSection={<Icon name="rotate-ccw" size={20} />}
- onClick={onRun}
- >
- {t("filesPage.processing.sweep", "Retry failed files")}
- </Menu.Item>
- )}
- <Menu.Item leftSection={<Icon name="pause" size={20} />} onClick={onStop}>
- {t("filesPage.processing.stop", "Pause processing")}
- </Menu.Item>
- {onEdit && (
- <Menu.Item
- leftSection={<Icon name="sliders-horizontal" size={20} />}
- onClick={onEdit}
- >
- {t("filesPage.processing.edit", "Edit processing...")}
- </Menu.Item>
- )}
- {onRevertAll && (
- <Menu.Item
- leftSection={<Icon name="rotate-ccw-clock" size={20} />}
- onClick={onRevertAll}
- >
- {t("filesPage.processing.restoreAll", "Restore all originals")}
- </Menu.Item>
- )}
- </>
- );
-}
-
/** A file's pipeline state chip; a failed state adds an inline retry. */
function FileStateBadge({
state,
@@ -1032,24 +838,32 @@ function FileStateBadge({
);
}
if (state === "failed") {
+ const failed = t("filesPage.diskState.failed", "Failed");
+ if (!onRetry) {
+ return <span className="files-page-state-badge is-failed">{failed}</span>;
+ }
+ const retryHint = t("filesPage.diskState.retryHint", "Run this file again");
return (
- <span className="files-page-state-badge is-failed">
- {t("filesPage.diskState.failed", "Failed")}
- {onRetry && (
- <button
- type="button"
- className="files-page-state-retry"
- onClick={(e) => {
- e.stopPropagation();
- onRetry();
- }}
- title={t("filesPage.diskState.retryHint", "Run this file again")}
- >
- <Icon name="rotate-ccw" size="0.8rem" />
- {t("filesPage.diskState.retry", "Retry")}
- </button>
- )}
- </span>
+ <button
+ type="button"
+ className="files-page-state-badge is-failed files-page-state-retry"
+ onClick={(e) => {
+ e.stopPropagation();
+ onRetry();
+ }}
+ title={retryHint}
+ aria-label={`${failed}: ${retryHint}`}
+ >
+ {/* Both labels share one grid cell, so the chip is as wide as the wider
+ of them and swapping on hover moves nothing around it. */}
+ <span className="files-page-state-retry-rest" aria-hidden="true">
+ {failed}
+ </span>
+ <span className="files-page-state-retry-hover" aria-hidden="true">
+ <Icon name="rotate-ccw" size="0.8rem" />
+ {t("filesPage.diskState.retry", "Retry")}
+ </span>
+ </button>
);
}
return (
@@ -1428,6 +1242,7 @@ function ListView({
selectedFileIds,
activeWorkspaceFileIds,
onSetSelection,
+ selectionActions,
onSaveToServer,
onVersionHistory,
onDownloadFile,
@@ -1463,6 +1278,7 @@ function ListView({
visibleFileIds.every((id) => selectedFileIds.has(id));
const someSelected =
!allSelected && visibleFileIds.some((id) => selectedFileIds.has(id));
+ const selecting = Boolean(selectionActions) && selectedFileIds.size > 0;
const sortIndicator = (asc: FilesPageSortMode, desc: FilesPageSortMode) => {
if (sortMode === asc) return " ↑";
@@ -1496,7 +1312,10 @@ function ListView({
<div className="files-page-list" role="grid" ref={setContainer}>
{/* Each direct child is a columnheader: a role="row" may only own cells, so
the sort controls and the select-all box have to sit inside one. */}
- <div className="files-page-list-row is-header" role="row">
+ <div
+ className={`files-page-list-row is-header${selecting ? " is-selecting" : ""}`}
+ role="row"
+ >
{onSetSelection && visibleFileIds.length > 0 ? (
<span role="columnheader">
<Checkbox
@@ -1517,26 +1336,44 @@ function ListView({
) : (
<span aria-hidden="true" />
)}
- <span role="columnheader">
- <span {...headerProps("name-asc", "name-desc")}>
- {t("filesPage.column.name", "Name")}
- {sortIndicator("name-asc", "name-desc")}
- </span>
- </span>
- <span role="columnheader">{t("filesPage.column.type", "Type")}</span>
- <span role="columnheader">
- <span {...headerProps("size-asc", "size-desc")}>
- {t("filesPage.column.size", "Size")}
- {sortIndicator("size-asc", "size-desc")}
- </span>
- </span>
- <span role="columnheader">
- <span {...headerProps("modified-asc", "modified-desc")}>
- {t("filesPage.column.modified", "Modified")}
- {sortIndicator("modified-asc", "modified-desc")}
+ {selecting ? (
+ <span role="columnheader" className="files-page-list-selection-bar">
+ <span className="files-page-list-selection-count">
+ {t("filesPage.selectedCount", "{{count}} selected", {
+ count: selectedFileIds.size,
+ })}
+ </span>
+ {selectionActions}
</span>
- </span>
- <span aria-hidden="true" />
+ ) : (
+ <>
+ <span role="columnheader">
+ <span {...headerProps("name-asc", "name-desc")}>
+ {t("filesPage.column.name", "Name")}
+ {sortIndicator("name-asc", "name-desc")}
+ </span>
+ </span>
+ <span role="columnheader">
+ {t("filesPage.column.type", "Type")}
+ </span>
+ <span role="columnheader">
+ <span {...headerProps("size-asc", "size-desc")}>
+ {t("filesPage.column.size", "Size")}
+ {sortIndicator("size-asc", "size-desc")}
+ </span>
+ </span>
+ <span role="columnheader">
+ <span {...headerProps("modified-asc", "modified-desc")}>
+ {t("filesPage.column.modified", "Modified")}
+ {sortIndicator("modified-asc", "modified-desc")}
+ </span>
+ </span>
+ <span role="columnheader">
+ {t("filesPage.column.status", "Status")}
+ </span>
+ <span aria-hidden="true" />
+ </>
+ )}
</div>
{padTop > 0 && (
<div
@@ -1673,124 +1510,8 @@ const FolderRow = React.memo(function FolderRow({
});
return (
- <FolderListRow
- folder={folder}
- fileCount={fileCount}
- parentPath={parentPath}
- status={
- processing ? (
- <>
- <FolderProcessingTag enabled={processing.enabled} />
- <ProcessingFolderStats
- recordId={processing.id}
- listFiles={listProcessingFiles}
- compact
- />
- </>
- ) : undefined
- }
- trailing={
- <Menu shadow="md" position="bottom-end" withinPortal>
- <Menu.Target>
- <ActionIcon
- ref={kebabRef}
- variant="tertiary"
- size="sm"
- onClick={(e) => e.stopPropagation()}
- aria-label={t("filesPage.folderMenu", "Folder actions")}
- >
- <Icon name="ellipsis-vertical" size={20} />
- </ActionIcon>
- </Menu.Target>
- <Menu.Dropdown>
- <Menu.Item
- leftSection={<Icon name="external-link" size={20} />}
- onClick={onOpen}
- >
- {t("filesPage.open", "Open")}
- </Menu.Item>
- {editsHidden && (
- <ProcessingMenuItems
- processing={processing}
- disabled={Boolean(processingBlock)}
- disabledHint={processingBlock ?? undefined}
- onRun={() => void runProcessing("process folder now")}
- onStop={() => void stopProcessing("pause processing folder")}
- onStart={() => actions.startProcessing(folder)}
- onResume={() => void resumeProcessing("resume processing")}
- onRevertAll={
- kind === "local"
- ? () => actions.requestRevertAll(folder)
- : undefined
- }
- onEdit={() => actions.startProcessing(folder)}
- onRemove={() =>
- void removeProcessing("remove processing folder")
- }
- />
- )}
- {/* Only a mount root can be removed; a subdirectory is the
- disk's, and the app never deletes directories. */}
- {editsHidden && folder.parentFolderId === null && (
- <Menu.Item
- color="red"
- leftSection={<Icon name="trash" size={20} />}
- onClick={() => actions.deleteFolder(folder)}
- >
- {t("filesPage.removeLocalFolder", "Unmount from Stirling")}
- </Menu.Item>
- )}
- {!editsHidden && (
- <>
- <Menu.Item
- leftSection={<Icon name="file-pen" size={20} />}
- onClick={() => actions.renameFolder(folder)}
- disabled={editsDisabled}
- title={editsDisabled ? offlineHint : undefined}
- >
- {t("filesPage.rename", "Rename")}
- </Menu.Item>
- <Menu.Divider />
- <Menu.Label>
- {t("filesPage.appearance.title", "Appearance")}
- </Menu.Label>
- <FolderAppearancePicker
- folder={folder}
- onChange={(appearance) =>
- actions.changeFolderAppearance(folder.id, appearance)
- }
- disabled={editsDisabled}
- />
- <Menu.Divider />
- <ProcessingMenuItems
- processing={processing}
- continuous={kind === "virtual"}
- disabled={editsDisabled || Boolean(processingBlock)}
- disabledHint={processingBlock ?? offlineHint}
- onRun={() => void runProcessing("process folder now")}
- onStop={() => void stopProcessing("pause processing folder")}
- onStart={() => actions.startProcessing(folder)}
- onResume={() => void resumeProcessing("resume processing")}
- onEdit={() => actions.startProcessing(folder)}
- onRemove={() =>
- void removeProcessing("remove processing folder")
- }
- />
- <Menu.Divider />
- <Menu.Item
- color="red"
- leftSection={<Icon name="trash" size={20} />}
- onClick={() => actions.deleteFolder(folder)}
- disabled={editsDisabled}
- title={editsDisabled ? offlineHint : undefined}
- >
- {t("filesPage.deleteFolder", "Delete folder")}
- </Menu.Item>
- </>
- )}
- </Menu.Dropdown>
- </Menu>
- }
+ <div
+ role="row"
tabIndex={0}
draggable
onDragStart={(e) => {
@@ -1812,8 +1533,111 @@ const FolderRow = React.memo(function FolderRow({
onKeyDown={(e) => {
if (e.key === "Enter") onOpen();
}}
- className={isDropTarget ? "is-drop-target" : undefined}
- />
+ className={`files-page-list-row${isDropTarget ? " is-drop-target" : ""}`}
+ >
+ <span aria-hidden="true" />
+ {/* Each direct child is a gridcell: a role="row" may only own cells, so the
+ actions menu has to sit inside one. */}
+ <span
+ role="gridcell"
+ style={{ display: "flex", alignItems: "center", gap: "0.5rem" }}
+ >
+ <FolderThumbnail
+ color={folder.color}
+ size="row"
+ iconGlyph={findFolderIcon(folder.icon)?.glyph}
+ />
+ <span
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ minWidth: 0,
+ overflow: "hidden",
+ }}
+ >
+ <span style={{ overflow: "hidden", textOverflow: "ellipsis" }}>
+ {folder.name}
+ </span>
+ {parentPath && (
+ <span
+ className="files-page-card-path"
+ style={{ marginTop: 0 }}
+ title={parentPath}
+ >
+ {t("filesPage.inPath", "in {{path}}", { path: parentPath })}
+ </span>
+ )}
+ </span>
+ <FolderOriginBadge folder={folder} />
+ </span>
+ <span role="gridcell">
+ {processing ? (
+ <span className="files-page-processing-tag">
+ {processing.enabled
+ ? t("filesPage.processing.active", "Processing folder")
+ : t("filesPage.processing.paused", "Processing paused")}
+ </span>
+ ) : kind === "virtual" ? (
+ t("filesPage.folderKind.virtual", "Browser folder")
+ ) : kind === "local" ? (
+ t("filesPage.folderKind.local", "Local folder")
+ ) : (
+ t("filesPage.folder", "Folder")
+ )}
+ </span>
+ <span role="gridcell">
+ {fileCount === 0
+ ? "-"
+ : t("filesPage.folderItems", "{{count}} items", { count: fileCount })}
+ </span>
+ <span role="gridcell">
+ {getFileDate({ lastModified: folder.updatedAt })}
+ </span>
+ <span role="gridcell" className="files-page-list-status">
+ {processing && (
+ <ProcessingFolderStats
+ recordId={processing.id}
+ listFiles={listProcessingFiles}
+ variant="row"
+ />
+ )}
+ </span>
+ <span role="gridcell">
+ <FolderMenu
+ folder={folder}
+ processing={processing}
+ continuous={kind === "virtual"}
+ isMount={editsHidden}
+ canUnmount={folder.parentFolderId === null}
+ editsDisabled={editsDisabled}
+ editsDisabledHint={offlineHint}
+ processingBlock={processingBlock}
+ variant="kebab"
+ triggerRef={kebabRef}
+ onOpen={onOpen}
+ onStartProcessing={() => actions.startProcessing(folder)}
+ onRunProcessing={() => void runProcessing("process folder now")}
+ onStopProcessing={() =>
+ void stopProcessing("pause processing folder")
+ }
+ onResumeProcessing={() => void resumeProcessing("resume processing")}
+ onRemoveProcessing={() =>
+ void removeProcessing("remove processing folder")
+ }
+ onEditProcessing={() => actions.startProcessing(folder)}
+ onRevertAll={
+ kind === "local"
+ ? () => actions.requestRevertAll(folder)
+ : undefined
+ }
+ onRename={() => actions.renameFolder(folder)}
+ onChangeAppearance={(appearance) =>
+ actions.changeFolderAppearance(folder.id, appearance)
+ }
+ onDelete={() => actions.deleteFolder(folder)}
+ />
+ </span>
+ </div>
);
});
@@ -1932,22 +1756,21 @@ const FileRow = React.memo(function FileRow({
minWidth: 0,
}}
>
- {resolvedThumbnail ? (
- <img
- src={resolvedThumbnail}
- alt=""
- // draggable={false} so row's onDragStart fires, not native image drag.
- draggable={false}
- style={{
- width: "1.5rem",
- height: "1.5rem",
- objectFit: "cover",
- borderRadius: "0.25rem",
- }}
- />
- ) : (
- <Icon name="file-pdf" size={20} />
- )}
+ {/* Fixed slot: the fallback and the thumbnail are different sizes, and a
+ thumbnail arrives after first paint, so sizing to the content would
+ leave the names ragged and then shift them as each one landed. */}
+ <span className="files-page-list-thumb">
+ {resolvedThumbnail ? (
+ <img
+ src={resolvedThumbnail}
+ alt=""
+ // draggable={false} so row's onDragStart fires, not native image drag.
+ draggable={false}
+ />
+ ) : (
+ <Icon name="file-pdf" size={20} />
+ )}
+ </span>
<span
style={{
display: "flex",
@@ -1978,10 +1801,6 @@ const FileRow = React.memo(function FileRow({
<FileOriginBadge origin={getFileOrigin(file)} compact />
<DiskLinkBadge file={file} compact />
<PolicyBadgeRow policies={badges} />
- <FileStateBadge
- state={processingState}
- onRetry={() => actions.retryFile(file.name)}
- />
{isInWorkspace && (
<span className="files-page-row-open-pill">
<span className="files-page-card-open-dot" />
@@ -1992,6 +1811,12 @@ const FileRow = React.memo(function FileRow({
<span role="gridcell">{ext || t("filesPage.file", "File")}</span>
<span role="gridcell">{fileSize}</span>
<span role="gridcell">{fileDate}</span>
+ <span role="gridcell" className="files-page-list-status">
+ <FileStateBadge
+ state={processingState}
+ onRetry={() => actions.retryFile(file.name)}
+ />
+ </span>
<span role="gridcell">
<FileActionsMenu
file={file}
@@ -2178,23 +2003,15 @@ const DiskFileRow = React.memo(function DiskFileRow({
minWidth: 0,
}}
>
- {thumbnail ? (
- <img
- src={thumbnail}
- alt=""
- draggable={false}
- style={{
- width: "1.5rem",
- height: "1.5rem",
- objectFit: "cover",
- borderRadius: "0.25rem",
- }}
- />
- ) : ext === "PDF" ? (
- <Icon name="file-pdf" size={20} />
- ) : (
- <Icon name="file" size={20} />
- )}
+ <span className="files-page-list-thumb">
+ {thumbnail ? (
+ <img src={thumbnail} alt="" draggable={false} />
+ ) : ext === "PDF" ? (
+ <Icon name="file-pdf" size={20} />
+ ) : (
+ <Icon name="file" size={20} />
+ )}
+ </span>
<span
style={{
overflow: "hidden",
@@ -2213,16 +2030,18 @@ const DiskFileRow = React.memo(function DiskFileRow({
)}
compact
/>
- <FileStateBadge
- state={state}
- onRetry={() => actions.retryFile(entry.name)}
- />
</span>
<span role="gridcell">{ext || t("filesPage.file", "File")}</span>
<span role="gridcell">{formatFileSize(entry.sizeBytes)}</span>
<span role="gridcell">
{getFileDate({ lastModified: entry.lastModified })}
</span>
+ <span role="gridcell" className="files-page-list-status">
+ <FileStateBadge
+ state={state}
+ onRetry={() => actions.retryFile(entry.name)}
+ />
+ </span>
<span role="gridcell">
<Menu shadow="md" position="bottom-end" withinPortal>
<Menu.Target>
diff --git a/frontend/editor/src/core/components/filesPage/FileManagerView.tsx b/frontend/editor/src/core/components/filesPage/FileManagerView.tsx
index 36419b1511..939efb222f 100644
--- a/frontend/editor/src/core/components/filesPage/FileManagerView.tsx
+++ b/frontend/editor/src/core/components/filesPage/FileManagerView.tsx
@@ -10,20 +10,19 @@ import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router-dom";
import {
Drawer,
- Group,
Menu,
MultiSelect,
Select,
TextInput,
Tooltip,
} from "@mantine/core";
-import { Button } from "@app/ui/Button";
import { ActionIcon } from "@app/ui/ActionIcon";
import { SegmentedControl } from "@app/ui/SegmentedControl";
import { useMediaQuery } from "@mantine/hooks";
import { FilesToolbarBulkMenu } from "@app/components/filesPage/FilesToolbarBulkMenu";
import { FilesToolbarCount } from "@app/components/filesPage/FilesToolbarCount";
import { FilesToolbarFilterMenu } from "@app/components/filesPage/FilesToolbarFilterMenu";
+import { FolderMenu } from "@app/components/filesPage/FolderMenu";
import { FilesToolbarSortMenu } from "@app/components/filesPage/FilesToolbarSortMenu";
import { NewFolderButton } from "@app/components/filesPage/NewFolderButton";
import { useFileLibraryWorkbenchBarButtons } from "@app/components/filesPage/useFileLibraryWorkbenchBarButtons";
@@ -64,7 +63,6 @@ import {
FilesPageEntry,
type DiskFileState,
} from "@app/components/filesPage/FileGrid";
-import { FolderAppearancePicker } from "@app/components/filesPage/FolderAppearancePicker";
import { useProcessingFolders } from "@app/hooks/useProcessingFolders";
import { FolderProcessingSetup } from "@app/components/policies/FolderProcessingSetup";
import { useServerProcessingBlock } from "@app/hooks/useServerProcessingBlock";
@@ -1426,10 +1424,7 @@ export default function FileManagerView() {
() => (
<>
<Tooltip
- label={
- signInRequiredReason ??
- t("filesPage.refresh", "Refresh from server")
- }
+ label={signInRequiredReason ?? t("filesPage.refresh", "Refresh")}
withinPortal
>
<ActionIcon
@@ -1438,7 +1433,7 @@ export default function FileManagerView() {
loading={refreshing}
disabled={refreshing || Boolean(signInRequiredReason)}
aria-busy={refreshing}
- aria-label={t("filesPage.refresh", "Refresh from server")}
+ aria-label={t("filesPage.refresh", "Refresh")}
onClick={handleRefresh}
>
<Icon name="refresh-cw" size={20} />
@@ -1474,6 +1469,30 @@ export default function FileManagerView() {
actions: isMobile ? libraryActions : null,
});
+ // One instance for whichever surface the view mode uses, so the two cannot
+ // drift apart.
+ const bulkActionsMenu =
+ selectedFiles.length > 0 ? (
+ <FilesToolbarBulkMenu
+ selectedCount={selectedFiles.length}
+ onAddToWorkspace={() => handleAddToWorkspace(selectedFiles)}
+ onSaveToServer={
+ localOnlySelectedStubs.length > 0
+ ? () => setSaveToServerTarget(localOnlySelectedStubs)
+ : undefined
+ }
+ saveToServerDisabledReason={saveToServerDisabledReason ?? undefined}
+ onShowDetails={
+ selectedFiles.length === 1 && isCompactDetailsViewport
+ ? () => setMobileDetailsOpen(true)
+ : undefined
+ }
+ onMove={() => promptMoveFiles(selectedFiles)}
+ onRemove={() => handleRemoveFiles(selectedFiles)}
+ onClearSelection={() => clearSelection()}
+ />
+ ) : null;
+
return (
<div className="files-page" ref={dropZoneRef}>
<input
@@ -1520,96 +1539,11 @@ export default function FileManagerView() {
<div className="files-page-body">
<main className="files-page-main">
- {/* Tab strip filters the file list; ARIA Tabs keyboard model. The
- library's path and actions share the row: kept out of the tablist
- itself, which may only contain tabs. */}
+ {/* The folder trail gets its own row above the toolbar. On mobile the
+ shared bar above carries it instead, so this row stays empty. */}
<div className="files-page-tabs-row">
- {(() => {
- const TAB_DEFS = [
- { id: "all", label: t("filesPage.tabs.all", "All") },
- { id: "recent", label: t("filesPage.tabs.recent", "Recent") },
- // Sharing tabs only when sharingEnabled.
- ...(sharingEnabled
- ? [
- {
- id: "shared" as const,
- label: t("filesPage.tabs.shared", "Shared with me"),
- },
- {
- id: "sharedByMe" as const,
- label: t("filesPage.tabs.sharedByMe", "Shared by me"),
- },
- ]
- : []),
- ] as const;
- const focusTab = (id: string) => {
- const el = document.getElementById(`filesPage-tab-${id}`);
- el?.focus();
- };
- return (
- <div
- className="files-page-tabs"
- role="tablist"
- aria-label={t("filesPage.tabs.ariaLabel", "File views")}
- onKeyDown={(e) => {
- const idx = TAB_DEFS.findIndex(
- (t2) => t2.id === currentTab,
- );
- if (idx < 0) return;
- let next: number;
- if (e.key === "ArrowRight")
- next = (idx + 1) % TAB_DEFS.length;
- else if (e.key === "ArrowLeft")
- next = (idx - 1 + TAB_DEFS.length) % TAB_DEFS.length;
- else if (e.key === "Home") next = 0;
- else if (e.key === "End") next = TAB_DEFS.length - 1;
- else return;
- e.preventDefault();
- const target = TAB_DEFS[next];
- setCurrentTab(target.id);
- focusTab(target.id);
- }}
- style={{
- display: "flex",
- gap: "0.1rem",
- padding: "0.2rem 1rem 0.2rem",
- }}
- >
- {TAB_DEFS.map((tab) => (
- <button
- key={tab.id}
- id={`filesPage-tab-${tab.id}`}
- role="tab"
- type="button"
- aria-selected={currentTab === tab.id}
- aria-controls="filesPage-tabpanel"
- tabIndex={currentTab === tab.id ? 0 : -1}
- onClick={() => setCurrentTab(tab.id)}
- style={{
- background:
- currentTab === tab.id
- ? "var(--c-hover)"
- : "transparent",
- border: "none",
- borderRadius: "0.3rem",
- padding: "0.2rem 0.6rem",
- color:
- currentTab === tab.id
- ? "var(--c-text)"
- : "var(--c-text-subtle)",
- fontWeight: currentTab === tab.id ? 500 : 400,
- fontSize: "0.75rem",
- cursor: "pointer",
- }}
- >
- {tab.label}
- </button>
- ))}
- </div>
- );
- })()}
- {!isMobile && (
- <>{path && <div className="files-page-tabs-path">{path}</div>}</>
+ {!isMobile && path && (
+ <div className="files-page-tabs-path">{path}</div>
)}
</div>
@@ -1618,477 +1552,77 @@ export default function FileManagerView() {
loading={loading}
totalCount={totalCount}
selectedCount={selectedFiles.length}
- selectionOnly={mobileSelection}
/>
{currentFolder && !mobileSelection && (
<div className="files-page-folder-actions">
- {!currentProcessing ? (
- <Tooltip
- label={
- processingBlock ??
- t(
- "filesPage.processing.start",
- "Process files in this folder...",
- )
- }
- withinPortal
- >
- {/* Mantine drops hover events on a disabled control, so the
- tooltip needs a live element to hang off. */}
- <span style={{ display: "inline-flex" }}>
- <ActionIcon
- size="sm"
- variant="secondary"
- disabled={Boolean(processingBlock)}
- onClick={() => setProcessingSetupFolder(currentFolder)}
- aria-label={t(
- "filesPage.processing.start",
- "Process files in this folder...",
- )}
- >
- <Icon name="workflow" size={20} />
- </ActionIcon>
- </span>
- </Tooltip>
- ) : (
- <>
- {currentProcessing.enabled ? (
- <>
- {folderKind(currentFolder) !== "virtual" &&
- stateCounts.failed > 0 && (
- <Tooltip
- label={t(
- "filesPage.processing.sweep",
- "Retry failed files",
- )}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() =>
- runFolderAction(
- processingApi.sweep,
- "process folder now",
- )
- }
- aria-label={t(
- "filesPage.processing.sweep",
- "Retry failed files",
- )}
- >
- <Icon name="rotate-ccw" size={20} />
- </ActionIcon>
- </Tooltip>
- )}
- <Tooltip
- label={t(
- "filesPage.processing.stop",
- "Pause processing",
- )}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() =>
- runFolderAction(
- processingApi.disable,
- "pause processing folder",
- )
- }
- aria-label={t(
- "filesPage.processing.stop",
- "Pause processing",
- )}
- >
- <Icon name="pause" size={20} />
- </ActionIcon>
- </Tooltip>
- </>
- ) : (
- <Tooltip
- label={t(
- "filesPage.processing.resume",
- "Resume processing",
- )}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() =>
- runFolderAction(
- processingApi.enable,
- "resume processing",
- )
- }
- aria-label={t(
- "filesPage.processing.resume",
- "Resume processing",
- )}
- >
- <Icon name="play" size={20} />
- </ActionIcon>
- </Tooltip>
- )}
- <Tooltip
- label={
- processingBlock ??
- t("filesPage.processing.edit", "Edit processing...")
- }
- withinPortal
- >
- {/* Mantine drops hover events on a disabled control, so the
- tooltip needs a live element to hang off. */}
- <span style={{ display: "inline-flex" }}>
- <ActionIcon
- size="sm"
- variant="secondary"
- disabled={Boolean(processingBlock)}
- onClick={() =>
- setProcessingSetupFolder(currentFolder)
- }
- aria-label={t(
- "filesPage.processing.edit",
- "Edit processing...",
- )}
- >
- <Icon name="sliders-horizontal" size={20} />
- </ActionIcon>
- </span>
- </Tooltip>
- {folderKind(currentFolder) === "local" && (
- <Tooltip
- label={t(
- "filesPage.processing.restoreAll",
- "Restore all originals",
- )}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() => setRevertAllTarget(currentFolder)}
- aria-label={t(
- "filesPage.processing.restoreAll",
- "Restore all originals",
- )}
- >
- <Icon name="rotate-ccw-clock" size={20} />
- </ActionIcon>
- </Tooltip>
- )}
- <Tooltip
- label={t(
- "filesPage.processing.remove",
- "Remove processing",
- )}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() =>
- runFolderAction(
- processingApi.remove,
- "remove processing folder",
- )
- }
- aria-label={t(
- "filesPage.processing.remove",
- "Remove processing",
- )}
- >
- <Icon name="workflow" size={20} />
- </ActionIcon>
- </Tooltip>
- </>
- )}
- {folderKind(currentFolder) === "local" ? (
- currentFolder.parentFolderId === null && (
- <Tooltip
- label={t(
- "filesPage.removeLocalFolder",
- "Unmount from Stirling",
- )}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() => promptDeleteFolder(currentFolder)}
- aria-label={t(
- "filesPage.removeLocalFolder",
- "Unmount from Stirling",
- )}
- >
- <Icon name="trash" size={20} />
- </ActionIcon>
- </Tooltip>
- )
- ) : (
- <>
- <Tooltip
- label={t("filesPage.rename", "Rename")}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() => openRenameFolderDialog(currentFolder)}
- disabled={headerEditsDisabled}
- aria-label={t("filesPage.rename", "Rename")}
- >
- <Icon name="file-pen" size={20} />
- </ActionIcon>
- </Tooltip>
- <Menu shadow="md" position="bottom-start" withinPortal>
- <Menu.Target>
- <Tooltip
- label={t("filesPage.appearance.title", "Appearance")}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- disabled={headerEditsDisabled}
- aria-label={t(
- "filesPage.appearance.title",
- "Appearance",
- )}
- >
- <Icon name="palette" size={20} />
- </ActionIcon>
- </Tooltip>
- </Menu.Target>
- <Menu.Dropdown>
- <FolderAppearancePicker
- folder={currentFolder}
- onChange={(appearance) => {
- setFolderAppearance(
- currentFolder.id,
- appearance,
- ).catch((err) =>
- folders.setError(
- err instanceof Error
- ? t(
- "filesPage.error.folderAppearanceFailedDetail",
- {
- message: err.message,
- defaultValue: `Could not update folder appearance: ${err.message}`,
- },
- )
- : t(
- "filesPage.error.folderAppearanceFailed",
- "Could not update folder appearance.",
- ),
- ),
- );
- }}
- disabled={headerEditsDisabled}
- />
- </Menu.Dropdown>
- </Menu>
- <Tooltip
- label={t("filesPage.deleteFolder", "Delete folder")}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() => promptDeleteFolder(currentFolder)}
- disabled={headerEditsDisabled}
- aria-label={t(
- "filesPage.deleteFolder",
- "Delete folder",
- )}
- >
- <Icon name="trash" size={20} />
- </ActionIcon>
- </Tooltip>
- </>
- )}
- </div>
- )}
- {(() => {
- // Select all / Clear toggle over visible files.
- if (visibleFiles.length === 0) return null;
- const allSelected = visibleFiles.every((f) =>
- selectedFileIds.has(f.id),
- );
- const someSelected = !allSelected && selectedFiles.length > 0;
- return (
- <Tooltip
- label={t(
- "filesPage.selectAllHint",
- "Click to select all. Tip: hold Ctrl (or Cmd) to add files one at a time, Shift to select a range.",
+ <FolderMenu
+ folder={currentFolder}
+ processing={currentProcessing}
+ continuous={folderKind(currentFolder) === "virtual"}
+ isMount={folderKind(currentFolder) === "local"}
+ canUnmount={currentFolder.parentFolderId === null}
+ editsDisabled={headerEditsDisabled}
+ processingBlock={processingBlock}
+ editsDisabledHint={t(
+ "filesPage.offlineNoFolderEdits",
+ "Offline - folder changes are disabled.",
)}
- withinPortal
- multiline
- w={280}
- >
- <Button
- variant="tertiary"
- size="sm"
- onClick={() => {
- if (allSelected) {
- setSelectedFileIds(new Set());
- } else {
- setSelectedFileIds(
- new Set(visibleFiles.map((f) => f.id)),
- );
- }
- }}
- aria-pressed={allSelected || someSelected}
- >
- {allSelected
- ? t("filesPage.deselectAll", "Clear selection")
- : t("filesPage.selectAll", "Select all")}
- </Button>
- </Tooltip>
- );
- })()}
- <div className="files-page-toolbar-actions">
- {mobileSelection ? (
- <FilesToolbarBulkMenu
- selectedCount={selectedFiles.length}
- onAddToWorkspace={() => handleAddToWorkspace(selectedFiles)}
- onSaveToServer={
- localOnlySelectedStubs.length > 0
- ? () => setSaveToServerTarget(localOnlySelectedStubs)
- : undefined
+ onStartProcessing={() =>
+ setProcessingSetupFolder(currentFolder)
+ }
+ onRunProcessing={() =>
+ runFolderAction(processingApi.sweep, "process folder now")
+ }
+ onStopProcessing={() =>
+ runFolderAction(
+ processingApi.disable,
+ "pause processing folder",
+ )
+ }
+ onResumeProcessing={() =>
+ runFolderAction(processingApi.enable, "resume processing")
}
- saveToServerDisabledReason={
- saveToServerDisabledReason ?? undefined
+ onRemoveProcessing={() =>
+ runFolderAction(
+ processingApi.remove,
+ "remove processing folder",
+ )
}
- onShowDetails={
- selectedFiles.length === 1
- ? () => setMobileDetailsOpen(true)
+ onEditProcessing={() =>
+ setProcessingSetupFolder(currentFolder)
+ }
+ onRevertAll={
+ folderKind(currentFolder) === "local"
+ ? () => setRevertAllTarget(currentFolder)
: undefined
}
- onMove={() => promptMoveFiles(selectedFiles)}
- onRemove={() => handleRemoveFiles(selectedFiles)}
+ onRename={() => openRenameFolderDialog(currentFolder)}
+ onChangeAppearance={(appearance) => {
+ setFolderAppearance(currentFolder.id, appearance).catch(
+ (err) =>
+ folders.setError(
+ err instanceof Error
+ ? t(
+ "filesPage.error.folderAppearanceFailedDetail",
+ {
+ message: err.message,
+ defaultValue: `Could not update folder appearance: ${err.message}`,
+ },
+ )
+ : t(
+ "filesPage.error.folderAppearanceFailed",
+ "Could not update folder appearance.",
+ ),
+ ),
+ );
+ }}
+ onDelete={() => promptDeleteFolder(currentFolder)}
/>
- ) : (
+ </div>
+ )}
+ <div className="files-page-toolbar-actions">
+ {!mobileSelection && (
<>
- {selectedFiles.length > 0 &&
- (() => {
- // Icon-only, as the folder-level strip is; the label is the tooltip.
- const addLabel =
- selectedFiles.length === 1
- ? t("filesPage.addToWorkspace", "Add to workspace")
- : t(
- "filesPage.addToWorkspaceCount",
- "Add {{count}} to workspace",
- { count: selectedFiles.length },
- );
- const moveLabel = t("filesPage.moveTo", "Move to…");
- const removeLabel = t("filesPage.remove", "Remove");
- return (
- // wrap="nowrap" keeps the row single-line.
- <Group gap="xs" wrap="nowrap">
- <Tooltip label={addLabel} withinPortal>
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() =>
- handleAddToWorkspace(selectedFiles)
- }
- aria-label={addLabel}
- data-testid="add-to-workspace"
- >
- <Icon name="external-link" size={20} />
- </ActionIcon>
- </Tooltip>
- {/* Save to server; shown whenever local-only files are
- selected. When storage is off it stays visible but
- disabled, tooltip pointing at the admin. */}
- {localOnlySelectedStubs.length > 0 && (
- <Tooltip
- label={
- saveToServerDisabledReason ??
- t("filesPage.saveToServer", "Save to server")
- }
- withinPortal
- multiline={Boolean(saveToServerDisabledReason)}
- w={saveToServerDisabledReason ? 240 : undefined}
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- disabled={Boolean(saveToServerDisabledReason)}
- onClick={() =>
- setSaveToServerTarget(localOnlySelectedStubs)
- }
- style={{
- // Keep the tooltip hoverable while disabled.
- pointerEvents: saveToServerDisabledReason
- ? "auto"
- : undefined,
- }}
- aria-label={t(
- "filesPage.saveToServer",
- "Save to server",
- )}
- >
- <Icon name="cloud-upload" size={20} />
- </ActionIcon>
- </Tooltip>
- )}
- {/* Show details button on compact viewports. */}
- {selectedFiles.length === 1 &&
- isCompactDetailsViewport && (
- <Tooltip
- label={t(
- "filesPage.showDetails",
- "Show details",
- )}
- withinPortal
- >
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() => setMobileDetailsOpen(true)}
- aria-label={t(
- "filesPage.showDetails",
- "Show details",
- )}
- >
- <Icon name="info" size={20} />
- </ActionIcon>
- </Tooltip>
- )}
- <Tooltip label={moveLabel} withinPortal>
- <ActionIcon
- size="sm"
- variant="secondary"
- onClick={() => promptMoveFiles(selectedFiles)}
- aria-label={moveLabel}
- >
- <Icon name="folder-input" size={20} />
- </ActionIcon>
- </Tooltip>
- <Tooltip label={removeLabel} withinPortal>
- <ActionIcon
- size="sm"
- accent="danger"
- variant="secondary"
- onClick={() => handleRemoveFiles(selectedFiles)}
- aria-label={removeLabel}
- >
- <Icon name="trash" size={20} />
- </ActionIcon>
- </Tooltip>
- </Group>
- );
- })()}
- {selectedFiles.length > 0 && (
- <span
- className="files-page-toolbar-divider"
- aria-hidden="true"
- />
- )}
{isMobile ? (
/* Side by side these need ~480px and were truncating to
stubs like "All sour"; collapsed they read in full. */
@@ -2300,10 +1834,9 @@ export default function FileManagerView() {
</div>
</div>
- <div
- className="files-page-content"
- onClick={handleContentBackgroundClick}
- >
+ {/* Always rendered: a row that only exists once something is selected
+ would push the listing down under the pointer mid-double-click. */}
+ <div className="files-page-above-table">
{processingView && (
<div className="files-page-state-filters">
{(
@@ -2328,6 +1861,17 @@ export default function FileManagerView() {
))}
</div>
)}
+ {viewMode === "grid" && bulkActionsMenu && (
+ <div className="files-page-toolbar-actions files-page-selection-actions">
+ {bulkActionsMenu}
+ </div>
+ )}
+ </div>
+
+ <div
+ className="files-page-content"
+ onClick={handleContentBackgroundClick}
+ >
<FolderSweepWall policyId={processingRecordId} />
<FileGrid
entries={entries}
@@ -2339,6 +1883,9 @@ export default function FileManagerView() {
selectedFileIds={selectedFileIds}
activeWorkspaceFileIds={activeWorkspaceFileIdSet}
viewMode={viewMode}
+ selectionActions={
+ viewMode === "list" ? bulkActionsMenu : undefined
+ }
sortMode={sortMode}
onChangeSortMode={setSortMode}
onSelectFile={handleSelectFile}
diff --git a/frontend/editor/src/core/components/filesPage/FilesPage.css b/frontend/editor/src/core/components/filesPage/FilesPage.css
index 6bb961e6fc..ad1a1dc7b3 100644
--- a/frontend/editor/src/core/components/filesPage/FilesPage.css
+++ b/frontend/editor/src/core/components/filesPage/FilesPage.css
@@ -8,9 +8,8 @@
overflow: hidden;
}
-/* The library's own row: the tabs, then the folder path. What the library brings
- sits here rather than in the shared bar above, which carries only what every view
- has. */
+/* The library's own row. The shared bar above carries only what every view has,
+ so the folder path sits here instead. */
.files-page-tabs-row {
display: flex;
align-items: center;
@@ -135,41 +134,31 @@
margin-left: auto;
display: flex;
align-items: center;
+ justify-content: flex-end;
+ flex-wrap: wrap;
gap: 0.5rem;
- /* Allow this container to shrink below its intrinsic content width so
- the bulk-action group + filter selects + view toggle can compete for
- space without bursting out of the toolbar (which previously bled
- under the right-hand details panel at wider viewports). */
+ /* Allow this container to shrink below its intrinsic content width so it
+ wraps inside the toolbar rather than bursting out of it (it would bleed
+ under the right-hand details panel). */
min-width: 0;
}
-/* Bulk-action buttons (Add to workspace, Quick view, Move to, Remove)
- are ICON-ONLY at every viewport. Even at 1280px when both side panels
- are visible, the main area is only ~616px wide - the labelled versions
- of these 4 buttons plus the 2 filter selects + view toggle simply
- don't fit. Each button has a Tooltip + aria-label, so the icon alone
- is accessible. */
-.files-page-toolbar-actions .mantine-Button-root {
- padding-left: 0.55rem;
- padding-right: 0.55rem;
+/* The filter, search and sort controls are text: shrinking them renders
+ "All sources" as "All s". They keep their declared width and the group
+ above wraps to a second line when the toolbar runs out of room. */
+.files-page-toolbar-actions > .mantine-Select-root,
+.files-page-toolbar-actions > .mantine-MultiSelect-root,
+.files-page-toolbar-actions > .mantine-TextInput-root {
flex-shrink: 0;
}
-.files-page-toolbar-actions .mantine-Button-section[data-position="left"] {
- margin-right: 0;
-}
-.files-page-toolbar-actions .mantine-Button-label {
- display: none;
-}
-/* Exception: the bulk-actions trigger IS its label. Collapsed to an icon it
- would read as a bare chevron with nothing to say what it opens. */
-.files-page-toolbar-actions
- .files-page-toolbar-bulk-trigger
- .mantine-Button-label {
- display: inline;
-}
-.files-page-toolbar-actions .files-page-toolbar-bulk-trigger {
+
+/* The menu triggers in the toolbar - selection actions, folder settings. Tighter
+ on the chevron side than the label side so the caret sits against the edge
+ rather than floating in its own margin. */
+.files-page-toolbar-bulk-trigger {
padding-left: 0.75rem;
padding-right: 0.5rem;
+ flex-shrink: 0;
}
/* Pin the view toggle: never let it clip off the right. flex-shrink:0
keeps its width fixed; the rest of the row shrinks around it. */
@@ -274,15 +263,30 @@
flex-direction: column;
border: 1px solid var(--c-border-subtle);
border-radius: 0.6rem;
- overflow: hidden;
+ /* Scrolls sideways once the rows hit their floors - see the narrow step
+ below. Still clips vertically, so rows stay inside the rounded corners. */
+ overflow-x: auto;
+ overflow-y: hidden;
background: var(--c-surface);
}
.files-page-list-row {
display: grid;
+ /* No column is ever dropped, so every track carries a floor: denied its width
+ a value wraps and the row grows, a timestamp into three lines. Type floors
+ for "Processing folder" and status for two chips ("1 Failed 12 Ready"),
+ the widest those cells hold; name floors widest, being what stays on screen
+ when the row is wider than the list.
+
+ Floors are lengths, never max-content: each row is its own grid, so a track
+ measuring its own text lands a few pixels off its neighbours and the
+ columns drift apart while scrolled. */
grid-template-columns:
- 2.25rem minmax(0, 3fr) minmax(3.5rem, 1fr) minmax(4.5rem, 1fr)
- minmax(max-content, 1.5fr) 2.5rem;
+ 2.25rem minmax(17rem, 3fr) minmax(7.5rem, 1fr) minmax(4.5rem, 1fr)
+ minmax(9.5rem, 1.5fr) minmax(8rem, 11rem) 2.5rem;
+ /* The sum of those floors: a flex item will not grow to its own content, so
+ without this the tracks overflow a box that never grew and nothing scrolls. */
+ min-width: 56rem;
gap: 0.5rem;
align-items: center;
/* Same offscreen skip as .files-page-card. */
@@ -307,6 +311,34 @@
letter-spacing: 0.05em;
cursor: default;
user-select: none;
+ /* Tall enough for the selection bar's button, so swapping the column labels
+ for it leaves the rows below where they were. A header that grows on the
+ first click moves the row under the pointer mid-double-click. */
+ min-height: 3rem;
+}
+
+/* Selecting replaces the column labels with what acts on the selection: they
+ have nothing to sort while a selection is the subject. The select-all box
+ keeps its track so it does not jump. */
+.files-page-list-row.is-header.is-selecting {
+ grid-template-columns: 2.25rem minmax(0, 1fr);
+ background: color-mix(in srgb, var(--c-primary) 10%, var(--c-bg-raised));
+ color: var(--c-text);
+ text-transform: none;
+ letter-spacing: normal;
+}
+
+.files-page-list-selection-bar {
+ display: flex;
+ align-items: center;
+ gap: 0.6rem;
+ min-width: 0;
+}
+
+.files-page-list-selection-count {
+ font-size: 0.85rem;
+ font-weight: 600;
+ white-space: nowrap;
}
.files-page-list-row.is-header [data-sortable="true"] {
@@ -464,6 +496,9 @@
.files-page-processing-tag {
display: inline-flex;
align-items: center;
+ /* Wrapping would make this row taller than the rest, and the list is
+ virtualised on a single row height. */
+ white-space: nowrap;
gap: 0.3rem;
padding: 0.05rem 0.4rem;
border-radius: var(--radius-sm, 4px);
@@ -489,9 +524,6 @@
state; a not-yet-processed file is also inert (no open, no menu) until its
result exists, and reads that way. */
.files-page-state-badge {
- position: absolute;
- top: 6px;
- right: 6px;
display: inline-flex;
align-items: center;
gap: 0.25rem;
@@ -504,6 +536,14 @@
color: var(--c-text-muted);
}
+/* Cards only: a row is a grid whose nearest positioned ancestor is the scrolling
+ area, so the same rule would take the badge out of the row entirely. */
+.files-page-card .files-page-state-badge {
+ position: absolute;
+ top: 6px;
+ right: 6px;
+}
+
.files-page-state-badge.is-failed {
color: var(--c-danger, var(--c-text));
border-color: color-mix(
@@ -536,18 +576,32 @@
.files-page-folder-actions {
display: flex;
align-items: center;
- gap: 0.3rem;
+ gap: 0.15rem;
margin-left: 0.6rem;
padding-left: 0.6rem;
border-left: 1px solid var(--c-border-subtle);
}
+/* The strip between the toolbar and the listing: state chips on the left, and
+ in grid view the selection's actions on the right, list view having a column
+ header to hold them. They sit here rather than in the toolbar because a
+ toolbar that reflows on selection moves every row under it, which breaks
+ double-click-to-open. Side padding matches the toolbar so the chips line up
+ with the count above them. */
+.files-page-above-table {
+ display: flex;
+ align-items: center;
+ gap: 0.6rem;
+ /* Same space empty as full, so filling it moves nothing below. */
+ min-height: 2.5rem;
+ padding: 0 1.25rem;
+}
+
/* State filter chips above a working folder's listing. */
.files-page-state-filters {
display: flex;
align-items: center;
gap: 0.4rem;
- padding: 0 0 0.6rem;
flex-wrap: wrap;
}
@@ -577,21 +631,39 @@
}
/* Retry on a failed file's badge; must stay clickable inside an inert card. */
+/* The failed chip is the retry control: hovering it swaps its label for the
+ action. Both labels occupy one grid cell so the chip keeps the width of the
+ wider of them and the row's other cells never shift. */
.files-page-state-retry {
- display: inline-flex;
- align-items: center;
- gap: 0.15rem;
- margin-left: 0.3rem;
- padding: 0;
+ display: inline-grid;
font: inherit;
- color: inherit;
- background: none;
- border: none;
- text-decoration: underline;
cursor: pointer;
pointer-events: auto;
}
+.files-page-state-retry-rest,
+.files-page-state-retry-hover {
+ grid-area: 1 / 1;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.15rem;
+}
+
+.files-page-state-retry-hover {
+ visibility: hidden;
+}
+
+.files-page-state-retry:hover .files-page-state-retry-rest,
+.files-page-state-retry:focus-visible .files-page-state-retry-rest {
+ visibility: hidden;
+}
+
+.files-page-state-retry:hover .files-page-state-retry-hover,
+.files-page-state-retry:focus-visible .files-page-state-retry-hover {
+ visibility: visible;
+}
+
/* A working folder's per-state counts, one dotted chip per non-zero state. */
.files-page-folder-stats {
display: flex;
@@ -600,15 +672,41 @@
margin-top: 0.3rem;
}
-/* In a row the counts share one line with the tag beside them, and the row's height
- is fixed: they never wrap, and the full labels live in the title. */
-.files-page-folder-stats.is-compact {
- display: inline-flex;
- flex-wrap: nowrap;
- gap: 0.3rem;
+/* The row's height is fixed, so the breakdown stays on the one line the status
+ cell gives it and clips rather than wrapping. */
+.files-page-folder-stats.is-row {
margin-top: 0;
- margin-left: 0.4rem;
- vertical-align: middle;
+ flex-wrap: nowrap;
+ white-space: nowrap;
+ min-width: 0;
+}
+
+/* One width whatever the row has to show, so every name in the column starts at
+ the same x and none of them move when a thumbnail resolves. */
+.files-page-list-thumb {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+ width: 1.5rem;
+ height: 1.5rem;
+}
+
+.files-page-list-thumb img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ border-radius: 0.25rem;
+}
+
+/* The state has a column of its own: beside the name it outgrows the cell and
+ runs under the actions. */
+.files-page-list-status {
+ display: flex;
+ align-items: center;
+ gap: 0.35rem;
+ min-width: 0;
+ overflow: hidden;
}
.files-page-folder-stat {
@@ -1453,25 +1551,17 @@
}
}
-/* ── Tablet / narrow desktop (≤900px) ────────────────────────────────
- As soon as the right-hand details panel disappears (at 800px) and
- even slightly before, the toolbar gets crowded - the bulk-action
- strip ("Add to workspace", "Quick view", "Move to…", "Remove") +
- filter selects + grid/list toggle is too wide to fit. This block
- collapses bulk-action button labels to icon-only, shrinks the
- filter selects, and pins the view toggle so it never clips off the
- right edge. */
+/* Below this width the toolbar holds the count, the filter and sort triggers
+ and the view toggle in the room the details panel used to leave it. What
+ follows tightens their spacing and collapses the controls that can afford to
+ lose their labels. */
@media (max-width: 1024px) {
.files-page-toolbar {
- /* nowrap so "7 items" + "Select all" sit on the same row as the
- filter dropdowns and view-toggle instead of stacking on three
- separate lines. Runs to the app's mobile breakpoint: capping it at
- 900px left 901-1024px wrapping to two rows, which is the band the
- mobile layout actually renders in.
-
- Scrolls rather than clips. With a selection active the bulk-action
- strip cannot fit any phone width, and `overflow-x: hidden` put those
- buttons permanently out of reach behind the edge. */
+ /* nowrap so the count shares a row with the filter and sort triggers and
+ the view toggle. Runs to the app's own mobile breakpoint: stopping at
+ 900px left 901-1024px wrapping to two rows, and that band is where the
+ mobile layout renders. Scrolls rather than clips, so nothing the row
+ cannot fit ends up unreachable behind its edge. */
flex-wrap: nowrap;
gap: 0.35rem;
padding: 0.35rem 0.5rem;
@@ -1494,6 +1584,32 @@
.files-page-toolbar-icon-btn {
flex-shrink: 0;
}
+
+ /* The desktop inset cost the state chips a chip's worth of room and wrapped
+ the last one onto a second line. */
+ .files-page-above-table {
+ padding: 0 0.5rem;
+ }
+
+ /* The gear alone: its label and caret cost more width here than the two
+ filter controls beside it. */
+ .files-page-folder-actions .files-page-toolbar-bulk-trigger {
+ padding-left: 0.4rem;
+ padding-right: 0.4rem;
+ }
+ .files-page-folder-actions
+ .files-page-toolbar-bulk-trigger
+ .mantine-Button-label,
+ .files-page-folder-actions
+ .files-page-toolbar-bulk-trigger
+ .mantine-Button-section[data-position="right"] {
+ display: none;
+ }
+ .files-page-folder-actions
+ .files-page-toolbar-bulk-trigger
+ .mantine-Button-section[data-position="left"] {
+ margin-right: 0;
+ }
.files-page-toolbar-actions {
flex-wrap: nowrap;
gap: 0.3rem;
@@ -1507,15 +1623,6 @@
max-width: 7.5rem;
width: auto !important;
}
- /* The "Select all" / "Clear selection" toggle is a Mantine Button
- directly inside .files-page-toolbar (NOT inside the actions group),
- so the icon-only collapse from base styles doesn't apply to it.
- Pin it to full text + nowrap so it never truncates to "Select al"
- mid-word. */
- .files-page-toolbar > .mantine-Button-root {
- flex-shrink: 0;
- white-space: nowrap;
- }
}
/* ── Mobile (≤640px) ────────────────────────────────────────────────
@@ -1545,19 +1652,6 @@
}
}
-@media (max-width: 560px) {
- /* List view at narrow widths becomes cramped - drop the size + type + modified
- columns and let name + actions take the room. */
- .files-page-list-row {
- grid-template-columns: 1.75rem minmax(0, 1fr) 2rem;
- }
- .files-page-list-row > :nth-child(3),
- .files-page-list-row > :nth-child(4),
- .files-page-list-row > :nth-child(5) {
- display: none;
- }
-}
-
/* Honour user preference for reduced motion (WCAG 2.3.3). Disables the
open-badge pulse, drop-overlay pulse + scale, and the card hover lift -
keeps focus rings and selection borders so state is still visible. */
diff --git a/frontend/editor/src/core/components/filesPage/FilesToolbarBulkMenu.tsx b/frontend/editor/src/core/components/filesPage/FilesToolbarBulkMenu.tsx
index 5e642ef250..f5ecf89aa2 100644
--- a/frontend/editor/src/core/components/filesPage/FilesToolbarBulkMenu.tsx
+++ b/frontend/editor/src/core/components/filesPage/FilesToolbarBulkMenu.tsx
@@ -13,13 +13,13 @@ interface FilesToolbarBulkMenuProps {
onShowDetails?: () => void;
onMove: () => void;
onRemove: () => void;
+ onClearSelection: () => void;
}
/**
- * Bulk actions behind one trigger. The full strip is five buttons wide, which
- * no phone can hold alongside the count and the clear control, so rather than
- * letting the row scroll them off the edge they collapse into a menu where
- * every action keeps its label.
+ * Everything that acts on the current selection, behind one trigger. A strip of
+ * five buttons only fits the widest viewports, and shrinking it to icons costs
+ * every label; one menu reads the same at any width.
*/
export function FilesToolbarBulkMenu({
selectedCount,
@@ -29,6 +29,7 @@ export function FilesToolbarBulkMenu({
onShowDetails,
onMove,
onRemove,
+ onClearSelection,
}: FilesToolbarBulkMenuProps) {
const { t } = useTranslation();
@@ -82,6 +83,12 @@ export function FilesToolbarBulkMenu({
>
{t("filesPage.moveTo", "Move to…")}
</Menu.Item>
+ <Menu.Item
+ leftSection={<Icon name="x" size={"1.1rem"} />}
+ onClick={onClearSelection}
+ >
+ {t("filesPage.clearSelection", "Clear selection")}
+ </Menu.Item>
<Menu.Divider />
<Menu.Item
color="red"
diff --git a/frontend/editor/src/core/components/filesPage/FilesToolbarCount.tsx b/frontend/editor/src/core/components/filesPage/FilesToolbarCount.tsx
index d808638d63..09f9658124 100644
--- a/frontend/editor/src/core/components/filesPage/FilesToolbarCount.tsx
+++ b/frontend/editor/src/core/components/filesPage/FilesToolbarCount.tsx
@@ -4,11 +4,6 @@ interface FilesToolbarCountProps {
loading: boolean;
totalCount: number;
selectedCount: number;
- /**
- * Selection-bar mode: report only the selection. A phone spends the room on
- * the actions rather than on "3 items · 3 selected".
- */
- selectionOnly: boolean;
}
/** Status text at the head of the files toolbar. */
@@ -16,7 +11,6 @@ export function FilesToolbarCount({
loading,
totalCount,
selectedCount,
- selectionOnly,
}: FilesToolbarCountProps) {
const { t } = useTranslation();
@@ -24,10 +18,6 @@ export function FilesToolbarCount({
count: selectedCount,
});
- if (selectionOnly) {
- return <span className="files-page-toolbar-info">{selected}</span>;
- }
-
return (
<span className="files-page-toolbar-info">
{loading
diff --git a/frontend/editor/src/core/components/filesPage/FolderAppearanceModal.tsx b/frontend/editor/src/core/components/filesPage/FolderAppearanceModal.tsx
new file mode 100644
index 0000000000..53c174c158
--- /dev/null
+++ b/frontend/editor/src/core/components/filesPage/FolderAppearanceModal.tsx
@@ -0,0 +1,55 @@
+import { useTranslation } from "react-i18next";
+
+import { Modal } from "@app/ui/Modal";
+import { Button } from "@app/ui/Button";
+import { FolderRecord } from "@app/types/folder";
+import { FolderAppearancePicker } from "@app/components/filesPage/FolderAppearancePicker";
+
+interface FolderAppearanceModalProps {
+ /** The folder being restyled; null closes the modal. */
+ folder: FolderRecord | null;
+ onClose: () => void;
+ onChange: (next: { color?: string; icon?: string | null }) => void;
+ disabled?: boolean;
+}
+
+/**
+ * The folder's colour and icon picker on its own surface, the folder menu having
+ * no room for a grid that tall beside the actions a reader came for.
+ *
+ * There is no cancel: every swatch applies as it is clicked, so the footer
+ * dismisses rather than commits.
+ */
+export function FolderAppearanceModal({
+ folder,
+ onClose,
+ onChange,
+ disabled = false,
+}: FolderAppearanceModalProps) {
+ const { t } = useTranslation();
+
+ return (
+ <Modal
+ open={Boolean(folder)}
+ onClose={onClose}
+ width="sm"
+ title={t("filesPage.appearance.title", "Appearance")}
+ subtitle={folder?.name}
+ footer={
+ <Button variant="secondary" onClick={onClose}>
+ {t("filesPage.appearance.done", "Done")}
+ </Button>
+ }
+ >
+ {folder && (
+ <FolderAppearancePicker
+ folder={folder}
+ onChange={onChange}
+ disabled={disabled}
+ />
+ )}
+ </Modal>
+ );
+}
+
+export default FolderAppearanceModal;
diff --git a/frontend/editor/src/core/components/filesPage/FolderAppearancePicker.css b/frontend/editor/src/core/components/filesPage/FolderAppearancePicker.css
new file mode 100644
index 0000000000..92bae5a1fa
--- /dev/null
+++ b/frontend/editor/src/core/components/filesPage/FolderAppearancePicker.css
@@ -0,0 +1,98 @@
+.folder-appearance {
+ display: flex;
+ flex-direction: column;
+ gap: 1.25rem;
+}
+
+.folder-appearance[data-disabled] {
+ opacity: 0.55;
+ pointer-events: none;
+}
+
+.folder-appearance-section {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+}
+
+.folder-appearance-label {
+ font-size: 0.7rem;
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.05em;
+ color: var(--c-text-subtle);
+}
+
+.folder-appearance-swatches {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.15rem;
+}
+
+/* The hit area is the button; the dot is only what it looks like. Keeps a
+ small swatch comfortably tappable without drawing a 2rem blob. */
+.folder-appearance-swatch {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 2rem;
+ height: 2rem;
+ padding: 0;
+ border: none;
+ border-radius: 50%;
+ background: transparent;
+ cursor: pointer;
+}
+
+.folder-appearance-swatch:hover .folder-appearance-dot {
+ transform: scale(1.12);
+}
+
+.folder-appearance-dot {
+ width: 1.25rem;
+ height: 1.25rem;
+ border-radius: 50%;
+ transition: transform 0.12s ease;
+}
+
+/* Ring sits outside the dot, with a gap in the surface colour between, so the
+ selection reads without thickening the swatch itself. */
+.folder-appearance-swatch[aria-pressed="true"] .folder-appearance-dot {
+ box-shadow:
+ 0 0 0 2px var(--c-surface),
+ 0 0 0 4px var(--c-text);
+}
+
+.folder-appearance-icons {
+ display: grid;
+ grid-template-columns: repeat(8, 1fr);
+ gap: 0.25rem;
+}
+
+.folder-appearance-icon {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 2.25rem;
+ height: 2.25rem;
+ padding: 0;
+ font-size: 1.1rem;
+ line-height: 1;
+ color: var(--c-text);
+ background: transparent;
+ border: 1px solid transparent;
+ border-radius: 0.5rem;
+ cursor: pointer;
+ transition:
+ background-color 0.12s ease,
+ border-color 0.12s ease;
+}
+
+.folder-appearance-icon:hover {
+ background: var(--c-hover);
+}
+
+.folder-appearance-icon[aria-pressed="true"] {
+ background: var(--c-hover);
+ border-color: var(--c-primary);
+}
diff --git a/frontend/editor/src/core/components/filesPage/FolderAppearancePicker.tsx b/frontend/editor/src/core/components/filesPage/FolderAppearancePicker.tsx
index 0a256b1310..5b0af1925e 100644
--- a/frontend/editor/src/core/components/filesPage/FolderAppearancePicker.tsx
+++ b/frontend/editor/src/core/components/filesPage/FolderAppearancePicker.tsx
@@ -1,7 +1,6 @@
/**
- * Inline colour + icon picker for a folder. Rendered inside the folder
- * kebab menu (Mantine Menu.Item with a custom body) so the menu can
- * still own close-on-outside-click behaviour.
+ * Colour + icon picker for a folder. Every change applies immediately, so the
+ * surface hosting it needs no save step of its own.
*/
import React from "react";
@@ -13,7 +12,7 @@ import {
FOLDER_ICONS,
FolderIconOption,
} from "@app/components/filesPage/folderIcons";
-import { Button } from "@app/ui/Button";
+import "@app/components/filesPage/FolderAppearancePicker.css";
interface FolderAppearancePickerProps {
folder: FolderRecord;
@@ -31,30 +30,19 @@ export function FolderAppearancePicker({
return (
<div
- style={{
- display: "flex",
- flexDirection: "column",
- gap: "0.75rem",
- padding: "0.5rem 0.75rem",
- minWidth: "16rem",
- opacity: disabled ? 0.55 : 1,
- pointerEvents: disabled ? "none" : undefined,
- }}
+ className="folder-appearance"
+ data-disabled={disabled || undefined}
aria-disabled={disabled || undefined}
>
<Section label={t("filesPage.appearance.colour", "Colour")}>
- <div
- style={{
- display: "grid",
- gridTemplateColumns: "repeat(8, 1fr)",
- gap: "0.35rem",
- }}
- >
+ <div className="folder-appearance-swatches">
{FOLDER_COLOR_PALETTE.map((c) => (
- <Button
+ <button
key={c}
- variant="secondary"
+ type="button"
+ className="folder-appearance-swatch"
disabled={disabled}
+ aria-pressed={folder.color === c}
aria-label={t(
"filesPage.appearance.useColour",
"Use colour {{c}}",
@@ -64,32 +52,19 @@ export function FolderAppearancePicker({
e.stopPropagation();
onChange({ color: c });
}}
- style={{
- width: "1.6rem",
- height: "1.6rem",
- borderRadius: "50%",
- border:
- folder.color === c
- ? "2px solid var(--c-text)"
- : "2px solid transparent",
- background: c,
- cursor: disabled ? "not-allowed" : "pointer",
- padding: 0,
- outlineOffset: "2px",
- }}
- />
+ >
+ {/* The colour is data, not theme, so it stays an inline value. */}
+ <span
+ className="folder-appearance-dot"
+ style={{ background: c }}
+ />
+ </button>
))}
</div>
</Section>
<Section label={t("filesPage.appearance.icon", "Icon")}>
- <div
- style={{
- display: "grid",
- gridTemplateColumns: "repeat(6, 1fr)",
- gap: "0.25rem",
- }}
- >
+ <div className="folder-appearance-icons">
{FOLDER_ICONS.map((icon) => (
<IconButton
key={icon.id}
@@ -117,18 +92,8 @@ function Section({
children: React.ReactNode;
}) {
return (
- <div style={{ display: "flex", flexDirection: "column", gap: "0.35rem" }}>
- <span
- style={{
- fontSize: "0.7rem",
- textTransform: "uppercase",
- letterSpacing: "0.05em",
- color: "var(--c-text-subtle)",
- fontWeight: 600,
- }}
- >
- {label}
- </span>
+ <div className="folder-appearance-section">
+ <span className="folder-appearance-label">{label}</span>
{children}
</div>
);
@@ -147,33 +112,19 @@ function IconButton({
}) {
return (
<Tooltip label={icon.label} withinPortal>
- <Button
- variant="tertiary"
+ <button
+ type="button"
+ className="folder-appearance-icon"
disabled={disabled}
+ aria-pressed={selected}
aria-label={icon.label}
onClick={(e) => {
e.stopPropagation();
onClick();
}}
- style={{
- width: "2rem",
- height: "2rem",
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- fontSize: "1.1rem",
- borderRadius: "0.4rem",
- background: selected ? "var(--c-hover)" : "transparent",
- border: selected
- ? "1px solid var(--c-primary)"
- : "1px solid transparent",
- cursor: disabled ? "not-allowed" : "pointer",
- padding: 0,
- color: "var(--c-text)",
- }}
>
- {icon.glyph || "-"}
- </Button>
+ {icon.glyph || "—"}
+ </button>
</Tooltip>
);
}
diff --git a/frontend/editor/src/core/components/filesPage/FolderMenu.tsx b/frontend/editor/src/core/components/filesPage/FolderMenu.tsx
new file mode 100644
index 0000000000..7c61d1a629
--- /dev/null
+++ b/frontend/editor/src/core/components/filesPage/FolderMenu.tsx
@@ -0,0 +1,199 @@
+import React, { useState } from "react";
+import { Menu } from "@mantine/core";
+import { useTranslation } from "react-i18next";
+import DeleteIcon from "@mui/icons-material/Delete";
+import DriveFileRenameOutlineIcon from "@mui/icons-material/DriveFileRenameOutline";
+import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
+import MoreVertIcon from "@mui/icons-material/MoreVert";
+import OpenInNewIcon from "@mui/icons-material/OpenInNew";
+import PaletteIcon from "@mui/icons-material/Palette";
+import SettingsIcon from "@mui/icons-material/Settings";
+
+import { FolderRecord } from "@app/types/folder";
+import { ProcessingFolderState } from "@app/hooks/useProcessingFolders";
+import { FolderAppearanceModal } from "@app/components/filesPage/FolderAppearanceModal";
+import { ProcessingMenuItems } from "@app/components/filesPage/ProcessingMenuItems";
+import { ActionIcon } from "@app/ui/ActionIcon";
+import { Button } from "@app/ui/Button";
+
+interface FolderMenuProps {
+ folder: FolderRecord;
+ processing: ProcessingFolderState | undefined;
+ /**
+ * A folder whose engine picks up arrivals on its own, where an explicit
+ * "retry failed" has nothing to act on.
+ */
+ continuous: boolean;
+ /**
+ * A mounted disk directory. The disk owns its name, colour and existence, so
+ * the rename, appearance and delete entries do not apply to it.
+ */
+ isMount: boolean;
+ /** Mount roots can be unmounted; a subdirectory below one cannot. */
+ canUnmount: boolean;
+ editsDisabled: boolean;
+ editsDisabledHint?: string;
+ /** Why processing cannot run, or null. Gates the processing entries alone: a
+ * build with no server behind it can still rename and recolour a folder. */
+ processingBlock?: string | null;
+ onStartProcessing: () => void;
+ onRunProcessing: () => void;
+ onStopProcessing: () => void;
+ onResumeProcessing: () => void;
+ onRemoveProcessing: () => void;
+ onEditProcessing: () => void;
+ /** Restore every archived original in the folder; absent hides the entry. */
+ onRevertAll?: () => void;
+ onRename: () => void;
+ onChangeAppearance: (appearance: {
+ color?: string;
+ icon?: string | null;
+ }) => void;
+ onDelete: () => void;
+ /** Adds an Open entry above the rest; absent where the folder is already open. */
+ onOpen?: () => void;
+ variant?: "toolbar" | "kebab";
+ /** Lets a row open its own menu from a right-click anywhere on it. */
+ triggerRef?: React.Ref<HTMLButtonElement>;
+}
+
+/**
+ * Everything that acts on one folder, behind a single trigger. The folder you
+ * are inside and every folder in a row open this same menu; only the trigger
+ * and the Open entry differ.
+ */
+export function FolderMenu({
+ folder,
+ processing,
+ continuous,
+ isMount,
+ canUnmount,
+ editsDisabled,
+ editsDisabledHint,
+ processingBlock,
+ onStartProcessing,
+ onRunProcessing,
+ onStopProcessing,
+ onResumeProcessing,
+ onRemoveProcessing,
+ onEditProcessing,
+ onRevertAll,
+ onRename,
+ onChangeAppearance,
+ onDelete,
+ onOpen,
+ variant = "toolbar",
+ triggerRef,
+}: FolderMenuProps) {
+ const { t } = useTranslation();
+ const [appearanceOpen, setAppearanceOpen] = useState(false);
+ const settingsLabel = t("filesPage.folderSettings", "Folder settings");
+
+ return (
+ <>
+ <Menu
+ shadow="md"
+ width={300}
+ position={variant === "kebab" ? "bottom-end" : "bottom-start"}
+ withinPortal
+ >
+ <Menu.Target>
+ {variant === "kebab" ? (
+ <ActionIcon
+ ref={triggerRef}
+ variant="tertiary"
+ size="sm"
+ onClick={(e) => e.stopPropagation()}
+ aria-label={t("filesPage.folderMenu", "Folder actions")}
+ >
+ <MoreVertIcon fontSize="small" />
+ </ActionIcon>
+ ) : (
+ <Button
+ ref={triggerRef}
+ size="sm"
+ variant="secondary"
+ className="files-page-toolbar-bulk-trigger"
+ leftSection={<SettingsIcon sx={{ fontSize: "1.1rem" }} />}
+ rightSection={<ExpandMoreIcon sx={{ fontSize: "1.1rem" }} />}
+ aria-label={settingsLabel}
+ >
+ {settingsLabel}
+ </Button>
+ )}
+ </Menu.Target>
+ <Menu.Dropdown>
+ {onOpen && (
+ <Menu.Item
+ leftSection={<OpenInNewIcon sx={{ fontSize: "1.1rem" }} />}
+ onClick={onOpen}
+ >
+ {t("filesPage.open", "Open")}
+ </Menu.Item>
+ )}
+ {!isMount && (
+ <>
+ <Menu.Label>{t("filesPage.folder", "Folder")}</Menu.Label>
+ <Menu.Item
+ leftSection={
+ <DriveFileRenameOutlineIcon sx={{ fontSize: "1.1rem" }} />
+ }
+ onClick={onRename}
+ disabled={editsDisabled}
+ title={editsDisabled ? editsDisabledHint : undefined}
+ >
+ {t("filesPage.rename", "Rename")}
+ </Menu.Item>
+ <Menu.Item
+ leftSection={<PaletteIcon sx={{ fontSize: "1.1rem" }} />}
+ onClick={() => setAppearanceOpen(true)}
+ disabled={editsDisabled}
+ title={editsDisabled ? editsDisabledHint : undefined}
+ >
+ {t("filesPage.appearance.edit", "Appearance…")}
+ </Menu.Item>
+ <Menu.Divider />
+ </>
+ )}
+ <ProcessingMenuItems
+ processing={processing}
+ continuous={continuous}
+ disabled={editsDisabled || Boolean(processingBlock)}
+ disabledHint={processingBlock ?? editsDisabledHint}
+ onRun={onRunProcessing}
+ onStop={onStopProcessing}
+ onStart={onStartProcessing}
+ onResume={onResumeProcessing}
+ onEdit={onEditProcessing}
+ onRemove={onRemoveProcessing}
+ onRevertAll={onRevertAll}
+ />
+ {(!isMount || canUnmount) && (
+ <>
+ <Menu.Divider />
+ <Menu.Item
+ color="red"
+ leftSection={<DeleteIcon sx={{ fontSize: "1.1rem" }} />}
+ onClick={onDelete}
+ disabled={editsDisabled}
+ title={editsDisabled ? editsDisabledHint : undefined}
+ >
+ {isMount
+ ? t("filesPage.removeLocalFolder", "Unmount from Stirling")
+ : t("filesPage.deleteFolder", "Delete folder")}
+ </Menu.Item>
+ </>
+ )}
+ </Menu.Dropdown>
+ </Menu>
+ <FolderAppearanceModal
+ folder={appearanceOpen ? folder : null}
+ onClose={() => setAppearanceOpen(false)}
+ onChange={onChangeAppearance}
+ disabled={editsDisabled}
+ />
+ </>
+ );
+}
+
+export default FolderMenu;
diff --git a/frontend/editor/src/core/components/filesPage/ProcessingMenuItems.tsx b/frontend/editor/src/core/components/filesPage/ProcessingMenuItems.tsx
new file mode 100644
index 0000000000..ed4d006692
--- /dev/null
+++ b/frontend/editor/src/core/components/filesPage/ProcessingMenuItems.tsx
@@ -0,0 +1,148 @@
+import { Menu } from "@mantine/core";
+import { useTranslation } from "react-i18next";
+import AutoModeIcon from "@mui/icons-material/AutoMode";
+import HistoryIcon from "@mui/icons-material/History";
+import PauseIcon from "@mui/icons-material/Pause";
+import PlayArrowIcon from "@mui/icons-material/PlayArrow";
+import ReplayIcon from "@mui/icons-material/Replay";
+import TuneIcon from "@mui/icons-material/Tune";
+
+import { ProcessingFolderState } from "@app/hooks/useProcessingFolders";
+
+/**
+ * The processing entries of a folder's action menu, carried by every folder kind
+ * including mounts, whose other edit actions are hidden.
+ */
+export function ProcessingMenuItems({
+ processing,
+ continuous = false,
+ disabled,
+ disabledHint,
+ onRun,
+ onStop,
+ onStart,
+ onResume,
+ onRemove,
+ onEdit,
+ onRevertAll,
+}: {
+ processing: ProcessingFolderState | undefined;
+ continuous?: boolean;
+ disabled: boolean;
+ disabledHint?: string;
+ onRun: () => void;
+ onStop: () => void;
+ onStart: () => void;
+ onResume: () => void;
+ onRemove: () => void;
+ /** Open the setup dialog seeded from the existing record; absent hides Edit. */
+ onEdit?: () => void;
+ /** Restore every archived original in the folder; absent hides the entry. */
+ onRevertAll?: () => void;
+}) {
+ const { t } = useTranslation();
+ const heading = (
+ <Menu.Label>{t("filesPage.processing.section", "Processing")}</Menu.Label>
+ );
+ if (!processing) {
+ return (
+ <>
+ {heading}
+ <Menu.Item
+ leftSection={<AutoModeIcon fontSize="small" />}
+ onClick={onStart}
+ disabled={disabled}
+ title={disabled ? disabledHint : undefined}
+ >
+ {t("filesPage.processing.start", "Process files in this folder...")}
+ </Menu.Item>
+ </>
+ );
+ }
+ if (!processing.enabled) {
+ // Paused, not gone: the pair kept its history, so resuming never re-runs
+ // what was already done. Removing is the destructive option, named as such.
+ return (
+ <>
+ {heading}
+ <Menu.Item
+ leftSection={<PlayArrowIcon fontSize="small" />}
+ onClick={onResume}
+ disabled={disabled}
+ title={disabled ? disabledHint : undefined}
+ >
+ {t("filesPage.processing.resume", "Resume processing")}
+ </Menu.Item>
+ {onEdit && (
+ <Menu.Item
+ leftSection={<TuneIcon fontSize="small" />}
+ onClick={onEdit}
+ disabled={disabled}
+ title={disabled ? disabledHint : undefined}
+ >
+ {t("filesPage.processing.edit", "Edit processing...")}
+ </Menu.Item>
+ )}
+ {onRevertAll && (
+ <Menu.Item
+ leftSection={<HistoryIcon fontSize="small" />}
+ onClick={onRevertAll}
+ disabled={disabled}
+ title={disabled ? disabledHint : undefined}
+ >
+ {t("filesPage.processing.restoreAll", "Restore all originals")}
+ </Menu.Item>
+ )}
+ <Menu.Item
+ color="red"
+ leftSection={<AutoModeIcon fontSize="small" />}
+ onClick={onRemove}
+ disabled={disabled}
+ title={disabled ? disabledHint : undefined}
+ >
+ {t("filesPage.processing.remove", "Remove processing")}
+ </Menu.Item>
+ </>
+ );
+ }
+ return (
+ <>
+ {heading}
+ {!continuous && (
+ <Menu.Item
+ leftSection={<ReplayIcon fontSize="small" />}
+ onClick={onRun}
+ >
+ {t("filesPage.processing.sweep", "Retry failed files")}
+ </Menu.Item>
+ )}
+ <Menu.Item leftSection={<PauseIcon fontSize="small" />} onClick={onStop}>
+ {t("filesPage.processing.stop", "Pause processing")}
+ </Menu.Item>
+ {onEdit && (
+ <Menu.Item leftSection={<TuneIcon fontSize="small" />} onClick={onEdit}>
+ {t("filesPage.processing.edit", "Edit processing...")}
+ </Menu.Item>
+ )}
+ {onRevertAll && (
+ <Menu.Item
+ leftSection={<HistoryIcon fontSize="small" />}
+ onClick={onRevertAll}
+ >
+ {t("filesPage.processing.restoreAll", "Restore all originals")}
+ </Menu.Item>
+ )}
+ {/* Offered while running too: detaching the folder from its pipeline
+ should not require pausing it first. */}
+ <Menu.Item
+ color="red"
+ leftSection={<AutoModeIcon fontSize="small" />}
+ onClick={onRemove}
+ disabled={disabled}
+ title={disabled ? disabledHint : undefined}
+ >
+ {t("filesPage.processing.remove", "Remove processing")}
+ </Menu.Item>
+ </>
+ );
+}
diff --git a/frontend/editor/src/core/components/filesPage/processingFolderCounts.test.tsx b/frontend/editor/src/core/components/filesPage/processingFolderCounts.test.tsx
index 5e2fac4f32..05a8f8ec9b 100644
--- a/frontend/editor/src/core/components/filesPage/processingFolderCounts.test.tsx
+++ b/frontend/editor/src/core/components/filesPage/processingFolderCounts.test.tsx
@@ -1,33 +1,64 @@
-import { act, render } from "@testing-library/react";
-import { describe, expect, it, vi } from "vitest";
+import { beforeEach, expect, test } from "vitest";
+import { render, screen, waitFor } from "@testing-library/react";
+import { useProcessingFolderCounts } from "@app/components/filesPage/processingFolderCounts";
+
+const COUNTS = '{"processing":1,"done":2}';
+
+let calls = 0;
+
+/** Stable identity, as the real call site's useCallback lister has. */
+const listFiles = async (): Promise<{ state: string }[]> => {
+ calls += 1;
+ return [{ state: "processing" }, { state: "done" }, { state: "done" }];
+};
+
+function Counts({ recordId, testId }: { recordId: string; testId: string }) {
+ const counts = useProcessingFolderCounts(recordId, listFiles);
+ return (
+ <span data-testid={testId}>{counts ? JSON.stringify(counts) : "-"}</span>
+ );
+}
+
+beforeEach(() => {
+ calls = 0;
+});
+
+test("reads the folder once and reports what it found", async () => {
+ render(<Counts recordId="rec-read" testId="only" />);
+
+ await waitFor(() =>
+ expect(screen.getByTestId("only")).toHaveTextContent(COUNTS),
+ );
+ expect(calls).toBe(1);
+});
+
+test("a second view of the same folder rides on the first one's request", async () => {
+ render(
+ <>
+ <Counts recordId="rec-shared" testId="card" />
+ <Counts recordId="rec-shared" testId="row" />
+ </>,
+ );
+
+ await waitFor(() =>
+ expect(screen.getByTestId("row")).toHaveTextContent(COUNTS),
+ );
+ expect(screen.getByTestId("card")).toHaveTextContent(COUNTS);
+ expect(calls).toBe(1);
+});
/**
- * The hook holds module-level state, so each case imports its own copy.
+ * The counts arriving re-renders every subscriber. When that re-render resubscribed -
+ * an inline subscribe closure is a new identity each time - the store dropped its last
+ * subscriber, cleared the numbers and read again, at the speed of the network.
*/
-async function loadHook() {
- vi.resetModules();
- return (await import("@app/components/filesPage/processingFolderCounts"))
- .useProcessingFolderCounts;
-}
+test("the render its own result causes does not start another read", async () => {
+ render(<Counts recordId="rec-loop" testId="loop" />);
+
+ await waitFor(() =>
+ expect(screen.getByTestId("loop")).toHaveTextContent(COUNTS),
+ );
+ await new Promise((resolve) => setTimeout(resolve, 200));
-describe("useProcessingFolderCounts", () => {
- it("reads once for a mounted folder, however many times it renders", async () => {
- const useProcessingFolderCounts = await loadHook();
- const listFiles = vi.fn(async () => [{ state: "done" }]);
-
- function Row() {
- const counts = useProcessingFolderCounts("folder-1", listFiles);
- return <span>{counts ? Object.keys(counts).join() : "none"}</span>;
- }
-
- render(<Row />);
- // Each settled read notifies subscribers, so a renewed subscription would
- // read again on the render that follows: several turns is enough to tell a
- // single read from a loop.
- for (let turn = 0; turn < 10; turn += 1) {
- await act(async () => {});
- }
-
- expect(listFiles).toHaveBeenCalledTimes(1);
- });
+ expect(calls).toBe(1);
});
diff --git a/frontend/editor/src/core/components/filesPage/processingFolderCounts.ts b/frontend/editor/src/core/components/filesPage/processingFolderCounts.ts
index 63bb208c89..b61c700797 100644
--- a/frontend/editor/src/core/components/filesPage/processingFolderCounts.ts
+++ b/frontend/editor/src/core/components/filesPage/processingFolderCounts.ts
@@ -8,16 +8,24 @@ const POLL_MS = 5000;
const counts = new Map<string, ProcessingCounts>();
const subscribers = new Map<string, Set<() => void>>();
+const inFlight = new Set<string>();
let timer: ReturnType<typeof setInterval> | null = null;
let lister: Lister | null = null;
async function read(recordId: string): Promise<void> {
- if (!lister) return;
- const files = await lister(recordId).catch(() => []);
- const next: ProcessingCounts = {};
- for (const file of files) next[file.state] = (next[file.state] ?? 0) + 1;
- counts.set(recordId, next);
- for (const notify of subscribers.get(recordId) ?? []) notify();
+ // One reading at a time per folder: a second subscriber, or a tick arriving
+ // while the last is still out, joins the request in flight.
+ if (!lister || inFlight.has(recordId)) return;
+ inFlight.add(recordId);
+ try {
+ const files = await lister(recordId).catch(() => []);
+ const next: ProcessingCounts = {};
+ for (const file of files) next[file.state] = (next[file.state] ?? 0) + 1;
+ counts.set(recordId, next);
+ for (const notify of subscribers.get(recordId) ?? []) notify();
+ } finally {
+ inFlight.delete(recordId);
+ }
}
/** One pass over every folder on screen, rather than one timer each. */
@@ -29,12 +37,14 @@ function subscribe(recordId: string, notify: () => void): () => void {
const forRecord = subscribers.get(recordId) ?? new Set<() => void>();
forRecord.add(notify);
subscribers.set(recordId, forRecord);
- void read(recordId);
+ // Only a folder with no numbers yet pays for a request on subscribe, so
+ // scrolling rows in and out cannot spray them.
+ if (!counts.has(recordId)) void read(recordId);
timer ??= setInterval(tick, POLL_MS);
return () => {
forRecord.delete(notify);
- // The numbers outlive the last subscriber, so a row the list windows out and
- // back paints what it had while the next read is in flight.
+ // The numbers outlive their last subscriber, so the snapshot never flips to
+ // null under a component that is still mounted.
if (forRecord.size === 0) subscribers.delete(recordId);
if (subscribers.size === 0 && timer) {
clearInterval(timer);
@@ -48,24 +58,23 @@ function subscribe(recordId: string, notify: () => void): () => void {
* shown as a card and as a row - or the same row remounted by the list's windowing -
* costs one request per interval rather than one per component.
*
- * One lister serves every subscriber, so callers must pass equivalent ones: the most
- * recent call's lister is the one the polling uses, for all records.
+ * `listFiles` must keep a stable identity across renders: React resubscribes
+ * whenever it changes, and every subscription opens with a request.
*/
export function useProcessingFolderCounts(
recordId: string,
listFiles: Lister,
): ProcessingCounts | null {
- lister = listFiles;
- // Both are held across renders: useSyncExternalStore resubscribes whenever the
- // subscribe function's identity changes, and resubscribing reads, which
- // notifies, which renders - a loop that never reaches the poll interval.
const subscribeToRecord = useCallback(
- (notify: () => void) => subscribe(recordId, notify),
- [recordId],
+ (notify: () => void) => {
+ lister = listFiles;
+ return subscribe(recordId, notify);
+ },
+ [recordId, listFiles],
);
- const readCounts = useCallback(
+ return useSyncExternalStore(
+ subscribeToRecord,
() => counts.get(recordId) ?? null,
- [recordId],
+ () => null,
);
- return useSyncExternalStore(subscribeToRecord, readCounts, () => null);
}
diff --git a/frontend/editor/src/core/contexts/FilesPageContext.tsx b/frontend/editor/src/core/contexts/FilesPageContext.tsx
index c1b82ff9d5..858bc101e0 100644
--- a/frontend/editor/src/core/contexts/FilesPageContext.tsx
+++ b/frontend/editor/src/core/contexts/FilesPageContext.tsx
@@ -79,7 +79,8 @@ const VIEW_MODE_STORAGE_KEY = "stirling.filesPageViewMode";
/**
* The list is the default: it shows more files per screen and carries the columns the
- * grid has no room for.
+ * grid has no room for. The grid is one click away, and the choice is the user's from
+ * then on.
*/
function readPersistedViewMode(): FilesPageViewMode {
try {
diff --git a/frontend/editor/src/core/pages/HomePage.tsx b/frontend/editor/src/core/pages/HomePage.tsx
index 62230b0fc1..e4fe7073d7 100644
--- a/frontend/editor/src/core/pages/HomePage.tsx
+++ b/frontend/editor/src/core/pages/HomePage.tsx
@@ -849,7 +849,7 @@ const MyFilesSidebarOverrides = forwardRef<HTMLDivElement, FileSidebarProps>(
className={refreshing ? "file-sidebar-spin" : undefined}
/>
),
- label: t("filesPage.refresh", "Refresh from server"),
+ label: t("filesPage.refresh", "Refresh"),
onClick: () => void refreshLibrary(),
disabled: refreshing || signInRequired !== null,
disabledTooltip: signInRequired ?? undefined,
diff --git a/frontend/editor/src/core/tests/helpers/stub-test-base.ts b/frontend/editor/src/core/tests/helpers/stub-test-base.ts
index 7c9afc163e..0affaea4fb 100644
--- a/frontend/editor/src/core/tests/helpers/stub-test-base.ts
+++ b/frontend/editor/src/core/tests/helpers/stub-test-base.ts
@@ -79,6 +79,11 @@ export const test = base.extend<StubFixtures>({
localStorage.setItem("stirling.filesPageViewMode", mode);
}, filesViewMode);
}
+ if (filesViewMode) {
+ await page.addInitScript((mode) => {
+ localStorage.setItem("stirling.filesPageViewMode", mode);
+ }, filesViewMode);
+ }
await mockAppApis(page, stubOptions);
if (autoGoto !== false) {
// waitUntil: 'domcontentloaded' avoids hanging on third-party CDN
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 f322b47a51..67a874e7b3 100644
--- a/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
@@ -1,5 +1,5 @@
import { test, expect } from "@app/tests/helpers/stub-test-base";
-import type { Page, Route } from "@playwright/test";
+import type { Locator, Page, Route } from "@playwright/test";
import { DATABASE_CONFIGS } from "@app/services/indexedDBManager";
/** Stubbed coverage for the /files page UI invariants. */
@@ -166,6 +166,20 @@ async function stubStorageApis(
);
}
+/** Open a menu and return the named item from that menu's own dropdown.
+ * Dropdowns stay mounted once opened, so a page-wide role query matches every
+ * menu that has been opened, not the one just clicked. */
+async function openMenuItem(
+ page: Page,
+ trigger: Locator,
+ name: RegExp,
+): Promise<Locator> {
+ await trigger.click();
+ const id = await trigger.getAttribute("aria-controls");
+ const dropdown = id ? page.locator(`#${id}`) : page.locator("body");
+ return dropdown.getByRole("menuitem", { name });
+}
+
/** Navigate to /files and wait for at least one real (non-skeleton) card.
* `.files-page-card` also matches the loading-state skeleton placeholders, and
* their parent grid carries `aria-busy="true"` which intercepts pointer events
@@ -247,18 +261,6 @@ test.describe("Files page", () => {
page.locator(".files-page-card-selector").first(),
).toBeVisible();
});
-
- test("Select all tooltip explains Ctrl/Shift shortcuts", async ({
- page,
- }) => {
- await gotoFilesPage(page);
- // Tooltip is the discovery point for Ctrl/Shift multi-select.
- const selectAll = page.getByRole("button", { name: /^Select all$/i });
- await selectAll.hover();
- await expect(
- page.getByText(/hold Ctrl.*Cmd.*Shift to select a range/i),
- ).toBeVisible({ timeout: 3_000 });
- });
});
test.describe("Bulk action button visibility", () => {
@@ -288,16 +290,30 @@ test.describe("Files page", () => {
.locator(".files-page-card:not(.is-folder)")
.filter({ hasText: "local-a.pdf" })
.click();
+ // Neither copy is a plain button: the selection's lives behind the
+ // Actions menu, the details panel's behind its own overflow menu. Both
+ // dropdowns stay mounted once opened, so each is read through the id its
+ // own trigger controls.
await expect(
page.getByRole("button", { name: /^Save to server$/i }),
+ ).toHaveCount(0);
+ await expect(
+ await openMenuItem(
+ page,
+ page.locator(
+ ".files-page-selection-actions .files-page-toolbar-bulk-trigger",
+ ),
+ /^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("menuitem", { name: /^Save to server$/i }),
+ await openMenuItem(
+ page,
+ page
+ .locator(".files-page-details-actions-row")
+ .getByRole("button", { name: /^Actions$/i }),
+ /^Save to server$/i,
+ ),
).toBeVisible();
});
@@ -364,19 +380,23 @@ test.describe("Files page", () => {
.locator(".files-page-card:not(.is-folder)")
.filter({ hasText: "local-a.pdf" })
.click();
- const toolbarSave = page.getByRole("button", {
- name: /^Save to server$/i,
- });
- await expect(toolbarSave).toBeVisible();
- await expect(toolbarSave).toBeDisabled();
+ const selectionSave = await openMenuItem(
+ page,
+ page.locator(
+ ".files-page-selection-actions .files-page-toolbar-bulk-trigger",
+ ),
+ /^Save to server$/i,
+ );
+ await expect(selectionSave).toBeVisible();
+ await expect(selectionSave).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,
- });
+ const panelSave = await openMenuItem(
+ page,
+ page
+ .locator(".files-page-details-actions-row")
+ .getByRole("button", { name: /^Actions$/i }),
+ /^Save to server$/i,
+ );
await expect(panelSave).toBeVisible();
await expect(panelSave).toBeDisabled();
});
@@ -819,102 +839,6 @@ test.describe("Files page", () => {
.filter({ hasText: "cross-browser.pdf" }),
).toBeVisible({ timeout: 5_000 });
});
-
- test("Shared-by-me tab lists only files I own with share links", async ({
- page,
- }) => {
- await stubStorageApis(page, { sharingEnabled: true });
- // Three server files: one shared via link (owned by me), one shared
- // with users (owned by me), one plain mine, and one owned by someone else.
- await page.route("**/api/v1/storage/files", (route: Route) =>
- route.fulfill({
- json: [
- {
- id: 1,
- fileName: "link-shared.pdf",
- contentType: "application/pdf",
- sizeBytes: 100,
- createdAt: new Date().toISOString(),
- owner: "admin",
- ownedByCurrentUser: true,
- accessRole: "owner",
- shareLinks: [{ token: "tok1" }],
- sharedUsers: [],
- filePurpose: "generic",
- folderId: null,
- },
- {
- id: 2,
- fileName: "user-shared.pdf",
- contentType: "application/pdf",
- sizeBytes: 100,
- createdAt: new Date().toISOString(),
- owner: "admin",
- ownedByCurrentUser: true,
- accessRole: "owner",
- shareLinks: [],
- sharedUsers: [{ username: "bob" }],
- filePurpose: "generic",
- folderId: null,
- },
- {
- id: 3,
- fileName: "plain-mine.pdf",
- contentType: "application/pdf",
- sizeBytes: 100,
- createdAt: new Date().toISOString(),
- owner: "admin",
- ownedByCurrentUser: true,
- accessRole: "owner",
- shareLinks: [],
- sharedUsers: [],
- filePurpose: "generic",
- folderId: null,
- },
- {
- id: 4,
- fileName: "from-someone-else.pdf",
- contentType: "application/pdf",
- sizeBytes: 100,
- createdAt: new Date().toISOString(),
- owner: "alice",
- ownedByCurrentUser: false,
- accessRole: "viewer",
- shareLinks: [],
- sharedUsers: [],
- filePurpose: "generic",
- folderId: null,
- },
- ],
- }),
- );
- await page.goto("/files", { waitUntil: "domcontentloaded" });
- // Wait for the 4 cards to land via server sync.
- await expect(
- page.locator(".files-page-card:not(.is-folder)"),
- ).toHaveCount(4, { timeout: 5_000 });
-
- // "Shared by me" -> link-shared.pdf AND user-shared.pdf
- // (The previously-separate "Shared by me" / "I'm sharing" tabs are now
- // merged into a single Shared-by-me view that shows both link shares
- // and direct user shares.)
- await page.locator("#filesPage-tab-sharedByMe").click();
- const sharedByMeCards = page.locator(".files-page-card:not(.is-folder)");
- await expect(sharedByMeCards).toHaveCount(2, { timeout: 5_000 });
- for (const name of ["link-shared.pdf", "user-shared.pdf"]) {
- await expect(sharedByMeCards.filter({ hasText: name })).toHaveCount(1);
- }
-
- // "Shared with me" -> only from-someone-else.pdf
- await page.locator("#filesPage-tab-shared").click();
- const sharedWithMeCards = page.locator(
- ".files-page-card:not(.is-folder)",
- );
- await expect(sharedWithMeCards).toHaveCount(1, { timeout: 3_000 });
- await expect(sharedWithMeCards.first()).toContainText(
- "from-someone-else.pdf",
- );
- });
});
test.describe("Folder chrome stability", () => {
@@ -1094,12 +1018,40 @@ test.describe("Files page", () => {
});
});
+ test.describe("Selection chrome", () => {
+ test.use({ autoGoto: false, filesViewMode: null });
+
+ /** Guards the bug that put selection actions in their own row: a toolbar
+ * that wraps on selection moves every row down, and the second click of a
+ * double-click lands on the wrong file. */
+ test("selecting files does not move the listing", async ({ page }) => {
+ await stubStorageApis(page);
+ await seedFiles(page, [
+ { id: "s-1", name: "alpha.pdf", remoteStorageId: null },
+ { id: "s-2", name: "beta.pdf", remoteStorageId: null },
+ { id: "s-3", name: "gamma.pdf", remoteStorageId: null },
+ ]);
+ await page.goto("/files", { waitUntil: "domcontentloaded" });
+
+ const rows = page.locator(".files-page-list-row:not(.is-header)");
+ await expect(rows.first()).toBeVisible({ timeout: 15_000 });
+ const topOf = async () =>
+ (await rows.first().boundingBox())?.y ?? Number.NaN;
+
+ const before = await topOf();
+ await rows.nth(0).click();
+ await rows.nth(1).click({ modifiers: ["ControlOrMeta"] });
+ await expect(page.locator(".files-page-list-selection-count")).toHaveText(
+ /2 selected/i,
+ );
+ expect(await topOf()).toBeCloseTo(before, 0);
+ });
+ });
+
test.describe("Library chrome placement", () => {
test.use({ autoGoto: false });
- /** The path sits on the library's own row with the tabs; its actions live in the
- * file sidebar, and the shared bar above carries only what every view has. */
- test("the path is on the tabs row and the actions are in the sidebar", async ({
+ test("the path is on the library row and the actions are in the sidebar", async ({
page,
}) => {
const NESTED = "11111111-2222-4333-8444-555555555581";