@cccsaurora/clue-ui 1.1.4 → 1.2.0-dev.109

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 (178) hide show
  1. package/ActionForm-ByeOzpc4.js +555 -0
  2. package/AnnotationDetails-DknbKDyl.js +175 -0
  3. package/AnnotationPreview-CQwKs8se.js +188 -0
  4. package/ClueEnrichContext-6NJfXpUB.js +536 -0
  5. package/FlexOne-BSYAhhtG.js +9 -0
  6. package/_Map-kgDsDYxq.js +64 -0
  7. package/_MapCache-DabaaWfq.js +161 -0
  8. package/_Uint8Array-BlVVH1tp.js +129 -0
  9. package/_baseAssignValue-CNbcU6Nb.js +25 -0
  10. package/_baseClone-D3a8Pa4T.js +284 -0
  11. package/_baseExtremum-B1o1zHjR.js +33 -0
  12. package/_baseFlatten-D4huXoEI.js +92 -0
  13. package/_baseGet-BSK_nnoz.js +109 -0
  14. package/_baseIsEqual-B5xLoweL.js +238 -0
  15. package/_baseIteratee-p6Nj07-n.js +126 -0
  16. package/_baseSlice-GAv_YFTT.js +20 -0
  17. package/_baseSum-D0WC1dN0.js +13 -0
  18. package/_baseUniq-CpupKWcL.js +89 -0
  19. package/_commonjsHelpers-DWwsNxpa.js +8 -0
  20. package/_createAggregator-BpVy5xMi.js +63 -0
  21. package/_getPrototype-D1LAdQKO.js +5 -0
  22. package/_getTag-D3ToyefI.js +126 -0
  23. package/cloneDeep-CjP5k9zW.js +8 -0
  24. package/components/AnnotationBody.js +49 -35
  25. package/components/AnnotationDetailPopover.js +36 -30
  26. package/components/AnnotationDetails.js +6 -6
  27. package/components/AnnotationEntry.js +50 -47
  28. package/components/AnnotationPreview.js +5 -5
  29. package/components/ClassificationChip.js +44 -23
  30. package/components/CountBadge.js +31 -26
  31. package/components/EnrichedCard.js +110 -97
  32. package/components/EnrichedChip.js +130 -105
  33. package/components/EnrichedTypography.js +133 -107
  34. package/components/ErrorBoundary.js +28 -24
  35. package/components/RetryFailedEnrichments.js +10 -9
  36. package/components/SourcePicker.js +57 -49
  37. package/components/actions/ActionForm.js +4 -4
  38. package/components/actions/ExecutePopover.js +64 -50
  39. package/components/actions/ResultModal.js +5 -5
  40. package/components/actions/form/schemaAdapter.js +39 -23
  41. package/components/display/graph/ExpandMoreButton.js +10 -10
  42. package/components/display/graph/elements/NodeCard.js +111 -91
  43. package/components/display/graph/elements/NodeTag.js +15 -13
  44. package/components/display/graph/index.js +261 -202
  45. package/components/display/graph/visualizations/Leaf.js +88 -69
  46. package/components/display/graph/visualizations/cloud/index.js +98 -81
  47. package/components/display/graph/visualizations/icons/BaseIcon.js +26 -21
  48. package/components/display/graph/visualizations/icons/BugIcon.js +12 -12
  49. package/components/display/graph/visualizations/icons/HostIcon.js +12 -12
  50. package/components/display/graph/visualizations/icons/NetworkIcon.js +12 -12
  51. package/components/display/graph/visualizations/icons/ProcessIcon.js +12 -12
  52. package/components/display/graph/visualizations/icons/TargetIcon.js +13 -13
  53. package/components/display/graph/visualizations/icons/index.js +14 -13
  54. package/components/display/graph/visualizations/panels/NodePanel.js +10 -8
  55. package/components/display/graph/visualizations/tree/BundleLine.js +108 -81
  56. package/components/display/graph/visualizations/tree/Triangle.js +13 -13
  57. package/components/display/graph/visualizations/tree/index.js +407 -305
  58. package/components/display/icons/Iconified.js +27 -12
  59. package/components/display/json/index.js +4 -4
  60. package/components/display/markdown/index.js +8658 -5757
  61. package/components/enrichment/EnrichPopover.js +55 -47
  62. package/components/fetchers/Fetcher.js +123 -95
  63. package/components/fetchers/PreviewModal.js +20 -17
  64. package/components/fetchers/StatusChip.js +21 -17
  65. package/components/group/Entry.js +13 -11
  66. package/components/group/Group.js +13 -10
  67. package/components/group/GroupControl.js +77 -66
  68. package/components/stats/QueryStatus.js +40 -35
  69. package/countBy-C69WslUA.js +14 -0
  70. package/data/event.js +6 -4
  71. package/database/index.js +2 -2
  72. package/debounce-bV0h5FC5.js +92 -0
  73. package/get-D3C3lEU3.js +8 -0
  74. package/groupBy-DC2oOuBN.js +14 -0
  75. package/hooks/ClueActionContext.js +7 -7
  76. package/hooks/ClueComponentContext.js +29 -23
  77. package/hooks/ClueConfigProvider.js +14 -12
  78. package/hooks/ClueDatabaseContext.js +19 -13
  79. package/hooks/ClueEnrichContext.js +8 -8
  80. package/hooks/ClueFetcherContext.js +74 -46
  81. package/hooks/ClueGroupContext.js +17 -14
  82. package/hooks/CluePopupContext.js +5 -5
  83. package/hooks/ClueProvider.js +12 -10
  84. package/hooks/selectors.js +21 -10
  85. package/hooks/useActionResult.js +2 -2
  86. package/hooks/useAnnotations.js +44 -32
  87. package/hooks/useClue.js +6 -4
  88. package/hooks/useClueActions.js +3 -3
  89. package/hooks/useClueConfig.js +6 -4
  90. package/hooks/useClueTypeConfig.js +3 -3
  91. package/hooks/useComparator.js +722 -435
  92. package/hooks/useErrors.js +22 -18
  93. package/hooks/useMyHighlights.js +66 -36
  94. package/hooks/useMyLocalStorage.js +66 -37
  95. package/iconify-CXMreGTg.js +1782 -0
  96. package/icons/Action.js +66 -49
  97. package/icons/Assessment.js +84 -68
  98. package/icons/Context.js +77 -63
  99. package/icons/Opinion.js +77 -65
  100. package/icons/iconMap.js +2 -2
  101. package/identity-CPGTqrE4.js +6 -0
  102. package/index-BDVjGvMI.js +696 -0
  103. package/index-BbPn6-Mw.js +15750 -0
  104. package/index-Bi21Wb23.js +465 -0
  105. package/index-C3lkTD69.js +1172 -0
  106. package/index-CC12Ux-9.js +17654 -0
  107. package/isEmpty-BQkZubqU.js +29 -0
  108. package/isNil-CIubwp4T.js +6 -0
  109. package/isObject-FTY-5JQX.js +7 -0
  110. package/isObjectLike-OAgjjZye.js +48 -0
  111. package/isSymbol-Xd2FsJyp.js +8 -0
  112. package/last-CUCl67Im.js +7 -0
  113. package/main.js +62 -62
  114. package/package.json +1 -1
  115. package/sortBy-B-UKp4GT.js +100 -0
  116. package/sumBy-MYkDPHZL.js +8 -0
  117. package/text/Frequency.js +42 -23
  118. package/toFinite-Bc55msYj.js +16 -0
  119. package/toNumber-DPxy1FBy.js +39 -0
  120. package/useClueTypeConfig-XvGvIw2S.js +3201 -0
  121. package/utils/chain.js +91 -64
  122. package/utils/classificationParser.js +519 -256
  123. package/utils/constants.js +35 -10
  124. package/utils/graph.js +72 -45
  125. package/utils/hashUtil.js +7 -7
  126. package/utils/line.js +131 -81
  127. package/utils/loggerUtil.js +5 -3
  128. package/utils/sessionStorage.js +41 -27
  129. package/utils/time.js +423 -423
  130. package/utils/utils.js +9 -9
  131. package/utils/window.js +21 -10
  132. package/utils-7OtvGnmf.js +200 -0
  133. package/ActionForm-myEAs2UC.js +0 -435
  134. package/AnnotationDetails-D9AJM0An.js +0 -160
  135. package/AnnotationPreview-Lb5be8ZG.js +0 -140
  136. package/ClueEnrichContext-DsFsXixD.js +0 -420
  137. package/FlexOne-BXWFOd1T.js +0 -6
  138. package/_Map-DXNg_Z-q.js +0 -54
  139. package/_MapCache-Cu25RRDU.js +0 -129
  140. package/_Uint8Array-DlJCtTvG.js +0 -102
  141. package/_baseAssignValue-CUmzp727.js +0 -20
  142. package/_baseClone-BlMmRXeX.js +0 -208
  143. package/_baseExtremum-P_0akmCi.js +0 -27
  144. package/_baseFlatten-CN7vDNEQ.js +0 -72
  145. package/_baseGet-Dgf6_xCm.js +0 -80
  146. package/_baseIsEqual-Cpjtfb3Q.js +0 -173
  147. package/_baseIteratee-CP1bocOX.js +0 -95
  148. package/_baseSlice-M5RKzt1A.js +0 -10
  149. package/_baseSum-wEbgNeUs.js +0 -10
  150. package/_baseUniq-tMFmk80M.js +0 -61
  151. package/_commonjsHelpers-DaMA6jEr.js +0 -8
  152. package/_createAggregator-B4Cav8ZM.js +0 -53
  153. package/_getPrototype-CHAFQYL_.js +0 -5
  154. package/_getTag-BV_UoLYG.js +0 -90
  155. package/cloneDeep-BPVpFBzJ.js +0 -8
  156. package/countBy-DOutsa_w.js +0 -8
  157. package/debounce-DryYcbJ4.js +0 -56
  158. package/get-Bow1vKwx.js +0 -8
  159. package/groupBy-BheQYl6f.js +0 -8
  160. package/iconify-BBckr5AQ.js +0 -1263
  161. package/identity-ByMq8VxU.js +0 -6
  162. package/index-BXxfAxFt.js +0 -12734
  163. package/index-C15OYgRY.js +0 -358
  164. package/index-E7g8cRyW.js +0 -568
  165. package/index-p5_wX7q1.js +0 -11729
  166. package/index-vF6IyBhz.js +0 -975
  167. package/isEmpty-g47Qir2A.js +0 -21
  168. package/isNil-CjWwlQS3.js +0 -6
  169. package/isObject-B53jY8Qg.js +0 -7
  170. package/isObjectLike-BatpeCIi.js +0 -29
  171. package/isSymbol-C3_SC0Qp.js +0 -8
  172. package/last-7CdUxN0r.js +0 -7
  173. package/sortBy-ITdmD17L.js +0 -79
  174. package/sumBy-DxJUU2E8.js +0 -8
  175. package/toFinite-BMy6GObD.js +0 -14
  176. package/toNumber-YVhnnJv4.js +0 -31
  177. package/useClueTypeConfig-DyeBcXQX.js +0 -2214
  178. package/utils-BnmI_6N8.js +0 -130
