drizzle-cube 0.2.9 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/client/charts.js +15 -15
  2. package/dist/client/chunks/{chart-activitygridchart-Cz4bEf3V.js → chart-activitygridchart-C1ts13cL.js} +40 -40
  3. package/dist/client/chunks/chart-activitygridchart-C1ts13cL.js.map +1 -0
  4. package/dist/client/chunks/{chart-activitygridchart-config-DVH-sdYZ.js → chart-activitygridchart-config-AVBoHdRn.js} +6 -6
  5. package/dist/client/chunks/{chart-activitygridchart-config-DVH-sdYZ.js.map → chart-activitygridchart-config-AVBoHdRn.js.map} +1 -1
  6. package/dist/client/chunks/{chart-areachart-config-C2iwLEgm.js → chart-areachart-config-0ICuIaRP.js} +2 -2
  7. package/dist/client/chunks/{chart-areachart-config-C2iwLEgm.js.map → chart-areachart-config-0ICuIaRP.js.map} +1 -1
  8. package/dist/client/chunks/{chart-areachart-DLdolSnU.js → chart-areachart-fOi6lwUq.js} +3 -3
  9. package/dist/client/chunks/{chart-areachart-DLdolSnU.js.map → chart-areachart-fOi6lwUq.js.map} +1 -1
  10. package/dist/client/chunks/{chart-barchart-Bdjz8DJp.js → chart-barchart-CJfPZQin.js} +4 -4
  11. package/dist/client/chunks/{chart-barchart-Bdjz8DJp.js.map → chart-barchart-CJfPZQin.js.map} +1 -1
  12. package/dist/client/chunks/{chart-barchart-config-CAsUZfHw.js → chart-barchart-config-DalFHdmP.js} +2 -2
  13. package/dist/client/chunks/{chart-barchart-config-CAsUZfHw.js.map → chart-barchart-config-DalFHdmP.js.map} +1 -1
  14. package/dist/client/chunks/{chart-bubblechart-BlQkmqkI.js → chart-bubblechart-BVk_qFly.js} +2 -2
  15. package/dist/client/chunks/{chart-bubblechart-BlQkmqkI.js.map → chart-bubblechart-BVk_qFly.js.map} +1 -1
  16. package/dist/client/chunks/{chart-bubblechart-config-DRuY0m7S.js → chart-bubblechart-config-WjiDlqnP.js} +2 -2
  17. package/dist/client/chunks/{chart-bubblechart-config-DRuY0m7S.js.map → chart-bubblechart-config-WjiDlqnP.js.map} +1 -1
  18. package/dist/client/chunks/{chart-charttooltip-k8soCd2n.js → chart-charttooltip-5tzcFRt0.js} +2 -2
  19. package/dist/client/chunks/{chart-charttooltip-k8soCd2n.js.map → chart-charttooltip-5tzcFRt0.js.map} +1 -1
  20. package/dist/client/chunks/{chart-datatable-zyVFtRJ_.js → chart-datatable-BW_dWRbb.js} +3 -3
  21. package/dist/client/chunks/{chart-datatable-zyVFtRJ_.js.map → chart-datatable-BW_dWRbb.js.map} +1 -1
  22. package/dist/client/chunks/{chart-datatable-config-C0MoGDgo.js → chart-datatable-config-C7TgMD3u.js} +2 -2
  23. package/dist/client/chunks/{chart-datatable-config-C0MoGDgo.js.map → chart-datatable-config-C7TgMD3u.js.map} +1 -1
  24. package/dist/client/chunks/{chart-kpidelta-CTcuIO9G.js → chart-kpidelta-D_VuZaVL.js} +2 -2
  25. package/dist/client/chunks/{chart-kpidelta-CTcuIO9G.js.map → chart-kpidelta-D_VuZaVL.js.map} +1 -1
  26. package/dist/client/chunks/{chart-kpidelta-config-Bq2Ph_Sp.js → chart-kpidelta-config-DtSDG4Kl.js} +2 -2
  27. package/dist/client/chunks/{chart-kpidelta-config-Bq2Ph_Sp.js.map → chart-kpidelta-config-DtSDG4Kl.js.map} +1 -1
  28. package/dist/client/chunks/{chart-kpinumber-slEXt8C-.js → chart-kpinumber-DeCkVi2e.js} +4 -4
  29. package/dist/client/chunks/{chart-kpinumber-slEXt8C-.js.map → chart-kpinumber-DeCkVi2e.js.map} +1 -1
  30. package/dist/client/chunks/{chart-kpinumber-config-OMNhJXdH.js → chart-kpinumber-config-Da2LFeKM.js} +2 -2
  31. package/dist/client/chunks/{chart-kpinumber-config-OMNhJXdH.js.map → chart-kpinumber-config-Da2LFeKM.js.map} +1 -1
  32. package/dist/client/chunks/{chart-kpitext-giq03TOK.js → chart-kpitext-D8OpA0CY.js} +3 -3
  33. package/dist/client/chunks/{chart-kpitext-giq03TOK.js.map → chart-kpitext-D8OpA0CY.js.map} +1 -1
  34. package/dist/client/chunks/{chart-kpitext-config-BLiwQIVN.js → chart-kpitext-config-DjvigyfE.js} +2 -2
  35. package/dist/client/chunks/{chart-kpitext-config-BLiwQIVN.js.map → chart-kpitext-config-DjvigyfE.js.map} +1 -1
  36. package/dist/client/chunks/{chart-linechart-BfnU6L-D.js → chart-linechart-BdfBVl3m.js} +4 -4
  37. package/dist/client/chunks/{chart-linechart-BfnU6L-D.js.map → chart-linechart-BdfBVl3m.js.map} +1 -1
  38. package/dist/client/chunks/{chart-linechart-config-CVbDAvCB.js → chart-linechart-config-C5tpU_2u.js} +2 -2
  39. package/dist/client/chunks/{chart-linechart-config-CVbDAvCB.js.map → chart-linechart-config-C5tpU_2u.js.map} +1 -1
  40. package/dist/client/chunks/{chart-markdownchart-config-uttA9Th4.js → chart-markdownchart-config-CgOA3YSw.js} +2 -2
  41. package/dist/client/chunks/{chart-markdownchart-config-uttA9Th4.js.map → chart-markdownchart-config-CgOA3YSw.js.map} +1 -1
  42. package/dist/client/chunks/{chart-piechart-CZRDQxeB.js → chart-piechart-CiFJQtC8.js} +3 -3
  43. package/dist/client/chunks/{chart-piechart-CZRDQxeB.js.map → chart-piechart-CiFJQtC8.js.map} +1 -1
  44. package/dist/client/chunks/{chart-piechart-config-J748ISAR.js → chart-piechart-config-CtP_JkGm.js} +2 -2
  45. package/dist/client/chunks/{chart-piechart-config-J748ISAR.js.map → chart-piechart-config-CtP_JkGm.js.map} +1 -1
  46. package/dist/client/chunks/{chart-radarchart-D5yRnY9j.js → chart-radarchart-CJ4kpk5J.js} +3 -3
  47. package/dist/client/chunks/{chart-radarchart-D5yRnY9j.js.map → chart-radarchart-CJ4kpk5J.js.map} +1 -1
  48. package/dist/client/chunks/{chart-radarchart-config-CU_MwXOg.js → chart-radarchart-config-BkD_6Khq.js} +2 -2
  49. package/dist/client/chunks/{chart-radarchart-config-CU_MwXOg.js.map → chart-radarchart-config-BkD_6Khq.js.map} +1 -1
  50. package/dist/client/chunks/{chart-radialbarchart-Djtcn7aH.js → chart-radialbarchart-DLQqN_1Z.js} +3 -3
  51. package/dist/client/chunks/{chart-radialbarchart-Djtcn7aH.js.map → chart-radialbarchart-DLQqN_1Z.js.map} +1 -1
  52. package/dist/client/chunks/{chart-radialbarchart-config-D0eEa2hb.js → chart-radialbarchart-config-CBZDlB2k.js} +2 -2
  53. package/dist/client/chunks/{chart-radialbarchart-config-D0eEa2hb.js.map → chart-radialbarchart-config-CBZDlB2k.js.map} +1 -1
  54. package/dist/client/chunks/{chart-scatterchart-C83KgqYY.js → chart-scatterchart-DeGqPbYm.js} +2 -2
  55. package/dist/client/chunks/{chart-scatterchart-C83KgqYY.js.map → chart-scatterchart-DeGqPbYm.js.map} +1 -1
  56. package/dist/client/chunks/{chart-scatterchart-config-Bh0qBq9F.js → chart-scatterchart-config-DsdmlpHr.js} +2 -2
  57. package/dist/client/chunks/{chart-scatterchart-config-Bh0qBq9F.js.map → chart-scatterchart-config-DsdmlpHr.js.map} +1 -1
  58. package/dist/client/chunks/{chart-treemapchart-BDKnKGTz.js → chart-treemapchart-ClXsAOjr.js} +3 -3
  59. package/dist/client/chunks/{chart-treemapchart-BDKnKGTz.js.map → chart-treemapchart-ClXsAOjr.js.map} +1 -1
  60. package/dist/client/chunks/{chart-treemapchart-config-Bl0wYGhB.js → chart-treemapchart-config-CdF9NvPP.js} +2 -2
  61. package/dist/client/chunks/{chart-treemapchart-config-Bl0wYGhB.js.map → chart-treemapchart-config-CdF9NvPP.js.map} +1 -1
  62. package/dist/client/chunks/{charts-BUq4jszb.js → charts-DY7pF_-4.js} +42 -42
  63. package/dist/client/chunks/{charts-BUq4jszb.js.map → charts-DY7pF_-4.js.map} +1 -1
  64. package/dist/client/chunks/components-DAOVOiM_.js +13429 -0
  65. package/dist/client/chunks/components-DAOVOiM_.js.map +1 -0
  66. package/dist/client/chunks/{index-CSeLP8gq.js → index-DH5abYWH.js} +2 -2
  67. package/dist/client/chunks/{index-CSeLP8gq.js.map → index-DH5abYWH.js.map} +1 -1
  68. package/dist/client/components/AnalysisBuilder/types.d.ts +19 -0
  69. package/dist/client/components/PortletAnalysisModal.d.ts +25 -0
  70. package/dist/client/components.js +3 -3
  71. package/dist/client/hooks.js +2 -2
  72. package/dist/client/icons.js +1 -1
  73. package/dist/client/index.d.ts +1 -0
  74. package/dist/client/index.js +51 -3466
  75. package/dist/client/index.js.map +1 -1
  76. package/dist/client/providers/CubeProvider.d.ts +1 -1
  77. package/dist/client/providers.js +1 -1
  78. package/dist/client/styles.css +1 -1
  79. package/dist/client/types.d.ts +1 -0
  80. package/dist/client-bundle-stats.html +1 -1
  81. package/package.json +1 -1
  82. package/dist/client/chunks/chart-activitygridchart-Cz4bEf3V.js.map +0 -1
  83. package/dist/client/chunks/components-DnhfrXo3.js +0 -9846
  84. package/dist/client/chunks/components-DnhfrXo3.js.map +0 -1
