@factorialco/f0-react 1.413.0 → 1.413.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,292 +0,0 @@
1
- import { jsx as $ } from "react/jsx-runtime";
2
- import { useRef as w, useCallback as v, useState as j, useEffect as R, useMemo as D } from "react";
3
- import { F as P } from "./F0AnalyticsDashboard-HOK1Grhk.js";
4
- function _(t, e, n) {
5
- const r = w(null), y = w(), i = w(t);
6
- i.current = t;
7
- const l = w(e);
8
- l.current = e;
9
- const b = w(n);
10
- b.current = n;
11
- const u = v(
12
- (h, f) => {
13
- const S = `${b.current}:${JSON.stringify(f)}`;
14
- if (r.current?.key === S)
15
- return r.current.promise.then(
16
- (d) => d.results[h] ?? { error: "No result for item" }
17
- );
18
- r.current?.controller.abort();
19
- const o = new AbortController(), s = i.current, a = l.current, g = {};
20
- for (const [d, m] of Object.entries(f))
21
- Array.isArray(m) && m.length > 0 && (g[d] = m.map(String));
22
- const c = {
23
- fetchSpecs: s.fetchSpecs,
24
- items: s.items,
25
- filters: s.filters,
26
- filterValues: Object.keys(g).length > 0 ? g : void 0
27
- }, F = fetch(`${a.baseUrl}/dashboard/compute`, {
28
- method: "POST",
29
- credentials: "include",
30
- headers: {
31
- "Content-Type": "application/json",
32
- ...a.headers
33
- },
34
- body: JSON.stringify(c),
35
- signal: o.signal
36
- }).then(async (d) => {
37
- if (!d.ok) {
38
- const k = await d.text().catch(() => "");
39
- throw new Error(`Dashboard compute failed: ${d.status} ${k}`);
40
- }
41
- const m = await d.json();
42
- return y.current = m, m;
43
- });
44
- return r.current = { key: S, promise: F, controller: o }, F.then(
45
- (d) => d.results[h] ?? { error: "No result for item" }
46
- );
47
- },
48
- []
49
- ), p = v(
50
- () => y.current?.filterOptions,
51
- []
52
- );
53
- return { fetchItem: u, getFilterOptions: p };
54
- }
55
- function A(t) {
56
- if (t)
57
- switch (t.type) {
58
- case "number":
59
- return (e) => e.toLocaleString();
60
- case "currency": {
61
- const e = t.currency ?? "EUR";
62
- return (n) => {
63
- try {
64
- return n.toLocaleString(void 0, {
65
- style: "currency",
66
- currency: e,
67
- maximumFractionDigits: 0
68
- });
69
- } catch {
70
- return `${n}`;
71
- }
72
- };
73
- }
74
- case "percent":
75
- return (e) => `${e}%`;
76
- case "compact":
77
- return (e) => Math.abs(e) >= 1e6 ? `${(e / 1e6).toFixed(1)}M` : Math.abs(e) >= 1e3 ? `${(e / 1e3).toFixed(1)}k` : `${e}`;
78
- default:
79
- return;
80
- }
81
- }
82
- function I(t) {
83
- const e = A(
84
- "valueFormat" in t ? t.valueFormat : void 0
85
- );
86
- switch (t.type) {
87
- case "bar": {
88
- const { valueFormat: n, ...r } = t;
89
- return { ...r, ...e ? { valueFormatter: e } : {} };
90
- }
91
- case "line": {
92
- const { valueFormat: n, ...r } = t;
93
- return { ...r, ...e ? { valueFormatter: e } : {} };
94
- }
95
- case "funnel": {
96
- const { valueFormat: n, ...r } = t;
97
- return { ...r, ...e ? { valueFormatter: e } : {} };
98
- }
99
- case "radar": {
100
- const { valueFormat: n, ...r } = t;
101
- return { ...r, ...e ? { valueFormatter: e } : {} };
102
- }
103
- case "pie": {
104
- const { valueFormat: n, ...r } = t;
105
- return { ...r, ...e ? { valueFormatter: e } : {} };
106
- }
107
- case "gauge": {
108
- const { valueFormat: n, ...r } = t;
109
- return { ...r, ...e ? { valueFormatter: e } : {} };
110
- }
111
- case "heatmap": {
112
- const { valueFormat: n, ...r } = t;
113
- return { ...r, ...e ? { valueFormatter: e } : {} };
114
- }
115
- }
116
- }
117
- const x = 20;
118
- function C({
119
- config: t,
120
- apiConfig: e,
121
- refreshKey: n = 0,
122
- editMode: r,
123
- onLayoutChange: y
124
- }) {
125
- const { fetchItem: i, getFilterOptions: l } = _(
126
- t,
127
- e,
128
- n
129
- ), [b, u] = j(), p = w(!1);
130
- R(() => {
131
- p.current = !1;
132
- }, [n]), R(() => {
133
- if (p.current) return;
134
- const o = setInterval(() => {
135
- const s = l();
136
- s && (u(s), p.current = !0, clearInterval(o));
137
- }, 100);
138
- return () => clearInterval(o);
139
- }, [l, n]);
140
- const h = D(() => {
141
- const o = t.filters;
142
- if (!o || Object.keys(o).length === 0 || !b) return;
143
- const s = {};
144
- for (const [a, g] of Object.entries(o)) {
145
- const c = b[a] ?? [];
146
- c.length !== 0 && (s[a] = {
147
- type: "in",
148
- label: g.label,
149
- options: {
150
- options: c.map((F) => ({ value: F, label: F }))
151
- }
152
- });
153
- }
154
- if (Object.keys(s).length !== 0)
155
- return s;
156
- }, [t.filters, b]), f = v(
157
- (o) => (s) => {
158
- const a = {};
159
- for (const [g, c] of Object.entries(s))
160
- Array.isArray(c) && c.length > 0 && (a[g] = c);
161
- return i(o, a).then((g) => {
162
- const c = l();
163
- return c && !p.current && (u(c), p.current = !0), g;
164
- });
165
- },
166
- [i, l]
167
- ), S = D(
168
- () => t.items.map((o) => {
169
- switch (o.type) {
170
- case "chart":
171
- return E(o, f(o.id));
172
- case "metric":
173
- return L(o, f(o.id));
174
- case "collection":
175
- return M(o, f(o.id));
176
- }
177
- }),
178
- [t.items, f]
179
- );
180
- return /* @__PURE__ */ $(
181
- P,
182
- {
183
- filters: h,
184
- items: S,
185
- editMode: r,
186
- onLayoutChange: y
187
- },
188
- n
189
- );
190
- }
191
- C.displayName = "F0ChatDashboard";
192
- function E(t, e) {
193
- return {
194
- id: t.id,
195
- title: t.title,
196
- description: O(t.description, t.sourceDescription),
197
- colSpan: t.colSpan,
198
- rowSpan: t.rowSpan,
199
- x: t.x,
200
- y: t.y,
201
- type: "chart",
202
- chart: I(t.chart),
203
- fetchData: (n) => e(n).then((r) => r.chart ?? { categories: [], series: [] })
204
- };
205
- }
206
- function O(t, e) {
207
- return e ? t ? `${t}
208
- ${e}` : e : t;
209
- }
210
- function L(t, e) {
211
- return {
212
- id: t.id,
213
- title: t.title,
214
- description: O(t.description, t.sourceDescription),
215
- colSpan: t.colSpan,
216
- rowSpan: t.rowSpan,
217
- x: t.x,
218
- y: t.y,
219
- type: "metric",
220
- format: t.format,
221
- decimals: t.decimals,
222
- fetchData: (n) => e(n).then((r) => r.metric ?? { value: 0 })
223
- };
224
- }
225
- function M(t, e) {
226
- return {
227
- id: t.id,
228
- title: t.title,
229
- description: O(t.description, t.sourceDescription),
230
- colSpan: t.colSpan ?? 12,
231
- rowSpan: t.rowSpan,
232
- x: t.x,
233
- y: t.y,
234
- type: "collection",
235
- createSource: (n) => {
236
- let r = null;
237
- const y = e(n).then((i) => (r = i.collection?.rows ?? [], r));
238
- return {
239
- dataAdapter: {
240
- paginationType: "pages",
241
- perPage: x,
242
- fetchData: async ({
243
- pagination: i,
244
- search: l
245
- }) => {
246
- let u = r ?? await y;
247
- if (l) {
248
- const o = l.toLowerCase();
249
- u = u.filter(
250
- (s) => Object.values(s).some(
251
- (a) => a != null && String(a).toLowerCase().includes(o)
252
- )
253
- );
254
- }
255
- const p = i?.currentPage ?? 1, h = i?.perPage ?? x, f = (p - 1) * h;
256
- return {
257
- type: "pages",
258
- records: u.slice(f, f + h),
259
- total: u.length,
260
- currentPage: p,
261
- perPage: h,
262
- pagesCount: Math.ceil(u.length / h)
263
- };
264
- }
265
- },
266
- search: {
267
- enabled: !0,
268
- sync: !0
269
- }
270
- };
271
- },
272
- visualizations: [
273
- {
274
- type: "table",
275
- options: {
276
- columns: t.columns.map((n) => ({
277
- label: n.label,
278
- id: n.id,
279
- ...n.width ? { width: n.width } : {},
280
- render: (r) => {
281
- const y = r[n.id];
282
- return y == null ? "-" : String(y);
283
- }
284
- }))
285
- }
286
- }
287
- ]
288
- };
289
- }
290
- export {
291
- C as F
292
- };