@arbidocs/react 0.5.152 → 0.5.154
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/artifacts/index.cjs +14 -14
- package/dist/calls/livekit/index.cjs +48 -48
- package/dist/{chunk-VXFTVWEI.cjs → chunk-4VHECR5O.cjs} +44 -44
- package/dist/{chunk-VXFTVWEI.cjs.map → chunk-4VHECR5O.cjs.map} +1 -1
- package/dist/{chunk-GFX7LQGR.cjs → chunk-5LKTSVTE.cjs} +66 -66
- package/dist/{chunk-GFX7LQGR.cjs.map → chunk-5LKTSVTE.cjs.map} +1 -1
- package/dist/{chunk-P2DPOZBS.cjs → chunk-5ZNO77YB.cjs} +11 -2
- package/dist/chunk-5ZNO77YB.cjs.map +1 -0
- package/dist/{chunk-BI7HFGXF.cjs → chunk-H2TP7JWR.cjs} +10 -10
- package/dist/{chunk-BI7HFGXF.cjs.map → chunk-H2TP7JWR.cjs.map} +1 -1
- package/dist/{chunk-WJIRX5MS.cjs → chunk-XQLJSNAL.cjs} +3 -3
- package/dist/{chunk-WJIRX5MS.cjs.map → chunk-XQLJSNAL.cjs.map} +1 -1
- package/dist/{chunk-MK5L56Z3.cjs → chunk-ZBCTLPO5.cjs} +57 -57
- package/dist/{chunk-MK5L56Z3.cjs.map → chunk-ZBCTLPO5.cjs.map} +1 -1
- package/dist/{chunk-SKJWJ3OY.cjs → chunk-ZELH6W5C.cjs} +37 -37
- package/dist/{chunk-SKJWJ3OY.cjs.map → chunk-ZELH6W5C.cjs.map} +1 -1
- package/dist/datasets/aggregate-source.js +133 -0
- package/dist/datasets/aggregate-source.js.map +7 -0
- package/dist/datasets/aggregate.js +72 -22
- package/dist/datasets/aggregate.js.map +2 -2
- package/dist/datasets/index.js +32 -2
- package/dist/datasets/index.js.map +2 -2
- package/dist/datasets/pages.js +70 -7
- package/dist/datasets/pages.js.map +2 -2
- package/dist/datasets/sources/activity.js +44 -9
- package/dist/datasets/sources/activity.js.map +2 -2
- package/dist/datasets/sources/conversations.js +37 -7
- package/dist/datasets/sources/conversations.js.map +2 -2
- package/dist/datasets/sources/documents.js +44 -6
- package/dist/datasets/sources/documents.js.map +2 -2
- package/dist/datasets/sources/facts.js +31 -5
- package/dist/datasets/sources/facts.js.map +3 -3
- package/dist/datasets/sources/tags.js +37 -5
- package/dist/datasets/sources/tags.js.map +3 -3
- package/dist/datasets/sources/usage.js +29 -32
- package/dist/datasets/sources/usage.js.map +2 -2
- package/dist/datasets/sources/workflows.js +56 -22
- package/dist/datasets/sources/workflows.js.map +2 -2
- package/dist/datasets/workspace-aggregate.js +64 -0
- package/dist/datasets/workspace-aggregate.js.map +7 -0
- package/dist/document-tools/core.cjs +100 -100
- package/dist/document-tools/core.d.ts +2 -2
- package/dist/document-tools/index.cjs +102 -102
- package/dist/document-tools/index.d.ts +2 -2
- package/dist/{file-shares.d-CamKxNLC.d.ts → file-shares.d-CyTnJ2Re.d.ts} +11 -0
- package/dist/index.cjs +2309 -1787
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +196 -7
- package/dist/index.js +11 -2
- package/dist/index.js.map +2 -2
- package/dist/projects.js +9 -0
- package/dist/projects.js.map +2 -2
- package/dist/query-keys.js +9 -0
- package/dist/query-keys.js.map +2 -2
- package/dist/storage.js +24 -1
- package/dist/storage.js.map +2 -2
- package/dist/table-views.js +19 -1
- package/dist/table-views.js.map +2 -2
- package/dist/ui/index.cjs +168 -168
- package/package.json +3 -3
- package/dist/chunk-P2DPOZBS.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/datasets/pages.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Pages: the open workspace's layouts of live blocks (charts, metrics, text and table views), kept\n * on the server (`arbi.pages`, `/v1/pages`) under the workspace key. A page is its creator's until\n * shared. Sharing is one-way: a shared page is every member's to read and every editor's to edit,\n * and only a workspace owner deletes it. A shared page never shows a private view (the server\n * refuses: `PagePrivateContentError`).\n *\n * A page is a 12-column grid: each block has a place and a size (`layout`). Chart and metric blocks\n * carry an Analytics panel's config (source, chart); a table block carries only the view it shows.\n * Dashboards saved before pages come back as private pages (`legacy`), opened with the user's key;\n * saving one places it in the open workspace.\n */\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport type { Page, PageSpecWire } from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../query-keys'\nimport type { ChartSpec, DashboardSpec, DataSourceRef, PanelSpec } from './types'\n\n/**\n * The transient view through which a host asks for a chart of a database (\"Chart this\"): set it to\n * `{ id, name, workspaceId }` and open the pages, which start a new page on that database and clear it.\n */\nexport const ANALYTICS_CHART_VIEW = 'analytics.chartDatabase'\n\n/** A database to chart. */\nexport interface AnalyticsChartRequest {\n id: string\n name: string\n /** The database's workspace, so the new blocks read it from anywhere. */\n workspaceId?: string\n}\n\n/** The columns of a page's grid. */\nexport const PAGE_GRID_COLUMNS = 12\n\nexport type PageBlockKind = 'chart' | 'metric' | 'text' | 'table' | 'document' | 'gallery'\n\n/** Where a block sits: column `x` (0\u201311) and row `y`, `w` columns wide and `h` rows high. */\nexport interface BlockLayout {\n x: number\n y: number\n w: number\n h: number\n}\n\n/** A chart or metric block: what an Analytics panel shows. */\nexport interface PanelBlockConfig {\n title: string\n description?: string\n source: DataSourceRef\n chart: ChartSpec\n}\n\ninterface BlockBase {\n id: string\n layout: BlockLayout\n}\n\nexport type PageBlock =\n | (BlockBase & { kind: 'chart'; config: PanelBlockConfig })\n | (BlockBase & { kind: 'metric'; config: PanelBlockConfig })\n | (BlockBase & { kind: 'text'; config: { text: string } })\n /** A saved table view, nothing else: its columns, filters and sort are the view's. */\n | (BlockBase & { kind: 'table'; config: { view: string } })\n /** One document (a PDF, a Word file, an image, a generated report), read-only. */\n | (BlockBase & { kind: 'document'; config: { document: string } })\n /** Documents shown one at a time, in this order, with previous / next and thumbnails. */\n | (BlockBase & { kind: 'gallery'; config: { documents: string[] } })\n\n/** A page: a titled grid of blocks. Plain JSON (`version` for later migrations). */\nexport interface PageSpec {\n version: 1\n title: string\n description?: string\n blocks: PageBlock[]\n}\n\n/** A page as read. */\nexport interface SavedPage {\n id: string\n /** `null`: a dashboard from before pages, not yet saved into a workspace. */\n workspaceId: string | null\n shared: boolean\n spec: PageSpec\n /** The views its table blocks show (the server's record). */\n viewIds: string[]\n /** The documents its document and gallery blocks show (the server's record). */\n documentIds: string[]\n createdBy: string | null\n updatedAt: string\n /** A dashboard from before pages (sealed to the user): saving it places it in this workspace. */\n legacy: boolean\n /** It could not be opened (sealed under another key, or damaged): it can only be deleted. */\n unreadable: boolean\n}\n\n/** A new block's height in rows, by kind. */\nexport const DEFAULT_BLOCK_HEIGHT: Record<PageBlockKind, number> = {\n metric: 2,\n text: 2,\n chart: 4,\n table: 6,\n document: 8,\n gallery: 8,\n}\n\nconst isObject = (v: unknown): v is Record<string, unknown> =>\n typeof v === 'object' && v !== null && !Array.isArray(v)\n\nconst clamp = (n: unknown, lo: number, hi: number, fallback: number) =>\n typeof n === 'number' && Number.isFinite(n) ? Math.min(hi, Math.max(lo, Math.round(n))) : fallback\n\n/**\n * Place blocks in order, left to right in rows: a block goes beside the last one when it fits in\n * the 12 columns, else below everything placed so far. Each keeps its size.\n */\nexport function packBlocks<B extends { layout: BlockLayout }>(blocks: readonly B[]): B[] {\n let x = 0\n let rowTop = 0\n let bottom = 0\n return blocks.map((b) => {\n const w = clamp(b.layout.w, 1, PAGE_GRID_COLUMNS, PAGE_GRID_COLUMNS)\n const h = clamp(b.layout.h, 1, 100, 4)\n if (x + w > PAGE_GRID_COLUMNS) {\n x = 0\n rowTop = bottom\n }\n const layout = { x, y: rowTop, w, h }\n x += w\n bottom = Math.max(bottom, rowTop + h)\n return { ...b, layout }\n })\n}\n\n/** A chart or metric block of an Analytics panel. */\nexport function blockOfPanel(panel: PanelSpec, h?: number): PageBlock {\n const kind = panel.chart.type === 'metric' ? 'metric' : 'chart'\n return {\n id: panel.id,\n kind,\n layout: { x: 0, y: 0, w: panel.width ?? PAGE_GRID_COLUMNS, h: h ?? DEFAULT_BLOCK_HEIGHT[kind] },\n config: {\n title: panel.title,\n ...(panel.description ? { description: panel.description } : {}),\n source: panel.source,\n chart: panel.chart,\n },\n }\n}\n\n/** The Analytics panel a chart or metric block draws. */\nexport function panelOfBlock(block: Extract<PageBlock, { kind: 'chart' | 'metric' }>): PanelSpec {\n return {\n id: block.id,\n title: block.config.title,\n ...(block.config.description ? { description: block.config.description } : {}),\n source: block.config.source,\n chart: block.config.chart,\n width: block.layout.w,\n }\n}\n\n/** A dashboard (a template, or one saved before pages) as a page: its panels as blocks, in order. */\nexport function pageFromDashboard(dashboard: DashboardSpec): PageSpec {\n return {\n version: 1,\n title: dashboard.title,\n ...(dashboard.description ? { description: dashboard.description } : {}),\n blocks: packBlocks(dashboard.panels.map((p) => blockOfPanel(p))),\n }\n}\n\nfunction isPanelConfig(v: unknown): v is PanelBlockConfig {\n return (\n isObject(v) &&\n typeof v.title === 'string' &&\n isObject(v.source) &&\n typeof v.source.id === 'string' &&\n isObject(v.chart) &&\n typeof v.chart.type === 'string'\n )\n}\n\nfunction blockOf(v: unknown): PageBlock | null {\n if (!isObject(v) || typeof v.id !== 'string' || !isObject(v.config)) return null\n const l = isObject(v.layout) ? v.layout : {}\n const layout = {\n x: clamp(l.x, 0, PAGE_GRID_COLUMNS - 1, 0),\n y: clamp(l.y, 0, 10_000, 0),\n w: clamp(l.w, 1, PAGE_GRID_COLUMNS, PAGE_GRID_COLUMNS),\n h: clamp(l.h, 1, 100, 4),\n }\n const config = v.config\n switch (v.kind) {\n case 'chart':\n case 'metric':\n return isPanelConfig(config) ? { id: v.id, kind: v.kind, layout, config } : null\n case 'text':\n return { id: v.id, kind: 'text', layout, config: { text: String(config.text ?? '') } }\n case 'table':\n return typeof config.view === 'string'\n ? { id: v.id, kind: 'table', layout, config: { view: config.view } }\n : null\n case 'document':\n return typeof config.document === 'string'\n ? { id: v.id, kind: 'document', layout, config: { document: config.document } }\n : null\n case 'gallery': {\n const documents = Array.isArray(config.documents)\n ? config.documents.filter((d): d is string => typeof d === 'string')\n : []\n return documents.length ? { id: v.id, kind: 'gallery', layout, config: { documents } } : null\n }\n default:\n return null\n }\n}\n\n/** A stored spec, checked: `null` when it is not a page (malformed blocks are dropped). */\nexport function parsePageSpec(value: unknown): PageSpec | null {\n if (!isObject(value) || value.version !== 1 || typeof value.title !== 'string') return null\n return {\n version: 1,\n title: value.title,\n ...(typeof value.description === 'string' && value.description\n ? { description: value.description }\n : {}),\n blocks: (Array.isArray(value.blocks) ? value.blocks : [])\n .map(blockOf)\n .filter((b): b is PageBlock => b !== null),\n }\n}\n\n/** A dashboard spec saved before pages (its JSON), checked. */\nfunction parseDashboardJson(json: string | null): DashboardSpec | null {\n if (json === null) return null\n let parsed: unknown\n try {\n parsed = JSON.parse(json)\n } catch {\n return null\n }\n if (!isObject(parsed) || typeof parsed.title !== 'string') return null\n const panels = (Array.isArray(parsed.panels) ? parsed.panels : []).filter(\n (p): p is PanelSpec =>\n isObject(p) &&\n typeof p.id === 'string' &&\n typeof p.title === 'string' &&\n isPanelConfig({ ...p, title: p.title })\n )\n return {\n version: 1,\n title: parsed.title,\n ...(typeof parsed.description === 'string' ? { description: parsed.description } : {}),\n panels,\n }\n}\n\nconst EMPTY: PageSpec = { version: 1, title: '', blocks: [] }\n\n/** A page as the hooks give it. */\nexport function savedPageOf(page: Page): SavedPage {\n const legacy = page.workspaceId === null\n const dashboard = legacy ? parseDashboardJson(page.legacyJson) : null\n const spec = legacy\n ? dashboard && pageFromDashboard(dashboard)\n : parsePageSpec(page.spec as unknown)\n return {\n id: page.id,\n workspaceId: page.workspaceId,\n shared: page.shared,\n spec: spec ?? EMPTY,\n viewIds: page.viewIds,\n documentIds: page.documentIds,\n createdBy: page.createdBy,\n updatedAt: page.updatedAt,\n legacy,\n unreadable: page.unreadable || spec === null,\n }\n}\n\n/** The open workspace's id, or '' with none open. */\nfunction openWorkspaceId(arbi: ReturnType<typeof useArbi>): string {\n return arbi.hasWorkspace ? arbi.getWorkspaceId() : ''\n}\n\n/** The open workspace's pages the user can see (shared ones and their own), oldest first. */\nexport function usePages() {\n const arbi = useArbi()\n const workspaceId = openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.pages(workspaceId),\n queryFn: () =>\n arbi.readInWorkspace(workspaceId, async () => (await arbi.pages.list()).map(savedPageOf)),\n enabled: !!workspaceId && arbi.isLoggedIn,\n staleTime: 1000 * 30,\n })\n}\n\nfunction usePageCache() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const key = arbiQueryKeys.pages(openWorkspaceId(arbi))\n return {\n put: (page: SavedPage) =>\n queryClient.setQueryData<SavedPage[]>(key, (old = []) =>\n old.some((p) => p.id === page.id)\n ? old.map((p) => (p.id === page.id ? page : p))\n : [...old, page]\n ),\n drop: (id: string) =>\n queryClient.setQueryData<SavedPage[]>(key, (old = []) => old.filter((p) => p.id !== id)),\n }\n}\n\n/** Save a page: new without `id` (private unless `shared`), else its spec replaced. */\nexport function useSavePage() {\n const arbi = useArbi()\n const cache = usePageCache()\n return useMutation({\n mutationFn: async ({ id, spec, shared }: { id?: string; spec: PageSpec; shared?: boolean }) =>\n savedPageOf(\n id\n ? await arbi.pages.update(id, spec as unknown as PageSpecWire)\n : await arbi.pages.create({ spec: spec as unknown as PageSpecWire, shared })\n ),\n onSuccess: cache.put,\n })\n}\n\n/** Share a page with the workspace. One-way: a shared page stays shared (only an owner deletes it). */\nexport function useSharePage() {\n const arbi = useArbi()\n const cache = usePageCache()\n return useMutation({\n mutationFn: async (id: string) => savedPageOf(await arbi.pages.share(id)),\n onSuccess: cache.put,\n })\n}\n\nexport function useDeletePage() {\n const arbi = useArbi()\n const cache = usePageCache()\n return useMutation({\n mutationFn: (id: string) => arbi.pages.remove(id),\n onSuccess: (_void, id) => cache.drop(id),\n })\n}\n"],
|
|
5
|
-
"mappings": "AAYA,SAAS,aAAa,UAAU,sBAAsB;
|
|
4
|
+
"sourcesContent": ["/**\n * Pages: the open workspace's layouts of live blocks (charts, metrics, text and table views), kept\n * on the server (`arbi.pages`, `/v1/pages`) under the workspace key. A page is its creator's until\n * shared. Sharing is one-way: a shared page is every member's to read and every editor's to edit,\n * and only a workspace owner deletes it. A shared page never shows a private view (the server\n * refuses: `PagePrivateContentError`).\n *\n * A page is a 12-column grid: each block has a place and a size (`layout`). Chart and metric blocks\n * carry an Analytics panel's config (source, chart); a table block carries only the view it shows.\n * Dashboards saved before pages come back as private pages (`legacy`), opened with the user's key;\n * saving one places it in the open workspace.\n */\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport type {\n AgendaBlockConfig,\n CarouselBlockConfig,\n ListBlockConfig,\n Page,\n PageSpecWire,\n StartBlockConfig,\n} from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../query-keys'\nimport type { ChartSpec, DashboardSpec, DataSourceRef, PanelSpec } from './types'\n\n/**\n * The transient view through which a host asks for a chart of a database (\"Chart this\"): set it to\n * `{ id, name, workspaceId }` and open the pages, which start a new page on that database and clear it.\n */\nexport const ANALYTICS_CHART_VIEW = 'analytics.chartDatabase'\n\n/** A database to chart. */\nexport interface AnalyticsChartRequest {\n id: string\n name: string\n /** The database's workspace, so the new blocks read it from anywhere. */\n workspaceId?: string\n}\n\n/** The columns of a page's grid. */\nexport const PAGE_GRID_COLUMNS = 12\n\nexport type PageBlockKind =\n | 'chart'\n | 'metric'\n | 'text'\n | 'table'\n | 'document'\n | 'gallery'\n | 'list'\n | 'carousel'\n | 'agenda'\n | 'start'\n\n/**\n * The live kinds: the workspace home's sections as blocks. They name no item: each viewer sees\n * their own visible items of the block's source, so a shared page of them shows nobody anything new.\n */\nexport const LIVE_BLOCK_KINDS = ['list', 'carousel', 'agenda', 'start'] as const\n\nexport type { AgendaBlockConfig, CarouselBlockConfig, ListBlockConfig, StartBlockConfig }\n\n/** Where a block sits: column `x` (0\u201311) and row `y`, `w` columns wide and `h` rows high. */\nexport interface BlockLayout {\n x: number\n y: number\n w: number\n h: number\n}\n\n/** A chart or metric block: what an Analytics panel shows. */\nexport interface PanelBlockConfig {\n title: string\n description?: string\n source: DataSourceRef\n chart: ChartSpec\n}\n\ninterface BlockBase {\n id: string\n layout: BlockLayout\n}\n\nexport type PageBlock =\n | (BlockBase & { kind: 'chart'; config: PanelBlockConfig })\n | (BlockBase & { kind: 'metric'; config: PanelBlockConfig })\n | (BlockBase & { kind: 'text'; config: { text: string } })\n /** A saved table view, nothing else: its columns, filters and sort are the view's. */\n | (BlockBase & { kind: 'table'; config: { view: string } })\n /** One document (a PDF, a Word file, an image, a generated report), read-only. */\n | (BlockBase & { kind: 'document'; config: { document: string } })\n /** Documents shown one at a time, in this order, with previous / next and thumbnails. */\n | (BlockBase & { kind: 'gallery'; config: { documents: string[] } })\n /** The viewer's latest files, threads or facts, each row opening its item. */\n | (BlockBase & { kind: 'list'; config: ListBlockConfig })\n /** The viewer's skills (each opens its launcher) or workflows (each opens it), as cards. */\n | (BlockBase & { kind: 'carousel'; config: CarouselBlockConfig })\n /** The viewer's next calendar events. */\n | (BlockBase & { kind: 'agenda'; config: AgendaBlockConfig })\n /** The workspace home's Start band: what the viewer can start, and adding files. */\n | (BlockBase & { kind: 'start'; config: StartBlockConfig })\n\n/** One of the live blocks. */\nexport type LiveBlock = Extract<PageBlock, { kind: (typeof LIVE_BLOCK_KINDS)[number] }>\n\n/** A page: a titled grid of blocks. Plain JSON (`version` for later migrations). */\nexport interface PageSpec {\n version: 1\n title: string\n description?: string\n blocks: PageBlock[]\n}\n\n/** A page as read. */\nexport interface SavedPage {\n id: string\n /** `null`: a dashboard from before pages, not yet saved into a workspace. */\n workspaceId: string | null\n shared: boolean\n spec: PageSpec\n /** The views its table blocks show (the server's record). */\n viewIds: string[]\n /** The documents its document and gallery blocks show (the server's record). */\n documentIds: string[]\n createdBy: string | null\n updatedAt: string\n /** A dashboard from before pages (sealed to the user): saving it places it in this workspace. */\n legacy: boolean\n /** It could not be opened (sealed under another key, or damaged): it can only be deleted. */\n unreadable: boolean\n}\n\n/**\n * A new block's height in rows, by kind: whole slots of the page's grid (a slot is 3 rows tall\n * and 3 columns wide): a metric or a text one slot, the rest two.\n */\nexport const DEFAULT_BLOCK_HEIGHT: Record<PageBlockKind, number> = {\n metric: 3,\n text: 3,\n chart: 6,\n table: 6,\n document: 6,\n gallery: 6,\n list: 6,\n carousel: 3,\n agenda: 6,\n start: 3,\n}\n\n/** The bounds of the live blocks' configs (the server's, `src/models/page.py`). */\nexport const LIVE_BLOCK_LIMITS = {\n listRows: { min: 1, max: 25, default: 5 },\n carouselItems: { min: 1, max: 50, default: 12 },\n agendaDays: { min: 1, max: 31, default: 7 },\n agendaEvents: { min: 1, max: 50, default: 8 },\n} as const\n\nconst LIST_SOURCES: ReadonlyArray<ListBlockConfig['source']> = [\n 'documents',\n 'conversations',\n 'facts',\n]\nconst FACTS_GROUPS: ReadonlyArray<NonNullable<ListBlockConfig['facts']>> = [\n 'upcoming_and_newest',\n 'upcoming',\n 'newest',\n]\nconst CAROUSEL_SOURCES: ReadonlyArray<CarouselBlockConfig['source']> = ['skills', 'workflows']\n\nconst oneOf = <T extends string>(options: ReadonlyArray<T>, v: unknown): T | undefined =>\n options.find((o) => o === v)\n\nconst bounded = (v: unknown, b: { min: number; max: number; default: number }) =>\n clamp(v, b.min, b.max, b.default)\n\nconst isObject = (v: unknown): v is Record<string, unknown> =>\n typeof v === 'object' && v !== null && !Array.isArray(v)\n\nconst clamp = (n: unknown, lo: number, hi: number, fallback: number) =>\n typeof n === 'number' && Number.isFinite(n) ? Math.min(hi, Math.max(lo, Math.round(n))) : fallback\n\n/**\n * Place blocks in order, left to right in rows: a block goes beside the last one when it fits in\n * the 12 columns, else below everything placed so far. Each keeps its size.\n */\nexport function packBlocks<B extends { layout: BlockLayout }>(blocks: readonly B[]): B[] {\n let x = 0\n let rowTop = 0\n let bottom = 0\n return blocks.map((b) => {\n const w = clamp(b.layout.w, 1, PAGE_GRID_COLUMNS, PAGE_GRID_COLUMNS)\n const h = clamp(b.layout.h, 1, 100, 4)\n if (x + w > PAGE_GRID_COLUMNS) {\n x = 0\n rowTop = bottom\n }\n const layout = { x, y: rowTop, w, h }\n x += w\n bottom = Math.max(bottom, rowTop + h)\n return { ...b, layout }\n })\n}\n\n/** A chart or metric block of an Analytics panel. */\nexport function blockOfPanel(panel: PanelSpec, h?: number): PageBlock {\n const kind = panel.chart.type === 'metric' ? 'metric' : 'chart'\n return {\n id: panel.id,\n kind,\n layout: { x: 0, y: 0, w: panel.width ?? PAGE_GRID_COLUMNS, h: h ?? DEFAULT_BLOCK_HEIGHT[kind] },\n config: {\n title: panel.title,\n ...(panel.description ? { description: panel.description } : {}),\n source: panel.source,\n chart: panel.chart,\n },\n }\n}\n\n/** The Analytics panel a chart or metric block draws. */\nexport function panelOfBlock(block: Extract<PageBlock, { kind: 'chart' | 'metric' }>): PanelSpec {\n return {\n id: block.id,\n title: block.config.title,\n ...(block.config.description ? { description: block.config.description } : {}),\n source: block.config.source,\n chart: block.config.chart,\n width: block.layout.w,\n }\n}\n\n/** A dashboard (a template, or one saved before pages) as a page: its panels as blocks, in order. */\nexport function pageFromDashboard(dashboard: DashboardSpec): PageSpec {\n return {\n version: 1,\n title: dashboard.title,\n ...(dashboard.description ? { description: dashboard.description } : {}),\n blocks: packBlocks(dashboard.panels.map((p) => blockOfPanel(p))),\n }\n}\n\nfunction isPanelConfig(v: unknown): v is PanelBlockConfig {\n return (\n isObject(v) &&\n typeof v.title === 'string' &&\n isObject(v.source) &&\n typeof v.source.id === 'string' &&\n isObject(v.chart) &&\n typeof v.chart.type === 'string'\n )\n}\n\nfunction blockOf(v: unknown): PageBlock | null {\n if (!isObject(v) || typeof v.id !== 'string') return null\n // An agenda or a Start block may carry no config (the server's defaults); every other kind has one.\n if (!isObject(v.config) && v.kind !== 'agenda' && v.kind !== 'start') return null\n const l = isObject(v.layout) ? v.layout : {}\n const layout = {\n x: clamp(l.x, 0, PAGE_GRID_COLUMNS - 1, 0),\n y: clamp(l.y, 0, 10_000, 0),\n w: clamp(l.w, 1, PAGE_GRID_COLUMNS, PAGE_GRID_COLUMNS),\n h: clamp(l.h, 1, 100, 4),\n }\n const config = isObject(v.config) ? v.config : {}\n switch (v.kind) {\n case 'chart':\n case 'metric':\n return isPanelConfig(config) ? { id: v.id, kind: v.kind, layout, config } : null\n case 'text':\n return { id: v.id, kind: 'text', layout, config: { text: String(config.text ?? '') } }\n case 'table':\n return typeof config.view === 'string'\n ? { id: v.id, kind: 'table', layout, config: { view: config.view } }\n : null\n case 'document':\n return typeof config.document === 'string'\n ? { id: v.id, kind: 'document', layout, config: { document: config.document } }\n : null\n case 'gallery': {\n const documents = Array.isArray(config.documents)\n ? config.documents.filter((d): d is string => typeof d === 'string')\n : []\n return documents.length ? { id: v.id, kind: 'gallery', layout, config: { documents } } : null\n }\n case 'list': {\n const source = oneOf(LIST_SOURCES, config.source)\n if (!source) return null\n const facts = source === 'facts' ? oneOf(FACTS_GROUPS, config.facts) : undefined\n return {\n id: v.id,\n kind: 'list',\n layout,\n config: {\n source,\n limit: bounded(config.limit, LIVE_BLOCK_LIMITS.listRows),\n ...(facts ? { facts } : {}),\n },\n }\n }\n case 'carousel': {\n const source = oneOf(CAROUSEL_SOURCES, config.source)\n return source\n ? {\n id: v.id,\n kind: 'carousel',\n layout,\n config: { source, limit: bounded(config.limit, LIVE_BLOCK_LIMITS.carouselItems) },\n }\n : null\n }\n case 'agenda':\n return {\n id: v.id,\n kind: 'agenda',\n layout,\n config: {\n days: bounded(config.days, LIVE_BLOCK_LIMITS.agendaDays),\n limit: bounded(config.limit, LIVE_BLOCK_LIMITS.agendaEvents),\n },\n }\n case 'start':\n return { id: v.id, kind: 'start', layout, config: {} }\n default:\n return null\n }\n}\n\n/** A stored spec, checked: `null` when it is not a page (malformed blocks are dropped). */\nexport function parsePageSpec(value: unknown): PageSpec | null {\n if (!isObject(value) || value.version !== 1 || typeof value.title !== 'string') return null\n return {\n version: 1,\n title: value.title,\n ...(typeof value.description === 'string' && value.description\n ? { description: value.description }\n : {}),\n blocks: (Array.isArray(value.blocks) ? value.blocks : [])\n .map(blockOf)\n .filter((b): b is PageBlock => b !== null),\n }\n}\n\n/** A dashboard spec saved before pages (its JSON), checked. */\nfunction parseDashboardJson(json: string | null): DashboardSpec | null {\n if (json === null) return null\n let parsed: unknown\n try {\n parsed = JSON.parse(json)\n } catch {\n return null\n }\n if (!isObject(parsed) || typeof parsed.title !== 'string') return null\n const panels = (Array.isArray(parsed.panels) ? parsed.panels : []).filter(\n (p): p is PanelSpec =>\n isObject(p) &&\n typeof p.id === 'string' &&\n typeof p.title === 'string' &&\n isPanelConfig({ ...p, title: p.title })\n )\n return {\n version: 1,\n title: parsed.title,\n ...(typeof parsed.description === 'string' ? { description: parsed.description } : {}),\n panels,\n }\n}\n\nconst EMPTY: PageSpec = { version: 1, title: '', blocks: [] }\n\n/** A page as the hooks give it. */\nexport function savedPageOf(page: Page): SavedPage {\n const legacy = page.workspaceId === null\n const dashboard = legacy ? parseDashboardJson(page.legacyJson) : null\n const spec = legacy\n ? dashboard && pageFromDashboard(dashboard)\n : parsePageSpec(page.spec as unknown)\n return {\n id: page.id,\n workspaceId: page.workspaceId,\n shared: page.shared,\n spec: spec ?? EMPTY,\n viewIds: page.viewIds,\n documentIds: page.documentIds,\n createdBy: page.createdBy,\n updatedAt: page.updatedAt,\n legacy,\n unreadable: page.unreadable || spec === null,\n }\n}\n\n/** The open workspace's id, or '' with none open. */\nfunction openWorkspaceId(arbi: ReturnType<typeof useArbi>): string {\n return arbi.hasWorkspace ? arbi.getWorkspaceId() : ''\n}\n\n/** The open workspace's pages the user can see (shared ones and their own), oldest first. */\nexport function usePages() {\n const arbi = useArbi()\n const workspaceId = openWorkspaceId(arbi)\n return useQuery({\n queryKey: arbiQueryKeys.pages(workspaceId),\n queryFn: () =>\n arbi.readInWorkspace(workspaceId, async () => (await arbi.pages.list()).map(savedPageOf)),\n enabled: !!workspaceId && arbi.isLoggedIn,\n staleTime: 1000 * 30,\n })\n}\n\nfunction usePageCache() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const key = arbiQueryKeys.pages(openWorkspaceId(arbi))\n return {\n put: (page: SavedPage) =>\n queryClient.setQueryData<SavedPage[]>(key, (old = []) =>\n old.some((p) => p.id === page.id)\n ? old.map((p) => (p.id === page.id ? page : p))\n : [...old, page]\n ),\n drop: (id: string) =>\n queryClient.setQueryData<SavedPage[]>(key, (old = []) => old.filter((p) => p.id !== id)),\n }\n}\n\n/** Save a page: new without `id` (private unless `shared`), else its spec replaced. */\nexport function useSavePage() {\n const arbi = useArbi()\n const cache = usePageCache()\n return useMutation({\n mutationFn: async ({ id, spec, shared }: { id?: string; spec: PageSpec; shared?: boolean }) =>\n savedPageOf(\n id\n ? await arbi.pages.update(id, spec as unknown as PageSpecWire)\n : await arbi.pages.create({ spec: spec as unknown as PageSpecWire, shared })\n ),\n onSuccess: cache.put,\n })\n}\n\n/** Share a page with the workspace. One-way: a shared page stays shared (only an owner deletes it). */\nexport function useSharePage() {\n const arbi = useArbi()\n const cache = usePageCache()\n return useMutation({\n mutationFn: async (id: string) => savedPageOf(await arbi.pages.share(id)),\n onSuccess: cache.put,\n })\n}\n\nexport function useDeletePage() {\n const arbi = useArbi()\n const cache = usePageCache()\n return useMutation({\n mutationFn: (id: string) => arbi.pages.remove(id),\n onSuccess: (_void, id) => cache.drop(id),\n })\n}\n"],
|
|
5
|
+
"mappings": "AAYA,SAAS,aAAa,UAAU,sBAAsB;AAStD,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAOvB,MAAM,uBAAuB;AAW7B,MAAM,oBAAoB;AAkB1B,MAAM,mBAAmB,CAAC,QAAQ,YAAY,UAAU,OAAO;AA8E/D,MAAM,uBAAsD;AAAA,EACjE,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA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,YAAY;AAAA,IACjB,YAAY,OAAO,EAAE,IAAI,MAAM,OAAO,MACpC;AAAA,MACE,KACI,MAAM,KAAK,MAAM,OAAO,IAAI,IAA+B,IAC3D,MAAM,KAAK,MAAM,OAAO,EAAE,MAAuC,OAAO,CAAC;AAAA,IAC/E;AAAA,IACF,WAAW,MAAM;AAAA,EACnB,CAAC;AACH;AAGO,SAAS,eAAe;AAC7B,QAAM,OAAO,QAAQ;AACrB,QAAM,QAAQ,aAAa;AAC3B,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,OAAe,YAAY,MAAM,KAAK,MAAM,MAAM,EAAE,CAAC;AAAA,IACxE,WAAW,MAAM;AAAA,EACnB,CAAC;AACH;AAEO,SAAS,gBAAgB;AAC9B,QAAM,OAAO,QAAQ;AACrB,QAAM,QAAQ,aAAa;AAC3B,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,OAAe,KAAK,MAAM,OAAO,EAAE;AAAA,IAChD,WAAW,CAAC,OAAO,OAAO,MAAM,KAAK,EAAE;AAAA,EACzC,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,8 +3,12 @@ import { useArbi } from "../../useArbi.js";
|
|
|
3
3
|
import { useWorkspaceActivity } from "../../hooks.js";
|
|
4
4
|
import { useArbiSessionState } from "../../session/index.js";
|
|
5
5
|
import { useSwitchWorkspace } from "../../workspaces/switch.js";
|
|
6
|
+
import {
|
|
7
|
+
cellText,
|
|
8
|
+
defineAggregateSource,
|
|
9
|
+
useOpenWorkspace
|
|
10
|
+
} from "../aggregate-source.js";
|
|
6
11
|
import { useNames } from "../members.js";
|
|
7
|
-
import { defineRowsSource, staticFields } from "../rows-source.js";
|
|
8
12
|
import { DEFAULT_WORKFLOWS_SOURCE_LABELS } from "./workflows.js";
|
|
9
13
|
const ENTRIES = 100;
|
|
10
14
|
const DEFAULT_ACTIVITY_SOURCE_LABELS = {
|
|
@@ -40,13 +44,40 @@ function createActivitySource(labels) {
|
|
|
40
44
|
{ id: "item", label: l.item, type: "string" },
|
|
41
45
|
{ id: "status", label: l.status, type: "string" }
|
|
42
46
|
];
|
|
43
|
-
|
|
47
|
+
const byId = new Map(fields.map((f) => [f.id, f]));
|
|
48
|
+
const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
|
|
49
|
+
const areas = new Map(Object.entries(l.areas));
|
|
50
|
+
const kindOf = (kind) => kind ? l.kinds[kind] ?? inWords(kind) : null;
|
|
51
|
+
const statusOf = (status) => status ? l.statuses[status] ?? inWords(status) : null;
|
|
52
|
+
return defineAggregateSource({
|
|
44
53
|
id: "activity",
|
|
45
|
-
|
|
54
|
+
source: "activity",
|
|
46
55
|
label: l.source,
|
|
47
56
|
description: l.description,
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
fields,
|
|
58
|
+
useAggregateFields(enabled) {
|
|
59
|
+
const nameOf = useNames(enabled);
|
|
60
|
+
return useMemo(
|
|
61
|
+
() => [
|
|
62
|
+
{ field: field("when"), from: ["when"] },
|
|
63
|
+
{
|
|
64
|
+
field: field("area"),
|
|
65
|
+
from: ["area"],
|
|
66
|
+
value: ([a]) => {
|
|
67
|
+
const area = cellText(a);
|
|
68
|
+
return area ? areas.get(area) ?? area : null;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{ field: field("kind"), from: ["kind"], value: ([k]) => kindOf(cellText(k)) },
|
|
72
|
+
{ field: field("person"), from: ["person"], value: ([u]) => nameOf(cellText(u)) },
|
|
73
|
+
{ field: field("item"), from: ["item"] },
|
|
74
|
+
{ field: field("status"), from: ["status"], value: ([st]) => statusOf(cellText(st)) }
|
|
75
|
+
],
|
|
76
|
+
[nameOf]
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
useWorkspace: useOpenWorkspace,
|
|
80
|
+
useRecords(_params, enabled) {
|
|
50
81
|
const arbi = useArbi();
|
|
51
82
|
const workspaceId = useArbiSessionState((s) => s.workspaceId) ?? void 0;
|
|
52
83
|
const { settled, openSelectedWorkspace } = useSwitchWorkspace();
|
|
@@ -63,16 +94,20 @@ function createActivitySource(labels) {
|
|
|
63
94
|
() => feed.data?.pages.flatMap(
|
|
64
95
|
(page) => page.items.map((e) => ({
|
|
65
96
|
when: e.created_at,
|
|
66
|
-
area:
|
|
67
|
-
kind:
|
|
97
|
+
area: areas.get(e.source) ?? e.source,
|
|
98
|
+
kind: kindOf(e.kind),
|
|
68
99
|
person: nameOf(e.actor_ext_id),
|
|
69
100
|
item: e.conversation_title || e.document_name || e.workflow_name || null,
|
|
70
|
-
status: e.status
|
|
101
|
+
status: statusOf(e.status ?? null)
|
|
71
102
|
}))
|
|
72
103
|
),
|
|
73
104
|
[feed.data, nameOf]
|
|
74
105
|
);
|
|
75
|
-
return {
|
|
106
|
+
return {
|
|
107
|
+
rows,
|
|
108
|
+
isLoading: enabled && feed.isPending && !!workspaceId,
|
|
109
|
+
error: feed.error
|
|
110
|
+
};
|
|
76
111
|
}
|
|
77
112
|
});
|
|
78
113
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/datasets/sources/activity.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The open workspace's recent activity as a dataset: a row per entry of its activity feed (thread\n * history, people posting, uploads, new versions and signatures, workflow runs), newest first, as\n * far as the feed's first page reaches (up to 100 entries, cached apart from the feed's own pages).\n * Titles and names decrypt only while the session has the workspace open, so it is re-opened\n * before the read, as the activity feed does. Activity by day, by person, or the\n * workflow runs and how they ended, are a group-by away. Reads the shared feed\n * (`useWorkspaceActivity`), so only what the user can see is counted.\n */\nimport { useMemo } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from '../../useArbi'\nimport { useWorkspaceActivity } from '../../hooks'\nimport { useArbiSessionState } from '../../session'\nimport { useSwitchWorkspace } from '../../workspaces/switch'\nimport {
|
|
5
|
-
"mappings": "AASA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,
|
|
4
|
+
"sourcesContent": ["/**\n * The open workspace's recent activity as a dataset: a row per entry of its activity feed (thread\n * history, people posting, uploads, new versions and signatures, workflow runs), newest first, as\n * far as the feed's first page reaches (up to 100 entries, cached apart from the feed's own pages).\n * Titles and names decrypt only while the session has the workspace open, so it is re-opened\n * before the read, as the activity feed does. Activity by day, by person, or the\n * workflow runs and how they ended, are a group-by away. Reads the shared feed\n * (`useWorkspaceActivity`), so only what the user can see is counted.\n */\nimport { useMemo } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from '../../useArbi'\nimport { useWorkspaceActivity } from '../../hooks'\nimport { useArbiSessionState } from '../../session'\nimport { useSwitchWorkspace } from '../../workspaces/switch'\nimport {\n cellText,\n defineAggregateSource,\n useOpenWorkspace,\n type AggregateField,\n} from '../aggregate-source'\nimport { useNames } from '../members'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\nimport { DEFAULT_WORKFLOWS_SOURCE_LABELS } from './workflows'\n\ntype ActivityEntry = components['schemas']['WorkspaceActivityEntry']\ntype ActivityArea = components['schemas']['WorkspaceActivitySource']\n\n/** Entries read: the most the feed gives in one page. */\nconst ENTRIES = 100\n\nexport interface ActivitySourceLabels {\n source: string\n description: string\n when: string\n area: string\n areas: Record<ActivityArea, string>\n kind: string\n /** An entry's kind by the server's name; one not listed is shown in words (`task_done`: \"Task done\"). */\n kinds: Readonly<Record<string, string>>\n person: string\n item: string\n status: string\n /** A workflow run's status by the server's name; one not listed is shown as it comes. */\n statuses: Readonly<Record<string, string>>\n}\n\nexport const DEFAULT_ACTIVITY_SOURCE_LABELS: ActivitySourceLabels = {\n source: 'Recent activity',\n description:\n 'The latest activity of the open workspace: threads, messages, documents and workflow runs.',\n when: 'When',\n area: 'Area',\n areas: { thread: 'Threads', message: 'Messages', document: 'Documents', workflow: 'Workflows' },\n kind: 'What happened',\n kinds: {\n message_posted: 'Message posted',\n document_uploaded: 'Document uploaded',\n document_version: 'New version',\n document_signed: 'Document signed',\n workflow_run: 'Workflow run',\n },\n person: 'Person',\n item: 'Item',\n status: 'Status',\n statuses: DEFAULT_WORKFLOWS_SOURCE_LABELS.results,\n}\n\nconst inWords = (name: string) => {\n const words = name.replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\nexport function createActivitySource(labels?: Partial<ActivitySourceLabels>): DataSource {\n const l = { ...DEFAULT_ACTIVITY_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'when', label: l.when, type: 'date' },\n { id: 'area', label: l.area, type: 'string', options: Object.values(l.areas) },\n { id: 'kind', label: l.kind, type: 'string' },\n { id: 'person', label: l.person, type: 'string' },\n { id: 'item', label: l.item, type: 'string' },\n { id: 'status', label: l.status, type: 'string' },\n ]\n const byId = new Map(fields.map((f) => [f.id, f]))\n const field = (id: string): DatasetField => byId.get(id) ?? { id, label: id, type: 'string' }\n const areas = new Map<string, string>(Object.entries(l.areas))\n const kindOf = (kind: string | null) => (kind ? (l.kinds[kind] ?? inWords(kind)) : null)\n const statusOf = (status: string | null) =>\n status ? (l.statuses[status] ?? inWords(status)) : null\n return defineAggregateSource({\n id: 'activity',\n source: 'activity',\n label: l.source,\n description: l.description,\n fields,\n useAggregateFields(enabled) {\n const nameOf = useNames(enabled)\n return useMemo(\n (): AggregateField[] => [\n { field: field('when'), from: ['when'] },\n {\n field: field('area'),\n from: ['area'],\n value: ([a]) => {\n const area = cellText(a)\n return area ? (areas.get(area) ?? area) : null\n },\n },\n { field: field('kind'), from: ['kind'], value: ([k]) => kindOf(cellText(k)) },\n { field: field('person'), from: ['person'], value: ([u]) => nameOf(cellText(u)) },\n { field: field('item'), from: ['item'] },\n { field: field('status'), from: ['status'], value: ([st]) => statusOf(cellText(st)) },\n ],\n [nameOf]\n )\n },\n useWorkspace: useOpenWorkspace,\n useRecords(_params, enabled) {\n const arbi = useArbi()\n const workspaceId = useArbiSessionState((s) => s.workspaceId) ?? undefined\n const { settled, openSelectedWorkspace } = useSwitchWorkspace()\n const feed = useWorkspaceActivity(workspaceId, {\n enabled: enabled && arbi.isLoggedIn,\n limit: ENTRIES,\n beforeFetch: async () => {\n await settled()\n await openSelectedWorkspace()\n },\n })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n feed.data?.pages.flatMap((page) =>\n (page.items as ActivityEntry[]).map((e): DatasetRow => ({\n when: e.created_at,\n area: areas.get(e.source) ?? e.source,\n kind: kindOf(e.kind),\n person: nameOf(e.actor_ext_id),\n item: e.conversation_title || e.document_name || e.workflow_name || null,\n status: statusOf(e.status ?? null),\n }))\n ),\n [feed.data, nameOf]\n )\n return {\n rows,\n isLoading: enabled && feed.isPending && !!workspaceId,\n error: feed.error,\n }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AASA,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AAEzB,SAAS,uCAAuC;AAMhD,MAAM,UAAU;AAkBT,MAAM,iCAAuD;AAAA,EAClE,QAAQ;AAAA,EACR,aACE;AAAA,EACF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO,EAAE,QAAQ,WAAW,SAAS,YAAY,UAAU,aAAa,UAAU,YAAY;AAAA,EAC9F,MAAM;AAAA,EACN,OAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,IACjB,cAAc;AAAA,EAChB;AAAA,EACA,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU,gCAAgC;AAC5C;AAEA,MAAM,UAAU,CAAC,SAAiB;AAChC,QAAM,QAAQ,KAAK,WAAW,KAAK,GAAG;AACtC,SAAO,MAAM,OAAO,CAAC,EAAE,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AAM,EAAE;AAAA,YACR,MAAM,MAAM,IAAI,EAAE,MAAM,KAAK,EAAE;AAAA,YAC/B,MAAM,OAAO,EAAE,IAAI;AAAA,YACnB,QAAQ,OAAO,EAAE,YAAY;AAAA,YAC7B,MAAM,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,iBAAiB;AAAA,YACpE,QAAQ,SAAS,EAAE,UAAU,IAAI;AAAA,UACnC,EAAE;AAAA,QACJ;AAAA,QACF,CAAC,KAAK,MAAM,MAAM;AAAA,MACpB;AACA,aAAO;AAAA,QACL;AAAA,QACA,WAAW,WAAW,KAAK,aAAa,CAAC,CAAC;AAAA,QAC1C,OAAO,KAAK;AAAA,MACd;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { useArbi } from "../../useArbi.js";
|
|
3
3
|
import { useConversations } from "../../hooks.js";
|
|
4
|
+
import { cellText, defineAggregateSource } from "../aggregate-source.js";
|
|
4
5
|
import { useNames } from "../members.js";
|
|
5
|
-
import { defineRowsSource, staticFields } from "../rows-source.js";
|
|
6
6
|
const DEFAULT_CONVERSATIONS_SOURCE_LABELS = {
|
|
7
7
|
source: "Threads",
|
|
8
8
|
description: "The threads and tasks of the open workspace: activity, status, owners, due dates.",
|
|
@@ -36,15 +36,45 @@ function createConversationsSource(labels) {
|
|
|
36
36
|
{ id: "messages", label: l.messages, type: "number" },
|
|
37
37
|
{ id: "shared", label: l.shared, type: "boolean" }
|
|
38
38
|
];
|
|
39
|
-
|
|
39
|
+
const byId = new Map(fields.map((f) => [f.id, f]));
|
|
40
|
+
const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
|
|
41
|
+
const statusOf = (status) => status === "todo" || status === "generating" || status === "done" ? l.statuses[status] : status;
|
|
42
|
+
function useWorkspaceOf(params) {
|
|
43
|
+
const arbi = useArbi();
|
|
44
|
+
return typeof params.workspaceId === "string" && params.workspaceId ? params.workspaceId : arbi.hasWorkspace ? arbi.getWorkspaceId() : void 0;
|
|
45
|
+
}
|
|
46
|
+
return defineAggregateSource({
|
|
40
47
|
id: "conversations",
|
|
41
|
-
|
|
48
|
+
source: "conversations",
|
|
42
49
|
label: l.source,
|
|
43
50
|
description: l.description,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
51
|
+
fields,
|
|
52
|
+
useAggregateFields(enabled) {
|
|
53
|
+
const nameOf = useNames(enabled);
|
|
54
|
+
return useMemo(
|
|
55
|
+
() => [
|
|
56
|
+
{ field: field("title"), from: ["title"] },
|
|
57
|
+
{ field: field("created"), from: ["created"] },
|
|
58
|
+
{ field: field("lastActivity"), from: ["last_activity"] },
|
|
59
|
+
{ field: field("due"), from: ["due"] },
|
|
60
|
+
{ field: field("completed"), from: ["completed"] },
|
|
61
|
+
{
|
|
62
|
+
field: field("kind"),
|
|
63
|
+
from: ["status"],
|
|
64
|
+
value: ([s]) => cellText(s) ? l.task : l.thread
|
|
65
|
+
},
|
|
66
|
+
{ field: field("status"), from: ["status"], value: ([s]) => statusOf(cellText(s)) },
|
|
67
|
+
{ field: field("overdue"), from: ["overdue"] },
|
|
68
|
+
{ field: field("owner"), from: ["owner"], value: ([u]) => nameOf(cellText(u)) },
|
|
69
|
+
{ field: field("messages"), from: ["messages"] },
|
|
70
|
+
{ field: field("shared"), from: ["shared"] }
|
|
71
|
+
],
|
|
72
|
+
[nameOf]
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
useWorkspace: useWorkspaceOf,
|
|
76
|
+
useRecords(params, enabled) {
|
|
77
|
+
const workspaceId = useWorkspaceOf(params);
|
|
48
78
|
const query = useConversations(workspaceId, { enabled });
|
|
49
79
|
const nameOf = useNames(enabled);
|
|
50
80
|
const rows = useMemo(() => {
|
|
@@ -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 *
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * The conversations of a workspace (threads and tasks) as a dataset (default: the open one;\n * `params.workspaceId` names another): activity over time, work by status, owner and due date.\n * Counted on the server (`defineAggregateSource`); a table of threads (due dates) reads the shared\n * conversation list (`useConversations`).\n */\nimport { useMemo } from 'react'\nimport { useArbi } from '../../useArbi'\nimport { useConversations } from '../../hooks'\nimport { cellText, defineAggregateSource, type AggregateField } from '../aggregate-source'\nimport { useNames } from '../members'\nimport type { DataSource, DataSourceParams, DatasetField, DatasetRow } from '../types'\n\nexport interface ConversationsSourceLabels {\n source: string\n description: string\n title: string\n created: string\n lastActivity: string\n due: string\n completed: string\n kind: string\n /** The `kind` of a conversation without a work status. */\n thread: string\n /** The `kind` of a conversation with a work status. */\n task: string\n status: string\n statuses: { todo: string; generating: string; done: string }\n overdue: string\n owner: string\n messages: string\n shared: string\n}\n\nexport const DEFAULT_CONVERSATIONS_SOURCE_LABELS: ConversationsSourceLabels = {\n source: 'Threads',\n description: 'The threads and tasks of the open workspace: activity, status, owners, due dates.',\n title: 'Title',\n created: 'Started',\n lastActivity: 'Last activity',\n due: 'Due',\n completed: 'Completed',\n kind: 'Kind',\n thread: 'Thread',\n task: 'Task',\n status: 'Status',\n statuses: { todo: 'To do', generating: 'Running', done: 'Done' },\n overdue: 'Overdue',\n owner: 'Owner',\n messages: 'Messages',\n shared: 'Shared',\n}\n\ninterface ConversationLike {\n external_id: string\n title?: string | null\n created_at?: string | null\n updated_at?: string | null\n last_message_updated_at?: string | null\n due_at?: string | null\n completed_at?: string | null\n status?: 'todo' | 'generating' | 'done' | null\n is_shared?: boolean | null\n message_count?: number | null\n owner_ext_id?: string | null\n created_by_ext_id?: string | null\n}\n\nexport function createConversationsSource(labels?: Partial<ConversationsSourceLabels>): DataSource {\n const l = { ...DEFAULT_CONVERSATIONS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'title', label: l.title, type: 'string' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'lastActivity', label: l.lastActivity, type: 'date' },\n { id: 'due', label: l.due, type: 'date' },\n { id: 'completed', label: l.completed, type: 'date' },\n { id: 'kind', label: l.kind, type: 'string', options: [l.thread, l.task] },\n { id: 'status', label: l.status, type: 'string', options: Object.values(l.statuses) },\n { id: 'overdue', label: l.overdue, type: 'boolean' },\n { id: 'owner', label: l.owner, type: 'string' },\n { id: 'messages', label: l.messages, type: 'number' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n ]\n const byId = new Map(fields.map((f) => [f.id, f]))\n const field = (id: string): DatasetField => byId.get(id) ?? { id, label: id, type: 'string' }\n const statusOf = (status: string | null): string | null =>\n status === 'todo' || status === 'generating' || status === 'done' ? l.statuses[status] : status\n function useWorkspaceOf(params: DataSourceParams): string | undefined {\n const arbi = useArbi()\n return typeof params.workspaceId === 'string' && params.workspaceId\n ? params.workspaceId\n : arbi.hasWorkspace\n ? arbi.getWorkspaceId()\n : undefined\n }\n return defineAggregateSource({\n id: 'conversations',\n source: 'conversations',\n label: l.source,\n description: l.description,\n fields,\n useAggregateFields(enabled) {\n const nameOf = useNames(enabled)\n return useMemo(\n (): AggregateField[] => [\n { field: field('title'), from: ['title'] },\n { field: field('created'), from: ['created'] },\n { field: field('lastActivity'), from: ['last_activity'] },\n { field: field('due'), from: ['due'] },\n { field: field('completed'), from: ['completed'] },\n {\n field: field('kind'),\n from: ['status'],\n value: ([s]) => (cellText(s) ? l.task : l.thread),\n },\n { field: field('status'), from: ['status'], value: ([s]) => statusOf(cellText(s)) },\n { field: field('overdue'), from: ['overdue'] },\n { field: field('owner'), from: ['owner'], value: ([u]) => nameOf(cellText(u)) },\n { field: field('messages'), from: ['messages'] },\n { field: field('shared'), from: ['shared'] },\n ],\n [nameOf]\n )\n },\n useWorkspace: useWorkspaceOf,\n useRecords(params: DataSourceParams, enabled) {\n const workspaceId = useWorkspaceOf(params)\n const query = useConversations(workspaceId, { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(() => {\n const now = new Date().toISOString()\n return (query.data as ConversationLike[] | undefined)?.map((c): DatasetRow => ({\n title: c.title || null,\n created: c.created_at ?? null,\n lastActivity: c.last_message_updated_at ?? c.updated_at ?? null,\n due: c.due_at ?? null,\n completed: c.completed_at ?? null,\n kind: c.status ? l.task : l.thread,\n status: c.status ? l.statuses[c.status] : null,\n overdue: Boolean(c.due_at && c.status !== 'done' && c.due_at < now),\n owner: nameOf(c.owner_ext_id ?? c.created_by_ext_id),\n messages: c.message_count ?? null,\n shared: c.is_shared ?? null,\n }))\n }, [query.data, nameOf])\n return { rows, isLoading: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,wBAAwB;AACjC,SAAS,UAAU,6BAAkD;AACrE,SAAS,gBAAgB;AAwBlB,MAAM,sCAAiE;AAAA,EAC5E,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS;AAAA,EACT,cAAc;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,OAA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O,QAAQ,MAAM;AACzB,cAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,eAAQ,MAAM,MAAyC,IAAI,CAAC,OAAmB;AAAA,UAC7E,OAAO,EAAE,SAAS;AAAA,UAClB,SAAS,EAAE,cAAc;AAAA,UACzB,cAAc,EAAE,2BAA2B,EAAE,cAAc;AAAA,UAC3D,KAAK,EAAE,UAAU;AAAA,UACjB,WAAW,EAAE,gBAAgB;AAAA,UAC7B,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE;AAAA,UAC5B,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,IAAI;AAAA,UAC1C,SAAS,QAAQ,EAAE,UAAU,EAAE,WAAW,UAAU,EAAE,SAAS,GAAG;AAAA,UAClE,OAAO,OAAO,EAAE,gBAAgB,EAAE,iBAAiB;AAAA,UACnD,UAAU,EAAE,iBAAiB;AAAA,UAC7B,QAAQ,EAAE,aAAa;AAAA,QACzB,EAAE;AAAA,MACJ,GAAG,CAAC,MAAM,MAAM,MAAM,CAAC;AACvB,aAAO,EAAE,MAAM,WAAW,WAAW,MAAM,WAAW,OAAO,MAAM,MAAM;AAAA,IAC3E;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
+
import { useArbi } from "../../useArbi.js";
|
|
2
3
|
import { useDocuments } from "../../documents/documents-data.js";
|
|
3
4
|
import { friendlyFileType } from "../../entities/file-type.js";
|
|
5
|
+
import { cellText, defineAggregateSource } from "../aggregate-source.js";
|
|
4
6
|
import { useNames } from "../members.js";
|
|
5
|
-
import { defineRowsSource, staticFields } from "../rows-source.js";
|
|
6
7
|
const DEFAULT_DOCUMENTS_SOURCE_LABELS = {
|
|
7
8
|
source: "Documents",
|
|
8
9
|
description: "The documents of the open workspace: type, folder, status, dates.",
|
|
@@ -55,13 +56,50 @@ function createDocumentsSource(labels) {
|
|
|
55
56
|
{ id: "size", label: l.size, type: "number", unit: "bytes" },
|
|
56
57
|
{ id: "shared", label: l.shared, type: "boolean" }
|
|
57
58
|
];
|
|
58
|
-
|
|
59
|
+
const byId = new Map(fields.map((f) => [f.id, f]));
|
|
60
|
+
const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
|
|
61
|
+
const statusOf = (status) => status ? l.statuses[status] ?? status : null;
|
|
62
|
+
return defineAggregateSource({
|
|
59
63
|
id: "documents",
|
|
60
|
-
|
|
64
|
+
source: "documents",
|
|
61
65
|
label: l.source,
|
|
62
66
|
description: l.description,
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
fields,
|
|
68
|
+
useAggregateFields(enabled) {
|
|
69
|
+
const nameOf = useNames(enabled);
|
|
70
|
+
return useMemo(
|
|
71
|
+
() => [
|
|
72
|
+
{ field: field("name"), from: ["name"] },
|
|
73
|
+
{ field: field("created"), from: ["created"] },
|
|
74
|
+
{ field: field("updated"), from: ["updated"] },
|
|
75
|
+
// Encrypted: the server buckets it, but cannot compare it.
|
|
76
|
+
{ field: field("documentDate"), from: ["document_date"], server: false },
|
|
77
|
+
{ field: field("status"), from: ["status"], value: ([s]) => statusOf(cellText(s)) },
|
|
78
|
+
{
|
|
79
|
+
field: field("type"),
|
|
80
|
+
// The name's extension, not the name: what a file type is read from.
|
|
81
|
+
from: ["file_type", "extension", "folder"],
|
|
82
|
+
value: ([type, extension, folder]) => {
|
|
83
|
+
const ext = cellText(extension);
|
|
84
|
+
return friendlyFileType(cellText(type), ext ? `file.${ext}` : null, cellText(folder)) || null;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{ field: field("folder"), from: ["folder"], value: ([f]) => cellText(f) },
|
|
88
|
+
{ field: field("nature"), from: ["nature"] },
|
|
89
|
+
{ field: field("author"), from: ["author"] },
|
|
90
|
+
{ field: field("createdBy"), from: ["created_by"], value: ([u]) => nameOf(cellText(u)) },
|
|
91
|
+
{ field: field("pages"), from: ["pages"] },
|
|
92
|
+
{ field: field("size"), from: ["size"] },
|
|
93
|
+
{ field: field("shared"), from: ["shared"] }
|
|
94
|
+
],
|
|
95
|
+
[nameOf]
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
useWorkspace(params) {
|
|
99
|
+
const arbi = useArbi();
|
|
100
|
+
return workspaceOf(params) ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : void 0);
|
|
101
|
+
},
|
|
102
|
+
useRecords(params, enabled) {
|
|
65
103
|
const query = useDocuments(workspaceOf(params), { enabled });
|
|
66
104
|
const nameOf = useNames(enabled);
|
|
67
105
|
const rows = useMemo(
|
|
@@ -70,7 +108,7 @@ function createDocumentsSource(labels) {
|
|
|
70
108
|
created: d.created_at ?? null,
|
|
71
109
|
updated: d.updated_at ?? null,
|
|
72
110
|
documentDate: d.doc_metadata?.doc_date ?? null,
|
|
73
|
-
status: d.status
|
|
111
|
+
status: statusOf(d.status ?? null),
|
|
74
112
|
type: friendlyFileType(d.file_type, d.file_name, d.folder) || null,
|
|
75
113
|
folder: d.folder || null,
|
|
76
114
|
nature: d.doc_metadata?.doc_nature ?? null,
|
|
@@ -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.
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * The documents of a workspace as a dataset (default: the open one; `params.workspaceId` names\n * another): counts and status by type, folder, author or time. Counted on the server\n * (`defineAggregateSource`), over every document at once; a table of the latest documents reads\n * the shared documents list (`useDocuments`).\n */\nimport { useMemo } from 'react'\nimport { useArbi } from '../../useArbi'\nimport { useDocuments } from '../../documents/documents-data'\nimport { friendlyFileType } from '../../entities/file-type'\nimport { cellText, defineAggregateSource, type AggregateField } from '../aggregate-source'\nimport { useNames } from '../members'\nimport type { DataSource, DataSourceParams, DatasetField, DatasetRow } from '../types'\n\n/** The field labels (a site's words). */\nexport interface DocumentsSourceLabels {\n source: string\n description: string\n created: string\n updated: string\n documentDate: string\n status: string\n /** A processing status by the server's name; one not listed is shown as it comes. */\n statuses: Readonly<Record<string, string>>\n type: string\n folder: string\n nature: string\n author: string\n createdBy: string\n pages: string\n size: string\n shared: string\n}\n\nexport const DEFAULT_DOCUMENTS_SOURCE_LABELS: DocumentsSourceLabels = {\n source: 'Documents',\n description: 'The documents of the open workspace: type, folder, status, dates.',\n created: 'Added',\n updated: 'Updated',\n documentDate: 'Document date',\n status: 'Status',\n statuses: {\n completed: 'Ready',\n 'low-content': 'Little text',\n failed: 'Failed',\n skipped: 'Skipped',\n empty: 'Empty',\n queued: 'Queued',\n uploading: 'Uploading',\n parsing: 'Processing',\n encrypting: 'Processing',\n indexing: 'Processing',\n analysing: 'Processing',\n },\n type: 'Type',\n folder: 'Folder',\n nature: 'Kind of document',\n author: 'Author',\n createdBy: 'Added by',\n pages: 'Pages',\n size: 'Size',\n shared: 'Shared',\n}\n\ninterface DocumentLike {\n external_id: string\n file_name?: string | null\n file_type?: string | null\n file_size?: number | null\n status?: string | null\n folder?: string | null\n n_pages?: number | null\n shared?: boolean | null\n created_by_ext_id?: string | null\n created_at?: string | null\n updated_at?: string | null\n doc_metadata?: {\n doc_nature?: string | null\n doc_author?: string | null\n doc_date?: string | null\n title?: string | null\n } | null\n}\n\nconst workspaceOf = (params: DataSourceParams) =>\n typeof params.workspaceId === 'string' && params.workspaceId ? params.workspaceId : undefined\n\nexport function createDocumentsSource(labels?: Partial<DocumentsSourceLabels>): DataSource {\n const l = { ...DEFAULT_DOCUMENTS_SOURCE_LABELS, ...labels }\n const fields: DatasetField[] = [\n { id: 'name', label: l.source, type: 'string' },\n { id: 'created', label: l.created, type: 'date' },\n { id: 'updated', label: l.updated, type: 'date' },\n { id: 'documentDate', label: l.documentDate, type: 'date' },\n {\n id: 'status',\n label: l.status,\n type: 'string',\n options: [...new Set(Object.values(l.statuses))],\n },\n { id: 'type', label: l.type, type: 'string' },\n { id: 'folder', label: l.folder, type: 'string' },\n { id: 'nature', label: l.nature, type: 'string' },\n { id: 'author', label: l.author, type: 'string' },\n { id: 'createdBy', label: l.createdBy, type: 'string' },\n { id: 'pages', label: l.pages, type: 'number' },\n { id: 'size', label: l.size, type: 'number', unit: 'bytes' },\n { id: 'shared', label: l.shared, type: 'boolean' },\n ]\n const byId = new Map(fields.map((f) => [f.id, f]))\n const field = (id: string): DatasetField => byId.get(id) ?? { id, label: id, type: 'string' }\n const statusOf = (status: string | null) => (status ? (l.statuses[status] ?? status) : null)\n return defineAggregateSource({\n id: 'documents',\n source: 'documents',\n label: l.source,\n description: l.description,\n fields,\n useAggregateFields(enabled) {\n const nameOf = useNames(enabled)\n return useMemo(\n (): AggregateField[] => [\n { field: field('name'), from: ['name'] },\n { field: field('created'), from: ['created'] },\n { field: field('updated'), from: ['updated'] },\n // Encrypted: the server buckets it, but cannot compare it.\n { field: field('documentDate'), from: ['document_date'], server: false },\n { field: field('status'), from: ['status'], value: ([s]) => statusOf(cellText(s)) },\n {\n field: field('type'),\n // The name's extension, not the name: what a file type is read from.\n from: ['file_type', 'extension', 'folder'],\n value: ([type, extension, folder]) => {\n const ext = cellText(extension)\n return (\n friendlyFileType(cellText(type), ext ? `file.${ext}` : null, cellText(folder)) ||\n null\n )\n },\n },\n { field: field('folder'), from: ['folder'], value: ([f]) => cellText(f) },\n { field: field('nature'), from: ['nature'] },\n { field: field('author'), from: ['author'] },\n { field: field('createdBy'), from: ['created_by'], value: ([u]) => nameOf(cellText(u)) },\n { field: field('pages'), from: ['pages'] },\n { field: field('size'), from: ['size'] },\n { field: field('shared'), from: ['shared'] },\n ],\n [nameOf]\n )\n },\n useWorkspace(params) {\n const arbi = useArbi()\n return workspaceOf(params) ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : undefined)\n },\n useRecords(params, enabled) {\n const query = useDocuments(workspaceOf(params), { enabled })\n const nameOf = useNames(enabled)\n const rows = useMemo(\n () =>\n (query.data as DocumentLike[] | undefined)?.map((d): DatasetRow => ({\n name: d.doc_metadata?.title || d.file_name || d.external_id,\n created: d.created_at ?? null,\n updated: d.updated_at ?? null,\n documentDate: d.doc_metadata?.doc_date ?? null,\n status: statusOf(d.status ?? null),\n type: friendlyFileType(d.file_type, d.file_name, d.folder) || null,\n folder: d.folder || null,\n nature: d.doc_metadata?.doc_nature ?? null,\n author: d.doc_metadata?.doc_author ?? null,\n createdBy: nameOf(d.created_by_ext_id),\n pages: d.n_pages ?? null,\n size: d.file_size ?? null,\n shared: d.shared ?? null,\n })),\n [query.data, nameOf]\n )\n return { rows, isLoading: enabled && query.isPending, error: query.error }\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC,SAAS,UAAU,6BAAkD;AACrE,SAAS,gBAAgB;AAuBlB,MAAM,kCAAyD;AAAA,EACpE,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS;AAAA,EACT,SAAS;AAAA,EACT,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,UAAU;AAAA,IACR,WAAW;AAAA,IACX,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,WAAW;AAAA,EACb;AAAA,EACA,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AACV;AAsBA,MAAM,cAAc,CAAC,WACnB,OAAO,OAAO,gBAAgB,YAAY,OAAO,cAAc,OAAO,cAAc;AAE/E,SAAS,sBAAsB,QAAqD;AACzF,QAAM,IAAI,EAAE,G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AM,WAAW,OAAO,MAAM,MAAM;AAAA,IAC3E;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { useFacts } from "../../facts.js";
|
|
3
|
+
import {
|
|
4
|
+
cellText,
|
|
5
|
+
defineAggregateSource,
|
|
6
|
+
useOpenWorkspace
|
|
7
|
+
} from "../aggregate-source.js";
|
|
3
8
|
import { useNames } from "../members.js";
|
|
4
|
-
import { defineRowsSource, staticFields } from "../rows-source.js";
|
|
5
9
|
const DEFAULT_FACTS_SOURCE_LABELS = {
|
|
6
10
|
source: "Facts",
|
|
7
11
|
description: "The facts of the open workspace: their tags, dates, and whether they are confirmed.",
|
|
@@ -24,13 +28,35 @@ function createFactsSource(labels) {
|
|
|
24
28
|
{ id: "created", label: l.created, type: "date" },
|
|
25
29
|
{ id: "createdBy", label: l.createdBy, type: "string" }
|
|
26
30
|
];
|
|
27
|
-
|
|
31
|
+
const byId = new Map(fields.map((f) => [f.id, f]));
|
|
32
|
+
const field = (id) => byId.get(id) ?? { id, label: id, type: "string" };
|
|
33
|
+
return defineAggregateSource({
|
|
28
34
|
id: "facts",
|
|
29
|
-
|
|
35
|
+
source: "facts",
|
|
30
36
|
label: l.source,
|
|
31
37
|
description: l.description,
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
fields,
|
|
39
|
+
useAggregateFields(enabled) {
|
|
40
|
+
const nameOf = useNames(enabled);
|
|
41
|
+
return useMemo(
|
|
42
|
+
() => [
|
|
43
|
+
{ field: field("text"), from: ["text"] },
|
|
44
|
+
{
|
|
45
|
+
field: field("tags"),
|
|
46
|
+
from: ["tags"],
|
|
47
|
+
value: ([ids], labels2) => Array.isArray(ids) ? ids.map((id) => labels2[id] ?? id) : []
|
|
48
|
+
},
|
|
49
|
+
{ field: field("confirmed"), from: ["confirmed"] },
|
|
50
|
+
{ field: field("shared"), from: ["shared"] },
|
|
51
|
+
{ field: field("date"), from: ["date"] },
|
|
52
|
+
{ field: field("created"), from: ["created"] },
|
|
53
|
+
{ field: field("createdBy"), from: ["created_by"], value: ([u]) => nameOf(cellText(u)) }
|
|
54
|
+
],
|
|
55
|
+
[nameOf]
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
useWorkspace: useOpenWorkspace,
|
|
59
|
+
useRecords(_params, enabled) {
|
|
34
60
|
const query = useFacts(void 0, { enabled });
|
|
35
61
|
const nameOf = useNames(enabled);
|
|
36
62
|
const rows = useMemo(
|
|
@@ -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.
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
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. Counted on the server\n * (`defineAggregateSource`: a fact's tags come as ids, with their names); a table of the latest\n * facts reads the shared fact list (`useFacts`).\n */\nimport { useMemo } from 'react'\nimport type { FactResponse } from '@arbidocs/sdk/browser'\nimport { useFacts } from '../../facts'\nimport {\n cellText,\n defineAggregateSource,\n useOpenWorkspace,\n type AggregateField,\n} from '../aggregate-source'\nimport { useNames } from '../members'\nimport type { DataSource, DatasetField, DatasetRow } from '../types'\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 const byId = new Map(fields.map((f) => [f.id, f]))\n const field = (id: string): DatasetField => byId.get(id) ?? { id, label: id, type: 'string' }\n return defineAggregateSource({\n id: 'facts',\n source: 'facts',\n label: l.source,\n description: l.description,\n fields,\n useAggregateFields(enabled) {\n const nameOf = useNames(enabled)\n return useMemo(\n (): AggregateField[] => [\n { field: field('text'), from: ['text'] },\n {\n field: field('tags'),\n from: ['tags'],\n value: ([ids], labels) => (Array.isArray(ids) ? ids.map((id) => labels[id] ?? id) : []),\n },\n { field: field('confirmed'), from: ['confirmed'] },\n { field: field('shared'), from: ['shared'] },\n { field: field('date'), from: ['date'] },\n { field: field('created'), from: ['created'] },\n { field: field('createdBy'), from: ['created_by'], value: ([u]) => nameOf(cellText(u)) },\n ],\n [nameOf]\n )\n },\n useWorkspace: useOpenWorkspace,\n useRecords(_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": "AAMA,SAAS,eAAe;AAExB,SAAS,gBAAgB;AACzB;AAAA,EACE;A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