@arbidocs/react 0.5.151 → 0.5.152
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.
- package/dist/{chunk-B6T54X65.cjs → chunk-WJIRX5MS.cjs} +4 -4
- package/dist/chunk-WJIRX5MS.cjs.map +1 -0
- package/dist/datasets/rows-source.js.map +2 -2
- package/dist/datasets/sources/activity.js +1 -1
- package/dist/datasets/sources/activity.js.map +2 -2
- package/dist/datasets/sources/conversations.js +1 -1
- package/dist/datasets/sources/conversations.js.map +2 -2
- package/dist/datasets/sources/database.js +17 -9
- package/dist/datasets/sources/database.js.map +2 -2
- package/dist/datasets/sources/documents.js +1 -1
- package/dist/datasets/sources/documents.js.map +2 -2
- package/dist/datasets/sources/facts.js +1 -1
- package/dist/datasets/sources/facts.js.map +2 -2
- package/dist/datasets/sources/projects.js +1 -1
- package/dist/datasets/sources/projects.js.map +2 -2
- package/dist/datasets/sources/tags.js +1 -1
- package/dist/datasets/sources/tags.js.map +2 -2
- package/dist/datasets/sources/usage.js +5 -4
- package/dist/datasets/sources/usage.js.map +2 -2
- package/dist/datasets/sources/workflows.js +1 -1
- package/dist/datasets/sources/workflows.js.map +2 -2
- package/dist/datasets/sources/workspaces.js +1 -1
- package/dist/datasets/sources/workspaces.js.map +2 -2
- package/dist/datasets/types.js.map +1 -1
- package/dist/index.cjs +245 -237
- package/dist/index.cjs.map +1 -1
- package/dist/{index.d-DbcrFwS6.d.ts → index.d-Dy_Pz6Vl.d.ts} +4 -0
- package/dist/index.d.ts +7 -2
- package/dist/ui/card.js +2 -2
- package/dist/ui/card.js.map +2 -2
- package/dist/ui/index.cjs +151 -151
- package/dist/ui/index.d.ts +1 -1
- package/package.json +3 -3
- package/dist/chunk-B6T54X65.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/datasets/rows-source.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * `defineRowsSource`: an adapter for data whose rows are loaded in the browser. The adapter gives\n * its fields and a hook reading its rows; filtering, grouping and measuring are applied here\n * (`aggregateDataset`), so every such source answers a query the same way.\n */\nimport { useMemo } from 'react'\nimport { aggregateDataset, recordsOf } from './aggregate'\nimport type {\n DataSource,\n DataSourceFieldsState,\n DataSourceParam,\n DataSourceParams,\n DatasetField,\n DatasetQuery,\n DatasetRow,\n DatasetState,\n} from './types'\n\n/** What a rows adapter's hook reads. */\nexport interface RowsState {\n rows: readonly DatasetRow[] | undefined\n isLoading: boolean\n error: unknown\n}\n\nexport interface RowsSourceDefinition {\n id: string\n label: string\n description?: string\n params?: readonly DataSourceParam[]\n scope?: DataSource['scope']\n /** The fields; a hook, so they may depend on loaded data (a project's own fields). */\n useFields: (params: DataSourceParams) => DataSourceFieldsState\n /** The rows (the same fields' ids). */\n useRows: (params: DataSourceParams, enabled: boolean) => RowsState\n}\n\n/** Answer a query over loaded rows: the groups measured, or the records. */\nexport function datasetOf(\n fields: readonly DatasetField[],\n rows: readonly DatasetRow[],\n query: DatasetQuery\n) {\n return query.records\n ? recordsOf({ fields, rows }, query)\n : aggregateDataset({ fields, rows }, query)\n}\n\n/** A `DataSource` over rows loaded in the browser. */\nexport function defineRowsSource(definition: RowsSourceDefinition): DataSource {\n const { useFields, useRows } = definition\n function useDataset(\n params: DataSourceParams,\n query: DatasetQuery,\n options?: { enabled?: boolean }\n ): DatasetState {\n const fields = useFields(params)\n const rows = useRows(params, options?.enabled ?? true)\n const result = useMemo(() => {\n if (!rows.rows) return { dataset: undefined, error: null }\n try {\n return { dataset: datasetOf(fields.fields, rows.rows, query), error: null }\n } catch (error) {\n return { dataset: undefined, error }\n }\n }, [fields.fields, rows.rows, query])\n return {\n dataset: result.dataset,\n isLoading: rows.isLoading || fields.isLoading,\n error: rows.error ?? fields.error ?? result.error,\n }\n }\n return {\n id: definition.id,\n label: definition.label,\n description: definition.description,\n ...(definition.scope ? { scope: definition.scope } : {}),\n params: definition.params,\n useFields,\n useDataset,\n }\n}\n\n/** A fields hook for a fixed list. */\nexport function staticFields(fields: readonly DatasetField[]) {\n const state: DataSourceFieldsState = { fields, isLoading: false, error: null }\n return () => state\n}\n"],
|
|
5
|
-
"mappings": "AAKA,SAAS,eAAe;AACxB,SAAS,kBAAkB,iBAAiB;
|
|
4
|
+
"sourcesContent": ["/**\n * `defineRowsSource`: an adapter for data whose rows are loaded in the browser. The adapter gives\n * its fields and a hook reading its rows; filtering, grouping and measuring are applied here\n * (`aggregateDataset`), so every such source answers a query the same way.\n */\nimport { useMemo } from 'react'\nimport { aggregateDataset, recordsOf } from './aggregate'\nimport type {\n DataSource,\n DataSourceFieldsState,\n DataSourceParam,\n DataSourceParams,\n DatasetField,\n DatasetQuery,\n DatasetRow,\n DatasetState,\n} from './types'\n\n/** What a rows adapter's hook reads. */\nexport interface RowsState {\n rows: readonly DatasetRow[] | undefined\n /** Rows are coming (the query is pending while enabled, even before it starts fetching). */\n isLoading: boolean\n error: unknown\n}\n\nexport interface RowsSourceDefinition {\n id: string\n label: string\n description?: string\n params?: readonly DataSourceParam[]\n scope?: DataSource['scope']\n /** The fields; a hook, so they may depend on loaded data (a project's own fields). */\n useFields: (params: DataSourceParams) => DataSourceFieldsState\n /** The rows (the same fields' ids). */\n useRows: (params: DataSourceParams, enabled: boolean) => RowsState\n}\n\n/** Answer a query over loaded rows: the groups measured, or the records. */\nexport function datasetOf(\n fields: readonly DatasetField[],\n rows: readonly DatasetRow[],\n query: DatasetQuery\n) {\n return query.records\n ? recordsOf({ fields, rows }, query)\n : aggregateDataset({ fields, rows }, query)\n}\n\n/** A `DataSource` over rows loaded in the browser. */\nexport function defineRowsSource(definition: RowsSourceDefinition): DataSource {\n const { useFields, useRows } = definition\n function useDataset(\n params: DataSourceParams,\n query: DatasetQuery,\n options?: { enabled?: boolean }\n ): DatasetState {\n const fields = useFields(params)\n const rows = useRows(params, options?.enabled ?? true)\n const result = useMemo(() => {\n if (!rows.rows) return { dataset: undefined, error: null }\n try {\n return { dataset: datasetOf(fields.fields, rows.rows, query), error: null }\n } catch (error) {\n return { dataset: undefined, error }\n }\n }, [fields.fields, rows.rows, query])\n return {\n dataset: result.dataset,\n isLoading: rows.isLoading || fields.isLoading,\n error: rows.error ?? fields.error ?? result.error,\n }\n }\n return {\n id: definition.id,\n label: definition.label,\n description: definition.description,\n ...(definition.scope ? { scope: definition.scope } : {}),\n params: definition.params,\n useFields,\n useDataset,\n }\n}\n\n/** A fields hook for a fixed list. */\nexport function staticFields(fields: readonly DatasetField[]) {\n const state: DataSourceFieldsState = { fields, isLoading: false, error: null }\n return () => state\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,eAAe;AACxB,SAAS,kBAAkB,iBAAiB;AAiCrC,SAAS,UACd,QACA,MACA,OACA;AACA,SAAO,MAAM,UACT,UAAU,EAAE,QAAQ,KAAK,GAAG,KAAK,IACjC,iBAAiB,EAAE,QAAQ,KAAK,GAAG,KAAK;AAC9C;AAGO,SAAS,iBAAiB,YAA8C;AAC7E,QAAM,EAAE,WAAW,QAAQ,IAAI;AAC/B,WAAS,WACP,QACA,OACA,SACc;AACd,UAAM,SAAS,UAAU,MAAM;AAC/B,UAAM,OAAO,QAAQ,QAAQ,SAAS,WAAW,IAAI;AACrD,UAAM,SAAS,QAAQ,MAAM;AAC3B,UAAI,CAAC,KAAK,KAAM,QAAO,EAAE,SAAS,QAAW,OAAO,KAAK;AACzD,UAAI;AACF,eAAO,EAAE,SAAS,UAAU,OAAO,QAAQ,KAAK,MAAM,KAAK,GAAG,OAAO,KAAK;AAAA,MAC5E,SAAS,OAAO;AACd,eAAO,EAAE,SAAS,QAAW,MAAM;AAAA,MACrC;AAAA,IACF,GAAG,CAAC,OAAO,QAAQ,KAAK,MAAM,KAAK,CAAC;AACpC,WAAO;AAAA,MACL,SAAS,OAAO;AAAA,MAChB,WAAW,KAAK,aAAa,OAAO;AAAA,MACpC,OAAO,KAAK,SAAS,OAAO,SAAS,OAAO;AAAA,IAC9C;AAAA,EACF;AACA,SAAO;AAAA,IACL,IAAI,WAAW;AAAA,IACf,OAAO,WAAW;AAAA,IAClB,aAAa,WAAW;AAAA,IACxB,GAAI,WAAW,QAAQ,EAAE,OAAO,WAAW,MAAM,IAAI,CAAC;AAAA,IACtD,QAAQ,WAAW;AAAA,IACnB;AAAA,IACA;AAAA,EACF;AACF;AAGO,SAAS,aAAa,QAAiC;AAC5D,QAAM,QAA+B,EAAE,QAAQ,WAAW,OAAO,OAAO,KAAK;AAC7E,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -72,7 +72,7 @@ function createActivitySource(labels) {
|
|
|
72
72
|
),
|
|
73
73
|
[feed.data, nameOf]
|
|
74
74
|
);
|
|
75
|
-
return { rows, isLoading: feed.
|
|
75
|
+
return { rows, isLoading: enabled && feed.isPending && !!workspaceId, error: feed.error };
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
}
|
|
@@ -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.
|
|
5
|
-
"mappings": "AASA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAE/C,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,YAA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AAE;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,
|
|
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: enabled && feed.isPending && !!workspaceId, error: feed.error }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AASA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAE/C,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,IAC1C,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM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EAAE,MAAM,IAAK;AAAA,UACnE,EAAE;AAAA,QACJ;AAAA,QACF,CAAC,KAAK,MAAM,MAAM;AAAA,MACpB;AACA,aAAO,EAAE,MAAM,WAAW,WAAW,KAAK,aAAa,CAAC,CAAC,aAAa,OAAO,KAAK,MAAM;AAAA,IAC1F;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -63,7 +63,7 @@ function createConversationsSource(labels) {
|
|
|
63
63
|
shared: c.is_shared ?? null
|
|
64
64
|
}));
|
|
65
65
|
}, [query.data, nameOf]);
|
|
66
|
-
return { rows, isLoading:
|
|
66
|
+
return { rows, isLoading: enabled && query.isPending, error: query.error };
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
}
|
|
@@ -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:
|
|
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,SAAS;AAAA,IAC9C,EAAE,IAAI,WAAW,OAAO,EAAE,SAAS,MAAM,OAAO;AAAA,IAChD,EAAE,IAAI,gBAAgB,OAAO,EAAE,cAAc,MAAM,OAAO;AAAA,IAC1D,EAAE,IAAI,OAAO,OAAO,EAAE,KAAK,MAAM,OAAO;AAAA,IACxC,EAAE,IAAI,aAAa,OAAO,EAAE,WAAW,MAAM,OAAO;AAAA,IACpD,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,UAAU,SAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,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AE,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,
|
|
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: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AACzB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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
|
|
99
|
-
|
|
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.
|
|
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.
|
|
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;A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AAkB,QAA6C;AAC1F,QAAM,SAAS,IAAI,UAAU,CAAC;AAC9B,QAAM,MAAoC,CAAC;AAC3C,aAAW,SAAS,QAAQ;AAC1B,UAAM,MAAM,IAAI,OAAO,MAAM,EAAE;AAC/B,QAAI,QAAQ,QAAQ,QAAQ,OAAW,KAAI,MAAM,EAAE,IAAI;AAAA,aAC9C,MAAM,QAAQ,GAAG,EAAG,KAAI,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC;AAAA,aACjF,OAAO,QAAQ;AACtB,UAAI,MAAM,EAAE,IAAI,MAAM,SAAS,WAAY,OAAO,GAAG,KAAK,MAAO;AAAA,aAC1D,OAAO,QAAQ,YAAY,OAAO,QAAQ,UAAW,KAAI,MAAM,EAAE,IAAI;AAAA,QACzE,KAAI,MAAM,EAAE,IAAI,OAAO,GAAG;AAAA,EACjC;AACA,SAAO;AACT;AAEO,SAAS,qBAAqB,QAAoD;AACvF,QAAM,IAAI,EAAE,GAAG,gCAAgC,GAAG,OAAO;
|
|
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,MAA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a,KAAK,OAAO,WAAW;AAAA,UACtC,CAAC;AACD,gBAAM,UAAU,QAAQ,MAAM;AAC5B,kBAAM,MAAM,CAAC,GAAI,UAAU,QAAQ,CAAC,CAAE;AACtC,gBAAI,QAAQ,QAAQ,CAAC,OAAQ,KAAI,KAAK,QAAQ,IAAI;AAClD,mBAAO,IAAI,IAAI,CAAC,OAAO;AAAA,cACrB,OAAO,EAAE;AAAA,cACT,OAAO,EAAE;AAAA,cACT,QAAQ,EAAE,aAAa,EAAE,aAAa;AAAA,YACxC,EAAE;AAAA,UACJ,GAAG,CAAC,UAAU,MAAM,QAAQ,MAAM,MAAM,CAAC;AACzC,iBAAO,EAAE,SAAS,WAAW,UAAU,aAAa,QAAQ,UAAU;AAAA,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,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.
|
|
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,a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ACA,aAAO,EAAE,MAAM,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,
|
|
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: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
|
|
5
|
+
"m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,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,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/datasets/sources/facts.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The facts (notes) of the open workspace as a dataset: a row per fact with its tags (a fact counts\n * under each), whether it is confirmed, its date and who added it. Reads the shared fact list\n * (`useFacts`), which every fact write refreshes.\n */\nimport { useMemo } from 'react'\nimport type { FactResponse } from '@arbidocs/sdk/browser'\nimport { useFacts } from '../../facts'\nimport { useNames } from '../members'\nimport { defineRowsSource, staticFields } from '../rows-source'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\n\nexport interface FactsSourceLabels {\n source: string\n description: string\n text: string\n tags: string\n confirmed: string\n shared: string\n date: string\n created: string\n createdBy: string\n}\n\nexport const DEFAULT_FACTS_SOURCE_LABELS: FactsSourceLabels = {\n source: 'Facts',\n description:\n 'The facts of the open workspace: their tags, dates, and whether they are confirmed.',\n text: 'Fact',\n tags: 'Tags',\n confirmed: 'Confirmed',\n shared: 'Shared',\n date: 'Date',\n created: 'Added',\n createdBy: 'Added by',\n}\n\nexport function createFactsSource(labels?: Partial<FactsSourceLabels>): DataSource {\n const l = { ...DEFAULT_FACTS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'text', label: l.text, type: 'string' },\n { id: 'tags', label: l.tags, type: 'string', multiple: true },\n { id: 'confirmed', label: l.confirmed, type: 'boolean' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n { id: 'date', label: l.date, type: 'date' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'createdBy', label: l.createdBy, type: 'string' },\n ]\n return defineRowsSource({\n id: 'facts',\n scope: 'workspace',\n label: l.source,\n description: l.description,\n useFields: staticFields(fields),\n useRows(_params, enabled) {\n const query = useFacts(undefined, { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n (query.data as FactResponse[] | undefined)?.map((f): DatasetRow => ({\n text: f.text,\n tags: f.tags.map((t) => t.name),\n confirmed: f.confirmed,\n shared: f.shared,\n date: f.date_start ?? null,\n created: f.created_at,\n createdBy: nameOf(f.created_by_ext_id),\n })),\n [query.data, nameOf]\n )\n return { rows, isLoading: query.
|
|
5
|
-
"mappings": "AAKA,SAAS,eAAe;AAExB,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAexC,MAAM,8BAAiD;AAAA,EAC5D,QAAQ;AAAA,EACR,aACE;AAAA,EACF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,WAAW;AACb;AAEO,SAAS,kBAAkB,QAAiD;AACjF,QAAM,IAAI,EAAE,GAAG,6BAA6B,GAAG,OAAO;AACtD,QAAM,SAAyB;AAAA,IAC7B,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,SAAS;AAAA,IAC5C,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,UAAU,UAAU,KAAK;AAAA,IAC5D,EAAE,IAAI,aAAa,OAAO,EAAE,WAAW,MAAM,UAAU;AAAA,IACvD,EAAE,IAAI,UAAU,OAAO,EAAE,QAAQ,MAAM,UAAU;AAAA,IACjD,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,OAAO;AAAA,IAC1C,EAAE,IAAI,WAAW,OAAO,EAAE,SAAS,MAAM,OAAO;AAAA,IAChD,EAAE,IAAI,aAAa,OAAO,EAAE,WAAW,MAAM,SAAS;AAAA,EACxD;AACA,SAAO,iBAAiB;AAAA,IACtB,IAAI;AAAA,IACJ,OAAO;AAAA,IACP,OAAO,EAAE;AAAA,IACT,aAAa,EAAE;AAAA,IACf,WAAW,aAAa,MAAM;AAAA,IAC9B,QAAQ,SAAS,SAAS;AACxB,YAAM,QAAQ,SAAS,QAAW,EAAE,QAAQ,CAAC;AAC7C,YAAM,SAAS,SAAS,OAAO;AAC/B,YAAM,OAAO;AAAA,QACX,MACG,MAAM,MAAqC,IAAI,CAAC,OAAmB;AAAA,UAClE,MAAM,EAAE;AAAA,UACR,MAAM,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,UAC9B,WAAW,EAAE;AAAA,UACb,QAAQ,EAAE;AAAA,UACV,MAAM,EAAE,cAAc;AAAA,UACtB,SAAS,EAAE;AAAA,UACX,WAAW,OAAO,EAAE,iBAAiB;AAAA,QACvC,EAAE;AAAA,QACJ,CAAC,MAAM,MAAM,MAAM;AAAA,MACrB;AACA,aAAO,EAAE,MAAM,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * The facts (notes) of the open workspace as a dataset: a row per fact with its tags (a fact counts\n * under each), whether it is confirmed, its date and who added it. Reads the shared fact list\n * (`useFacts`), which every fact write refreshes.\n */\nimport { useMemo } from 'react'\nimport type { FactResponse } from '@arbidocs/sdk/browser'\nimport { useFacts } from '../../facts'\nimport { useNames } from '../members'\nimport { defineRowsSource, staticFields } from '../rows-source'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\n\nexport interface FactsSourceLabels {\n source: string\n description: string\n text: string\n tags: string\n confirmed: string\n shared: string\n date: string\n created: string\n createdBy: string\n}\n\nexport const DEFAULT_FACTS_SOURCE_LABELS: FactsSourceLabels = {\n source: 'Facts',\n description:\n 'The facts of the open workspace: their tags, dates, and whether they are confirmed.',\n text: 'Fact',\n tags: 'Tags',\n confirmed: 'Confirmed',\n shared: 'Shared',\n date: 'Date',\n created: 'Added',\n createdBy: 'Added by',\n}\n\nexport function createFactsSource(labels?: Partial<FactsSourceLabels>): DataSource {\n const l = { ...DEFAULT_FACTS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'text', label: l.text, type: 'string' },\n { id: 'tags', label: l.tags, type: 'string', multiple: true },\n { id: 'confirmed', label: l.confirmed, type: 'boolean' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n { id: 'date', label: l.date, type: 'date' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'createdBy', label: l.createdBy, type: 'string' },\n ]\n return defineRowsSource({\n id: 'facts',\n scope: 'workspace',\n label: l.source,\n description: l.description,\n useFields: staticFields(fields),\n useRows(_params, enabled) {\n const query = useFacts(undefined, { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n (query.data as FactResponse[] | undefined)?.map((f): DatasetRow => ({\n text: f.text,\n tags: f.tags.map((t) => t.name),\n confirmed: f.confirmed,\n shared: f.shared,\n date: f.date_start ?? null,\n created: f.created_at,\n createdBy: nameOf(f.created_by_ext_id),\n })),\n [query.data, nameOf]\n )\n return { rows, isLoading: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,eAAe;AAExB,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAexC,MAAM,8BAAiD;AAAA,EAC5D,QAAQ;AAAA,EACR,aACE;AAAA,EACF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,WAAW;AACb;AAEO,SAAS,kBAAkB,QAAiD;AACjF,QAAM,IAAI,EAAE,GAAG,6BAA6B,GAAG,OAAO;AACtD,QAAM,SAAyB;AAAA,IAC7B,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,SAAS;AAAA,IAC5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-
return { rows, isLoading: query.
|
|
109
|
+
return { rows, isLoading: enabled && query.isPending, error: query.error };
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/datasets/sources/projects.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The user's projects as a dataset: by stage, lead, client and the host's own project fields, and\n * opened or closed over time. Reads the shared project list (`useProjects`).\n *\n * The backend records a stage and when it last changed, not a \"closed\" flag: a host that has\n * closing stages names them (`closedStages`), and a project in one of them is closed as of its\n * stage change. A site's word for a project and its stages come in through `labels`.\n */\nimport { useMemo } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { useProjects } from '../../hooks'\nimport { useNames } from '../members'\nimport { defineRowsSource } from '../rows-source'\nimport type { DataSource, DataSourceFieldsState, DatasetField, DatasetRow } from '../types'\n\ntype ProjectResponse = components['schemas']['ProjectResponse']\ntype FieldSchemaEntry = components['schemas']['FieldSchemaEntry']\n\nexport interface ProjectsSourceLabels {\n source: string\n description: string\n name: string\n opened: string\n stage: string\n stageChanged: string\n lead: string\n client: string\n plan: string\n state: string\n open: string\n closed: string\n closedAt: string\n}\n\nexport const DEFAULT_PROJECTS_SOURCE_LABELS: ProjectsSourceLabels = {\n source: 'Projects',\n description: 'Your projects: stage, lead, client and their own fields; opened and closed.',\n name: 'Name',\n opened: 'Opened',\n stage: 'Stage',\n stageChanged: 'Stage changed',\n lead: 'Lead',\n client: 'Client',\n plan: 'Plan',\n state: 'Open or closed',\n open: 'Open',\n closed: 'Closed',\n closedAt: 'Closed',\n}\n\nexport interface ProjectsSourceOptions {\n labels?: Partial<ProjectsSourceLabels>\n /** Stages that close a project (compared without case). */\n closedStages?: readonly string[]\n}\n\nconst FIELD_PREFIX = 'field:'\n\nfunction hostField(entry: FieldSchemaEntry): DatasetField {\n const type =\n entry.type === 'number' || entry.type === 'rollup'\n ? 'number'\n : entry.type === 'date'\n ? 'date'\n : entry.type === 'checkbox'\n ? 'boolean'\n : 'string'\n return {\n id: `${FIELD_PREFIX}${entry.key}`,\n label: entry.label || entry.key,\n type,\n ...(entry.options?.length ? { options: entry.options } : {}),\n }\n}\n\n/** A host field's cell as a dataset value. */\nfunction hostValue(value: unknown, field: DatasetField): DatasetRow[string] {\n if (value === null || value === undefined || value === '') return null\n if (Array.isArray(value)) return value.map(String)\n if (field.type === 'number') return typeof value === 'number' ? value : Number(value) || null\n if (field.type === 'boolean') return Boolean(value)\n return String(value)\n}\n\nexport function createProjectsSource(options: ProjectsSourceOptions = {}): DataSource {\n const l = { ...DEFAULT_PROJECTS_SOURCE_LABELS, ...options.labels }\n const closing = new Set((options.closedStages ?? []).map((s) => s.toLowerCase()))\n const base: DatasetField[] = [\n { id: 'name', label: l.name, type: 'string' },\n { id: 'opened', label: l.opened, type: 'date' },\n { id: 'stage', label: l.stage, type: 'string' },\n { id: 'stageChanged', label: l.stageChanged, type: 'date' },\n { id: 'lead', label: l.lead, type: 'string' },\n { id: 'client', label: l.client, type: 'string' },\n { id: 'plan', label: l.plan, type: 'string' },\n ...(closing.size\n ? [\n { id: 'state', label: l.state, type: 'string' as const, options: [l.open, l.closed] },\n { id: 'closedAt', label: l.closedAt, type: 'date' as const },\n ]\n : []),\n ]\n\n /** The host fields every project declares (the first declaration of a key wins). */\n function fieldsOf(projects: readonly ProjectResponse[] | undefined): DatasetField[] {\n const seen = new Map<string, DatasetField>()\n for (const p of projects ?? []) {\n for (const entry of p.field_schema ?? []) {\n if (!seen.has(entry.key)) seen.set(entry.key, hostField(entry))\n }\n }\n return [...base, ...seen.values()]\n }\n\n return defineRowsSource({\n id: 'projects',\n label: l.source,\n description: l.description,\n useFields(): DataSourceFieldsState {\n const query = useProjects()\n const fields = useMemo(\n () => fieldsOf(query.data as ProjectResponse[] | undefined),\n [query.data]\n )\n return { fields, isLoading: query.isLoading, error: query.error }\n },\n useRows(_params, enabled) {\n const query = useProjects({ enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(() => {\n const projects = query.data as ProjectResponse[] | undefined\n if (!projects) return undefined\n const host = fieldsOf(projects).filter((f) => f.id.startsWith(FIELD_PREFIX))\n const people = new Set(\n projects.flatMap((p) =>\n (p.field_schema ?? []).filter((e) => e.type === 'person').map((e) => e.key)\n )\n )\n return projects.map((p): DatasetRow => {\n const closed = !!p.stage && closing.has(p.stage.toLowerCase())\n const row: Record<string, DatasetRow[string]> = {\n name: p.name,\n opened: p.created_at,\n stage: p.stage ?? null,\n stageChanged: p.stage_changed_at ?? null,\n lead: nameOf(p.lead_user),\n client: p.client ?? null,\n plan: p.subscription ?? null,\n }\n if (closing.size) {\n row.state = closed ? l.closed : l.open\n row.closedAt = closed ? (p.stage_changed_at ?? null) : null\n }\n for (const field of host) {\n const key = field.id.slice(FIELD_PREFIX.length)\n const value = hostValue(p.fields?.[key], field)\n row[field.id] =\n people.has(key) && value !== null\n ? Array.isArray(value)\n ? value.map((id) => nameOf(id) ?? id)\n : nameOf(String(value))\n : value\n }\n return row\n })\n }, [query.data, nameOf])\n return { rows, isLoading: query.
|
|
5
|
-
"mappings": "AAQA,SAAS,eAAe;AAExB,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AAsB1B,MAAM,iCAAuD;AAAA,EAClE,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,cAAc;AAAA,EACd,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU;AACZ;AAQA,MAAM,eAAe;AAErB,SAAS,UAAU,OAAuC;AACxD,QAAM,OACJ,MAAM,SAAS,YAAY,MAAM,SAAS,WACtC,WACA,MAAM,SAAS,SACb,SACA,MAAM,SAAS,aACb,YACA;AACV,SAAO;AAAA,IACL,IAAI,GAAG,YAAY,GA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MAAkB;AACrC,gBAAM,SAAS,CAAC,CAAC,EAAE,SAAS,QAAQ,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7D,gBAAM,MAA0C;AAAA,YAC9C,MAAM,EAAE;AAAA,YACR,QAAQ,EAAE;AAAA,YACV,OAAO,EAAE,SAAS;AAAA,YAClB,cAAc,EAAE,oBAAoB;AAAA,YACpC,MAAM,OAAO,EAAE,SAAS;AAAA,YACxB,QAAQ,EAAE,UAAU;AAAA,YACpB,MAAM,EAAE,gBAAgB;AAAA,UAC1B;AACA,cAAI,QAAQ,MAAM;AAChB,gBAAI,QAAQ,SAAS,EAAE,SAAS,EAAE;AAClC,gBAAI,WAAW,SAAU,EAAE,oBAAoB,OAAQ;AAAA,UACzD;AACA,qBAAW,SAAS,MAAM;AACxB,kBAAM,MAAM,MAAM,GAAG,MAAM,aAAa,MAAM;AAC9C,kBAAM,QAAQ,UAAU,EAAE,SAAS,GAAG,GAAG,KAAK;AAC9C,gBAAI,MAAM,EAAE,IACV,OAAO,IAAI,GAAG,KAAK,UAAU,OACzB,MAAM,QAAQ,KAAK,IACjB,MAAM,IAAI,CAAC,OAAO,OAAO,EAAE,KAAK,EAAE,IAClC,OAAO,OAAO,KAAK,CAAC,IACtB;AAAA,UACR;AACA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH,GAAG,CAAC,MAAM,MAAM,MAAM,CAAC;AACvB,aAAO,EAAE,MAAM,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * The user's projects as a dataset: by stage, lead, client and the host's own project fields, and\n * opened or closed over time. Reads the shared project list (`useProjects`).\n *\n * The backend records a stage and when it last changed, not a \"closed\" flag: a host that has\n * closing stages names them (`closedStages`), and a project in one of them is closed as of its\n * stage change. A site's word for a project and its stages come in through `labels`.\n */\nimport { useMemo } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { useProjects } from '../../hooks'\nimport { useNames } from '../members'\nimport { defineRowsSource } from '../rows-source'\nimport type { DataSource, DataSourceFieldsState, DatasetField, DatasetRow } from '../types'\n\ntype ProjectResponse = components['schemas']['ProjectResponse']\ntype FieldSchemaEntry = components['schemas']['FieldSchemaEntry']\n\nexport interface ProjectsSourceLabels {\n source: string\n description: string\n name: string\n opened: string\n stage: string\n stageChanged: string\n lead: string\n client: string\n plan: string\n state: string\n open: string\n closed: string\n closedAt: string\n}\n\nexport const DEFAULT_PROJECTS_SOURCE_LABELS: ProjectsSourceLabels = {\n source: 'Projects',\n description: 'Your projects: stage, lead, client and their own fields; opened and closed.',\n name: 'Name',\n opened: 'Opened',\n stage: 'Stage',\n stageChanged: 'Stage changed',\n lead: 'Lead',\n client: 'Client',\n plan: 'Plan',\n state: 'Open or closed',\n open: 'Open',\n closed: 'Closed',\n closedAt: 'Closed',\n}\n\nexport interface ProjectsSourceOptions {\n labels?: Partial<ProjectsSourceLabels>\n /** Stages that close a project (compared without case). */\n closedStages?: readonly string[]\n}\n\nconst FIELD_PREFIX = 'field:'\n\nfunction hostField(entry: FieldSchemaEntry): DatasetField {\n const type =\n entry.type === 'number' || entry.type === 'rollup'\n ? 'number'\n : entry.type === 'date'\n ? 'date'\n : entry.type === 'checkbox'\n ? 'boolean'\n : 'string'\n return {\n id: `${FIELD_PREFIX}${entry.key}`,\n label: entry.label || entry.key,\n type,\n ...(entry.options?.length ? { options: entry.options } : {}),\n }\n}\n\n/** A host field's cell as a dataset value. */\nfunction hostValue(value: unknown, field: DatasetField): DatasetRow[string] {\n if (value === null || value === undefined || value === '') return null\n if (Array.isArray(value)) return value.map(String)\n if (field.type === 'number') return typeof value === 'number' ? value : Number(value) || null\n if (field.type === 'boolean') return Boolean(value)\n return String(value)\n}\n\nexport function createProjectsSource(options: ProjectsSourceOptions = {}): DataSource {\n const l = { ...DEFAULT_PROJECTS_SOURCE_LABELS, ...options.labels }\n const closing = new Set((options.closedStages ?? []).map((s) => s.toLowerCase()))\n const base: DatasetField[] = [\n { id: 'name', label: l.name, type: 'string' },\n { id: 'opened', label: l.opened, type: 'date' },\n { id: 'stage', label: l.stage, type: 'string' },\n { id: 'stageChanged', label: l.stageChanged, type: 'date' },\n { id: 'lead', label: l.lead, type: 'string' },\n { id: 'client', label: l.client, type: 'string' },\n { id: 'plan', label: l.plan, type: 'string' },\n ...(closing.size\n ? [\n { id: 'state', label: l.state, type: 'string' as const, options: [l.open, l.closed] },\n { id: 'closedAt', label: l.closedAt, type: 'date' as const },\n ]\n : []),\n ]\n\n /** The host fields every project declares (the first declaration of a key wins). */\n function fieldsOf(projects: readonly ProjectResponse[] | undefined): DatasetField[] {\n const seen = new Map<string, DatasetField>()\n for (const p of projects ?? []) {\n for (const entry of p.field_schema ?? []) {\n if (!seen.has(entry.key)) seen.set(entry.key, hostField(entry))\n }\n }\n return [...base, ...seen.values()]\n }\n\n return defineRowsSource({\n id: 'projects',\n label: l.source,\n description: l.description,\n useFields(): DataSourceFieldsState {\n const query = useProjects()\n const fields = useMemo(\n () => fieldsOf(query.data as ProjectResponse[] | undefined),\n [query.data]\n )\n return { fields, isLoading: query.isLoading, error: query.error }\n },\n useRows(_params, enabled) {\n const query = useProjects({ enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(() => {\n const projects = query.data as ProjectResponse[] | undefined\n if (!projects) return undefined\n const host = fieldsOf(projects).filter((f) => f.id.startsWith(FIELD_PREFIX))\n const people = new Set(\n projects.flatMap((p) =>\n (p.field_schema ?? []).filter((e) => e.type === 'person').map((e) => e.key)\n )\n )\n return projects.map((p): DatasetRow => {\n const closed = !!p.stage && closing.has(p.stage.toLowerCase())\n const row: Record<string, DatasetRow[string]> = {\n name: p.name,\n opened: p.created_at,\n stage: p.stage ?? null,\n stageChanged: p.stage_changed_at ?? null,\n lead: nameOf(p.lead_user),\n client: p.client ?? null,\n plan: p.subscription ?? null,\n }\n if (closing.size) {\n row.state = closed ? l.closed : l.open\n row.closedAt = closed ? (p.stage_changed_at ?? null) : null\n }\n for (const field of host) {\n const key = field.id.slice(FIELD_PREFIX.length)\n const value = hostValue(p.fields?.[key], field)\n row[field.id] =\n people.has(key) && value !== null\n ? Array.isArray(value)\n ? value.map((id) => nameOf(id) ?? id)\n : nameOf(String(value))\n : value\n }\n return row\n })\n }, [query.data, nameOf])\n return { rows, isLoading: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AAQA,SAAS,eAAe;AAExB,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AAsB1B,MAAM,iCAAuD;AAAA,EAClE,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,cAAc;AAAA,EACd,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU;AACZ;AAQA,MAAM,eAAe;AAErB,SAAS,UAAU,OAAuC;AACxD,QAAM,OACJ,MAAM,SAAS,YAAY,MAAM,SAAS,WACtC,WACA,MAAM,SAAS,SACb,SACA,MAAM,SAAS,aACb,YACA;AACV,SAAO;AAAA,IACL,IAAI,GAAG,YAAY,GAAG,MAAM,GAAG;AAAA,IAC/B,OAAO,MAAM,SAAS,MAAM;AAAA,IAC5B;AAAA,IACA,GAAI,MAAM,SAAS,SAAS,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,EAC5D;AACF;AAGA,SAAS,UAAU,OAAgB,OAAyC;AAC1E,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,GAAI,QAAO;AAClE,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,IAAI,MAAM;AACjD,MAAI,MAAM,SAAS,SAAU,QAAO,OAAO,UAAU,WAAW,QAAQ,OAAO,KAAK,KAAK;AACzF,MAAI,MAAM,SAAS,UAAW,QAAO,QAAQ,KAAK;AAClD,SAAO,OAAO,KAAK;AACrB;AAEO,SAAS,qBAAqB,U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xB,kBAAM,MAAM,MAAM,GAAG,MAAM,aAAa,MAAM;AAC9C,kBAAM,QAAQ,UAAU,EAAE,SAAS,GAAG,GAAG,KAAK;AAC9C,gBAAI,MAAM,EAAE,IACV,OAAO,IAAI,GAAG,KAAK,UAAU,OACzB,MAAM,QAAQ,KAAK,IACjB,MAAM,IAAI,CAAC,OAAO,OAAO,EAAE,KAAK,EAAE,IAClC,OAAO,OAAO,KAAK,CAAC,IACtB;AAAA,UACR;AACA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH,GAAG,CAAC,MAAM,MAAM,MAAM,CAAC;AACvB,aAAO,EAAE,MAAM,WAAW,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,IAC3E;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/datasets/sources/tags.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The tags of the open workspace as a dataset: a row per tag with its kind, and how many\n * documents, facts and threads carry it. The most used tags, or tags by kind, are a group-by and a\n * sum away. Reads the shared tag list (`useTags`), which every tag write keeps current.\n */\nimport { useMemo } from 'react'\nimport type { TagResponse } from '@arbidocs/sdk/browser'\nimport { useTags } from '../../hooks'\nimport { useNames } from '../members'\nimport { defineRowsSource, staticFields } from '../rows-source'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\n\nexport interface TagsSourceLabels {\n source: string\n description: string\n name: string\n kind: string\n kinds: Record<TagResponse['kind'], string>\n documents: string\n facts: string\n threads: string\n shared: string\n created: string\n createdBy: string\n}\n\nexport const DEFAULT_TAGS_SOURCE_LABELS: TagsSourceLabels = {\n source: 'Tags',\n description:\n 'The tags of the open workspace: their kind, and the documents, facts and threads carrying them.',\n name: 'Tag',\n kind: 'Kind',\n kinds: {\n label: 'Label',\n annotation: 'Annotation',\n search: 'Search',\n issue: 'Issue',\n person: 'Person',\n organisation: 'Organisation',\n },\n documents: 'Documents',\n facts: 'Facts',\n threads: 'Threads',\n shared: 'Shared',\n created: 'Created',\n createdBy: 'Created by',\n}\n\nexport function createTagsSource(labels?: Partial<TagsSourceLabels>): DataSource {\n const l = { ...DEFAULT_TAGS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'name', label: l.name, type: 'string' },\n { id: 'kind', label: l.kind, type: 'string', options: Object.values(l.kinds) },\n { id: 'documents', label: l.documents, type: 'number' },\n { id: 'facts', label: l.facts, type: 'number' },\n { id: 'threads', label: l.threads, type: 'number' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'createdBy', label: l.createdBy, type: 'string' },\n ]\n return defineRowsSource({\n id: 'tags',\n scope: 'workspace',\n label: l.source,\n description: l.description,\n useFields: staticFields(fields),\n useRows(_params, enabled) {\n const query = useTags(undefined, { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n (query.data as TagResponse[] | undefined)?.map((t): DatasetRow => ({\n name: t.name,\n kind: l.kinds[t.kind] ?? t.kind,\n documents: t.doctag_count,\n facts: t.facttag_count,\n threads: t.convotag_count,\n shared: t.shared,\n created: t.created_at,\n createdBy: nameOf(t.created_by_ext_id),\n })),\n [query.data, nameOf]\n )\n return { rows, isLoading: query.
|
|
5
|
-
"mappings": "AAKA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAiBxC,MAAM,6BAA+C;AAAA,EAC1D,QAAQ;AAAA,EACR,aACE;AAAA,EACF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,IACL,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,cAAc;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,EACX,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAA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vC,EAAE;AAAA,QACJ,CAAC,MAAM,MAAM,MAAM;AAAA,MACrB;AACA,aAAO,EAAE,MAAM,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * The tags of the open workspace as a dataset: a row per tag with its kind, and how many\n * documents, facts and threads carry it. The most used tags, or tags by kind, are a group-by and a\n * sum away. Reads the shared tag list (`useTags`), which every tag write keeps current.\n */\nimport { useMemo } from 'react'\nimport type { TagResponse } from '@arbidocs/sdk/browser'\nimport { useTags } from '../../hooks'\nimport { useNames } from '../members'\nimport { defineRowsSource, staticFields } from '../rows-source'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\n\nexport interface TagsSourceLabels {\n source: string\n description: string\n name: string\n kind: string\n kinds: Record<TagResponse['kind'], string>\n documents: string\n facts: string\n threads: string\n shared: string\n created: string\n createdBy: string\n}\n\nexport const DEFAULT_TAGS_SOURCE_LABELS: TagsSourceLabels = {\n source: 'Tags',\n description:\n 'The tags of the open workspace: their kind, and the documents, facts and threads carrying them.',\n name: 'Tag',\n kind: 'Kind',\n kinds: {\n label: 'Label',\n annotation: 'Annotation',\n search: 'Search',\n issue: 'Issue',\n person: 'Person',\n organisation: 'Organisation',\n },\n documents: 'Documents',\n facts: 'Facts',\n threads: 'Threads',\n shared: 'Shared',\n created: 'Created',\n createdBy: 'Created by',\n}\n\nexport function createTagsSource(labels?: Partial<TagsSourceLabels>): DataSource {\n const l = { ...DEFAULT_TAGS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'name', label: l.name, type: 'string' },\n { id: 'kind', label: l.kind, type: 'string', options: Object.values(l.kinds) },\n { id: 'documents', label: l.documents, type: 'number' },\n { id: 'facts', label: l.facts, type: 'number' },\n { id: 'threads', label: l.threads, type: 'number' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'createdBy', label: l.createdBy, type: 'string' },\n ]\n return defineRowsSource({\n id: 'tags',\n scope: 'workspace',\n label: l.source,\n description: l.description,\n useFields: staticFields(fields),\n useRows(_params, enabled) {\n const query = useTags(undefined, { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n (query.data as TagResponse[] | undefined)?.map((t): DatasetRow => ({\n name: t.name,\n kind: l.kinds[t.kind] ?? t.kind,\n documents: t.doctag_count,\n facts: t.facttag_count,\n threads: t.convotag_count,\n shared: t.shared,\n created: t.created_at,\n createdBy: nameOf(t.created_by_ext_id),\n })),\n [query.data, nameOf]\n )\n return { rows, isLoading: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAiBxC,MAAM,6BAA+C;AAAA,EAC1D,QAAQ;AAAA,EACR,aACE;AAAA,EACF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,IACL,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,cAAc;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,EACX,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AACb;AAEO,SAAS,iBAAiB,QAAgD;AAC/E,QAAM,IAAI,EAAE,GAAG,4BAA4B,GAAG,OAAO;AACrD,QAAM,SAAyB;AAAA,IAC7B,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,SAAS;AAAA,IAC5C,EAAE,IAAI,QAAQ,OAAO,EAAE,MAAM,MAAM,UAAU,SAAS,OAAO,OAAO,EAAE,KAAK,EAAE;AAAA,IAC7E,EAAE,IAAI,aAAa,OAAO,EAAE,WAAW,MAAM,SAAS;AAAA,IACtD,EAAE,IAAI,SAAS,OAAO,EAAE,OAAO,MAAM,SAAS;AAAA,IAC9C,EAAE,IAAI,WAAW,OAAO,EAAE,SAAS,MAAM,SAAS;AAAA,IAClD,EAAE,IAAI,UAAU,OAAO,EAAE,QAAQ,MAAM,UAAU;AAAA,IACjD,EAAE,IAAI,WAAW,OAAO,EAAE,SAAS,MAAM,OAAO;AAAA,IAChD,EAAE,IAAI,aAAa,OAAO,EAAE,WAAW,MAAM,SAAS;AAAA,EACxD;AACA,SAAO,iBAAiB;AAAA,IACtB,IAAI;AAAA,IACJ,OAAO;AAAA,IACP,OAAO,EAAE;AAAA,IACT,aAAa,EAAE;AAAA,IACf,WAAW,aAAa,MAAM;AAAA,IAC9B,QAAQ,SAAS,SAAS;AACxB,YAAM,QAAQ,QAAQ,QAAW,EAAE,QAAQ,CAAC;AAC5C,YAAM,SAAS,SAAS,OAAO;AAC/B,YAAM,OAAO;AAAA,QACX,MACG,MAAM,MAAoC,IAAI,CAAC,OAAmB;AAAA,UACjE,MAAM,EAAE;AAAA,UACR,MAAM,EAAE,MAAM,EAAE,IAAI,KAAK,EAAE;AAAA,UAC3B,WAAW,EAAE;AAAA,UACb,OAAO,EAAE;AAAA,UACT,SAAS,EAAE;AAAA,UACX,QAAQ,EAAE;AAAA,UACV,SAAS,EAAE;AAAA,UACX,WAAW,OAAO,EAAE,iBAAiB;AAAA,QACvC,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
|
}
|
|
@@ -128,21 +128,22 @@ function useUsageResponses(params, enabled) {
|
|
|
128
128
|
}))
|
|
129
129
|
});
|
|
130
130
|
const signature = results.map((r) => `${r.status}:${r.dataUpdatedAt}`).join("|");
|
|
131
|
+
const loading = enabled && arbi.isLoggedIn && results.some((r) => r.isPending);
|
|
132
|
+
const userPending = enabled && arbi.isLoggedIn && !only && user.isPending;
|
|
131
133
|
const usages = useMemo(() => {
|
|
132
|
-
if (
|
|
134
|
+
if (loading) return void 0;
|
|
133
135
|
if (!only && (!projects.data || !me)) return void 0;
|
|
134
136
|
return results.map((r, i) => ({
|
|
135
137
|
project: list[i],
|
|
136
138
|
usage: r.data
|
|
137
139
|
}));
|
|
138
|
-
}, [projects.data, me, only, signature]);
|
|
139
|
-
const loading = results.some((r) => r.isLoading);
|
|
140
|
+
}, [projects.data, me, only, signature, loading]);
|
|
140
141
|
return only ? (
|
|
141
142
|
// One project: its usage is the point, so its error shows (the project's name can wait).
|
|
142
143
|
{ usages, isLoading: loading, error: results[0]?.error ?? null }
|
|
143
144
|
) : {
|
|
144
145
|
usages,
|
|
145
|
-
isLoading: projects.
|
|
146
|
+
isLoading: enabled && projects.isPending || userPending || loading,
|
|
146
147
|
// One project's usage failing (not its owner after all, a hiccup) leaves it out.
|
|
147
148
|
error: projects.error ?? user.error ?? null
|
|
148
149
|
};
|