@arbidocs/blocks 0.5.152 → 0.5.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  /**
2
- * `TableViewBlock`: a page's table block. It shows one saved table view of a database: the database's
3
- * rows read with the view applied on the server (`?view=`: its filters and sort), in the view's
4
- * columns, through the database grid (`DatabaseTable`) in read mode. Only what the viewer can read:
5
- * a view they cannot see (someone else's private one, or deleted) says so instead.
2
+ * `TableViewBlock`: a page's table block. It shows one saved table view of a database: the view,
3
+ * its database's columns and its rows read in one request with the view applied on the server
4
+ * (`useTableViewRows`: its filters, sort and columns), through the database grid (`DatabaseTable`)
5
+ * in read mode. Only what the viewer can read: a view they cannot see (someone else's private one,
6
+ * or deleted), or whose database they cannot, says so instead.
6
7
  */
7
8
  import { type ReactNode } from 'react';
8
9
  export interface TableViewBlockLabels {
@@ -2,9 +2,12 @@
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useMemo } from "react";
4
4
  import { Table2 } from "lucide-react";
5
- import { useDatabase, useDatabaseRows, useTableView } from "@arbidocs/react";
5
+ import { useTableViewRows } from "@arbidocs/react";
6
6
  import { Card, cn } from "@arbidocs/react/ui";
7
7
  import { DatabaseTable } from "../../databases/DatabaseTable.js";
