@burdenoff/microfe-bigconsole 2026.1124.2 → 2026.1124.3

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.
@@ -4,53 +4,61 @@ import t from "../../hooks/useWidgetOperations.js";
4
4
  import "../../hooks/index.js";
5
5
  import { useAsOf as n } from "../../asof/AsOfProvider.js";
6
6
  import "../../asof/index.js";
7
- import { BIGCONSOLE_PERMISSIONS as r } from "../../../constants/permissions.js";
8
- import { memo as i, useCallback as a, useEffect as o, useRef as s, useState as c } from "react";
9
- import { usePermissions as l } from "@burdenoff/fe-libs/shared/providers/shell";
10
- import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
11
- import { createPortal as p } from "react-dom";
7
+ import { useFleetWidgetMenu as r } from "../fleet/FleetWidgetActions.js";
8
+ import { fleetMenuOffers as i } from "../../utils/fleetWidgetMenu.js";
9
+ import { BIGCONSOLE_PERMISSIONS as a } from "../../../constants/permissions.js";
10
+ import { memo as o, useCallback as s, useEffect as c, useRef as l, useState as u } from "react";
11
+ import { usePermissions as d } from "@burdenoff/fe-libs/shared/providers/shell";
12
+ import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
13
+ import { createPortal as h } from "react-dom";
12
14
  // src/bigconsole/components/widgets/WidgetMenu.tsx
