@arbidocs/react 0.5.151 → 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.
Files changed (78) hide show
  1. package/dist/artifacts/index.cjs +46 -46
  2. package/dist/calls/livekit/index.cjs +51 -51
  3. package/dist/{chunk-VXFTVWEI.cjs → chunk-4VHECR5O.cjs} +44 -44
  4. package/dist/{chunk-VXFTVWEI.cjs.map → chunk-4VHECR5O.cjs.map} +1 -1
  5. package/dist/{chunk-P2DPOZBS.cjs → chunk-5ZNO77YB.cjs} +11 -2
  6. package/dist/chunk-5ZNO77YB.cjs.map +1 -0
  7. package/dist/{chunk-MK5L56Z3.cjs → chunk-BUMLF3MS.cjs} +60 -60
  8. package/dist/{chunk-MK5L56Z3.cjs.map → chunk-BUMLF3MS.cjs.map} +1 -1
  9. package/dist/{chunk-6RRKO4ZK.cjs → chunk-DBWW6DXJ.cjs} +5 -5
  10. package/dist/{chunk-6RRKO4ZK.cjs.map → chunk-DBWW6DXJ.cjs.map} +1 -1
  11. package/dist/{chunk-KULS4YWP.cjs → chunk-DQODLWFX.cjs} +3 -3
  12. package/dist/{chunk-KULS4YWP.cjs.map → chunk-DQODLWFX.cjs.map} +1 -1
  13. package/dist/{chunk-GFX7LQGR.cjs → chunk-HISGJISX.cjs} +67 -67
  14. package/dist/{chunk-GFX7LQGR.cjs.map → chunk-HISGJISX.cjs.map} +1 -1
  15. package/dist/{chunk-BI7HFGXF.cjs → chunk-NJWQPNGD.cjs} +14 -14
  16. package/dist/{chunk-BI7HFGXF.cjs.map → chunk-NJWQPNGD.cjs.map} +1 -1
  17. package/dist/{chunk-SKJWJ3OY.cjs → chunk-WWGUGZZN.cjs} +39 -39
  18. package/dist/{chunk-SKJWJ3OY.cjs.map → chunk-WWGUGZZN.cjs.map} +1 -1
  19. package/dist/{chunk-B6T54X65.cjs → chunk-XQLJSNAL.cjs} +5 -5
  20. package/dist/chunk-XQLJSNAL.cjs.map +1 -0
  21. package/dist/datasets/aggregate-source.js +133 -0
  22. package/dist/datasets/aggregate-source.js.map +7 -0
  23. package/dist/datasets/aggregate.js +72 -22
  24. package/dist/datasets/aggregate.js.map +2 -2
  25. package/dist/datasets/index.js +27 -1
  26. package/dist/datasets/index.js.map +2 -2
  27. package/dist/datasets/rows-source.js.map +2 -2
  28. package/dist/datasets/sources/activity.js +44 -9
  29. package/dist/datasets/sources/activity.js.map +2 -2
  30. package/dist/datasets/sources/conversations.js +38 -8
  31. package/dist/datasets/sources/conversations.js.map +2 -2
  32. package/dist/datasets/sources/database.js +17 -9
  33. package/dist/datasets/sources/database.js.map +2 -2
  34. package/dist/datasets/sources/documents.js +45 -7
  35. package/dist/datasets/sources/documents.js.map +2 -2
  36. package/dist/datasets/sources/facts.js +32 -6
  37. package/dist/datasets/sources/facts.js.map +3 -3
  38. package/dist/datasets/sources/projects.js +1 -1
  39. package/dist/datasets/sources/projects.js.map +2 -2
  40. package/dist/datasets/sources/tags.js +38 -6
  41. package/dist/datasets/sources/tags.js.map +3 -3
  42. package/dist/datasets/sources/usage.js +29 -31
  43. package/dist/datasets/sources/usage.js.map +2 -2
  44. package/dist/datasets/sources/workflows.js +56 -22
  45. package/dist/datasets/sources/workflows.js.map +2 -2
  46. package/dist/datasets/sources/workspaces.js +1 -1
  47. package/dist/datasets/sources/workspaces.js.map +2 -2
  48. package/dist/datasets/types.js.map +1 -1
  49. package/dist/datasets/workspace-aggregate.js +64 -0
  50. package/dist/datasets/workspace-aggregate.js.map +7 -0
  51. package/dist/document-tools/core.cjs +102 -102
  52. package/dist/document-tools/core.d.ts +2 -2
  53. package/dist/document-tools/index.cjs +104 -104
  54. package/dist/document-tools/index.d.ts +2 -2
  55. package/dist/{file-shares.d-CamKxNLC.d.ts → file-shares.d-CyTnJ2Re.d.ts} +11 -0
  56. package/dist/index.cjs +2956 -2489
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/{index.d-DbcrFwS6.d.ts → index.d-Dy_Pz6Vl.d.ts} +4 -0
  59. package/dist/index.d.ts +145 -7
  60. package/dist/index.js +11 -2
  61. package/dist/index.js.map +2 -2
  62. package/dist/projects.js +9 -0
  63. package/dist/projects.js.map +2 -2
  64. package/dist/query-keys.js +9 -0
  65. package/dist/query-keys.js.map +2 -2
  66. package/dist/shell/index.cjs +40 -40
  67. package/dist/storage.js +24 -1
  68. package/dist/storage.js.map +2 -2
  69. package/dist/table-views.js +19 -1
  70. package/dist/table-views.js.map +2 -2
  71. package/dist/ui/card.js +2 -2
  72. package/dist/ui/card.js.map +2 -2
  73. package/dist/ui/index.cjs +181 -181
  74. package/dist/ui/index.d.ts +1 -1
  75. package/dist/viewers/index.cjs +9 -9
  76. package/package.json +3 -3
  77. package/dist/chunk-B6T54X65.cjs.map +0 -1
  78. package/dist/chunk-P2DPOZBS.cjs.map +0 -1
@@ -3,8 +3,12 @@ import { useArbi } from "../../useArbi.js";
3
3
  import { useWorkspaceActivity } from "../../hooks.js";
4
4
  import { useArbiSessionState } from "../../session/index.js";
5
5
  import { useSwitchWorkspace } from "../../workspaces/switch.js";
6
+ import {
7
+ cellText,
8
+ defineAggregateSource,
9
+ useOpenWorkspace
10
+ } from "../aggregate-source.js";
6
11
  import { useNames } from "../members.js";
7
- import { defineRowsSource, staticFields } from "../rows-source.js";
8
12
  import { DEFAULT_WORKFLOWS_SOURCE_LABELS } from "./workflows.js";
9
13
  const ENTRIES = 100;
