@cccsaurora/clue-ui 1.2.0-dev.241 → 1.2.0-dev.249

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 (80) hide show
  1. package/ActionForm-C0aE9HUv.js +5941 -0
  2. package/{AnnotationDetails-BEHFNNv3.js → AnnotationDetails-CEou0vCc.js} +3 -3
  3. package/{AnnotationPreview-MO5UsP5l.js → AnnotationPreview-CLMVD6Ec.js} +3 -3
  4. package/{ClueEnrichContext-DoOHQeVr.js → ClueEnrichContext-BkD9ZwM9.js} +3 -3
  5. package/{_Uint8Array-BYE8bXpl.js → _Uint8Array-DdG4KLKn.js} +1 -1
  6. package/{_baseClone-BZWIR6v5.js → _baseClone-BpWiBnMp.js} +1 -1
  7. package/{_baseExtremum-CvA2lsVF.js → _baseExtremum-BY663UjY.js} +1 -1
  8. package/{_baseFlatten-hXNFmTLV.js → _baseFlatten-B69cDsaV.js} +1 -1
  9. package/{_baseIsEqual-CIc2ClfN.js → _baseIsEqual-B4IufFlL.js} +1 -1
  10. package/{_baseIteratee-B7fb_3hC.js → _baseIteratee-7AQvAy1o.js} +2 -2
  11. package/{_createAggregator-WsSxBVpS.js → _createAggregator-CwGPThny.js} +2 -2
  12. package/{cloneDeep-CASxfDJM.js → cloneDeep-DmUylbkM.js} +1 -1
  13. package/components/AnnotationDetailPopover.js +1 -1
  14. package/components/AnnotationDetails.js +4 -4
  15. package/components/AnnotationEntry.js +1 -1
  16. package/components/AnnotationPreview.js +3 -3
  17. package/components/EnrichedCard.js +4 -4
  18. package/components/EnrichedChip.js +5 -5
  19. package/components/EnrichedTypography.js +5 -5
  20. package/components/RetryFailedEnrichments.js +2 -2
  21. package/components/SourcePicker.js +3 -3
  22. package/components/actions/ActionForm.js +4 -4
  23. package/components/actions/ExecutePopover.js +2 -2
  24. package/components/actions/ResultModal.js +2 -2
  25. package/components/actions/form/schemaAdapter.js +1 -1
  26. package/components/actions/formats/FileResult.js +1 -1
  27. package/components/actions/formats/index.js +1 -1
  28. package/components/display/graph/elements/NodeCard.js +4 -4
  29. package/components/display/graph/index.js +4 -4
  30. package/components/display/graph/visualizations/cloud/index.js +3 -3
  31. package/components/display/graph/visualizations/tree/BundleLine.js +1 -1
  32. package/components/display/graph/visualizations/tree/index.js +2 -2
  33. package/components/display/json/index.js +3 -3
  34. package/components/enrichment/EnrichPopover.js +1 -2
  35. package/components/fetchers/Fetcher.js +5 -5
  36. package/components/fetchers/StatusChip.js +1 -1
  37. package/components/group/Entry.js +4 -4
  38. package/components/group/Group.js +2 -2
  39. package/components/group/GroupControl.js +2 -3
  40. package/components/stats/QueryStatus.js +1 -1
  41. package/{countBy-BM48i7TV.js → countBy-DqlU5OwT.js} +1 -1
  42. package/database/index.js +1 -1
  43. package/fr/translation.json +1 -1
  44. package/{groupBy-mXHt-nYT.js → groupBy-ChDRT7uy.js} +1 -1
  45. package/hooks/ClueActionContext.d.ts +5 -0
  46. package/hooks/ClueActionContext.js +3 -4
  47. package/hooks/ClueComponentContext.js +1 -1
  48. package/hooks/ClueDatabaseContext.js +1 -1
  49. package/hooks/ClueEnrichContext.js +3 -3
  50. package/hooks/ClueFetcherContext.js +1 -1
  51. package/hooks/ClueGroupContext.js +2 -2
  52. package/hooks/CluePopupContext.js +3 -3
  53. package/hooks/ClueProvider.js +3 -3
  54. package/hooks/selectors.js +9 -21
  55. package/hooks/useActionResult.js +2 -2
  56. package/hooks/useAnnotations.js +2 -2
  57. package/hooks/useClue.js +2 -2
  58. package/hooks/useClueActions.js +2 -2
  59. package/hooks/useErrors.js +1 -1
  60. package/hooks/useFetcherResult.js +1 -1
  61. package/icons/Action.js +4 -4
  62. package/icons/Assessment.js +6 -6
  63. package/icons/Context.js +3 -3
  64. package/icons/Opinion.js +6 -6
  65. package/{index-BDVjGvMI.js → index-AMfoEg_6.js} +49 -49
  66. package/{index-C3lkTD69.js → index-B6C2a_Lg.js} +1 -1
  67. package/{index-CC12Ux-9.js → index-C12gPw2W.js} +15818 -15774
  68. package/{index-BbPn6-Mw.js → index-DCKkHTvx.js} +39 -39
  69. package/{index-Bmoj6JY8.js → index-UkW8Sur3.js} +2 -2
  70. package/main.js +9 -10
  71. package/package.json +2 -2
  72. package/{sortBy-B0zptFuY.js → sortBy-C7mGPI_D.js} +4 -4
  73. package/{sumBy-ByJNa2hf.js → sumBy-CGALjmwQ.js} +1 -1
  74. package/text/Frequency.js +1 -1
  75. package/types/RunningActionData.d.ts +2 -0
  76. package/utils/chain.js +7 -7
  77. package/utils/time.js +4 -4
  78. package/utils/utils.js +1 -1
  79. package/{utils-CW9CNV1h.js → utils-71DpzFrA.js} +1 -1
  80. package/ActionForm-U5a2mLUv.js +0 -557
