@arbidocs/react 0.5.145 → 0.5.147
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/PdfViewerImpl-DC5K3TYK.cjs +22 -0
- package/dist/{PdfViewerImpl-ZVJZ4KNW.cjs.map → PdfViewerImpl-DC5K3TYK.cjs.map} +1 -1
- package/dist/{PdfViewerImpl.d-CqnEzQO7.d.ts → PdfViewerImpl.d-DcM6iPY_.d.ts} +6 -1
- package/dist/annotations/freeze/index.d.ts +1 -1
- package/dist/artifacts/index.cjs +14 -14
- package/dist/calls/livekit/index.cjs +48 -48
- package/dist/chat/conversation-cache.js +5 -0
- package/dist/chat/conversation-cache.js.map +2 -2
- package/dist/chat/useConversation.js +10 -5
- package/dist/chat/useConversation.js.map +2 -2
- package/dist/chat/useConversationActions.js +4 -0
- package/dist/chat/useConversationActions.js.map +2 -2
- package/dist/chat/useConversationSettings.js +4 -10
- package/dist/chat/useConversationSettings.js.map +2 -2
- package/dist/{chunk-FE6ZSNZE.cjs → chunk-5FQB5F2F.cjs} +9 -4
- package/dist/chunk-5FQB5F2F.cjs.map +1 -0
- package/dist/{chunk-4B2GW3AY.cjs → chunk-FK33RWIO.cjs} +3 -3
- package/dist/{chunk-4B2GW3AY.cjs.map → chunk-FK33RWIO.cjs.map} +1 -1
- package/dist/{chunk-2F24LLVZ.cjs → chunk-MHYTO2EX.cjs} +38 -38
- package/dist/{chunk-2F24LLVZ.cjs.map → chunk-MHYTO2EX.cjs.map} +1 -1
- package/dist/{chunk-26SZ3DS4.cjs → chunk-MJIXYLI4.cjs} +66 -66
- package/dist/{chunk-26SZ3DS4.cjs.map → chunk-MJIXYLI4.cjs.map} +1 -1
- package/dist/{chunk-MAOGK7IC.cjs → chunk-PGD4ZWI3.cjs} +3 -3
- package/dist/{chunk-MAOGK7IC.cjs.map → chunk-PGD4ZWI3.cjs.map} +1 -1
- package/dist/{chunk-ZZZYVNFW.cjs → chunk-VBUEDJMK.cjs} +57 -57
- package/dist/{chunk-ZZZYVNFW.cjs.map → chunk-VBUEDJMK.cjs.map} +1 -1
- package/dist/{chunk-ICBT2XGF.cjs → chunk-WGCFGA3L.cjs} +3 -3
- package/dist/chunk-WGCFGA3L.cjs.map +1 -0
- package/dist/{chunk-FDYZA6NO.cjs → chunk-XBY4RLC6.cjs} +4 -4
- package/dist/{chunk-FDYZA6NO.cjs.map → chunk-XBY4RLC6.cjs.map} +1 -1
- package/dist/{chunk-VO7OWQP6.cjs → chunk-ZFTWH6B6.cjs} +44 -44
- package/dist/{chunk-VO7OWQP6.cjs.map → chunk-ZFTWH6B6.cjs.map} +1 -1
- package/dist/databases.js +9 -6
- package/dist/databases.js.map +2 -2
- package/dist/datasets/index.js +25 -21
- package/dist/datasets/index.js.map +2 -2
- package/dist/datasets/pages.js +208 -0
- package/dist/datasets/pages.js.map +7 -0
- package/dist/datasets/registry.js.map +2 -2
- package/dist/datasets/sources/database.js +21 -23
- package/dist/datasets/sources/database.js.map +2 -2
- package/dist/document-tools/core.cjs +98 -98
- package/dist/document-tools/core.d.ts +2 -2
- package/dist/document-tools/index.cjs +100 -100
- package/dist/document-tools/index.d.ts +1 -1
- package/dist/documents/documents-writes.js +45 -14
- package/dist/documents/documents-writes.js.map +2 -2
- package/dist/documents/index.js +8 -0
- package/dist/documents/index.js.map +2 -2
- package/dist/documents/tag-when-processed.js +47 -0
- package/dist/documents/tag-when-processed.js.map +7 -0
- package/dist/host/config.js.map +1 -1
- package/dist/index.cjs +1880 -1583
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +319 -97
- package/dist/index.js +27 -5
- package/dist/index.js.map +2 -2
- package/dist/notifications/notification-types.js +7 -0
- package/dist/notifications/notification-types.js.map +2 -2
- package/dist/notifications/server-notifications.js +66 -10
- package/dist/notifications/server-notifications.js.map +2 -2
- package/dist/{pdf-region-impl-ZG5G2OX2.cjs → pdf-region-impl-J2TVABQU.cjs} +9 -9
- package/dist/{pdf-region-impl-ZG5G2OX2.cjs.map → pdf-region-impl-J2TVABQU.cjs.map} +1 -1
- package/dist/{query-keys.d-d2M4FAq2.d.ts → query-keys.d-pgq-4jyZ.d.ts} +7 -2
- package/dist/query-keys.js +7 -2
- package/dist/query-keys.js.map +2 -2
- package/dist/table-views.js +166 -0
- package/dist/table-views.js.map +7 -0
- package/dist/viewers/PdfViewer.cjs +3 -3
- package/dist/viewers/PdfViewer.d.ts +2 -2
- package/dist/viewers/PdfViewerImpl.js +1 -1
- package/dist/viewers/PdfViewerImpl.js.map +2 -2
- package/dist/viewers/index.cjs +10 -10
- package/dist/viewers/index.d.ts +2 -2
- package/package.json +3 -3
- package/dist/PdfViewerImpl-ZVJZ4KNW.cjs +0 -22
- package/dist/account/table-views.js +0 -16
- package/dist/account/table-views.js.map +0 -7
- package/dist/chunk-FE6ZSNZE.cjs.map +0 -1
- package/dist/chunk-ICBT2XGF.cjs.map +0 -1
- package/dist/datasets/store.js +0 -194
- package/dist/datasets/store.js.map +0 -7
package/dist/datasets/store.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
-
import { useArbiHost } from "../host/config.js";
|
|
4
|
-
import { useArbi } from "../useArbi.js";
|
|
5
|
-
import { arbiQueryKeys } from "../query-keys.js";
|
|
6
|
-
const ANALYTICS_CHART_VIEW = "analytics.chartDatabase";
|
|
7
|
-
const MAX_DASHBOARD_SPEC_CHARS = 1e4;
|
|
8
|
-
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
9
|
-
function isPanel(v) {
|
|
10
|
-
return isObject(v) && typeof v.id === "string" && typeof v.title === "string" && isObject(v.source) && typeof v.source.id === "string" && isObject(v.chart) && typeof v.chart.type === "string";
|
|
11
|
-
}
|
|
12
|
-
function parseDashboardSpec(value) {
|
|
13
|
-
let parsed = value;
|
|
14
|
-
if (typeof value === "string") {
|
|
15
|
-
try {
|
|
16
|
-
parsed = JSON.parse(value);
|
|
17
|
-
} catch {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (!isObject(parsed) || parsed.version !== 1 || typeof parsed.title !== "string") return null;
|
|
22
|
-
const panels = Array.isArray(parsed.panels) ? parsed.panels.filter(isPanel) : [];
|
|
23
|
-
return {
|
|
24
|
-
version: 1,
|
|
25
|
-
title: parsed.title,
|
|
26
|
-
...typeof parsed.description === "string" ? { description: parsed.description } : {},
|
|
27
|
-
panels
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function serializeDashboardSpec(spec, max = MAX_DASHBOARD_SPEC_CHARS) {
|
|
31
|
-
const json = JSON.stringify(spec);
|
|
32
|
-
if (json.length > max) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`This dashboard is too large to save (${json.length.toLocaleString("en-GB")} characters, at most ${max.toLocaleString("en-GB")}). Remove a panel or split it into two dashboards.`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
return json;
|
|
38
|
-
}
|
|
39
|
-
function useUserDashboardStore() {
|
|
40
|
-
const arbi = useArbi();
|
|
41
|
-
const scope = arbi.isLoggedIn ? arbi.user.identity()?.externalId ?? null : null;
|
|
42
|
-
return useMemo(
|
|
43
|
-
() => ({
|
|
44
|
-
scope: scope && `user:${scope}`,
|
|
45
|
-
list: async () => (await arbi.dashboards.list()).map(({ id, json, updatedAt }) => {
|
|
46
|
-
const spec = json === null ? null : parseDashboardSpec(json);
|
|
47
|
-
return spec ? { id, spec, updatedAt } : {
|
|
48
|
-
id,
|
|
49
|
-
spec: { version: 1, title: "", panels: [] },
|
|
50
|
-
updatedAt,
|
|
51
|
-
unreadable: true
|
|
52
|
-
};
|
|
53
|
-
}),
|
|
54
|
-
async save({ id, spec }) {
|
|
55
|
-
const saved = await arbi.dashboards.save({ id, json: serializeDashboardSpec(spec) });
|
|
56
|
-
return { id: saved.id, spec, updatedAt: saved.updatedAt };
|
|
57
|
-
},
|
|
58
|
-
remove: (id) => arbi.dashboards.remove(id)
|
|
59
|
-
}),
|
|
60
|
-
[arbi, scope]
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
function createMemoryDashboardStore(initial = [], scope = "memory") {
|
|
64
|
-
let items = [...initial];
|
|
65
|
-
let next = items.length + 1;
|
|
66
|
-
return {
|
|
67
|
-
scope,
|
|
68
|
-
list: async () => items.map((d) => ({ ...d })),
|
|
69
|
-
save: async ({ id, spec }) => {
|
|
70
|
-
const saved = { id: id ?? `dash-${next++}`, spec, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
71
|
-
items = id ? items.map((d) => d.id === id ? saved : d) : [...items, saved];
|
|
72
|
-
return saved;
|
|
73
|
-
},
|
|
74
|
-
remove: async (id) => {
|
|
75
|
-
items = items.filter((d) => d.id !== id);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
const NAME_COLUMN = "Name";
|
|
80
|
-
const SPEC_COLUMN = "Spec";
|
|
81
|
-
function useDatabaseDashboardStore(options = {}) {
|
|
82
|
-
const arbi = useArbi();
|
|
83
|
-
const queryClient = useQueryClient();
|
|
84
|
-
const name = options.name ?? "Dashboards";
|
|
85
|
-
const workspaceId = arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
|
|
86
|
-
return useMemo(() => {
|
|
87
|
-
async function find() {
|
|
88
|
-
const all = await arbi.databases.list();
|
|
89
|
-
return all.find(
|
|
90
|
-
(d) => d.editable && d.workspace_id === workspaceId && d.name === name && (d.columns ?? []).some((c) => c.name === SPEC_COLUMN)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
function inWorkspace(read) {
|
|
94
|
-
return workspaceId ? arbi.readInWorkspace(workspaceId, read) : read();
|
|
95
|
-
}
|
|
96
|
-
async function ensure() {
|
|
97
|
-
return inWorkspace(ensureHere);
|
|
98
|
-
}
|
|
99
|
-
async function ensureHere() {
|
|
100
|
-
const found = await find();
|
|
101
|
-
if (found) return found;
|
|
102
|
-
const created = await arbi.databases.create({
|
|
103
|
-
name,
|
|
104
|
-
description: "Saved dashboards (written by the Dashboards page).",
|
|
105
|
-
columns: [
|
|
106
|
-
{ name: NAME_COLUMN, type: "text" },
|
|
107
|
-
{ name: SPEC_COLUMN, type: "text" }
|
|
108
|
-
]
|
|
109
|
-
});
|
|
110
|
-
void queryClient.invalidateQueries({
|
|
111
|
-
queryKey: arbiQueryKeys.databaseList(workspaceId ?? void 0)
|
|
112
|
-
});
|
|
113
|
-
return created;
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
scope: workspaceId,
|
|
117
|
-
list: () => inWorkspace(async () => {
|
|
118
|
-
const database = await find();
|
|
119
|
-
if (!database) return [];
|
|
120
|
-
const spec = database.columns?.find((c) => c.name === SPEC_COLUMN)?.id ?? SPEC_COLUMN;
|
|
121
|
-
const page = await arbi.databases.rows(database.id, { limit: 1e3 });
|
|
122
|
-
return page.rows.flatMap((row) => {
|
|
123
|
-
const parsed = parseDashboardSpec(row.values[spec]);
|
|
124
|
-
return parsed ? [{ id: row.id, spec: parsed, updatedAt: row.updated_at }] : [];
|
|
125
|
-
});
|
|
126
|
-
}),
|
|
127
|
-
async save({ id, spec }) {
|
|
128
|
-
const values = { [NAME_COLUMN]: spec.title, [SPEC_COLUMN]: serializeDashboardSpec(spec) };
|
|
129
|
-
const database = await ensure();
|
|
130
|
-
const row = id ? await arbi.databases.updateRow(database.id, id, values) : (await arbi.databases.addRows(database.id, [{ values }]))[0];
|
|
131
|
-
void queryClient.invalidateQueries({
|
|
132
|
-
queryKey: arbiQueryKeys.databaseRows(workspaceId ?? "", database.id)
|
|
133
|
-
});
|
|
134
|
-
return { id: row.id, spec, updatedAt: row.updated_at };
|
|
135
|
-
},
|
|
136
|
-
async remove(id) {
|
|
137
|
-
const database = await find();
|
|
138
|
-
if (!database) return;
|
|
139
|
-
await arbi.databases.deleteRows(database.id, [id]);
|
|
140
|
-
void queryClient.invalidateQueries({
|
|
141
|
-
queryKey: arbiQueryKeys.databaseRows(workspaceId ?? "", database.id)
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}, [arbi, queryClient, name, workspaceId]);
|
|
146
|
-
}
|
|
147
|
-
function useDashboardStore() {
|
|
148
|
-
const { dashboards } = useArbiHost();
|
|
149
|
-
return (dashboards?.useStore ?? useUserDashboardStore)();
|
|
150
|
-
}
|
|
151
|
-
function useSavedDashboards(store) {
|
|
152
|
-
return useQuery({
|
|
153
|
-
queryKey: arbiQueryKeys.dashboards(store.scope ?? ""),
|
|
154
|
-
queryFn: () => store.list(),
|
|
155
|
-
enabled: store.scope !== null
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
function useSaveDashboard(store) {
|
|
159
|
-
const queryClient = useQueryClient();
|
|
160
|
-
const key = arbiQueryKeys.dashboards(store.scope ?? "");
|
|
161
|
-
return useMutation({
|
|
162
|
-
mutationFn: (dashboard) => store.save(dashboard),
|
|
163
|
-
onSuccess: (saved) => {
|
|
164
|
-
queryClient.setQueryData(
|
|
165
|
-
key,
|
|
166
|
-
(old = []) => old.some((d) => d.id === saved.id) ? old.map((d) => d.id === saved.id ? saved : d) : [...old, saved]
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
function useDeleteDashboard(store) {
|
|
172
|
-
const queryClient = useQueryClient();
|
|
173
|
-
const key = arbiQueryKeys.dashboards(store.scope ?? "");
|
|
174
|
-
return useMutation({
|
|
175
|
-
mutationFn: (id) => store.remove(id),
|
|
176
|
-
onSuccess: (_void, id) => {
|
|
177
|
-
queryClient.setQueryData(key, (old = []) => old.filter((d) => d.id !== id));
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
export {
|
|
182
|
-
ANALYTICS_CHART_VIEW,
|
|
183
|
-
MAX_DASHBOARD_SPEC_CHARS,
|
|
184
|
-
createMemoryDashboardStore,
|
|
185
|
-
parseDashboardSpec,
|
|
186
|
-
serializeDashboardSpec,
|
|
187
|
-
useDashboardStore,
|
|
188
|
-
useDatabaseDashboardStore,
|
|
189
|
-
useDeleteDashboard,
|
|
190
|
-
useSaveDashboard,
|
|
191
|
-
useSavedDashboards,
|
|
192
|
-
useUserDashboardStore
|
|
193
|
-
};
|
|
194
|
-
//# sourceMappingURL=store.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/datasets/store.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Saved dashboards: where `DashboardSpec`s are kept, and the hooks that read and write them.\n *\n * Default store: the person's own (`useUserDashboardStore`, `/v1/user/dashboards`), each spec sealed\n * in the browser to their own key, so Analytics is theirs across workspaces. A host keeps them\n * elsewhere with `<ArbiHost config={{ dashboards: { useStore } }}>`, e.g. in a database of the open\n * workspace, shared with its members (`useDatabaseDashboardStore`).\n */\nimport { useMemo } from 'react'\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport { useArbiHost } from '../host/config'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../query-keys'\nimport type { DashboardSpec, PanelSpec } from './types'\n\n/**\n * The transient view through which a host asks Analytics to chart a database (\"Chart this\"): set it to\n * `{ id, name, workspaceId }` and open the page, which makes a dashboard on that database and clears it.\n */\nexport const ANALYTICS_CHART_VIEW = 'analytics.chartDatabase'\n\n/** A database Analytics is asked to chart. */\nexport interface AnalyticsChartRequest {\n id: string\n name: string\n /** The database's workspace, so the new panels read it from anywhere. */\n workspaceId?: string\n}\n\n/** A dashboard as stored. */\nexport interface SavedDashboard {\n id: string\n spec: DashboardSpec\n updatedAt?: string\n /** It could not be opened (sealed under another key, or not a dashboard): it can only be deleted. */\n unreadable?: boolean\n}\n\n/** Where dashboards are kept. */\nexport interface DashboardStore {\n /** What the saved list is cached under (the workspace it belongs to). `null`: not available. */\n scope: string | null\n list: () => Promise<SavedDashboard[]>\n /** Create (no `id`) or replace a dashboard; resolves with it as stored. */\n save: (dashboard: { id?: string; spec: DashboardSpec }) => Promise<SavedDashboard>\n remove: (id: string) => Promise<void>\n}\n\n/** The longest spec a database text cell holds (the server's limit). */\nexport const MAX_DASHBOARD_SPEC_CHARS = 10_000\n\nconst isObject = (v: unknown): v is Record<string, unknown> =>\n typeof v === 'object' && v !== null && !Array.isArray(v)\n\nfunction isPanel(v: unknown): v is PanelSpec {\n return (\n isObject(v) &&\n typeof v.id === 'string' &&\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\n/** A stored spec, checked: `null` when it is not a dashboard (malformed panels are dropped). */\nexport function parseDashboardSpec(value: unknown): DashboardSpec | null {\n let parsed = value\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value)\n } catch {\n return null\n }\n }\n if (!isObject(parsed) || parsed.version !== 1 || typeof parsed.title !== 'string') return null\n const panels = Array.isArray(parsed.panels) ? parsed.panels.filter(isPanel) : []\n return {\n version: 1,\n title: parsed.title,\n ...(typeof parsed.description === 'string' ? { description: parsed.description } : {}),\n panels,\n }\n}\n\n/** A spec as JSON for storage; throws when it is longer than the store holds. */\nexport function serializeDashboardSpec(spec: DashboardSpec, max = MAX_DASHBOARD_SPEC_CHARS) {\n const json = JSON.stringify(spec)\n if (json.length > max) {\n throw new Error(\n `This dashboard is too large to save (${json.length.toLocaleString('en-GB')} characters, at most ${max.toLocaleString('en-GB')}). Remove a panel or split it into two dashboards.`\n )\n }\n return json\n}\n\n/** The person's own dashboards (`arbi.dashboards`: sealed to their key); unavailable signed out. */\nexport function useUserDashboardStore(): DashboardStore {\n const arbi = useArbi()\n const scope = arbi.isLoggedIn ? (arbi.user.identity()?.externalId ?? null) : null\n return useMemo(\n () => ({\n scope: scope && `user:${scope}`,\n list: async () =>\n (await arbi.dashboards.list()).map(({ id, json, updatedAt }) => {\n const spec = json === null ? null : parseDashboardSpec(json)\n return spec\n ? { id, spec, updatedAt }\n : {\n id,\n spec: { version: 1 as const, title: '', panels: [] },\n updatedAt,\n unreadable: true,\n }\n }),\n async save({ id, spec }) {\n const saved = await arbi.dashboards.save({ id, json: serializeDashboardSpec(spec) })\n return { id: saved.id, spec, updatedAt: saved.updatedAt }\n },\n remove: (id) => arbi.dashboards.remove(id),\n }),\n [arbi, scope]\n )\n}\n\n/** A store kept in memory (a demo, a test, a page without a workspace). */\nexport function createMemoryDashboardStore(\n initial: readonly SavedDashboard[] = [],\n scope = 'memory'\n): DashboardStore {\n let items = [...initial]\n let next = items.length + 1\n return {\n scope,\n list: async () => items.map((d) => ({ ...d })),\n save: async ({ id, spec }) => {\n const saved = { id: id ?? `dash-${next++}`, spec, updatedAt: new Date().toISOString() }\n items = id ? items.map((d) => (d.id === id ? saved : d)) : [...items, saved]\n return saved\n },\n remove: async (id) => {\n items = items.filter((d) => d.id !== id)\n },\n }\n}\n\nexport interface DatabaseDashboardStoreOptions {\n /** The database's name. Default \"Dashboards\". */\n name?: string\n}\n\nconst NAME_COLUMN = 'Name'\nconst SPEC_COLUMN = 'Spec'\n\n/** Dashboards kept as rows of a database of the open workspace (made on the first save). */\nexport function useDatabaseDashboardStore(\n options: DatabaseDashboardStoreOptions = {}\n): DashboardStore {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const name = options.name ?? 'Dashboards'\n const workspaceId = arbi.hasWorkspace ? arbi.getWorkspaceId() : null\n return useMemo(() => {\n /** The workspace's own dashboards database, if there is one. */\n async function find() {\n const all = await arbi.databases.list()\n return all.find(\n (d) =>\n d.editable &&\n d.workspace_id === workspaceId &&\n d.name === name &&\n (d.columns ?? []).some((c) => c.name === SPEC_COLUMN)\n )\n }\n /**\n * Run `read` only while this store's workspace is the one open on the server (databases are\n * listed and created there): a switch meanwhile drops it, so nothing is cached, or created,\n * as another workspace's.\n */\n function inWorkspace<T>(read: () => Promise<T>): Promise<T> {\n return workspaceId ? arbi.readInWorkspace(workspaceId, read) : read()\n }\n async function ensure() {\n return inWorkspace(ensureHere)\n }\n async function ensureHere() {\n const found = await find()\n if (found) return found\n const created = await arbi.databases.create({\n name,\n description: 'Saved dashboards (written by the Dashboards page).',\n columns: [\n { name: NAME_COLUMN, type: 'text' },\n { name: SPEC_COLUMN, type: 'text' },\n ],\n })\n void queryClient.invalidateQueries({\n queryKey: arbiQueryKeys.databaseList(workspaceId ?? undefined),\n })\n return created\n }\n return {\n scope: workspaceId,\n list: () =>\n inWorkspace(async () => {\n const database = await find()\n if (!database) return []\n const spec = database.columns?.find((c) => c.name === SPEC_COLUMN)?.id ?? SPEC_COLUMN\n const page = await arbi.databases.rows(database.id, { limit: 1000 })\n return page.rows.flatMap((row) => {\n const parsed = parseDashboardSpec(row.values[spec])\n return parsed ? [{ id: row.id, spec: parsed, updatedAt: row.updated_at }] : []\n })\n }),\n async save({ id, spec }) {\n const values = { [NAME_COLUMN]: spec.title, [SPEC_COLUMN]: serializeDashboardSpec(spec) }\n const database = await ensure()\n const row = id\n ? await arbi.databases.updateRow(database.id, id, values)\n : (await arbi.databases.addRows(database.id, [{ values }]))[0]\n // The database's own rows changed (it shows in Databases like any other).\n void queryClient.invalidateQueries({\n queryKey: arbiQueryKeys.databaseRows(workspaceId ?? '', database.id),\n })\n return { id: row.id, spec, updatedAt: row.updated_at }\n },\n async remove(id) {\n const database = await find()\n if (!database) return\n await arbi.databases.deleteRows(database.id, [id])\n void queryClient.invalidateQueries({\n queryKey: arbiQueryKeys.databaseRows(workspaceId ?? '', database.id),\n })\n },\n }\n }, [arbi, queryClient, name, workspaceId])\n}\n\n/** The store dashboards are kept in here: the host's (`dashboards.useStore`) or a database. */\nexport function useDashboardStore(): DashboardStore {\n const { dashboards } = useArbiHost()\n // The host's configuration is one object for its life: the same hook runs every render.\n return (dashboards?.useStore ?? useUserDashboardStore)()\n}\n\n/** The saved dashboards, oldest first. */\nexport function useSavedDashboards(store: DashboardStore) {\n return useQuery({\n queryKey: arbiQueryKeys.dashboards(store.scope ?? ''),\n queryFn: () => store.list(),\n enabled: store.scope !== null,\n })\n}\n\n/** Save a dashboard (create without `id`); the saved list takes it straight away. */\nexport function useSaveDashboard(store: DashboardStore) {\n const queryClient = useQueryClient()\n const key = arbiQueryKeys.dashboards(store.scope ?? '')\n return useMutation({\n mutationFn: (dashboard: { id?: string; spec: DashboardSpec }) => store.save(dashboard),\n onSuccess: (saved) => {\n queryClient.setQueryData<SavedDashboard[]>(key, (old = []) =>\n old.some((d) => d.id === saved.id)\n ? old.map((d) => (d.id === saved.id ? saved : d))\n : [...old, saved]\n )\n },\n })\n}\n\nexport function useDeleteDashboard(store: DashboardStore) {\n const queryClient = useQueryClient()\n const key = arbiQueryKeys.dashboards(store.scope ?? '')\n return useMutation({\n mutationFn: (id: string) => store.remove(id),\n onSuccess: (_void, id) => {\n queryClient.setQueryData<SavedDashboard[]>(key, (old = []) => old.filter((d) => d.id !== id))\n },\n })\n}\n"],
|
|
5
|
-
"mappings": "AAQA,SAAS,eAAe;AACxB,SAAS,aAAa,UAAU,sBAAsB;AACtD,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAOvB,MAAM,uBAAuB;AA8B7B,MAAM,2BAA2B;AAExC,MAAM,WAAW,CAAC,MAChB,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,MAAM,QAAQ,CAAC;AAEzD,SAAS,QAAQ,GAA4B;AAC3C,SACE,SAAS,CAAC,KACV,OAAO,EAAE,OAAO,YAChB,OAAO,EAAE,UAAU,YACnB,SAAS,EAAE,MAAM,KACjB,OAAO,EAAE,OAAO,OAAO,YACvB,SAAS,EAAE,KAAK,KAChB,OAAO,EAAE,MAAM,SAAS;AAE5B;AAGO,SAAS,mBAAmB,OAAsC;AACvE,MAAI,SAAS;AACb,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI;AACF,eAAS,KAAK,MAAM,KAAK;AAAA,IAC3B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAC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