10
14
  const DEFAULT_ACTIVITY_SOURCE_LABELS = {
@@ -40,13 +44,40 @@ function createActivitySource(labels) {
40
44
  { id: "item", label: l.item, type: "string" },
41
45
  { id: "status", label: l.status, type: "string" }
42
46
  ];
43
- return defineRowsSource({
47
+ const byId = new Map(fields.map((f) => [f.id, f]));
48
+ const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
49
+ const areas = new Map(Object.entries(l.areas));
50
+ const kindOf = (kind) => kind ? l.kinds[kind] ?? inWords(kind) : null;
51
+ const statusOf = (status) => status ? l.statuses[status] ?? inWords(status) : null;
52
+ return defineAggregateSource({
44
53
  id: "activity",
45
- scope: "workspace",
54
+ source: "activity",
46
55
  label: l.source,
47
56
  description: l.description,
48
- useFields: staticFields(fields),
49
- useRows(_params, enabled) {
57
+ fields,
58
+ useAggregateFields(enabled) {
59
+ const nameOf = useNames(enabled);
60
+ return useMemo(
61
+ () => [
62
+ { field: field("when"), from: ["when"] },
63
+ {
64
+ field: field("area"),
65
+ from: ["area"],
66
+ value: ([a]) => {
67
+ const area = cellText(a);
68
+ return area ? areas.get(area) ?? area : null;
69
+ }
70
+ },
71
+ { field: field("kind"), from: ["kind"], value: ([k]) => kindOf(cellText(k)) },
72
+ { field: field("person"), from: ["person"], value: ([u]) => nameOf(cellText(u)) },
73
+ { field: field("item"), from: ["item"] },
74
+ { field: field("status"), from: ["status"], value: ([st]) => statusOf(cellText(st)) }
75
+ ],
76
+ [nameOf]
77
+ );
78
+ },
79
+ useWorkspace: useOpenWorkspace,
80
+ useRecords(_params, enabled) {
50
81
  const arbi = useArbi();
51
82
  const workspaceId = useArbiSessionState((s) => s.workspaceId) ?? void 0;
52
83
  const { settled, openSelectedWorkspace } = useSwitchWorkspace();
@@ -63,16 +94,20 @@ function createActivitySource(labels) {
63
94
  () => feed.data?.pages.flatMap(
64
95
  (page) => page.items.map((e) => ({
65
96
  when: e.created_at,
66
- area: l.areas[e.source] ?? e.source,
67
- kind: l.kinds[e.kind] ?? inWords(e.kind),
97
+ area: areas.get(e.source) ?? e.source,
98
+ kind: kindOf(e.kind),
68
99
  person: nameOf(e.actor_ext_id),
69
100
  item: e.conversation_title || e.document_name || e.workflow_name || null,
70
- status: e.status ? l.statuses[e.status] ?? inWords(e.status) : null
101
+ status: statusOf(e.status ?? null)
71
102
  }))
72
103
  ),
73
104
  [feed.data, nameOf]
74
105
  );
75
- return { rows, isLoading: feed.isLoading && !!workspaceId, error: feed.error };
106
+ return {
107
+ rows,
108
+ isLoading: enabled && feed.isPending && !!workspaceId,
109
+ error: feed.error
110
+ };
76
111
  }
77
112
  });
78
113
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/datasets/sources/activity.ts"],
4
- "sourcesContent": ["/**\n * The open workspace's recent activity as a dataset: a row per entry of its activity feed (thread\n * history, people posting, uploads, new versions and signatures, workflow runs), newest first, as\n * far as the feed's first page reaches (up to 100 entries, cached apart from the feed's own pages).\n * Titles and names decrypt only while the session has the workspace open, so it is re-opened\n * before the read, as the activity feed does. Activity by day, by person, or the\n * workflow runs and how they ended, are a group-by away. Reads the shared feed\n * (`useWorkspaceActivity`), so only what the user can see is counted.\n */\nimport { useMemo } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from '../../useArbi'\nimport { useWorkspaceActivity } from '../../hooks'\nimport { useArbiSessionState } from '../../session'\nimport { useSwitchWorkspace } from '../../workspaces/switch'\nimport { useNames } from '../members'\nimport { defineRowsSource, staticFields } from '../rows-source'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\nimport { DEFAULT_WORKFLOWS_SOURCE_LABELS } from './workflows'\n\ntype ActivityEntry = components['schemas']['WorkspaceActivityEntry']\ntype ActivityArea = components['schemas']['WorkspaceActivitySource']\n\n/** Entries read: the most the feed gives in one page. */\nconst ENTRIES = 100\n\nexport interface ActivitySourceLabels {\n source: string\n description: string\n when: string\n area: string\n areas: Record<ActivityArea, string>\n kind: string\n /** An entry's kind by the server's name; one not listed is shown in words (`task_done`: \"Task done\"). */\n kinds: Readonly<Record<string, string>>\n person: string\n item: string\n status: string\n /** A workflow run's status by the server's name; one not listed is shown as it comes. */\n statuses: Readonly<Record<string, string>>\n}\n\nexport const DEFAULT_ACTIVITY_SOURCE_LABELS: ActivitySourceLabels = {\n source: 'Recent activity',\n description:\n 'The latest activity of the open workspace: threads, messages, documents and workflow runs.',\n when: 'When',\n area: 'Area',\n areas: { thread: 'Threads', message: 'Messages', document: 'Documents', workflow: 'Workflows' },\n kind: 'What happened',\n kinds: {\n message_posted: 'Message posted',\n document_uploaded: 'Document uploaded',\n document_version: 'New version',\n document_signed: 'Document signed',\n workflow_run: 'Workflow run',\n },\n person: 'Person',\n item: 'Item',\n status: 'Status',\n statuses: DEFAULT_WORKFLOWS_SOURCE_LABELS.results,\n}\n\nconst inWords = (name: string) => {\n const words = name.replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\nexport function createActivitySource(labels?: Partial<ActivitySourceLabels>): DataSource {\n const l = { ...DEFAULT_ACTIVITY_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'when', label: l.when, type: 'date' },\n { id: 'area', label: l.area, type: 'string', options: Object.values(l.areas) },\n { id: 'kind', label: l.kind, type: 'string' },\n { id: 'person', label: l.person, type: 'string' },\n { id: 'item', label: l.item, type: 'string' },\n { id: 'status', label: l.status, type: 'string' },\n ]\n return defineRowsSource({\n id: 'activity',\n scope: 'workspace',\n label: l.source,\n description: l.description,\n useFields: staticFields(fields),\n useRows(_params, enabled) {\n const arbi = useArbi()\n const workspaceId = useArbiSessionState((s) => s.workspaceId) ?? undefined\n const { settled, openSelectedWorkspace } = useSwitchWorkspace()\n const feed = useWorkspaceActivity(workspaceId, {\n enabled: enabled && arbi.isLoggedIn,\n limit: ENTRIES,\n beforeFetch: async () => {\n await settled()\n await openSelectedWorkspace()\n },\n })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n feed.data?.pages.flatMap((page) =>\n (page.items as ActivityEntry[]).map((e): DatasetRow => ({\n when: e.created_at,\n area: l.areas[e.source] ?? e.source,\n kind: l.kinds[e.kind] ?? inWords(e.kind),\n person: nameOf(e.actor_ext_id),\n item: e.conversation_title || e.document_name || e.workflow_name || null,\n status: e.status ? (l.statuses[e.status] ?? inWords(e.status)) : null,\n }))\n ),\n [feed.data, nameOf]\n )\n return { rows, isLoading: feed.isLoading && !!workspaceId, error: feed.error }\n },\n })\n}\n"],
5
- "mappings": "AASA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,4BAA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;AAAA,IACJ,OAAO;AAAA,IACP,OAAO,EAAE;AAAA,IACT,aAAa,EAAE;AAAA,IACf,WAAW,aAAa,MAAM;AAAA,IAC9B,QAAQ,SAAS,SAAS;AACxB,YAAM,OAAO,QAAQ;AACrB,YAAM,cAAc,oBAAoB,CAAC,MAAM,EAAE,WAAW,KAAK;AACjE,YAAM,EAAE,SAAS,sBAAsB,IAAI,mBAAmB;AAC9D,YAAM,OAAO,qBAAqB,aAAa;AAAA,QAC7C,SAAS,WAAW,KAAK;AAAA,QACzB,OAAO;AAAA,QACP,aAAa,YAAY;AACvB,gBAAM,QAAQ;AACd,gBAAM,sBAAsB;AAAA,QAC9B;AAAA,MACF,CAAC;AACD,YAAM,SAAS,SAAS,OAAO;AAC/B,YAAM,OAAO;AAAA,QACX,MACE,KAAK,MAAM,MAAM;AAAA,UAAQ,CAAC,SACvB,KAAK,MAA0B,IAAI,CAAC,OAAmB;AAAA,YACtD,MAAM,EAAE;AAAA,YACR,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,EAAE;AAAA,YAC7B,MAAM,EAAE,MAAM,EAAE,IAAI,KAAK,QAAQ,EAAE,IAAI;AAAA,YACvC,QAAQ,OAAO,EAAE,YAAY;AAAA,YAC7B,MAAM,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,iBAAiB;AAAA,YACpE,QAAQ,EAAE,SAAU,EAAE,SAAS,EAAE,MAAM,KAAK,QAAQ,EAAE,MAAM,IAAK;AAAA,UACnE,EAAE;AAAA,QACJ;AAAA,QACF,CAAC,KAAK,MAAM,MAAM;AAAA,MACpB;AACA,aAAO,EAAE,MAAM,WAAW,KAAK,aAAa,CAAC,CAAC,aAAa,OAAO,KAAK,MAAM;AAAA,IAC/E;AAAA,EACF,CAAC;AACH;",
4
+ "sourcesContent": ["/**\n * The open workspace's recent activity as a dataset: a row per entry of its activity feed (thread\n * history, people posting, uploads, new versions and signatures, workflow runs), newest first, as\n * far as the feed's first page reaches (up to 100 entries, cached apart from the feed's own pages).\n * Titles and names decrypt only while the session has the workspace open, so it is re-opened\n * before the read, as the activity feed does. Activity by day, by person, or the\n * workflow runs and how they ended, are a group-by away. Reads the shared feed\n * (`useWorkspaceActivity`), so only what the user can see is counted.\n */\nimport { useMemo } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from '../../useArbi'\nimport { useWorkspaceActivity } from '../../hooks'\nimport { useArbiSessionState } from '../../session'\nimport { useSwitchWorkspace } from '../../workspaces/switch'\nimport {\n cellText,\n defineAggregateSource,\n useOpenWorkspace,\n type AggregateField,\n} from '../aggregate-source'\nimport { useNames } from '../members'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\nimport { DEFAULT_WORKFLOWS_SOURCE_LABELS } from './workflows'\n\ntype ActivityEntry = components['schemas']['WorkspaceActivityEntry']\ntype ActivityArea = components['schemas']['WorkspaceActivitySource']\n\n/** Entries read: the most the feed gives in one page. */\nconst ENTRIES = 100\n\nexport interface ActivitySourceLabels {\n source: string\n description: string\n when: string\n area: string\n areas: Record<ActivityArea, string>\n kind: string\n /** An entry's kind by the server's name; one not listed is shown in words (`task_done`: \"Task done\"). */\n kinds: Readonly<Record<string, string>>\n person: string\n item: string\n status: string\n /** A workflow run's status by the server's name; one not listed is shown as it comes. */\n statuses: Readonly<Record<string, string>>\n}\n\nexport const DEFAULT_ACTIVITY_SOURCE_LABELS: ActivitySourceLabels = {\n source: 'Recent activity',\n description:\n 'The latest activity of the open workspace: threads, messages, documents and workflow runs.',\n when: 'When',\n area: 'Area',\n areas: { thread: 'Threads', message: 'Messages', document: 'Documents', workflow: 'Workflows' },\n kind: 'What happened',\n kinds: {\n message_posted: 'Message posted',\n document_uploaded: 'Document uploaded',\n document_version: 'New version',\n document_signed: 'Document signed',\n workflow_run: 'Workflow run',\n },\n person: 'Person',\n item: 'Item',\n status: 'Status',\n statuses: DEFAULT_WORKFLOWS_SOURCE_LABELS.results,\n}\n\nconst inWords = (name: string) => {\n const words = name.replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\nexport function createActivitySource(labels?: Partial<ActivitySourceLabels>): DataSource {\n const l = { ...DEFAULT_ACTIVITY_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'when', label: l.when, type: 'date' },\n { id: 'area', label: l.area, type: 'string', options: Object.values(l.areas) },\n { id: 'kind', label: l.kind, type: 'string' },\n { id: 'person', label: l.person, type: 'string' },\n { id: 'item', label: l.item, type: 'string' },\n { id: 'status', label: l.status, type: 'string' },\n ]\n const byId = new Map(fields.map((f) => [f.id, f]))\n const field = (id: string): DatasetField => byId.get(id) ?? { id, label: id, type: 'string' }\n const areas = new Map<string, string>(Object.entries(l.areas))\n const kindOf = (kind: string | null) => (kind ? (l.kinds[kind] ?? inWords(kind)) : null)\n const statusOf = (status: string | null) =>\n status ? (l.statuses[status] ?? inWords(status)) : null\n return defineAggregateSource({\n id: 'activity',\n source: 'activity',\n label: l.source,\n description: l.description,\n fields,\n useAggregateFields(enabled) {\n const nameOf = useNames(enabled)\n return useMemo(\n (): AggregateField[] => [\n { field: field('when'), from: ['when'] },\n {\n field: field('area'),\n from: ['area'],\n value: ([a]) => {\n const area = cellText(a)\n return area ? (areas.get(area) ?? area) : null\n },\n },\n { field: field('kind'), from: ['kind'], value: ([k]) => kindOf(cellText(k)) },\n { field: field('person'), from: ['person'], value: ([u]) => nameOf(cellText(u)) },\n { field: field('item'), from: ['item'] },\n { field: field('status'), from: ['status'], value: ([st]) => statusOf(cellText(st)) },\n ],\n [nameOf]\n )\n },\n useWorkspace: useOpenWorkspace,\n useRecords(_params, enabled) {\n const arbi = useArbi()\n const workspaceId = useArbiSessionState((s) => s.workspaceId) ?? undefined\n const { settled, openSelectedWorkspace } = useSwitchWorkspace()\n const feed = useWorkspaceActivity(workspaceId, {\n enabled: enabled && arbi.isLoggedIn,\n limit: ENTRIES,\n beforeFetch: async () => {\n await settled()\n await openSelectedWorkspace()\n },\n })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n feed.data?.pages.flatMap((page) =>\n (page.items as ActivityEntry[]).map((e): DatasetRow => ({\n when: e.created_at,\n area: areas.get(e.source) ?? e.source,\n kind: kindOf(e.kind),\n person: nameOf(e.actor_ext_id),\n item: e.conversation_title || e.document_name || e.workflow_name || null,\n status: statusOf(e.status ?? null),\n }))\n ),\n [feed.data, nameOf]\n )\n return {\n rows,\n isLoading: enabled && feed.isPending && !!workspaceId,\n error: feed.error,\n }\n },\n })\n}\n"],
5
+ "mappings": "AASA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AAEzB,SAAS,uCAAuC;AAMhD,MAAM,UAAU;AAkBT,MAAM,iCAAuD;AAAA,EAClE,QAAQ;AAAA,EACR,aACE;AAAA,EACF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO,EAAE,QAAQ,WAAW,SAAS,YAAY,UAAU,aAAa,UAAU,YAAY;AAAA,EAC9F,MAAM;AAAA,EACN,OAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,IACjB,cAAc;AAAA,EAChB;AAAA,EACA,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU,gCAAgC;AAC5C;AAEA,MAAM,UAAU,CAAC,SAAiB;AAChC,QAAM,QAAQ,KAAK,WAAW,KAAK,GAAG;AACtC,SAAO,MAAM,OAAO,CAAC,EAAE,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;AAEO,SAAS,qBAAqB,QAAoD;AACvF,QAAM,IAAI,EAAE,GAAG,gCAAgC,GAAG,OAAO;AACzD,QAAM,SAAyB;AAAA,IAC7B,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,OAAO;AAAA,IAC1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YACpE,QAAQ,SAAS,EAAE,UAAU,IAAI;AAAA,UACnC,EAAE;AAAA,QACJ;AAAA,QACF,CAAC,KAAK,MAAM,MAAM;AAAA,MACpB;AACA,aAAO;AAAA,QACL;AAAA,QACA,WAAW,WAAW,KAAK,aAAa,CAAC,CAAC;AAAA,QAC1C,OAAO,KAAK;AAAA,MACd;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,8 @@
1
1
  import { useMemo } from "react";
2
2
  import { useArbi } from "../../useArbi.js";
3
3
  import { useConversations } from "../../hooks.js";
4
+ import { cellText, defineAggregateSource } from "../aggregate-source.js";
4
5
  import { useNames } from "../members.js";
5
- import { defineRowsSource, staticFields } from "../rows-source.js";
6
6
  const DEFAULT_CONVERSATIONS_SOURCE_LABELS = {
7
7
  source: "Threads",
8
8
  description: "The threads and tasks of the open workspace: activity, status, owners, due dates.",
@@ -36,15 +36,45 @@ function createConversationsSource(labels) {
36
36
  { id: "messages", label: l.messages, type: "number" },
37
37
  { id: "shared", label: l.shared, type: "boolean" }
38
38
  ];
39
- return defineRowsSource({
39
+ const byId = new Map(fields.map((f) => [f.id, f]));
40
+ const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
41
+ const statusOf = (status) => status === "todo" || status === "generating" || status === "done" ? l.statuses[status] : status;
42
+ function useWorkspaceOf(params) {
43
+ const arbi = useArbi();
44
+ return typeof params.workspaceId === "string" && params.workspaceId ? params.workspaceId : arbi.hasWorkspace ? arbi.getWorkspaceId() : void 0;
45
+ }
46
+ return defineAggregateSource({
40
47
  id: "conversations",
41
- scope: "workspace",
48
+ source: "conversations",
42
49
  label: l.source,
43
50
  description: l.description,
44
- useFields: staticFields(fields),
45
- useRows(params, enabled) {
46
- const arbi = useArbi();
47
- const workspaceId = typeof params.workspaceId === "string" && params.workspaceId ? params.workspaceId : arbi.hasWorkspace ? arbi.getWorkspaceId() : void 0;
51
+ fields,
52
+ useAggregateFields(enabled) {
53
+ const nameOf = useNames(enabled);
54
+ return useMemo(
55
+ () => [
56
+ { field: field("title"), from: ["title"] },
57
+ { field: field("created"), from: ["created"] },
58
+ { field: field("lastActivity"), from: ["last_activity"] },
59
+ { field: field("due"), from: ["due"] },
60
+ { field: field("completed"), from: ["completed"] },
61
+ {
62
+ field: field("kind"),
63
+ from: ["status"],
64
+ value: ([s]) => cellText(s) ? l.task : l.thread
65
+ },
66
+ { field: field("status"), from: ["status"], value: ([s]) => statusOf(cellText(s)) },
67
+ { field: field("overdue"), from: ["overdue"] },
68
+ { field: field("owner"), from: ["owner"], value: ([u]) => nameOf(cellText(u)) },
69
+ { field: field("messages"), from: ["messages"] },
70
+ { field: field("shared"), from: ["shared"] }
71
+ ],
72
+ [nameOf]
73
+ );
74
+ },
75
+ useWorkspace: useWorkspaceOf,
76
+ useRecords(params, enabled) {
77
+ const workspaceId = useWorkspaceOf(params);
48
78
  const query = useConversations(workspaceId, { enabled });
49
79
  const nameOf = useNames(enabled);
50
80
  const rows = useMemo(() => {
@@ -63,7 +93,7 @@ function createConversationsSource(labels) {
63
93
  shared: c.is_shared ?? null
64
94
  }));
65
95
  }, [query.data, nameOf]);
66
- return { rows, isLoading: query.isLoading && !!workspaceId, error: query.error };
96
+ return { rows, isLoading: enabled && query.isPending, error: query.error };
67
97
  }
68
98
  });
69
99
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/datasets/sources/conversations.ts"],
4
- "sourcesContent": ["/**\n * The conversations of a workspace (threads and tasks) as a dataset (default: the open one;\n * `params.workspaceId` names another): activity over time, work by status, owner and due date.\n * Reads the shared conversation list (`useConversations`), which live updates keep current.\n */\nimport { useMemo } from 'react'\nimport { useArbi } from '../../useArbi'\nimport { useConversations } from '../../hooks'\nimport { useNames } from '../members'\nimport { defineRowsSource, staticFields } from '../rows-source'\nimport type { DataSource, DataSourceParams, DatasetField, DatasetRow } from '../types'\n\nexport interface ConversationsSourceLabels {\n source: string\n description: string\n title: string\n created: string\n lastActivity: string\n due: string\n completed: string\n kind: string\n /** The `kind` of a conversation without a work status. */\n thread: string\n /** The `kind` of a conversation with a work status. */\n task: string\n status: string\n statuses: { todo: string; generating: string; done: string }\n overdue: string\n owner: string\n messages: string\n shared: string\n}\n\nexport const DEFAULT_CONVERSATIONS_SOURCE_LABELS: ConversationsSourceLabels = {\n source: 'Threads',\n description: 'The threads and tasks of the open workspace: activity, status, owners, due dates.',\n title: 'Title',\n created: 'Started',\n lastActivity: 'Last activity',\n due: 'Due',\n completed: 'Completed',\n kind: 'Kind',\n thread: 'Thread',\n task: 'Task',\n status: 'Status',\n statuses: { todo: 'To do', generating: 'Running', done: 'Done' },\n overdue: 'Overdue',\n owner: 'Owner',\n messages: 'Messages',\n shared: 'Shared',\n}\n\ninterface ConversationLike {\n external_id: string\n title?: string | null\n created_at?: string | null\n updated_at?: string | null\n last_message_updated_at?: string | null\n due_at?: string | null\n completed_at?: string | null\n status?: 'todo' | 'generating' | 'done' | null\n is_shared?: boolean | null\n message_count?: number | null\n owner_ext_id?: string | null\n created_by_ext_id?: string | null\n}\n\nexport function createConversationsSource(labels?: Partial<ConversationsSourceLabels>): DataSource {\n const l = { ...DEFAULT_CONVERSATIONS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'title', label: l.title, type: 'string' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'lastActivity', label: l.lastActivity, type: 'date' },\n { id: 'due', label: l.due, type: 'date' },\n { id: 'completed', label: l.completed, type: 'date' },\n { id: 'kind', label: l.kind, type: 'string', options: [l.thread, l.task] },\n { id: 'status', label: l.status, type: 'string', options: Object.values(l.statuses) },\n { id: 'overdue', label: l.overdue, type: 'boolean' },\n { id: 'owner', label: l.owner, type: 'string' },\n { id: 'messages', label: l.messages, type: 'number' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n ]\n return defineRowsSource({\n id: 'conversations',\n scope: 'workspace',\n label: l.source,\n description: l.description,\n useFields: staticFields(fields),\n useRows(params: DataSourceParams, enabled) {\n const arbi = useArbi()\n const workspaceId =\n typeof params.workspaceId === 'string' && params.workspaceId\n ? params.workspaceId\n : arbi.hasWorkspace\n ? arbi.getWorkspaceId()\n : undefined\n const query = useConversations(workspaceId, { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(() => {\n const now = new Date().toISOString()\n return (query.data as ConversationLike[] | undefined)?.map((c): DatasetRow => ({\n title: c.title || null,\n created: c.created_at ?? null,\n lastActivity: c.last_message_updated_at ?? c.updated_at ?? null,\n due: c.due_at ?? null,\n completed: c.completed_at ?? null,\n kind: c.status ? l.task : l.thread,\n status: c.status ? l.statuses[c.status] : null,\n overdue: Boolean(c.due_at && c.status !== 'done' && c.due_at < now),\n owner: nameOf(c.owner_ext_id ?? c.created_by_ext_id),\n messages: c.message_count ?? null,\n shared: c.is_shared ?? null,\n }))\n }, [query.data, nameOf])\n return { rows, isLoading: query.isLoading && !!workspaceId, error: query.error }\n },\n })\n}\n"],
5
- "mappings": "AAKA,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAwBxC,MAAM,sCAAiE;AAAA,EAC5E,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS;AAAA,EACT,cAAc;AAAA,EACd,KAAK;AAAA,EACL,WAAW;AAAA,EACX,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU,EAAE,MAAM,SAAS,YAAY,WAAW,MAAM,OAAO;AAAA,EAC/D,SAAS;AAAA,EACT,OAAO;AAAA,EACP,UAAU;AAAA,EACV,QAAQ;AACV;AAiBO,SAAS,0BAA0B,QAAyD;AACjG,QAAM,IAAI,EAAE,GAAG,qCAAqC,GAAG,OAAO;AAC9D,QAAM,SAAyB;AAAA,IAC7B,EAAE,IAAI,SAAS,OAAO,EAAE,OAAO,MAAM,SA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A,UAClB,SAAS,EAAE,cAAc;AAAA,UACzB,cAAc,EAAE,2BAA2B,EAAE,cAAc;AAAA,UAC3D,KAAK,EAAE,UAAU;AAAA,UACjB,WAAW,EAAE,gBAAgB;AAAA,UAC7B,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE;AAAA,UAC5B,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,IAAI;AAAA,UAC1C,SAAS,QAAQ,EAAE,UAAU,EAAE,WAAW,UAAU,EAAE,SAAS,GAAG;AAAA,UAClE,OAAO,OAAO,EAAE,gBAAgB,EAAE,iBAAiB;AAAA,UACnD,UAAU,EAAE,iBAAiB;AAAA,UAC7B,QAAQ,EAAE,aAAa;AAAA,QACzB,EAAE;AAAA,MACJ,GAAG,CAAC,MAAM,MAAM,MAAM,CAAC;AACvB,aAAO,EAAE,MAAM,WAAW,MAAM,aAAa,CAAC,CAAC,aAAa,OAAO,MAAM,MAAM;AAAA,IACjF;AAAA,EACF,CAAC;AACH;",
4
+ "sourcesContent": ["/**\n * The conversations of a workspace (threads and tasks) as a dataset (default: the open one;\n * `params.workspaceId` names another): activity over time, work by status, owner and due date.\n * Counted on the server (`defineAggregateSource`); a table of threads (due dates) reads the shared\n * conversation list (`useConversations`).\n */\nimport { useMemo } from 'react'\nimport { useArbi } from '../../useArbi'\nimport { useConversations } from '../../hooks'\nimport { cellText, defineAggregateSource, type AggregateField } from '../aggregate-source'\nimport { useNames } from '../members'\nimport type { DataSource, DataSourceParams, DatasetField, DatasetRow } from '../types'\n\nexport interface ConversationsSourceLabels {\n source: string\n description: string\n title: string\n created: string\n lastActivity: string\n due: string\n completed: string\n kind: string\n /** The `kind` of a conversation without a work status. */\n thread: string\n /** The `kind` of a conversation with a work status. */\n task: string\n status: string\n statuses: { todo: string; generating: string; done: string }\n overdue: string\n owner: string\n messages: string\n shared: string\n}\n\nexport const DEFAULT_CONVERSATIONS_SOURCE_LABELS: ConversationsSourceLabels = {\n source: 'Threads',\n description: 'The threads and tasks of the open workspace: activity, status, owners, due dates.',\n title: 'Title',\n created: 'Started',\n lastActivity: 'Last activity',\n due: 'Due',\n completed: 'Completed',\n kind: 'Kind',\n thread: 'Thread',\n task: 'Task',\n status: 'Status',\n statuses: { todo: 'To do', generating: 'Running', done: 'Done' },\n overdue: 'Overdue',\n owner: 'Owner',\n messages: 'Messages',\n shared: 'Shared',\n}\n\ninterface ConversationLike {\n external_id: string\n title?: string | null\n created_at?: string | null\n updated_at?: string | null\n last_message_updated_at?: string | null\n due_at?: string | null\n completed_at?: string | null\n status?: 'todo' | 'generating' | 'done' | null\n is_shared?: boolean | null\n message_count?: number | null\n owner_ext_id?: string | null\n created_by_ext_id?: string | null\n}\n\nexport function createConversationsSource(labels?: Partial<ConversationsSourceLabels>): DataSource {\n const l = { ...DEFAULT_CONVERSATIONS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'title', label: l.title, type: 'string' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'lastActivity', label: l.lastActivity, type: 'date' },\n { id: 'due', label: l.due, type: 'date' },\n { id: 'completed', label: l.completed, type: 'date' },\n { id: 'kind', label: l.kind, type: 'string', options: [l.thread, l.task] },\n { id: 'status', label: l.status, type: 'string', options: Object.values(l.statuses) },\n { id: 'overdue', label: l.overdue, type: 'boolean' },\n { id: 'owner', label: l.owner, type: 'string' },\n { id: 'messages', label: l.messages, type: 'number' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n ]\n const byId = new Map(fields.map((f) => [f.id, f]))\n const field = (id: string): DatasetField => byId.get(id) ?? { id, label: id, type: 'string' }\n const statusOf = (status: string | null): string | null =>\n status === 'todo' || status === 'generating' || status === 'done' ? l.statuses[status] : status\n function useWorkspaceOf(params: DataSourceParams): string | undefined {\n const arbi = useArbi()\n return typeof params.workspaceId === 'string' && params.workspaceId\n ? params.workspaceId\n : arbi.hasWorkspace\n ? arbi.getWorkspaceId()\n : undefined\n }\n return defineAggregateSource({\n id: 'conversations',\n source: 'conversations',\n label: l.source,\n description: l.description,\n fields,\n useAggregateFields(enabled) {\n const nameOf = useNames(enabled)\n return useMemo(\n (): AggregateField[] => [\n { field: field('title'), from: ['title'] },\n { field: field('created'), from: ['created'] },\n { field: field('lastActivity'), from: ['last_activity'] },\n { field: field('due'), from: ['due'] },\n { field: field('completed'), from: ['completed'] },\n {\n field: field('kind'),\n from: ['status'],\n value: ([s]) => (cellText(s) ? l.task : l.thread),\n },\n { field: field('status'), from: ['status'], value: ([s]) => statusOf(cellText(s)) },\n { field: field('overdue'), from: ['overdue'] },\n { field: field('owner'), from: ['owner'], value: ([u]) => nameOf(cellText(u)) },\n { field: field('messages'), from: ['messages'] },\n { field: field('shared'), from: ['shared'] },\n ],\n [nameOf]\n )\n },\n useWorkspace: useWorkspaceOf,\n useRecords(params: DataSourceParams, enabled) {\n const workspaceId = useWorkspaceOf(params)\n const query = useConversations(workspaceId, { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(() => {\n const now = new Date().toISOString()\n return (query.data as ConversationLike[] | undefined)?.map((c): DatasetRow => ({\n title: c.title || null,\n created: c.created_at ?? null,\n lastActivity: c.last_message_updated_at ?? c.updated_at ?? null,\n due: c.due_at ?? null,\n completed: c.completed_at ?? null,\n kind: c.status ? l.task : l.thread,\n status: c.status ? l.statuses[c.status] : null,\n overdue: Boolean(c.due_at && c.status !== 'done' && c.due_at < now),\n owner: nameOf(c.owner_ext_id ?? c.created_by_ext_id),\n messages: c.message_count ?? null,\n shared: c.is_shared ?? null,\n }))\n }, [query.data, nameOf])\n return { rows, isLoading: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
5
+ "mappings": "AAMA,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,wBAAwB;AACjC,SAAS,UAAU,6BAAkD;AACrE,SAAS,gBAAgB;AAwBlB,MAAM,sCAAiE;AAAA,EAC5E,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS;AAAA,EACT,cAAc;AA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5 +1,6 @@
1
1
  import { useMemo } from "react";
2
2
  import { useTableViewsQuery } from "../../table-views.js";
3
+ import { useArbi } from "../../useArbi.js";
3
4
  import {
4
5
  useDatabase,
5
6
  useDatabaseAggregate,
@@ -95,24 +96,31 @@ function createDatabaseSource(labels) {
95
96
  function useView(params) {
96
97
  const databaseId = text(params.databaseId);
97
98
  const wanted = text(params.view);
98
- const views = useTableViewsQuery(databaseId ?? null, { enabled: Boolean(wanted && databaseId) });
99
- return useMemo(
99
+ const named = Boolean(wanted && databaseId);
100
+ const workspaceOpen = useArbi().hasWorkspace;
101
+ const views = useTableViewsQuery(databaseId ?? null, { enabled: named });
102
+ const view = useMemo(
100
103
  () => wanted && databaseId ? (views.data ?? []).find((v) => v.id === wanted) ?? (views.data ?? []).find((v) => v.spec.name === wanted) : void 0,
101
104
  [views.data, databaseId, wanted]
102
105
  );
106
+ return {
107
+ view,
108
+ ready: !named || !workspaceOpen || !views.isPending,
109
+ error: named ? views.error : null
110
+ };
103
111
  }
104
112
  function useFields(params) {
105
113
  const databaseId = text(params.databaseId) ?? null;
106
114
  const database = useDatabase(databaseId, { workspaceId: text(params.workspaceId) });
107
- const view = useView(params);
115
+ const { view } = useView(params);
108
116
  const fields = useMemo(() => databaseFields(database.data, view?.spec), [database.data, view]);
109
- return { fields, isLoading: database.isLoading && !!databaseId, error: database.error };
117
+ return { fields, isLoading: database.isPending && !!databaseId, error: database.error };
110
118
  }
111
119
  function useDataset(params, query, options) {
112
120
  const databaseId = text(params.databaseId) ?? null;
113
121
  const enabled = options?.enabled ?? true;
114
122
  const fields = useFields(params);
115
- const view = useView(params);
123
+ const { view, ready: viewReady, error: viewError } = useView(params);
116
124
  const grouped = !query.records;
117
125
  const request = useMemo(() => {
118
126
  if (!grouped) return {};
@@ -122,10 +130,10 @@ function createDatabaseSource(labels) {
122
130
  }, [grouped, query, view]);
123
131
  const workspaceId = text(params.workspaceId);
124
132
  const aggregate = useDatabaseAggregate(databaseId, request, {
125
- enabled: enabled && grouped,
133
+ enabled: enabled && grouped && viewReady,
126
134
  workspaceId
127
135
  });
128
- const rows = useDatabaseRows(enabled && !grouped ? databaseId : null, "", {
136
+ const rows = useDatabaseRows(enabled && !grouped && viewReady ? databaseId : null, "", {
129
137
  workspaceId,
130
138
  view: view?.id
131
139
  });
@@ -140,8 +148,8 @@ function createDatabaseSource(labels) {
140
148
  const active = grouped ? aggregate : rows;
141
149
  return {
142
150
  dataset,
143
- isLoading: !!databaseId && (active.isLoading || fields.isLoading),
144
- error: active.error ?? fields.error
151
+ isLoading: enabled && !!databaseId && (!viewReady || active.isPending || fields.isLoading),
152
+ error: active.error ?? viewError ?? fields.error
145
153
  };
146
154
  }
147
155
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/datasets/sources/database.ts"],
4
- "sourcesContent": ["/**\n * A database of the open workspace (one the user created or imported from a spreadsheet) as a\n * dataset: `params.databaseId` picks it, `params.view` one of its saved views (the grid's\n * \"Columns\" menu; its id, or its name for a panel saved before views had ids), whose columns are\n * then the fields offered and whose filters narrow every query. Grouping and measuring run on the\n * server (`POST /v1/databases/{id}/aggregate`, over every row, so totals are exact however large the\n * database is); a table of records reads the first page of rows.\n */\nimport { useMemo } from 'react'\nimport { useTableViewsQuery, type TableViewRecord, type TableViewSpec } from '../../table-views'\nimport {\n useDatabase,\n useDatabaseAggregate,\n useDatabaseRows,\n useDatabases,\n type Database,\n type DatabaseAggregateRequest,\n type DatabaseAggregateResult,\n type DatabaseColumn,\n type DatabaseRow,\n} from '../../databases'\nimport { aggregateFields, recordsOf } from '../aggregate'\nimport {\n AGGREGATE_FIELDS,\n type DataSource,\n type DataSourceFieldsState,\n type DataSourceParams,\n type Dataset,\n type DatasetField,\n type DatasetQuery,\n type DatasetRow,\n type DatasetState,\n type DatasetValue,\n} from '../types'\n\nexport interface DatabaseSourceLabels {\n source: string\n description: string\n database: string\n view: string\n allColumns: string\n}\n\nexport const DEFAULT_DATABASE_SOURCE_LABELS: DatabaseSourceLabels = {\n source: 'Database',\n description: 'A database, or one of its saved views.',\n database: 'Database',\n view: 'Saved view',\n allColumns: 'All columns',\n}\n\nconst MULTI = new Set(['document', 'relation', 'lookup', 'tag'])\n\n/** A database column as a dataset field (ids are the column ids the server groups by). */\nexport function fieldOfColumn(column: DatabaseColumn): DatasetField {\n const type =\n column.type === 'number' || column.type === 'rollup'\n ? 'number'\n : column.type === 'date'\n ? 'date'\n : column.type === 'checkbox'\n ? 'boolean'\n : 'string'\n return {\n id: column.id,\n label: column.name,\n type,\n ...(column.options?.length ? { options: column.options } : {}),\n ...(MULTI.has(column.type) ? { multiple: true } : {}),\n }\n}\n\nconst text = (v: DatasetValue | undefined) => (typeof v === 'string' && v ? v : undefined)\n\n/** The fields of a database, limited to a saved view's columns (in its order) when one is named. */\nexport function databaseFields(\n database: Pick<Database, 'columns'> | undefined,\n view?: Pick<TableViewSpec, 'columns'>\n): DatasetField[] {\n const columns = database?.columns ?? []\n if (!view?.columns?.length) return columns.map(fieldOfColumn)\n const byId = new Map(columns.map((c) => [c.id, c]))\n return view.columns.flatMap((id) => {\n const column = byId.get(id)\n return column ? [fieldOfColumn(column)] : []\n })\n}\n\n/** The server request for a query. */\nexport function aggregateRequest(query: DatasetQuery): Partial<DatabaseAggregateRequest> {\n return {\n group_by: query.groupBy ?? null,\n split_by: query.splitBy ?? null,\n time_bucket: query.bucket ?? 'month',\n measure: { op: query.measure?.op ?? 'count', column: query.measure?.field ?? null },\n filters: (query.filters ?? []).map((f) => ({ column: f.field, op: f.op, value: f.value })),\n limit: query.limit ?? 50,\n }\n}\n\n/** The server's labels and series as a long-form aggregated dataset, re-sorted when asked. */\nexport function datasetOfAggregate(\n result: DatabaseAggregateResult,\n fields: readonly DatasetField[],\n query: DatasetQuery\n): Dataset {\n const split = Boolean(query.splitBy)\n let order = result.keys.map((_, i) => i)\n const total = (i: number) => result.series.reduce((sum, s) => sum + (s.values[i] ?? 0), 0)\n if (query.sort === 'label') {\n order = [...order].sort((a, b) =>\n result.keys[a] === ''\n ? 1\n : result.keys[b] === ''\n ? -1\n : result.labels[a].localeCompare(result.labels[b])\n )\n } else if (query.sort === 'value-asc') {\n order = [...order].sort((a, b) => total(a) - total(b))\n } else if (query.sort === 'value-desc') {\n order = [...order].sort((a, b) => total(b) - total(a))\n }\n const rows: DatasetRow[] = order.flatMap((i) =>\n result.series.map((s) => ({\n [AGGREGATE_FIELDS.group]: result.labels[i],\n [AGGREGATE_FIELDS.key]: result.keys[i],\n ...(split ? { [AGGREGATE_FIELDS.series]: s.label } : {}),\n [AGGREGATE_FIELDS.value]: s.values[i] ?? null,\n }))\n )\n return {\n fields: aggregateFields(fields, query),\n rows,\n totalRows: result.total_rows,\n truncated: result.truncated,\n }\n}\n\n/** A database row as a dataset row: linked ids read as their titles. */\nexport function datasetRowOf(row: DatabaseRow, fields: readonly DatasetField[]): DatasetRow {\n const titles = row.titles ?? {}\n const out: Record<string, DatasetValue> = {}\n for (const field of fields) {\n const raw = row.values[field.id]\n if (raw === null || raw === undefined) out[field.id] = null\n else if (Array.isArray(raw)) out[field.id] = raw.map((v) => titles[String(v)] ?? String(v))\n else if (typeof raw === 'string')\n out[field.id] = field.type === 'string' ? (titles[raw] ?? raw) : raw\n else if (typeof raw === 'number' || typeof raw === 'boolean') out[field.id] = raw\n else out[field.id] = String(raw)\n }\n return out\n}\n\nexport function createDatabaseSource(labels?: Partial<DatabaseSourceLabels>): DataSource {\n const l = { ...DEFAULT_DATABASE_SOURCE_LABELS, ...labels }\n\n function useView(params: DataSourceParams): TableViewRecord | undefined {\n const databaseId = text(params.databaseId)\n const wanted = text(params.view)\n const views = useTableViewsQuery(databaseId ?? null, { enabled: Boolean(wanted && databaseId) })\n return useMemo(\n () =>\n wanted && databaseId\n ? ((views.data ?? []).find((v) => v.id === wanted) ??\n (views.data ?? []).find((v) => v.spec.name === wanted))\n : undefined,\n [views.data, databaseId, wanted]\n )\n }\n\n function useFields(params: DataSourceParams): DataSourceFieldsState {\n const databaseId = text(params.databaseId) ?? null\n const database = useDatabase(databaseId, { workspaceId: text(params.workspaceId) })\n const view = useView(params)\n const fields = useMemo(() => databaseFields(database.data, view?.spec), [database.data, view])\n return { fields, isLoading: database.isLoading && !!databaseId, error: database.error }\n }\n\n function useDataset(\n params: DataSourceParams,\n query: DatasetQuery,\n options?: { enabled?: boolean }\n ): DatasetState {\n const databaseId = text(params.databaseId) ?? null\n const enabled = options?.enabled ?? true\n const fields = useFields(params)\n const view = useView(params)\n const grouped = !query.records\n // A view's filters narrow every query (its conditions first, the panel's after them).\n const request = useMemo(() => {\n if (!grouped) return {}\n const req = aggregateRequest(query)\n const own = view?.spec.filters ?? []\n return own.length ? { ...req, filters: [...own, ...(req.filters ?? [])] } : req\n }, [grouped, query, view])\n const workspaceId = text(params.workspaceId)\n const aggregate = useDatabaseAggregate(databaseId, request, {\n enabled: enabled && grouped,\n workspaceId,\n })\n const rows = useDatabaseRows(enabled && !grouped ? databaseId : null, '', {\n workspaceId,\n view: view?.id,\n })\n const dataset = useMemo(() => {\n if (grouped) {\n return aggregate.data ? datasetOfAggregate(aggregate.data, fields.fields, query) : undefined\n }\n if (!rows.data) return undefined\n const records = rows.data.rows.map((r) => datasetRowOf(r, fields.fields))\n return recordsOf({ fields: fields.fields, rows: records }, query)\n }, [grouped, query, aggregate.data, rows.data, fields.fields])\n const active = grouped ? aggregate : rows\n return {\n dataset,\n isLoading: !!databaseId && (active.isLoading || fields.isLoading),\n error: active.error ?? fields.error,\n }\n }\n\n return {\n id: 'database',\n label: l.source,\n description: l.description,\n // A panel that names its database's workspace reads it anywhere; an older one, only in the open one.\n scope: (params) => (text(params.workspaceId) ? undefined : 'workspace'),\n params: [\n {\n id: 'databaseId',\n label: l.database,\n required: true,\n // The open workspace's databases (the list is read there), and the panel's own database\n // wherever it is (read by id in its workspace), so its name shows with none or another open.\n useOptions(params) {\n const databases = useDatabases()\n const currentId = text(params.databaseId) ?? null\n const listed = (databases.data ?? []).some((d) => d.id === currentId)\n const current = useDatabase(listed ? null : currentId, {\n workspaceId: text(params.workspaceId),\n })\n const options = useMemo(() => {\n const all = [...(databases.data ?? [])]\n if (current.data && !listed) all.push(current.data)\n return all.map((d) => ({\n value: d.id,\n label: d.name,\n params: { workspaceId: d.workspace_id },\n }))\n }, [databases.data, current.data, listed])\n return { options, isLoading: databases.isLoading || current.isLoading }\n },\n },\n {\n id: 'view',\n label: l.view,\n placeholder: l.allColumns,\n useOptions(params) {\n const databaseId = text(params.databaseId)\n const views = useTableViewsQuery(databaseId ?? null, { enabled: Boolean(databaseId) })\n const options = useMemo(\n () =>\n databaseId\n ? (views.data ?? []).map((v) => ({ value: v.id, label: v.spec.name }))\n : [],\n [views.data, databaseId]\n )\n return { options, isLoading: views.isLoading && !!databaseId }\n },\n },\n ],\n useFields,\n useDataset,\n }\n}\n"],
5
- "mappings": "AAQA,SAAS,eAAe;AACxB,SAAS,0BAAoE;AAC7E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP,SAAS,iBAAiB,iBAAiB;AAC3C;AAAA,EACE;AAAA,OAUK;AAUA,MAAM,iCAAuD;AAAA,EAClE,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,UAAU;AAAA,EACV,MAAM;AAAA,EACN,YAAY;AACd;AAEA,MAAM,QAAQ,oBAAI,IAAI,CAAC,YAAY,YAAY,UAAU,KAAK,CAAC;AAGxD,SAAS,cAAc,QAAsC;AAClE,QAAM,OACJ,OAAO,SAAS,YAAY,OAAO,SAAS,WACxC,WACA,OAAO,SAAS,SACd,SACA,OAAO,SAAS,aACd,YACA;AACV,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,OAAO,OAAO;AAAA,IACd;AAAA,IACA,GAAI,OAAO,SAAS,SAAS,EAAE,SAAS,OAAO,QAAQ,IAAI,CAAC;AAAA,IAC5D,GAAI,MAAM,IAAI,OAAO,IAAI,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;AAA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IAAI,OAAO,EAAE,KAAK,KAAK,EAAE,IACnE,CAAC;AAAA,YACP,CAAC,MAAM,MAAM,UAAU;AAAA,UACzB;AACA,iBAAO,EAAE,SAAS,WAAW,MAAM,aAAa,CAAC,CAAC,WAAW;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["/**\n * A database of the open workspace (one the user created or imported from a spreadsheet) as a\n * dataset: `params.databaseId` picks it, `params.view` one of its saved views (the grid's\n * \"Columns\" menu; its id, or its name for a panel saved before views had ids), whose columns are\n * then the fields offered and whose filters narrow every query. Grouping and measuring run on the\n * server (`POST /v1/databases/{id}/aggregate`, over every row, so totals are exact however large the\n * database is); a table of records reads the first page of rows.\n */\nimport { useMemo } from 'react'\nimport { useTableViewsQuery, type TableViewRecord, type TableViewSpec } from '../../table-views'\nimport { useArbi } from '../../useArbi'\nimport {\n useDatabase,\n useDatabaseAggregate,\n useDatabaseRows,\n useDatabases,\n type Database,\n type DatabaseAggregateRequest,\n type DatabaseAggregateResult,\n type DatabaseColumn,\n type DatabaseRow,\n} from '../../databases'\nimport { aggregateFields, recordsOf } from '../aggregate'\nimport {\n AGGREGATE_FIELDS,\n type DataSource,\n type DataSourceFieldsState,\n type DataSourceParams,\n type Dataset,\n type DatasetField,\n type DatasetQuery,\n type DatasetRow,\n type DatasetState,\n type DatasetValue,\n} from '../types'\n\nexport interface DatabaseSourceLabels {\n source: string\n description: string\n database: string\n view: string\n allColumns: string\n}\n\nexport const DEFAULT_DATABASE_SOURCE_LABELS: DatabaseSourceLabels = {\n source: 'Database',\n description: 'A database, or one of its saved views.',\n database: 'Database',\n view: 'Saved view',\n allColumns: 'All columns',\n}\n\nconst MULTI = new Set(['document', 'relation', 'lookup', 'tag'])\n\n/** A database column as a dataset field (ids are the column ids the server groups by). */\nexport function fieldOfColumn(column: DatabaseColumn): DatasetField {\n const type =\n column.type === 'number' || column.type === 'rollup'\n ? 'number'\n : column.type === 'date'\n ? 'date'\n : column.type === 'checkbox'\n ? 'boolean'\n : 'string'\n return {\n id: column.id,\n label: column.name,\n type,\n ...(column.options?.length ? { options: column.options } : {}),\n ...(MULTI.has(column.type) ? { multiple: true } : {}),\n }\n}\n\nconst text = (v: DatasetValue | undefined) => (typeof v === 'string' && v ? v : undefined)\n\n/** The fields of a database, limited to a saved view's columns (in its order) when one is named. */\nexport function databaseFields(\n database: Pick<Database, 'columns'> | undefined,\n view?: Pick<TableViewSpec, 'columns'>\n): DatasetField[] {\n const columns = database?.columns ?? []\n if (!view?.columns?.length) return columns.map(fieldOfColumn)\n const byId = new Map(columns.map((c) => [c.id, c]))\n return view.columns.flatMap((id) => {\n const column = byId.get(id)\n return column ? [fieldOfColumn(column)] : []\n })\n}\n\n/** The server request for a query. */\nexport function aggregateRequest(query: DatasetQuery): Partial<DatabaseAggregateRequest> {\n return {\n group_by: query.groupBy ?? null,\n split_by: query.splitBy ?? null,\n time_bucket: query.bucket ?? 'month',\n measure: { op: query.measure?.op ?? 'count', column: query.measure?.field ?? null },\n filters: (query.filters ?? []).map((f) => ({ column: f.field, op: f.op, value: f.value })),\n limit: query.limit ?? 50,\n }\n}\n\n/** The server's labels and series as a long-form aggregated dataset, re-sorted when asked. */\nexport function datasetOfAggregate(\n result: DatabaseAggregateResult,\n fields: readonly DatasetField[],\n query: DatasetQuery\n): Dataset {\n const split = Boolean(query.splitBy)\n let order = result.keys.map((_, i) => i)\n const total = (i: number) => result.series.reduce((sum, s) => sum + (s.values[i] ?? 0), 0)\n if (query.sort === 'label') {\n order = [...order].sort((a, b) =>\n result.keys[a] === ''\n ? 1\n : result.keys[b] === ''\n ? -1\n : result.labels[a].localeCompare(result.labels[b])\n )\n } else if (query.sort === 'value-asc') {\n order = [...order].sort((a, b) => total(a) - total(b))\n } else if (query.sort === 'value-desc') {\n order = [...order].sort((a, b) => total(b) - total(a))\n }\n const rows: DatasetRow[] = order.flatMap((i) =>\n result.series.map((s) => ({\n [AGGREGATE_FIELDS.group]: result.labels[i],\n [AGGREGATE_FIELDS.key]: result.keys[i],\n ...(split ? { [AGGREGATE_FIELDS.series]: s.label } : {}),\n [AGGREGATE_FIELDS.value]: s.values[i] ?? null,\n }))\n )\n return {\n fields: aggregateFields(fields, query),\n rows,\n totalRows: result.total_rows,\n truncated: result.truncated,\n }\n}\n\n/** A database row as a dataset row: linked ids read as their titles. */\nexport function datasetRowOf(row: DatabaseRow, fields: readonly DatasetField[]): DatasetRow {\n const titles = row.titles ?? {}\n const out: Record<string, DatasetValue> = {}\n for (const field of fields) {\n const raw = row.values[field.id]\n if (raw === null || raw === undefined) out[field.id] = null\n else if (Array.isArray(raw)) out[field.id] = raw.map((v) => titles[String(v)] ?? String(v))\n else if (typeof raw === 'string')\n out[field.id] = field.type === 'string' ? (titles[raw] ?? raw) : raw\n else if (typeof raw === 'number' || typeof raw === 'boolean') out[field.id] = raw\n else out[field.id] = String(raw)\n }\n return out\n}\n\nexport function createDatabaseSource(labels?: Partial<DatabaseSourceLabels>): DataSource {\n const l = { ...DEFAULT_DATABASE_SOURCE_LABELS, ...labels }\n\n /**\n * The panel's saved view, and whether it is known yet (`ready`: no view named, or the views\n * read). A query narrowed by a view waits for it rather than reading everything first and again\n * once the view's filters arrive. Views are read in the open workspace: with none open they\n * never come, so nothing waits for them.\n */\n function useView(params: DataSourceParams): {\n view: TableViewRecord | undefined\n ready: boolean\n error: unknown\n } {\n const databaseId = text(params.databaseId)\n const wanted = text(params.view)\n const named = Boolean(wanted && databaseId)\n const workspaceOpen = useArbi().hasWorkspace\n const views = useTableViewsQuery(databaseId ?? null, { enabled: named })\n const view = useMemo(\n () =>\n wanted && databaseId\n ? ((views.data ?? []).find((v) => v.id === wanted) ??\n (views.data ?? []).find((v) => v.spec.name === wanted))\n : undefined,\n [views.data, databaseId, wanted]\n )\n return {\n view,\n ready: !named || !workspaceOpen || !views.isPending,\n error: named ? views.error : null,\n }\n }\n\n function useFields(params: DataSourceParams): DataSourceFieldsState {\n const databaseId = text(params.databaseId) ?? null\n const database = useDatabase(databaseId, { workspaceId: text(params.workspaceId) })\n const { view } = useView(params)\n const fields = useMemo(() => databaseFields(database.data, view?.spec), [database.data, view])\n return { fields, isLoading: database.isPending && !!databaseId, error: database.error }\n }\n\n function useDataset(\n params: DataSourceParams,\n query: DatasetQuery,\n options?: { enabled?: boolean }\n ): DatasetState {\n const databaseId = text(params.databaseId) ?? null\n const enabled = options?.enabled ?? true\n const fields = useFields(params)\n const { view, ready: viewReady, error: viewError } = useView(params)\n const grouped = !query.records\n // A view's filters narrow every query (its conditions first, the panel's after them).\n const request = useMemo(() => {\n if (!grouped) return {}\n const req = aggregateRequest(query)\n const own = view?.spec.filters ?? []\n return own.length ? { ...req, filters: [...own, ...(req.filters ?? [])] } : req\n }, [grouped, query, view])\n const workspaceId = text(params.workspaceId)\n const aggregate = useDatabaseAggregate(databaseId, request, {\n enabled: enabled && grouped && viewReady,\n workspaceId,\n })\n const rows = useDatabaseRows(enabled && !grouped && viewReady ? databaseId : null, '', {\n workspaceId,\n view: view?.id,\n })\n const dataset = useMemo(() => {\n if (grouped) {\n return aggregate.data ? datasetOfAggregate(aggregate.data, fields.fields, query) : undefined\n }\n if (!rows.data) return undefined\n const records = rows.data.rows.map((r) => datasetRowOf(r, fields.fields))\n return recordsOf({ fields: fields.fields, rows: records }, query)\n }, [grouped, query, aggregate.data, rows.data, fields.fields])\n const active = grouped ? aggregate : rows\n return {\n dataset,\n isLoading: enabled && !!databaseId && (!viewReady || active.isPending || fields.isLoading),\n error: active.error ?? viewError ?? fields.error,\n }\n }\n\n return {\n id: 'database',\n label: l.source,\n description: l.description,\n // A panel that names its database's workspace reads it anywhere; an older one, only in the open one.\n scope: (params) => (text(params.workspaceId) ? undefined : 'workspace'),\n params: [\n {\n id: 'databaseId',\n label: l.database,\n required: true,\n // The open workspace's databases (the list is read there), and the panel's own database\n // wherever it is (read by id in its workspace), so its name shows with none or another open.\n useOptions(params) {\n const databases = useDatabases()\n const currentId = text(params.databaseId) ?? null\n const listed = (databases.data ?? []).some((d) => d.id === currentId)\n const current = useDatabase(listed ? null : currentId, {\n workspaceId: text(params.workspaceId),\n })\n const options = useMemo(() => {\n const all = [...(databases.data ?? [])]\n if (current.data && !listed) all.push(current.data)\n return all.map((d) => ({\n value: d.id,\n label: d.name,\n params: { workspaceId: d.workspace_id },\n }))\n }, [databases.data, current.data, listed])\n return { options, isLoading: databases.isLoading || current.isLoading }\n },\n },\n {\n id: 'view',\n label: l.view,\n placeholder: l.allColumns,\n useOptions(params) {\n const databaseId = text(params.databaseId)\n const views = useTableViewsQuery(databaseId ?? null, { enabled: Boolean(databaseId) })\n const options = useMemo(\n () =>\n databaseId\n ? (views.data ?? []).map((v) => ({ value: v.id, label: v.spec.name }))\n : [],\n [views.data, databaseId]\n )\n return { options, isLoading: views.isLoading && !!databaseId }\n },\n },\n ],\n useFields,\n useDataset,\n }\n}\n"],
5
+ "mappings": "AAQA,SAAS,eAAe;AACxB,SAAS,0BAAoE;AAC7E,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP,SAAS,iBAAiB,iBAAiB;AAC3C;AAAA,EACE;AAAA,OAUK;AAUA,MAAM,iCAAuD;AAAA,EAClE,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,UAAU;AAAA,EACV,MAAM;AAAA,EACN,YAAY;AACd;AAEA,MAAM,QAAQ,oBAAI,IAAI,CAAC,YAAY,YAAY,UAAU,KAAK,CAAC;AAGxD,SAAS,cAAc,QAAsC;AAClE,QAAM,OACJ,OAAO,SAAS,YAAY,OAAO,SAAS,WACxC,WACA,OAAO,SAAS,SACd,SACA,OAAO,SAAS,aACd,YACA;AACV,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,OAAO,OAAO;AAAA,IACd;AAAA,IACA,GAAI,OAAO,SAAS,SAAS,EAAE,SAAS,OAAO,QAAQ,IAAI,CAAC;AAAA,IAC5D,GAAI,M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A,QACxE;AAAA,MACF;AAAA,MACA;AAAA,QACE,IAAI;AAAA,QACJ,OAAO,EAAE;AAAA,QACT,aAAa,EAAE;AAAA,QACf,WAAW,QAAQ;AACjB,gBAAM,aAAa,KAAK,OAAO,UAAU;AACzC,gBAAM,QAAQ,mBAAmB,cAAc,MAAM,EAAE,SAAS,QAAQ,UAAU,EAAE,CAAC;AACrF,gBAAM,UAAU;AAAA,YACd,MACE,cACK,MAAM,QAAQ,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,OAAO,EAAE,KAAK,KAAK,EAAE,IACnE,CAAC;AAAA,YACP,CAAC,MAAM,MAAM,UAAU;AAAA,UACzB;AACA,iBAAO,EAAE,SAAS,WAAW,MAAM,aAAa,CAAC,CAAC,WAAW;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,9 @@
1
1
  import { useMemo } from "react";
2
+ import { useArbi } from "../../useArbi.js";
2
3
  import { useDocuments } from "../../documents/documents-data.js";
3
4
  import { friendlyFileType } from "../../entities/file-type.js";
5
+ import { cellText, defineAggregateSource } from "../aggregate-source.js";
4
6
  import { useNames } from "../members.js";
5
- import { defineRowsSource, staticFields } from "../rows-source.js";
6
7
  const DEFAULT_DOCUMENTS_SOURCE_LABELS = {
7
8
  source: "Documents",
8
9
  description: "The documents of the open workspace: type, folder, status, dates.",
@@ -55,13 +56,50 @@ function createDocumentsSource(labels) {
55
56
  { id: "size", label: l.size, type: "number", unit: "bytes" },
56
57
  { id: "shared", label: l.shared, type: "boolean" }
57
58
  ];
58
- return defineRowsSource({
59
+ const byId = new Map(fields.map((f) => [f.id, f]));
60
+ const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
61
+ const statusOf = (status) => status ? l.statuses[status] ?? status : null;
62
+ return defineAggregateSource({
59
63
  id: "documents",
60
- scope: "workspace",
64
+ source: "documents",
61
65
  label: l.source,
62
66
  description: l.description,
63
- useFields: staticFields(fields),
64
- useRows(params, enabled) {
67
+ fields,
68
+ useAggregateFields(enabled) {
69
+ const nameOf = useNames(enabled);
70
+ return useMemo(
71
+ () => [
72
+ { field: field("name"), from: ["name"] },
73
+ { field: field("created"), from: ["created"] },
74
+ { field: field("updated"), from: ["updated"] },
75
+ // Encrypted: the server buckets it, but cannot compare it.
76
+ { field: field("documentDate"), from: ["document_date"], server: false },
77
+ { field: field("status"), from: ["status"], value: ([s]) => statusOf(cellText(s)) },
78
+ {
79
+ field: field("type"),
80
+ // The name's extension, not the name: what a file type is read from.
81
+ from: ["file_type", "extension", "folder"],
82
+ value: ([type, extension, folder]) => {
83
+ const ext = cellText(extension);
84
+ return friendlyFileType(cellText(type), ext ? `file.${ext}` : null, cellText(folder)) || null;
85
+ }
86
+ },
87
+ { field: field("folder"), from: ["folder"], value: ([f]) => cellText(f) },
88
+ { field: field("nature"), from: ["nature"] },
89
+ { field: field("author"), from: ["author"] },
90
+ { field: field("createdBy"), from: ["created_by"], value: ([u]) => nameOf(cellText(u)) },
91
+ { field: field("pages"), from: ["pages"] },
92
+ { field: field("size"), from: ["size"] },
93
+ { field: field("shared"), from: ["shared"] }
94
+ ],
95
+ [nameOf]
96
+ );
97
+ },
98
+ useWorkspace(params) {
99
+ const arbi = useArbi();
100
+ return workspaceOf(params) ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : void 0);
101
+ },
102
+ useRecords(params, enabled) {
65
103
  const query = useDocuments(workspaceOf(params), { enabled });
66
104
  const nameOf = useNames(enabled);
67
105
  const rows = useMemo(
@@ -70,7 +108,7 @@ function createDocumentsSource(labels) {
70
108
  created: d.created_at ?? null,
71
109
  updated: d.updated_at ?? null,
72
110
  documentDate: d.doc_metadata?.doc_date ?? null,
73
- status: d.status ? l.statuses[d.status] ?? d.status : null,
111
+ status: statusOf(d.status ?? null),
74
112
  type: friendlyFileType(d.file_type, d.file_name, d.folder) || null,
75
113
  folder: d.folder || null,
76
114
  nature: d.doc_metadata?.doc_nature ?? null,
@@ -82,7 +120,7 @@ function createDocumentsSource(labels) {
82
120
  })),
83
121
  [query.data, nameOf]
84
122
  );
85
- return { rows, isLoading: query.isLoading, error: query.error };
123
+ return { rows, isLoading: enabled && query.isPending, error: query.error };
86
124
  }
87
125
  });
88
126
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/datasets/sources/documents.ts"],
4
- "sourcesContent": ["/**\n * The documents of a workspace as a dataset (default: the open one; `params.workspaceId` names\n * another): counts and status by type, folder, author or time. Reads the shared documents list\n * (`useDocuments`), which live updates keep current, so a panel follows uploads as they process.\n */\nimport { useMemo } from 'react'\nimport { useDocuments } from '../../documents/documents-data'\nimport { friendlyFileType } from '../../entities/file-type'\nimport { useNames } from '../members'\nimport { defineRowsSource, staticFields } from '../rows-source'\nimport type { DataSource, DataSourceParams, DatasetField, DatasetRow } from '../types'\n\n/** The field labels (a site's words). */\nexport interface DocumentsSourceLabels {\n source: string\n description: string\n created: string\n updated: string\n documentDate: string\n status: string\n /** A processing status by the server's name; one not listed is shown as it comes. */\n statuses: Readonly<Record<string, string>>\n type: string\n folder: string\n nature: string\n author: string\n createdBy: string\n pages: string\n size: string\n shared: string\n}\n\nexport const DEFAULT_DOCUMENTS_SOURCE_LABELS: DocumentsSourceLabels = {\n source: 'Documents',\n description: 'The documents of the open workspace: type, folder, status, dates.',\n created: 'Added',\n updated: 'Updated',\n documentDate: 'Document date',\n status: 'Status',\n statuses: {\n completed: 'Ready',\n 'low-content': 'Little text',\n failed: 'Failed',\n skipped: 'Skipped',\n empty: 'Empty',\n queued: 'Queued',\n uploading: 'Uploading',\n parsing: 'Processing',\n encrypting: 'Processing',\n indexing: 'Processing',\n analysing: 'Processing',\n },\n type: 'Type',\n folder: 'Folder',\n nature: 'Kind of document',\n author: 'Author',\n createdBy: 'Added by',\n pages: 'Pages',\n size: 'Size',\n shared: 'Shared',\n}\n\ninterface DocumentLike {\n external_id: string\n file_name?: string | null\n file_type?: string | null\n file_size?: number | null\n status?: string | null\n folder?: string | null\n n_pages?: number | null\n shared?: boolean | null\n created_by_ext_id?: string | null\n created_at?: string | null\n updated_at?: string | null\n doc_metadata?: {\n doc_nature?: string | null\n doc_author?: string | null\n doc_date?: string | null\n title?: string | null\n } | null\n}\n\nconst workspaceOf = (params: DataSourceParams) =>\n typeof params.workspaceId === 'string' && params.workspaceId ? params.workspaceId : undefined\n\nexport function createDocumentsSource(labels?: Partial<DocumentsSourceLabels>): DataSource {\n const l = { ...DEFAULT_DOCUMENTS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'name', label: l.source, type: 'string' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'updated', label: l.updated, type: 'date' },\n { id: 'documentDate', label: l.documentDate, type: 'date' },\n {\n id: 'status',\n label: l.status,\n type: 'string',\n options: [...new Set(Object.values(l.statuses))],\n },\n { id: 'type', label: l.type, type: 'string' },\n { id: 'folder', label: l.folder, type: 'string' },\n { id: 'nature', label: l.nature, type: 'string' },\n { id: 'author', label: l.author, type: 'string' },\n { id: 'createdBy', label: l.createdBy, type: 'string' },\n { id: 'pages', label: l.pages, type: 'number' },\n { id: 'size', label: l.size, type: 'number', unit: 'bytes' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n ]\n return defineRowsSource({\n id: 'documents',\n scope: 'workspace',\n label: l.source,\n description: l.description,\n useFields: staticFields(fields),\n useRows(params, enabled) {\n const query = useDocuments(workspaceOf(params), { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n (query.data as DocumentLike[] | undefined)?.map((d): DatasetRow => ({\n name: d.doc_metadata?.title || d.file_name || d.external_id,\n created: d.created_at ?? null,\n updated: d.updated_at ?? null,\n documentDate: d.doc_metadata?.doc_date ?? null,\n status: d.status ? (l.statuses[d.status] ?? d.status) : null,\n type: friendlyFileType(d.file_type, d.file_name, d.folder) || null,\n folder: d.folder || null,\n nature: d.doc_metadata?.doc_nature ?? null,\n author: d.doc_metadata?.doc_author ?? null,\n createdBy: nameOf(d.created_by_ext_id),\n pages: d.n_pages ?? null,\n size: d.file_size ?? null,\n shared: d.shared ?? null,\n })),\n [query.data, nameOf]\n )\n return { rows, isLoading: query.isLoading, error: query.error }\n },\n })\n}\n"],
5
- "mappings": "AAKA,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAuBxC,MAAM,kCAAyD;AAAA,EACpE,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS;AAAA,EACT,SAAS;AAAA,EACT,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,UAAU;AAAA,IACR,WAAW;AAAA,IACX,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,WAAW;AAAA,EACb;AAAA,EACA,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AACV;AAsBA,MAAM,cAAc,CAAC,WACnB,OAAO,OAAO,gBAAgB,YAAY,OAAO,cAAc,OAAO,cAAc;AAE/E,SAAS,sBAAsB,QAAqD;AACzF,QAAM,IAAI,EAAE,GAAG,iCAAiC,GAAG,OAAO;AAC1D,QAAM,SAAyB;AAAA,IAC7B,EAAE,IAAI,QAAQ,OAAO,EAAE,QAAQ,MAAM,SAAS;AAAA,IAC9C,EAAE,IAAI,WAAW,OAAO,EAAE,SAAS,MAAM,OAAO;AAAA,IAChD,EAAE,IAAI,WAAW,OAAO,EAAE,SAAS,MAAM,OAAO;AAAA,IAChD,EAAE,IAAI,gBAAgB,OAAO,EAAE,cAAc,MAAM,OAAO;AA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ACxD,MAAM,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,KAAK;AAAA,UAC9D,QAAQ,EAAE,UAAU;AAAA,UACpB,QAAQ,EAAE,cAAc,cAAc;AAAA,UACtC,QAAQ,EAAE,cAAc,cAAc;AAAA,UACtC,WAAW,OAAO,EAAE,iBAAiB;AAAA,UACrC,OAAO,EAAE,WAAW;AAAA,UACpB,MAAM,EAAE,aAAa;AAAA,UACrB,QAAQ,EAAE,UAAU;AAAA,QACtB,EAAE;AAAA,QACJ,CAAC,MAAM,MAAM,MAAM;AAAA,MACrB;AACA,aAAO,EAAE,MAAM,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,IAChE;AAAA,EACF,CAAC;AACH;",
4
+ "sourcesContent": ["/**\n * The documents of a workspace as a dataset (default: the open one; `params.workspaceId` names\n * another): counts and status by type, folder, author or time. Counted on the server\n * (`defineAggregateSource`), over every document at once; a table of the latest documents reads\n * the shared documents list (`useDocuments`).\n */\nimport { useMemo } from 'react'\nimport { useArbi } from '../../useArbi'\nimport { useDocuments } from '../../documents/documents-data'\nimport { friendlyFileType } from '../../entities/file-type'\nimport { cellText, defineAggregateSource, type AggregateField } from '../aggregate-source'\nimport { useNames } from '../members'\nimport type { DataSource, DataSourceParams, DatasetField, DatasetRow } from '../types'\n\n/** The field labels (a site's words). */\nexport interface DocumentsSourceLabels {\n source: string\n description: string\n created: string\n updated: string\n documentDate: string\n status: string\n /** A processing status by the server's name; one not listed is shown as it comes. */\n statuses: Readonly<Record<string, string>>\n type: string\n folder: string\n nature: string\n author: string\n createdBy: string\n pages: string\n size: string\n shared: string\n}\n\nexport const DEFAULT_DOCUMENTS_SOURCE_LABELS: DocumentsSourceLabels = {\n source: 'Documents',\n description: 'The documents of the open workspace: type, folder, status, dates.',\n created: 'Added',\n updated: 'Updated',\n documentDate: 'Document date',\n status: 'Status',\n statuses: {\n completed: 'Ready',\n 'low-content': 'Little text',\n failed: 'Failed',\n skipped: 'Skipped',\n empty: 'Empty',\n queued: 'Queued',\n uploading: 'Uploading',\n parsing: 'Processing',\n encrypting: 'Processing',\n indexing: 'Processing',\n analysing: 'Processing',\n },\n type: 'Type',\n folder: 'Folder',\n nature: 'Kind of document',\n author: 'Author',\n createdBy: 'Added by',\n pages: 'Pages',\n size: 'Size',\n shared: 'Shared',\n}\n\ninterface DocumentLike {\n external_id: string\n file_name?: string | null\n file_type?: string | null\n file_size?: number | null\n status?: string | null\n folder?: string | null\n n_pages?: number | null\n shared?: boolean | null\n created_by_ext_id?: string | null\n created_at?: string | null\n updated_at?: string | null\n doc_metadata?: {\n doc_nature?: string | null\n doc_author?: string | null\n doc_date?: string | null\n title?: string | null\n } | null\n}\n\nconst workspaceOf = (params: DataSourceParams) =>\n typeof params.workspaceId === 'string' && params.workspaceId ? params.workspaceId : undefined\n\nexport function createDocumentsSource(labels?: Partial<DocumentsSourceLabels>): DataSource {\n const l = { ...DEFAULT_DOCUMENTS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'name', label: l.source, type: 'string' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'updated', label: l.updated, type: 'date' },\n { id: 'documentDate', label: l.documentDate, type: 'date' },\n {\n id: 'status',\n label: l.status,\n type: 'string',\n options: [...new Set(Object.values(l.statuses))],\n },\n { id: 'type', label: l.type, type: 'string' },\n { id: 'folder', label: l.folder, type: 'string' },\n { id: 'nature', label: l.nature, type: 'string' },\n { id: 'author', label: l.author, type: 'string' },\n { id: 'createdBy', label: l.createdBy, type: 'string' },\n { id: 'pages', label: l.pages, type: 'number' },\n { id: 'size', label: l.size, type: 'number', unit: 'bytes' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n ]\n const byId = new Map(fields.map((f) => [f.id, f]))\n const field = (id: string): DatasetField => byId.get(id) ?? { id, label: id, type: 'string' }\n const statusOf = (status: string | null) => (status ? (l.statuses[status] ?? status) : null)\n return defineAggregateSource({\n id: 'documents',\n source: 'documents',\n label: l.source,\n description: l.description,\n fields,\n useAggregateFields(enabled) {\n const nameOf = useNames(enabled)\n return useMemo(\n (): AggregateField[] => [\n { field: field('name'), from: ['name'] },\n { field: field('created'), from: ['created'] },\n { field: field('updated'), from: ['updated'] },\n // Encrypted: the server buckets it, but cannot compare it.\n { field: field('documentDate'), from: ['document_date'], server: false },\n { field: field('status'), from: ['status'], value: ([s]) => statusOf(cellText(s)) },\n {\n field: field('type'),\n // The name's extension, not the name: what a file type is read from.\n from: ['file_type', 'extension', 'folder'],\n value: ([type, extension, folder]) => {\n const ext = cellText(extension)\n return (\n friendlyFileType(cellText(type), ext ? `file.${ext}` : null, cellText(folder)) ||\n null\n )\n },\n },\n { field: field('folder'), from: ['folder'], value: ([f]) => cellText(f) },\n { field: field('nature'), from: ['nature'] },\n { field: field('author'), from: ['author'] },\n { field: field('createdBy'), from: ['created_by'], value: ([u]) => nameOf(cellText(u)) },\n { field: field('pages'), from: ['pages'] },\n { field: field('size'), from: ['size'] },\n { field: field('shared'), from: ['shared'] },\n ],\n [nameOf]\n )\n },\n useWorkspace(params) {\n const arbi = useArbi()\n return workspaceOf(params) ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : undefined)\n },\n useRecords(params, enabled) {\n const query = useDocuments(workspaceOf(params), { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n (query.data as DocumentLike[] | undefined)?.map((d): DatasetRow => ({\n name: d.doc_metadata?.title || d.file_name || d.external_id,\n created: d.created_at ?? null,\n updated: d.updated_at ?? null,\n documentDate: d.doc_metadata?.doc_date ?? null,\n status: statusOf(d.status ?? null),\n type: friendlyFileType(d.file_type, d.file_name, d.folder) || null,\n folder: d.folder || null,\n nature: d.doc_metadata?.doc_nature ?? null,\n author: d.doc_metadata?.doc_author ?? null,\n createdBy: nameOf(d.created_by_ext_id),\n pages: d.n_pages ?? null,\n size: d.file_size ?? null,\n shared: d.shared ?? null,\n })),\n [query.data, nameOf]\n )\n return { rows, isLoading: enabled && query.isPending, error: query.error }\n },\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,SAAS;AAC1B,YAAM,QAAQ,aAAa,YAAY,MAAM,GAAG,EAAE,QAAQ,CAAC;AAC3D,YAAM,SAAS,SAAS,OAAO;AAC/B,YAAM,OAAO;AAAA,QACX,MACG,MAAM,MAAqC,IAAI,CAAC,OAAmB;AAAA,UAClE,MAAM,EAAE,cAAc,SAAS,EAAE,aAAa,EAAE;AAAA,UAChD,SAAS,EAAE,cAAc;AAAA,UACzB,SAAS,EAAE,cAAc;AAAA,UACzB,cAAc,EAAE,cAAc,YAAY;AAAA,UAC1C,QAAQ,SAAS,EAAE,UAAU,IAAI;AAAA,UACjC,MAAM,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,KAAK;AAAA,UAC9D,QAAQ,EAAE,UAAU;AAAA,UACpB,QAAQ,EAAE,cAAc,cAAc;AAAA,UACtC,QAAQ,EAAE,cAAc,cAAc;AAAA,UACtC,WAAW,OAAO,EAAE,iBAAiB;AAAA,UACrC,OAAO,EAAE,WAAW;AAAA,UACpB,MAAM,EAAE,aAAa;AAAA,UACrB,QAAQ,EAAE,UAAU;AAAA,QACtB,EAAE;AAAA,QACJ,CAAC,MAAM,MAAM,MAAM;AAAA,MACrB;AACA,aAAO,EAAE,MAAM,WAAW,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,IAC3E;AAAA,EACF,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,11 @@
1
1
  import { useMemo } from "react";
2
2
  import { useFacts } from "../../facts.js";
3
+ import {
4
+ cellText,
5
+ defineAggregateSource,
6
+ useOpenWorkspace
7
+ } from "../aggregate-source.js";
3
8
  import { useNames } from "../members.js";
4
- import { defineRowsSource, staticFields } from "../rows-source.js";
5
9
  const DEFAULT_FACTS_SOURCE_LABELS = {
6
10
  source: "Facts",
7
11
  description: "The facts of the open workspace: their tags, dates, and whether they are confirmed.",
@@ -24,13 +28,35 @@ function createFactsSource(labels) {
24
28
  { id: "created", label: l.created, type: "date" },
25
29
  { id: "createdBy", label: l.createdBy, type: "string" }
26
30
  ];
27
- return defineRowsSource({
31
+ const byId = new Map(fields.map((f) => [f.id, f]));
32
+ const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
33
+ return defineAggregateSource({
28
34
  id: "facts",
29
- scope: "workspace",
35
+ source: "facts",
30
36
  label: l.source,
31
37
  description: l.description,
32
- useFields: staticFields(fields),
33
- useRows(_params, enabled) {
38
+ fields,
39
+ useAggregateFields(enabled) {
40
+ const nameOf = useNames(enabled);
41
+ return useMemo(
42
+ () => [
43
+ { field: field("text"), from: ["text"] },
44
+ {
45
+ field: field("tags"),
46
+ from: ["tags"],
47
+ value: ([ids], labels2) => Array.isArray(ids) ? ids.map((id) => labels2[id] ?? id) : []
48
+ },
49
+ { field: field("confirmed"), from: ["confirmed"] },
50
+ { field: field("shared"), from: ["shared"] },
51
+ { field: field("date"), from: ["date"] },
52
+ { field: field("created"), from: ["created"] },
53
+ { field: field("createdBy"), from: ["created_by"], value: ([u]) => nameOf(cellText(u)) }
54
+ ],
55
+ [nameOf]
56
+ );
57
+ },
58
+ useWorkspace: useOpenWorkspace,
59
+ useRecords(_params, enabled) {
34
60
  const query = useFacts(void 0, { enabled });
35
61
  const nameOf = useNames(enabled);
36
62
  const rows = useMemo(
@@ -45,7 +71,7 @@ function createFactsSource(labels) {
45
71
  })),
46
72
  [query.data, nameOf]
47
73
  );
48
- return { rows, isLoading: query.isLoading, error: query.error };
74
+ return { rows, isLoading: enabled && query.isPending, error: query.error };
49
75
  }
50
76
  });
51
77
  }