@@ -0,0 +1,555 @@
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-Bi21Wb23.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-XvGvIw2S.js";
10
+ import { d as toString } from "./_baseGet-BSK_nnoz.js";
11
+ import { b as baseSlice } from "./_baseSlice-GAv_YFTT.js";
12
+ import { i as isEqual } from "./utils-7OtvGnmf.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 Markdown from "./components/display/markdown/index.js";
19
+ import ClassificationChip from "./components/ClassificationChip.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
+ if (!result) {
102
+ return null;
103
+ }
104
+ 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: [
105
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [
106
+ result.action.action_icon && /* @__PURE__ */ jsx(Icon, { height: "1.5rem", icon: result.action.action_icon }),
107
+ /* @__PURE__ */ jsx(Typography, { variant: "h5", children: result.action.name }),
108
+ result.action.supported_types && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: result.action.supported_types.map((type) => type.toUpperCase()).join(", ") }),
109
+ /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
110
+ /* @__PURE__ */ jsx(ClassificationChip, { size: "small", classification: result.action.classification })
111
+ ] }),
112
+ /* @__PURE__ */ jsx(Typography, { variant: "body1", children: result.action.summary }),
113
+ /* @__PURE__ */ jsx(Divider, { flexItem: true }),
114
+ result.done ? /* @__PURE__ */ jsx(ErrorBoundary, { children: result.format === "markdown" ? /* @__PURE__ */ jsx(Markdown, { md: result.output }) : result.format === "json" ? /* @__PURE__ */ jsx(JSONViewer, { data: result.output, collapse: true, forceCompact: true }) : /* @__PURE__ */ jsxs(Stack, { sx: { overflowY: "auto" }, children: [
115
+ /* @__PURE__ */ jsx(Markdown, { md: "`" + result.format + "` is not recognized as a format in this application." }),
116
+ /* @__PURE__ */ jsx(JSONViewer, { data: result, collapse: true, forceCompact: true })
117
+ ] }) }) : /* @__PURE__ */ jsxs(Stack, { flex: 1, sx: { pt: 2, alignItems: "center" }, spacing: 1, children: [
118
+ result.summary && /* @__PURE__ */ jsx(Typography, { variant: "caption", children: result.summary }),
119
+ /* @__PURE__ */ jsx(
120
+ LinearProgress,
121
+ {
122
+ variant: ((_a = result.output) == null ? void 0 : _a.progress) ? "determinate" : "indeterminate",
123
+ value: ((_b = result.output) == null ? void 0 : _b.progress) * 100,
124
+ sx: { maxWidth: 500, width: "100%", borderRadius: (theme) => theme.shape.borderRadius }
125
+ }
126
+ )
127
+ ] }),
128
+ /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
129
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, children: [
130
+ /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
131
+ result.link && /* @__PURE__ */ jsx(Button, { variant: "outlined", component: "a", target: "_blank", href: result.link, children: t("details.open") }),
132
+ /* @__PURE__ */ jsx(Button, { variant: "outlined", color: "error", onClick: onClose, children: t("close") })
133
+ ] })
134
+ ] }) }) }) });
135
+ };
136
+ const ResultModal$1 = memo(ResultModal);
137
+ const AJV = new Ajv({ removeAdditional: true, coerceTypes: true, strict: false });
138
+ const ClueActionContext = createContext(null);
139
+ const ClueActionProvider = ({
140
+ baseURL,
141
+ children,
142
+ classification: defaultClassification,
143
+ includeContext: defaultIncludeContext,
144
+ getToken,
145
+ onNetworkCall
146
+ }) => {
147
+ const { t, i18n } = useContextSelector(ClueComponentContext, (ctx) => ctx.i18next);
148
+ const { ready } = useClue();
149
+ const [runningActionData, setRunningActionData] = useState(null);
150
+ const [actionResults, setActionResults] = useState({});
151
+ const [showResultModal, setShowResultModal] = useState(false);
152
+ const [lastResult, setLastResult] = useState(null);
153
+ const [loading, setLoading] = useState(false);
154
+ const [availableActions, setAvailableActions] = useState({});
155
+ const requestConfig = useMemo(() => {
156
+ const headers = {};
157
+ const token = getToken == null ? void 0 : getToken();
158
+ if (token) {
159
+ headers.Authorization = `Bearer ${token}`;
160
+ }
161
+ const baseConfig = { baseURL, headers };
162
+ return onNetworkCall ? onNetworkCall(baseConfig) : { baseURL, headers };
163
+ }, [baseURL, getToken, onNetworkCall]);
164
+ const refreshActions = useCallback(async () => {
165
+ if (!ready) {
166
+ return;
167
+ }
168
+ const _actions = await api.actions.get(requestConfig);
169
+ if (_actions) {
170
+ setAvailableActions(_actions);
171
+ }
172
+ return _actions;
173
+ }, [ready, requestConfig]);
174
+ useEffect(() => {
175
+ refreshActions();
176
+ }, [baseURL, ready]);
177
+ const getHashKey = useCallback(
178
+ (type, value, classification) => JSON.stringify({ type, value, classification: classification ?? defaultClassification }),
179
+ [defaultClassification]
180
+ );
181
+ const executeAction = useCallback(
182
+ async (actionId, selectors, params, options) => {
183
+ const { forceMenu, onComplete, skipMenu, skipResultModal, timeout, includeContext, extraContext } = {
184
+ forceMenu: false,
185
+ skipMenu: false,
186
+ onComplete: null,
187
+ timeout: null,
188
+ includeContext: defaultIncludeContext ?? false,
189
+ extraContext: null,
190
+ ...options
191
+ };
192
+ if (!Object.keys(availableActions).includes(actionId)) {
193
+ throw new Error("Invalid action id");
194
+ }
195
+ const stringifiedSelectors = selectors.map(
196
+ (selector) => selector.type === "telemetry" ? { ...selector, value: JSON.stringify(selector.value) } : selector
197
+ );
198
+ const actionToRun = availableActions[actionId];
199
+ const validator = AJV.compile(actionToRun.params);
200
+ const validatedParams = { selectors: stringifiedSelectors, ...params };
201
+ let context2 = null;
202
+ if (includeContext) {
203
+ context2 = {
204
+ timestamp: dayjs().toISOString(),
205
+ url: window.location,
206
+ language: (i18n == null ? void 0 : i18n.language) ?? "en"
207
+ };
208
+ }
209
+ if (!isNil(extraContext)) {
210
+ context2 = {
211
+ ...context2 ?? {},
212
+ ...extraContext
213
+ };
214
+ }
215
+ setLoading(true);
216
+ if (!validator(validatedParams) || forceMenu) {
217
+ if (skipMenu && !forceMenu) {
218
+ console.error(`Form is not valid (${validator.errors.length} errors)`);
219
+ throw new Error("Form is not completed");
220
+ }
221
+ if ((runningActionData == null ? void 0 : runningActionData.id) === actionId) {
222
+ console.error(`Form is not valid (${validator.errors.length} errors)`);
223
+ safeDispatchEvent(
224
+ new CustomEvent(SNACKBAR_EVENT_ID, {
225
+ detail: {
226
+ message: t("action.error.validation"),
227
+ level: "error"
228
+ }
229
+ })
230
+ );
231
+ }
232
+ setRunningActionData({
233
+ id: actionId,
234
+ action: actionToRun,
235
+ selectors,
236
+ params: validatedParams ?? {},
237
+ context: context2,
238
+ onComplete,
239
+ timeout
240
+ });
241
+ return;
242
+ }
243
+ try {
244
+ const actionResult = await api.actions.post(
245
+ actionId,
246
+ stringifiedSelectors,
247
+ validatedParams ?? {},
248
+ context2,
249
+ { timeout },
250
+ requestConfig
251
+ );
252
+ const actionResultWithData = { ...actionResult, actionId, action: actionToRun };
253
+ onComplete == null ? void 0 : onComplete(actionResultWithData);
254
+ setActionResults((_results) => {
255
+ const keys = selectors.map((value) => getHashKey(value.type, value.value, value.classification));
256
+ return {
257
+ ..._results,
258
+ ...keys.reduce(
259
+ (acc, key) => ({
260
+ ...acc,
261
+ [key]: [..._results[key] ?? [], actionResultWithData]
262
+ }),
263
+ {}
264
+ )
265
+ };
266
+ });
267
+ safeDispatchEvent(
268
+ new CustomEvent(SNACKBAR_EVENT_ID, {
269
+ detail: {
270
+ message: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.5, width: "100%", children: [
271
+ /* @__PURE__ */ jsx(Typography, { children: actionResult.summary }),
272
+ 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" }) })
273
+ ] }),
274
+ timeout: actionResult.link ? null : 5e3,
275
+ level: actionResult.outcome === "success" ? "success" : actionResult.outcome === "pending" ? "info" : "error",
276
+ options: {
277
+ style: {
278
+ minWidth: 0
279
+ },
280
+ SnackbarProps: {
281
+ style: {
282
+ minWidth: 0
283
+ }
284
+ }
285
+ }
286
+ }
287
+ })
288
+ );
289
+ if (actionResult.outcome === "success") {
290
+ setRunningActionData(null);
291
+ }
292
+ if (actionResult.outcome === "pending") {
293
+ setLastResult({ ...actionResult, actionId, action: actionToRun });
294
+ if (!skipResultModal) {
295
+ setShowResultModal(true);
296
+ }
297
+ }
298
+ if (actionResult.format) {
299
+ setLastResult({ ...actionResult, actionId, action: actionToRun });
300
+ if (actionResult.format !== "pivot" && !skipResultModal) {
301
+ setShowResultModal(true);
302
+ } else {
303
+ window.open(actionResult.output, "_blank", "noreferrer");
304
+ }
305
+ }
306
+ } catch (e) {
307
+ safeDispatchEvent(
308
+ new CustomEvent(SNACKBAR_EVENT_ID, {
309
+ detail: {
310
+ message: e.toString(),
311
+ level: "error"
312
+ }
313
+ })
314
+ );
315
+ } finally {
316
+ setLoading(false);
317
+ }
318
+ },
319
+ [availableActions, defaultIncludeContext, getHashKey, i18n == null ? void 0 : i18n.language, requestConfig, runningActionData == null ? void 0 : runningActionData.id, t]
320
+ );
321
+ const getActionStatus = useCallback(
322
+ async (actionId, taskId) => {
323
+ try {
324
+ const res = await api.actions.status.get(actionId, taskId, {}, requestConfig);
325
+ return res;
326
+ } catch (e) {
327
+ safeDispatchEvent(
328
+ new CustomEvent(SNACKBAR_EVENT_ID, {
329
+ detail: {
330
+ message: e.toString(),
331
+ level: "error"
332
+ }
333
+ })
334
+ );
335
+ }
336
+ },
337
+ [requestConfig]
338
+ );
339
+ const cancelAction = useCallback(() => {
340
+ setRunningActionData(null);
341
+ setLoading(false);
342
+ }, []);
343
+ const getActionResults = useCallback(
344
+ (type, value, classification) => actionResults[getHashKey(type, value, classification)] ?? [],
345
+ [actionResults, getHashKey]
346
+ );
347
+ const context = useMemo(
348
+ () => ({
349
+ availableActions,
350
+ executeAction,
351
+ cancelAction,
352
+ getActionStatus,
353
+ getActionResults,
354
+ loading,
355
+ refreshActions
356
+ }),
357
+ [availableActions, cancelAction, executeAction, getActionResults, getActionStatus, loading, refreshActions]
358
+ );
359
+ return /* @__PURE__ */ jsxs(ClueActionContext.Provider, { value: context, children: [
360
+ children,
361
+ /* @__PURE__ */ jsxs(ErrorBoundary, { children: [
362
+ runningActionData && /* @__PURE__ */ jsx(ActionForm$1, { runningActionData }),
363
+ /* @__PURE__ */ jsx(
364
+ ResultModal$1,
365
+ {
366
+ show: showResultModal && !!lastResult,
367
+ result: lastResult,
368
+ onClose: () => setShowResultModal(false)
369
+ }
370
+ )
371
+ ] })
372
+ ] });
373
+ };
374
+ const useClueActions = () => {
375
+ return useContext(ClueActionContext);
376
+ };
377
+ const WRAPPED_RENDERERS = materialRenderers.map((value) => ({
378
+ ...value,
379
+ renderer: ({ ...props }) => /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(value.renderer, { ...props }) })
380
+ }));
381
+ const ActionForm = ({ runningActionData }) => {
382
+ const { executeAction, cancelAction } = useClueActions();
383
+ const { t } = useContextSelector(ClueComponentContext, (ctx) => ctx.i18next);
384
+ const [loading, setLoading] = useState(false);
385
+ const [errors, setErrors] = useState(null);
386
+ const [formData, setFormData] = useState(runningActionData == null ? void 0 : runningActionData.params);
387
+ const [showFormDataJson, setShowFormDataJson] = useState(false);
388
+ const formSchema = useMemo(
389
+ () => (runningActionData == null ? void 0 : runningActionData.action) ? { ...adaptSchema(runningActionData.action.params), ...runningActionData.action.extra_schema ?? {} } : null,
390
+ [runningActionData == null ? void 0 : runningActionData.action]
391
+ );
392
+ const uiSchema = useMemo(
393
+ () => ({
394
+ type: "VerticalLayout",
395
+ elements: Object.entries((formSchema == null ? void 0 : formSchema.properties) ?? {}).sort(([a_key, a_ent], [b_key, b_ent]) => {
396
+ if (!!a_ent.order || !!b_ent.order) {
397
+ return a_ent.order - b_ent.order;
398
+ } else {
399
+ return +(formSchema == null ? void 0 : formSchema.required.includes(a_key)) - +(formSchema == null ? void 0 : formSchema.required.includes(b_key));
400
+ }
401
+ }).map(([key, value]) => {
402
+ var _a;
403
+ return {
404
+ type: "Control",
405
+ scope: `#/properties/${key}`,
406
+ options: {
407
+ autocomplete: !!value.enum || ((_a = value.options) == null ? void 0 : _a.autocomplete),
408
+ showUnfocusedDescription: true,
409
+ ...value.options
410
+ },
411
+ rule: value.rule
412
+ };
413
+ })
414
+ }),
415
+ [formSchema == null ? void 0 : formSchema.properties, formSchema == null ? void 0 : formSchema.required]
416
+ );
417
+ const execute = useCallback(async () => {
418
+ try {
419
+ setLoading(true);
420
+ const options = {};
421
+ if (runningActionData == null ? void 0 : runningActionData.onComplete) {
422
+ options.onComplete = runningActionData == null ? void 0 : runningActionData.onComplete;
423
+ }
424
+ if (runningActionData == null ? void 0 : runningActionData.timeout) {
425
+ options.timeout = runningActionData == null ? void 0 : runningActionData.timeout;
426
+ }
427
+ await executeAction(runningActionData == null ? void 0 : runningActionData.id, runningActionData == null ? void 0 : runningActionData.selectors, formData, options);
428
+ } catch (e) {
429
+ console.error(e);
430
+ } finally {
431
+ setLoading(false);
432
+ }
433
+ }, [
434
+ executeAction,
435
+ runningActionData == null ? void 0 : runningActionData.id,
436
+ runningActionData == null ? void 0 : runningActionData.selectors,
437
+ runningActionData == null ? void 0 : runningActionData.onComplete,
438
+ runningActionData == null ? void 0 : runningActionData.timeout,
439
+ formData
440
+ ]);
441
+ if (!(runningActionData == null ? void 0 : runningActionData.action)) {
442
+ return;
443
+ }
444
+ try {
445
+ return /* @__PURE__ */ jsx(Modal, { open: true, sx: { display: "flex", alignItems: "center", justifyContent: "center" }, onClose: cancelAction, children: /* @__PURE__ */ jsx(
446
+ Paper,
447
+ {
448
+ sx: { maxHeight: "80%", maxWidth: "80%", height: "100%", px: 2, pt: 2, minWidth: "750px", overflow: "auto" },
449
+ children: /* @__PURE__ */ jsxs(
450
+ Stack,
451
+ {
452
+ spacing: 1,
453
+ height: "100%",
454
+ sx: {
455
+ ".MuiFormHelperText-root": {
456
+ marginLeft: "0 !important",
457
+ "&:last-of-type": { mb: 3 }
458
+ }
459
+ },
460
+ children: [
461
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, children: [
462
+ /* @__PURE__ */ jsxs(Stack, { direction: "column", spacing: 1, children: [
463
+ /* @__PURE__ */ jsxs(Typography, { variant: "h5", children: [
464
+ t("actions.executing"),
465
+ " ",
466
+ runningActionData == null ? void 0 : runningActionData.action.id.replace(/_/g, " ").split(" ").map(capitalize).join(" ")
467
+ ] }),
468
+ (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 })
469
+ ] }),
470
+ /* @__PURE__ */ jsx(Box, { flex: 1 }),
471
+ /* @__PURE__ */ jsx(Box, { alignContent: "end", children: /* @__PURE__ */ jsx(
472
+ Button,
473
+ {
474
+ variant: "outlined",
475
+ onClick: () => setShowFormDataJson((prev) => !prev),
476
+ startIcon: /* @__PURE__ */ jsx(
477
+ Box,
478
+ {
479
+ component: "span",
480
+ sx: (theme) => ({
481
+ transition: theme.transitions.create("transform"),
482
+ transform: showFormDataJson ? "rotate(180deg)" : "rotate(0deg)"
483
+ }),
484
+ children: /* @__PURE__ */ jsx(Iconified, { icon: "ic:baseline-keyboard-double-arrow-right" })
485
+ }
486
+ ),
487
+ children: !showFormDataJson ? t("actions.json.show") : t("actions.json.hide")
488
+ }
489
+ ) })
490
+ ] }),
491
+ /* @__PURE__ */ jsx(Divider, { orientation: "horizontal", variant: "middle" }),
492
+ /* @__PURE__ */ jsx(Box, { pt: 1.5 }),
493
+ /* @__PURE__ */ jsxs(Stack, { flexGrow: 1, direction: "row", spacing: 1, children: [
494
+ /* @__PURE__ */ jsxs(Stack, { direction: "column", flexGrow: 1, children: [
495
+ /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(
496
+ JsonForms,
497
+ {
498
+ schema: formSchema,
499
+ uischema: uiSchema,
500
+ renderers: WRAPPED_RENDERERS,
501
+ cells: materialCells,
502
+ data: formData,
503
+ onChange: ({ data, errors: _errors }) => {
504
+ if (!isEqual(data, formData)) {
505
+ setFormData(data);
506
+ }
507
+ setErrors(_errors);
508
+ },
509
+ config: {}
510
+ }
511
+ ) }),
512
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, pb: 1, children: [
513
+ /* @__PURE__ */ jsx("div", { style: { flex: 1 } }),
514
+ /* @__PURE__ */ jsx(Button, { color: "error", variant: "outlined", onClick: cancelAction, children: t("cancel") }),
515
+ /* @__PURE__ */ jsx(
516
+ Button,
517
+ {
518
+ color: "success",
519
+ variant: "outlined",
520
+ disabled: loading || (errors == null ? void 0 : errors.length) > 0,
521
+ onClick: execute,
522
+ endIcon: loading && /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 18 }),
523
+ children: t("actions.execute")
524
+ }
525
+ )
526
+ ] })
527
+ ] }),
528
+ /* @__PURE__ */ jsx(Collapse, { orientation: "horizontal", in: showFormDataJson, unmountOnExit: true, mountOnEnter: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "row", height: "100%", spacing: 1, children: [
529
+ /* @__PURE__ */ jsx(Divider, { orientation: "vertical" }),
530
+ /* @__PURE__ */ jsxs(Stack, { children: [
531
+ /* @__PURE__ */ jsx(Typography, { variant: "h5", children: t("action.data") }),
532
+ /* @__PURE__ */ jsx(Box, { width: 600, height: "100%", children: /* @__PURE__ */ jsx(JSONViewer, { data: formData, slotProps: { stack: { height: "100%" }, json: { name: false } } }) })
533
+ ] })
534
+ ] }) })
535
+ ] })
536
+ ]
537
+ }
538
+ )
539
+ }
540
+ ) });
541
+ } catch (e) {
542
+ console.warn(e);
543
+ return null;
544
+ }
545
+ };
546
+ const ActionForm$1 = memo(ActionForm);
547
+ export {
548
+ ActionForm$1 as A,
549
+ ClueActionProvider as C,
550
+ ResultModal$1 as R,
551
+ ClueActionContext as a,
552
+ useActionResult as b,
553
+ capitalize as c,
554
+ useClueActions as u
555
+ };