Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+321
-176
@@ -4,17 +4,26 @@
|
||||
// no server imports. The final Subframe optics land as a tracked design-nachzug once
|
||||
// David's D-P4 delta ships; this interim screen keeps the VM/loader boundary stable.
|
||||
|
||||
import { type FormEvent, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherDownload, FeatherFile, FeatherGrid, FeatherList, FeatherUpload } from "@subframe/core";
|
||||
import { fileTypeLabelKey } from "~/utils/files/fileTypeLabel";
|
||||
import { FeatherDownload, FeatherFile, FeatherFileText, FeatherGrid, FeatherLink, FeatherList, FeatherTag, FeatherUpload, FeatherUser } from "@subframe/core";
|
||||
import type { FileBrowserRow, FileBrowserVM, FilePreviewStatus, FileScanStatus, FileViewMode } from "@hivegrid/view-models";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
||||
import { FacetFilterBar, type ClientFacet } from "../shared/FacetFilterBar";
|
||||
import { FileUploadDialog } from "./FileUploadDialog";
|
||||
import type { FileUploadDisplayItem } from "./FileUploadPage";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { ToggleGroup } from "~/ui/components/ToggleGroup";
|
||||
import { APP_TIME_ZONE } from "~/locale/format";
|
||||
import { useLiveFilter } from "~/hooks/use-live-filter";
|
||||
import { useSaveToast, type SaveActionResult } from "~/hooks/use-save-toast";
|
||||
import { AppLink } from "~/components/app/AppLink";
|
||||
|
||||
export type FilesBrowserQuery = {
|
||||
mimeGroup: string | null;
|
||||
@@ -22,23 +31,40 @@ export type FilesBrowserQuery = {
|
||||
tag: string | null;
|
||||
assignedToUserId: string | null;
|
||||
includeArchived: boolean;
|
||||
/** Free-text search over the file name. */
|
||||
q: string;
|
||||
viewMode: FileViewMode;
|
||||
};
|
||||
|
||||
export type FilesBrowserActions = {
|
||||
/** Navigate (GET) to the same route with the given filter/view state. */
|
||||
onApply: (query: FilesBrowserQuery) => void;
|
||||
/** Navigate (GET) to another page of the current result set. */
|
||||
onGoToPage: (query: FilesBrowserQuery, page: number) => void;
|
||||
/** Toggle a single row in the bulk selection. */
|
||||
onToggleSelect: (id: string) => void;
|
||||
/** Select or clear all currently-listed rows. */
|
||||
onToggleSelectAll: (ids: readonly string[], selectAll: boolean) => void;
|
||||
};
|
||||
|
||||
export type FilesBrowserUpload = {
|
||||
/** Queue of the open dialog session. */
|
||||
items: readonly FileUploadDisplayItem[];
|
||||
/** Hand picked/dropped files to the route's chunked upload pipeline. */
|
||||
onFiles: (files: FileList | null) => void;
|
||||
/** True while at least one file is still on its way. */
|
||||
uploading: boolean;
|
||||
/** Clear the queue when the dialog closes. */
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export type FilesBrowserPageProps = {
|
||||
vm: FileBrowserVM;
|
||||
uploadHref: string;
|
||||
/** Href for the next cursor page, or null on the last page. */
|
||||
nextHref: string | null;
|
||||
/**
|
||||
* Upload pipeline of the route. Absent for a reader — without it the header
|
||||
* shows no upload button, because there would be nothing behind it.
|
||||
*/
|
||||
upload?: FilesBrowserUpload;
|
||||
/** Absolute action URL the bulk-ZIP form POSTs to. */
|
||||
bulkZipAction: string;
|
||||
/** Currently selected row ids (for the bulk-ZIP download). */
|
||||
@@ -46,10 +72,8 @@ export type FilesBrowserPageProps = {
|
||||
actions: FilesBrowserActions;
|
||||
};
|
||||
|
||||
const MIME_ALL = "all";
|
||||
// Shared "no filter" sentinel for the entity/tag/assignee Selects (empty string
|
||||
// is not a valid Select value, so a non-empty sentinel maps back to null).
|
||||
const FILTER_ALL = "__all__";
|
||||
/** Mime groups the server knows how to filter on. */
|
||||
const MIME_GROUPS = ["image", "pdf", "text"] as const;
|
||||
|
||||
type StatusBadge = { farbe: "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral"; key: string };
|
||||
|
||||
@@ -87,171 +111,293 @@ function formatBytes(bytes: number): string {
|
||||
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
export function FilesBrowserPage({ vm, uploadHref, nextHref, bulkZipAction, selectedIds, actions }: FilesBrowserPageProps) {
|
||||
export function FilesBrowserPage({ vm, upload, bulkZipAction, selectedIds, actions }: FilesBrowserPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [uploadOpen, setUploadOpen] = useState(false);
|
||||
const [downloadingZip, setDownloadingZip] = useState(false);
|
||||
const [downloadError, setDownloadError] = useState<SaveActionResult>();
|
||||
useSaveToast(downloadError);
|
||||
// Local search buffer, live-committed to the route (GET) debounced — the same
|
||||
// behaviour the board filter bar has.
|
||||
const data = vm.status === "ready" ? vm.data : null;
|
||||
const searchFromVm = data?.filter.q ?? "";
|
||||
const [search, setSearch] = useState(searchFromVm);
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.browser" />;
|
||||
/** Current query with one part replaced — the shape every control reports. */
|
||||
function currentQuery(patch: Partial<FilesBrowserQuery> = {}): FilesBrowserQuery {
|
||||
return {
|
||||
mimeGroup: data?.filter.mimeGroup ?? null,
|
||||
entityType: data?.filter.entityType ?? null,
|
||||
tag: data?.filter.tags[0] ?? null,
|
||||
assignedToUserId: data?.filter.assignedToUserId ?? null,
|
||||
includeArchived: data?.filter.includeArchived ?? false,
|
||||
q: searchFromVm,
|
||||
viewMode: data?.viewMode ?? "table",
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
const { rows, viewMode, filter, filterOptions, canWrite } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
|
||||
function applyPatch(patch: Partial<FilesBrowserQuery>) {
|
||||
actions.onApply(currentQuery(patch));
|
||||
}
|
||||
|
||||
useLiveFilter(search.trim(), searchFromVm.trim(), () => applyPatch({ q: search.trim() }));
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (!data) {
|
||||
return (
|
||||
<PageShell uiId="ui.files.browser">
|
||||
<PageHeader icon={<FeatherFileText className={PAGE_HEADER_ICON_CLASS} />} title={t("files.browser.title")} subtitle={t("files.browser.subtitle")} />
|
||||
<PageBody>{null}</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
const { rows, viewMode, filter, filterOptions, canWrite, pagination } = data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium" });
|
||||
|
||||
// Single-select facets on a multi-select control: picking the active option
|
||||
// again clears it, which is what the chip's X does too.
|
||||
function toggleFacet(facetKey: string, value: string) {
|
||||
switch (facetKey) {
|
||||
case "mime":
|
||||
return applyPatch({ mimeGroup: filter.mimeGroup === value ? null : value });
|
||||
case "entity":
|
||||
return applyPatch({ entityType: filter.entityType === value ? null : value });
|
||||
case "tag":
|
||||
return applyPatch({ tag: filter.tags[0] === value ? null : value });
|
||||
case "assignee":
|
||||
return applyPatch({ assignedToUserId: filter.assignedToUserId === value ? null : value });
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
setSearch("");
|
||||
actions.onApply({
|
||||
mimeGroup: filter.mimeGroup,
|
||||
entityType: filter.entityType,
|
||||
tag: filter.tags[0] ?? null,
|
||||
assignedToUserId: filter.assignedToUserId,
|
||||
includeArchived: filter.includeArchived,
|
||||
mimeGroup: null,
|
||||
entityType: null,
|
||||
tag: null,
|
||||
assignedToUserId: null,
|
||||
includeArchived: false,
|
||||
q: "",
|
||||
viewMode,
|
||||
...patch,
|
||||
});
|
||||
}
|
||||
|
||||
async function downloadZip(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setDownloadingZip(true);
|
||||
try {
|
||||
const response = await fetch(bulkZipAction, {
|
||||
method: "POST",
|
||||
body: new FormData(event.currentTarget),
|
||||
});
|
||||
if (!response.ok) throw new Error("bulk zip failed");
|
||||
|
||||
const href = URL.createObjectURL(await response.blob());
|
||||
const link = document.createElement("a");
|
||||
link.href = href;
|
||||
link.download = "dateien.zip";
|
||||
link.click();
|
||||
window.setTimeout(() => URL.revokeObjectURL(href), 0);
|
||||
} catch {
|
||||
setDownloadError({
|
||||
intent: "bulk-zip",
|
||||
error: "files.browser.bulk.downloadError",
|
||||
});
|
||||
} finally {
|
||||
setDownloadingZip(false);
|
||||
}
|
||||
}
|
||||
|
||||
const allFacets: ClientFacet[] = [
|
||||
{
|
||||
key: "mime",
|
||||
label: t("files.browser.filter.mime.label"),
|
||||
icon: <FeatherFile />,
|
||||
tone: "blue-subtle",
|
||||
options: MIME_GROUPS.map((group) => ({ value: group, label: t(`files.browser.filter.mime.${group}`) })),
|
||||
selected: new Set(filter.mimeGroup ? [filter.mimeGroup] : []),
|
||||
},
|
||||
{
|
||||
key: "entity",
|
||||
label: t("files.browser.filter.entity.label"),
|
||||
icon: <FeatherLink />,
|
||||
tone: "violet-subtle",
|
||||
options: filterOptions.entityTypes.map((type) => ({
|
||||
value: type,
|
||||
label: t(`files.entityType.${type}`, { defaultValue: t("files.entityType.unknown") }),
|
||||
})),
|
||||
selected: new Set(filter.entityType ? [filter.entityType] : []),
|
||||
},
|
||||
{
|
||||
key: "tag",
|
||||
label: t("files.browser.filter.tag.label"),
|
||||
icon: <FeatherTag />,
|
||||
tone: "neutral-subtle",
|
||||
options: filterOptions.tags.map((tag) => ({ value: tag, label: tag })),
|
||||
selected: new Set(filter.tags),
|
||||
},
|
||||
{
|
||||
key: "assignee",
|
||||
label: t("files.browser.filter.assignee.label"),
|
||||
icon: <FeatherUser />,
|
||||
tone: "sky-subtle",
|
||||
options: filterOptions.assignees.map((assignee) => ({ value: assignee.id, label: assignee.name })),
|
||||
selected: new Set(filter.assignedToUserId ? [filter.assignedToUserId] : []),
|
||||
},
|
||||
];
|
||||
// A facet with nothing to pick is a dead button; the tenant may simply have
|
||||
// no tags or no linked entities yet.
|
||||
const facets = allFacets.filter((facet) => facet.options.length > 0);
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.browser">
|
||||
{/* Header: title + subtitle (0px rhythm), view toggle + upload CTA */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("files.browser.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("files.browser.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<ToggleGroup
|
||||
value={viewMode}
|
||||
onValueChange={(value: string) => {
|
||||
if (value === "table" || value === "grid") applyPatch({ viewMode: value });
|
||||
}}
|
||||
<PageShell uiId="ui.files.browser">
|
||||
<PageHeader
|
||||
icon={<FeatherFileText className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("files.browser.title")}
|
||||
subtitle={t("files.browser.subtitle")}
|
||||
actions={
|
||||
<>
|
||||
<ToggleGroup
|
||||
value={viewMode}
|
||||
onValueChange={(value: string) => {
|
||||
if (value === "table" || value === "grid") applyPatch({ viewMode: value });
|
||||
}}
|
||||
>
|
||||
<ToggleGroup.Item icon={<FeatherList />} value="table" aria-label={t("files.browser.viewMode.table")}>
|
||||
{t("files.browser.viewMode.table")}
|
||||
</ToggleGroup.Item>
|
||||
<ToggleGroup.Item icon={<FeatherGrid />} value="grid" aria-label={t("files.browser.viewMode.grid")}>
|
||||
{t("files.browser.viewMode.grid")}
|
||||
</ToggleGroup.Item>
|
||||
</ToggleGroup>
|
||||
{canWrite && upload ? (
|
||||
<Button icon={<FeatherUpload />} onClick={() => setUploadOpen(true)} data-ui-id="ui.files.browser.upload">
|
||||
{t("files.browser.actions.upload")}
|
||||
</Button>
|
||||
) : null}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
{/* --- Filter bar: search box + facet dropdowns, the same strip the
|
||||
boards use, so a filter looks and behaves the same on both screens. --- */}
|
||||
<FacetFilterBar
|
||||
facets={facets}
|
||||
onToggle={toggleFacet}
|
||||
search={search}
|
||||
onSearchChange={setSearch}
|
||||
searchPlaceholder={t("files.browser.filter.searchPlaceholder")}
|
||||
onReset={resetFilters}
|
||||
labels={{ reset: t("files.browser.filter.reset"), removeChip: t("files.browser.filter.removeChip") }}
|
||||
uiId="ui.files.browser.filter"
|
||||
trailing={
|
||||
<Checkbox
|
||||
label={t("files.browser.filter.archived")}
|
||||
checked={filter.includeArchived}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeArchived: checked })}
|
||||
data-ui-id="ui.files.browser.filter.archived"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
{/* Filter bar (server-side, navigation on change) */}
|
||||
|
||||
{rows.length > 0 && viewMode === "table" && selectedIds.length > 0 ? (
|
||||
<form
|
||||
method="post"
|
||||
action={bulkZipAction}
|
||||
onSubmit={downloadZip}
|
||||
className="border-border-default bg-surface-neutral-secondary flex flex-wrap items-center gap-3 rounded-md border border-solid px-4 py-3"
|
||||
data-ui-id="ui.files.browser.bulkbar"
|
||||
>
|
||||
<ToggleGroup.Item icon={<FeatherList />} value="table" aria-label={t("files.browser.viewMode.table")}>
|
||||
{t("files.browser.viewMode.table")}
|
||||
</ToggleGroup.Item>
|
||||
<ToggleGroup.Item icon={<FeatherGrid />} value="grid" aria-label={t("files.browser.viewMode.grid")}>
|
||||
{t("files.browser.viewMode.grid")}
|
||||
</ToggleGroup.Item>
|
||||
</ToggleGroup>
|
||||
{canWrite ? (
|
||||
<a href={uploadHref} className="no-underline" data-ui-id="ui.files.browser.upload">
|
||||
<Button icon={<FeatherUpload />}>{t("files.browser.actions.upload")}</Button>
|
||||
</a>
|
||||
{selectedIds.map((id) => (
|
||||
<input key={id} type="hidden" name="fileIds" value={id} />
|
||||
))}
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("files.browser.bulk.selected", { count: selectedIds.length })}
|
||||
</span>
|
||||
<Button type="submit" variant="secondary" icon={<FeatherDownload />} disabled={downloadingZip}>
|
||||
{t("files.browser.bulk.downloadZip")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<EmptyBrowser
|
||||
canWrite={canWrite && Boolean(upload)}
|
||||
onUpload={() => setUploadOpen(true)}
|
||||
headlineKey={data.emptyHeadlineKey}
|
||||
bodyKey={data.emptyBodyKey}
|
||||
/>
|
||||
) : viewMode === "grid" ? (
|
||||
<GridView rows={rows} />
|
||||
) : (
|
||||
<TableView
|
||||
rows={rows}
|
||||
dateFormatter={dateFormatter}
|
||||
selectedIds={selectedIds}
|
||||
onToggleSelect={actions.onToggleSelect}
|
||||
onToggleSelectAll={actions.onToggleSelectAll}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Page footer: how many files there are, which page of how many, and
|
||||
the way in both directions — in both views, since paging is a
|
||||
property of the result set, not of how it is drawn. */}
|
||||
<div className="flex w-full items-center justify-between gap-2" data-ui-id="ui.files.browser.pagination">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t("files.browser.pagination.total", { count: pagination.total })}
|
||||
</span>
|
||||
{rows.length > 0 ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="neutral"
|
||||
size="small"
|
||||
disabled={!pagination.hasPrevious}
|
||||
onClick={() => actions.onGoToPage(currentQuery(), pagination.page - 1)}
|
||||
data-ui-id="ui.files.browser.pagination.prev"
|
||||
>
|
||||
{t("files.browser.pagination.previous")}
|
||||
</Button>
|
||||
<span
|
||||
className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary"
|
||||
data-ui-id="ui.files.browser.pagination.position"
|
||||
>
|
||||
{t("files.browser.pagination.position", { page: pagination.page, pageCount: pagination.pageCount })}
|
||||
</span>
|
||||
<Button
|
||||
variant="neutral"
|
||||
size="small"
|
||||
disabled={!pagination.hasNext}
|
||||
onClick={() => actions.onGoToPage(currentQuery(), pagination.page + 1)}
|
||||
data-ui-id="ui.files.browser.pagination.next"
|
||||
>
|
||||
{t("files.browser.pagination.next")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
|
||||
{/* Filter bar (server-side, navigation on change) */}
|
||||
<div className="flex flex-wrap items-center gap-4" data-ui-id="ui.files.browser.filter">
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.mime.label")}
|
||||
showLabel
|
||||
value={filter.mimeGroup ?? MIME_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ mimeGroup: value === MIME_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={MIME_ALL}>{t("files.browser.filter.mime.all")}</Select.Item>
|
||||
<Select.Item value="image">{t("files.browser.filter.mime.image")}</Select.Item>
|
||||
<Select.Item value="pdf">{t("files.browser.filter.mime.pdf")}</Select.Item>
|
||||
<Select.Item value="text">{t("files.browser.filter.mime.text")}</Select.Item>
|
||||
</Select>
|
||||
{filterOptions.entityTypes.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.entity.label")}
|
||||
showLabel
|
||||
value={filter.entityType ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ entityType: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.entity.all")}</Select.Item>
|
||||
{filterOptions.entityTypes.map((type) => (
|
||||
<Select.Item key={type} value={type}>
|
||||
{t(`files.entityType.${type}`, { defaultValue: type })}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
{filterOptions.tags.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.tag.label")}
|
||||
showLabel
|
||||
value={filter.tags[0] ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ tag: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.tag.all")}</Select.Item>
|
||||
{filterOptions.tags.map((tag) => (
|
||||
<Select.Item key={tag} value={tag}>
|
||||
{tag}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
{filterOptions.assignees.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.assignee.label")}
|
||||
showLabel
|
||||
value={filter.assignedToUserId ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ assignedToUserId: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.assignee.all")}</Select.Item>
|
||||
{filterOptions.assignees.map((assignee) => (
|
||||
<Select.Item key={assignee.id} value={assignee.id}>
|
||||
{assignee.name}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
<Checkbox
|
||||
label={t("files.browser.filter.archived")}
|
||||
checked={filter.includeArchived}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeArchived: checked })}
|
||||
{/* Uploading stays on this page: the browser is where the new file is
|
||||
expected to appear, and a separate upload route took the reader away
|
||||
from it. */}
|
||||
{upload ? (
|
||||
<FileUploadDialog
|
||||
open={uploadOpen}
|
||||
onOpenChange={(open) => {
|
||||
setUploadOpen(open);
|
||||
if (!open) upload.onClose();
|
||||
}}
|
||||
items={upload.items}
|
||||
onFiles={upload.onFiles}
|
||||
uploading={upload.uploading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{rows.length > 0 && viewMode === "table" && selectedIds.length > 0 ? (
|
||||
<form
|
||||
method="post"
|
||||
action={bulkZipAction}
|
||||
className="flex flex-wrap items-center gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-3"
|
||||
data-ui-id="ui.files.browser.bulkbar"
|
||||
>
|
||||
{selectedIds.map((id) => (
|
||||
<input key={id} type="hidden" name="fileIds" value={id} />
|
||||
))}
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("files.browser.bulk.selected", { count: selectedIds.length })}
|
||||
</span>
|
||||
<Button type="submit" variant="secondary" icon={<FeatherDownload />}>
|
||||
{t("files.browser.bulk.downloadZip")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<EmptyBrowser canWrite={canWrite} uploadHref={uploadHref} vm={vm} />
|
||||
) : viewMode === "grid" ? (
|
||||
<GridView rows={rows} />
|
||||
) : (
|
||||
<TableView
|
||||
rows={rows}
|
||||
dateFormatter={dateFormatter}
|
||||
selectedIds={selectedIds}
|
||||
onToggleSelect={actions.onToggleSelect}
|
||||
onToggleSelectAll={actions.onToggleSelectAll}
|
||||
/>
|
||||
)}
|
||||
|
||||
{nextHref ? (
|
||||
<div className="flex justify-center pt-2" data-ui-id="ui.files.browser.pagination">
|
||||
<a href={nextHref} className="no-underline">
|
||||
<Button variant="tertiary">{t("files.browser.pagination.next")}</Button>
|
||||
</a>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -327,19 +473,17 @@ function TableView({
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<Checkbox
|
||||
aria-label={t("files.browser.select.row")}
|
||||
checked={selectedSet.has(row.id)}
|
||||
onCheckedChange={() => onToggleSelect(row.id)}
|
||||
/>
|
||||
<Checkbox aria-label={t("files.browser.select.row")} checked={selectedSet.has(row.id)} onCheckedChange={() => onToggleSelect(row.id)} />
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<a href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
<AppLink href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
{row.displayName}
|
||||
</a>
|
||||
</AppLink>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{row.mimeType}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary" title={row.mimeType}>
|
||||
{t(fileTypeLabelKey(row.mimeType))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{formatBytes(row.sizeBytes)}</span>
|
||||
@@ -366,9 +510,9 @@ function GridView({ rows }: { rows: readonly FileBrowserRow[] }) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4" data-ui-id="ui.files.browser.grid">
|
||||
{rows.map((row) => (
|
||||
<a key={row.id} href={row.detailHref} className="no-underline" data-row-id={row.id}>
|
||||
<AppLink key={row.id} href={row.detailHref} className="no-underline" data-row-id={row.id}>
|
||||
<Card>
|
||||
<div className="flex h-32 w-full items-center justify-center overflow-hidden rounded-md bg-surface-neutral-tertiary">
|
||||
<div className="bg-surface-neutral-tertiary flex h-32 w-full items-center justify-center overflow-hidden rounded-md">
|
||||
{row.thumbnailUrl ? (
|
||||
<img src={row.thumbnailUrl} alt={row.displayName} className="h-full w-full object-cover" />
|
||||
) : (
|
||||
@@ -376,32 +520,33 @@ function GridView({ rows }: { rows: readonly FileBrowserRow[] }) {
|
||||
)}
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
<span className="line-clamp-1 text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.displayName}</span>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary line-clamp-1">{row.displayName}</span>
|
||||
<StatusBadges row={row} />
|
||||
<RowTags tags={row.tags} />
|
||||
</div>
|
||||
</Card>
|
||||
</a>
|
||||
</AppLink>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EmptyBrowser({ canWrite, uploadHref, vm }: { canWrite: boolean; uploadHref: string; vm: Extract<FileBrowserVM, { status: "ready" }> }) {
|
||||
function EmptyBrowser({ canWrite, onUpload, headlineKey, bodyKey }: { canWrite: boolean; onUpload: () => void; headlineKey: string; bodyKey: string }) {
|
||||
const { t } = useTranslation();
|
||||
const headlineKey = vm.data.emptyHeadlineKey;
|
||||
const bodyKey = vm.data.emptyBodyKey;
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-6 py-16 text-center" data-ui-id="ui.files.browser.empty">
|
||||
<div
|
||||
className="border-border-default bg-surface-neutral-primary flex flex-col items-center gap-4 rounded-md border border-solid px-6 py-16 text-center"
|
||||
data-ui-id="ui.files.browser.empty"
|
||||
>
|
||||
<FeatherFile className="text-heading-1 font-heading-1 text-icon-neutral-tertiary" />
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{t(headlineKey)}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t(bodyKey)}</span>
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<a href={uploadHref} className="no-underline">
|
||||
<Button icon={<FeatherUpload />}>{t("files.browser.actions.upload")}</Button>
|
||||
</a>
|
||||
<Button icon={<FeatherUpload />} onClick={onUpload} data-ui-id="ui.files.browser.empty.upload">
|
||||
{t("files.browser.actions.upload")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user