react-semaphor 0.1.172 → 0.1.174
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{dashboard-controls-BuKUWOU1.js → dashboard-controls-BdFhbpoS.js} +6 -6
- package/dist/chunks/{dashboard-controls-DA-lJWSK.js → dashboard-controls-Bxjvkywu.js} +354 -352
- package/dist/chunks/{dashboard-json-CUTAJhWz.js → dashboard-json-BCH4SQkg.js} +1 -1
- package/dist/chunks/{dashboard-json-BTWzsbui.js → dashboard-json-ClK3yCs7.js} +1 -1
- package/dist/chunks/edit-dashboard-visual-BEAKONcQ.js +189 -0
- package/dist/chunks/{edit-dashboard-visual-BEWMIe7g.js → edit-dashboard-visual-CSI-cZoT.js} +4835 -4809
- package/dist/chunks/{editor-action-buttons-WGWavDMB.js → editor-action-buttons-BaHzz3CT.js} +1 -1
- package/dist/chunks/{editor-action-buttons-C5Ejuo4M.js → editor-action-buttons-DIFwpB2w.js} +2 -2
- package/dist/chunks/{index-DMR0K1Nf.js → index-BAb30JIE.js} +75 -75
- package/dist/chunks/{index-C8T45uat.js → index-CtuIHKSY.js} +4370 -4304
- package/dist/chunks/{resource-management-panel-DFC27hgo.js → resource-management-panel-Cs7tkTxZ.js} +1 -1
- package/dist/chunks/{resource-management-panel-BKAs9Em0.js → resource-management-panel-DRMNQIkI.js} +3 -3
- package/dist/chunks/{schedule-dashboard-r_XMtRaW.js → schedule-dashboard-Bj4mXU5g.js} +38 -38
- package/dist/chunks/{schedule-dashboard-DC7XeEaW.js → schedule-dashboard-CInkuI61.js} +2 -2
- package/dist/chunks/{use-role-aware-display-preferences-CAbBsXoz.js → use-role-aware-display-preferences-BGTLQ_rf.js} +1 -1
- package/dist/chunks/{use-role-aware-display-preferences-BOpxNd8x.js → use-role-aware-display-preferences-DgSkQ7I0.js} +1 -1
- package/dist/chunks/use-visual-utils-BmwT7aG_.js +338 -0
- package/dist/chunks/use-visual-utils-CeBDoiB8.js +1 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/dist/types/main.d.ts +36 -0
- package/package.json +1 -1
- package/dist/chunks/edit-dashboard-visual-_uEu62dm.js +0 -189
- package/dist/chunks/use-visual-utils-BJxotk2m.js +0 -331
- package/dist/chunks/use-visual-utils-DG7j82aL.js +0 -1
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { az as z, aA as G, p as Y, q as J, aB as K, m as _, o as X, u as U, aC as Z, aD as q, t as v, aE as ee, n as h } from "./index-C8T45uat.js";
|
|
2
|
-
import { useState as T, useEffect as te, useCallback as V } from "react";
|
|
3
|
-
function re(e) {
|
|
4
|
-
const o = e.toUpperCase().indexOf("WHERE"), r = e.toUpperCase().indexOf("GROUP BY"), t = e.toUpperCase().indexOf("LIMIT"), i = e.toUpperCase().indexOf("ORDER BY");
|
|
5
|
-
let n = e.length;
|
|
6
|
-
if (i !== -1 && (n = i), t !== -1 && t < n && (n = t), o !== -1) {
|
|
7
|
-
const a = e.substring(0, o), s = e.substring(o);
|
|
8
|
-
return `${a} {{ filters | where }} AND ${s.substring(
|
|
9
|
-
6
|
|
10
|
-
)}`;
|
|
11
|
-
} else if (r !== -1) {
|
|
12
|
-
const a = e.substring(0, r), s = e.substring(r);
|
|
13
|
-
return `${a} {{ filters | where }} ${s}`;
|
|
14
|
-
} else {
|
|
15
|
-
const a = e.substring(0, n), s = e.substring(n);
|
|
16
|
-
return console.log("beforeClause", a), console.log("afterClause", s), s ? `${a} {{ filters | where }} ${s}` : `${a.replace(/;$/, "")} {{ filters | where }}`;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function se(e) {
|
|
20
|
-
const [o, r] = T(null), [t, i] = T(null), n = z();
|
|
21
|
-
return te(() => {
|
|
22
|
-
if (!e || e.trim() === "") {
|
|
23
|
-
r(null), i(null);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (!n)
|
|
27
|
-
return;
|
|
28
|
-
(async () => {
|
|
29
|
-
try {
|
|
30
|
-
if (!e.startsWith("http://") && !e.startsWith("https://"))
|
|
31
|
-
throw new Error(`Invalid URL format: ${e}`);
|
|
32
|
-
try {
|
|
33
|
-
new URL(e);
|
|
34
|
-
} catch {
|
|
35
|
-
throw new Error(`Invalid URL: ${e}`);
|
|
36
|
-
}
|
|
37
|
-
const d = `${e.endsWith("/") ? e : `${e}/`}index.js`;
|
|
38
|
-
try {
|
|
39
|
-
if (!(await fetch(d, { method: "HEAD" })).ok)
|
|
40
|
-
throw new Error(`Module not found at ${d}`);
|
|
41
|
-
} catch {
|
|
42
|
-
}
|
|
43
|
-
const m = await import(
|
|
44
|
-
/* @vite-ignore */
|
|
45
|
-
/* webpackIgnore: true */
|
|
46
|
-
d
|
|
47
|
-
);
|
|
48
|
-
if (typeof m.useChartStore != "function")
|
|
49
|
-
throw new Error("useChartStore is not a function");
|
|
50
|
-
r(() => m.useChartStore), i(null);
|
|
51
|
-
} catch (s) {
|
|
52
|
-
const d = s instanceof Error ? s.message : "Unknown error";
|
|
53
|
-
console.error("Failed to load remote chart store:", d), i(d), r(null);
|
|
54
|
-
}
|
|
55
|
-
})();
|
|
56
|
-
}, [e, n]), o;
|
|
57
|
-
}
|
|
58
|
-
function oe(e, o) {
|
|
59
|
-
if (e.length === 0)
|
|
60
|
-
return "";
|
|
61
|
-
if (o) {
|
|
62
|
-
const r = e.find((t) => t.id === o);
|
|
63
|
-
if (r) {
|
|
64
|
-
const t = r.tabTitle;
|
|
65
|
-
if (t == "All__Header")
|
|
66
|
-
return e[0].id;
|
|
67
|
-
if (t && t.endsWith("__Header")) {
|
|
68
|
-
const n = t.split("__")[0], a = e.find(
|
|
69
|
-
(s) => s.tabTitle === n
|
|
70
|
-
);
|
|
71
|
-
return a ? a.id : e[0].id;
|
|
72
|
-
}
|
|
73
|
-
return o;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return e[0].id;
|
|
77
|
-
}
|
|
78
|
-
async function M(e, o, r, t) {
|
|
79
|
-
if (!o || !r)
|
|
80
|
-
throw new Error("Missing auth token or visual ID");
|
|
81
|
-
const i = ["resource-by-id", "visual", r], n = t.getQueryData(i);
|
|
82
|
-
if (n)
|
|
83
|
-
return console.log("Using cached visual data for:", r), { data: n, fromCache: !0 };
|
|
84
|
-
console.log("Fetching visual data from network for:", r);
|
|
85
|
-
const a = v.loading("Loading visual...", {
|
|
86
|
-
position: "top-center"
|
|
87
|
-
});
|
|
88
|
-
try {
|
|
89
|
-
const s = await fetch(
|
|
90
|
-
`${e}/management/v1/visuals/${r}`,
|
|
91
|
-
{
|
|
92
|
-
headers: {
|
|
93
|
-
Authorization: `Bearer ${o}`
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
if (!s.ok)
|
|
98
|
-
throw new Error("Failed to load visual");
|
|
99
|
-
const d = await s.json();
|
|
100
|
-
return t.setQueryData(i, d), v.dismiss(a), { data: d, fromCache: !1 };
|
|
101
|
-
} catch (s) {
|
|
102
|
-
throw v.dismiss(a), s;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function H(e) {
|
|
106
|
-
if (typeof e == "string")
|
|
107
|
-
return JSON.parse(e);
|
|
108
|
-
if (typeof e == "object")
|
|
109
|
-
return e;
|
|
110
|
-
throw new Error("Invalid frame object format");
|
|
111
|
-
}
|
|
112
|
-
function ae(e, o) {
|
|
113
|
-
var n, a;
|
|
114
|
-
const r = (e == null ? void 0 : e.frameObject) ?? ((n = e == null ? void 0 : e.visual) == null ? void 0 : n.frameObject);
|
|
115
|
-
if (!r)
|
|
116
|
-
return !1;
|
|
117
|
-
const t = H(r);
|
|
118
|
-
if (!(t != null && t.cards) || t.cards.length === 0)
|
|
119
|
-
return !1;
|
|
120
|
-
const i = (a = t.cards) == null ? void 0 : a.find(
|
|
121
|
-
(s) => s.id === t.activeCardId
|
|
122
|
-
);
|
|
123
|
-
return i ? (ee({
|
|
124
|
-
...o,
|
|
125
|
-
frame: t,
|
|
126
|
-
card: i,
|
|
127
|
-
visualId: (e == null ? void 0 : e.id) || t.visualId
|
|
128
|
-
}), !0) : !1;
|
|
129
|
-
}
|
|
130
|
-
function ne() {
|
|
131
|
-
var b;
|
|
132
|
-
const { setCardSql: e } = _(), o = h((c) => c.frame), r = h((c) => c.card), t = se(
|
|
133
|
-
((b = r.customCardPreferences) == null ? void 0 : b.url) || ""
|
|
134
|
-
), i = h(
|
|
135
|
-
(c) => c.selectedSchemaName
|
|
136
|
-
), n = h(
|
|
137
|
-
(c) => c.selectedDatamodelId
|
|
138
|
-
), a = h(
|
|
139
|
-
(c) => c.selectedDatabaseName
|
|
140
|
-
), s = h((c) => c.selectedTableName), d = h(
|
|
141
|
-
(c) => c.selectedConnectionId
|
|
142
|
-
), m = h((c) => c.isShowingVisual), u = r.sql;
|
|
143
|
-
return { getUpdatedFrame: V(() => {
|
|
144
|
-
var C;
|
|
145
|
-
let c = u;
|
|
146
|
-
u && !u.includes("{{") && (c = re(u), e(c));
|
|
147
|
-
const S = (C = t == null ? void 0 : t.getState()) == null ? void 0 : C.settings, F = {
|
|
148
|
-
...r,
|
|
149
|
-
dataSource: r.dataSource || { mode: "directSource" },
|
|
150
|
-
lastSelectedSchema: i,
|
|
151
|
-
lastSelectedDatamodelId: n,
|
|
152
|
-
lastSelectedDatabase: a,
|
|
153
|
-
lastSelectedTable: s,
|
|
154
|
-
connectionId: d,
|
|
155
|
-
// type: isShowingVisual ? card.type : 'table', /// CHECK THIS!!!!
|
|
156
|
-
sql: c,
|
|
157
|
-
customCfg: m ? r.customCfg : null,
|
|
158
|
-
preferences: r.preferences,
|
|
159
|
-
// Preserve all preferences including column sizing
|
|
160
|
-
...S && {
|
|
161
|
-
customCardPreferences: {
|
|
162
|
-
...r.customCardPreferences,
|
|
163
|
-
settings: S
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}, w = o.cards.map(
|
|
167
|
-
(p) => p.id === r.id ? F : p
|
|
168
|
-
);
|
|
169
|
-
return {
|
|
170
|
-
...o,
|
|
171
|
-
cards: w,
|
|
172
|
-
activeCardId: oe(w, o.activeCardId)
|
|
173
|
-
};
|
|
174
|
-
}, [
|
|
175
|
-
r,
|
|
176
|
-
o,
|
|
177
|
-
m,
|
|
178
|
-
i,
|
|
179
|
-
n,
|
|
180
|
-
a,
|
|
181
|
-
s,
|
|
182
|
-
d,
|
|
183
|
-
e,
|
|
184
|
-
t,
|
|
185
|
-
u
|
|
186
|
-
]) };
|
|
187
|
-
}
|
|
188
|
-
function de() {
|
|
189
|
-
const { authToken: e, tokenProps: o } = G(), r = Y(), t = J(), { selectVisual: i } = K(), {
|
|
190
|
-
setFrame: n,
|
|
191
|
-
setCard: a,
|
|
192
|
-
setIsDevMode: s,
|
|
193
|
-
setActiveTabCardId: d,
|
|
194
|
-
updateDataSource: m,
|
|
195
|
-
setQueryResultColumns: u,
|
|
196
|
-
setSelectedConnectionId: $,
|
|
197
|
-
setSelectedDatabaseName: b,
|
|
198
|
-
setSelectedSchemaName: c,
|
|
199
|
-
setSelectedTableName: S,
|
|
200
|
-
setSelectedDatamodelId: F,
|
|
201
|
-
setFilterValues: w,
|
|
202
|
-
setApplyFilters: C
|
|
203
|
-
} = _(), {
|
|
204
|
-
setIsDashboardEditing: p,
|
|
205
|
-
setIsVisualEditing: A,
|
|
206
|
-
setSelectedFrameId: N,
|
|
207
|
-
clearSelectedFrameId: O,
|
|
208
|
-
addFrame: x,
|
|
209
|
-
setIsDashboardPanelOpen: R
|
|
210
|
-
} = X(), I = U((l) => l.selectedSheetId), W = U((l) => l.selectedFrameId), D = U((l) => l.dashboard), B = U((l) => l.filterValues), E = Z((t == null ? void 0 : t.id) || "", {
|
|
211
|
-
enabled: !!(t != null && t.id) && !!(e != null && e.accessToken)
|
|
212
|
-
}), Q = V(
|
|
213
|
-
async (l) => {
|
|
214
|
-
try {
|
|
215
|
-
i(l), O();
|
|
216
|
-
const { data: g, fromCache: f } = await M(
|
|
217
|
-
o.apiServiceUrl,
|
|
218
|
-
(e == null ? void 0 : e.accessToken) || "",
|
|
219
|
-
l.id,
|
|
220
|
-
r
|
|
221
|
-
);
|
|
222
|
-
if (!ae(g, {
|
|
223
|
-
setFrame: n,
|
|
224
|
-
setCard: a,
|
|
225
|
-
setIsDevMode: s,
|
|
226
|
-
setActiveTabCardId: d,
|
|
227
|
-
updateDataSource: m,
|
|
228
|
-
setQueryResultColumns: u,
|
|
229
|
-
setSelectedConnectionId: $,
|
|
230
|
-
setSelectedDatabaseName: b,
|
|
231
|
-
setSelectedSchemaName: c,
|
|
232
|
-
setSelectedTableName: S,
|
|
233
|
-
setSelectedDatamodelId: F,
|
|
234
|
-
setFilterValues: w,
|
|
235
|
-
setApplyFilters: C,
|
|
236
|
-
setIsDashboardEditing: p,
|
|
237
|
-
setIsVisualEditing: A,
|
|
238
|
-
dashboard: D,
|
|
239
|
-
selectedSheetId: I,
|
|
240
|
-
selectedFrameId: W,
|
|
241
|
-
filterValues: B
|
|
242
|
-
}))
|
|
243
|
-
throw new Error("Failed to setup editor with visual data");
|
|
244
|
-
return { success: !0, fromCache: f };
|
|
245
|
-
} catch (g) {
|
|
246
|
-
return console.error("Error editing visual:", g), { success: !1, error: "Failed to load visual for editing" };
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
[
|
|
250
|
-
e == null ? void 0 : e.accessToken,
|
|
251
|
-
o.apiServiceUrl,
|
|
252
|
-
r,
|
|
253
|
-
i,
|
|
254
|
-
n,
|
|
255
|
-
a,
|
|
256
|
-
p,
|
|
257
|
-
A,
|
|
258
|
-
s,
|
|
259
|
-
d,
|
|
260
|
-
m,
|
|
261
|
-
u,
|
|
262
|
-
$,
|
|
263
|
-
b,
|
|
264
|
-
c,
|
|
265
|
-
S,
|
|
266
|
-
F,
|
|
267
|
-
w,
|
|
268
|
-
C,
|
|
269
|
-
O,
|
|
270
|
-
D,
|
|
271
|
-
I,
|
|
272
|
-
W,
|
|
273
|
-
B
|
|
274
|
-
]
|
|
275
|
-
), k = V(
|
|
276
|
-
async (l) => {
|
|
277
|
-
var g;
|
|
278
|
-
try {
|
|
279
|
-
if (i(l), !I)
|
|
280
|
-
return {
|
|
281
|
-
success: !1,
|
|
282
|
-
error: "No sheet selected. Please select a sheet first."
|
|
283
|
-
};
|
|
284
|
-
const { data: f, fromCache: L } = await M(
|
|
285
|
-
o.apiServiceUrl,
|
|
286
|
-
(e == null ? void 0 : e.accessToken) || "",
|
|
287
|
-
l.id,
|
|
288
|
-
r
|
|
289
|
-
), P = (f == null ? void 0 : f.frameObject) ?? ((g = f == null ? void 0 : f.visual) == null ? void 0 : g.frameObject);
|
|
290
|
-
if (!P)
|
|
291
|
-
return { success: !1, error: "Visual has no frame data" };
|
|
292
|
-
const y = H(P);
|
|
293
|
-
if (!(y != null && y.cards) || y.cards.length === 0)
|
|
294
|
-
return { success: !1, error: "Visual frame is malformed" };
|
|
295
|
-
const j = {
|
|
296
|
-
...q(y),
|
|
297
|
-
visualId: l.id
|
|
298
|
-
// Link this frame to the library visual
|
|
299
|
-
};
|
|
300
|
-
return x(I, j, "end"), p(!0), N(j.id), R(!1), { success: !0, fromCache: L };
|
|
301
|
-
} catch (f) {
|
|
302
|
-
return console.error("Error adding visual:", f), { success: !1, error: "Failed to add visual to dashboard" };
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
[
|
|
306
|
-
e == null ? void 0 : e.accessToken,
|
|
307
|
-
o.apiServiceUrl,
|
|
308
|
-
r,
|
|
309
|
-
i,
|
|
310
|
-
I,
|
|
311
|
-
x,
|
|
312
|
-
p,
|
|
313
|
-
N,
|
|
314
|
-
R
|
|
315
|
-
]
|
|
316
|
-
);
|
|
317
|
-
return {
|
|
318
|
-
visual: E.data,
|
|
319
|
-
isLoading: E.isLoading,
|
|
320
|
-
isError: E.isError,
|
|
321
|
-
error: E.error,
|
|
322
|
-
handleEditLibraryVisual: Q,
|
|
323
|
-
handleAddLibraryVisual: k,
|
|
324
|
-
getUpdatedFrame: ne().getUpdatedFrame,
|
|
325
|
-
refetch: E.refetch
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
export {
|
|
329
|
-
de as a,
|
|
330
|
-
se as u
|
|
331
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const o=require("./index-DMR0K1Nf.js"),b=require("react");function _(e){const a=e.toUpperCase().indexOf("WHERE"),r=e.toUpperCase().indexOf("GROUP BY"),t=e.toUpperCase().indexOf("LIMIT"),d=e.toUpperCase().indexOf("ORDER BY");let c=e.length;if(d!==-1&&(c=d),t!==-1&&t<c&&(c=t),a!==-1){const n=e.substring(0,a),s=e.substring(a);return`${n} {{ filters | where }} AND ${s.substring(6)}`}else if(r!==-1){const n=e.substring(0,r),s=e.substring(r);return`${n} {{ filters | where }} ${s}`}else{const n=e.substring(0,c),s=e.substring(c);return console.log("beforeClause",n),console.log("afterClause",s),s?`${n} {{ filters | where }} ${s}`:`${n.replace(/;$/,"")} {{ filters | where }}`}}function B(e){const[a,r]=b.useState(null),[t,d]=b.useState(null),c=o.useEnsureReactGlobals();return b.useEffect(()=>{if(!e||e.trim()===""){r(null),d(null);return}if(!c)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const l=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(l,{method:"HEAD"})).ok)throw new Error(`Module not found at ${l}`)}catch{}const m=await import(l);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");r(()=>m.useChartStore),d(null)}catch(s){const l=s instanceof Error?s.message:"Unknown error";console.error("Failed to load remote chart store:",l),d(l),r(null)}})()},[e,c]),a}function H(e,a){if(e.length===0)return"";if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const c=t.split("__")[0],n=e.find(s=>s.tabTitle===c);return n?n.id:e[0].id}return a}}return e[0].id}async function j(e,a,r,t){if(!a||!r)throw new Error("Missing auth token or visual ID");const d=["resource-by-id","visual",r],c=t.getQueryData(d);if(c)return console.log("Using cached visual data for:",r),{data:c,fromCache:!0};console.log("Fetching visual data from network for:",r);const n=o.ue.loading("Loading visual...",{position:"top-center"});try{const s=await fetch(`${e}/management/v1/visuals/${r}`,{headers:{Authorization:`Bearer ${a}`}});if(!s.ok)throw new Error("Failed to load visual");const l=await s.json();return t.setQueryData(d,l),o.ue.dismiss(n),{data:l,fromCache:!1}}catch(s){throw o.ue.dismiss(n),s}}function T(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function Q(e,a){var c,n;const r=(e==null?void 0:e.frameObject)??((c=e==null?void 0:e.visual)==null?void 0:c.frameObject);if(!r)return!1;const t=T(r);if(!(t!=null&&t.cards)||t.cards.length===0)return!1;const d=(n=t.cards)==null?void 0:n.find(s=>s.id===t.activeCardId);return d?(o.setupEditorWithCard({...a,frame:t,card:d,visualId:(e==null?void 0:e.id)||t.visualId}),!0):!1}function G(){var g;const{setCardSql:e}=o.useEditorActions(),a=o.useEditorStore(i=>i.frame),r=o.useEditorStore(i=>i.card),t=B(((g=r.customCardPreferences)==null?void 0:g.url)||""),d=o.useEditorStore(i=>i.selectedSchemaName),c=o.useEditorStore(i=>i.selectedDatamodelId),n=o.useEditorStore(i=>i.selectedDatabaseName),s=o.useEditorStore(i=>i.selectedTableName),l=o.useEditorStore(i=>i.selectedConnectionId),m=o.useEditorStore(i=>i.isShowingVisual),f=r.sql;return{getUpdatedFrame:b.useCallback(()=>{var E;let i=f;f&&!f.includes("{{")&&(i=_(f),e(i));const C=(E=t==null?void 0:t.getState())==null?void 0:E.settings,U={...r,dataSource:r.dataSource||{mode:"directSource"},lastSelectedSchema:d,lastSelectedDatamodelId:c,lastSelectedDatabase:n,lastSelectedTable:s,connectionId:l,sql:i,customCfg:m?r.customCfg:null,preferences:r.preferences,...C&&{customCardPreferences:{...r.customCardPreferences,settings:C}}},w=a.cards.map(S=>S.id===r.id?U:S);return{...a,cards:w,activeCardId:H(w,a.activeCardId)}},[r,a,m,d,c,n,s,l,e,t,f])}}function z(){const{authToken:e,tokenProps:a}=o.useSemaphorContext(),r=o.useQueryClient(),t=o.useSelectedVisual(),{selectVisual:d}=o.useManagementActions(),{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E}=o.useEditorActions(),{setIsDashboardEditing:S,setIsVisualEditing:$,setSelectedFrameId:v,clearSelectedFrameId:A,addFrame:N,setIsDashboardPanelOpen:R}=o.useDashboardActions(),I=o.useDashboardStore(u=>u.selectedSheetId),D=o.useDashboardStore(u=>u.selectedFrameId),O=o.useDashboardStore(u=>u.dashboard),x=o.useDashboardStore(u=>u.filterValues),y=o.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),M=b.useCallback(async u=>{try{d(u),A();const{data:p,fromCache:h}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r);if(!Q(p,{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E,setIsDashboardEditing:S,setIsVisualEditing:$,dashboard:O,selectedSheetId:I,selectedFrameId:D,filterValues:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:h}}catch(p){return console.error("Error editing visual:",p),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,c,n,S,$,s,l,m,f,V,g,i,C,U,w,E,A,O,I,D,x]),k=b.useCallback(async u=>{var p;try{if(d(u),!I)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:h,fromCache:W}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r),L=(h==null?void 0:h.frameObject)??((p=h==null?void 0:h.visual)==null?void 0:p.frameObject);if(!L)return{success:!1,error:"Visual has no frame data"};const F=T(L);if(!(F!=null&&F.cards)||F.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const P={...o.cloneFrameWithNewIds(F),visualId:u.id};return N(I,P,"end"),S(!0),v(P.id),R(!1),{success:!0,fromCache:W}}catch(h){return console.error("Error adding visual:",h),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,I,N,S,v,R]);return{visual:y.data,isLoading:y.isLoading,isError:y.isError,error:y.error,handleEditLibraryVisual:M,handleAddLibraryVisual:k,getUpdatedFrame:G().getUpdatedFrame,refetch:y.refetch}}exports.useRemoteChartStore=B;exports.useVisualUtils=z;
|