@@ -1,3469 +1,54 @@
1
- import { F as qe, D as Fe, c as bt, C as pt, a as gt } from "./chunks/components-DnhfrXo3.js";
2
- import { b as Gr, A as Qr, f as Jr, d as zr, M as Yr, P as Wr, e as Zr, Q as Hr } from "./chunks/components-DnhfrXo3.js";
3
- import { L as Xr } from "./chunks/chart-chartcontainer-CdwzIKP1.js";
4
- import { i as vt, L as Le, g as yt } from "./chunks/charts-BUq4jszb.js";
5
- import { c as es, f as ts, b as rs, p as ss, a as ns } from "./chunks/charts-BUq4jszb.js";
6
- import { jsxs as n, jsx as e, Fragment as we } from "react/jsx-runtime";
7
- import _e, { memo as ue, useState as J, useRef as ae, useMemo as H, useEffect as U, useCallback as I, forwardRef as Nt, useImperativeHandle as wt } from "react";
8
- import { u as kt } from "./chunks/chart-activitygridchart-Cz4bEf3V.js";
9
- import { n as ls, T as cs, y as is, r as ds, g as os, v as us, B as ms, z as hs, A as fs, x as xs, w as bs } from "./chunks/chart-activitygridchart-Cz4bEf3V.js";
10
- import { useDebounce as Dt, useFilterValues as Tt, useCubeQuery as Ct } from "./hooks.js";
11
- import { b as _, a as ye, c as Ce } from "./chunks/chart-activitygridchart-config-DVH-sdYZ.js";
12
- import { D as gs, g as vs, d as ys, f as Ns, h as ws, r as ks, e as Ds, s as Ts } from "./chunks/chart-activitygridchart-config-DVH-sdYZ.js";
13
- import { ScrollContainerProvider as Ss, useScrollContainer as As } from "./providers.js";
14
- function Ge(t, r) {
15
- if (!r) return null;
16
- for (const s of r.cubes) {
17
- const l = s.measures.find((u) => u.name === t);
18
- if (l)
19
- return { field: l, cubeName: s.name, fieldType: "measure" };
20
- const a = s.dimensions.find((u) => u.name === t);
21
- if (a)
22
- return {
23
- field: a,
24
- cubeName: s.name,
25
- fieldType: a.type === "time" ? "timeDimension" : "dimension"
26
- };
27
- }
28
- return null;
29
- }
30
- function St(t, r) {
31
- const s = Ge(t, r);
32
- return s && (s.field.title || s.field.shortTitle) || t;
33
- }
34
- function Qe(t, r) {
35
- if (!t) return [];
36
- const s = [];
37
- for (const l of t.cubes)
38
- if (r === "metrics")
39
- for (const a of l.measures)
40
- s.push({
41
- name: a.name,
42
- title: a.title || a.shortTitle || a.name,
43
- shortTitle: a.shortTitle || a.title || a.name,
44
- type: a.type,
45
- description: a.description,
46
- cubeName: l.name,
47
- fieldType: "measure"
48
- });
49
- else if (r === "breakdown")
50
- for (const a of l.dimensions) {
51
- const u = a.type === "time";
52
- s.push({
53
- name: a.name,
54
- title: a.title || a.shortTitle || a.name,
55
- shortTitle: a.shortTitle || a.title || a.name,
56
- type: a.type,
57
- description: a.description,
58
- cubeName: l.name,
59
- fieldType: u ? "timeDimension" : "dimension"
60
- });
61
- }
62
- else {
63
- for (const a of l.measures)
64
- s.push({
65
- name: a.name,
66
- title: a.title || a.shortTitle || a.name,
67
- shortTitle: a.shortTitle || a.title || a.name,
68
- type: a.type,
69
- description: a.description,
70
- cubeName: l.name,
71
- fieldType: "measure"
72
- });
73
- for (const a of l.dimensions) {
74
- const u = a.type === "time";
75
- s.push({
76
- name: a.name,
77
- title: a.title || a.shortTitle || a.name,
78
- shortTitle: a.shortTitle || a.title || a.name,
79
- type: a.type,
80
- description: a.description,
81
- cubeName: l.name,
82
- fieldType: u ? "timeDimension" : "dimension"
83
- });
84
- }
85
- }
86
- return s;
87
- }
88
- function At(t, r, s) {
89
- let l = t;
90
- if (s && s !== "all" && (l = l.filter((a) => a.cubeName === s)), r.trim()) {
91
- const a = r.toLowerCase();
92
- l = l.filter(
93
- (u) => u.name.toLowerCase().includes(a) || u.title.toLowerCase().includes(a) || (u.description?.toLowerCase().includes(a) ?? !1)
94
- );
95
- }
96
- return l;
97
- }
98
- function Ft(t) {
99
- const r = /* @__PURE__ */ new Map();
100
- for (const s of t) {
101
- const l = r.get(s.cubeName) || [];
102
- l.push(s), r.set(s.cubeName, l);
103
- }
104
- return r;
105
- }
106
- const Je = "drizzle-cube-recent-fields", It = 10;
107
- function ze() {
108
- try {
109
- const t = localStorage.getItem(Je);
110
- if (t)
111
- return JSON.parse(t);
112
- } catch {
113
- }
114
- return { metrics: [], breakdowns: [] };
115
- }
116
- function Rt(t, r) {
117
- try {
118
- const s = ze(), a = s[r].filter((u) => u !== t);
119
- a.unshift(t), s[r] = a.slice(0, It), localStorage.setItem(Je, JSON.stringify(s));
120
- } catch {
121
- }
122
- }
123
- function $t(t, r, s) {
124
- if (!t || s.length === 0) return [];
125
- const l = Qe(t, r), a = [];
126
- for (const u of s) {
127
- const N = l.find((D) => D.name === u);
128
- N && a.push(N);
129
- }
130
- return a;
131
- }
132
- function Ot(t) {
133
- return t ? t.cubes.map((r) => r.name) : [];
134
- }
135
- function ke(t, r) {
136
- return r && r.cubes.find((l) => l.name === t)?.title || t;
137
- }
138
- const Mt = _("check");
139
- function Et({
140
- field: t,
141
- isSelected: r,
142
- isFocused: s,
143
- onClick: l,
144
- onMouseEnter: a,
145
- ...u
146
- }) {
147
- const N = () => {
148
- if (t.fieldType === "measure") {
149
- const b = ye(t.type);
150
- return b ? /* @__PURE__ */ e(b, { className: "w-4 h-4" }) : null;
151
- } else if (t.fieldType === "timeDimension") {
152
- const b = Ce("time");
153
- return b ? /* @__PURE__ */ e(b, { className: "w-4 h-4" }) : null;
154
- } else {
155
- const b = Ce("dimension");
156
- return b ? /* @__PURE__ */ e(b, { className: "w-4 h-4" }) : null;
157
- }
158
- }, D = () => t.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300" : t.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300" : "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300", i = () => t.fieldType === "measure" ? t.type.charAt(0).toUpperCase() + t.type.slice(1) : t.fieldType === "timeDimension" ? "Time" : "Dim";
159
- return /* @__PURE__ */ n(
160
- "button",
161
- {
162
- onClick: l,
163
- onMouseEnter: a,
164
- className: `w-full text-left px-3 py-2 rounded-lg flex items-center gap-3 transition-colors group ${s ? "bg-dc-primary/10 ring-1 ring-dc-primary" : r ? "bg-dc-success/10" : "hover:bg-dc-surface-hover"}`,
165
- ...u,
166
- children: [
167
- /* @__PURE__ */ e(
168
- "span",
169
- {
170
- className: `shrink-0 w-8 h-8 flex items-center justify-center rounded-md ${t.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400" : t.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-600 dark:text-purple-400" : "bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400"}`,
171
- children: N()
172
- }
173
- ),
174
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
175
- /* @__PURE__ */ e("div", { className: "text-sm font-medium text-dc-text truncate", children: t.title }),
176
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted truncate", children: t.name })
177
- ] }),
178
- /* @__PURE__ */ e(
179
- "span",
180
- {
181
- className: `shrink-0 px-2 py-0.5 rounded text-xs font-medium ${D()}`,
182
- children: i()
183
- }
184
- ),
185
- r && /* @__PURE__ */ e("span", { className: "shrink-0 w-5 h-5 flex items-center justify-center rounded-full bg-dc-success text-white", children: /* @__PURE__ */ e(Mt, { className: "w-3 h-3" }) })
186
- ]
187
- }
188
- );
189
- }
190
- const je = ue(Et);
191
- function Lt({ field: t }) {
192
- if (!t)
193
- return /* @__PURE__ */ e("div", { className: "p-6 text-center text-dc-text-muted", children: /* @__PURE__ */ e("p", { className: "text-sm", children: "Hover over a field to see details" }) });
194
- const r = () => {
195
- if (t.fieldType === "measure") {
196
- const a = ye(t.type);
197
- return a ? /* @__PURE__ */ e(a, { className: "w-6 h-6" }) : null;
198
- } else if (t.fieldType === "timeDimension") {
199
- const a = Ce("time");
200
- return a ? /* @__PURE__ */ e(a, { className: "w-6 h-6" }) : null;
201
- } else {
202
- const a = Ce("dimension");
203
- return a ? /* @__PURE__ */ e(a, { className: "w-6 h-6" }) : null;
204
- }
205
- }, s = () => t.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400" : t.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-600 dark:text-purple-400" : "bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400", l = () => t.fieldType === "measure" ? {
206
- count: "Count",
207
- countDistinct: "Count Distinct",
208
- countDistinctApprox: "Count Distinct (Approx)",
209
- sum: "Sum",
210
- avg: "Average",
211
- min: "Minimum",
212
- max: "Maximum",
213
- runningTotal: "Running Total",
214
- number: "Number"
215
- }[t.type] || t.type : t.fieldType === "timeDimension" ? "Time Dimension" : {
216
- string: "Text",
217
- number: "Number",
218
- boolean: "Boolean",
219
- geo: "Geographic"
220
- }[t.type] || "Dimension";
221
- return /* @__PURE__ */ n("div", { className: "p-4", children: [
222
- /* @__PURE__ */ n("div", { className: "flex items-start gap-3 mb-4", children: [
223
- /* @__PURE__ */ e(
224
- "span",
225
- {
226
- className: `shrink-0 w-12 h-12 flex items-center justify-center rounded-lg ${s()}`,
227
- children: r()
228
- }
229
- ),
230
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
231
- /* @__PURE__ */ e("h3", { className: "text-base font-semibold text-dc-text leading-tight", children: t.title }),
232
- /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-muted mt-0.5 truncate", children: t.name })
233
- ] })
234
- ] }),
235
- t.description && /* @__PURE__ */ e("div", { className: "mb-4", children: /* @__PURE__ */ e("p", { className: "text-sm text-dc-text-secondary leading-relaxed", children: t.description }) }),
236
- /* @__PURE__ */ n("div", { className: "space-y-3 pt-4 border-t border-dc-border", children: [
237
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
238
- /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted", children: "Type" }),
239
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text font-medium", children: l() })
240
- ] }),
241
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
242
- /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted", children: "Cube" }),
243
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text font-medium", children: t.cubeName })
244
- ] }),
245
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
246
- /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted", children: "Category" }),
247
- /* @__PURE__ */ e(
248
- "span",
249
- {
250
- className: `text-xs px-2 py-0.5 rounded font-medium ${t.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300" : t.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300" : "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300"}`,
251
- children: t.fieldType === "measure" ? "Measure" : t.fieldType === "timeDimension" ? "Time Dimension" : "Dimension"
252
- }
253
- )
254
- ] })
255
- ] }),
256
- /* @__PURE__ */ e("div", { className: "mt-6 p-3 bg-dc-surface rounded-lg", children: /* @__PURE__ */ n("p", { className: "text-xs text-dc-text-muted", children: [
257
- "Press ",
258
- /* @__PURE__ */ e("kbd", { className: "px-1 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Enter" }),
259
- " or click to add this field to your query."
260
- ] }) })
261
- ] });
262
- }
263
- const _t = ue(Lt), jt = _("search"), Bt = _("close");
264
- function Ye({
265
- isOpen: t,
266
- onClose: r,
267
- onSelect: s,
268
- mode: l,
269
- schema: a,
270
- selectedFields: u,
271
- recentFields: N
272
- }) {
273
- const [D, i] = J(""), [b, g] = J(null), [T, f] = J(null), [S, y] = J(-1), [G, E] = J(null), P = ae(null), j = ae(null), Q = H(() => {
274
- if (N) return N;
275
- const d = ze();
276
- return l === "metrics" ? d.metrics : d.breakdowns;
277
- }, [N, l]), R = l, x = H(() => Qe(a, R), [a, R]), h = H(() => Ot(a), [a]), o = H(() => At(x, D, b), [x, D, b]), v = H(() => Ft(o), [o]), A = H(() => D.trim() ? [] : $t(a, R, Q).filter(
278
- (d) => !b || d.cubeName === b
279
- ), [a, R, Q, D, b]), O = H(() => {
280
- const d = [...A];
281
- return v.forEach((k) => {
282
- d.push(...k);
283
- }), d;
284
- }, [A, v]);
285
- U(() => {
286
- t && P.current && P.current.focus();
287
- }, [t]), U(() => {
288
- t || (i(""), g(null), f(null), y(-1), E(null));
289
- }, [t]);
290
- const V = I(
291
- (d, k = !1) => {
292
- Rt(d.name, l === "metrics" ? "metrics" : "breakdowns");
293
- const B = {
294
- name: d.name,
295
- title: d.title,
296
- shortTitle: d.shortTitle,
297
- type: d.type,
298
- description: d.description
299
- };
300
- s(B, d.fieldType, d.cubeName, k);
301
- },
302
- [l, s]
303
- ), z = I(
304
- (d, k, B = !1) => {
305
- if (B && G !== null && G !== k) {
306
- const Z = Math.min(G, k), X = Math.max(G, k);
307
- for (let Y = Z; Y <= X; Y++) {
308
- const re = O[Y];
309
- re && !u.includes(re.name) && V(re, !0);
310
- }
311
- } else B ? V(d, !0) : V(d, !1);
312
- E(k);
313
- },
314
- [O, G, V, u]
315
- ), c = I(
316
- (d) => {
317
- if (O.length !== 0)
318
- switch (d.key) {
319
- case "ArrowDown":
320
- d.preventDefault(), y((k) => {
321
- const B = Math.min(k + 1, O.length - 1);
322
- return f(O[B]), B;
323
- });
324
- break;
325
- case "ArrowUp":
326
- d.preventDefault(), y((k) => {
327
- const B = Math.max(k - 1, 0);
328
- return f(O[B]), B;
329
- });
330
- break;
331
- case "Enter":
332
- d.preventDefault(), S >= 0 && O[S] && z(O[S], S, d.shiftKey);
333
- break;
334
- case "Escape":
335
- d.preventDefault(), r();
336
- break;
337
- }
338
- },
339
- [O, S, z, r]
340
- );
341
- if (U(() => {
342
- if (S >= 0 && j.current) {
343
- const d = j.current.querySelector(
344
- `[data-field-index="${S}"]`
345
- );
346
- d && d.scrollIntoView({ block: "nearest", behavior: "smooth" });
347
- }
348
- }, [S]), !t) return null;
349
- const p = l === "metrics" ? "Search metrics..." : l === "filter" ? "Search fields to filter..." : "Search dimensions...", m = l === "metrics" ? "Select a Metric" : l === "filter" ? "Select a Field to Filter" : "Select a Dimension", w = S >= 0 && O[S] ? `field-option-${O[S].name.replace(/\./g, "-")}` : void 0;
350
- return /* @__PURE__ */ e(
351
- "div",
352
- {
353
- className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50",
354
- onClick: r,
355
- role: "presentation",
356
- children: /* @__PURE__ */ n(
357
- "div",
358
- {
359
- role: "dialog",
360
- "aria-modal": "true",
361
- "aria-label": m,
362
- className: "bg-dc-surface shadow-xl w-full h-full md:rounded-lg md:w-auto md:max-w-5xl md:h-[80vh] md:max-h-[700px] flex flex-col overflow-hidden",
363
- onClick: (d) => d.stopPropagation(),
364
- onKeyDown: c,
365
- children: [
366
- /* @__PURE__ */ n("div", { className: "shrink-0 border-b border-dc-border", children: [
367
- /* @__PURE__ */ n("div", { className: "flex items-center px-4 py-3 gap-3", children: [
368
- /* @__PURE__ */ e(jt, { className: "w-5 h-5 text-dc-text-muted", "aria-hidden": !0 }),
369
- /* @__PURE__ */ e(
370
- "input",
371
- {
372
- ref: P,
373
- type: "text",
374
- value: D,
375
- onChange: (d) => {
376
- i(d.target.value), y(-1);
377
- },
378
- placeholder: p,
379
- className: "flex-1 bg-transparent border-none outline-none text-dc-text placeholder-dc-text-muted text-lg",
380
- "aria-label": p,
381
- "aria-controls": "field-search-results",
382
- "aria-activedescendant": w,
383
- role: "combobox",
384
- "aria-expanded": "true",
385
- "aria-autocomplete": "list"
386
- }
387
- ),
388
- /* @__PURE__ */ e(
389
- "button",
390
- {
391
- onClick: r,
392
- className: "p-1 text-dc-text-secondary hover:text-dc-text rounded",
393
- "aria-label": "Close dialog",
394
- children: /* @__PURE__ */ e(Bt, { className: "w-5 h-5", "aria-hidden": !0 })
395
- }
396
- )
397
- ] }),
398
- h.length > 1 && /* @__PURE__ */ e("div", { className: "md:hidden px-4 pb-3", children: /* @__PURE__ */ n(
399
- "select",
400
- {
401
- value: b || "",
402
- onChange: (d) => g(d.target.value || null),
403
- className: "w-full px-3 py-2 bg-dc-surface border border-dc-border rounded-lg text-sm text-dc-text focus:outline-none focus:ring-1 focus:ring-dc-primary",
404
- "aria-label": "Filter by cube",
405
- children: [
406
- /* @__PURE__ */ e("option", { value: "", children: "All Cubes" }),
407
- h.map((d) => /* @__PURE__ */ e("option", { value: d, children: ke(d, a) }, d))
408
- ]
409
- }
410
- ) })
411
- ] }),
412
- /* @__PURE__ */ n("div", { className: "flex-1 flex overflow-hidden", children: [
413
- /* @__PURE__ */ e(
414
- "nav",
415
- {
416
- className: "hidden md:block w-48 shrink-0 border-r border-dc-border overflow-y-auto bg-dc-surface-secondary",
417
- "aria-label": "Filter by cube",
418
- children: /* @__PURE__ */ n("div", { className: "p-2", role: "group", "aria-label": "Cube categories", children: [
419
- /* @__PURE__ */ e(
420
- "button",
421
- {
422
- onClick: () => g(null),
423
- className: `w-full text-left px-3 py-2 rounded-md text-sm transition-colors ${b === null ? "bg-dc-primary/10 text-dc-primary font-medium" : "text-dc-text hover:bg-dc-surface-hover"}`,
424
- "aria-pressed": b === null,
425
- children: "All"
426
- }
427
- ),
428
- h.map((d) => /* @__PURE__ */ e(
429
- "button",
430
- {
431
- onClick: () => g(d),
432
- className: `w-full text-left px-3 py-2 rounded-md text-sm transition-colors truncate ${b === d ? "bg-dc-primary/10 text-dc-primary font-medium" : "text-dc-text hover:bg-dc-surface-hover"}`,
433
- title: ke(d, a),
434
- "aria-pressed": b === d,
435
- children: ke(d, a)
436
- },
437
- d
438
- ))
439
- ] })
440
- }
441
- ),
442
- /* @__PURE__ */ e(
443
- "div",
444
- {
445
- id: "field-search-results",
446
- ref: j,
447
- className: "flex-1 overflow-y-auto p-4",
448
- role: "listbox",
449
- "aria-label": "Available fields",
450
- children: o.length === 0 && A.length === 0 ? /* @__PURE__ */ n("div", { className: "text-center py-12 text-dc-text-muted", children: [
451
- /* @__PURE__ */ e("p", { className: "text-lg mb-2", children: "No fields found" }),
452
- /* @__PURE__ */ e("p", { className: "text-sm", children: D ? `No ${l === "metrics" ? "metrics" : "dimensions"} match "${D}"` : `No ${l === "metrics" ? "metrics" : "dimensions"} available` })
453
- ] }) : /* @__PURE__ */ n("div", { className: "space-y-6", children: [
454
- A.length > 0 && /* @__PURE__ */ n("div", { children: [
455
- /* @__PURE__ */ e("h3", { className: "text-xs font-semibold text-dc-text-muted uppercase tracking-wider mb-2", children: "Recents" }),
456
- /* @__PURE__ */ e("div", { className: "space-y-1", children: A.map((d, k) => /* @__PURE__ */ e(
457
- je,
458
- {
459
- field: d,
460
- isSelected: u.includes(d.name),
461
- isFocused: S === k,
462
- onClick: (B) => z(d, k, B.shiftKey),
463
- onMouseEnter: () => {
464
- f(d), y(k);
465
- },
466
- "data-field-index": k
467
- },
468
- `recent-${d.name}`
469
- )) })
470
- ] }),
471
- Array.from(v.entries()).map(([d, k]) => /* @__PURE__ */ n("div", { children: [
472
- /* @__PURE__ */ e("h3", { className: "text-xs font-semibold text-dc-text-muted uppercase tracking-wider mb-2", children: ke(d, a) }),
473
- /* @__PURE__ */ e("div", { className: "space-y-1", children: k.map((B) => {
474
- const Z = A.length + Array.from(v.entries()).slice(
475
- 0,
476
- Array.from(v.keys()).indexOf(d)
477
- ).reduce((X, [, Y]) => X + Y.length, 0) + k.indexOf(B);
478
- return /* @__PURE__ */ e(
479
- je,
480
- {
481
- field: B,
482
- isSelected: u.includes(B.name),
483
- isFocused: S === Z,
484
- onClick: (X) => z(B, Z, X.shiftKey),
485
- onMouseEnter: () => {
486
- f(B), y(Z);
487
- },
488
- "data-field-index": Z
489
- },
490
- B.name
491
- );
492
- }) })
493
- ] }, d))
494
- ] })
495
- }
496
- ),
497
- /* @__PURE__ */ e("div", { className: "hidden md:block w-72 shrink-0 border-l border-dc-border bg-dc-surface-secondary overflow-y-auto", children: /* @__PURE__ */ e(_t, { field: T }) })
498
- ] }),
499
- /* @__PURE__ */ n("div", { className: "shrink-0 border-t border-dc-border px-4 py-3 flex items-center justify-between text-sm text-dc-text-muted", children: [
500
- /* @__PURE__ */ n("div", { children: [
501
- /* @__PURE__ */ e("span", { className: "text-dc-text-secondary", children: o.length }),
502
- " ",
503
- l === "metrics" ? "metrics" : l === "filter" ? "fields" : "dimensions",
504
- " available"
505
- ] }),
506
- /* @__PURE__ */ n("div", { className: "hidden md:flex items-center gap-4", children: [
507
- /* @__PURE__ */ n("span", { children: [
508
- /* @__PURE__ */ e("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "↑↓" }),
509
- " Navigate"
510
- ] }),
511
- /* @__PURE__ */ n("span", { children: [
512
- /* @__PURE__ */ e("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Enter" }),
513
- " Select"
514
- ] }),
515
- /* @__PURE__ */ n("span", { children: [
516
- /* @__PURE__ */ e("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Shift" }),
517
- "+Click Multi-select"
518
- ] }),
519
- /* @__PURE__ */ n("span", { children: [
520
- /* @__PURE__ */ e("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Esc" }),
521
- " Close"
522
- ] })
523
- ] })
524
- ] })
525
- ]
526
- }
527
- )
528
- }
529
- );
530
- }
531
- function Pt(t) {
532
- return "member" in t && "operator" in t && "values" in t;
533
- }
534
- function Vt(t) {
535
- return "type" in t && "filters" in t;
536
- }
537
- function qt(t) {
538
- const r = (s) => {
539
- if (Pt(s))
540
- return s;
541
- if (Vt(s)) {
542
- const l = s.filters.map(r);
543
- return s.type === "and" ? { and: l } : { or: l };
544
- }
545
- return s;
546
- };
547
- return t.map(r);
548
- }
549
- function Gt(t) {
550
- const r = {};
551
- return t.measures && t.measures.length > 0 && (r.measures = t.measures), t.dimensions && t.dimensions.length > 0 && (r.dimensions = t.dimensions), t.timeDimensions && t.timeDimensions.length > 0 && (r.timeDimensions = t.timeDimensions), t.filters && t.filters.length > 0 && (r.filters = t.filters), t.order && (r.order = t.order), t.limit && (r.limit = t.limit), t.offset && (r.offset = t.offset), t.segments && t.segments.length > 0 && (r.segments = t.segments), r;
552
- }
553
- function Qt(t) {
554
- const r = Gt(t);
555
- return r.filters && r.filters.length > 0 && (r.filters = qt(r.filters)), r;
556
- }
557
- function Jt(t) {
558
- const r = [];
559
- for (const [s, l] of Object.entries(qe))
560
- l.fieldTypes.includes(t) && r.push({
561
- operator: s,
562
- label: l.label
563
- });
564
- return r;
565
- }
566
- function ve(t, r) {
567
- const s = {
568
- today: "today",
569
- yesterday: "yesterday",
570
- this_week: "this week",
571
- this_month: "this month",
572
- this_quarter: "this quarter",
573
- this_year: "this year",
574
- last_7_days: "last 7 days",
575
- last_30_days: "last 30 days",
576
- last_week: "last week",
577
- last_month: "last month",
578
- last_quarter: "last quarter",
579
- last_year: "last year",
580
- last_12_months: "last 12 months"
581
- };
582
- if (t.startsWith("last_n_") && r !== void 0 && r > 0) {
583
- const l = t.replace("last_n_", ""), a = l.slice(0, -1);
584
- return r === 1 ? `last ${a}` : `last ${r} ${l}`;
585
- }
586
- return s[t] || t;
587
- }
588
- function De(t) {
589
- return t.startsWith("last_n_");
590
- }
591
- function Be(t) {
592
- return t.replace(/_/g, " ");
593
- }
594
- function zt(t) {
595
- switch (t) {
596
- case "most_dimensions":
597
- return "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300";
598
- case "most_connected":
599
- return "bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300";
600
- case "alphabetical_fallback":
601
- return "bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300";
602
- case "single_cube":
603
- return "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300";
604
- default:
605
- return "bg-gray-100 dark:bg-gray-900/30 text-gray-700 dark:text-gray-300";
606
- }
607
- }
608
- const Yt = ({ analysis: t }) => {
609
- const r = _("info"), s = _("chevronRight"), l = _("warning"), a = _("table"), u = _("link"), N = _("success"), D = _("error");
610
- return /* @__PURE__ */ n("div", { className: "bg-dc-surface-secondary border border-dc-border rounded-lg p-4 space-y-4", children: [
611
- /* @__PURE__ */ n("div", { className: "border-b border-dc-border pb-3", children: [
612
- /* @__PURE__ */ n("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
613
- /* @__PURE__ */ e(r, { className: "w-4 h-4 mr-2" }),
614
- "Query Summary"
615
- ] }),
616
- /* @__PURE__ */ n("div", { className: "grid grid-cols-2 md:grid-cols-4 gap-2 text-xs", children: [
617
- /* @__PURE__ */ n("div", { className: "bg-dc-surface p-2 rounded", children: [
618
- /* @__PURE__ */ e("span", { className: "text-dc-text-muted", children: "Type:" }),
619
- /* @__PURE__ */ e("span", { className: "ml-1 font-medium text-dc-text", children: Be(t.querySummary.queryType) })
620
- ] }),
621
- /* @__PURE__ */ n("div", { className: "bg-dc-surface p-2 rounded", children: [
622
- /* @__PURE__ */ e("span", { className: "text-dc-text-muted", children: "Cubes:" }),
623
- /* @__PURE__ */ e("span", { className: "ml-1 font-medium text-dc-text", children: t.cubeCount })
624
- ] }),
625
- /* @__PURE__ */ n("div", { className: "bg-dc-surface p-2 rounded", children: [
626
- /* @__PURE__ */ e("span", { className: "text-dc-text-muted", children: "Joins:" }),
627
- /* @__PURE__ */ e("span", { className: "ml-1 font-medium text-dc-text", children: t.querySummary.joinCount })
628
- ] }),
629
- /* @__PURE__ */ n("div", { className: "bg-dc-surface p-2 rounded", children: [
630
- /* @__PURE__ */ e("span", { className: "text-dc-text-muted", children: "CTEs:" }),
631
- /* @__PURE__ */ e("span", { className: "ml-1 font-medium text-dc-text", children: t.querySummary.cteCount })
632
- ] })
633
- ] })
634
- ] }),
635
- /* @__PURE__ */ n("div", { className: "border-b border-dc-border pb-3", children: [
636
- /* @__PURE__ */ n("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
637
- /* @__PURE__ */ e(a, { className: "w-4 h-4 mr-2" }),
638
- "Primary Cube (FROM table)"
639
- ] }),
640
- /* @__PURE__ */ n("div", { className: "bg-dc-surface p-3 rounded text-sm", children: [
641
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2 mb-2 flex-wrap", children: [
642
- /* @__PURE__ */ e("span", { className: "font-mono font-medium text-dc-primary", children: t.primaryCube.selectedCube }),
643
- /* @__PURE__ */ e("span", { className: `text-xs px-2 py-0.5 rounded ${zt(t.primaryCube.reason)}`, children: Be(t.primaryCube.reason) })
644
- ] }),
645
- /* @__PURE__ */ e("p", { className: "text-dc-text-secondary text-xs", children: t.primaryCube.explanation }),
646
- t.primaryCube.candidates && t.primaryCube.candidates.length > 1 && /* @__PURE__ */ n("details", { className: "mt-2", children: [
647
- /* @__PURE__ */ n("summary", { className: "text-xs text-dc-text-muted cursor-pointer hover:text-dc-text", children: [
648
- "Show candidates (",
649
- t.primaryCube.candidates.length,
650
- ")"
651
- ] }),
652
- /* @__PURE__ */ e("div", { className: "mt-2 space-y-1 ml-2", children: t.primaryCube.candidates.map((i, b) => /* @__PURE__ */ n("div", { className: "text-xs flex items-center gap-2 flex-wrap", children: [
653
- /* @__PURE__ */ e("span", { className: `font-mono ${i.cubeName === t.primaryCube.selectedCube ? "font-bold text-dc-primary" : "text-dc-text-muted"}`, children: i.cubeName }),
654
- /* @__PURE__ */ n("span", { className: "text-dc-text-muted", children: [
655
- "dims: ",
656
- i.dimensionCount,
657
- ", joins: ",
658
- i.joinCount
659
- ] }),
660
- i.canReachAll ? /* @__PURE__ */ n("span", { className: "text-green-600 dark:text-green-400 flex items-center gap-0.5", children: [
661
- /* @__PURE__ */ e(N, { className: "w-3 h-3" }),
662
- "reachable"
663
- ] }) : /* @__PURE__ */ n("span", { className: "text-red-600 dark:text-red-400 flex items-center gap-0.5", children: [
664
- /* @__PURE__ */ e(D, { className: "w-3 h-3" }),
665
- "cannot reach all"
666
- ] })
667
- ] }, b)) })
668
- ] })
669
- ] })
670
- ] }),
671
- t.joinPaths.length > 0 && /* @__PURE__ */ n("div", { className: "border-b border-dc-border pb-3", children: [
672
- /* @__PURE__ */ n("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
673
- /* @__PURE__ */ e(u, { className: "w-4 h-4 mr-2" }),
674
- "Join Paths"
675
- ] }),
676
- /* @__PURE__ */ e("div", { className: "space-y-2", children: t.joinPaths.map((i, b) => /* @__PURE__ */ n("div", { className: "bg-dc-surface p-3 rounded text-sm", children: [
677
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2 mb-2 flex-wrap", children: [
678
- /* @__PURE__ */ e("span", { className: "font-mono text-dc-text-secondary", children: t.primaryCube.selectedCube }),
679
- /* @__PURE__ */ e(s, { className: "w-4 h-4 text-dc-text-muted" }),
680
- /* @__PURE__ */ e("span", { className: "font-mono font-medium text-dc-text", children: i.targetCube }),
681
- i.pathFound ? /* @__PURE__ */ n("span", { className: "text-xs px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 rounded", children: [
682
- i.pathLength,
683
- " step",
684
- i.pathLength !== 1 ? "s" : ""
685
- ] }) : /* @__PURE__ */ e("span", { className: "text-xs px-2 py-0.5 bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 rounded", children: "No path" })
686
- ] }),
687
- i.pathFound && i.path && i.path.length > 0 && /* @__PURE__ */ e("div", { className: "space-y-1 ml-2", children: i.path.map((g, T) => /* @__PURE__ */ n("div", { className: "flex items-center gap-1 text-xs flex-wrap", children: [
688
- /* @__PURE__ */ e("span", { className: "font-mono text-dc-text-secondary", children: g.fromCube }),
689
- /* @__PURE__ */ e(s, { className: "w-3 h-3 text-dc-text-muted" }),
690
- /* @__PURE__ */ e("span", { className: "font-mono text-dc-text", children: g.toCube }),
691
- /* @__PURE__ */ n("span", { className: "text-dc-text-muted", children: [
692
- "(",
693
- g.relationship,
694
- ", ",
695
- g.joinType,
696
- " join)"
697
- ] }),
698
- g.joinColumns.length > 0 && /* @__PURE__ */ n("span", { className: "text-dc-text-muted", children: [
699
- "on ",
700
- g.joinColumns.map((f) => `${f.sourceColumn}=${f.targetColumn}`).join(", ")
701
- ] })
702
- ] }, T)) }),
703
- !i.pathFound && i.error && /* @__PURE__ */ e("p", { className: "text-xs text-red-600 dark:text-red-400 mt-1", children: i.error }),
704
- i.visitedCubes && i.visitedCubes.length > 0 && !i.pathFound && /* @__PURE__ */ n("details", { className: "mt-1", children: [
705
- /* @__PURE__ */ n("summary", { className: "text-xs text-dc-text-muted cursor-pointer hover:text-dc-text", children: [
706
- "Cubes visited during search (",
707
- i.visitedCubes.length,
708
- ")"
709
- ] }),
710
- /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-dc-text-muted ml-2", children: i.visitedCubes.join(" → ") })
711
- ] })
712
- ] }, b)) })
713
- ] }),
714
- t.preAggregations.length > 0 && /* @__PURE__ */ n("div", { className: "border-b border-dc-border pb-3", children: [
715
- /* @__PURE__ */ n("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
716
- /* @__PURE__ */ e(a, { className: "w-4 h-4 mr-2" }),
717
- "Pre-Aggregation CTEs"
718
- ] }),
719
- /* @__PURE__ */ e("div", { className: "space-y-2", children: t.preAggregations.map((i, b) => /* @__PURE__ */ n("div", { className: "bg-dc-surface p-3 rounded text-sm", children: [
720
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2 mb-1 flex-wrap", children: [
721
- /* @__PURE__ */ e("span", { className: "font-mono font-medium text-dc-text", children: i.cubeName }),
722
- /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted", children: "as" }),
723
- /* @__PURE__ */ e("code", { className: "text-xs bg-dc-surface-secondary px-1 rounded font-mono", children: i.cteAlias })
724
- ] }),
725
- /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-secondary", children: i.reason }),
726
- /* @__PURE__ */ n("div", { className: "mt-1 text-xs text-dc-text-muted", children: [
727
- /* @__PURE__ */ e("span", { className: "font-medium", children: "Measures:" }),
728
- " ",
729
- i.measures.join(", ")
730
- ] }),
731
- i.joinKeys.length > 0 && /* @__PURE__ */ n("div", { className: "mt-1 text-xs text-dc-text-muted", children: [
732
- /* @__PURE__ */ e("span", { className: "font-medium", children: "Join keys:" }),
733
- " ",
734
- i.joinKeys.map((g) => `${g.sourceColumn}=${g.targetColumn}`).join(", ")
735
- ] })
736
- ] }, b)) })
737
- ] }),
738
- t.warnings && t.warnings.length > 0 && /* @__PURE__ */ n("div", { children: [
739
- /* @__PURE__ */ n("h4", { className: "text-sm font-semibold text-amber-600 dark:text-amber-400 mb-2 flex items-center", children: [
740
- /* @__PURE__ */ e(l, { className: "w-4 h-4 mr-2" }),
741
- "Warnings"
742
- ] }),
743
- /* @__PURE__ */ e("ul", { className: "list-disc list-inside text-xs text-amber-600 dark:text-amber-400 space-y-1", children: t.warnings.map((i, b) => /* @__PURE__ */ e("li", { children: i }, b)) })
744
- ] }),
745
- t.cubesInvolved.length > 0 && /* @__PURE__ */ n("div", { className: "text-xs text-dc-text-muted pt-2 border-t border-dc-border", children: [
746
- /* @__PURE__ */ e("span", { className: "font-medium", children: "Cubes involved:" }),
747
- " ",
748
- t.cubesInvolved.join(", ")
749
- ] })
750
- ] });
751
- };
752
- function We(t) {
753
- return t.isTimeDimension;
754
- }
755
- function Wt(t) {
756
- return t.find(We);
757
- }
758
- function Zt(t) {
759
- return t.find((r) => !r.isTimeDimension);
760
- }
761
- function $e(t) {
762
- return t.filter((r) => !r.isTimeDimension);
763
- }
764
- function Ze(t) {
765
- return t.filter(We);
766
- }
767
- function Oe(t, r, s) {
768
- const l = r.length, a = $e(s).length, u = Ze(s).length, N = s.length;
769
- switch (t) {
770
- // Always available charts
771
- case "table":
772
- case "markdown":
773
- return { available: !0 };
774
- // Measure-only charts (KPI Number, KPI Text)
775
- case "kpiNumber":
776
- case "kpiText":
777
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : { available: !0 };
778
- // Bar chart - needs dimension for categories + measure for values
779
- case "bar":
780
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : N < 1 ? { available: !1, reason: "Requires at least 1 breakdown for categories" } : { available: !0 };
781
- // KPI Delta - needs dimension for ordering + measure for values
782
- case "kpiDelta":
783
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : N < 1 ? { available: !1, reason: "Requires at least 1 breakdown for ordering" } : { available: !0 };
784
- // Line and area charts - need dimension/time + measure
785
- case "line":
786
- case "area":
787
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : N < 1 ? { available: !1, reason: "Requires a breakdown (dimension or time)" } : { available: !0 };
788
- // Pie chart - needs dimension (not time) + measure
789
- case "pie":
790
- return l < 1 ? { available: !1, reason: "Requires 1 measure" } : a < 1 ? { available: !1, reason: "Requires 1 dimension (not time dimension)" } : { available: !0 };
791
- // Scatter - needs measure + any breakdown
792
- case "scatter":
793
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : l < 2 && N < 1 ? { available: !1, reason: "Requires 2 measures or 1 measure + 1 breakdown" } : { available: !0 };
794
- // Bubble - needs 2+ measures and 1+ dimension
795
- case "bubble":
796
- return l < 2 ? { available: !1, reason: "Requires at least 2 measures" } : a < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
797
- // Radar - needs dimension + measure
798
- case "radar":
799
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : a < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
800
- // Radial Bar - needs dimension + measure
801
- case "radialBar":
802
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : a < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
803
- // Treemap - needs dimension + measure
804
- case "treemap":
805
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : a < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
806
- // Activity Grid - needs time dimension + measure
807
- case "activityGrid":
808
- return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : u < 1 ? { available: !1, reason: "Requires a time dimension" } : { available: !0 };
809
- default:
810
- return { available: !0 };
811
- }
812
- }
813
- function Ht(t, r) {
814
- const s = [
815
- "activityGrid",
816
- "area",
817
- "bar",
818
- "bubble",
819
- "kpiDelta",
820
- "kpiNumber",
821
- "kpiText",
822
- "line",
823
- "markdown",
824
- "pie",
825
- "radar",
826
- "radialBar",
827
- "scatter",
828
- "table",
829
- "treemap"
830
- ], l = {};
831
- for (const a of s)
832
- l[a] = Oe(a, t, r);
833
- return l;
834
- }
835
- function He(t, r, s) {
836
- if (Oe(s, t, r).available || t.length === 0 && r.length === 0)
837
- return s;
838
- const a = Ze(r).length > 0, u = $e(r).length > 0, N = t.length > 0;
839
- return a && N ? "line" : u && N ? "bar" : N && !u && !a ? "kpiNumber" : "table";
840
- }
841
- function Ie(t, r, s) {
842
- const l = He(t, r, s), a = Kt(l, t, r);
843
- return { chartType: l, chartConfig: a };
844
- }
845
- function Kt(t, r, s) {
846
- const l = Wt(s), a = Zt(s), u = $e(s), N = s;
847
- switch (t) {
848
- case "line":
849
- case "area":
850
- return {
851
- xAxis: l ? [l.field] : a ? [a.field] : [],
852
- yAxis: r.map((D) => D.field),
853
- series: u.length > 1 ? [u[1].field] : a && l ? [a.field] : []
854
- };
855
- case "bar":
856
- return {
857
- xAxis: a ? [a.field] : l ? [l.field] : [],
858
- yAxis: r.map((D) => D.field),
859
- series: u.length > 1 ? [u[1].field] : l && a ? [l.field] : []
860
- };
861
- case "pie":
862
- return {
863
- xAxis: a ? [a.field] : [],
864
- yAxis: r.length > 0 ? [r[0].field] : []
865
- };
866
- case "scatter":
867
- return r.length >= 2 ? {
868
- xAxis: [r[0].field],
869
- yAxis: [r[1].field],
870
- series: a ? [a.field] : []
871
- } : {
872
- xAxis: N.length > 0 ? [N[0].field] : [],
873
- yAxis: r.length > 0 ? [r[0].field] : [],
874
- series: u.length > 1 ? [u[1].field] : []
875
- };
876
- case "bubble":
877
- return {
878
- xAxis: r.length > 0 ? [r[0].field] : [],
879
- yAxis: r.length > 1 ? [r[1].field] : [],
880
- sizeField: r.length > 2 ? r[2].field : r.length > 1 ? r[1].field : void 0,
881
- series: a ? [a.field] : []
882
- };
883
- case "radar":
884
- case "radialBar":
885
- case "treemap":
886
- return {
887
- xAxis: a ? [a.field] : [],
888
- yAxis: r.length > 0 ? [r[0].field] : []
889
- };
890
- case "activityGrid":
891
- return {
892
- dateField: l ? [l.field] : [],
893
- valueField: r.length > 0 ? [r[0].field] : []
894
- };
895
- case "kpiNumber":
896
- case "kpiDelta":
897
- case "kpiText":
898
- return {
899
- yAxis: r.length > 0 ? [r[0].field] : []
900
- };
901
- case "table":
902
- return {
903
- xAxis: [
904
- ...s.map((D) => D.field),
905
- ...r.map((D) => D.field)
906
- ]
907
- };
908
- case "markdown":
909
- return {};
910
- default:
911
- return {
912
- xAxis: N.length > 0 ? [N[0].field] : [],
913
- yAxis: r.map((D) => D.field)
914
- };
915
- }
916
- }
917
- function Xt(t, r, s, l) {
918
- if (l && Oe(s, t, r).available)
919
- return null;
920
- const a = He(t, r, s);
921
- return a !== s ? a : null;
922
- }
923
- const Ut = ue(function({
924
- executionStatus: r,
925
- executionResults: s,
926
- executionError: l,
927
- totalRowCount: a,
928
- resultsStale: u = !1,
929
- chartType: N = "line",
930
- chartConfig: D = {},
931
- displayConfig: i = {},
932
- query: b,
933
- activeView: g = "chart",
934
- onActiveViewChange: T,
935
- displayLimit: f = 100,
936
- onDisplayLimitChange: S,
937
- hasMetrics: y = !1,
938
- // Debug props
939
- debugQuery: G,
940
- debugSql: E,
941
- debugAnalysis: P,
942
- debugLoading: j,
943
- debugError: Q,
944
- // Share props
945
- onShareClick: R,
946
- canShare: x = !1,
947
- shareButtonState: h = "idle"
948
- }) {
949
- const [o, v] = J(!1);
950
- U(() => {
951
- !y && g === "chart" && T("table");
952
- }, [y, g, T]);
953
- const A = _("success"), O = _("error"), V = _("warning"), z = _("table"), c = _("measure"), p = _("timeDimension"), m = _("codeBracket"), w = _("share"), d = _("check"), k = () => /* @__PURE__ */ e("div", { className: "h-full flex items-center justify-center", children: /* @__PURE__ */ n("div", { className: "text-center", children: [
954
- /* @__PURE__ */ e(
955
- "div",
956
- {
957
- className: "animate-spin rounded-full h-12 w-12 border-b-2 mx-auto mb-4",
958
- style: { borderBottomColor: "var(--dc-primary)" }
959
- }
960
- ),
961
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold text-dc-text-secondary mb-1", children: "Executing Query..." }),
962
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted", children: "Running your query against the cube API" })
963
- ] }) }), B = () => /* @__PURE__ */ e("div", { className: "h-full flex items-center justify-center p-4", children: /* @__PURE__ */ n("div", { className: "text-center max-w-md", children: [
964
- /* @__PURE__ */ e(O, { className: "w-12 h-12 mx-auto text-red-500 mb-4" }),
965
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold text-dc-text mb-2", children: "Query Execution Failed" }),
966
- /* @__PURE__ */ e("div", { className: "text-sm text-dc-text-secondary mb-4", children: "There was an error executing your query. Please check the query and try again." }),
967
- l && /* @__PURE__ */ e("div", { className: "bg-red-50 border border-red-200 rounded-lg p-3 text-left", children: /* @__PURE__ */ e("div", { className: "text-xs font-mono text-red-800 break-words", children: l }) })
968
- ] }) }), Z = !!(b.measures && b.measures.length > 0 || b.dimensions && b.dimensions.length > 0 || b.timeDimensions && b.timeDimensions.length > 0), X = () => /* @__PURE__ */ e("div", { className: "h-full flex items-center justify-center", children: /* @__PURE__ */ n("div", { className: "text-center", children: [
969
- /* @__PURE__ */ e(
970
- "div",
971
- {
972
- className: "animate-spin rounded-full h-12 w-12 border-b-2 mx-auto mb-4",
973
- style: { borderBottomColor: "var(--dc-primary)" }
974
- }
975
- ),
976
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold text-dc-text-secondary mb-1", children: "Preparing Query..." }),
977
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted", children: "Your query will execute shortly" })
978
- ] }) }), Y = () => /* @__PURE__ */ e("div", { className: "h-full flex items-center justify-center pt-6", children: /* @__PURE__ */ n("div", { className: "text-center mb-16", children: [
979
- /* @__PURE__ */ e(p, { className: "w-12 h-12 mx-auto text-dc-text-muted mb-3" }),
980
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold text-dc-text-secondary mb-1", children: "No Results Yet" }),
981
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted", children: "Add metrics or breakdowns from the panel on the right to see results" })
982
- ] }) }), re = () => /* @__PURE__ */ e("div", { className: "h-full flex items-center justify-center", children: /* @__PURE__ */ n("div", { className: "text-center", children: [
983
- /* @__PURE__ */ e(A, { className: "w-12 h-12 mx-auto text-green-500 mb-3" }),
984
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold text-dc-text mb-1", children: "Query Successful" }),
985
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted", children: "No data returned from the query" })
986
- ] }) }), se = () => !s || s.length === 0 ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-full text-dc-text-muted", children: /* @__PURE__ */ n("div", { className: "text-center", children: [
987
- /* @__PURE__ */ e(c, { className: "w-12 h-12 mx-auto mb-3 opacity-50" }),
988
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold mb-1", children: "No data to display" }),
989
- /* @__PURE__ */ e("div", { className: "text-xs", children: "Run a query to see chart visualization" })
990
- ] }) }) : vt(N) ? /* @__PURE__ */ e(
991
- Le,
992
- {
993
- chartType: N,
994
- data: s,
995
- chartConfig: D,
996
- displayConfig: i,
997
- queryObject: b,
998
- height: "100%",
999
- fallback: /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ e("div", { className: "animate-pulse bg-dc-surface-secondary rounded w-full h-full" }) })
1000
- }
1001
- ) : /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-full text-dc-text-muted", children: /* @__PURE__ */ n("div", { className: "text-center", children: [
1002
- /* @__PURE__ */ e(V, { className: "w-12 h-12 mx-auto mb-3 opacity-50" }),
1003
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold mb-1", children: "Unsupported chart type" }),
1004
- /* @__PURE__ */ e("div", { className: "text-xs", children: N })
1005
- ] }) }), he = () => /* @__PURE__ */ n("div", { className: "p-4 space-y-4 overflow-auto h-full", children: [
1006
- l && /* @__PURE__ */ n("div", { className: "bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded p-3", children: [
1007
- /* @__PURE__ */ e("h4", { className: "text-sm font-semibold text-red-700 dark:text-red-400 mb-1", children: "Execution Error" }),
1008
- /* @__PURE__ */ e("p", { className: "text-sm text-red-600 dark:text-red-300", children: l })
1009
- ] }),
1010
- /* @__PURE__ */ n("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1011
- /* @__PURE__ */ n("div", { children: [
1012
- /* @__PURE__ */ e("h4", { className: "text-sm font-semibold text-dc-text mb-2", children: "JSON Query" }),
1013
- /* @__PURE__ */ e("pre", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-xs overflow-auto max-h-64 text-dc-text-secondary", children: G ? JSON.stringify(G, null, 2) : "No query" })
1014
- ] }),
1015
- /* @__PURE__ */ n("div", { children: [
1016
- /* @__PURE__ */ e("h4", { className: "text-sm font-semibold text-dc-text mb-2", children: "Generated SQL" }),
1017
- j ? /* @__PURE__ */ e("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: "Loading..." }) : Q ? /* @__PURE__ */ e("div", { className: "text-red-500 text-sm bg-red-50 dark:bg-red-900/20 p-3 rounded border border-red-200 dark:border-red-800", children: Q }) : E ? /* @__PURE__ */ n("pre", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-xs overflow-auto max-h-64 text-dc-text-secondary font-mono whitespace-pre-wrap", children: [
1018
- E.sql,
1019
- E.params && E.params.length > 0 && /* @__PURE__ */ n(we, { children: [
1020
- `
1021
-
1022
- -- Parameters:
1023
- `,
1024
- JSON.stringify(E.params, null, 2)
1025
- ] })
1026
- ] }) : /* @__PURE__ */ e("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: "Add metrics to generate SQL" })
1027
- ] })
1028
- ] }),
1029
- /* @__PURE__ */ n("div", { children: [
1030
- /* @__PURE__ */ e("h4", { className: "text-sm font-semibold text-dc-text mb-2", children: "Query Analysis" }),
1031
- j ? /* @__PURE__ */ e("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: "Loading..." }) : P ? /* @__PURE__ */ e("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3", children: /* @__PURE__ */ e(Yt, { analysis: P }) }) : /* @__PURE__ */ e("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: Q ? "Analysis unavailable due to error" : "Add metrics to see analysis" })
1032
- ] })
1033
- ] }), de = () => {
1034
- if (!s || s.length === 0)
1035
- return /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-full text-dc-text-muted", children: /* @__PURE__ */ n("div", { className: "text-center", children: [
1036
- /* @__PURE__ */ e(z, { className: "w-12 h-12 mx-auto mb-3 opacity-50" }),
1037
- /* @__PURE__ */ e("div", { className: "text-sm font-semibold mb-1", children: "No data to display" }),
1038
- /* @__PURE__ */ e("div", { className: "text-xs", children: "Run a query to see table data" })
1039
- ] }) });
1040
- const ee = s.slice(0, f);
1041
- return /* @__PURE__ */ e(
1042
- Le,
1043
- {
1044
- chartType: "table",
1045
- data: ee,
1046
- queryObject: b,
1047
- height: "100%",
1048
- fallback: /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ e("div", { className: "animate-pulse bg-dc-surface-secondary rounded w-full h-full" }) })
1049
- }
1050
- );
1051
- }, me = () => /* @__PURE__ */ e("div", { className: "absolute inset-0 flex items-center justify-center bg-dc-surface bg-opacity-75 z-10", children: /* @__PURE__ */ n("div", { className: "text-center", children: [
1052
- /* @__PURE__ */ e(
1053
- "div",
1054
- {
1055
- className: "animate-spin rounded-full h-10 w-10 border-b-2 mx-auto mb-2",
1056
- style: { borderBottomColor: "var(--dc-primary)" }
1057
- }
1058
- ),
1059
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-secondary", children: "Refreshing results..." })
1060
- ] }) }), fe = () => !s || s.length === 0 ? re() : /* @__PURE__ */ n("div", { className: "h-full flex flex-col", children: [
1061
- /* @__PURE__ */ n("div", { className: "px-4 py-2 border-b border-dc-border bg-dc-surface-secondary flex-shrink-0", children: [
1062
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
1063
- /* @__PURE__ */ n("div", { className: "flex items-center", children: [
1064
- r === "refreshing" ? /* @__PURE__ */ e(
1065
- "div",
1066
- {
1067
- className: "w-4 h-4 mr-2 rounded-full border-b-2 animate-spin",
1068
- style: { borderBottomColor: "var(--dc-primary)" }
1069
- }
1070
- ) : /* @__PURE__ */ e(A, { className: "w-4 h-4 text-green-500 mr-2" }),
1071
- /* @__PURE__ */ n("span", { className: "text-sm text-dc-text-secondary", children: [
1072
- s.length,
1073
- " row",
1074
- s.length !== 1 ? "s" : "",
1075
- a !== null && a > s.length && /* @__PURE__ */ n("span", { className: "text-dc-text-muted", children: [
1076
- " of ",
1077
- a.toLocaleString()
1078
- ] }),
1079
- u && /* @__PURE__ */ e("span", { className: "text-dc-warning ml-2", children: "• Results may be outdated" })
1080
- ] })
1081
- ] }),
1082
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
1083
- g === "table" && !o && S && /* @__PURE__ */ n(
1084
- "select",
1085
- {
1086
- value: f,
1087
- onChange: (ee) => S(Number(ee.target.value)),
1088
- className: "text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text focus:outline-none focus:ring-1 focus:ring-dc-primary",
1089
- children: [
1090
- /* @__PURE__ */ e("option", { value: 50, children: "50 rows" }),
1091
- /* @__PURE__ */ e("option", { value: 100, children: "100 rows" }),
1092
- /* @__PURE__ */ e("option", { value: 250, children: "250 rows" }),
1093
- /* @__PURE__ */ e("option", { value: 500, children: "500 rows" })
1094
- ]
1095
- }
1096
- ),
1097
- R && /* @__PURE__ */ e(
1098
- "button",
1099
- {
1100
- onClick: R,
1101
- className: `flex items-center gap-1 px-2 py-1.5 text-xs font-medium rounded transition-colors ${h === "idle" && x ? "text-blue-700 dark:text-blue-300 bg-blue-100 dark:bg-blue-900/30 border border-blue-200 dark:border-blue-800 hover:bg-blue-200 dark:hover:bg-blue-900/50" : h !== "idle" ? "text-green-700 dark:text-green-300 bg-green-100 dark:bg-green-900/30 border border-green-200 dark:border-green-800" : "text-dc-text-muted bg-dc-surface-secondary border border-dc-border cursor-not-allowed"}`,
1102
- title: h === "idle" ? "Share this analysis" : "Link copied!",
1103
- disabled: !x || h !== "idle",
1104
- children: h === "idle" ? /* @__PURE__ */ n(we, { children: [
1105
- /* @__PURE__ */ e(w, { className: "w-3 h-3" }),
1106
- /* @__PURE__ */ e("span", { className: "hidden sm:inline", children: "Share" })
1107
- ] }) : h === "copied" ? /* @__PURE__ */ n(we, { children: [
1108
- /* @__PURE__ */ e(d, { className: "w-3 h-3" }),
1109
- /* @__PURE__ */ e("span", { className: "hidden sm:inline", children: "Copied!" })
1110
- ] }) : /* @__PURE__ */ n(we, { children: [
1111
- /* @__PURE__ */ e(d, { className: "w-3 h-3" }),
1112
- /* @__PURE__ */ e("span", { className: "hidden sm:inline", children: "Copied!" }),
1113
- /* @__PURE__ */ e("span", { className: "hidden lg:inline text-[10px] opacity-75", children: "(no chart)" })
1114
- ] })
1115
- }
1116
- ),
1117
- /* @__PURE__ */ n(
1118
- "button",
1119
- {
1120
- onClick: () => v(!o),
1121
- className: `p-1.5 rounded transition-colors relative ${o ? "bg-dc-primary text-white" : "text-dc-text-secondary hover:text-dc-text hover:bg-dc-surface-hover"}`,
1122
- title: o ? "Hide debug info" : "Show debug info",
1123
- children: [
1124
- /* @__PURE__ */ e(m, { className: "w-4 h-4" }),
1125
- (l || Q) && !o && /* @__PURE__ */ e("span", { className: "absolute -top-0.5 -right-0.5 w-2 h-2 bg-red-500 rounded-full" })
1126
- ]
1127
- }
1128
- )
1129
- ] })
1130
- ] }),
1131
- a !== null && a > 1e3 && /* @__PURE__ */ n("div", { className: "mt-2 bg-yellow-50 border border-yellow-200 rounded-lg p-2 flex items-start", children: [
1132
- /* @__PURE__ */ e(V, { className: "w-4 h-4 text-yellow-600 mr-2 shrink-0 mt-0.5" }),
1133
- /* @__PURE__ */ n("div", { className: "text-xs text-yellow-800", children: [
1134
- /* @__PURE__ */ e("span", { className: "font-semibold", children: "Large dataset:" }),
1135
- " ",
1136
- a.toLocaleString(),
1137
- " rows. Consider adding filters to improve performance."
1138
- ] })
1139
- ] })
1140
- ] }),
1141
- /* @__PURE__ */ e("div", { className: "flex-1 min-h-0 relative overflow-auto", children: o ? he() : g === "chart" ? /* @__PURE__ */ e("div", { className: "p-4 h-full", children: se() }) : /* @__PURE__ */ e("div", { className: "h-full", children: de() }) }),
1142
- !o && /* @__PURE__ */ e("div", { className: "px-4 py-3 border-t border-dc-border bg-dc-surface flex justify-center flex-shrink-0", children: /* @__PURE__ */ n("div", { className: "flex items-center bg-dc-surface-secondary border border-dc-border rounded-md overflow-hidden", children: [
1143
- /* @__PURE__ */ n(
1144
- "button",
1145
- {
1146
- onClick: () => y && T("chart"),
1147
- disabled: !y,
1148
- className: `flex items-center gap-1.5 px-4 py-1.5 text-sm font-medium transition-colors ${g === "chart" ? "bg-dc-primary text-white" : y ? "text-dc-text-secondary hover:bg-dc-surface-hover" : "text-dc-text-muted cursor-not-allowed opacity-50"}`,
1149
- title: y ? "Chart view" : "Add metrics to enable chart view",
1150
- children: [
1151
- /* @__PURE__ */ e(c, { className: "w-4 h-4" }),
1152
- "Chart"
1153
- ]
1154
- }
1155
- ),
1156
- /* @__PURE__ */ n(
1157
- "button",
1158
- {
1159
- onClick: () => T("table"),
1160
- className: `flex items-center gap-1.5 px-4 py-1.5 text-sm font-medium transition-colors ${g === "table" ? "bg-dc-primary text-white" : "text-dc-text-secondary hover:bg-dc-surface-hover"}`,
1161
- title: "Table view",
1162
- children: [
1163
- /* @__PURE__ */ e(z, { className: "w-4 h-4" }),
1164
- "Table"
1165
- ]
1166
- }
1167
- )
1168
- ] }) })
1169
- ] }), le = s !== null;
1170
- return /* @__PURE__ */ n("div", { className: "h-full min-h-[400px] flex flex-col bg-dc-surface relative", children: [
1171
- r === "idle" && !Z && Y(),
1172
- r === "idle" && Z && !le && X(),
1173
- r === "loading" && !le && k(),
1174
- r === "error" && !le && B(),
1175
- (r === "success" || le) && fe(),
1176
- (r === "loading" || r === "refreshing") && le && me()
1177
- ] });
1178
- }), er = ue(function({
1179
- metric: r,
1180
- fieldMeta: s,
1181
- onRemove: l,
1182
- sortDirection: a,
1183
- sortPriority: u,
1184
- onToggleSort: N,
1185
- index: D,
1186
- isDragging: i,
1187
- onDragStart: b,
1188
- onDragEnd: g
1189
- }) {
1190
- const T = _("close"), f = _("chevronUp"), S = _("chevronDown"), y = _("chevronUpDown"), G = s?.type || "count", E = ye(G) || _("measure"), P = s?.shortTitle || s?.title || r.field.split(".").pop() || r.field, j = r.field.split(".")[0], Q = () => {
1191
- switch (a) {
1192
- case "asc":
1193
- return f ? /* @__PURE__ */ e(f, { className: "w-4 h-4" }) : "↑";
1194
- case "desc":
1195
- return S ? /* @__PURE__ */ e(S, { className: "w-4 h-4" }) : "↓";
1196
- default:
1197
- return y ? /* @__PURE__ */ e(y, { className: "w-4 h-4" }) : "⇅";
1198
- }
1199
- }, R = () => {
1200
- switch (a) {
1201
- case "asc":
1202
- return "Sorted ascending (click for descending)";
1203
- case "desc":
1204
- return "Sorted descending (click to remove)";
1205
- default:
1206
- return "Click to sort ascending";
1207
- }
1208
- }, x = typeof D == "number" && b && g;
1209
- return /* @__PURE__ */ n(
1210
- "div",
1211
- {
1212
- className: `flex items-center gap-2 p-2 bg-dc-surface-secondary rounded-lg group hover:bg-dc-surface-tertiary transition-all duration-150 ${x ? "cursor-grab active:cursor-grabbing" : ""} ${i ? "opacity-30" : ""}`,
1213
- draggable: x ? !0 : void 0,
1214
- onDragStart: x ? (h) => b(h, D) : void 0,
1215
- onDragEnd: x ? g : void 0,
1216
- children: [
1217
- /* @__PURE__ */ e("span", { className: "w-6 h-6 flex items-center justify-center rounded bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 flex-shrink-0", children: E && /* @__PURE__ */ e(E, { className: "w-4 h-4" }) }),
1218
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
1219
- /* @__PURE__ */ e("div", { className: "text-sm text-dc-text truncate", title: r.field, children: P }),
1220
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted truncate", children: j })
1221
- ] }),
1222
- N && /* @__PURE__ */ n(
1223
- "button",
1224
- {
1225
- onClick: N,
1226
- className: `p-1 transition-opacity flex-shrink-0 flex items-center gap-0.5 ${a ? "opacity-100 text-dc-primary" : "opacity-0 group-hover:opacity-100 text-dc-text-muted hover:text-dc-primary"}`,
1227
- title: R(),
1228
- children: [
1229
- Q(),
1230
- a && u && /* @__PURE__ */ n("span", { className: "text-xs font-medium", children: [
1231
- "(",
1232
- u,
1233
- ")"
1234
- ] })
1235
- ]
1236
- }
1237
- ),
1238
- /* @__PURE__ */ e(
1239
- "button",
1240
- {
1241
- onClick: l,
1242
- className: "p-1 text-dc-text-muted hover:text-dc-danger opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",
1243
- title: "Remove metric",
1244
- children: /* @__PURE__ */ e(T, { className: "w-4 h-4" })
1245
- }
1246
- )
1247
- ]
1248
- }
1249
- );
1250
- }), tr = _("add");
1251
- function rr(t, r) {
1252
- if (!r?.cubes) return null;
1253
- const [s] = t.split("."), l = r.cubes.find((a) => a.name === s);
1254
- return l && l.measures?.find((a) => a.name === t) || null;
1255
- }
1256
- function sr(t) {
1257
- switch (t) {
1258
- case null:
1259
- return "asc";
1260
- case "asc":
1261
- return "desc";
1262
- case "desc":
1263
- return null;
1264
- default:
1265
- return "asc";
1266
- }
1267
- }
1268
- const nr = ue(function({
1269
- metrics: r,
1270
- schema: s,
1271
- onAdd: l,
1272
- onRemove: a,
1273
- order: u,
1274
- onOrderChange: N,
1275
- onReorder: D
1276
- }) {
1277
- const [i, b] = J(null), [g, T] = J(null), f = H(() => u ? Object.keys(u) : [], [u]), S = H(() => r.map((h, o) => {
1278
- const v = u?.[h.field] || null, A = v ? f.indexOf(h.field) + 1 : void 0;
1279
- return {
1280
- metric: h,
1281
- fieldMeta: rr(h.field, s),
1282
- sortDirection: v,
1283
- sortPriority: A,
1284
- index: o
1285
- };
1286
- }), [r, s, u, f]), y = ae(null), G = I((h, o) => {
1287
- b(o), h.dataTransfer.effectAllowed = "move", h.dataTransfer.setData("text/plain", JSON.stringify({ type: "metric", index: o, field: r[o].field }));
1288
- const v = h.currentTarget, A = v.cloneNode(!0);
1289
- A.style.cssText = `
1290
- position: absolute;
1291
- top: -9999px;
1292
- left: -9999px;
1293
- width: ${v.offsetWidth}px;
1294
- opacity: 0.7;
1295
- transform: rotate(2deg);
1296
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
1297
- pointer-events: none;
1298
- `, document.body.appendChild(A), y.current = A;
1299
- const O = v.getBoundingClientRect(), V = h.clientX - O.left, z = h.clientY - O.top;
1300
- h.dataTransfer.setDragImage(A, V, z);
1301
- }, [r]), E = I(() => {
1302
- b(null), T(null), y.current && (document.body.removeChild(y.current), y.current = null);
1303
- }, []), P = I((h, o) => {
1304
- h.preventDefault(), h.stopPropagation(), i !== null && T(o);
1305
- }, [i]), j = I((h) => {
1306
- h.preventDefault(), h.stopPropagation();
1307
- const o = h.relatedTarget;
1308
- (!o || !h.currentTarget.contains(o)) && T(null);
1309
- }, []), Q = I((h, o) => {
1310
- h.preventDefault(), h.stopPropagation();
1311
- try {
1312
- if (JSON.parse(h.dataTransfer.getData("text/plain")).type === "metric" && i !== null && D) {
1313
- const A = o > i ? o - 1 : o;
1314
- A !== i && D(i, A);
1315
- }
1316
- } catch {
1317
- }
1318
- b(null), T(null);
1319
- }, [i, D]), R = I((h) => {
1320
- const o = h.relatedTarget;
1321
- (!o || !h.currentTarget.contains(o)) && T(null);
1322
- }, []), x = (h, o = !1) => {
1323
- const v = g === h && i !== null, A = i !== null && h !== i && h !== i + 1;
1324
- return i === null ? null : /* @__PURE__ */ e(
1325
- "div",
1326
- {
1327
- className: `absolute left-0 right-0 z-10 ${o ? "-top-1" : "-bottom-1"}`,
1328
- style: { height: "16px", transform: o ? "translateY(-50%)" : "translateY(50%)" },
1329
- onDragOver: (O) => P(O, h),
1330
- onDragLeave: j,
1331
- onDrop: (O) => Q(O, h),
1332
- children: A && /* @__PURE__ */ e(
1333
- "div",
1334
- {
1335
- className: `absolute inset-x-0 top-1/2 -translate-y-1/2 rounded-md border-2 border-dashed flex items-center justify-center transition-all ${v ? "border-dc-primary bg-dc-primary/10 h-8" : "border-transparent h-1"}`,
1336
- children: v && /* @__PURE__ */ e("span", { className: "text-xs text-dc-primary font-medium", children: "Drop here" })
1337
- }
1338
- )
1339
- },
1340
- `drop-${h}`
1341
- );
1342
- };
1343
- return /* @__PURE__ */ n("div", { children: [
1344
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between mb-3", children: [
1345
- /* @__PURE__ */ e("h3", { className: "text-sm font-semibold text-dc-text", children: "Metrics" }),
1346
- /* @__PURE__ */ e(
1347
- "button",
1348
- {
1349
- onClick: l,
1350
- className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-secondary rounded transition-colors",
1351
- title: "Add metric",
1352
- children: /* @__PURE__ */ e(tr, { className: "w-5 h-5" })
1353
- }
1354
- )
1355
- ] }),
1356
- /* @__PURE__ */ e("div", { className: "space-y-2", onDragLeave: D ? R : void 0, children: S.map(({ metric: h, fieldMeta: o, sortDirection: v, sortPriority: A, index: O }) => /* @__PURE__ */ n("div", { className: "relative", children: [
1357
- O === 0 && D && x(0, !0),
1358
- /* @__PURE__ */ e(
1359
- er,
1360
- {
1361
- metric: h,
1362
- fieldMeta: o,
1363
- onRemove: () => a(h.id),
1364
- sortDirection: v,
1365
- sortPriority: A,
1366
- onToggleSort: N ? () => {
1367
- const V = sr(v);
1368
- N(h.field, V);
1369
- } : void 0,
1370
- index: O,
1371
- isDragging: i === O,
1372
- onDragStart: D ? G : void 0,
1373
- onDragEnd: D ? E : void 0
1374
- }
1375
- ),
1376
- D && x(O + 1)
1377
- ] }, h.id)) })
1378
- ] });
1379
- }), ar = [
1380
- { value: "hour", label: "Hour" },
1381
- { value: "day", label: "Day" },
1382
- { value: "week", label: "Week" },
1383
- { value: "month", label: "Month" },
1384
- { value: "quarter", label: "Quarter" },
1385
- { value: "year", label: "Year" }
1386
- ], lr = ue(function({
1387
- breakdown: r,
1388
- fieldMeta: s,
1389
- onRemove: l,
1390
- onGranularityChange: a,
1391
- sortDirection: u,
1392
- sortPriority: N,
1393
- onToggleSort: D,
1394
- index: i,
1395
- isDragging: b,
1396
- onDragStart: g,
1397
- onDragEnd: T
1398
- }) {
1399
- const f = _("dimension"), S = _("timeDimension"), y = _("close"), G = _("chevronUp"), E = _("chevronDown"), P = _("chevronUpDown"), j = s?.shortTitle || s?.title || r.field.split(".").pop() || r.field, Q = r.field.split(".")[0], R = r.isTimeDimension ? S : f, x = () => {
1400
- switch (u) {
1401
- case "asc":
1402
- return G ? /* @__PURE__ */ e(G, { className: "w-4 h-4" }) : "↑";
1403
- case "desc":
1404
- return E ? /* @__PURE__ */ e(E, { className: "w-4 h-4" }) : "↓";
1405
- default:
1406
- return P ? /* @__PURE__ */ e(P, { className: "w-4 h-4" }) : "⇅";
1407
- }
1408
- }, h = () => {
1409
- switch (u) {
1410
- case "asc":
1411
- return "Sorted ascending (click for descending)";
1412
- case "desc":
1413
- return "Sorted descending (click to remove)";
1414
- default:
1415
- return "Click to sort ascending";
1416
- }
1417
- }, o = typeof i == "number" && g && T;
1418
- return /* @__PURE__ */ n(
1419
- "div",
1420
- {
1421
- className: `flex items-center gap-2 p-2 bg-dc-surface-secondary rounded-lg group hover:bg-dc-surface-tertiary transition-all duration-150 ${o ? "cursor-grab active:cursor-grabbing" : ""} ${b ? "opacity-30" : ""}`,
1422
- draggable: o ? !0 : void 0,
1423
- onDragStart: o ? (v) => g(v, i) : void 0,
1424
- onDragEnd: o ? T : void 0,
1425
- children: [
1426
- /* @__PURE__ */ e(R, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }),
1427
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
1428
- /* @__PURE__ */ e("div", { className: "text-sm text-dc-text truncate", title: r.field, children: j }),
1429
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted truncate", children: Q })
1430
- ] }),
1431
- r.isTimeDimension && a && /* @__PURE__ */ e(
1432
- "select",
1433
- {
1434
- value: r.granularity || "day",
1435
- onChange: (v) => a(v.target.value),
1436
- onClick: (v) => v.stopPropagation(),
1437
- className: "text-xs bg-dc-surface border border-dc-border rounded px-2 py-1 text-dc-text focus:outline-none focus:ring-1 focus:ring-dc-primary flex-shrink-0",
1438
- children: ar.map((v) => /* @__PURE__ */ e("option", { value: v.value, children: v.label }, v.value))
1439
- }
1440
- ),
1441
- D && /* @__PURE__ */ n(
1442
- "button",
1443
- {
1444
- onClick: D,
1445
- className: `p-1 transition-opacity flex-shrink-0 flex items-center gap-0.5 ${u ? "opacity-100 text-dc-primary" : "opacity-0 group-hover:opacity-100 text-dc-text-muted hover:text-dc-primary"}`,
1446
- title: h(),
1447
- children: [
1448
- x(),
1449
- u && N && /* @__PURE__ */ n("span", { className: "text-xs font-medium", children: [
1450
- "(",
1451
- N,
1452
- ")"
1453
- ] })
1454
- ]
1455
- }
1456
- ),
1457
- /* @__PURE__ */ e(
1458
- "button",
1459
- {
1460
- onClick: l,
1461
- className: "p-1 text-dc-text-muted hover:text-dc-danger opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",
1462
- title: "Remove breakdown",
1463
- children: /* @__PURE__ */ e(y, { className: "w-4 h-4" })
1464
- }
1465
- )
1466
- ]
1467
- }
1468
- );
1469
- }), cr = _("add");
1470
- function ir(t, r) {
1471
- if (!r?.cubes) return null;
1472
- const [s] = t.split("."), l = r.cubes.find((a) => a.name === s);
1473
- return l && l.dimensions?.find((a) => a.name === t) || null;
1474
- }
1475
- function dr(t) {
1476
- switch (t) {
1477
- case null:
1478
- return "asc";
1479
- case "asc":
1480
- return "desc";
1481
- case "desc":
1482
- return null;
1483
- default:
1484
- return "asc";
1485
- }
1486
- }
1487
- const or = ue(function({
1488
- breakdowns: r,
1489
- schema: s,
1490
- onAdd: l,
1491
- onRemove: a,
1492
- onGranularityChange: u,
1493
- order: N,
1494
- onOrderChange: D,
1495
- onReorder: i
1496
- }) {
1497
- const [b, g] = J(null), [T, f] = J(null), S = H(() => N ? Object.keys(N) : [], [N]), y = H(() => r.map((o, v) => {
1498
- const A = N?.[o.field] || null, O = A ? S.indexOf(o.field) + 1 : void 0;
1499
- return {
1500
- breakdown: o,
1501
- fieldMeta: ir(o.field, s),
1502
- sortDirection: A,
1503
- sortPriority: O,
1504
- index: v
1505
- };
1506
- }), [r, s, N, S]), G = ae(null), E = I((o, v) => {
1507
- g(v), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setData("text/plain", JSON.stringify({ type: "breakdown", index: v, field: r[v].field }));
1508
- const A = o.currentTarget, O = A.cloneNode(!0);
1509
- O.style.cssText = `
1510
- position: absolute;
1511
- top: -9999px;
1512
- left: -9999px;
1513
- width: ${A.offsetWidth}px;
1514
- opacity: 0.7;
1515
- transform: rotate(2deg);
1516
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
1517
- pointer-events: none;
1518
- `, document.body.appendChild(O), G.current = O;
1519
- const V = A.getBoundingClientRect(), z = o.clientX - V.left, c = o.clientY - V.top;
1520
- o.dataTransfer.setDragImage(O, z, c);
1521
- }, [r]), P = I(() => {
1522
- g(null), f(null), G.current && (document.body.removeChild(G.current), G.current = null);
1523
- }, []), j = I((o, v) => {
1524
- o.preventDefault(), o.stopPropagation(), b !== null && f(v);
1525
- }, [b]), Q = I((o) => {
1526
- o.preventDefault(), o.stopPropagation();
1527
- const v = o.relatedTarget;
1528
- (!v || !o.currentTarget.contains(v)) && f(null);
1529
- }, []), R = I((o, v) => {
1530
- o.preventDefault(), o.stopPropagation();
1531
- try {
1532
- if (JSON.parse(o.dataTransfer.getData("text/plain")).type === "breakdown" && b !== null && i) {
1533
- const O = v > b ? v - 1 : v;
1534
- O !== b && i(b, O);
1535
- }
1536
- } catch {
1537
- }
1538
- g(null), f(null);
1539
- }, [b, i]), x = I((o) => {
1540
- const v = o.relatedTarget;
1541
- (!v || !o.currentTarget.contains(v)) && f(null);
1542
- }, []), h = (o, v = !1) => {
1543
- const A = T === o && b !== null, O = b !== null && o !== b && o !== b + 1;
1544
- return b === null ? null : /* @__PURE__ */ e(
1545
- "div",
1546
- {
1547
- className: `absolute left-0 right-0 z-10 ${v ? "-top-1" : "-bottom-1"}`,
1548
- style: { height: "16px", transform: v ? "translateY(-50%)" : "translateY(50%)" },
1549
- onDragOver: (V) => j(V, o),
1550
- onDragLeave: Q,
1551
- onDrop: (V) => R(V, o),
1552
- children: O && /* @__PURE__ */ e(
1553
- "div",
1554
- {
1555
- className: `absolute inset-x-0 top-1/2 -translate-y-1/2 rounded-md border-2 border-dashed flex items-center justify-center transition-all ${A ? "border-dc-primary bg-dc-primary/10 h-8" : "border-transparent h-1"}`,
1556
- children: A && /* @__PURE__ */ e("span", { className: "text-xs text-dc-primary font-medium", children: "Drop here" })
1557
- }
1558
- )
1559
- },
1560
- `drop-${o}`
1561
- );
1562
- };
1563
- return /* @__PURE__ */ n("div", { children: [
1564
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between mb-3", children: [
1565
- /* @__PURE__ */ e("h3", { className: "text-sm font-semibold text-dc-text", children: "Breakdown" }),
1566
- /* @__PURE__ */ e(
1567
- "button",
1568
- {
1569
- onClick: l,
1570
- className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-secondary rounded transition-colors",
1571
- title: "Add breakdown",
1572
- children: /* @__PURE__ */ e(cr, { className: "w-5 h-5" })
1573
- }
1574
- )
1575
- ] }),
1576
- /* @__PURE__ */ e("div", { className: "space-y-2", onDragLeave: i ? x : void 0, children: y.map(({ breakdown: o, fieldMeta: v, sortDirection: A, sortPriority: O, index: V }) => /* @__PURE__ */ n("div", { className: "relative", children: [
1577
- V === 0 && i && h(0, !0),
1578
- /* @__PURE__ */ e(
1579
- lr,
1580
- {
1581
- breakdown: o,
1582
- fieldMeta: v,
1583
- onRemove: () => a(o.id),
1584
- onGranularityChange: o.isTimeDimension ? (z) => u(o.id, z) : void 0,
1585
- sortDirection: A,
1586
- sortPriority: O,
1587
- onToggleSort: D ? () => {
1588
- const z = dr(A);
1589
- D(o.field, z);
1590
- } : void 0,
1591
- index: V,
1592
- isDragging: b === V,
1593
- onDragStart: i ? E : void 0,
1594
- onDragEnd: i ? P : void 0
1595
- }
1596
- ),
1597
- i && h(V + 1)
1598
- ] }, o.id)) })
1599
- ] });
1600
- }), Pe = _("close"), Re = _("chevronDown"), ur = _("dimension"), mr = _("timeDimension"), hr = _("measure");
1601
- function Ke({
1602
- filter: t,
1603
- schema: r,
1604
- onRemove: s,
1605
- onUpdate: l,
1606
- depth: a = 0
1607
- }) {
1608
- const [u, N] = J(!1), [D, i] = J(!1), [b, g] = J(!1), [T, f] = J("this_month"), [S, y] = J(1), [G, E] = J(""), P = ae(null), j = Dt(G, 300), Q = Ge(t.member, r), R = Q?.field.type || "string", x = R === "time", h = Q?.fieldType === "measure", o = Q?.fieldType === "dimension", v = St(t.member, r), A = qe[t.operator], O = Jt(R), V = x && t.operator === "inDateRange", z = H(() => ["equals", "notEquals", "in", "notIn"].includes(t.operator) && o && !x, [t.operator, o, x]), {
1609
- values: c,
1610
- loading: p,
1611
- error: m,
1612
- searchValues: w
1613
- } = Tt(t.member, z);
1614
- U(() => {
1615
- const C = (M) => {
1616
- P.current && !P.current.contains(M.target) && (N(!1), i(!1), g(!1));
1617
- };
1618
- return document.addEventListener("mousedown", C), () => document.removeEventListener("mousedown", C);
1619
- }, []), U(() => {
1620
- D && z && w && w("", !0);
1621
- }, [D, z, w]), U(() => {
1622
- D && z && w && j !== void 0 && w(j);
1623
- }, [j, D, z, w]), U(() => {
1624
- if (!(!V || !t.dateRange))
1625
- if (Array.isArray(t.dateRange))
1626
- f("custom");
1627
- else {
1628
- const C = t.dateRange.match(/^last (\d+) (days|weeks|months|quarters|years)$/);
1629
- if (C) {
1630
- const [, M, W] = C;
1631
- f(`last_n_${W}`), y(parseInt(M) || 1);
1632
- } else {
1633
- let M = !1;
1634
- for (const W of Fe)
1635
- if (W.value !== "custom" && !De(W.value) && ve(W.value) === t.dateRange) {
1636
- f(W.value), M = !0;
1637
- break;
1638
- }
1639
- M || f("custom");
1640
- }
1641
- }
1642
- }, [t.dateRange, V]);
1643
- const d = I((C) => {
1644
- const M = {
1645
- member: t.member,
1646
- operator: C,
1647
- values: []
1648
- };
1649
- l(M), N(!1);
1650
- }, [t.member, l]), k = I((C) => {
1651
- const M = t.values || [];
1652
- A?.supportsMultipleValues ? M.includes(C) || l({ ...t, values: [...M, C] }) : (l({ ...t, values: [C] }), i(!1)), E("");
1653
- }, [t, A?.supportsMultipleValues, l]), B = I((C) => {
1654
- const M = (t.values || []).filter((W) => W !== C);
1655
- l({ ...t, values: M });
1656
- }, [t, l]), Z = I((C) => {
1657
- const M = C.target.value;
1658
- if (A?.valueType === "number") {
1659
- const W = parseFloat(M);
1660
- isNaN(W) ? (M === "" || M === "-") && l({ ...t, values: [] }) : l({ ...t, values: [W] });
1661
- } else
1662
- l({ ...t, values: M ? [M] : [] });
1663
- }, [t, A?.valueType, l]), X = I((C) => {
1664
- const M = parseFloat(C.target.value), W = t.values?.length >= 2 ? t.values : ["", ""], ce = [isNaN(M) ? "" : M, W[1]].filter((be) => be !== "");
1665
- l({ ...t, values: ce });
1666
- }, [t, l]), Y = I((C) => {
1667
- const M = parseFloat(C.target.value), ce = [(t.values?.length >= 2 ? t.values : ["", ""])[0], isNaN(M) ? "" : M].filter((be) => be !== "");
1668
- l({ ...t, values: ce });
1669
- }, [t, l]), re = I((C) => {
1670
- const M = C.target.value;
1671
- l({ ...t, values: M ? [M] : [] });
1672
- }, [t, l]), se = I((C) => {
1673
- f(C), g(!1);
1674
- let M;
1675
- if (C === "custom") {
1676
- const W = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
1677
- M = [W, W];
1678
- } else De(C) ? M = ve(C, S) : M = ve(C);
1679
- l({ ...t, dateRange: M });
1680
- }, [t, S, l]), he = I((C) => {
1681
- if (y(C), De(T)) {
1682
- const M = ve(T, C);
1683
- l({ ...t, dateRange: M });
1684
- }
1685
- }, [t, T, l]), de = I((C) => {
1686
- const M = C.target.value, ce = (Array.isArray(t.dateRange) ? t.dateRange : [t.dateRange || "", ""])[1] || M;
1687
- l({ ...t, dateRange: [M, ce] });
1688
- }, [t, l]), me = I((C) => {
1689
- const M = C.target.value, ce = (Array.isArray(t.dateRange) ? t.dateRange : ["", t.dateRange || ""])[0] || M;
1690
- l({ ...t, dateRange: [ce, M] });
1691
- }, [t, l]), fe = O.find((C) => C.operator === t.operator)?.label || t.operator, le = Fe.find((C) => C.value === T)?.label || "Select range", ee = x ? mr : h ? hr : ur, ne = x ? "text-blue-500" : h ? "text-amber-500" : "text-green-500", oe = () => A?.requiresValues ? V ? /* @__PURE__ */ n("div", { className: "space-y-1.5", children: [
1692
- /* @__PURE__ */ n("div", { className: "relative", children: [
1693
- /* @__PURE__ */ n(
1694
- "button",
1695
- {
1696
- onClick: () => {
1697
- N(!1), i(!1), g(!b);
1698
- },
1699
- className: "w-full flex items-center justify-between text-left text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text hover:bg-dc-surface-hover",
1700
- children: [
1701
- /* @__PURE__ */ e("span", { className: "truncate", children: le }),
1702
- /* @__PURE__ */ e(Re, { className: `w-3 h-3 text-dc-text-muted shrink-0 ml-1 transition-transform ${b ? "rotate-180" : ""}` })
1703
- ]
1704
- }
1705
- ),
1706
- b && /* @__PURE__ */ e("div", { className: "absolute z-30 left-0 right-0 mt-1 bg-dc-surface border border-dc-border rounded shadow-lg max-h-40 overflow-y-auto", children: Fe.map((C) => /* @__PURE__ */ e(
1707
- "button",
1708
- {
1709
- onClick: () => se(C.value),
1710
- className: `w-full text-left px-2 py-1.5 text-xs hover:bg-dc-surface-hover ${C.value === T ? "bg-dc-primary/10 text-dc-primary" : "text-dc-text"}`,
1711
- children: C.label
1712
- },
1713
- C.value
1714
- )) })
1715
- ] }),
1716
- De(T) && /* @__PURE__ */ n("div", { className: "flex items-center gap-1.5", children: [
1717
- /* @__PURE__ */ e(
1718
- "input",
1719
- {
1720
- type: "number",
1721
- min: "1",
1722
- max: "1000",
1723
- value: S,
1724
- onChange: (C) => he(Math.max(1, parseInt(C.target.value) || 1)),
1725
- className: "flex-1 text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text w-16"
1726
- }
1727
- ),
1728
- /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted", children: T.replace("last_n_", "") })
1729
- ] }),
1730
- T === "custom" && /* @__PURE__ */ n("div", { className: "flex items-center gap-1.5", children: [
1731
- /* @__PURE__ */ e(
1732
- "input",
1733
- {
1734
- type: "date",
1735
- value: Array.isArray(t.dateRange) ? t.dateRange[0] : "",
1736
- onChange: de,
1737
- className: "flex-1 text-xs border border-dc-border rounded px-1.5 py-1 bg-dc-surface text-dc-text"
1738
- }
1739
- ),
1740
- /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted", children: "to" }),
1741
- /* @__PURE__ */ e(
1742
- "input",
1743
- {
1744
- type: "date",
1745
- value: Array.isArray(t.dateRange) ? t.dateRange[1] : "",
1746
- onChange: me,
1747
- className: "flex-1 text-xs border border-dc-border rounded px-1.5 py-1 bg-dc-surface text-dc-text"
1748
- }
1749
- )
1750
- ] })
1751
- ] }) : t.operator === "between" || t.operator === "notBetween" ? /* @__PURE__ */ n("div", { className: "flex items-center gap-1.5", children: [
1752
- /* @__PURE__ */ e(
1753
- "input",
1754
- {
1755
- type: "number",
1756
- value: t.values?.[0] ?? "",
1757
- onChange: X,
1758
- placeholder: "Min",
1759
- className: "flex-1 text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1760
- }
1761
- ),
1762
- /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted", children: "to" }),
1763
- /* @__PURE__ */ e(
1764
- "input",
1765
- {
1766
- type: "number",
1767
- value: t.values?.[1] ?? "",
1768
- onChange: Y,
1769
- placeholder: "Max",
1770
- className: "flex-1 text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1771
- }
1772
- )
1773
- ] }) : A?.valueType === "date" ? /* @__PURE__ */ e(
1774
- "input",
1775
- {
1776
- type: "date",
1777
- value: t.values?.[0] || "",
1778
- onChange: re,
1779
- className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1780
- }
1781
- ) : A?.valueType === "number" ? /* @__PURE__ */ e(
1782
- "input",
1783
- {
1784
- type: "number",
1785
- value: t.values?.[0] ?? "",
1786
- onChange: Z,
1787
- placeholder: "Enter number",
1788
- className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1789
- }
1790
- ) : z ? /* @__PURE__ */ n("div", { className: "space-y-1.5", children: [
1791
- t.values && t.values.length > 0 && /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1", children: t.values.map((C, M) => /* @__PURE__ */ n(
1792
- "span",
1793
- {
1794
- className: "inline-flex items-center gap-0.5 bg-dc-primary/10 text-dc-primary text-xs px-1.5 py-0.5 rounded",
1795
- children: [
1796
- /* @__PURE__ */ e("span", { className: "max-w-[100px] truncate", children: String(C) }),
1797
- /* @__PURE__ */ e(
1798
- "button",
1799
- {
1800
- onClick: () => B(C),
1801
- className: "hover:text-red-600",
1802
- children: /* @__PURE__ */ e(Pe, { className: "w-3 h-3" })
1803
- }
1804
- )
1805
- ]
1806
- },
1807
- M
1808
- )) }),
1809
- /* @__PURE__ */ n("div", { className: "relative", children: [
1810
- /* @__PURE__ */ n(
1811
- "button",
1812
- {
1813
- onClick: () => {
1814
- N(!1), g(!1), i(!D);
1815
- },
1816
- className: "w-full flex items-center justify-between text-left text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text hover:bg-dc-surface-hover",
1817
- children: [
1818
- /* @__PURE__ */ e("span", { className: "text-dc-text-muted truncate", children: p ? "Loading..." : "Select value..." }),
1819
- /* @__PURE__ */ e(Re, { className: `w-3 h-3 text-dc-text-muted shrink-0 ml-1 transition-transform ${D ? "rotate-180" : ""}` })
1820
- ]
1821
- }
1822
- ),
1823
- D && /* @__PURE__ */ n("div", { className: "absolute z-30 left-0 right-0 mt-1 bg-dc-surface border border-dc-border rounded shadow-lg max-h-48 overflow-hidden", children: [
1824
- /* @__PURE__ */ e("div", { className: "p-1.5 border-b border-dc-border", children: /* @__PURE__ */ e(
1825
- "input",
1826
- {
1827
- type: "text",
1828
- value: G,
1829
- onChange: (C) => E(C.target.value),
1830
- placeholder: "Search...",
1831
- className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text",
1832
- autoFocus: !0
1833
- }
1834
- ) }),
1835
- /* @__PURE__ */ e("div", { className: "max-h-36 overflow-y-auto", children: p ? /* @__PURE__ */ e("div", { className: "px-2 py-2 text-xs text-dc-text-muted", children: "Loading..." }) : m ? /* @__PURE__ */ n("div", { className: "px-2 py-2 text-xs text-red-600", children: [
1836
- "Error: ",
1837
- m
1838
- ] }) : c.length === 0 ? /* @__PURE__ */ e("div", { className: "px-2 py-2 text-xs text-dc-text-muted", children: "No values found" }) : c.map((C, M) => {
1839
- const W = t.values?.includes(C);
1840
- return /* @__PURE__ */ n(
1841
- "button",
1842
- {
1843
- onClick: () => k(C),
1844
- className: `w-full text-left px-2 py-1.5 text-xs hover:bg-dc-surface-hover ${W ? "bg-dc-primary/10 text-dc-primary" : "text-dc-text"}`,
1845
- children: [
1846
- String(C),
1847
- W && /* @__PURE__ */ e("span", { className: "float-right", children: "✓" })
1848
- ]
1849
- },
1850
- `${C}-${M}`
1851
- );
1852
- }) })
1853
- ] })
1854
- ] })
1855
- ] }) : /* @__PURE__ */ e(
1856
- "input",
1857
- {
1858
- type: "text",
1859
- value: t.values?.[0] ?? "",
1860
- onChange: Z,
1861
- placeholder: "Enter value...",
1862
- className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text placeholder-dc-text-muted"
1863
- }
1864
- ) : /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted italic py-1", children: "No value required" });
1865
- return /* @__PURE__ */ n(
1866
- "div",
1867
- {
1868
- ref: P,
1869
- className: `bg-dc-surface border border-dc-border rounded-lg p-2 ${a > 0 ? "ml-3" : ""}`,
1870
- children: [
1871
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between mb-1.5", children: [
1872
- /* @__PURE__ */ n("div", { className: "flex items-center gap-1.5 min-w-0", children: [
1873
- /* @__PURE__ */ e(ee, { className: `w-3.5 h-3.5 ${ne} shrink-0` }),
1874
- /* @__PURE__ */ e("span", { className: "text-xs font-medium text-dc-text truncate", title: t.member, children: v })
1875
- ] }),
1876
- /* @__PURE__ */ e(
1877
- "button",
1878
- {
1879
- onClick: s,
1880
- className: "text-dc-text-muted hover:text-red-600 transition-colors shrink-0 p-0.5",
1881
- title: "Remove filter",
1882
- children: /* @__PURE__ */ e(Pe, { className: "w-3.5 h-3.5" })
1883
- }
1884
- )
1885
- ] }),
1886
- /* @__PURE__ */ n("div", { className: "relative mb-1.5", children: [
1887
- /* @__PURE__ */ n(
1888
- "button",
1889
- {
1890
- onClick: () => {
1891
- i(!1), g(!1), N(!u);
1892
- },
1893
- className: "w-full flex items-center justify-between text-left text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text hover:bg-dc-surface-hover",
1894
- children: [
1895
- /* @__PURE__ */ e("span", { className: "truncate", children: fe }),
1896
- /* @__PURE__ */ e(Re, { className: `w-3 h-3 text-dc-text-muted shrink-0 ml-1 transition-transform ${u ? "rotate-180" : ""}` })
1897
- ]
1898
- }
1899
- ),
1900
- u && /* @__PURE__ */ e("div", { className: "absolute z-30 left-0 right-0 mt-1 bg-dc-surface border border-dc-border rounded shadow-lg max-h-40 overflow-y-auto", children: O.map((C) => /* @__PURE__ */ e(
1901
- "button",
1902
- {
1903
- onClick: () => d(C.operator),
1904
- className: `w-full text-left px-2 py-1.5 text-xs hover:bg-dc-surface-hover ${C.operator === t.operator ? "bg-dc-primary/10 text-dc-primary" : "text-dc-text"}`,
1905
- children: C.label
1906
- },
1907
- C.operator
1908
- )) })
1909
- ] }),
1910
- oe()
1911
- ]
1912
- }
1913
- );
1914
- }
1915
- const fr = _("add"), xr = _("close");
1916
- function br(t) {
1917
- return "member" in t && typeof t.member == "string";
1918
- }
1919
- function pr(t) {
1920
- return "type" in t && (t.type === "and" || t.type === "or");
1921
- }
1922
- function Xe({
1923
- group: t,
1924
- schema: r,
1925
- onUpdate: s,
1926
- onRemove: l,
1927
- onAddFilter: a,
1928
- depth: u = 0,
1929
- hideRemoveButton: N = !1
1930
- }) {
1931
- const [D, i] = J(!1), b = ae(null);
1932
- U(() => {
1933
- const R = (x) => {
1934
- b.current && !b.current.contains(x.target) && i(!1);
1935
- };
1936
- return document.addEventListener("mousedown", R), () => document.removeEventListener("mousedown", R);
1937
- }, []);
1938
- const g = I(() => {
1939
- const R = t.type === "and" ? "or" : "and";
1940
- s({ ...t, type: R });
1941
- }, [t, s]), T = I((R, x) => {
1942
- const h = [...t.filters];
1943
- h[R] = x, s({ ...t, filters: h });
1944
- }, [t, s]), f = I((R) => {
1945
- const x = t.filters.filter((h, o) => o !== R);
1946
- x.length === 0 ? l() : x.length === 1 && u > 0 ? s({ ...t, filters: x }) : s({ ...t, filters: x });
1947
- }, [t, s, l, u]), S = I((R) => {
1948
- const x = { type: R, filters: [] };
1949
- s({ ...t, filters: [...t.filters, x] }), i(!1);
1950
- }, [t, s]), y = I(() => {
1951
- a([]), i(!1);
1952
- }, [a]), G = I((R) => (x = []) => {
1953
- a([R, ...x]);
1954
- }, [a]), E = () => u % 2 === 0 ? "border-dc-border" : "border-slate-300 dark:border-slate-600", P = () => t.type === "and" ? "bg-blue-50/50 dark:bg-blue-900/10" : "bg-amber-50/50 dark:bg-amber-900/10", j = t.filters.length, Q = j === 1 ? "condition" : "conditions";
1955
- return /* @__PURE__ */ n("div", { className: `border ${E()} rounded-lg ${P()} ${u > 0 ? "ml-3" : ""}`, children: [
1956
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between px-2 py-1.5 border-b border-dc-border/50", children: [
1957
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
1958
- /* @__PURE__ */ e(
1959
- "button",
1960
- {
1961
- onClick: g,
1962
- className: `px-2 py-0.5 text-xs font-semibold rounded transition-colors ${t.type === "and" ? "bg-blue-100 text-blue-700 hover:bg-blue-200 dark:bg-blue-800/50 dark:text-blue-300" : "bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-800/50 dark:text-amber-300"}`,
1963
- title: `Click to switch to ${t.type === "and" ? "OR" : "AND"}`,
1964
- children: t.type.toUpperCase()
1965
- }
1966
- ),
1967
- /* @__PURE__ */ n("span", { className: "text-xs text-dc-text-muted", children: [
1968
- j,
1969
- " ",
1970
- Q
1971
- ] })
1972
- ] }),
1973
- /* @__PURE__ */ n("div", { className: "flex items-center gap-1", children: [
1974
- /* @__PURE__ */ n("div", { className: "relative", ref: b, children: [
1975
- /* @__PURE__ */ e(
1976
- "button",
1977
- {
1978
- onClick: () => i(!D),
1979
- className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-hover rounded transition-colors",
1980
- title: "Add condition",
1981
- children: /* @__PURE__ */ e(fr, { className: "w-4 h-4" })
1982
- }
1983
- ),
1984
- D && /* @__PURE__ */ n("div", { className: "absolute right-0 mt-1 z-40 bg-dc-surface border border-dc-border rounded shadow-lg py-1 min-w-[120px]", children: [
1985
- /* @__PURE__ */ e(
1986
- "button",
1987
- {
1988
- onClick: y,
1989
- className: "w-full text-left px-3 py-1.5 text-xs text-dc-text hover:bg-dc-surface-hover",
1990
- children: "Add Filter"
1991
- }
1992
- ),
1993
- /* @__PURE__ */ e(
1994
- "button",
1995
- {
1996
- onClick: () => S("and"),
1997
- className: "w-full text-left px-3 py-1.5 text-xs text-dc-text hover:bg-dc-surface-hover",
1998
- children: "Add AND Group"
1999
- }
2000
- ),
2001
- /* @__PURE__ */ e(
2002
- "button",
2003
- {
2004
- onClick: () => S("or"),
2005
- className: "w-full text-left px-3 py-1.5 text-xs text-dc-text hover:bg-dc-surface-hover",
2006
- children: "Add OR Group"
2007
- }
2008
- )
2009
- ] })
2010
- ] }),
2011
- !N && /* @__PURE__ */ e(
2012
- "button",
2013
- {
2014
- onClick: l,
2015
- className: "p-1 text-dc-text-muted hover:text-red-600 transition-colors",
2016
- title: "Remove group",
2017
- children: /* @__PURE__ */ e(xr, { className: "w-4 h-4" })
2018
- }
2019
- )
2020
- ] })
2021
- ] }),
2022
- /* @__PURE__ */ e("div", { className: "p-2 space-y-2", children: t.filters.length === 0 ? /* @__PURE__ */ n("div", { className: "text-center py-3", children: [
2023
- /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-muted mb-1", children: "No conditions in this group" }),
2024
- /* @__PURE__ */ e(
2025
- "button",
2026
- {
2027
- onClick: () => a([]),
2028
- className: "text-xs text-dc-primary hover:underline",
2029
- children: "Add a filter"
2030
- }
2031
- )
2032
- ] }) : t.filters.map((R, x) => br(R) ? /* @__PURE__ */ e(
2033
- Ke,
2034
- {
2035
- filter: R,
2036
- schema: r,
2037
- onUpdate: (h) => T(x, h),
2038
- onRemove: () => f(x),
2039
- depth: u + 1
2040
- },
2041
- `filter-${x}`
2042
- ) : pr(R) ? /* @__PURE__ */ e(
2043
- Xe,
2044
- {
2045
- group: R,
2046
- schema: r,
2047
- onUpdate: (h) => T(x, h),
2048
- onRemove: () => f(x),
2049
- onAddFilter: G(x),
2050
- depth: u + 1
2051
- },
2052
- `group-${x}`
2053
- ) : null) })
2054
- ] });
2055
- }
2056
- const gr = _("add");
2057
- function Se(t) {
2058
- return "member" in t && typeof t.member == "string";
2059
- }
2060
- function xe(t) {
2061
- return "type" in t && (t.type === "and" || t.type === "or");
2062
- }
2063
- function Ue(t) {
2064
- let r = 0;
2065
- for (const s of t)
2066
- Se(s) ? r++ : xe(s) && (r += Ue(s.filters));
2067
- return r;
2068
- }
2069
- function et(t) {
2070
- const r = [];
2071
- for (const s of t)
2072
- Se(s) ? r.push(s.member) : xe(s) && r.push(...et(s.filters));
2073
- return r;
2074
- }
2075
- function tt(t, r, s) {
2076
- if (r.length === 0)
2077
- return t.length === 0 ? [s] : t.length === 1 && Se(t[0]) ? [{ type: "and", filters: [t[0], s] }] : t.length === 1 && xe(t[0]) ? [{
2078
- ...t[0],
2079
- filters: [...t[0].filters, s]
2080
- }] : [{ type: "and", filters: [...t, s] }];
2081
- const [l, ...a] = r, u = [...t], N = u[l];
2082
- return xe(N) && (a.length === 0 ? u[l] = {
2083
- ...N,
2084
- filters: [...N.filters, s]
2085
- } : u[l] = {
2086
- ...N,
2087
- filters: tt(N.filters, a, s)
2088
- }), u;
2089
- }
2090
- function vr({
2091
- filters: t,
2092
- schema: r,
2093
- onFiltersChange: s,
2094
- onFieldDropped: l
2095
- }) {
2096
- const [a, u] = J(!1), [N, D] = J(!1), i = ae([]), b = Ue(t), g = I((x) => {
2097
- x.preventDefault(), x.stopPropagation(), D(!0);
2098
- }, []), T = I((x) => {
2099
- x.preventDefault(), x.stopPropagation(), D(!1);
2100
- }, []), f = I((x) => {
2101
- x.preventDefault(), x.stopPropagation(), D(!1);
2102
- try {
2103
- const h = JSON.parse(x.dataTransfer.getData("text/plain"));
2104
- h.field && l && l(h.field);
2105
- } catch {
2106
- }
2107
- }, [l]), S = et(t), y = I(
2108
- (x, h, o) => {
2109
- const v = x.type === "time", A = v ? "inDateRange" : "equals", O = {
2110
- member: x.name,
2111
- operator: A,
2112
- values: []
2113
- };
2114
- v && A === "inDateRange" && (O.dateRange = ve("this_month"));
2115
- const V = tt(t, i.current, O);
2116
- s(V), u(!1), i.current = [];
2117
- },
2118
- [t, s]
2119
- ), G = I(
2120
- (x, h) => {
2121
- const o = [...t];
2122
- o[x] = h, s(o);
2123
- },
2124
- [t, s]
2125
- ), E = I(
2126
- (x) => {
2127
- const h = t.filter((o, v) => v !== x);
2128
- if (h.length === 1 && xe(h[0])) {
2129
- const o = h[0];
2130
- if (o.filters.length === 1) {
2131
- s([o.filters[0]]);
2132
- return;
2133
- }
2134
- }
2135
- s(h);
2136
- },
2137
- [t, s]
2138
- ), P = I(() => {
2139
- s([]);
2140
- }, [s]), j = I(() => {
2141
- i.current = [], u(!0);
2142
- }, []), Q = I((x) => (h = []) => {
2143
- i.current = [...x, ...h], u(!0);
2144
- }, []), R = (x, h, o = []) => {
2145
- const v = [...o, h];
2146
- return Se(x) ? /* @__PURE__ */ e(
2147
- Ke,
2148
- {
2149
- filter: x,
2150
- schema: r,
2151
- onUpdate: (A) => G(h, A),
2152
- onRemove: () => E(h)
2153
- },
2154
- `filter-${v.join("-")}`
2155
- ) : xe(x) ? /* @__PURE__ */ e(
2156
- Xe,
2157
- {
2158
- group: x,
2159
- schema: r,
2160
- onUpdate: (A) => G(h, A),
2161
- onRemove: () => E(h),
2162
- onAddFilter: Q(v),
2163
- hideRemoveButton: t.length === 1
2164
- },
2165
- `group-${v.join("-")}`
2166
- ) : null;
2167
- };
2168
- return /* @__PURE__ */ n(
2169
- "div",
2170
- {
2171
- onDragOver: l ? g : void 0,
2172
- onDragLeave: l ? T : void 0,
2173
- onDrop: l ? f : void 0,
2174
- className: `transition-colors rounded-lg ${N ? "bg-dc-primary/10 ring-2 ring-dc-primary ring-dashed" : ""}`,
2175
- children: [
2176
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between mb-3", children: [
2177
- /* @__PURE__ */ n("h3", { className: "text-sm font-semibold text-dc-text", children: [
2178
- "Filter",
2179
- b > 0 && /* @__PURE__ */ n("span", { className: "ml-1.5 text-xs font-normal text-dc-text-muted", children: [
2180
- "(",
2181
- b,
2182
- ")"
2183
- ] })
2184
- ] }),
2185
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
2186
- b > 0 && /* @__PURE__ */ e(
2187
- "button",
2188
- {
2189
- onClick: P,
2190
- className: "text-xs text-dc-text-muted hover:text-red-600 underline",
2191
- children: "Clear all"
2192
- }
2193
- ),
2194
- /* @__PURE__ */ e(
2195
- "button",
2196
- {
2197
- onClick: j,
2198
- className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-secondary rounded transition-colors",
2199
- title: "Add filter",
2200
- children: /* @__PURE__ */ e(gr, { className: "w-5 h-5" })
2201
- }
2202
- )
2203
- ] })
2204
- ] }),
2205
- t.length === 0 ? /* @__PURE__ */ e("p", { className: `text-sm ${N ? "text-dc-primary" : "text-dc-text-muted"}`, children: N ? "Drop to add filter" : "No filters applied" }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: t.map((x, h) => R(x, h)) }),
2206
- /* @__PURE__ */ e(
2207
- Ye,
2208
- {
2209
- isOpen: a,
2210
- onClose: () => {
2211
- u(!1), i.current = [];
2212
- },
2213
- onSelect: y,
2214
- mode: "filter",
2215
- schema: r,
2216
- selectedFields: S
2217
- }
2218
- )
2219
- ]
2220
- }
2221
- );
2222
- }
2223
- const yr = _("close"), Nr = _("dimension"), wr = _("timeDimension"), kr = _("measure");
2224
- function Dr({
2225
- config: t,
2226
- fields: r,
2227
- onDrop: s,
2228
- onRemove: l,
2229
- onDragStart: a,
2230
- onDragEnd: u,
2231
- onDragOver: N,
2232
- onReorder: D,
2233
- draggedItem: i,
2234
- getFieldMeta: b
2235
- }) {
2236
- const { key: g, label: T, description: f, mandatory: S, maxItems: y, emptyText: G } = t, [E, P] = J(null), [j, Q] = J(!1), [R, x] = J(!1), h = () => {
2237
- let m = r.length;
2238
- return i && i.fromAxis === g && (m = Math.max(0, r.length - 1)), !y || m < y;
2239
- }, o = () => {
2240
- let m = r.length;
2241
- return i && i.fromAxis === g && (m = Math.max(0, r.length - 1)), y && m >= y;
2242
- }, v = h(), A = o();
2243
- _e.useEffect(() => {
2244
- const m = () => {
2245
- P(null), Q(!1), x(!1);
2246
- };
2247
- return document.addEventListener("dragend", m), () => {
2248
- document.removeEventListener("dragend", m);
2249
- };
2250
- }, []), _e.useEffect(() => {
2251
- i ? i.fromAxis !== g ? (x(!1), P(null)) : i.fromAxis === g && i.fromIndex !== void 0 && Q(!1) : (P(null), Q(!1), x(!1));
2252
- }, [i, g]);
2253
- const O = (m, w) => {
2254
- i && i.fromAxis === g && i.fromIndex !== void 0 && (m.preventDefault(), m.stopPropagation(), P(w), x(!0));
2255
- }, V = () => {
2256
- P(null);
2257
- }, z = (m, w) => {
2258
- if (m.preventDefault(), m.stopPropagation(), P(null), x(!1), i && i.fromAxis === g && i.fromIndex !== void 0 && D) {
2259
- D(i.fromIndex, w, g);
2260
- return;
2261
- }
2262
- try {
2263
- const d = JSON.parse(m.dataTransfer.getData("text/plain"));
2264
- d.fromAxis === g && D && d.fromIndex !== void 0 && D(d.fromIndex, w, g);
2265
- } catch {
2266
- }
2267
- }, c = (m) => {
2268
- const w = m.split("."), d = w[0] || m, k = w[1] || m;
2269
- return {
2270
- title: k,
2271
- shortTitle: k,
2272
- cubeName: d,
2273
- type: "dimension"
2274
- // Default assumption
2275
- };
2276
- }, p = (m) => {
2277
- if (m.type === "measure") {
2278
- const w = ye(m.measureType || "count") || kr;
2279
- return /* @__PURE__ */ e("span", { className: "w-6 h-6 flex items-center justify-center rounded bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 flex-shrink-0", children: /* @__PURE__ */ e(w, { className: "w-4 h-4" }) });
2280
- } else return m.type === "timeDimension" ? /* @__PURE__ */ e(wr, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }) : /* @__PURE__ */ e(Nr, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" });
2281
- };
2282
- return /* @__PURE__ */ n("div", { className: "mb-3", children: [
2283
- /* @__PURE__ */ n("div", { className: "mb-2", children: [
2284
- /* @__PURE__ */ n("h4", { className: "text-sm font-medium text-dc-text flex items-center", children: [
2285
- T,
2286
- S && /* @__PURE__ */ e("span", { className: "text-red-500 ml-1", children: "*" })
2287
- ] }),
2288
- f && /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted mt-0.5", children: f })
2289
- ] }),
2290
- /* @__PURE__ */ e(
2291
- "div",
2292
- {
2293
- "data-axis-container": g,
2294
- className: `min-h-[48px] border-2 border-dashed rounded-lg p-2 transition-all duration-300 ${j && (v || y === 1) || R ? "shadow-lg border-solid animate-pulse" : A ? "bg-dc-surface-secondary" : "bg-dc-surface-secondary hover:bg-dc-surface-hover"}`,
2295
- style: {
2296
- borderColor: j && (v || y === 1) || R ? "var(--dc-primary)" : "var(--dc-border)",
2297
- backgroundColor: j && (v || y === 1) || R ? "rgba(var(--dc-primary-rgb), 0.1)" : void 0
2298
- },
2299
- onDragOver: (m) => {
2300
- if (i && i.fromAxis === g && i.fromIndex !== void 0)
2301
- return;
2302
- v || y === 1 ? (Q(!0), N(m)) : (m.preventDefault(), m.dataTransfer.dropEffect = "none");
2303
- },
2304
- onDragLeave: (m) => {
2305
- const w = m.currentTarget.getBoundingClientRect(), d = m.clientX < w.left || m.clientX > w.right || m.clientY < w.top || m.clientY > w.bottom, k = m.relatedTarget, B = k && !m.currentTarget.contains(k);
2306
- (d || B || m.currentTarget === m.target) && (Q(!1), x(!1));
2307
- },
2308
- onDrop: (m) => {
2309
- if (i && i.fromAxis === g && i.fromIndex !== void 0)
2310
- return;
2311
- v || y === 1 ? s(m, g) : m.preventDefault(), Q(!1), x(!1);
2312
- },
2313
- children: r.length === 0 ? /* @__PURE__ */ e("div", { className: "text-sm text-dc-text-muted text-center py-2", children: A ? "Maximum items reached" : G || "Drop fields here" }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: r.map((m, w) => {
2314
- const d = b ? b(m) : c(m), k = E === w, B = i && i.field === m && i.fromAxis === g;
2315
- return /* @__PURE__ */ n("div", { className: "relative ", children: [
2316
- k && /* @__PURE__ */ e(
2317
- "div",
2318
- {
2319
- className: "absolute -top-1 left-0 right-0 h-0.5 rounded-full z-10",
2320
- style: { backgroundColor: "var(--dc-primary)" }
2321
- }
2322
- ),
2323
- /* @__PURE__ */ n(
2324
- "div",
2325
- {
2326
- draggable: !0,
2327
- onDragStart: (Z) => {
2328
- a(Z, m, g, w);
2329
- },
2330
- onDragEnd: u,
2331
- onDragOver: (Z) => O(Z, w),
2332
- onDragLeave: V,
2333
- onDrop: (Z) => z(Z, w),
2334
- className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg group hover:bg-dc-surface-tertiary transition-colors cursor-move ${B ? "opacity-50 cursor-grabbing" : ""} ${k ? "mt-1" : ""}`,
2335
- children: [
2336
- p(d),
2337
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
2338
- /* @__PURE__ */ e("div", { className: "text-sm text-dc-text truncate", title: m, children: d.shortTitle || d.title || m.split(".").pop() }),
2339
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted truncate", children: d.cubeName })
2340
- ] }),
2341
- /* @__PURE__ */ e(
2342
- "button",
2343
- {
2344
- type: "button",
2345
- onClick: () => l(m, g),
2346
- className: "p-1 text-dc-text-muted hover:text-dc-danger opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",
2347
- title: `Remove from ${T}`,
2348
- children: /* @__PURE__ */ e(yr, { className: "w-4 h-4" })
2349
- }
2350
- )
2351
- ]
2352
- }
2353
- )
2354
- ] }, `${m}-${w}`);
2355
- }) })
2356
- }
2357
- ),
2358
- S && r.length === 0 && /* @__PURE__ */ e("div", { className: "text-xs text-red-500 mt-1", children: "This field is required" })
2359
- ] });
2360
- }
2361
- const Tr = _("measure"), Cr = _("dimension"), Sr = _("timeDimension");
2362
- function Ar({
2363
- chartType: t,
2364
- chartConfig: r,
2365
- displayConfig: s,
2366
- metrics: l,
2367
- breakdowns: a,
2368
- colorPalette: u,
2369
- schema: N,
2370
- chartAvailability: D,
2371
- onChartTypeChange: i,
2372
- onChartConfigChange: b,
2373
- onDisplayConfigChange: g
2374
- }) {
2375
- const [T, f] = J(null), S = H(
2376
- () => ({
2377
- measures: l.map((c) => c.field),
2378
- dimensions: a.filter((c) => !c.isTimeDimension).map((c) => c.field),
2379
- timeDimensions: a.filter((c) => c.isTimeDimension).map((c) => c.field)
2380
- }),
2381
- [l, a]
2382
- ), y = H(
2383
- () => yt(t, bt),
2384
- [t]
2385
- ), G = y.skipQuery === !0, E = (c) => {
2386
- const p = r[c];
2387
- return Array.isArray(p) ? p : typeof p == "string" ? [p] : [];
2388
- };
2389
- U(() => {
2390
- const c = [
2391
- ...S.dimensions,
2392
- ...S.timeDimensions,
2393
- ...S.measures
2394
- ];
2395
- let p = !1;
2396
- const m = { ...r };
2397
- y.dropZones.forEach((w) => {
2398
- const d = E(w.key), k = d.filter((B) => c.includes(B));
2399
- k.length !== d.length && (p = !0, k.length === 0 ? delete m[w.key] : w.maxItems === 1 ? m[w.key] = k[0] : m[w.key] = k);
2400
- }), p && b(m);
2401
- }, [S, r, y.dropZones, b]);
2402
- const P = (c) => S.measures.includes(c) ? "measure" : S.timeDimensions.includes(c) ? "timeDimension" : "dimension", j = (c) => {
2403
- if (!N?.cubes) return null;
2404
- const [p] = c.split("."), m = N.cubes.find((k) => k.name === p);
2405
- if (!m) return null;
2406
- const w = m.measures?.find((k) => k.name === c);
2407
- if (w) return { ...w, fieldType: "measure" };
2408
- const d = m.dimensions?.find((k) => k.name === c);
2409
- return d ? { ...d, fieldType: d.type === "time" ? "timeDimension" : "dimension" } : null;
2410
- }, Q = (c) => {
2411
- const p = P(c), m = c.split("."), w = m[0] || c, d = m[1] || c, k = j(c), B = a.find((Z) => Z.field === c);
2412
- return k ? {
2413
- title: k.title || d,
2414
- shortTitle: k.shortTitle || k.title || d,
2415
- cubeName: w,
2416
- type: k.fieldType,
2417
- measureType: k.fieldType === "measure" ? k.type : void 0
2418
- } : B ? {
2419
- title: d,
2420
- shortTitle: d,
2421
- cubeName: w,
2422
- type: B.isTimeDimension ? "timeDimension" : "dimension"
2423
- } : {
2424
- title: d,
2425
- shortTitle: d,
2426
- cubeName: w,
2427
- type: p
2428
- };
2429
- }, R = (c, p, m, w) => {
2430
- c.dataTransfer.setData("text/plain", JSON.stringify({ field: p, fromAxis: m, fromIndex: w })), f({ field: p, fromAxis: m, fromIndex: w });
2431
- }, x = (c) => {
2432
- c.preventDefault();
2433
- }, h = () => {
2434
- f(null);
2435
- }, o = (c, p) => {
2436
- c.preventDefault();
2437
- const m = JSON.parse(c.dataTransfer.getData("text/plain")), { field: w, fromAxis: d } = m, k = { ...r };
2438
- if (d !== "available" && d !== p) {
2439
- const X = k[d];
2440
- if (Array.isArray(X)) {
2441
- const Y = X.filter((re) => re !== w);
2442
- Y.length === 0 ? delete k[d] : k[d] = Y;
2443
- } else X === w && delete k[d];
2444
- }
2445
- const B = k[p];
2446
- y.dropZones.find((X) => X.key === p)?.maxItems === 1 ? k[p] = w : Array.isArray(B) ? B.includes(w) || (k[p] = [...B, w]) : k[p] = [w], f(null), b(k);
2447
- }, v = (c, p) => {
2448
- const m = { ...r }, w = m[p];
2449
- if (Array.isArray(w)) {
2450
- const d = w.filter((k) => k !== c);
2451
- d.length === 0 ? delete m[p] : m[p] = d;
2452
- } else w === c && delete m[p];
2453
- b(m);
2454
- }, A = (c, p, m) => {
2455
- const w = { ...r }, d = w[m];
2456
- if (Array.isArray(d) && d.length > 1 && c !== p) {
2457
- const k = [...d], [B] = k.splice(c, 1);
2458
- k.splice(p, 0, B), w[m] = k, f(null), b(w);
2459
- }
2460
- }, V = (() => {
2461
- const c = /* @__PURE__ */ new Set();
2462
- return y.dropZones.forEach((p) => {
2463
- E(p.key).forEach((m) => c.add(m));
2464
- }), T && T.fromAxis !== "available" && c.add(T.field), {
2465
- dimensions: S.dimensions.filter((p) => !c.has(p)),
2466
- timeDimensions: S.timeDimensions.filter((p) => !c.has(p)),
2467
- measures: S.measures.filter((p) => !c.has(p))
2468
- };
2469
- })(), z = V.dimensions.length > 0 || V.timeDimensions.length > 0 || V.measures.length > 0;
2470
- return /* @__PURE__ */ n("div", { className: "space-y-6", children: [
2471
- /* @__PURE__ */ n("div", { children: [
2472
- /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-dc-text mb-2", children: "Chart Type" }),
2473
- /* @__PURE__ */ e(
2474
- pt,
2475
- {
2476
- selectedType: t,
2477
- onTypeChange: i,
2478
- availability: D,
2479
- compact: !0
2480
- }
2481
- )
2482
- ] }),
2483
- !G && y.dropZones.length > 0 && /* @__PURE__ */ n("div", { children: [
2484
- /* @__PURE__ */ e("h4", { className: "text-xs font-semibold text-dc-text-secondary mb-2", children: "Chart Configuration" }),
2485
- /* @__PURE__ */ e("div", { className: "space-y-1", children: y.dropZones.map((c) => /* @__PURE__ */ e(
2486
- Dr,
2487
- {
2488
- config: c,
2489
- fields: E(c.key),
2490
- onDrop: o,
2491
- onRemove: v,
2492
- onDragStart: R,
2493
- onDragEnd: h,
2494
- onDragOver: x,
2495
- onReorder: A,
2496
- draggedItem: T,
2497
- getFieldMeta: Q
2498
- },
2499
- c.key
2500
- )) })
2501
- ] }),
2502
- !G && z && /* @__PURE__ */ n("div", { children: [
2503
- /* @__PURE__ */ n("div", { className: "mb-2", children: [
2504
- /* @__PURE__ */ e("h4", { className: "text-sm font-medium text-dc-text", children: "Unassigned Fields" }),
2505
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted mt-0.5", children: "Drag fields to chart axes above" })
2506
- ] }),
2507
- /* @__PURE__ */ e("div", { className: "border-2 border-dashed border-dc-border rounded-lg p-2 bg-dc-surface-secondary", children: /* @__PURE__ */ n("div", { className: "space-y-2", children: [
2508
- V.measures.map((c) => {
2509
- const p = Q(c), m = T && T.field === c && T.fromAxis === "available", w = ye(p.measureType || "count") || Tr;
2510
- return /* @__PURE__ */ n(
2511
- "div",
2512
- {
2513
- draggable: !0,
2514
- onDragStart: (d) => R(d, c, "available"),
2515
- onDragEnd: h,
2516
- className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg hover:bg-dc-surface-tertiary transition-colors cursor-move ${m ? "opacity-50 cursor-grabbing" : ""}`,
2517
- title: c,
2518
- children: [
2519
- /* @__PURE__ */ e("span", { className: "w-6 h-6 flex items-center justify-center rounded bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 flex-shrink-0", children: /* @__PURE__ */ e(w, { className: "w-4 h-4" }) }),
2520
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
2521
- /* @__PURE__ */ e("div", { className: "text-sm text-dc-text truncate", children: p.shortTitle }),
2522
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted truncate", children: p.cubeName })
2523
- ] })
2524
- ]
2525
- },
2526
- c
2527
- );
2528
- }),
2529
- V.dimensions.map((c) => {
2530
- const p = Q(c), m = T && T.field === c && T.fromAxis === "available";
2531
- return /* @__PURE__ */ n(
2532
- "div",
2533
- {
2534
- draggable: !0,
2535
- onDragStart: (w) => R(w, c, "available"),
2536
- onDragEnd: h,
2537
- className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg hover:bg-dc-surface-tertiary transition-colors cursor-move ${m ? "opacity-50 cursor-grabbing" : ""}`,
2538
- title: c,
2539
- children: [
2540
- /* @__PURE__ */ e(Cr, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }),
2541
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
2542
- /* @__PURE__ */ e("div", { className: "text-sm text-dc-text truncate", children: p.shortTitle }),
2543
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted truncate", children: p.cubeName })
2544
- ] })
2545
- ]
2546
- },
2547
- c
2548
- );
2549
- }),
2550
- V.timeDimensions.map((c) => {
2551
- const p = Q(c), m = T && T.field === c && T.fromAxis === "available";
2552
- return /* @__PURE__ */ n(
2553
- "div",
2554
- {
2555
- draggable: !0,
2556
- onDragStart: (w) => R(w, c, "available"),
2557
- onDragEnd: h,
2558
- className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg hover:bg-dc-surface-tertiary transition-colors cursor-move ${m ? "opacity-50 cursor-grabbing" : ""}`,
2559
- title: c,
2560
- children: [
2561
- /* @__PURE__ */ e(Sr, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }),
2562
- /* @__PURE__ */ n("div", { className: "flex-1 min-w-0", children: [
2563
- /* @__PURE__ */ e("div", { className: "text-sm text-dc-text truncate", children: p.shortTitle }),
2564
- /* @__PURE__ */ e("div", { className: "text-xs text-dc-text-muted truncate", children: p.cubeName })
2565
- ] })
2566
- ]
2567
- },
2568
- c
2569
- );
2570
- })
2571
- ] }) })
2572
- ] }),
2573
- (y.displayOptions && y.displayOptions.length > 0 || y.displayOptionsConfig && y.displayOptionsConfig.length > 0) && /* @__PURE__ */ n("div", { children: [
2574
- /* @__PURE__ */ e("h4", { className: "text-xs font-semibold text-dc-text-secondary mb-2", children: "Display Options" }),
2575
- /* @__PURE__ */ n("div", { className: "space-y-2", children: [
2576
- y.displayOptions?.includes("showLegend") && /* @__PURE__ */ n("label", { className: "flex items-center space-x-2", children: [
2577
- /* @__PURE__ */ e(
2578
- "input",
2579
- {
2580
- type: "checkbox",
2581
- checked: s.showLegend ?? !0,
2582
- onChange: (c) => g({
2583
- ...s,
2584
- showLegend: c.target.checked
2585
- }),
2586
- className: "rounded border-dc-border focus:ring-blue-500",
2587
- style: { color: "var(--dc-primary)" }
2588
- }
2589
- ),
2590
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text", children: "Show Legend" })
2591
- ] }),
2592
- y.displayOptions?.includes("showGrid") && /* @__PURE__ */ n("label", { className: "flex items-center space-x-2", children: [
2593
- /* @__PURE__ */ e(
2594
- "input",
2595
- {
2596
- type: "checkbox",
2597
- checked: s.showGrid ?? !0,
2598
- onChange: (c) => g({
2599
- ...s,
2600
- showGrid: c.target.checked
2601
- }),
2602
- className: "rounded border-dc-border focus:ring-blue-500",
2603
- style: { color: "var(--dc-primary)" }
2604
- }
2605
- ),
2606
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text", children: "Show Grid" })
2607
- ] }),
2608
- y.displayOptions?.includes("showTooltip") && /* @__PURE__ */ n("label", { className: "flex items-center space-x-2", children: [
2609
- /* @__PURE__ */ e(
2610
- "input",
2611
- {
2612
- type: "checkbox",
2613
- checked: s.showTooltip ?? !0,
2614
- onChange: (c) => g({
2615
- ...s,
2616
- showTooltip: c.target.checked
2617
- }),
2618
- className: "rounded border-dc-border focus:ring-blue-500",
2619
- style: { color: "var(--dc-primary)" }
2620
- }
2621
- ),
2622
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text", children: "Show Tooltip" })
2623
- ] }),
2624
- y.displayOptions?.includes("stacked") && /* @__PURE__ */ n("label", { className: "flex items-center space-x-2", children: [
2625
- /* @__PURE__ */ e(
2626
- "input",
2627
- {
2628
- type: "checkbox",
2629
- checked: s.stacked ?? !1,
2630
- onChange: (c) => g({
2631
- ...s,
2632
- stacked: c.target.checked
2633
- }),
2634
- className: "rounded border-dc-border focus:ring-blue-500",
2635
- style: { color: "var(--dc-primary)" }
2636
- }
2637
- ),
2638
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text", children: "Stacked" })
2639
- ] }),
2640
- y.displayOptions?.includes("hideHeader") && /* @__PURE__ */ n("label", { className: "flex items-center space-x-2", children: [
2641
- /* @__PURE__ */ e(
2642
- "input",
2643
- {
2644
- type: "checkbox",
2645
- checked: s.hideHeader ?? !1,
2646
- onChange: (c) => g({
2647
- ...s,
2648
- hideHeader: c.target.checked
2649
- }),
2650
- className: "rounded border-dc-border focus:ring-blue-500",
2651
- style: { color: "var(--dc-primary)" }
2652
- }
2653
- ),
2654
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text", children: "Hide Header" })
2655
- ] }),
2656
- y.displayOptionsConfig?.map((c) => /* @__PURE__ */ n("div", { className: "space-y-1", children: [
2657
- c.type === "boolean" && /* @__PURE__ */ n("label", { className: "flex items-center space-x-2", children: [
2658
- /* @__PURE__ */ e(
2659
- "input",
2660
- {
2661
- type: "checkbox",
2662
- checked: s[c.key] ?? c.defaultValue ?? !1,
2663
- onChange: (p) => g({
2664
- ...s,
2665
- [c.key]: p.target.checked
2666
- }),
2667
- className: "rounded border-dc-border focus:ring-blue-500",
2668
- style: { color: "var(--dc-primary)" }
2669
- }
2670
- ),
2671
- /* @__PURE__ */ e("span", { className: "text-sm text-dc-text", children: c.label })
2672
- ] }),
2673
- c.type === "string" && /* @__PURE__ */ n("div", { className: "space-y-1", children: [
2674
- /* @__PURE__ */ n("label", { className: "text-sm text-dc-text-secondary", children: [
2675
- c.label,
2676
- c.key === "content" && /* @__PURE__ */ e("span", { className: "text-xs text-dc-text-muted ml-1", children: "(only headers, lists and links)" })
2677
- ] }),
2678
- c.key === "content" ? /* @__PURE__ */ e(
2679
- "textarea",
2680
- {
2681
- value: s[c.key] ?? c.defaultValue ?? "",
2682
- onChange: (p) => g({
2683
- ...s,
2684
- [c.key]: p.target.value
2685
- }),
2686
- placeholder: c.placeholder,
2687
- rows: 8,
2688
- className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 font-mono resize-y bg-dc-surface text-dc-text"
2689
- }
2690
- ) : /* @__PURE__ */ e(
2691
- "input",
2692
- {
2693
- type: "text",
2694
- value: s[c.key] ?? c.defaultValue ?? "",
2695
- onChange: (p) => g({
2696
- ...s,
2697
- [c.key]: p.target.value
2698
- }),
2699
- placeholder: c.placeholder,
2700
- className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text"
2701
- }
2702
- ),
2703
- c.description && /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-muted", children: c.description })
2704
- ] }),
2705
- c.type === "paletteColor" && /* @__PURE__ */ n("div", { className: "space-y-1", children: [
2706
- /* @__PURE__ */ e("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2707
- /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-2", children: u?.colors.map((p, m) => {
2708
- const w = (s[c.key] ?? c.defaultValue ?? 0) === m;
2709
- return /* @__PURE__ */ e(
2710
- "button",
2711
- {
2712
- type: "button",
2713
- onClick: () => g({
2714
- ...s,
2715
- [c.key]: m
2716
- }),
2717
- className: `w-8 h-8 rounded border-2 transition-all duration-200 hover:scale-110 focus:outline-hidden focus:ring-2 focus:ring-blue-500 focus:ring-offset-1 ${w ? "ring-2 ring-offset-1 scale-110" : "hover:border-dc-text-muted"}`,
2718
- style: {
2719
- backgroundColor: p,
2720
- borderColor: w ? "var(--dc-primary)" : "var(--dc-border)"
2721
- },
2722
- title: `Color ${m + 1}: ${p}`
2723
- },
2724
- m
2725
- );
2726
- }) || [
2727
- // Fallback if no palette available
2728
- /* @__PURE__ */ e(
2729
- "button",
2730
- {
2731
- type: "button",
2732
- onClick: () => g({
2733
- ...s,
2734
- [c.key]: 0
2735
- }),
2736
- className: "w-8 h-8 rounded-sm border-2 ring-2 ring-offset-1",
2737
- style: {
2738
- backgroundColor: "#8884d8",
2739
- borderColor: "var(--dc-primary)",
2740
- boxShadow: "0 0 0 2px var(--dc-primary)"
2741
- },
2742
- title: "Default Color"
2743
- },
2744
- 0
2745
- )
2746
- ] }),
2747
- c.description && /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-muted", children: c.description })
2748
- ] }),
2749
- c.type === "number" && /* @__PURE__ */ n("div", { className: "space-y-1", children: [
2750
- /* @__PURE__ */ e("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2751
- /* @__PURE__ */ e(
2752
- "input",
2753
- {
2754
- type: "number",
2755
- value: s[c.key] ?? c.defaultValue ?? 0,
2756
- onChange: (p) => g({
2757
- ...s,
2758
- [c.key]: p.target.value === "" ? void 0 : Number(p.target.value)
2759
- }),
2760
- placeholder: c.placeholder,
2761
- min: c.min,
2762
- max: c.max,
2763
- step: c.step,
2764
- className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text"
2765
- }
2766
- ),
2767
- c.description && /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-muted", children: c.description })
2768
- ] }),
2769
- c.type === "select" && /* @__PURE__ */ n("div", { className: "space-y-1", children: [
2770
- /* @__PURE__ */ e("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2771
- /* @__PURE__ */ e(
2772
- "select",
2773
- {
2774
- value: s[c.key] ?? c.defaultValue ?? "",
2775
- onChange: (p) => g({
2776
- ...s,
2777
- [c.key]: p.target.value
2778
- }),
2779
- className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text",
2780
- children: c.options?.map((p) => /* @__PURE__ */ e("option", { value: p.value, children: p.label }, p.value))
2781
- }
2782
- ),
2783
- c.description && /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-muted", children: c.description })
2784
- ] }),
2785
- c.type === "color" && /* @__PURE__ */ n("div", { className: "space-y-1", children: [
2786
- /* @__PURE__ */ e("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2787
- /* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
2788
- /* @__PURE__ */ e(
2789
- "input",
2790
- {
2791
- type: "color",
2792
- value: s[c.key] ?? c.defaultValue ?? "#8884d8",
2793
- onChange: (p) => g({
2794
- ...s,
2795
- [c.key]: p.target.value
2796
- }),
2797
- className: "w-12 h-8 border border-dc-border rounded-sm cursor-pointer"
2798
- }
2799
- ),
2800
- /* @__PURE__ */ e(
2801
- "input",
2802
- {
2803
- type: "text",
2804
- value: s[c.key] ?? c.defaultValue ?? "#8884d8",
2805
- onChange: (p) => g({
2806
- ...s,
2807
- [c.key]: p.target.value
2808
- }),
2809
- placeholder: c.placeholder || "#8884d8",
2810
- className: "flex-1 px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text"
2811
- }
2812
- )
2813
- ] }),
2814
- c.description && /* @__PURE__ */ e("p", { className: "text-xs text-dc-text-muted", children: c.description })
2815
- ] })
2816
- ] }, c.key))
2817
- ] })
2818
- ] }),
2819
- !G && S.measures.length === 0 && S.dimensions.length === 0 && S.timeDimensions.length === 0 && /* @__PURE__ */ e("div", { className: "text-center text-dc-text-muted text-sm py-4", children: /* @__PURE__ */ e("p", { children: "Add metrics and breakdowns in the Query tab to configure your chart." }) })
2820
- ] });
2821
- }
2822
- const Fr = ue(function({
2823
- metrics: r,
2824
- breakdowns: s,
2825
- filters: l,
2826
- schema: a,
2827
- activeTab: u,
2828
- onActiveTabChange: N,
2829
- onAddMetric: D,
2830
- onRemoveMetric: i,
2831
- onReorderMetrics: b,
2832
- onAddBreakdown: g,
2833
- onRemoveBreakdown: T,
2834
- onBreakdownGranularityChange: f,
2835
- onReorderBreakdowns: S,
2836
- onFiltersChange: y,
2837
- onDropFieldToFilter: G,
2838
- // Sorting
2839
- order: E,
2840
- onOrderChange: P,
2841
- // Chart configuration
2842
- chartType: j,
2843
- chartConfig: Q,
2844
- displayConfig: R,
2845
- chartAvailability: x,
2846
- onChartTypeChange: h,
2847
- onChartConfigChange: o,
2848
- onDisplayConfigChange: v
2849
- }) {
2850
- return U(() => {
2851
- r.length === 0 && u === "chart" && N("query");
2852
- }, [r.length, u, N]), /* @__PURE__ */ n("div", { className: "h-full flex flex-col bg-dc-surface", children: [
2853
- /* @__PURE__ */ n("div", { className: "flex border-b border-dc-border flex-shrink-0", children: [
2854
- /* @__PURE__ */ e(
2855
- "button",
2856
- {
2857
- onClick: () => N("query"),
2858
- className: `flex-1 px-4 py-3 text-sm font-medium transition-colors ${u === "query" ? "text-dc-primary border-b-2 border-dc-primary" : "text-dc-text-secondary hover:text-dc-text"}`,
2859
- children: "Query"
2860
- }
2861
- ),
2862
- /* @__PURE__ */ e(
2863
- "button",
2864
- {
2865
- onClick: () => r.length > 0 && N("chart"),
2866
- disabled: r.length === 0,
2867
- className: `flex-1 px-4 py-3 text-sm font-medium transition-colors ${u === "chart" ? "text-dc-primary border-b-2 border-dc-primary" : r.length === 0 ? "text-dc-text-muted cursor-not-allowed opacity-50" : "text-dc-text-secondary hover:text-dc-text"}`,
2868
- title: r.length === 0 ? "Add metrics to configure chart" : "Chart configuration",
2869
- children: "Chart"
2870
- }
2871
- )
2872
- ] }),
2873
- /* @__PURE__ */ e("div", { className: "flex-1 overflow-auto p-4", children: u === "query" ? /* @__PURE__ */ n("div", { className: "space-y-6", children: [
2874
- /* @__PURE__ */ e(
2875
- nr,
2876
- {
2877
- metrics: r,
2878
- schema: a,
2879
- onAdd: D,
2880
- onRemove: i,
2881
- order: E,
2882
- onOrderChange: P,
2883
- onReorder: b
2884
- }
2885
- ),
2886
- /* @__PURE__ */ e(
2887
- or,
2888
- {
2889
- breakdowns: s,
2890
- schema: a,
2891
- onAdd: g,
2892
- onRemove: T,
2893
- onGranularityChange: f,
2894
- order: E,
2895
- onOrderChange: P,
2896
- onReorder: S
2897
- }
2898
- ),
2899
- /* @__PURE__ */ e(
2900
- vr,
2901
- {
2902
- filters: l,
2903
- schema: a,
2904
- onFiltersChange: y,
2905
- onFieldDropped: G
2906
- }
2907
- )
2908
- ] }) : u === "chart" ? (
2909
- /* Chart Tab Content */
2910
- /* @__PURE__ */ e(
2911
- Ar,
2912
- {
2913
- chartType: j,
2914
- chartConfig: Q,
2915
- displayConfig: R,
2916
- metrics: r,
2917
- breakdowns: s,
2918
- schema: a,
2919
- chartAvailability: x,
2920
- onChartTypeChange: h,
2921
- onChartConfigChange: o,
2922
- onDisplayConfigChange: v
2923
- }
2924
- )
2925
- ) : null })
2926
- ] });
2927
- }), rt = "drizzle-cube-analysis-builder-state", Ir = 300;
2928
- function ge() {
2929
- return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2930
- }
2931
- function Ve(t) {
2932
- let r = "", s = t;
2933
- do
2934
- r = String.fromCharCode(65 + s % 26) + r, s = Math.floor(s / 26) - 1;
2935
- while (s >= 0);
2936
- return r;
2937
- }
2938
- function Rr(t, r, s, l) {
2939
- const a = {
2940
- measures: t.map((u) => u.field),
2941
- dimensions: r.filter((u) => !u.isTimeDimension).map((u) => u.field),
2942
- timeDimensions: r.filter((u) => u.isTimeDimension).map((u) => ({
2943
- dimension: u.field,
2944
- granularity: u.granularity || "day"
2945
- })),
2946
- filters: s.length > 0 ? s : void 0,
2947
- order: l && Object.keys(l).length > 0 ? l : void 0
2948
- };
2949
- return a.measures?.length === 0 && delete a.measures, a.dimensions?.length === 0 && delete a.dimensions, a.timeDimensions?.length === 0 && delete a.timeDimensions, a;
2950
- }
2951
- function Te() {
2952
- return {
2953
- metrics: [],
2954
- breakdowns: [],
2955
- filters: [],
2956
- validationStatus: "idle",
2957
- validationError: null,
2958
- executionStatus: "idle",
2959
- executionResults: null,
2960
- executionError: null,
2961
- totalRowCount: null,
2962
- resultsStale: !1
2963
- };
2964
- }
2965
- function $r(t) {
2966
- if (t) return null;
2967
- try {
2968
- const r = localStorage.getItem(rt);
2969
- if (r)
2970
- return JSON.parse(r);
2971
- } catch {
2972
- }
2973
- return null;
2974
- }
2975
- const Or = Nt(
2976
- ({
2977
- className: t = "",
2978
- maxHeight: r,
2979
- initialQuery: s,
2980
- disableLocalStorage: l = !1,
2981
- hideSettings: a = !1,
2982
- onQueryChange: u,
2983
- onChartConfigChange: N
2984
- }, D) => {
2985
- const i = l || !!s, { meta: b, cubeApi: g } = kt(), T = H(
2986
- () => $r(l),
2987
- []
2988
- // Only run once on mount
2989
- ), [f, S] = J(() => s ? {
2990
- ...Te(),
2991
- metrics: (s.measures || []).map(($, q) => ({
2992
- id: ge(),
2993
- field: $,
2994
- label: Ve(q)
2995
- })),
2996
- breakdowns: [
2997
- ...(s.dimensions || []).map(($) => ({
2998
- id: ge(),
2999
- field: $,
3000
- isTimeDimension: !1
3001
- })),
3002
- ...(s.timeDimensions || []).map(($) => ({
3003
- id: ge(),
3004
- field: $.dimension,
3005
- granularity: $.granularity,
3006
- isTimeDimension: !0
3007
- }))
3008
- ],
3009
- filters: s.filters || []
3010
- } : T ? {
3011
- ...Te(),
3012
- metrics: T.metrics || [],
3013
- breakdowns: T.breakdowns || [],
3014
- filters: T.filters || []
3015
- } : Te()), [y, G] = J(() => !s && T?.chartType ? T.chartType : "line"), [E, P] = J(() => !s && T?.chartConfig ? T.chartConfig : {}), [j, Q] = J(() => !s && T?.displayConfig ? T.displayConfig : { showLegend: !0, showGrid: !0, showTooltip: !0 }), [R, x] = J(() => {
3016
- if (s?.order)
3017
- return s.order;
3018
- if (!s && T?.order)
3019
- return T.order;
3020
- }), [h, o] = J("query"), [v, A] = J(() => !s && T?.activeView ? T.activeView : "chart"), [O, V] = J(100), [z, c] = J(!1), [p, m] = J({ sql: null, analysis: null, loading: !1, error: null }), [w, d] = J(!1), [k, B] = J("metrics"), [Z, X] = J("idle"), Y = H(
3021
- () => Rr(f.metrics, f.breakdowns, f.filters, R),
3022
- [f.metrics, f.breakdowns, f.filters, R]
3023
- ), re = H(() => JSON.stringify(Y), [Y]), [se, he] = J(null), de = ae(null), me = ae(""), fe = ae(""), le = ae(E), ee = Y.measures && Y.measures.length > 0 || Y.dimensions && Y.dimensions.length > 0 || Y.timeDimensions && Y.timeDimensions.length > 0;
3024
- U(() => {
3025
- if (re !== me.current)
3026
- return de.current && clearTimeout(de.current), ee ? de.current = setTimeout(() => {
3027
- me.current = re, he(Y);
3028
- }, Ir) : (me.current = re, he(null)), () => {
3029
- de.current && clearTimeout(de.current);
3030
- };
3031
- }, [re, Y, ee]);
3032
- const ne = H(() => se ? Qt(se) : null, [se]), { resultSet: oe, isLoading: C, error: M } = Ct(ne, {
3033
- skip: !ne
3034
- }), W = H(() => se ? C && !oe ? "loading" : C && oe ? "refreshing" : M ? "error" : oe ? "success" : "idle" : "idle", [se, C, M, oe]), ce = H(() => {
3035
- if (!oe) return null;
3036
- try {
3037
- return oe.rawData();
3038
- } catch {
3039
- return null;
3040
- }
3041
- }, [oe]), be = H(
3042
- () => Ht(f.metrics, f.breakdowns),
3043
- [f.metrics, f.breakdowns]
3044
- ), Me = I(($) => ["xAxis", "yAxis", "series", "sizeField", "colorField", "dateField", "valueField"].every((F) => {
3045
- const L = $[F];
3046
- return L == null ? !0 : Array.isArray(L) ? L.length === 0 : typeof L == "string" ? L === "" : !1;
3047
- }), []);
3048
- le.current = E, U(() => {
3049
- if (!se || f.metrics.length === 0 && f.breakdowns.length === 0)
3050
- return;
3051
- const $ = JSON.stringify({
3052
- metrics: f.metrics.map((F) => F.field),
3053
- breakdowns: f.breakdowns.map((F) => ({ field: F.field, isTime: F.isTimeDimension }))
3054
- });
3055
- if ($ === fe.current)
3056
- return;
3057
- fe.current = $;
3058
- const q = Xt(
3059
- f.metrics,
3060
- f.breakdowns,
3061
- y,
3062
- z
3063
- );
3064
- if (q) {
3065
- const { chartConfig: F } = Ie(
3066
- f.metrics,
3067
- f.breakdowns,
3068
- q
3069
- );
3070
- G(q), P(F), c(!1);
3071
- } else if ((f.metrics.length > 0 || f.breakdowns.length > 0) && Me(le.current)) {
3072
- const { chartConfig: F } = Ie(
3073
- f.metrics,
3074
- f.breakdowns,
3075
- y
3076
- );
3077
- P(F);
3078
- }
3079
- }, [se, f.metrics, f.breakdowns, y, z, Me]), U(() => {
3080
- if (i) return;
3081
- const $ = setTimeout(() => {
3082
- try {
3083
- const q = {
3084
- metrics: f.metrics,
3085
- breakdowns: f.breakdowns,
3086
- filters: f.filters,
3087
- order: R,
3088
- chartType: y,
3089
- chartConfig: E,
3090
- displayConfig: j,
3091
- activeView: v
3092
- };
3093
- localStorage.setItem(rt, JSON.stringify(q));
3094
- } catch {
3095
- }
3096
- }, 0);
3097
- return () => clearTimeout($);
3098
- }, [
3099
- f.metrics,
3100
- f.breakdowns,
3101
- f.filters,
3102
- R,
3103
- y,
3104
- E,
3105
- j,
3106
- v,
3107
- i
3108
- ]), U(() => {
3109
- u && ee && u(Y);
3110
- }, [Y, ee, u]), U(() => {
3111
- N && N({ chartType: y, chartConfig: E, displayConfig: j });
3112
- }, [y, E, j, N]), U(() => {
3113
- if (!ee || !ne) {
3114
- m({ sql: null, analysis: null, loading: !1, error: null });
3115
- return;
3116
- }
3117
- let $ = !1;
3118
- return (async () => {
3119
- m((F) => ({ ...F, loading: !0, error: null }));
3120
- try {
3121
- const F = await g.dryRun(ne);
3122
- $ || m({
3123
- sql: F.sql,
3124
- analysis: F.analysis,
3125
- loading: !1,
3126
- error: null
3127
- });
3128
- } catch (F) {
3129
- $ || m({
3130
- sql: null,
3131
- analysis: null,
3132
- loading: !1,
3133
- error: F instanceof Error ? F.message : "Failed to fetch debug info"
3134
- });
3135
- }
3136
- })(), () => {
3137
- $ = !0;
3138
- };
3139
- }, [ne, g, ee]);
3140
- const st = I(() => {
3141
- B("metrics"), d(!0);
3142
- }, []), nt = I(($) => {
3143
- const q = f.metrics.find((F) => F.id === $)?.field;
3144
- S((F) => ({
3145
- ...F,
3146
- metrics: F.metrics.filter((L) => L.id !== $),
3147
- resultsStale: !0
3148
- })), q && x((F) => {
3149
- if (!F || !F[q]) return F;
3150
- const L = { ...F };
3151
- return delete L[q], Object.keys(L).length > 0 ? L : void 0;
3152
- });
3153
- }, [f.metrics]), at = I(
3154
- ($, q, F, L) => {
3155
- if (k === "metrics" && q === "measure")
3156
- S((K) => {
3157
- const te = K.metrics.findIndex((Ne) => Ne.field === $.name);
3158
- if (te >= 0)
3159
- return {
3160
- ...K,
3161
- metrics: K.metrics.filter((Ne, pe) => pe !== te),
3162
- resultsStale: !0
3163
- };
3164
- const ie = {
3165
- id: ge(),
3166
- field: $.name,
3167
- label: Ve(K.metrics.length)
3168
- };
3169
- return {
3170
- ...K,
3171
- metrics: [...K.metrics, ie],
3172
- resultsStale: !0
3173
- };
3174
- });
3175
- else if (k === "breakdown") {
3176
- const K = q === "timeDimension";
3177
- S((te) => {
3178
- const ie = te.breakdowns.findIndex((pe) => pe.field === $.name);
3179
- if (ie >= 0)
3180
- return {
3181
- ...te,
3182
- breakdowns: te.breakdowns.filter((pe, Ae) => Ae !== ie),
3183
- resultsStale: !0
3184
- };
3185
- if (K && te.breakdowns.some((Ae) => Ae.isTimeDimension))
3186
- return te;
3187
- const Ne = {
3188
- id: ge(),
3189
- field: $.name,
3190
- isTimeDimension: K,
3191
- granularity: K ? "month" : void 0
3192
- };
3193
- return {
3194
- ...te,
3195
- breakdowns: [...te.breakdowns, Ne],
3196
- resultsStale: !0
3197
- };
3198
- });
3199
- }
3200
- L || d(!1);
3201
- },
3202
- [k]
3203
- ), lt = I(() => {
3204
- B("breakdown"), d(!0);
3205
- }, []), ct = I(($) => {
3206
- const q = f.breakdowns.find((F) => F.id === $)?.field;
3207
- S((F) => ({
3208
- ...F,
3209
- breakdowns: F.breakdowns.filter((L) => L.id !== $),
3210
- resultsStale: !0
3211
- })), q && x((F) => {
3212
- if (!F || !F[q]) return F;
3213
- const L = { ...F };
3214
- return delete L[q], Object.keys(L).length > 0 ? L : void 0;
3215
- });
3216
- }, [f.breakdowns]), it = I(
3217
- ($, q) => {
3218
- S((F) => ({
3219
- ...F,
3220
- breakdowns: F.breakdowns.map(
3221
- (L) => L.id === $ ? { ...L, granularity: q } : L
3222
- ),
3223
- resultsStale: !0
3224
- }));
3225
- },
3226
- []
3227
- ), dt = I(
3228
- ($, q) => {
3229
- S((F) => {
3230
- const L = [...F.metrics], [K] = L.splice($, 1);
3231
- return L.splice(q, 0, K), {
3232
- ...F,
3233
- metrics: L,
3234
- resultsStale: !0
3235
- };
3236
- });
3237
- },
3238
- []
3239
- ), ot = I(
3240
- ($, q) => {
3241
- S((F) => {
3242
- const L = [...F.breakdowns], [K] = L.splice($, 1);
3243
- return L.splice(q, 0, K), {
3244
- ...F,
3245
- breakdowns: L,
3246
- resultsStale: !0
3247
- };
3248
- });
3249
- },
3250
- []
3251
- ), ut = I(($) => {
3252
- S((q) => ({
3253
- ...q,
3254
- filters: $,
3255
- resultsStale: !0
3256
- }));
3257
- }, []), mt = I(($) => {
3258
- const q = {
3259
- member: $,
3260
- operator: "set",
3261
- values: []
3262
- };
3263
- S((F) => {
3264
- const L = F.filters || [];
3265
- if (L.some(
3266
- (ie) => "member" in ie && ie.member === $
3267
- ))
3268
- return F;
3269
- let te;
3270
- if (L.length === 0)
3271
- te = [q];
3272
- else if (L.length === 1 && "type" in L[0]) {
3273
- const ie = L[0];
3274
- te = [{
3275
- ...ie,
3276
- filters: [...ie.filters, q]
3277
- }];
3278
- } else
3279
- te = [{
3280
- type: "and",
3281
- filters: [...L, q]
3282
- }];
3283
- return {
3284
- ...F,
3285
- filters: te,
3286
- resultsStale: !0
3287
- };
3288
- });
3289
- }, []), ht = I(
3290
- ($, q) => {
3291
- x((F) => {
3292
- const L = { ...F || {} };
3293
- return q === null ? delete L[$] : L[$] = q, Object.keys(L).length > 0 ? L : void 0;
3294
- });
3295
- },
3296
- []
3297
- ), Ee = I(() => {
3298
- S(Te()), x(void 0), c(!1);
3299
- }, []), ft = I(($) => {
3300
- G($), c(!0);
3301
- const { chartConfig: q } = Ie(
3302
- f.metrics,
3303
- f.breakdowns,
3304
- $
3305
- );
3306
- P(q);
3307
- }, [f.metrics, f.breakdowns]), xt = I(async () => {
3308
- if (!ee || !ne) return;
3309
- const $ = {
3310
- query: ne,
3311
- chartType: y,
3312
- chartConfig: E,
3313
- displayConfig: j,
3314
- activeView: v
3315
- }, { encoded: q, queryOnly: F } = gt($);
3316
- if (!q)
3317
- return;
3318
- const L = `${window.location.origin}${window.location.pathname}#share=${q}`;
3319
- try {
3320
- await navigator.clipboard.writeText(L);
3321
- } catch {
3322
- const K = document.createElement("textarea");
3323
- K.value = L, document.body.appendChild(K), K.select(), document.execCommand("copy"), document.body.removeChild(K);
3324
- }
3325
- X(F ? "copied-no-chart" : "copied"), setTimeout(() => {
3326
- X("idle");
3327
- }, 2e3);
3328
- }, [ee, ne, y, E, j, v]);
3329
- return wt(
3330
- D,
3331
- () => ({
3332
- getCurrentQuery: () => Y,
3333
- getChartConfig: () => ({ chartType: y, chartConfig: E, displayConfig: j }),
3334
- executeQuery: () => {
3335
- },
3336
- clearQuery: Ee
3337
- }),
3338
- [Y, y, E, j, Ee]
3339
- ), /* @__PURE__ */ n(
3340
- "div",
3341
- {
3342
- className: `flex flex-col lg:flex-row bg-dc-surface border-x border-b border-dc-border ${t}`,
3343
- style: r ? { height: r, maxHeight: r, overflow: "hidden" } : { height: "100%" },
3344
- children: [
3345
- /* @__PURE__ */ e("div", { className: "flex-1 min-w-0 border-r border-dc-border overflow-auto", children: /* @__PURE__ */ e(
3346
- Ut,
3347
- {
3348
- executionStatus: W,
3349
- executionResults: ce,
3350
- executionError: M?.message || null,
3351
- totalRowCount: null,
3352
- resultsStale: C && ce !== null,
3353
- chartType: y,
3354
- chartConfig: E,
3355
- displayConfig: j,
3356
- query: Y,
3357
- schema: b,
3358
- activeView: v,
3359
- onActiveViewChange: A,
3360
- displayLimit: O,
3361
- onDisplayLimitChange: V,
3362
- hasMetrics: f.metrics.length > 0,
3363
- debugQuery: ne,
3364
- debugSql: p.sql,
3365
- debugAnalysis: p.analysis,
3366
- debugLoading: p.loading,
3367
- debugError: p.error,
3368
- onShareClick: xt,
3369
- canShare: ee,
3370
- shareButtonState: Z
3371
- }
3372
- ) }),
3373
- /* @__PURE__ */ e("div", { className: "w-full lg:w-96 flex-shrink-0 h-full overflow-hidden", children: /* @__PURE__ */ e(
3374
- Fr,
3375
- {
3376
- metrics: f.metrics,
3377
- breakdowns: f.breakdowns,
3378
- filters: f.filters,
3379
- schema: b,
3380
- activeTab: h,
3381
- onActiveTabChange: o,
3382
- onAddMetric: st,
3383
- onRemoveMetric: nt,
3384
- onReorderMetrics: dt,
3385
- onAddBreakdown: lt,
3386
- onRemoveBreakdown: ct,
3387
- onBreakdownGranularityChange: it,
3388
- onReorderBreakdowns: ot,
3389
- onFiltersChange: ut,
3390
- onDropFieldToFilter: mt,
3391
- order: R,
3392
- onOrderChange: ht,
3393
- chartType: y,
3394
- chartConfig: E,
3395
- displayConfig: j,
3396
- chartAvailability: be,
3397
- onChartTypeChange: ft,
3398
- onChartConfigChange: P,
3399
- onDisplayConfigChange: Q,
3400
- validationStatus: f.validationStatus,
3401
- validationError: f.validationError
3402
- }
3403
- ) }),
3404
- /* @__PURE__ */ e(
3405
- Ye,
3406
- {
3407
- isOpen: w,
3408
- onClose: () => d(!1),
3409
- onSelect: at,
3410
- mode: k,
3411
- schema: b,
3412
- selectedFields: [
3413
- ...f.metrics.map(($) => $.field),
3414
- ...f.breakdowns.map(($) => $.field)
3415
- ]
3416
- }
3417
- )
3418
- ]
3419
- }
3420
- );
3421
- }
3422
- );
3423
- Or.displayName = "AnalysisBuilder";
1
+ import { e as s, a as r, A as t, d as o, D as l, M as i, c as n, P as d, b as c, Q as h } from "./chunks/components-DAOVOiM_.js";
2
+ import { L as g } from "./chunks/chart-chartcontainer-CdwzIKP1.js";
3
+ import { L as p, c as T, f as m, g as u, i as b, p as I, a as f } from "./chunks/charts-DY7pF_-4.js";
4
+ import { n as x, T as A, y as M, r as P, g as E, v as L, B as S, z as v, A as B, x as Q, u as V, w } from "./chunks/chart-activitygridchart-C1ts13cL.js";
5
+ import { ScrollContainerProvider as F, useScrollContainer as R } from "./providers.js";
6
+ import { useCubeQuery as k } from "./hooks.js";
7
+ import { D as H, g as N, h as O, b as U, c as j, e as q, f as J, a as K, r as W, d as X, s as Y } from "./chunks/chart-activitygridchart-config-AVBoHdRn.js";
3424
8
  export {
3425
- Or as AnalysisBuilder,
3426
- Gr as AnalyticsDashboard,
3427
- Qr as AnalyticsPortlet,
3428
- ls as CubeProvider,
3429
- gs as DEFAULT_ICONS,
3430
- Jr as DashboardEditModal,
3431
- zr as DashboardGrid,
3432
- Le as LazyChart,
3433
- Xr as LoadingIndicator,
3434
- Yr as Modal,
3435
- Wr as PortletContainer,
3436
- Zr as PortletEditModal,
3437
- Hr as QueryBuilder,
3438
- Ss as ScrollContainerProvider,
3439
- cs as THEME_PRESETS,
3440
- is as applyTheme,
3441
- ds as createCubeClient,
3442
- es as createDashboardLayout,
3443
- ts as formatChartData,
3444
- rs as getAvailableChartTypes,
3445
- vs as getChartTypeIcon,
3446
- Ce as getFieldTypeIcon,
3447
- _ as getIcon,
3448
- ys as getIconData,
3449
- Ns as getIconRegistry,
3450
- ws as getIconsByCategory,
3451
- ye as getMeasureTypeIcon,
3452
- os as getTheme,
3453
- us as getThemeVariable,
3454
- ms as isDarkMode,
3455
- vt as isValidChartType,
3456
- ss as preloadChart,
3457
- ns as preloadCharts,
3458
- ks as registerIcons,
3459
- Ds as resetIcons,
3460
- hs as resetTheme,
3461
- Ts as setIcon,
3462
- fs as setTheme,
3463
- xs as setThemeVariable,
3464
- kt as useCubeContext,
3465
- Ct as useCubeQuery,
3466
- As as useScrollContainer,
3467
- bs as watchThemeChanges
9
+ s as AnalysisBuilder,
10
+ r as AnalyticsDashboard,
11
+ t as AnalyticsPortlet,
12
+ x as CubeProvider,
13
+ H as DEFAULT_ICONS,
14
+ o as DashboardEditModal,
15
+ l as DashboardGrid,
16
+ p as LazyChart,
17
+ g as LoadingIndicator,
18
+ i as Modal,
19
+ n as PortletAnalysisModal,
20
+ d as PortletContainer,
21
+ c as PortletEditModal,
22
+ h as QueryBuilder,
23
+ F as ScrollContainerProvider,
24
+ A as THEME_PRESETS,
25
+ M as applyTheme,
26
+ P as createCubeClient,
27
+ T as createDashboardLayout,
28
+ m as formatChartData,
29
+ u as getAvailableChartTypes,
30
+ N as getChartTypeIcon,
31
+ O as getFieldTypeIcon,
32
+ U as getIcon,
33
+ j as getIconData,
34
+ q as getIconRegistry,
35
+ J as getIconsByCategory,
36
+ K as getMeasureTypeIcon,
37
+ E as getTheme,
38
+ L as getThemeVariable,
39
+ S as isDarkMode,
40
+ b as isValidChartType,
41
+ I as preloadChart,
42
+ f as preloadCharts,
43
+ W as registerIcons,
44
+ X as resetIcons,
45
+ v as resetTheme,
46
+ Y as setIcon,
47
+ B as setTheme,
48
+ Q as setThemeVariable,
49
+ V as useCubeContext,
50
+ k as useCubeQuery,
51
+ R as useScrollContainer,
52
+ w as watchThemeChanges
3468
53
  };
3469
54
  //# sourceMappingURL=index.js.map