8
+ import {
9
+ DATABASE_COLUMN_TYPES
10
+ } from "../../databases/column-types.js";
8
11
  const DEFAULT_TABLE_VIEW_BLOCK_LABELS = {
9
12
  loading: "Loading\u2026",
10
13
  unavailable: "This table view is not available to you.",
@@ -16,6 +19,12 @@ const toRowView = (r) => ({
16
19
  titles: { ...r.titles ?? {} },
17
20
  shared: r.shared ?? true
18
21
  });
22
+ const GRID_TYPES = new Set(DATABASE_COLUMN_TYPES);
23
+ const isGridType = (type) => GRID_TYPES.has(type);
24
+ const toColumnView = (c) => ({
25
+ ...c,
26
+ type: isGridType(c.type) ? c.type : "text"
27
+ });
19
28
  function TableViewBlock({
20
29
  viewId,
21
30
  actions,
@@ -24,34 +33,25 @@ function TableViewBlock({
24
33
  testId
25
34
  }) {
26
35
  const l = { ...DEFAULT_TABLE_VIEW_BLOCK_LABELS, ...labels };
27
- const view = useTableView(viewId || null);
28
- const target = view.data?.target ?? null;
29
- const databaseId = target && target.startsWith("dbs-") ? target : null;
30
- const database = useDatabase(databaseId);
31
- const rows = useDatabaseRows(databaseId, "", { view: viewId });
32
- const columns = useMemo(() => {
33
- const all = database.data?.columns ?? [];
34
- const wanted = view.data?.spec.columns ?? [];
35
- if (!wanted.length) return all;
36
- const byId = new Map(all.map((c) => [c.id, c]));
37
- return wanted.flatMap((id) => byId.get(id) ?? []);
38
- }, [database.data, view.data]);
36
+ const read = useTableViewRows(viewId || null);
37
+ const data = read.data;
38
+ const columns = useMemo(() => (data?.columns ?? []).map(toColumnView), [data]);
39
+ const rows = useMemo(() => (data?.rows ?? []).map(toRowView), [data]);
39
40
  let body;
40
- if (view.isError || database.isError) {
41
+ if (read.isError) {
41
42
  body = /* @__PURE__ */ jsx("p", { className: "p-4 text-sm text-muted-foreground", children: l.unavailable });
42
- } else if (view.data && !databaseId) {
43
+ } else if (data && !data.database) {
43
44
  body = /* @__PURE__ */ jsx("p", { className: "p-4 text-sm text-muted-foreground", children: l.notADatabase });
44
- } else if (!view.data || !database.data) {
45
+ } else if (!data) {
45
46
  body = /* @__PURE__ */ jsx("p", { className: "p-4 text-sm text-muted-foreground", children: l.loading });
46
47
  } else {
47
48
  body = /* @__PURE__ */ jsx(
48
49
  DatabaseTable,
49
50
  {
50
51
  columns,
51
- rows: (rows.data?.rows ?? []).map(toRowView),
52
+ rows,
52
53
  readOnly: true,
53
54
  isFiltered: true,
54
- isLoading: rows.isLoading,
55
55
  gridId: `page-view-${viewId}`,
56
56
  height: "100%",
57
57
  testId: testId && `${testId}-table`
@@ -67,7 +67,7 @@ function TableViewBlock({
67
67
  children: [
68
68
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 border-b border-border px-4 py-2", children: [
69
69
  /* @__PURE__ */ jsx(Table2, { className: "size-4 text-muted-foreground" }),
70
- /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium", "data-testid": testId && `${testId}-name`, children: view.data?.spec.name ?? "" }),
70
+ /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium", "data-testid": testId && `${testId}-name`, children: data?.view.spec.name ?? "" }),
71
71
  actions && /* @__PURE__ */ jsx("div", { className: "ml-auto flex gap-1", children: actions })
72
72
  ] }),
73
73
  /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1", children: body })
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/connection/pages/TableViewBlock.tsx"],
4
- "sourcesContent": ["/**\n * `TableViewBlock`: a page's table block. It shows one saved table view of a database: the database's\n * rows read with the view applied on the server (`?view=`: its filters and sort), in the view's\n * columns, through the database grid (`DatabaseTable`) in read mode. Only what the viewer can read:\n * a view they cannot see (someone else's private one, or deleted) says so instead.\n */\nimport { useMemo, type ReactNode } from 'react'\nimport { Table2 } from 'lucide-react'\nimport { useDatabase, useDatabaseRows, useTableView, type DatabaseRow } from '@arbidocs/react'\nimport { Card, cn } from '@arbidocs/react/ui'\nimport { DatabaseTable } from '../../databases/DatabaseTable'\nimport type { DatabaseColumnView, DatabaseRowView } from '../../databases/column-types'\n\nexport interface TableViewBlockLabels {\n loading: string\n /** The view is not one the viewer can see (private to someone else, or deleted). */\n unavailable: string\n /** A view of the document table (pages show database views). */\n notADatabase: string\n}\n\nexport const DEFAULT_TABLE_VIEW_BLOCK_LABELS: TableViewBlockLabels = {\n loading: 'Loading\u2026',\n unavailable: 'This table view is not available to you.',\n notADatabase: 'This view is of the documents table, which a page does not show.',\n}\n\nexport interface TableViewBlockProps {\n viewId: string\n /** Buttons in the block's corner (a page being edited). */\n actions?: ReactNode\n labels?: Partial<TableViewBlockLabels>\n className?: string\n testId?: string\n}\n\nconst toRowView = (r: DatabaseRow): DatabaseRowView => ({\n id: r.id,\n values: { ...r.values },\n titles: { ...(r.titles ?? {}) },\n shared: r.shared ?? true,\n})\n\nexport function TableViewBlock({\n viewId,\n actions,\n labels,\n className,\n testId,\n}: TableViewBlockProps) {\n const l = { ...DEFAULT_TABLE_VIEW_BLOCK_LABELS, ...labels }\n const view = useTableView(viewId || null)\n const target = view.data?.target ?? null\n const databaseId = target && target.startsWith('dbs-') ? target : null\n const database = useDatabase(databaseId)\n const rows = useDatabaseRows(databaseId, '', { view: viewId })\n\n // The view's columns, in its order (none named: every column of the database).\n const columns = useMemo(() => {\n const all = (database.data?.columns ?? []) as DatabaseColumnView[]\n const wanted = view.data?.spec.columns ?? []\n if (!wanted.length) return all\n const byId = new Map(all.map((c) => [c.id, c]))\n return wanted.flatMap((id) => byId.get(id) ?? [])\n }, [database.data, view.data])\n\n let body: ReactNode\n if (view.isError || database.isError) {\n body = <p className=\"p-4 text-sm text-muted-foreground\">{l.unavailable}</p>\n } else if (view.data && !databaseId) {\n body = <p className=\"p-4 text-sm text-muted-foreground\">{l.notADatabase}</p>\n } else if (!view.data || !database.data) {\n body = <p className=\"p-4 text-sm text-muted-foreground\">{l.loading}</p>\n } else {\n body = (\n <DatabaseTable\n columns={columns}\n rows={(rows.data?.rows ?? []).map(toRowView)}\n readOnly\n isFiltered\n isLoading={rows.isLoading}\n gridId={`page-view-${viewId}`}\n height=\"100%\"\n testId={testId && `${testId}-table`}\n />\n )\n }\n\n return (\n <Card\n variant=\"elevated\"\n className={cn('flex h-full min-h-[12rem] flex-col overflow-hidden rounded-xl p-0', className)}\n data-testid={testId}\n >\n <div className=\"flex items-center gap-2 border-b border-border px-4 py-2\">\n <Table2 className=\"size-4 text-muted-foreground\" />\n <span className=\"truncate text-sm font-medium\" data-testid={testId && `${testId}-name`}>\n {view.data?.spec.name ?? ''}\n </span>\n {actions && <div className=\"ml-auto flex gap-1\">{actions}</div>}\n </div>\n <div className=\"min-h-0 flex-1\">{body}</div>\n </Card>\n )\n}\n"],
5
- "mappings": ";A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CAAqC,YAAE,aAAY;AAAA,EACzE,WAAW,KAAK,QAAQ,CAAC,YAAY;AACnC,WAAO,oBAAC,OAAE,WAAU,qCAAqC,YAAE,cAAa;AAAA,EAC1E,WAAW,CAAC,KAAK,QAAQ,CAAC,SAAS,MAAM;AACvC,WAAO,oBAAC,OAAE,WAAU,qCAAqC,YAAE,SAAQ;AAAA,EACrE,OAAO;AACL,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,OAAO,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,SAAS;AAAA,QAC3C,UAAQ;AAAA,QACR,YAAU;AAAA,QACV,WAAW,KAAK;AAAA,QAChB,QAAQ,aAAa,MAAM;AAAA,QAC3B,QAAO;AAAA,QACP,QAAQ,UAAU,GAAG,MAAM;AAAA;AAAA,IAC7B;AAAA,EAEJ;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,WAAW,GAAG,qEAAqE,SAAS;AAAA,MAC5F,eAAa;AAAA,MAEb;AAAA,6BAAC,SAAI,WAAU,4DACb;AAAA,8BAAC,UAAO,WAAU,gCAA+B;AAAA,UACjD,oBAAC,UAAK,WAAU,gCAA+B,eAAa,UAAU,GAAG,MAAM,SAC5E,eAAK,MAAM,KAAK,QAAQ,IAC3B;AAAA,UACC,WAAW,oBAAC,SAAI,WAAU,sBAAsB,mBAAQ;AAAA,WAC3D;AAAA,QACA,oBAAC,SAAI,WAAU,kBAAkB,gBAAK;AAAA;AAAA;AAAA,EACxC;AAEJ;",
4
+ "sourcesContent": ["/**\n * `TableViewBlock`: a page's table block. It shows one saved table view of a database: the view,\n * its database's columns and its rows read in one request with the view applied on the server\n * (`useTableViewRows`: its filters, sort and columns), through the database grid (`DatabaseTable`)\n * in read mode. Only what the viewer can read: a view they cannot see (someone else's private one,\n * or deleted), or whose database they cannot, says so instead.\n */\nimport { useMemo, type ReactNode } from 'react'\nimport { Table2 } from 'lucide-react'\nimport { useTableViewRows, type DatabaseColumn, type DatabaseRow } from '@arbidocs/react'\nimport { Card, cn } from '@arbidocs/react/ui'\nimport { DatabaseTable } from '../../databases/DatabaseTable'\nimport {\n DATABASE_COLUMN_TYPES,\n type DatabaseColumnType,\n type DatabaseColumnView,\n type DatabaseRowView,\n} from '../../databases/column-types'\n\nexport interface TableViewBlockLabels {\n loading: string\n /** The view is not one the viewer can see (private to someone else, or deleted). */\n unavailable: string\n /** A view of the document table (pages show database views). */\n notADatabase: string\n}\n\nexport const DEFAULT_TABLE_VIEW_BLOCK_LABELS: TableViewBlockLabels = {\n loading: 'Loading\u2026',\n unavailable: 'This table view is not available to you.',\n notADatabase: 'This view is of the documents table, which a page does not show.',\n}\n\nexport interface TableViewBlockProps {\n viewId: string\n /** Buttons in the block's corner (a page being edited). */\n actions?: ReactNode\n labels?: Partial<TableViewBlockLabels>\n className?: string\n testId?: string\n}\n\nconst toRowView = (r: DatabaseRow): DatabaseRowView => ({\n id: r.id,\n values: { ...r.values },\n titles: { ...(r.titles ?? {}) },\n shared: r.shared ?? true,\n})\n\nconst GRID_TYPES: ReadonlySet<string> = new Set<string>(DATABASE_COLUMN_TYPES)\nconst isGridType = (type: string): type is DatabaseColumnType => GRID_TYPES.has(type)\n\n/** A column as the grid reads it: a type the grid does not draw (a tag column) reads as text. */\nconst toColumnView = (c: DatabaseColumn): DatabaseColumnView => ({\n ...c,\n type: isGridType(c.type) ? c.type : 'text',\n})\n\nexport function TableViewBlock({\n viewId,\n actions,\n labels,\n className,\n testId,\n}: TableViewBlockProps) {\n const l = { ...DEFAULT_TABLE_VIEW_BLOCK_LABELS, ...labels }\n const read = useTableViewRows(viewId || null)\n const data = read.data\n const columns = useMemo(() => (data?.columns ?? []).map(toColumnView), [data])\n const rows = useMemo(() => (data?.rows ?? []).map(toRowView), [data])\n\n let body: ReactNode\n if (read.isError) {\n body = <p className=\"p-4 text-sm text-muted-foreground\">{l.unavailable}</p>\n } else if (data && !data.database) {\n body = <p className=\"p-4 text-sm text-muted-foreground\">{l.notADatabase}</p>\n } else if (!data) {\n body = <p className=\"p-4 text-sm text-muted-foreground\">{l.loading}</p>\n } else {\n body = (\n <DatabaseTable\n columns={columns}\n rows={rows}\n readOnly\n isFiltered\n gridId={`page-view-${viewId}`}\n height=\"100%\"\n testId={testId && `${testId}-table`}\n />\n )\n }\n\n return (\n <Card\n variant=\"elevated\"\n className={cn('flex h-full min-h-[12rem] flex-col overflow-hidden rounded-xl p-0', className)}\n data-testid={testId}\n >\n <div className=\"flex items-center gap-2 border-b border-border px-4 py-2\">\n <Table2 className=\"size-4 text-muted-foreground\" />\n <span className=\"truncate text-sm font-medium\" data-testid={testId && `${testId}-name`}>\n {data?.view.spec.name ?? ''}\n </span>\n {actions && <div className=\"ml-auto flex gap-1\">{actions}</div>}\n </div>\n <div className=\"min-h-0 flex-1\">{body}</div>\n </Card>\n )\n}\n"],
5
+ "mappings": ";AAyEW,cAyBL,YAzBK;AAlEX,SAAS,eAA+B;AACxC,SAAS,cAAc;AACvB,SAAS,wBAA+D;AACxE,SAAS,MAAM,UAAU;AACzB,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,OAIK;AAUA,MAAM,kCAAwD;AAAA,EACnE,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAChB;AAWA,MAAM,YAAY,CAAC,OAAqC;AAAA,EACtD,IAAI,EAAE;AAAA,EACN,QAAQ,EAAE,GAAG,EAAE,OAAO;AAAA,EACtB,QAAQ,EAAE,GAAI,EAAE,UAAU,CAAC,EAAG;AAAA,EAC9B,QAAQ,EAAE,UAAU;AACtB;AAEA,MAAM,aAAkC,IAAI,IAAY,qBAAqB;AAC7E,MAAM,aAAa,CAAC,SAA6C,WAAW,IAAI,IAAI;AAGpF,MAAM,eAAe,CAAC,OAA2C;AAAA,EAC/D,GAAG;AAAA,EACH,MAAM,WAAW,EAAE,IAAI,IAAI,EAAE,OAAO;AACtC;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,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EACxC;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -86,7 +86,7 @@ function ConnectedStorageProjectCard({
86
86
  setBusy(true);
87
87
  try {
88
88
  notify(await action(), "success");
89
- await invalidate();
89
+ void invalidate();
90
90
  } catch (error) {
91
91
  notify(error instanceof Error ? error.message : failure, "error");
92
92
  } finally {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/connection/storage/ConnectedStorageProjectCard.tsx"],
4
- "sourcesContent": ["/**\n * One project's storage: used against its limit, by kind (and by workspace), its largest items, and Recently\n * deleted with Restore, Delete permanently and Empty trash. A personal project also shows its mail by folder.\n *\n * Everything stored counts: every version, preview and search file of a document, mail, recordings, chat\n * attachments \u2014 and deleted items until they are removed for good (ARBI's storage ledger).\n */\n\nimport { useMemo, useState } from 'react'\nimport { HardDrive, RotateCcw, Trash2 } from 'lucide-react'\nimport { Button } from '@arbidocs/react/ui'\nimport { UsageMeter } from '../../components/UsageMeter'\nimport { ConfirmDialog } from '../../provider/dialogs'\nimport { SettingsCard } from '../../settings/SettingsPanel'\nimport { UsageToggle } from '../../settings/Usage'\nimport {\n useInvalidateStorage,\n useStorageActions,\n useStorageItemNames,\n useStorageItems,\n type StorageItem,\n type StorageItemsQuery,\n type StorageProjectUsage,\n} from '@arbidocs/react'\nimport { useBlocksEnvironment } from '../../provider/environment'\nimport {\n formatBytes,\n itemTitle,\n kindRows,\n MAIL_FOLDER_LABELS,\n RECENTLY_DELETED_NOTE,\n usedOfLimit,\n usedPct,\n type StorageItemRow,\n} from './storage-labels'\nimport { StorageBreakdown, StorageItemsTable, StorageTiers } from './StorageParts'\nimport { ConnectedWorkspaceTrash } from './ConnectedWorkspaceTrash'\n\ntype View = 'overview' | 'largest' | 'deleted'\ntype KindFilter = 'all' | NonNullable<StorageItemsQuery['kind']>\n\nconst KIND_FILTERS: { value: KindFilter; label: string }[] = [\n { value: 'all', label: 'All' },\n { value: 'document', label: 'Documents' },\n { value: 'mail', label: 'Mail' },\n { value: 'recording', label: 'Recordings' },\n { value: 'chat_attachment', label: 'Attachments' },\n]\n\ntype Pending =\n | { kind: 'purge'; rows: StorageItemRow[] }\n | { kind: 'empty-mail' }\n | { kind: 'delete'; row: StorageItemRow }\n\nexport interface ConnectedStorageProjectCardProps {\n project: StorageProjectUsage\n /** The fraction archived and deleted bytes count at (the server's `reduced_rate`). */\n reducedRate: number\n /** Show the by-workspace breakdown (project settings). */\n showWorkspaces?: boolean\n /** Close the surface this card lives in before navigating away (Settings panel). */\n onNavigate?: () => void\n}\n\nexport function ConnectedStorageProjectCard({\n project,\n reducedRate,\n showWorkspaces = false,\n onNavigate,\n}: ConnectedStorageProjectCardProps) {\n const [view, setView] = useState<View>('overview')\n const [kind, setKind] = useState<KindFilter>('all')\n const [pending, setPending] = useState<Pending | null>(null)\n const [busy, setBusy] = useState(false)\n const invalidate = useInvalidateStorage()\n const {\n deleteDocuments,\n emptyMailTrash,\n purgeStorageItems,\n restoreDocuments,\n restoreWorkspaces,\n updateNativeMail,\n } = useStorageActions()\n // A mail item opens in the host's mail at its folder; without mail it has no Open.\n const { notify, openDocument, openMail } = useBlocksEnvironment()\n\n const testId = `storage-project-${project.project_ext_id}`\n const deletedWorkspaces = (project.workspaces ?? []).filter((w) => w.deleted)\n const deletedWorkspaceIds = new Set(deletedWorkspaces.map((w) => w.workspace_ext_id))\n\n const largestQuery: StorageItemsQuery = {\n project: project.project_ext_id,\n state: 'live',\n ...(kind !== 'all' ? { kind } : {}),\n limit: 25,\n }\n const trashQuery: StorageItemsQuery = {\n project: project.project_ext_id,\n state: 'trash',\n limit: 100,\n }\n const largest = useStorageItems(largestQuery, view === 'largest')\n const trash = useStorageItems(trashQuery, view === 'deleted')\n const largestNames = useStorageItemNames(largest.data?.items, largestQuery)\n const trashNames = useStorageItemNames(trash.data?.items, trashQuery)\n\n const largestRows = useMemo(\n () => (largest.data?.items ?? []).map((item) => row(item, largestNames.data)),\n [largest.data, largestNames.data]\n )\n // Live workspaces with deleted documents: each gets its own Recently deleted (ConnectedWorkspaceTrash).\n const trashedWorkspaces = (project.workspaces ?? []).filter(\n (w) => !w.deleted && w.trash_bytes > 0\n )\n // A deleted workspace is one entry (restore it whole); documents are listed per workspace; the rest here.\n const trashRows = useMemo(\n () =>\n (trash.data?.items ?? [])\n .filter((item) => item.kind !== 'document' && item.kind !== 'private')\n .filter((item) => !item.workspace_ext_id || !deletedWorkspaceIds.has(item.workspace_ext_id))\n .map((item) => row(item, trashNames.data)),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the set derives from project.workspaces\n [trash.data, trashNames.data, project.workspaces]\n )\n\n const run = async (action: () => Promise<string>, failure: string) => {\n setBusy(true)\n try {\n notify(await action(), 'success')\n await invalidate()\n } catch (error) {\n notify(error instanceof Error ? error.message : failure, 'error')\n } finally {\n setBusy(false)\n setPending(null)\n }\n }\n\n const open = ({ item }: StorageItemRow) => {\n if (item.kind === 'mail') {\n if (!openMail) return\n onNavigate?.()\n openMail({ folder: item.folder ?? 'inbox' })\n return\n }\n if (item.kind === 'document' && item.ref && item.workspace_ext_id) {\n // The host opens the document's workspace first when it is not the open one.\n onNavigate?.()\n openDocument(item.ref, { workspaceId: item.workspace_ext_id })\n }\n }\n\n const moveToTrash = ({ item }: StorageItemRow) =>\n run(async () => {\n if (item.kind === 'mail') await updateNativeMail(item.ref!, 'trash')\n else await deleteDocuments([item.ref!])\n return 'Moved to Recently deleted'\n }, 'Could not delete')\n\n const restore = ({ item }: StorageItemRow) =>\n run(async () => {\n if (item.kind === 'mail') {\n await updateNativeMail(item.ref!, 'restore')\n return 'Restored'\n }\n await restoreDocuments(item.workspace_ext_id!, [item.ref!])\n return 'Restoring. It reappears when its files are back.'\n }, 'Could not restore')\n\n const restoreWorkspace = (workspaceExtId: string) =>\n run(async () => {\n await restoreWorkspaces([workspaceExtId])\n return 'Restoring the workspace. It opens when its files are back.'\n }, 'Could not restore the workspace')\n\n const confirm = () => {\n if (!pending) return\n if (pending.kind === 'purge') {\n void run(async () => {\n const freed = await purgeStorageItems(\n project.project_ext_id,\n pending.rows.map((r) => r.item.ref!).filter(Boolean)\n )\n return `Deleted permanently \u00B7 ${formatBytes(freed)} freed`\n }, 'Could not delete permanently')\n } else if (pending.kind === 'empty-mail') {\n void run(async () => {\n const count = await emptyMailTrash()\n return `Mail Trash emptied (${count} ${count === 1 ? 'message' : 'messages'})`\n }, 'Could not empty the Trash')\n } else {\n void moveToTrash(pending.row)\n }\n }\n\n // Mail comes back from the Trash; a document from its workspace's Recently deleted.\n const canRestore = (item: StorageItem) =>\n item.kind === 'mail'\n ? !!item.ref?.startsWith('eml-')\n : item.kind === 'document' && !!item.ref && !!item.workspace_ext_id\n\n const kinds = kindRows(project.by_kind)\n const folders = Object.entries(project.mail_folders ?? {}).sort((a, b) => b[1] - a[1])\n\n return (\n <SettingsCard data-testid={testId}>\n <div className=\"flex flex-wrap items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-2\">\n <HardDrive className=\"size-4 text-muted-foreground\" />\n <h3 className=\"truncate text-base font-semibold text-foreground\">\n {project.personal ? 'Personal' : project.name}\n </h3>\n </div>\n {project.personal && (\n <p className=\"mt-0.5 text-sm text-muted-foreground\">\n Mail, recordings of calls you host, chat attachments and everything not in a project.\n </p>\n )}\n </div>\n <UsageToggle\n value={view}\n onChange={setView}\n ariaLabel=\"Storage view\"\n options={[\n { value: 'overview', label: 'Overview' },\n { value: 'largest', label: 'Largest items' },\n { value: 'deleted', label: 'Recently deleted' },\n ]}\n />\n </div>\n\n {/* What counts against the limit: live in full, archived and deleted at the reduced rate. */}\n <UsageMeter\n label=\"Storage\"\n value={usedOfLimit(project.billable_bytes, project.limit_bytes)}\n pct={usedPct(project.billable_bytes, project.limit_bytes)}\n details={\n <StorageTiers\n bytes={project.bytes}\n archivedBytes={project.archived_bytes ?? 0}\n trashBytes={project.trash_bytes}\n reducedRate={reducedRate}\n testId={`${testId}-tiers`}\n />\n }\n testId={`${testId}-meter`}\n />\n\n {view === 'overview' && (\n <div className=\"space-y-5\">\n <StorageBreakdown rows={kinds} total={project.bytes} testId={`${testId}-kinds`} />\n {folders.length > 0 && (\n <div className=\"space-y-2\" data-testid={`${testId}-mail`}>\n <div className=\"flex items-center justify-between gap-3\">\n <h4 className=\"text-sm font-semibold text-foreground\">Mail by folder</h4>\n <div className=\"flex gap-1\">\n {(project.mail_folders?.trash ?? 0) > 0 && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => setPending({ kind: 'empty-mail' })}\n data-testid={`${testId}-empty-mail-trash`}\n >\n Empty Trash\n </Button>\n )}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n onClick={() => {\n setKind('mail')\n setView('largest')\n }}\n >\n Largest emails\n </Button>\n </div>\n </div>\n <ul className=\"space-y-1 text-sm\">\n {folders.map(([folder, bytes]) => (\n <li key={folder} className=\"flex justify-between gap-3\">\n <span className=\"text-foreground\">{MAIL_FOLDER_LABELS[folder] ?? folder}</span>\n <span className=\"tabular-nums text-muted-foreground\">{formatBytes(bytes)}</span>\n </li>\n ))}\n </ul>\n </div>\n )}\n {showWorkspaces && (project.workspaces?.length ?? 0) > 0 && (\n <div className=\"space-y-2\" data-testid={`${testId}-workspaces`}>\n <h4 className=\"text-sm font-semibold text-foreground\">By workspace</h4>\n <StorageBreakdown\n rows={(project.workspaces ?? []).map((w) => ({\n kind: w.workspace_ext_id,\n label: w.deleted\n ? `${w.name} (deleted)`\n : w.archived\n ? `${w.name} (archived)`\n : w.name,\n bytes: w.bytes,\n trashBytes: w.trash_bytes,\n }))}\n total={project.bytes}\n />\n </div>\n )}\n </div>\n )}\n\n {view === 'largest' && (\n <div className=\"space-y-3\">\n <UsageToggle value={kind} onChange={setKind} options={KIND_FILTERS} ariaLabel=\"Kind\" />\n {largest.isLoading ? (\n <p className=\"text-sm text-muted-foreground\">Loading\u2026</p>\n ) : (\n <StorageItemsTable\n rows={largestRows}\n area={`${testId}-largest`}\n emptyTitle=\"Nothing stored here yet\"\n actions={(r) => (\n <>\n {(r.item.kind === 'document' || (r.item.kind === 'mail' && openMail)) && (\n <Button size=\"sm\" variant=\"ghost\" onClick={() => open(r)}>\n Open\n </Button>\n )}\n {(r.item.kind === 'document' || r.item.kind === 'mail') && r.item.ref && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n aria-label={`Delete ${itemTitle(r)}`}\n disabled={busy}\n onClick={() => setPending({ kind: 'delete', row: r })}\n >\n <Trash2 className=\"size-4\" />\n </Button>\n )}\n </>\n )}\n />\n )}\n </div>\n )}\n\n {view === 'deleted' && (\n <div className=\"space-y-3\">\n <p className=\"text-sm text-muted-foreground\">{RECENTLY_DELETED_NOTE}</p>\n {deletedWorkspaces.length > 0 && (\n <ul className=\"divide-y divide-border rounded-md border border-border\">\n {deletedWorkspaces.map((w) => (\n <li\n key={w.workspace_ext_id}\n className=\"flex items-center justify-between gap-3 px-3 py-2 text-sm\"\n data-testid={`${testId}-deleted-workspace-${w.workspace_ext_id}`}\n >\n <span className=\"min-w-0 truncate\">\n <span className=\"font-medium text-foreground\">{w.name}</span>\n <span className=\"text-muted-foreground\">\n {' '}\n \u00B7 deleted workspace \u00B7 {formatBytes(w.bytes)}\n </span>\n </span>\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => void restoreWorkspace(w.workspace_ext_id)}\n >\n <RotateCcw className=\"mr-1.5 size-4\" />\n Restore\n </Button>\n </li>\n ))}\n </ul>\n )}\n {trashedWorkspaces.map((w) => (\n <ConnectedWorkspaceTrash\n key={w.workspace_ext_id}\n workspaceExtId={w.workspace_ext_id}\n title={w.name}\n testId={`${testId}-workspace-trash-${w.workspace_ext_id}`}\n />\n ))}\n {trash.isLoading ? (\n <p className=\"text-sm text-muted-foreground\">Loading\u2026</p>\n ) : (\n <StorageItemsTable\n rows={trashRows}\n area={`${testId}-deleted`}\n emptyTitle={\n deletedWorkspaces.length || trashedWorkspaces.length\n ? 'No other deleted items'\n : 'Nothing in Recently deleted'\n }\n actions={(r) => (\n <>\n {canRestore(r.item) && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => void restore(r)}\n >\n <RotateCcw className=\"mr-1.5 size-4\" />\n Restore\n </Button>\n )}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => setPending({ kind: 'purge', rows: [r] })}\n >\n Delete permanently\n </Button>\n </>\n )}\n />\n )}\n </div>\n )}\n\n <ConfirmDialog\n isOpen={pending !== null}\n onClose={() => setPending(null)}\n onConfirm={confirm}\n isLoading={busy}\n title={confirmTitle(pending)}\n description={confirmDescription(pending)}\n confirmText={confirmButton(pending)}\n testId={`${testId}-confirm`}\n />\n </SettingsCard>\n )\n}\n\nfunction row(item: StorageItem, names: Record<string, string> | undefined): StorageItemRow {\n return { item, name: item.ref ? names?.[item.ref] : undefined }\n}\n\nfunction confirmTitle(pending: Pending | null): string {\n switch (pending?.kind) {\n case 'purge':\n return 'Delete permanently?'\n case 'empty-mail':\n return 'Empty mail Trash?'\n case 'delete':\n return `Delete ${itemTitle(pending.row)}?`\n default:\n return ''\n }\n}\n\nfunction confirmDescription(pending: Pending | null): string {\n switch (pending?.kind) {\n case 'purge':\n return 'It is removed for good now and stops using storage. This cannot be undone.'\n case 'empty-mail':\n return 'Every message in your mail Trash is deleted for good and stops using storage. This cannot be undone.'\n case 'delete':\n return `It moves to Recently deleted, where you can restore it. ${RECENTLY_DELETED_NOTE}`\n default:\n return ''\n }\n}\n\nfunction confirmButton(pending: Pending | null): string {\n switch (pending?.kind) {\n case 'purge':\n return 'Delete permanently'\n case 'empty-mail':\n return 'Empty'\n default:\n return 'Delete'\n }\n}\n"],
5
- "mappings": ";AAgNU,SAkHM,UAjHJ,KADF;AAxMV,SAAS,SAAS,gBAAgB;AAClC,SAAS,WAAW,WAAW,cAAc;AAC7C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,oBA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AAA,IACT,KAAK;AACH,aAAO,2DAA2D,qBAAqB;AAAA,IACzF;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,cAAc,SAAiC;AACtD,UAAQ,SAAS,MAAM;AAAA,IACrB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;",
4
+ "sourcesContent": ["/**\n * One project's storage: used against its limit, by kind (and by workspace), its largest items, and Recently\n * deleted with Restore, Delete permanently and Empty trash. A personal project also shows its mail by folder.\n *\n * Everything stored counts: every version, preview and search file of a document, mail, recordings, chat\n * attachments \u2014 and deleted items until they are removed for good (ARBI's storage ledger).\n */\n\nimport { useMemo, useState } from 'react'\nimport { HardDrive, RotateCcw, Trash2 } from 'lucide-react'\nimport { Button } from '@arbidocs/react/ui'\nimport { UsageMeter } from '../../components/UsageMeter'\nimport { ConfirmDialog } from '../../provider/dialogs'\nimport { SettingsCard } from '../../settings/SettingsPanel'\nimport { UsageToggle } from '../../settings/Usage'\nimport {\n useInvalidateStorage,\n useStorageActions,\n useStorageItemNames,\n useStorageItems,\n type StorageItem,\n type StorageItemsQuery,\n type StorageProjectUsage,\n} from '@arbidocs/react'\nimport { useBlocksEnvironment } from '../../provider/environment'\nimport {\n formatBytes,\n itemTitle,\n kindRows,\n MAIL_FOLDER_LABELS,\n RECENTLY_DELETED_NOTE,\n usedOfLimit,\n usedPct,\n type StorageItemRow,\n} from './storage-labels'\nimport { StorageBreakdown, StorageItemsTable, StorageTiers } from './StorageParts'\nimport { ConnectedWorkspaceTrash } from './ConnectedWorkspaceTrash'\n\ntype View = 'overview' | 'largest' | 'deleted'\ntype KindFilter = 'all' | NonNullable<StorageItemsQuery['kind']>\n\nconst KIND_FILTERS: { value: KindFilter; label: string }[] = [\n { value: 'all', label: 'All' },\n { value: 'document', label: 'Documents' },\n { value: 'mail', label: 'Mail' },\n { value: 'recording', label: 'Recordings' },\n { value: 'chat_attachment', label: 'Attachments' },\n]\n\ntype Pending =\n | { kind: 'purge'; rows: StorageItemRow[] }\n | { kind: 'empty-mail' }\n | { kind: 'delete'; row: StorageItemRow }\n\nexport interface ConnectedStorageProjectCardProps {\n project: StorageProjectUsage\n /** The fraction archived and deleted bytes count at (the server's `reduced_rate`). */\n reducedRate: number\n /** Show the by-workspace breakdown (project settings). */\n showWorkspaces?: boolean\n /** Close the surface this card lives in before navigating away (Settings panel). */\n onNavigate?: () => void\n}\n\nexport function ConnectedStorageProjectCard({\n project,\n reducedRate,\n showWorkspaces = false,\n onNavigate,\n}: ConnectedStorageProjectCardProps) {\n const [view, setView] = useState<View>('overview')\n const [kind, setKind] = useState<KindFilter>('all')\n const [pending, setPending] = useState<Pending | null>(null)\n const [busy, setBusy] = useState(false)\n const invalidate = useInvalidateStorage()\n const {\n deleteDocuments,\n emptyMailTrash,\n purgeStorageItems,\n restoreDocuments,\n restoreWorkspaces,\n updateNativeMail,\n } = useStorageActions()\n // A mail item opens in the host's mail at its folder; without mail it has no Open.\n const { notify, openDocument, openMail } = useBlocksEnvironment()\n\n const testId = `storage-project-${project.project_ext_id}`\n const deletedWorkspaces = (project.workspaces ?? []).filter((w) => w.deleted)\n const deletedWorkspaceIds = new Set(deletedWorkspaces.map((w) => w.workspace_ext_id))\n\n const largestQuery: StorageItemsQuery = {\n project: project.project_ext_id,\n state: 'live',\n ...(kind !== 'all' ? { kind } : {}),\n limit: 25,\n }\n const trashQuery: StorageItemsQuery = {\n project: project.project_ext_id,\n state: 'trash',\n limit: 100,\n }\n const largest = useStorageItems(largestQuery, view === 'largest')\n const trash = useStorageItems(trashQuery, view === 'deleted')\n const largestNames = useStorageItemNames(largest.data?.items, largestQuery)\n const trashNames = useStorageItemNames(trash.data?.items, trashQuery)\n\n const largestRows = useMemo(\n () => (largest.data?.items ?? []).map((item) => row(item, largestNames.data)),\n [largest.data, largestNames.data]\n )\n // Live workspaces with deleted documents: each gets its own Recently deleted (ConnectedWorkspaceTrash).\n const trashedWorkspaces = (project.workspaces ?? []).filter(\n (w) => !w.deleted && w.trash_bytes > 0\n )\n // A deleted workspace is one entry (restore it whole); documents are listed per workspace; the rest here.\n const trashRows = useMemo(\n () =>\n (trash.data?.items ?? [])\n .filter((item) => item.kind !== 'document' && item.kind !== 'private')\n .filter((item) => !item.workspace_ext_id || !deletedWorkspaceIds.has(item.workspace_ext_id))\n .map((item) => row(item, trashNames.data)),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the set derives from project.workspaces\n [trash.data, trashNames.data, project.workspaces]\n )\n\n // The refetch after an action is not waited for: the action's own answer is what the viewer waits on.\n const run = async (action: () => Promise<string>, failure: string) => {\n setBusy(true)\n try {\n notify(await action(), 'success')\n void invalidate()\n } catch (error) {\n notify(error instanceof Error ? error.message : failure, 'error')\n } finally {\n setBusy(false)\n setPending(null)\n }\n }\n\n const open = ({ item }: StorageItemRow) => {\n if (item.kind === 'mail') {\n if (!openMail) return\n onNavigate?.()\n openMail({ folder: item.folder ?? 'inbox' })\n return\n }\n if (item.kind === 'document' && item.ref && item.workspace_ext_id) {\n // The host opens the document's workspace first when it is not the open one.\n onNavigate?.()\n openDocument(item.ref, { workspaceId: item.workspace_ext_id })\n }\n }\n\n const moveToTrash = ({ item }: StorageItemRow) =>\n run(async () => {\n if (item.kind === 'mail') await updateNativeMail(item.ref!, 'trash')\n else await deleteDocuments([item.ref!])\n return 'Moved to Recently deleted'\n }, 'Could not delete')\n\n const restore = ({ item }: StorageItemRow) =>\n run(async () => {\n if (item.kind === 'mail') {\n await updateNativeMail(item.ref!, 'restore')\n return 'Restored'\n }\n await restoreDocuments(item.workspace_ext_id!, [item.ref!])\n return 'Restoring. It reappears when its files are back.'\n }, 'Could not restore')\n\n const restoreWorkspace = (workspaceExtId: string) =>\n run(async () => {\n await restoreWorkspaces([workspaceExtId])\n return 'Restoring the workspace. It opens when its files are back.'\n }, 'Could not restore the workspace')\n\n const confirm = () => {\n if (!pending) return\n if (pending.kind === 'purge') {\n void run(async () => {\n const freed = await purgeStorageItems(\n project.project_ext_id,\n pending.rows.map((r) => r.item.ref!).filter(Boolean)\n )\n return `Deleted permanently \u00B7 ${formatBytes(freed)} freed`\n }, 'Could not delete permanently')\n } else if (pending.kind === 'empty-mail') {\n void run(async () => {\n const count = await emptyMailTrash()\n return `Mail Trash emptied (${count} ${count === 1 ? 'message' : 'messages'})`\n }, 'Could not empty the Trash')\n } else {\n void moveToTrash(pending.row)\n }\n }\n\n // Mail comes back from the Trash; a document from its workspace's Recently deleted.\n const canRestore = (item: StorageItem) =>\n item.kind === 'mail'\n ? !!item.ref?.startsWith('eml-')\n : item.kind === 'document' && !!item.ref && !!item.workspace_ext_id\n\n const kinds = kindRows(project.by_kind)\n const folders = Object.entries(project.mail_folders ?? {}).sort((a, b) => b[1] - a[1])\n\n return (\n <SettingsCard data-testid={testId}>\n <div className=\"flex flex-wrap items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-2\">\n <HardDrive className=\"size-4 text-muted-foreground\" />\n <h3 className=\"truncate text-base font-semibold text-foreground\">\n {project.personal ? 'Personal' : project.name}\n </h3>\n </div>\n {project.personal && (\n <p className=\"mt-0.5 text-sm text-muted-foreground\">\n Mail, recordings of calls you host, chat attachments and everything not in a project.\n </p>\n )}\n </div>\n <UsageToggle\n value={view}\n onChange={setView}\n ariaLabel=\"Storage view\"\n options={[\n { value: 'overview', label: 'Overview' },\n { value: 'largest', label: 'Largest items' },\n { value: 'deleted', label: 'Recently deleted' },\n ]}\n />\n </div>\n\n {/* What counts against the limit: live in full, archived and deleted at the reduced rate. */}\n <UsageMeter\n label=\"Storage\"\n value={usedOfLimit(project.billable_bytes, project.limit_bytes)}\n pct={usedPct(project.billable_bytes, project.limit_bytes)}\n details={\n <StorageTiers\n bytes={project.bytes}\n archivedBytes={project.archived_bytes ?? 0}\n trashBytes={project.trash_bytes}\n reducedRate={reducedRate}\n testId={`${testId}-tiers`}\n />\n }\n testId={`${testId}-meter`}\n />\n\n {view === 'overview' && (\n <div className=\"space-y-5\">\n <StorageBreakdown rows={kinds} total={project.bytes} testId={`${testId}-kinds`} />\n {folders.length > 0 && (\n <div className=\"space-y-2\" data-testid={`${testId}-mail`}>\n <div className=\"flex items-center justify-between gap-3\">\n <h4 className=\"text-sm font-semibold text-foreground\">Mail by folder</h4>\n <div className=\"flex gap-1\">\n {(project.mail_folders?.trash ?? 0) > 0 && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => setPending({ kind: 'empty-mail' })}\n data-testid={`${testId}-empty-mail-trash`}\n >\n Empty Trash\n </Button>\n )}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n onClick={() => {\n setKind('mail')\n setView('largest')\n }}\n >\n Largest emails\n </Button>\n </div>\n </div>\n <ul className=\"space-y-1 text-sm\">\n {folders.map(([folder, bytes]) => (\n <li key={folder} className=\"flex justify-between gap-3\">\n <span className=\"text-foreground\">{MAIL_FOLDER_LABELS[folder] ?? folder}</span>\n <span className=\"tabular-nums text-muted-foreground\">{formatBytes(bytes)}</span>\n </li>\n ))}\n </ul>\n </div>\n )}\n {showWorkspaces && (project.workspaces?.length ?? 0) > 0 && (\n <div className=\"space-y-2\" data-testid={`${testId}-workspaces`}>\n <h4 className=\"text-sm font-semibold text-foreground\">By workspace</h4>\n <StorageBreakdown\n rows={(project.workspaces ?? []).map((w) => ({\n kind: w.workspace_ext_id,\n label: w.deleted\n ? `${w.name} (deleted)`\n : w.archived\n ? `${w.name} (archived)`\n : w.name,\n bytes: w.bytes,\n trashBytes: w.trash_bytes,\n }))}\n total={project.bytes}\n />\n </div>\n )}\n </div>\n )}\n\n {view === 'largest' && (\n <div className=\"space-y-3\">\n <UsageToggle value={kind} onChange={setKind} options={KIND_FILTERS} ariaLabel=\"Kind\" />\n {largest.isLoading ? (\n <p className=\"text-sm text-muted-foreground\">Loading\u2026</p>\n ) : (\n <StorageItemsTable\n rows={largestRows}\n area={`${testId}-largest`}\n emptyTitle=\"Nothing stored here yet\"\n actions={(r) => (\n <>\n {(r.item.kind === 'document' || (r.item.kind === 'mail' && openMail)) && (\n <Button size=\"sm\" variant=\"ghost\" onClick={() => open(r)}>\n Open\n </Button>\n )}\n {(r.item.kind === 'document' || r.item.kind === 'mail') && r.item.ref && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n aria-label={`Delete ${itemTitle(r)}`}\n disabled={busy}\n onClick={() => setPending({ kind: 'delete', row: r })}\n >\n <Trash2 className=\"size-4\" />\n </Button>\n )}\n </>\n )}\n />\n )}\n </div>\n )}\n\n {view === 'deleted' && (\n <div className=\"space-y-3\">\n <p className=\"text-sm text-muted-foreground\">{RECENTLY_DELETED_NOTE}</p>\n {deletedWorkspaces.length > 0 && (\n <ul className=\"divide-y divide-border rounded-md border border-border\">\n {deletedWorkspaces.map((w) => (\n <li\n key={w.workspace_ext_id}\n className=\"flex items-center justify-between gap-3 px-3 py-2 text-sm\"\n data-testid={`${testId}-deleted-workspace-${w.workspace_ext_id}`}\n >\n <span className=\"min-w-0 truncate\">\n <span className=\"font-medium text-foreground\">{w.name}</span>\n <span className=\"text-muted-foreground\">\n {' '}\n \u00B7 deleted workspace \u00B7 {formatBytes(w.bytes)}\n </span>\n </span>\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => void restoreWorkspace(w.workspace_ext_id)}\n >\n <RotateCcw className=\"mr-1.5 size-4\" />\n Restore\n </Button>\n </li>\n ))}\n </ul>\n )}\n {trashedWorkspaces.map((w) => (\n <ConnectedWorkspaceTrash\n key={w.workspace_ext_id}\n workspaceExtId={w.workspace_ext_id}\n title={w.name}\n testId={`${testId}-workspace-trash-${w.workspace_ext_id}`}\n />\n ))}\n {trash.isLoading ? (\n <p className=\"text-sm text-muted-foreground\">Loading\u2026</p>\n ) : (\n <StorageItemsTable\n rows={trashRows}\n area={`${testId}-deleted`}\n emptyTitle={\n deletedWorkspaces.length || trashedWorkspaces.length\n ? 'No other deleted items'\n : 'Nothing in Recently deleted'\n }\n actions={(r) => (\n <>\n {canRestore(r.item) && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => void restore(r)}\n >\n <RotateCcw className=\"mr-1.5 size-4\" />\n Restore\n </Button>\n )}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => setPending({ kind: 'purge', rows: [r] })}\n >\n Delete permanently\n </Button>\n </>\n )}\n />\n )}\n </div>\n )}\n\n <ConfirmDialog\n isOpen={pending !== null}\n onClose={() => setPending(null)}\n onConfirm={confirm}\n isLoading={busy}\n title={confirmTitle(pending)}\n description={confirmDescription(pending)}\n confirmText={confirmButton(pending)}\n testId={`${testId}-confirm`}\n />\n </SettingsCard>\n )\n}\n\nfunction row(item: StorageItem, names: Record<string, string> | undefined): StorageItemRow {\n return { item, name: item.ref ? names?.[item.ref] : undefined }\n}\n\nfunction confirmTitle(pending: Pending | null): string {\n switch (pending?.kind) {\n case 'purge':\n return 'Delete permanently?'\n case 'empty-mail':\n return 'Empty mail Trash?'\n case 'delete':\n return `Delete ${itemTitle(pending.row)}?`\n default:\n return ''\n }\n}\n\nfunction confirmDescription(pending: Pending | null): string {\n switch (pending?.kind) {\n case 'purge':\n return 'It is removed for good now and stops using storage. This cannot be undone.'\n case 'empty-mail':\n return 'Every message in your mail Trash is deleted for good and stops using storage. This cannot be undone.'\n case 'delete':\n return `It moves to Recently deleted, where you can restore it. ${RECENTLY_DELETED_NOTE}`\n default:\n return ''\n }\n}\n\nfunction confirmButton(pending: Pending | null): string {\n switch (pending?.kind) {\n case 'purge':\n return 'Delete permanently'\n case 'empty-mail':\n return 'Empty'\n default:\n return 'Delete'\n }\n}\n"],
5
+ "mappings": ";AAiNU,SAkHM,UAjHJ,KADF;AAzMV,SAAS,SAAS,gBAAgB;AAClC,SAAS,WAAW,WAAW,cAAc;AAC7C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AA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AA2D,qBAAqB;AAAA,IACzF;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,cAAc,SAAiC;AACtD,UAAQ,SAAS,MAAM;AAAA,IACrB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;",
6
6
  "names": []
7
7
  }
@@ -6,6 +6,9 @@
6
6
  * delete any listed document and Empty trash for the whole workspace; other members' private deleted
7
7
  * documents are never listed to them, only counted, and go only when they tick the opt-in. Anyone else's
8
8
  * Empty trash removes just their own deleted documents.
9
+ *
10
+ * Delete permanently and Empty trash look done at once: the dialog closes and the documents leave the list
11
+ * before the server answers (the button shows Emptying… meanwhile); if it refuses, they come back.
9
12
  */
10
13
  export interface ConnectedWorkspaceTrashProps {
11
14
  workspaceExtId: string;
@@ -1,10 +1,11 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useState } from "react";
4
4
  import { Loader2, Lock, RotateCcw, Trash2 } from "lucide-react";
5
5
  import { Button, Checkbox, formatFriendlyDate } from "@arbidocs/react/ui";
6
6
  import { ConfirmDialog } from "../../provider/dialogs.js";
7
7
  import {
8
+ useHideFromWorkspaceTrash,
8
9
  useInvalidateStorage,
9
10
  useStorageActions,
10
11
  useWorkspaceTrash
@@ -18,11 +19,13 @@ function ConnectedWorkspaceTrash({
18
19
  }) {
19
20
  const trash = useWorkspaceTrash(workspaceExtId);
20
21
  const invalidate = useInvalidateStorage();
22
+ const hide = useHideFromWorkspaceTrash();
21
23
  const { purgeDeletedDocuments, restoreDocuments } = useStorageActions();
22
24
  const { notify } = useBlocksEnvironment();
23
25
  const [pending, setPending] = useState(null);
24
26
  const [includeOthers, setIncludeOthers] = useState(false);
25
27
  const [busy, setBusy] = useState(false);
28
+ const [removing, setRemoving] = useState(null);
26
29
  const page = trash.data;
27
30
  const items = page?.items ?? [];
28
31
  const manager = page?.can_manage ?? false;
@@ -31,15 +34,17 @@ function ConnectedWorkspaceTrash({
31
34
  const removable = items.filter((d) => !d.restoring);
32
35
  const emptiable = manager ? removable : removable.filter((d) => d.mine);
33
36
  const emptiableBytes = emptiable.reduce((sum, d) => sum + d.bytes, 0);
34
- const run = async (action, failure) => {
37
+ const run = async (action, failure, undo) => {
35
38
  setBusy(true);
36
39
  try {
37
40
  notify(await action(), "success");
38
- await invalidate();
41
+ void invalidate();
39
42
  } catch (error) {
43
+ undo?.();
40
44
  notify(error instanceof Error ? error.message : failure, "error");
41
45
  } finally {
42
46
  setBusy(false);
47
+ setRemoving(null);
43
48
  setPending(null);
44
49
  setIncludeOthers(false);
45
50
  }
@@ -50,20 +55,36 @@ function ConnectedWorkspaceTrash({
50
55
  }, "Could not restore");
51
56
  const confirm = () => {
52
57
  if (!pending) return;
58
+ const withOthers = pending.kind === "empty" && manager && includeOthers;
59
+ const undo = hide(
60
+ workspaceExtId,
61
+ pending.kind === "purge" ? [pending.doc.external_id] : emptiable.map((d) => d.external_id),
62
+ withOthers
63
+ );
64
+ setRemoving(pending.kind);
65
+ setPending(null);
53
66
  if (pending.kind === "purge") {
54
- void run(async () => {
55
- await purgeDeletedDocuments(workspaceExtId, { externalIds: [pending.doc.external_id] });
56
- return `Deleted permanently \xB7 ${formatBytes(pending.doc.bytes)} freed`;
57
- }, "Could not delete permanently");
67
+ void run(
68
+ async () => {
69
+ await purgeDeletedDocuments(workspaceExtId, { externalIds: [pending.doc.external_id] });
70
+ return `Deleted permanently \xB7 ${formatBytes(pending.doc.bytes)} freed`;
71
+ },
72
+ "Could not delete permanently",
73
+ undo
74
+ );
58
75
  return;
59
76
  }
60
- const freed = emptiableBytes + (includeOthers ? others?.bytes ?? 0 : 0);
61
- void run(async () => {
62
- const removed = await purgeDeletedDocuments(workspaceExtId, {
63
- includeOthersPrivate: manager && includeOthers
64
- });
65
- return `Trash emptied \xB7 ${removed.length} ${removed.length === 1 ? "item" : "items"} \xB7 ${formatBytes(freed)} freed`;
66
- }, "Could not empty the trash");
77
+ const freed = emptiableBytes + (withOthers ? others?.bytes ?? 0 : 0);
78
+ void run(
79
+ async () => {
80
+ const removed = await purgeDeletedDocuments(workspaceExtId, {
81
+ includeOthersPrivate: withOthers
82
+ });
83
+ return `Trash emptied \xB7 ${removed.length} ${removed.length === 1 ? "item" : "items"} \xB7 ${formatBytes(freed)} freed`;
84
+ },
85
+ "Could not empty the trash",
86
+ undo
87
+ );
67
88
  };
68
89
  const nothingToEmpty = emptiable.length === 0 && !(manager && othersCount > 0);
69
90
  return /* @__PURE__ */ jsxs("section", { className: "space-y-2", "data-testid": testId, children: [
@@ -72,7 +93,7 @@ function ConnectedWorkspaceTrash({
72
93
  title && /* @__PURE__ */ jsx("h4", { className: "truncate text-sm font-medium text-foreground", children: title }),
73
94
  /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: manager ? RECENTLY_DELETED_NOTE : `${RECENTLY_DELETED_NOTE} You can remove your own deleted items.` })
74
95
  ] }),
75
- /* @__PURE__ */ jsxs(
96
+ /* @__PURE__ */ jsx(
76
97
  Button,
77
98
  {
78
99
  size: "sm",
@@ -80,10 +101,13 @@ function ConnectedWorkspaceTrash({
80
101
  disabled: busy || trash.isLoading || nothingToEmpty,
81
102
  onClick: () => setPending({ kind: "empty" }),
82
103
  "data-testid": `${testId}-empty`,
83
- children: [
104
+ children: removing === "empty" ? /* @__PURE__ */ jsxs(Fragment, { children: [
105
+ /* @__PURE__ */ jsx(Loader2, { className: "mr-1.5 size-4 animate-spin", "aria-hidden": "true" }),
106
+ "Emptying\u2026"
107
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
84
108
  /* @__PURE__ */ jsx(Trash2, { className: "mr-1.5 size-4" }),
85
109
  manager ? "Empty trash" : "Empty my trash"
86
- ]
110
+ ] })
87
111
  }
88
112
  )
89
113
  ] }),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/connection/storage/ConnectedWorkspaceTrash.tsx"],
4
- "sourcesContent": ["/**\n * ConnectedWorkspaceTrash: one workspace's Recently deleted, as RLS lets the viewer see it.\n *\n * Everyone sees only the deleted documents they could see live (shared ones and their own) and may restore\n * or delete their own. A workspace manager (the project's owner, or the workspace's owner) may restore or\n * delete any listed document and Empty trash for the whole workspace; other members' private deleted\n * documents are never listed to them, only counted, and go only when they tick the opt-in. Anyone else's\n * Empty trash removes just their own deleted documents.\n */\n\nimport { useState } from 'react'\nimport { Loader2, Lock, RotateCcw, Trash2 } from 'lucide-react'\nimport { Button, Checkbox, formatFriendlyDate } from '@arbidocs/react/ui'\nimport { ConfirmDialog } from '../../provider/dialogs'\nimport {\n useInvalidateStorage,\n useStorageActions,\n useWorkspaceTrash,\n type DeletedDocument,\n} from '@arbidocs/react'\nimport { useBlocksEnvironment } from '../../provider/environment'\nimport { formatBytes, RECENTLY_DELETED_NOTE } from './storage-labels'\n\ntype Pending = { kind: 'purge'; doc: DeletedDocument } | { kind: 'empty' }\n\nexport interface ConnectedWorkspaceTrashProps {\n workspaceExtId: string\n /** Shown above the list (e.g. the workspace's name on the project's Storage). */\n title?: string\n testId?: string\n}\n\nexport function ConnectedWorkspaceTrash({\n workspaceExtId,\n title,\n testId = 'workspace-trash',\n}: ConnectedWorkspaceTrashProps) {\n const trash = useWorkspaceTrash(workspaceExtId)\n const invalidate = useInvalidateStorage()\n const { purgeDeletedDocuments, restoreDocuments } = useStorageActions()\n const { notify } = useBlocksEnvironment()\n const [pending, setPending] = useState<Pending | null>(null)\n const [includeOthers, setIncludeOthers] = useState(false)\n const [busy, setBusy] = useState(false)\n\n const page = trash.data\n const items = page?.items ?? []\n const manager = page?.can_manage ?? false\n const others = page?.others_private\n const othersCount = others?.count ?? 0\n // What Empty trash removes without the opt-in: everything listed for a manager, the viewer's own otherwise.\n // Documents being restored are on their way back, not in the trash any more.\n const removable = items.filter((d) => !d.restoring)\n const emptiable = manager ? removable : removable.filter((d) => d.mine)\n const emptiableBytes = emptiable.reduce((sum, d) => sum + d.bytes, 0)\n\n const run = async (action: () => Promise<string>, failure: string) => {\n setBusy(true)\n try {\n notify(await action(), 'success')\n await invalidate()\n } catch (error) {\n notify(error instanceof Error ? error.message : failure, 'error')\n } finally {\n setBusy(false)\n setPending(null)\n setIncludeOthers(false)\n }\n }\n\n const restore = (doc: DeletedDocument) =>\n run(async () => {\n await restoreDocuments(workspaceExtId, [doc.external_id])\n return 'Restoring. It reappears in the workspace when its files are back.'\n }, 'Could not restore')\n\n const confirm = () => {\n if (!pending) return\n if (pending.kind === 'purge') {\n void run(async () => {\n await purgeDeletedDocuments(workspaceExtId, { externalIds: [pending.doc.external_id] })\n return `Deleted permanently \u00B7 ${formatBytes(pending.doc.bytes)} freed`\n }, 'Could not delete permanently')\n return\n }\n const freed = emptiableBytes + (includeOthers ? (others?.bytes ?? 0) : 0)\n void run(async () => {\n const removed = await purgeDeletedDocuments(workspaceExtId, {\n includeOthersPrivate: manager && includeOthers,\n })\n return `Trash emptied \u00B7 ${removed.length} ${removed.length === 1 ? 'item' : 'items'} \u00B7 ${formatBytes(freed)} freed`\n }, 'Could not empty the trash')\n }\n\n const nothingToEmpty = emptiable.length === 0 && !(manager && othersCount > 0)\n\n return (\n <section className=\"space-y-2\" data-testid={testId}>\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <div className=\"min-w-0\">\n {title && <h4 className=\"truncate text-sm font-medium text-foreground\">{title}</h4>}\n <p className=\"text-xs text-muted-foreground\">\n {manager\n ? RECENTLY_DELETED_NOTE\n : `${RECENTLY_DELETED_NOTE} You can remove your own deleted items.`}\n </p>\n </div>\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={busy || trash.isLoading || nothingToEmpty}\n onClick={() => setPending({ kind: 'empty' })}\n data-testid={`${testId}-empty`}\n >\n <Trash2 className=\"mr-1.5 size-4\" />\n {manager ? 'Empty trash' : 'Empty my trash'}\n </Button>\n </div>\n\n {trash.isLoading ? (\n <p className=\"text-sm text-muted-foreground\">Loading\u2026</p>\n ) : trash.isError ? (\n <p className=\"text-sm text-muted-foreground\" data-testid={`${testId}-error`}>\n {trash.error instanceof Error ? trash.error.message : 'Could not load Recently deleted'}\n </p>\n ) : (\n <ul className=\"divide-y divide-border rounded-md border border-border\">\n {items.length === 0 && (\n <li\n className=\"px-3 py-3 text-sm text-muted-foreground\"\n data-testid={`${testId}-empty-state`}\n >\n Nothing in Recently deleted\n </li>\n )}\n {items.map((doc) => (\n <li\n key={doc.external_id}\n className=\"flex items-center justify-between gap-3 px-3 py-2 text-sm\"\n data-testid={`${testId}-row-${doc.external_id}`}\n >\n <span className=\"min-w-0 truncate\">\n <span className=\"font-medium text-foreground\">{doc.file_name || 'Untitled'}</span>\n <span className=\"text-muted-foreground\">\n {' '}\n \u00B7 deleted {formatFriendlyDate(doc.deleted_at)} \u00B7 {formatBytes(doc.bytes)}\n </span>\n </span>\n {doc.restoring ? (\n <span\n className=\"inline-flex shrink-0 items-center gap-1.5 text-sm text-muted-foreground\"\n data-testid={`${testId}-restoring-${doc.external_id}`}\n >\n <Loader2 className=\"size-4 animate-spin\" aria-hidden=\"true\" />\n Restoring\u2026\n </span>\n ) : (\n <span className=\"flex shrink-0 gap-1\">\n {doc.can_restore && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => void restore(doc)}\n data-testid={`${testId}-restore-${doc.external_id}`}\n >\n <RotateCcw className=\"mr-1.5 size-4\" />\n Restore\n </Button>\n )}\n {doc.can_delete && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => setPending({ kind: 'purge', doc })}\n data-testid={`${testId}-delete-${doc.external_id}`}\n >\n Delete permanently\n </Button>\n )}\n </span>\n )}\n </li>\n ))}\n {manager && othersCount > 0 && (\n <li\n className=\"flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground\"\n data-testid={`${testId}-others-private`}\n >\n <Lock className=\"size-4 shrink-0\" aria-hidden=\"true\" />\n {othersCount} private {othersCount === 1 ? 'item' : 'items'} of other members \u00B7{' '}\n {formatBytes(others?.bytes ?? 0)}\n </li>\n )}\n </ul>\n )}\n\n <ConfirmDialog\n isOpen={pending !== null}\n onClose={() => {\n setPending(null)\n setIncludeOthers(false)\n }}\n onConfirm={confirm}\n isLoading={busy}\n title={pending?.kind === 'purge' ? 'Delete permanently?' : 'Empty trash?'}\n description={\n pending?.kind === 'purge'\n ? `${pending.doc.file_name || 'It'} is removed for good now and stops using storage. This cannot be undone.`\n : manager\n ? `${emptiable.length} deleted ${emptiable.length === 1 ? 'item' : 'items'} you can see (${formatBytes(emptiableBytes)}) ${emptiable.length === 1 ? 'is' : 'are'} removed for good now and stop using storage. This cannot be undone.`\n : `Your ${emptiable.length} deleted ${emptiable.length === 1 ? 'item' : 'items'} in this workspace (${formatBytes(emptiableBytes)}) ${emptiable.length === 1 ? 'is' : 'are'} removed for good now. This cannot be undone.`\n }\n confirmText={pending?.kind === 'purge' ? 'Delete permanently' : 'Empty'}\n testId={`${testId}-confirm`}\n >\n {pending?.kind === 'empty' && manager && othersCount > 0 && (\n <label\n className=\"flex items-start gap-2 text-sm text-foreground\"\n data-testid={`${testId}-include-others`}\n >\n <Checkbox\n checked={includeOthers}\n onCheckedChange={(checked) => setIncludeOthers(checked === true)}\n aria-label=\"Also delete other members' private items\"\n />\n <span>\n Also delete {othersCount} private {othersCount === 1 ? 'item' : 'items'} of other\n members ({formatBytes(others?.bytes ?? 0)})\n <span className=\"block text-xs text-muted-foreground\">\n {\n \"You can't see these. Left alone, their owners can still restore them until they're removed automatically.\"\n }\n </span>\n </span>\n </label>\n )}\n </ConfirmDialog>\n </section>\n )\n}\n"],
5
- "mappings": ";AAmGQ,SACY,KADZ;AAzFR,SAAS,gBAAgB;AACzB,SAAS,SAAS,MAAM,WAAW,cAAc;AACjD,SAAS,QAAQ,UAAU,0BAA0B;AACrD,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAA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AA;AAAA,kBACC,SAAS;AAAA,kBACT,iBAAiB,CAAC,YAAY,iBAAiB,YAAY,IAAI;AAAA,kBAC/D,cAAW;AAAA;AAAA,cACb;AAAA,cACA,qBAAC,UAAK;AAAA;AAAA,gBACS;AAAA,gBAAY;AAAA,gBAAU,gBAAgB,IAAI,SAAS;AAAA,gBAAQ;AAAA,gBAC9D,YAAY,QAAQ,SAAS,CAAC;AAAA,gBAAE;AAAA,gBAC1C,oBAAC,UAAK,WAAU,uCAEZ,uHAEJ;AAAA,iBACF;AAAA;AAAA;AAAA,QACF;AAAA;AAAA,IAEJ;AAAA,KACF;AAEJ;",
4
+ "sourcesContent": ["/**\n * ConnectedWorkspaceTrash: one workspace's Recently deleted, as RLS lets the viewer see it.\n *\n * Everyone sees only the deleted documents they could see live (shared ones and their own) and may restore\n * or delete their own. A workspace manager (the project's owner, or the workspace's owner) may restore or\n * delete any listed document and Empty trash for the whole workspace; other members' private deleted\n * documents are never listed to them, only counted, and go only when they tick the opt-in. Anyone else's\n * Empty trash removes just their own deleted documents.\n *\n * Delete permanently and Empty trash look done at once: the dialog closes and the documents leave the list\n * before the server answers (the button shows Emptying\u2026 meanwhile); if it refuses, they come back.\n */\n\nimport { useState } from 'react'\nimport { Loader2, Lock, RotateCcw, Trash2 } from 'lucide-react'\nimport { Button, Checkbox, formatFriendlyDate } from '@arbidocs/react/ui'\nimport { ConfirmDialog } from '../../provider/dialogs'\nimport {\n useHideFromWorkspaceTrash,\n useInvalidateStorage,\n useStorageActions,\n useWorkspaceTrash,\n type DeletedDocument,\n} from '@arbidocs/react'\nimport { useBlocksEnvironment } from '../../provider/environment'\nimport { formatBytes, RECENTLY_DELETED_NOTE } from './storage-labels'\n\ntype Pending = { kind: 'purge'; doc: DeletedDocument } | { kind: 'empty' }\n\nexport interface ConnectedWorkspaceTrashProps {\n workspaceExtId: string\n /** Shown above the list (e.g. the workspace's name on the project's Storage). */\n title?: string\n testId?: string\n}\n\nexport function ConnectedWorkspaceTrash({\n workspaceExtId,\n title,\n testId = 'workspace-trash',\n}: ConnectedWorkspaceTrashProps) {\n const trash = useWorkspaceTrash(workspaceExtId)\n const invalidate = useInvalidateStorage()\n const hide = useHideFromWorkspaceTrash()\n const { purgeDeletedDocuments, restoreDocuments } = useStorageActions()\n const { notify } = useBlocksEnvironment()\n const [pending, setPending] = useState<Pending | null>(null)\n const [includeOthers, setIncludeOthers] = useState(false)\n const [busy, setBusy] = useState(false)\n // Delete permanently / Empty trash on its way (the dialog has closed, the documents are off the list).\n const [removing, setRemoving] = useState<Pending['kind'] | null>(null)\n\n const page = trash.data\n const items = page?.items ?? []\n const manager = page?.can_manage ?? false\n const others = page?.others_private\n const othersCount = others?.count ?? 0\n // What Empty trash removes without the opt-in: everything listed for a manager, the viewer's own otherwise.\n // Documents being restored are on their way back, not in the trash any more.\n const removable = items.filter((d) => !d.restoring)\n const emptiable = manager ? removable : removable.filter((d) => d.mine)\n const emptiableBytes = emptiable.reduce((sum, d) => sum + d.bytes, 0)\n\n // The refetch after an action is not waited for: the action's own answer is what the viewer waits on.\n const run = async (action: () => Promise<string>, failure: string, undo?: () => void) => {\n setBusy(true)\n try {\n notify(await action(), 'success')\n void invalidate()\n } catch (error) {\n undo?.()\n notify(error instanceof Error ? error.message : failure, 'error')\n } finally {\n setBusy(false)\n setRemoving(null)\n setPending(null)\n setIncludeOthers(false)\n }\n }\n\n const restore = (doc: DeletedDocument) =>\n run(async () => {\n await restoreDocuments(workspaceExtId, [doc.external_id])\n return 'Restoring. It reappears in the workspace when its files are back.'\n }, 'Could not restore')\n\n const confirm = () => {\n if (!pending) return\n // Off the list and the dialog closed now; back on the list if the server refuses.\n const withOthers = pending.kind === 'empty' && manager && includeOthers\n const undo = hide(\n workspaceExtId,\n pending.kind === 'purge' ? [pending.doc.external_id] : emptiable.map((d) => d.external_id),\n withOthers\n )\n setRemoving(pending.kind)\n setPending(null)\n if (pending.kind === 'purge') {\n void run(\n async () => {\n await purgeDeletedDocuments(workspaceExtId, { externalIds: [pending.doc.external_id] })\n return `Deleted permanently \u00B7 ${formatBytes(pending.doc.bytes)} freed`\n },\n 'Could not delete permanently',\n undo\n )\n return\n }\n const freed = emptiableBytes + (withOthers ? (others?.bytes ?? 0) : 0)\n void run(\n async () => {\n const removed = await purgeDeletedDocuments(workspaceExtId, {\n includeOthersPrivate: withOthers,\n })\n return `Trash emptied \u00B7 ${removed.length} ${removed.length === 1 ? 'item' : 'items'} \u00B7 ${formatBytes(freed)} freed`\n },\n 'Could not empty the trash',\n undo\n )\n }\n\n const nothingToEmpty = emptiable.length === 0 && !(manager && othersCount > 0)\n\n return (\n <section className=\"space-y-2\" data-testid={testId}>\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <div className=\"min-w-0\">\n {title && <h4 className=\"truncate text-sm font-medium text-foreground\">{title}</h4>}\n <p className=\"text-xs text-muted-foreground\">\n {manager\n ? RECENTLY_DELETED_NOTE\n : `${RECENTLY_DELETED_NOTE} You can remove your own deleted items.`}\n </p>\n </div>\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={busy || trash.isLoading || nothingToEmpty}\n onClick={() => setPending({ kind: 'empty' })}\n data-testid={`${testId}-empty`}\n >\n {removing === 'empty' ? (\n <>\n <Loader2 className=\"mr-1.5 size-4 animate-spin\" aria-hidden=\"true\" />\n Emptying\u2026\n </>\n ) : (\n <>\n <Trash2 className=\"mr-1.5 size-4\" />\n {manager ? 'Empty trash' : 'Empty my trash'}\n </>\n )}\n </Button>\n </div>\n\n {trash.isLoading ? (\n <p className=\"text-sm text-muted-foreground\">Loading\u2026</p>\n ) : trash.isError ? (\n <p className=\"text-sm text-muted-foreground\" data-testid={`${testId}-error`}>\n {trash.error instanceof Error ? trash.error.message : 'Could not load Recently deleted'}\n </p>\n ) : (\n <ul className=\"divide-y divide-border rounded-md border border-border\">\n {items.length === 0 && (\n <li\n className=\"px-3 py-3 text-sm text-muted-foreground\"\n data-testid={`${testId}-empty-state`}\n >\n Nothing in Recently deleted\n </li>\n )}\n {items.map((doc) => (\n <li\n key={doc.external_id}\n className=\"flex items-center justify-between gap-3 px-3 py-2 text-sm\"\n data-testid={`${testId}-row-${doc.external_id}`}\n >\n <span className=\"min-w-0 truncate\">\n <span className=\"font-medium text-foreground\">{doc.file_name || 'Untitled'}</span>\n <span className=\"text-muted-foreground\">\n {' '}\n \u00B7 deleted {formatFriendlyDate(doc.deleted_at)} \u00B7 {formatBytes(doc.bytes)}\n </span>\n </span>\n {doc.restoring ? (\n <span\n className=\"inline-flex shrink-0 items-center gap-1.5 text-sm text-muted-foreground\"\n data-testid={`${testId}-restoring-${doc.external_id}`}\n >\n <Loader2 className=\"size-4 animate-spin\" aria-hidden=\"true\" />\n Restoring\u2026\n </span>\n ) : (\n <span className=\"flex shrink-0 gap-1\">\n {doc.can_restore && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => void restore(doc)}\n data-testid={`${testId}-restore-${doc.external_id}`}\n >\n <RotateCcw className=\"mr-1.5 size-4\" />\n Restore\n </Button>\n )}\n {doc.can_delete && (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={busy}\n onClick={() => setPending({ kind: 'purge', doc })}\n data-testid={`${testId}-delete-${doc.external_id}`}\n >\n Delete permanently\n </Button>\n )}\n </span>\n )}\n </li>\n ))}\n {manager && othersCount > 0 && (\n <li\n className=\"flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground\"\n data-testid={`${testId}-others-private`}\n >\n <Lock className=\"size-4 shrink-0\" aria-hidden=\"true\" />\n {othersCount} private {othersCount === 1 ? 'item' : 'items'} of other members \u00B7{' '}\n {formatBytes(others?.bytes ?? 0)}\n </li>\n )}\n </ul>\n )}\n\n <ConfirmDialog\n isOpen={pending !== null}\n onClose={() => {\n setPending(null)\n setIncludeOthers(false)\n }}\n onConfirm={confirm}\n isLoading={busy}\n title={pending?.kind === 'purge' ? 'Delete permanently?' : 'Empty trash?'}\n description={\n pending?.kind === 'purge'\n ? `${pending.doc.file_name || 'It'} is removed for good now and stops using storage. This cannot be undone.`\n : manager\n ? `${emptiable.length} deleted ${emptiable.length === 1 ? 'item' : 'items'} you can see (${formatBytes(emptiableBytes)}) ${emptiable.length === 1 ? 'is' : 'are'} removed for good now and stop using storage. This cannot be undone.`\n : `Your ${emptiable.length} deleted ${emptiable.length === 1 ? 'item' : 'items'} in this workspace (${formatBytes(emptiableBytes)}) ${emptiable.length === 1 ? 'is' : 'are'} removed for good now. This cannot be undone.`\n }\n confirmText={pending?.kind === 'purge' ? 'Delete permanently' : 'Empty'}\n testId={`${testId}-confirm`}\n >\n {pending?.kind === 'empty' && manager && othersCount > 0 && (\n <label\n className=\"flex items-start gap-2 text-sm text-foreground\"\n data-testid={`${testId}-include-others`}\n >\n <Checkbox\n checked={includeOthers}\n onCheckedChange={(checked) => setIncludeOthers(checked === true)}\n aria-label=\"Also delete other members' private items\"\n />\n <span>\n Also delete {othersCount} private {othersCount === 1 ? 'item' : 'items'} of other\n members ({formatBytes(others?.bytes ?? 0)})\n <span className=\"block text-xs text-muted-foreground\">\n {\n \"You can't see these. Left alone, their owners can still restore them until they're removed automatically.\"\n }\n </span>\n </span>\n </label>\n )}\n </ConfirmDialog>\n </section>\n )\n}\n"],
5
+ "mappings": ";AA8HQ,SAgBI,UAfQ,KADZ;AAjHR,SAAS,gBAAgB;AACzB,SAAS,SAAS,MAAM,WAAW,cAAc;AACjD,SAAS,QAAQ,UAAU,0BAA0B;AACrD,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,4BAA4B;AACrC,SAAS,aAAa,6BAA6B;AAW5C,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA,SAAS;AACX,GAAiC;AAC/B,QAAM,QAAQ,kBAAkB,cAAc;AAC9C,QAAM,aAAa,qBAAqB;AACxC,QAAM,OAAO,0BAA0B;AACvC,QAAM,EAAE,uBAAuB,iBAAiB,IAAI,kBAAk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AW,IAAI,OAAO,KAAK;AAAA,QAEjL,aAAa,SAAS,SAAS,UAAU,uBAAuB;AAAA,QAChE,QAAQ,GAAG,MAAM;AAAA,QAEhB,mBAAS,SAAS,WAAW,WAAW,cAAc,KACrD;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,eAAa,GAAG,MAAM;AAAA,YAEtB;AAAA;AAAA,gBAAC;AAAA;AAAA,kBACC,SAAS;AAAA,kBACT,iBAAiB,CAAC,YAAY,iBAAiB,YAAY,IAAI;AAAA,kBAC/D,cAAW;AAAA;AAAA,cACb;AAAA,cACA,qBAAC,UAAK;AAAA;AAAA,gBACS;AAAA,gBAAY;AAAA,gBAAU,gBAAgB,IAAI,SAAS;AAAA,gBAAQ;AAAA,gBAC9D,YAAY,QAAQ,SAAS,CAAC;AAAA,gBAAE;AAAA,gBAC1C,oBAAC,UAAK,WAAU,uCAEZ,uHAEJ;AAAA,iBACF;AAAA;AAAA;AAAA,QACF;AAAA;AAAA,IAEJ;AAAA,KACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -805,6 +805,12 @@ var toRowView = (r) => ({
805
805
  titles: { ...r.titles ?? {} },
806
806
  shared: r.shared ?? true
807
807
  });
808
+ var GRID_TYPES = new Set(chunkQ25CZLK6_cjs.DATABASE_COLUMN_TYPES);
809
+ var isGridType = (type) => GRID_TYPES.has(type);
810
+ var toColumnView = (c) => ({
811
+ ...c,
812
+ type: isGridType(c.type) ? c.type : "text"
813
+ });
808
814
  function TableViewBlock({
809
815
  viewId,
810
816
  actions,
@@ -813,34 +819,25 @@ function TableViewBlock({
813
819
  testId
814
820
  }) {
815
821
  const l = { ...DEFAULT_TABLE_VIEW_BLOCK_LABELS, ...labels };
816
- const view = react.useTableView(viewId || null);
817
- const target = view.data?.target ?? null;
818
- const databaseId = target && target.startsWith("dbs-") ? target : null;
819
- const database = react.useDatabase(databaseId);
820
- const rows = react.useDatabaseRows(databaseId, "", { view: viewId });
821
- const columns = react$1.useMemo(() => {
822
- const all = database.data?.columns ?? [];
823
- const wanted = view.data?.spec.columns ?? [];
824
- if (!wanted.length) return all;
825
- const byId = new Map(all.map((c) => [c.id, c]));
826
- return wanted.flatMap((id) => byId.get(id) ?? []);
827
- }, [database.data, view.data]);
822
+ const read = react.useTableViewRows(viewId || null);
823
+ const data = read.data;
824
+ const columns = react$1.useMemo(() => (data?.columns ?? []).map(toColumnView), [data]);
825
+ const rows = react$1.useMemo(() => (data?.rows ?? []).map(toRowView), [data]);
828
826
  let body;
829
- if (view.isError || database.isError) {
827
+ if (read.isError) {
830
828
  body = /* @__PURE__ */ jsxRuntime.jsx("p", { className: "p-4 text-sm text-muted-foreground", children: l.unavailable });
831
- } else if (view.data && !databaseId) {
829
+ } else if (data && !data.database) {
832
830
  body = /* @__PURE__ */ jsxRuntime.jsx("p", { className: "p-4 text-sm text-muted-foreground", children: l.notADatabase });
833
- } else if (!view.data || !database.data) {
831
+ } else if (!data) {
834
832
  body = /* @__PURE__ */ jsxRuntime.jsx("p", { className: "p-4 text-sm text-muted-foreground", children: l.loading });
835
833
  } else {
836
834
  body = /* @__PURE__ */ jsxRuntime.jsx(
837
835
  chunkQ25CZLK6_cjs.DatabaseTable,
838
836
  {
839
837
  columns,
840
- rows: (rows.data?.rows ?? []).map(toRowView),
838
+ rows,
841
839
  readOnly: true,
842
840
  isFiltered: true,
843
- isLoading: rows.isLoading,
844
841
  gridId: `page-view-${viewId}`,
845
842
  height: "100%",
846
843
  testId: testId && `${testId}-table`
@@ -856,7 +853,7 @@ function TableViewBlock({
856
853
  children: [
857
854
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 border-b border-border px-4 py-2", children: [
858
855
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Table2, { className: "size-4 text-muted-foreground" }),
859
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-sm font-medium", "data-testid": testId && `${testId}-name`, children: view.data?.spec.name ?? "" }),
856
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-sm font-medium", "data-testid": testId && `${testId}-name`, children: data?.view.spec.name ?? "" }),
860
857
  actions && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ml-auto flex gap-1", children: actions })
861
858
  ] }),
862
859
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1", children: body })