13
- var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onExportPNG: _, onSpotOutliers: v, onReconcile: y }) {
14
- let [b, x] = c(!1), [S, C] = c(!1), [w, T] = c({
15
+ var g = o(function({ widget: o, isEditMode: g, onRefresh: _, onExportCSV: v, onExportPNG: y, onSpotOutliers: b, onReconcile: x }) {
16
+ let [S, C] = u(!1), [w, T] = u(!1), [E, D] = u({
15
17
  top: 0,
16
18
  left: 0
17
- }), E = s(null), D = s(null), { hasPermission: O } = l(), k = O(r.WIDGET_UPDATE), A = O(r.WIDGET_CREATE), j = O(r.WIDGET_DELETE), M = e((e) => e.selectWidget), N = e((e) => e.copyWidget), P = e((e) => e.cutWidget), F = e((e) => e.removeWidget), I = e((e) => e.openConfigPanel), { asOf: L } = n(), { duplicateWidget: R, deleteWidget: z, refreshWidgetData: B } = t(i.pageId, i.dashboardId, { skipFetch: !0 });
18
- o(() => {
19
+ }), O = l(null), k = l(null), { hasPermission: A } = d(), j = A(a.WIDGET_UPDATE), M = A(a.WIDGET_CREATE), N = A(a.WIDGET_DELETE), P = e((e) => e.selectWidget), F = e((e) => e.copyWidget), I = e((e) => e.cutWidget), L = e((e) => e.removeWidget), R = e((e) => e.openConfigPanel), { asOf: z } = n(), B = r(), V = B ? i(o, {
20
+ isActiveCopy: B.isActiveCopy,
21
+ inPastView: !!z
22
+ }) : {
23
+ restore: !1,
24
+ promote: !1
25
+ }, { duplicateWidget: H, deleteWidget: U, refreshWidgetData: W } = t(o.pageId, o.dashboardId, { skipFetch: !0 });
26
+ c(() => {
19
27
  let e = (e) => {
20
- E.current && !E.current.contains(e.target) && D.current && !D.current.contains(e.target) && x(!1);
28
+ O.current && !O.current.contains(e.target) && k.current && !k.current.contains(e.target) && C(!1);
21
29
  };
22
- return b && document.addEventListener("mousedown", e), () => {
30
+ return S && document.addEventListener("mousedown", e), () => {
23
31
  document.removeEventListener("mousedown", e);
24
32
  };
25
- }, [b]), o(() => {
33
+ }, [S]), c(() => {
26
34
  let e = (e) => {
27
- e.key === "Escape" && (x(!1), D.current?.focus());
35
+ e.key === "Escape" && (C(!1), k.current?.focus());
28
36
  };
29
- return b && document.addEventListener("keydown", e), () => {
37
+ return S && document.addEventListener("keydown", e), () => {
30
38
  document.removeEventListener("keydown", e);
31
39
  };
32
- }, [b]);
33
- let V = a((e) => {
34
- e.stopPropagation(), x((e) => {
35
- if (!e && D.current) {
36
- let e = D.current.getBoundingClientRect(), t = e.bottom + 4, n = e.right - 160;
37
- n + 160 > window.innerWidth - 10 && (n = window.innerWidth - 160 - 10), n < 10 && (n = 10), t + 320 > window.innerHeight - 10 && (t = e.top - 320 - 4, t < 10 && (t = 10)), T({
40
+ }, [S]);
41
+ let G = s((e) => {
42
+ e.stopPropagation(), C((e) => {
43
+ if (!e && k.current) {
44
+ let e = k.current.getBoundingClientRect(), t = e.bottom + 4, n = e.right - 160;
45
+ n + 160 > window.innerWidth - 10 && (n = window.innerWidth - 160 - 10), n < 10 && (n = 10), t + 380 > window.innerHeight - 10 && (t = e.top - 380 - 4, t < 10 && (t = 10)), D({
38
46
  top: t + window.scrollY,
39
47
  left: n + window.scrollX
40
48
  });
41
49
  }
42
50
  return !e;
43
51
  });
44
- }, []), H = [
52
+ }, []), K = [
45
53
  {
46
54
  id: "edit",
47
55
  label: "Edit Widget",
48
- icon: /* @__PURE__ */ d("svg", {
56
+ icon: /* @__PURE__ */ p("svg", {
49
57
  fill: "none",
50
58
  stroke: "currentColor",
51
59
  viewBox: "0 0 24 24",
52
60
  className: "w-4 h-4",
53
- children: /* @__PURE__ */ d("path", {
61
+ children: /* @__PURE__ */ p("path", {
54
62
  strokeLinecap: "round",
55
63
  strokeLinejoin: "round",
56
64
  strokeWidth: 2,
@@ -58,20 +66,20 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
58
66
  })
59
67
  }),
60
68
  action: () => {
61
- M(i.id), I(), x(!1);
69
+ P(o.id), R(), C(!1);
62
70
  },
63
- disabled: !m,
64
- permitted: k
71
+ disabled: !g,
72
+ permitted: j
65
73
  },
66
74
  {
67
75
  id: "refresh",
68
76
  label: "Refresh Data",
69
- icon: /* @__PURE__ */ d("svg", {
77
+ icon: /* @__PURE__ */ p("svg", {
70
78
  fill: "none",
71
79
  stroke: "currentColor",
72
80
  viewBox: "0 0 24 24",
73
81
  className: "w-4 h-4",
74
- children: /* @__PURE__ */ d("path", {
82
+ children: /* @__PURE__ */ p("path", {
75
83
  strokeLinecap: "round",
76
84
  strokeLinejoin: "round",
77
85
  strokeWidth: 2,
@@ -79,19 +87,19 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
79
87
  })
80
88
  }),
81
89
  action: async () => {
82
- x(!1), L || (h ? h() : await B(i.id));
90
+ C(!1), z || (_ ? _() : await W(o.id));
83
91
  },
84
- disabled: !!L
92
+ disabled: !!z
85
93
  },
86
94
  {
87
95
  id: "spotOutliers",
88
96
  label: "Spot outliers",
89
- icon: /* @__PURE__ */ d("svg", {
97
+ icon: /* @__PURE__ */ p("svg", {
90
98
  fill: "none",
91
99
  stroke: "currentColor",
92
100
  viewBox: "0 0 24 24",
93
101
  className: "w-4 h-4",
94
- children: /* @__PURE__ */ d("path", {
102
+ children: /* @__PURE__ */ p("path", {
95
103
  strokeLinecap: "round",
96
104
  strokeLinejoin: "round",
97
105
  strokeWidth: 2,
@@ -99,19 +107,19 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
99
107
  })
100
108
  }),
101
109
  action: () => {
102
- x(!1), v?.();
110
+ C(!1), b?.();
103
111
  },
104
- disabled: !v
112
+ disabled: !b
105
113
  },
106
- ...y ? [{
114
+ ...x ? [{
107
115
  id: "reconcile",
108
116
  label: "Reconcile",
109
- icon: /* @__PURE__ */ d("svg", {
117
+ icon: /* @__PURE__ */ p("svg", {
110
118
  fill: "none",
111
119
  stroke: "currentColor",
112
120
  viewBox: "0 0 24 24",
113
121
  className: "w-4 h-4",
114
- children: /* @__PURE__ */ d("path", {
122
+ children: /* @__PURE__ */ p("path", {
115
123
  strokeLinecap: "round",
116
124
  strokeLinejoin: "round",
117
125
  strokeWidth: 2,
@@ -119,18 +127,18 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
119
127
  })
120
128
  }),
121
129
  action: () => {
122
- x(!1), y();
130
+ C(!1), x();
123
131
  }
124
132
  }] : [],
125
133
  {
126
134
  id: "exportCSV",
127
135
  label: "Export CSV",
128
- icon: /* @__PURE__ */ d("svg", {
136
+ icon: /* @__PURE__ */ p("svg", {
129
137
  fill: "none",
130
138
  stroke: "currentColor",
131
139
  viewBox: "0 0 24 24",
132
140
  className: "w-4 h-4",
133
- children: /* @__PURE__ */ d("path", {
141
+ children: /* @__PURE__ */ p("path", {
134
142
  strokeLinecap: "round",
135
143
  strokeLinejoin: "round",
136
144
  strokeWidth: 2,
@@ -138,19 +146,19 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
138
146
  })
139
147
  }),
140
148
  action: () => {
141
- x(!1), g?.();
149
+ C(!1), v?.();
142
150
  },
143
- disabled: !g
151
+ disabled: !v
144
152
  },
145
153
  {
146
154
  id: "exportPNG",
147
155
  label: "Export PNG",
148
- icon: /* @__PURE__ */ d("svg", {
156
+ icon: /* @__PURE__ */ p("svg", {
149
157
  fill: "none",
150
158
  stroke: "currentColor",
151
159
  viewBox: "0 0 24 24",
152
160
  className: "w-4 h-4",
153
- children: /* @__PURE__ */ d("path", {
161
+ children: /* @__PURE__ */ p("path", {
154
162
  strokeLinecap: "round",
155
163
  strokeLinejoin: "round",
156
164
  strokeWidth: 2,
@@ -158,26 +166,26 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
158
166
  })
159
167
  }),
160
168
  action: () => {
161
- x(!1), _?.();
169
+ C(!1), y?.();
162
170
  },
163
- disabled: !_
171
+ disabled: !y
164
172
  },
165
173
  {
166
174
  id: "divider1",
167
175
  label: "",
168
- icon: /* @__PURE__ */ d(u, {}),
176
+ icon: /* @__PURE__ */ p(f, {}),
169
177
  action: () => {},
170
178
  divider: !0
171
179
  },
172
180
  {
173
181
  id: "copy",
174
182
  label: "Copy",
175
- icon: /* @__PURE__ */ d("svg", {
183
+ icon: /* @__PURE__ */ p("svg", {
176
184
  fill: "none",
177
185
  stroke: "currentColor",
178
186
  viewBox: "0 0 24 24",
179
187
  className: "w-4 h-4",
180
- children: /* @__PURE__ */ d("path", {
188
+ children: /* @__PURE__ */ p("path", {
181
189
  strokeLinecap: "round",
182
190
  strokeLinejoin: "round",
183
191
  strokeWidth: 2,
@@ -185,20 +193,20 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
185
193
  })
186
194
  }),
187
195
  action: () => {
188
- N(i.id), x(!1);
196
+ F(o.id), C(!1);
189
197
  },
190
- disabled: !m,
191
- permitted: A
198
+ disabled: !g,
199
+ permitted: M
192
200
  },
193
201
  {
194
202
  id: "cut",
195
203
  label: "Cut",
196
- icon: /* @__PURE__ */ d("svg", {
204
+ icon: /* @__PURE__ */ p("svg", {
197
205
  fill: "none",
198
206
  stroke: "currentColor",
199
207
  viewBox: "0 0 24 24",
200
208
  className: "w-4 h-4",
201
- children: /* @__PURE__ */ d("path", {
209
+ children: /* @__PURE__ */ p("path", {
202
210
  strokeLinecap: "round",
203
211
  strokeLinejoin: "round",
204
212
  strokeWidth: 2,
@@ -206,20 +214,20 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
206
214
  })
207
215
  }),
208
216
  action: () => {
209
- P(i.id), x(!1);
217
+ I(o.id), C(!1);
210
218
  },
211
- disabled: !m,
212
- permitted: A && k
219
+ disabled: !g,
220
+ permitted: M && j
213
221
  },
214
222
  {
215
223
  id: "duplicate",
216
224
  label: "Duplicate",
217
- icon: /* @__PURE__ */ d("svg", {
225
+ icon: /* @__PURE__ */ p("svg", {
218
226
  fill: "none",
219
227
  stroke: "currentColor",
220
228
  viewBox: "0 0 24 24",
221
229
  className: "w-4 h-4",
222
- children: /* @__PURE__ */ d("path", {
230
+ children: /* @__PURE__ */ p("path", {
223
231
  strokeLinecap: "round",
224
232
  strokeLinejoin: "round",
225
233
  strokeWidth: 2,
@@ -227,34 +235,76 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
227
235
  })
228
236
  }),
229
237
  action: async () => {
230
- x(!1);
238
+ C(!1);
231
239
  let e = {
232
- x: (i.positionX ?? 0) + 1,
233
- y: (i.positionY ?? 0) + 1,
234
- width: i.positionWidth ?? 4,
235
- height: i.positionHeight ?? 4
240
+ x: (o.positionX ?? 0) + 1,
241
+ y: (o.positionY ?? 0) + 1,
242
+ width: o.positionWidth ?? 4,
243
+ height: o.positionHeight ?? 4
236
244
  };
237
- await R(i.id, e, `${i.title} (Copy)`);
245
+ await H(o.id, e, `${o.title} (Copy)`);
238
246
  },
239
- disabled: !m,
240
- permitted: A
247
+ disabled: !g,
248
+ permitted: M
241
249
  },
250
+ ...B && V.restore ? [{
251
+ id: "fleetRestore",
252
+ label: B.labels.restore,
253
+ icon: /* @__PURE__ */ p("svg", {
254
+ fill: "none",
255
+ stroke: "currentColor",
256
+ viewBox: "0 0 24 24",
257
+ className: "w-4 h-4",
258
+ children: /* @__PURE__ */ p("path", {
259
+ strokeLinecap: "round",
260
+ strokeLinejoin: "round",
261
+ strokeWidth: 2,
262
+ d: "M3 10h10a5 5 0 010 10H9M3 10l4-4m-4 4l4 4"
263
+ })
264
+ }),
265
+ action: () => {
266
+ C(!1), B.restore(o);
267
+ },
268
+ disabled: B.busy,
269
+ permitted: j
270
+ }] : [],
271
+ ...B && V.promote ? [{
272
+ id: "fleetPromote",
273
+ label: B.labels.promote,
274
+ icon: /* @__PURE__ */ p("svg", {
275
+ fill: "none",
276
+ stroke: "currentColor",
277
+ viewBox: "0 0 24 24",
278
+ className: "w-4 h-4",
279
+ children: /* @__PURE__ */ p("path", {
280
+ strokeLinecap: "round",
281
+ strokeLinejoin: "round",
282
+ strokeWidth: 2,
283
+ d: "M5 15l7-7 7 7M12 8v13"
284
+ })
285
+ }),
286
+ action: () => {
287
+ C(!1), B.promote(o);
288
+ },
289
+ disabled: B.busy,
290
+ permitted: j
291
+ }] : [],
242
292
  {
243
293
  id: "divider2",
244
294
  label: "",
245
- icon: /* @__PURE__ */ d(u, {}),
295
+ icon: /* @__PURE__ */ p(f, {}),
246
296
  action: () => {},
247
297
  divider: !0
248
298
  },
249
299
  {
250
300
  id: "delete",
251
301
  label: "Delete",
252
- icon: /* @__PURE__ */ d("svg", {
302
+ icon: /* @__PURE__ */ p("svg", {
253
303
  fill: "none",
254
304
  stroke: "currentColor",
255
305
  viewBox: "0 0 24 24",
256
306
  className: "w-4 h-4",
257
- children: /* @__PURE__ */ d("path", {
307
+ children: /* @__PURE__ */ p("path", {
258
308
  strokeLinecap: "round",
259
309
  strokeLinejoin: "round",
260
310
  strokeWidth: 2,
@@ -263,58 +313,58 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
263
313
  }),
264
314
  action: async () => {
265
315
  if (window.confirm("Are you sure you want to delete this widget?")) {
266
- x(!1);
267
- let e = await z(i.id);
268
- i.savedQueryId ? C(!e) : e || F(i.id);
269
- } else x(!1);
316
+ C(!1);
317
+ let e = await U(o.id);
318
+ o.savedQueryId ? T(!e) : e || L(o.id);
319
+ } else C(!1);
270
320
  },
271
- disabled: !m,
321
+ disabled: !g,
272
322
  destructive: !0,
273
- permitted: j
323
+ permitted: N
274
324
  }
275
- ].filter((e) => e.permitted !== !1 && (!i.savedQueryId || m && e.id === "delete")), U = H.filter((e, t) => {
325
+ ].filter((e) => e.permitted !== !1 && (!o.savedQueryId || g && e.id === "delete" || e.id === "fleetRestore" || e.id === "fleetPromote")), q = K.filter((e, t) => {
276
326
  if (!e.divider) return !0;
277
- let n = H[t - 1], r = H[t + 1];
327
+ let n = K[t - 1], r = K[t + 1];
278
328
  return n !== void 0 && r !== void 0 && !n.divider && !r.divider;
279
329
  });
280
- return U.length ? /* @__PURE__ */ f("div", {
330
+ return q.length ? /* @__PURE__ */ m("div", {
281
331
  className: "relative",
282
332
  children: [
283
- S && /* @__PURE__ */ d("span", {
333
+ w && /* @__PURE__ */ p("span", {
284
334
  role: "alert",
285
335
  children: "Could not delete this widget."
286
336
  }),
287
- /* @__PURE__ */ d("button", {
288
- ref: D,
337
+ /* @__PURE__ */ p("button", {
338
+ ref: k,
289
339
  type: "button",
290
- onClick: V,
340
+ onClick: G,
291
341
  className: `
292
342
  p-1.5 rounded-md
293
343
  text-text-secondary
294
344
  hover:text-text-primary
295
345
  hover:bg-bg-sunken
296
346
  transition-colors
297
- ${b ? "bg-bg-sunken" : ""}
347
+ ${S ? "bg-bg-sunken" : ""}
298
348
  `,
299
349
  title: "Widget options",
300
350
  "aria-haspopup": "menu",
301
- "aria-expanded": b,
302
- children: /* @__PURE__ */ f("svg", {
351
+ "aria-expanded": S,
352
+ children: /* @__PURE__ */ m("svg", {
303
353
  className: "w-4 h-4",
304
354
  fill: "currentColor",
305
355
  viewBox: "0 0 24 24",
306
356
  children: [
307
- /* @__PURE__ */ d("circle", {
357
+ /* @__PURE__ */ p("circle", {
308
358
  cx: "12",
309
359
  cy: "5",
310
360
  r: "2"
311
361
  }),
312
- /* @__PURE__ */ d("circle", {
362
+ /* @__PURE__ */ p("circle", {
313
363
  cx: "12",
314
364
  cy: "12",
315
365
  r: "2"
316
366
  }),
317
- /* @__PURE__ */ d("circle", {
367
+ /* @__PURE__ */ p("circle", {
318
368
  cx: "12",
319
369
  cy: "19",
320
370
  r: "2"
@@ -322,18 +372,18 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
322
372
  ]
323
373
  })
324
374
  }),
325
- b && p(/* @__PURE__ */ d("div", {
326
- ref: E,
375
+ S && h(/* @__PURE__ */ p("div", {
376
+ ref: O,
327
377
  style: {
328
378
  position: "fixed",
329
- top: w.top,
330
- left: w.left,
379
+ top: E.top,
380
+ left: E.left,
331
381
  zIndex: 99999
332
382
  },
333
383
  className: "\n min-w-[160px]\n py-1\n bg-bg-surface\n border border-border-default\n rounded-lg shadow-lg\n ",
334
384
  role: "menu",
335
385
  "aria-orientation": "vertical",
336
- children: U.map((e) => e.divider ? /* @__PURE__ */ d("div", { className: "my-1 border-t border-border-default" }, e.id) : /* @__PURE__ */ f("button", {
386
+ children: q.map((e) => e.divider ? /* @__PURE__ */ p("div", { className: "my-1 border-t border-border-default" }, e.id) : /* @__PURE__ */ m("button", {
337
387
  type: "button",
338
388
  onClick: (t) => {
339
389
  t.stopPropagation(), e.action();
@@ -347,10 +397,10 @@ var m = i(function({ widget: i, isEditMode: m, onRefresh: h, onExportCSV: g, onE
347
397
  ${e.destructive ? "text-status-error-text hover:text-status-error-text" : "text-text-primary"}
348
398
  `,
349
399
  role: "menuitem",
350
- children: [e.icon, /* @__PURE__ */ d("span", { children: e.label })]
400
+ children: [e.icon, /* @__PURE__ */ p("span", { children: e.label })]
351
401
  }, e.id))
352
402
  }), document.body)
353
403
  ]
354
404
  }) : null;
355
405
  });
356
- export { m as WidgetMenu, m as default };
406
+ export { g as WidgetMenu, g as default };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * useFleetConfirm (BOFF-15410)
3
+ *
4
+ * The confirmation prompt of a fleet action that replaces the owner's work: the native one where the app runs
5
+ * inside a shell that has it, the browser's otherwise.
6
+ */
7
+ export declare function useFleetConfirm(): (title: string, text: string, ok: string) => Promise<boolean>;
@@ -0,0 +1,17 @@
1
+ import { nativeConfirm as e } from "../../utils/nativeBridge.js";
2
+ import { useTr as t } from "../../shared/hooks/useTr.js";
3
+ import { useCallback as n } from "react";
4
+ // src/bigconsole/hooks/useFleetConfirm.ts
5
+ function r() {
6
+ let r = t();
7
+ return n(async (t, n, i) => {
8
+ let a = await e({
9
+ title: t,
10
+ message: n,
11
+ okButtonTitle: i,
12
+ cancelButtonTitle: r("bigconsole.fleet.link.cancel", "Cancel")
13
+ });
14
+ return a === null ? window.confirm(n) : a;
15
+ }, [r]);
16
+ }
17
+ export { r as useFleetConfirm };
@@ -0,0 +1,10 @@
1
+ import { RestoreNotice } from './useFleetCopyActions';
2
+ interface UseFleetWidgetActionsResult {
3
+ busy: boolean;
4
+ /** Puts the widget back to the master's version. Returns what could not be carried over exactly. */
5
+ restoreWidget: (widgetId: string) => Promise<RestoreNotice[]>;
6
+ /** Adds the widget to the master, which the board's widget then follows. Returns what could not be carried over. */
7
+ promoteWidget: (widgetId: string) => Promise<RestoreNotice[]>;
8
+ }
9
+ export declare function useFleetWidgetActions(): UseFleetWidgetActionsResult;
10
+ export {};
@@ -0,0 +1,41 @@
1
+ import { PromoteWidgetToMasterDocument as e, RestoreWidgetToOriginalDocument as t } from "../../generated/wspace-operations.js";
2
+ import { useCallback as n, useState as r } from "react";
3
+ import { useApolloClient as i } from "@apollo/client/react";
4
+ // src/bigconsole/hooks/useFleetWidgetActions.ts
5
+ var a = (e) => e.map((e) => ({
6
+ code: e.code,
7
+ pageName: e.pageName,
8
+ widgetId: e.widgetId
9
+ }));
10
+ function o() {
11
+ let o = i(), [s, c] = r(!1), l = n(async (e) => {
12
+ c(!0);
13
+ try {
14
+ return await e();
15
+ } finally {
16
+ c(!1);
17
+ }
18
+ }, []);
19
+ return {
20
+ busy: s,
21
+ restoreWidget: n((e) => l(async () => {
22
+ let n = (await o.mutate({
23
+ mutation: t,
24
+ variables: { widgetId: e },
25
+ errorPolicy: "none"
26
+ })).data?.restoreWidgetToOriginal;
27
+ if (!n) throw Error("The widget could not be restored.");
28
+ return a(n.notices);
29
+ }), [o, l]),
30
+ promoteWidget: n((t) => l(async () => {
31
+ let n = (await o.mutate({
32
+ mutation: e,
33
+ variables: { widgetId: t },
34
+ errorPolicy: "none"
35
+ })).data?.promoteWidgetToMaster;
36
+ if (!n) throw Error("The widget could not be promoted.");
37
+ return a(n.notices);
38
+ }), [o, l])
39
+ };
40
+ }
41
+ export { o as useFleetWidgetActions };
@@ -1,23 +1,18 @@
1
+ import { Dispatch, SetStateAction } from 'react';
1
2
  /**
2
- * useOwnerBoundRun (BOFF-15410)
3
- *
4
- * Runs an action of a fleet panel, then shows its outcome, then reads the board again, in a way that cannot
5
- * leak across boards, workspaces or accounts:
6
- *
7
- * - the outcome is shown only if the panel is still on the owner (board, workspace and account) the action
8
- * started for, so an answer that arrives after the person moved on is dropped before it touches any state;
9
- * - a failed re-read is not a failed action: the action already happened, and the read reports its own failure;
10
- * - `acting` stays true until the re-read is done, not only until the action returns, so a second click cannot
11
- * start a second action in the gap.
12
- *
13
- * When the owner changes, `onOwnerChange` lets the panel drop the state that belonged to the previous one.
14
- *
15
- * Two sections of one panel can share a lock (`useActionLock`), so an action in one holds the buttons of the
16
- * other: a board that is both a copy and a master must not start a push while a restore is still running.
17
- * A run that finishes after the panel went away is dropped too: it must not touch a board the person left.
3
+ * An action lock: which owner has an action running (`owner`, for the buttons to show), and the same fact kept
4
+ * synchronously, which is what decides whether an action may start. The state is only seen after a render; the
5
+ * synchronous side changes the instant an action starts, so two prompts answered together in different sections
6
+ * of one panel cannot both start.
18
7
  */
19
- /** The state of an action lock: which owner has an action running, or null. */
20
- export type ActionLock = readonly [string | null, (owner: string | null) => void];
8
+ export interface ActionLock {
9
+ owner: string | null;
10
+ setOwner: Dispatch<SetStateAction<string | null>>;
11
+ /** Takes the lock for the owner; false when an action of that owner already holds it. */
12
+ tryAcquire: (owner: string) => boolean;
13
+ /** Lets go of the lock if the owner still holds it. */
14
+ release: (owner: string) => void;
15
+ }
21
16
  /** One lock for the sections of a panel to share. */
22
17
  export declare function useActionLock(): ActionLock;
23
18
  interface UseOwnerBoundRunResult {