@@ -1,557 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { materialRenderers, materialCells } from "@jsonforms/material-renderers";
3
- import { JsonForms } from "@jsonforms/react";
4
- import { Modal, Paper, Stack, Typography, Divider, LinearProgress, Button, IconButton, Box, CircularProgress, Collapse } from "@mui/material";
5
- import Iconified from "./components/display/icons/Iconified.js";
6
- import { J as JSONViewer } from "./index-Bmoj6JY8.js";
7
- import { ClueComponentContext } from "./hooks/ClueComponentContext.js";
8
- import { A as Ajv } from "./index-CC12Ux-9.js";
9
- import { a as api } from "./useClueTypeConfig-D2tf4-NM.js";
10
- import { d as toString } from "./_baseGet-Bx3A4Qfp.js";
11
- import { b as baseSlice } from "./_baseSlice-GAv_YFTT.js";
12
- import { i as isEqual } from "./utils-CW9CNV1h.js";
13
- import { useState, useRef, useMemo, useEffect, memo, useCallback } from "react";
14
- import { u as useContextSelector, c as createContext, a as useContext } from "./index-BDVjGvMI.js";
15
- import ErrorBoundary from "./components/ErrorBoundary.js";
16
- import { adaptSchema } from "./components/actions/form/schemaAdapter.js";
17
- import { I as Icon } from "./iconify-CXMreGTg.js";
18
- import ClassificationChip from "./components/ClassificationChip.js";
19
- import Result from "./components/actions/formats/index.js";
20
- import { SNACKBAR_EVENT_ID } from "./data/event.js";
21
- import { dayjs } from "./utils/time.js";
22
- import { safeDispatchEvent } from "./utils/window.js";
23
- import useClue from "./hooks/useClue.js";
24
- import { i as isNil } from "./isNil-CIubwp4T.js";
25
- function castSlice(array, start, end) {
26
- var length = array.length;
27
- end = end === void 0 ? length : end;
28
- return !start && end >= length ? array : baseSlice(array, start, end);
29
- }
30
- var rsAstralRange$1 = "\\ud800-\\udfff", rsComboMarksRange$1 = "\\u0300-\\u036f", reComboHalfMarksRange$1 = "\\ufe20-\\ufe2f", rsComboSymbolsRange$1 = "\\u20d0-\\u20ff", rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1, rsVarRange$1 = "\\ufe0e\\ufe0f";
31
- var rsZWJ$1 = "\\u200d";
32
- var reHasUnicode = RegExp("[" + rsZWJ$1 + rsAstralRange$1 + rsComboRange$1 + rsVarRange$1 + "]");
33
- function hasUnicode(string) {
34
- return reHasUnicode.test(string);
35
- }
36
- function asciiToArray(string) {
37
- return string.split("");
38
- }
39
- var rsAstralRange = "\\ud800-\\udfff", rsComboMarksRange = "\\u0300-\\u036f", reComboHalfMarksRange = "\\ufe20-\\ufe2f", rsComboSymbolsRange = "\\u20d0-\\u20ff", rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, rsVarRange = "\\ufe0e\\ufe0f";
40
- var rsAstral = "[" + rsAstralRange + "]", rsCombo = "[" + rsComboRange + "]", rsFitz = "\\ud83c[\\udffb-\\udfff]", rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")", rsNonAstral = "[^" + rsAstralRange + "]", rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}", rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]", rsZWJ = "\\u200d";
41
- var reOptMod = rsModifier + "?", rsOptVar = "[" + rsVarRange + "]?", rsOptJoin = "(?:" + rsZWJ + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*", rsSeq = rsOptVar + reOptMod + rsOptJoin, rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")";
42
- var reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g");
43
- function unicodeToArray(string) {
44
- return string.match(reUnicode) || [];
45
- }
46
- function stringToArray(string) {
47
- return hasUnicode(string) ? unicodeToArray(string) : asciiToArray(string);
48
- }
49
- function createCaseFirst(methodName) {
50
- return function(string) {
51
- string = toString(string);
52
- var strSymbols = hasUnicode(string) ? stringToArray(string) : void 0;
53
- var chr = strSymbols ? strSymbols[0] : string.charAt(0);
54
- var trailing = strSymbols ? castSlice(strSymbols, 1).join("") : string.slice(1);
55
- return chr[methodName]() + trailing;
56
- };
57
- }
58
- var upperFirst = createCaseFirst("toUpperCase");
59
- function capitalize(string) {
60
- return upperFirst(toString(string).toLowerCase());
61
- }
62
- const useActionResult = (resultWithData, interval = 2e3) => {
63
- const [result, setResult] = useState(resultWithData);
64
- const timeoutRef = useRef(null);
65
- const { getActionStatus } = useClueActions();
66
- const taskId = useMemo(() => resultWithData == null ? void 0 : resultWithData.task_id, [resultWithData == null ? void 0 : resultWithData.task_id]);
67
- const actionId = useMemo(() => resultWithData == null ? void 0 : resultWithData.actionId, [resultWithData == null ? void 0 : resultWithData.actionId]);
68
- useEffect(() => {
69
- if ((resultWithData == null ? void 0 : resultWithData.outcome) !== "pending" || !taskId) return;
70
- let cancelled = false;
71
- const poll = async () => {
72
- const res = await getActionStatus(actionId, taskId);
73
- if (!res) {
74
- setResult({ outcome: "failure", done: true });
75
- } else if (res.outcome === "success" || res.outcome === "failure") {
76
- setResult({ ...res, done: true });
77
- } else {
78
- if (cancelled) return;
79
- setResult({ ...res });
80
- timeoutRef.current = setTimeout(poll, interval);
81
- }
82
- };
83
- poll();
84
- return () => {
85
- cancelled = true;
86
- if (timeoutRef.current) clearTimeout(timeoutRef.current);
87
- };
88
- }, [actionId, getActionStatus, interval, resultWithData == null ? void 0 : resultWithData.outcome, taskId]);
89
- useEffect(() => {
90
- setResult(resultWithData);
91
- }, [resultWithData]);
92
- return useMemo(
93
- () => resultWithData || result ? { ...resultWithData, ...result } : void 0,
94
- [resultWithData, result]
95
- );
96
- };
97
- const ResultModal = ({ result: _result, onClose, show = false }) => {
98
- var _a, _b;
99
- const { t } = useContextSelector(ClueComponentContext, (ctx) => ctx.i18next);
100
- const result = useActionResult(_result);
101
- const resultFinished = useMemo(
102
- () => (result == null ? void 0 : result.outcome) === "success" || (result == null ? void 0 : result.outcome) === "failure" || (result == null ? void 0 : result.done),
103
- [result == null ? void 0 : result.done, result == null ? void 0 : result.outcome]
104
- );
105
- if (!result) {
106
- return null;
107
- }
108
- return /* @__PURE__ */ jsx(Modal, { open: show, sx: { display: "flex", alignItems: "center", justifyContent: "center" }, onClose, children: /* @__PURE__ */ jsx(Paper, { sx: { maxHeight: "80%", maxWidth: "80%", height: "100%", p: 2, minWidth: "750px" }, children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsxs(Stack, { spacing: 1, height: "100%", children: [
109
- /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [
110
- result.action.action_icon && /* @__PURE__ */ jsx(Icon, { height: "1.5rem", icon: result.action.action_icon }),
111
- /* @__PURE__ */ jsx(Typography, { variant: "h5", children: result.action.name }),
112
- result.action.supported_types && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: result.action.supported_types.map((type) => type.toUpperCase()).join(", ") }),
113
- /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
114
- /* @__PURE__ */ jsx(ClassificationChip, { size: "small", classification: result.action.classification })
115
- ] }),
116
- /* @__PURE__ */ jsx(Typography, { variant: "body1", children: result.action.summary }),
117
- /* @__PURE__ */ jsx(Divider, { flexItem: true }),
118
- resultFinished ? /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(Result, { result }) }) : /* @__PURE__ */ jsxs(Stack, { flex: 1, sx: { pt: 2, alignItems: "center" }, spacing: 1, children: [
119
- result.summary && /* @__PURE__ */ jsx(Typography, { variant: "caption", children: result.summary }),
120
- /* @__PURE__ */ jsx(
121
- LinearProgress,
122
- {
123
- variant: ((_a = result.output) == null ? void 0 : _a.progress) ? "determinate" : "indeterminate",
124
- value: ((_b = result.output) == null ? void 0 : _b.progress) * 100,
125
- sx: { maxWidth: 500, width: "100%", borderRadius: (theme) => theme.shape.borderRadius }
126
- }
127
- )
128
- ] }),
129
- /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
130
- /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, children: [
131
- /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
132
- result.link && /* @__PURE__ */ jsx(Button, { variant: "outlined", component: "a", target: "_blank", href: result.link, children: t("details.open") }),
133
- /* @__PURE__ */ jsx(Button, { variant: "outlined", color: "error", onClick: onClose, children: t("close") })
134
- ] })
135
- ] }) }) }) });
136
- };
137
- const ResultModal$1 = memo(ResultModal);
138
- const AJV = new Ajv({ removeAdditional: true, coerceTypes: true, strict: false });
139
- const ClueActionContext = createContext(null);
140
- const ClueActionProvider = ({
141
- baseURL,
142
- children,
143
- classification: defaultClassification,
144
- includeContext: defaultIncludeContext,
145
- getToken,
146
- onNetworkCall
147
- }) => {
148
- const { t, i18n } = useContextSelector(ClueComponentContext, (ctx) => ctx.i18next);
149
- const { ready } = useClue();
150
- const [runningActionData, setRunningActionData] = useState(null);
151
- const [actionResults, setActionResults] = useState({});
152
- const [showResultModal, setShowResultModal] = useState(false);
153
- const [lastResult, setLastResult] = useState(null);
154
- const [loading, setLoading] = useState(false);
155
- const [availableActions, setAvailableActions] = useState({});
156
- const requestConfig = useMemo(() => {
157
- const headers = {};
158
- const token = getToken == null ? void 0 : getToken();
159
- if (token) {
160
- headers.Authorization = `Bearer ${token}`;
161
- }
162
- const baseConfig = { baseURL, headers };
163
- return onNetworkCall ? onNetworkCall(baseConfig) : { baseURL, headers };
164
- }, [baseURL, getToken, onNetworkCall]);
165
- const refreshActions = useCallback(async () => {
166
- if (!ready) {
167
- return;
168
- }
169
- const _actions = await api.actions.get(requestConfig);
170
- if (_actions) {
171
- setAvailableActions(_actions);
172
- }
173
- return _actions;
174
- }, [ready, requestConfig]);
175
- useEffect(() => {
176
- refreshActions();
177
- }, [baseURL, ready]);
178
- const getHashKey = useCallback(
179
- (type, value, classification) => JSON.stringify({ type, value, classification: classification ?? defaultClassification }),
180
- [defaultClassification]
181
- );
182
- const executeAction = useCallback(
183
- async (actionId, selectors, params, options) => {
184
- const { forceMenu, onComplete, skipMenu, skipResultModal, timeout, includeContext, extraContext } = {
185
- forceMenu: false,
186
- skipMenu: false,
187
- skipResultModal: false,
188
- onComplete: null,
189
- timeout: null,
190
- includeContext: defaultIncludeContext ?? false,
191
- extraContext: null,
192
- ...options
193
- };
194
- if (!Object.keys(availableActions).includes(actionId)) {
195
- throw new Error("Invalid action id");
196
- }
197
- const stringifiedSelectors = selectors.map(
198
- (selector) => selector.type === "telemetry" ? { ...selector, value: JSON.stringify(selector.value) } : selector
199
- );
200
- const actionToRun = availableActions[actionId];
201
- const validator = AJV.compile(actionToRun.params);
202
- const validatedParams = { selectors: stringifiedSelectors, ...params };
203
- let context2 = null;
204
- if (includeContext) {
205
- context2 = {
206
- timestamp: dayjs().toISOString(),
207
- url: window.location,
208
- language: (i18n == null ? void 0 : i18n.language) ?? "en"
209
- };
210
- }
211
- if (!isNil(extraContext)) {
212
- context2 = {
213
- ...context2 ?? {},
214
- ...extraContext
215
- };
216
- }
217
- setLoading(true);
218
- if (!validator(validatedParams) || forceMenu) {
219
- if (skipMenu && !forceMenu) {
220
- console.error(`Form is not valid (${validator.errors.length} errors)`);
221
- throw new Error("Form is not completed");
222
- }
223
- if ((runningActionData == null ? void 0 : runningActionData.id) === actionId) {
224
- console.error(`Form is not valid (${validator.errors.length} errors)`);
225
- safeDispatchEvent(
226
- new CustomEvent(SNACKBAR_EVENT_ID, {
227
- detail: {
228
- message: t("action.error.validation"),
229
- level: "error"
230
- }
231
- })
232
- );
233
- }
234
- setRunningActionData({
235
- id: actionId,
236
- action: actionToRun,
237
- selectors,
238
- params: validatedParams ?? {},
239
- context: context2,
240
- onComplete,
241
- timeout
242
- });
243
- return;
244
- }
245
- try {
246
- const actionResult = await api.actions.post(
247
- actionId,
248
- stringifiedSelectors,
249
- validatedParams ?? {},
250
- context2,
251
- { timeout },
252
- requestConfig
253
- );
254
- const actionResultWithData = { ...actionResult, actionId, action: actionToRun };
255
- onComplete == null ? void 0 : onComplete(actionResultWithData);
256
- setActionResults((_results) => {
257
- const keys = selectors.map((value) => getHashKey(value.type, value.value, value.classification));
258
- return {
259
- ..._results,
260
- ...keys.reduce(
261
- (acc, key) => ({
262
- ...acc,
263
- [key]: [..._results[key] ?? [], actionResultWithData]
264
- }),
265
- {}
266
- )
267
- };
268
- });
269
- safeDispatchEvent(
270
- new CustomEvent(SNACKBAR_EVENT_ID, {
271
- detail: {
272
- message: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.5, width: "100%", children: [
273
- /* @__PURE__ */ jsx(Typography, { children: actionResult.summary }),
274
- actionResult.link && /* @__PURE__ */ jsx(IconButton, { component: "a", href: actionResult.link, size: "small", target: "_blank", children: /* @__PURE__ */ jsx(Iconified, { icon: "ic:baseline-open-in-new", fontSize: "small" }) })
275
- ] }),
276
- timeout: actionResult.link ? null : 5e3,
277
- level: actionResult.outcome === "success" ? "success" : actionResult.outcome === "pending" ? "info" : "error",
278
- options: {
279
- style: {
280
- minWidth: 0
281
- },
282
- SnackbarProps: {
283
- style: {
284
- minWidth: 0
285
- }
286
- }
287
- }
288
- }
289
- })
290
- );
291
- if (actionResult.outcome === "success") {
292
- setRunningActionData(null);
293
- }
294
- if (actionResult.outcome === "pending") {
295
- setLastResult({ ...actionResult, actionId, action: actionToRun });
296
- if (!skipResultModal) {
297
- setShowResultModal(true);
298
- }
299
- }
300
- if (actionResult.format) {
301
- setLastResult({ ...actionResult, actionId, action: actionToRun });
302
- if (actionResult.format !== "pivot" && !skipResultModal) {
303
- setShowResultModal(true);
304
- } else {
305
- window.open(actionResult.output, "_blank", "noreferrer");
306
- }
307
- }
308
- } catch (e) {
309
- safeDispatchEvent(
310
- new CustomEvent(SNACKBAR_EVENT_ID, {
311
- detail: {
312
- message: e.toString(),
313
- level: "error"
314
- }
315
- })
316
- );
317
- } finally {
318
- setLoading(false);
319
- }
320
- },
321
- [availableActions, defaultIncludeContext, getHashKey, i18n == null ? void 0 : i18n.language, requestConfig, runningActionData == null ? void 0 : runningActionData.id, t]
322
- );
323
- const getActionStatus = useCallback(
324
- async (actionId, taskId) => {
325
- try {
326
- const res = await api.actions.status.get(actionId, taskId, {}, requestConfig);
327
- return res;
328
- } catch (e) {
329
- safeDispatchEvent(
330
- new CustomEvent(SNACKBAR_EVENT_ID, {
331
- detail: {
332
- message: e.toString(),
333
- level: "error"
334
- }
335
- })
336
- );
337
- }
338
- },
339
- [requestConfig]
340
- );
341
- const cancelAction = useCallback(() => {
342
- setRunningActionData(null);
343
- setLoading(false);
344
- }, []);
345
- const getActionResults = useCallback(
346
- (type, value, classification) => actionResults[getHashKey(type, value, classification)] ?? [],
347
- [actionResults, getHashKey]
348
- );
349
- const context = useMemo(
350
- () => ({
351
- availableActions,
352
- executeAction,
353
- cancelAction,
354
- getActionStatus,
355
- getActionResults,
356
- loading,
357
- refreshActions
358
- }),
359
- [availableActions, cancelAction, executeAction, getActionResults, getActionStatus, loading, refreshActions]
360
- );
361
- return /* @__PURE__ */ jsxs(ClueActionContext.Provider, { value: context, children: [
362
- children,
363
- /* @__PURE__ */ jsxs(ErrorBoundary, { children: [
364
- runningActionData && /* @__PURE__ */ jsx(ActionForm$1, { runningActionData }),
365
- /* @__PURE__ */ jsx(
366
- ResultModal$1,
367
- {
368
- show: showResultModal && !!lastResult,
369
- result: lastResult,
370
- onClose: () => setShowResultModal(false)
371
- }
372
- )
373
- ] })
374
- ] });
375
- };
376
- const useClueActions = () => {
377
- return useContext(ClueActionContext);
378
- };
379
- const WRAPPED_RENDERERS = materialRenderers.map((value) => ({
380
- ...value,
381
- renderer: ({ ...props }) => /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(value.renderer, { ...props }) })
382
- }));
383
- const ActionForm = ({ runningActionData }) => {
384
- const { executeAction, cancelAction } = useClueActions();
385
- const { t } = useContextSelector(ClueComponentContext, (ctx) => ctx.i18next);
386
- const [loading, setLoading] = useState(false);
387
- const [errors, setErrors] = useState(null);
388
- const [formData, setFormData] = useState(runningActionData == null ? void 0 : runningActionData.params);
389
- const [showFormDataJson, setShowFormDataJson] = useState(false);
390
- const formSchema = useMemo(
391
- () => (runningActionData == null ? void 0 : runningActionData.action) ? { ...adaptSchema(runningActionData.action.params), ...runningActionData.action.extra_schema ?? {} } : null,
392
- [runningActionData == null ? void 0 : runningActionData.action]
393
- );
394
- const uiSchema = useMemo(
395
- () => ({
396
- type: "VerticalLayout",
397
- elements: Object.entries((formSchema == null ? void 0 : formSchema.properties) ?? {}).sort(([a_key, a_ent], [b_key, b_ent]) => {
398
- if (!!a_ent.order || !!b_ent.order) {
399
- return a_ent.order - b_ent.order;
400
- } else {
401
- return +(formSchema == null ? void 0 : formSchema.required.includes(a_key)) - +(formSchema == null ? void 0 : formSchema.required.includes(b_key));
402
- }
403
- }).map(([key, value]) => {
404
- var _a;
405
- return {
406
- type: "Control",
407
- scope: `#/properties/${key}`,
408
- options: {
409
- autocomplete: !!value.enum || ((_a = value.options) == null ? void 0 : _a.autocomplete),
410
- showUnfocusedDescription: true,
411
- ...value.options
412
- },
413
- rule: value.rule
414
- };
415
- })
416
- }),
417
- [formSchema == null ? void 0 : formSchema.properties, formSchema == null ? void 0 : formSchema.required]
418
- );
419
- const execute = useCallback(async () => {
420
- try {
421
- setLoading(true);
422
- const options = {};
423
- if (runningActionData == null ? void 0 : runningActionData.onComplete) {
424
- options.onComplete = runningActionData == null ? void 0 : runningActionData.onComplete;
425
- }
426
- if (runningActionData == null ? void 0 : runningActionData.timeout) {
427
- options.timeout = runningActionData == null ? void 0 : runningActionData.timeout;
428
- }
429
- await executeAction(runningActionData == null ? void 0 : runningActionData.id, runningActionData == null ? void 0 : runningActionData.selectors, formData, options);
430
- } catch (e) {
431
- console.error(e);
432
- } finally {
433
- setLoading(false);
434
- }
435
- }, [
436
- executeAction,
437
- runningActionData == null ? void 0 : runningActionData.id,
438
- runningActionData == null ? void 0 : runningActionData.selectors,
439
- runningActionData == null ? void 0 : runningActionData.onComplete,
440
- runningActionData == null ? void 0 : runningActionData.timeout,
441
- formData
442
- ]);
443
- if (!(runningActionData == null ? void 0 : runningActionData.action)) {
444
- return;
445
- }
446
- try {
447
- return /* @__PURE__ */ jsx(Modal, { open: true, sx: { display: "flex", alignItems: "center", justifyContent: "center" }, onClose: cancelAction, children: /* @__PURE__ */ jsx(
448
- Paper,
449
- {
450
- sx: { maxHeight: "80%", maxWidth: "80%", height: "100%", px: 2, pt: 2, minWidth: "750px", overflow: "auto" },
451
- children: /* @__PURE__ */ jsxs(
452
- Stack,
453
- {
454
- spacing: 1,
455
- height: "100%",
456
- sx: {
457
- ".MuiFormHelperText-root": {
458
- marginLeft: "0 !important",
459
- "&:last-of-type": { mb: 3 }
460
- }
461
- },
462
- children: [
463
- /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, children: [
464
- /* @__PURE__ */ jsxs(Stack, { direction: "column", spacing: 1, children: [
465
- /* @__PURE__ */ jsxs(Typography, { variant: "h5", children: [
466
- t("actions.executing"),
467
- " ",
468
- runningActionData == null ? void 0 : runningActionData.action.id.replace(/_/g, " ").split(" ").map(capitalize).join(" ")
469
- ] }),
470
- (runningActionData == null ? void 0 : runningActionData.action.summary) && /* @__PURE__ */ jsx(Typography, { variant: "body1", color: "text.secondary", sx: { pb: 1.5 }, children: runningActionData == null ? void 0 : runningActionData.action.summary })
471
- ] }),
472
- /* @__PURE__ */ jsx(Box, { flex: 1 }),
473
- /* @__PURE__ */ jsx(Box, { alignContent: "end", children: /* @__PURE__ */ jsx(
474
- Button,
475
- {
476
- variant: "outlined",
477
- onClick: () => setShowFormDataJson((prev) => !prev),
478
- startIcon: /* @__PURE__ */ jsx(
479
- Box,
480
- {
481
- component: "span",
482
- sx: (theme) => ({
483
- transition: theme.transitions.create("transform"),
484
- transform: showFormDataJson ? "rotate(180deg)" : "rotate(0deg)"
485
- }),
486
- children: /* @__PURE__ */ jsx(Iconified, { icon: "ic:baseline-keyboard-double-arrow-right" })
487
- }
488
- ),
489
- children: !showFormDataJson ? t("actions.json.show") : t("actions.json.hide")
490
- }
491
- ) })
492
- ] }),
493
- /* @__PURE__ */ jsx(Divider, { orientation: "horizontal", variant: "middle" }),
494
- /* @__PURE__ */ jsx(Box, { pt: 1.5 }),
495
- /* @__PURE__ */ jsxs(Stack, { flexGrow: 1, direction: "row", spacing: 1, children: [
496
- /* @__PURE__ */ jsxs(Stack, { direction: "column", flexGrow: 1, children: [
497
- /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(
498
- JsonForms,
499
- {
500
- schema: formSchema,
501
- uischema: uiSchema,
502
- renderers: WRAPPED_RENDERERS,
503
- cells: materialCells,
504
- data: formData,
505
- onChange: ({ data, errors: _errors }) => {
506
- if (!isEqual(data, formData)) {
507
- setFormData(data);
508
- }
509
- setErrors(_errors);
510
- },
511
- config: {}
512
- }
513
- ) }),
514
- /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, pb: 1, children: [
515
- /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
516
- /* @__PURE__ */ jsx(Button, { color: "error", variant: "outlined", onClick: cancelAction, children: t("cancel") }),
517
- /* @__PURE__ */ jsx(
518
- Button,
519
- {
520
- color: "success",
521
- variant: "outlined",
522
- disabled: loading || (errors == null ? void 0 : errors.length) > 0,
523
- onClick: execute,
524
- endIcon: loading && /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 18 }),
525
- children: t("actions.execute")
526
- }
527
- )
528
- ] })
529
- ] }),
530
- /* @__PURE__ */ jsx(Collapse, { orientation: "horizontal", in: showFormDataJson, unmountOnExit: true, mountOnEnter: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "row", height: "100%", spacing: 1, children: [
531
- /* @__PURE__ */ jsx(Divider, { orientation: "vertical" }),
532
- /* @__PURE__ */ jsxs(Stack, { children: [
533
- /* @__PURE__ */ jsx(Typography, { variant: "h5", children: t("action.data") }),
534
- /* @__PURE__ */ jsx(Box, { width: 600, height: "100%", children: /* @__PURE__ */ jsx(JSONViewer, { data: formData, slotProps: { stack: { height: "100%" }, json: { name: false } } }) })
535
- ] })
536
- ] }) })
537
- ] })
538
- ]
539
- }
540
- )
541
- }
542
- ) });
543
- } catch (e) {
544
- console.warn(e);
545
- return null;
546
- }
547
- };
548
- const ActionForm$1 = memo(ActionForm);
549
- export {
550
- ActionForm$1 as A,
551
- ClueActionProvider as C,
552
- ResultModal$1 as R,
553
- ClueActionContext as a,
554
- useActionResult as b,
555
- capitalize as c,
556
- useClueActions as u
557
- };