@box/metadata-editor 1.60.0 → 1.61.0
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/esm/lib/components/metadata-editor-fields/metadata-editor-field-wrapper.js +91 -90
- package/dist/esm/lib/components/metadata-instance-editor/subcomponents/metadata-instance-form-autofill-button/metadata-instance-form-autofill-button.js +57 -55
- package/dist/esm/lib/utils/autofill-context.js +50 -46
- package/dist/types/lib/types.d.ts +1 -0
- package/dist/types/lib/utils/autofill-context.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,141 +1,142 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFormikContext as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { memo as
|
|
1
|
+
import C from "clsx";
|
|
2
|
+
import { useFormikContext as M } from "formik";
|
|
3
|
+
import oo from "lodash/isEqual";
|
|
4
|
+
import eo from "lodash/isUndefined";
|
|
5
|
+
import { memo as io, forwardRef as to, useCallback as a, useEffect as K, useMemo as no } from "react";
|
|
6
6
|
import { A as p } from "../../../../chunks/types.js";
|
|
7
|
-
import { checkIfHasBoundingBoxes as
|
|
8
|
-
import { isInteractiveFormElement as
|
|
7
|
+
import { checkIfHasBoundingBoxes as so } from "../../utils/check-if-has-bounding-boxes.js";
|
|
8
|
+
import { isInteractiveFormElement as q } from "../../utils/is-interactive-form-element.js";
|
|
9
9
|
import { s as d } from "../../../../chunks/shared-field-styles.module.js";
|
|
10
|
-
import { UpdateModeFieldWrapper as
|
|
11
|
-
import { editorFieldTypes as
|
|
10
|
+
import { UpdateModeFieldWrapper as ro } from "./components/update-mode-field-wrapper/update-mode-field-wrapper.js";
|
|
11
|
+
import { editorFieldTypes as co } from "./editor-field-types.js";
|
|
12
12
|
import { s as f } from "../../../../chunks/utils2.js";
|
|
13
|
-
import { jsx as m, jsxs as
|
|
14
|
-
import { isConfidenceScoreNeedingReview as
|
|
15
|
-
import { AiSuggestionField as
|
|
16
|
-
import { LowConfidenceSuggestionField as
|
|
17
|
-
const
|
|
13
|
+
import { jsx as m, jsxs as ao } from "react/jsx-runtime";
|
|
14
|
+
import { isConfidenceScoreNeedingReview as w } from "../../utils/confidence-score/is-confidence-score-needing-review.js";
|
|
15
|
+
import { AiSuggestionField as po } from "./components/ai-suggestion-field/ai-suggestion-field.js";
|
|
16
|
+
import { LowConfidenceSuggestionField as uo } from "./components/low-confidence-suggestion-field/low-confidence-suggestion-field.js";
|
|
17
|
+
const Vo = /* @__PURE__ */ io(/* @__PURE__ */ to(({
|
|
18
18
|
disableForm: x,
|
|
19
19
|
portalElement: N,
|
|
20
|
-
field:
|
|
21
|
-
index:
|
|
20
|
+
field: o,
|
|
21
|
+
index: H,
|
|
22
22
|
taxonomyOptionsFetcher: I,
|
|
23
|
-
isExternallyOwned:
|
|
24
|
-
isMultilevelTaxonomyFieldEnabled:
|
|
23
|
+
isExternallyOwned: L,
|
|
24
|
+
isMultilevelTaxonomyFieldEnabled: V,
|
|
25
25
|
isConfidenceScoreReviewEnabled: s = !1,
|
|
26
26
|
onSelectMetadataField: n,
|
|
27
|
-
selectedMetadataFieldId:
|
|
28
|
-
},
|
|
27
|
+
selectedMetadataFieldId: z
|
|
28
|
+
}, P) => {
|
|
29
29
|
const {
|
|
30
|
-
setFieldValue:
|
|
31
|
-
} =
|
|
30
|
+
setFieldValue: i
|
|
31
|
+
} = M(), h = o.aiSuggestionState || p.Initial, c = h === p.Pending, B = h === p.Applied, T = h === p.Initial, y = co[o.type], {
|
|
32
32
|
aiSuggestion: r,
|
|
33
|
-
aiSuggestionConfidenceScore:
|
|
33
|
+
aiSuggestionConfidenceScore: $,
|
|
34
|
+
aiSuggestionTargetLocation: W,
|
|
34
35
|
type: l,
|
|
35
36
|
value: u
|
|
36
|
-
} =
|
|
37
|
-
[f.aiApproved]:
|
|
37
|
+
} = o, G = y && !o.hidden, J = !eo(o.updateMode), e = `metadata.fields[${H}]`, Q = o.type === "taxonomy" && o.optionsRules?.multiSelect, k = s && !!o.confidenceScore, F = k && w(o.confidenceScore), X = k && !c && !w(o.confidenceScore), D = z === o.id, Y = so(o.targetLocation), S = k && Y && !!n, Z = C({
|
|
38
|
+
[f.aiApproved]: B || X,
|
|
38
39
|
[f.hasSuggestion]: c,
|
|
39
|
-
[f.hasConfidenceReview]: !c &&
|
|
40
|
+
[f.hasConfidenceReview]: !c && F,
|
|
40
41
|
[f.dateField]: l === "date"
|
|
41
|
-
}), g = a((
|
|
42
|
-
|
|
43
|
-
}, [
|
|
44
|
-
|
|
45
|
-
}, [
|
|
46
|
-
g(p.Initial),
|
|
47
|
-
}, [g,
|
|
48
|
-
|
|
49
|
-
}, [
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
}, [
|
|
53
|
-
|
|
54
|
-
}, [
|
|
55
|
-
n && (
|
|
56
|
-
}, [
|
|
57
|
-
if (
|
|
58
|
-
if (!n ||
|
|
42
|
+
}), g = a((t) => {
|
|
43
|
+
i(`${e}.aiSuggestionState`, t);
|
|
44
|
+
}, [e, i]), A = a((t) => {
|
|
45
|
+
i(`${e}.value`, t), g(p.Applied), s && (i(`${e}.confidenceScore`, $), i(`${e}.aiSuggestionConfidenceScore`, void 0), i(`${e}.targetLocation`, W), i(`${e}.aiSuggestionTargetLocation`, void 0));
|
|
46
|
+
}, [e, i, g, $, W, s]), v = a(() => {
|
|
47
|
+
g(p.Initial), i(`${e}.aiSuggestion`, void 0), s && (i(`${e}.aiSuggestionConfidenceScore`, void 0), i(`${e}.aiSuggestionTargetLocation`, void 0));
|
|
48
|
+
}, [g, i, e, s]), _ = a(() => {
|
|
49
|
+
i(`${e}.confidenceScore.isAccepted`, !0), n?.(null);
|
|
50
|
+
}, [e, i, n]), b = a(() => {
|
|
51
|
+
const t = l === "multiSelect" || l === "taxonomy" ? [] : "";
|
|
52
|
+
i(`${e}.value`, t), i(`${e}.confidenceScore`, void 0), n?.(null);
|
|
53
|
+
}, [e, i, l, n]), U = a(() => {
|
|
54
|
+
v(), s && o.confidenceScore && (i(`${e}.confidenceScore`, void 0), n?.(null));
|
|
55
|
+
}, [v, s, o.confidenceScore, i, e, n]), O = a((t) => {
|
|
56
|
+
n && (q(t.target) || n(o));
|
|
57
|
+
}, [o, n]), E = a((t) => {
|
|
58
|
+
if (t.key === "Enter") {
|
|
59
|
+
if (!n || q(t.target))
|
|
59
60
|
return;
|
|
60
|
-
|
|
61
|
+
t.preventDefault(), t.stopPropagation(), n(o);
|
|
61
62
|
}
|
|
62
|
-
}, [
|
|
63
|
+
}, [o, n]);
|
|
63
64
|
K(() => {
|
|
64
65
|
c && (!u || Array.isArray(u) && u.length === 0) && A(r);
|
|
65
66
|
}, [r, c, A]), K(() => {
|
|
66
|
-
|
|
67
|
-
}, [
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
67
|
+
T && r && g(p.Pending);
|
|
68
|
+
}, [T, r, g]);
|
|
69
|
+
const R = no(() => r ? oo(u, r) : !1, [r, u]);
|
|
70
|
+
if (!G)
|
|
70
71
|
return null;
|
|
71
72
|
const j = {
|
|
72
73
|
"data-metadata-field": !0,
|
|
73
74
|
"data-testid": "metadata-field",
|
|
74
|
-
onClick:
|
|
75
|
-
onKeyDown:
|
|
75
|
+
onClick: O,
|
|
76
|
+
onKeyDown: E,
|
|
76
77
|
role: "button",
|
|
77
78
|
tabIndex: 0
|
|
78
79
|
};
|
|
79
|
-
if (
|
|
80
|
-
const
|
|
81
|
-
fieldNamePrefix:
|
|
82
|
-
fieldType:
|
|
83
|
-
isTaxonomyMultiSelect:
|
|
80
|
+
if (J) {
|
|
81
|
+
const t = /* @__PURE__ */ m(ro, {
|
|
82
|
+
fieldNamePrefix: e,
|
|
83
|
+
fieldType: o.type,
|
|
84
|
+
isTaxonomyMultiSelect: Q,
|
|
84
85
|
children: /* @__PURE__ */ m(y, {
|
|
85
|
-
ref:
|
|
86
|
-
description:
|
|
86
|
+
ref: P,
|
|
87
|
+
description: o.description,
|
|
87
88
|
disableForm: x,
|
|
88
|
-
fieldNamePrefix:
|
|
89
|
+
fieldNamePrefix: e,
|
|
89
90
|
isAiSuggestionApplied: !1,
|
|
90
|
-
isExternallyOwned:
|
|
91
|
-
isMultilevelTaxonomyFieldEnabled:
|
|
92
|
-
label:
|
|
93
|
-
levels:
|
|
91
|
+
isExternallyOwned: L,
|
|
92
|
+
isMultilevelTaxonomyFieldEnabled: V,
|
|
93
|
+
label: o.displayName,
|
|
94
|
+
levels: o.levels,
|
|
94
95
|
onValueEdited: U,
|
|
95
96
|
portalElement: N,
|
|
96
97
|
taxonomyOptionsFetcher: I
|
|
97
98
|
})
|
|
98
|
-
},
|
|
99
|
+
}, o.key);
|
|
99
100
|
return S ? /* @__PURE__ */ m("div", {
|
|
100
|
-
className:
|
|
101
|
+
className: C(d.spacious, d.clickableField, D && d.selectedField),
|
|
101
102
|
...j,
|
|
102
|
-
children:
|
|
103
|
-
}) :
|
|
103
|
+
children: t
|
|
104
|
+
}) : t;
|
|
104
105
|
}
|
|
105
|
-
return /* @__PURE__ */
|
|
106
|
-
className:
|
|
106
|
+
return /* @__PURE__ */ ao("div", {
|
|
107
|
+
className: C(f.fieldWrapper, s && d.spacious, S && d.clickableField, S && D && d.selectedField),
|
|
107
108
|
...S && j,
|
|
108
109
|
children: [/* @__PURE__ */ m(y, {
|
|
109
|
-
ref:
|
|
110
|
-
className:
|
|
111
|
-
description:
|
|
110
|
+
ref: P,
|
|
111
|
+
className: Z,
|
|
112
|
+
description: o.description,
|
|
112
113
|
disableForm: x,
|
|
113
|
-
fieldNamePrefix:
|
|
114
|
-
isAiSuggestionApplied:
|
|
115
|
-
isExternallyOwned:
|
|
116
|
-
confidenceScore: s && !c ?
|
|
117
|
-
isMultilevelTaxonomyFieldEnabled:
|
|
118
|
-
label:
|
|
114
|
+
fieldNamePrefix: e,
|
|
115
|
+
isAiSuggestionApplied: B,
|
|
116
|
+
isExternallyOwned: L,
|
|
117
|
+
confidenceScore: s && !c ? o.confidenceScore : void 0,
|
|
118
|
+
isMultilevelTaxonomyFieldEnabled: V,
|
|
119
|
+
label: o.displayName,
|
|
119
120
|
onValueEdited: U,
|
|
120
121
|
portalElement: N,
|
|
121
122
|
taxonomyOptionsFetcher: I
|
|
122
|
-
}), c && /* @__PURE__ */ m(
|
|
123
|
+
}), c && /* @__PURE__ */ m(po, {
|
|
123
124
|
aiSuggestion: r,
|
|
124
|
-
confidenceLevel: s ?
|
|
125
|
-
isSameValue:
|
|
125
|
+
confidenceLevel: s ? $?.level : void 0,
|
|
126
|
+
isSameValue: R,
|
|
126
127
|
onAiSuggestionAppend: () => {
|
|
127
|
-
const
|
|
128
|
-
A(
|
|
128
|
+
const t = [...new Set([u, r].flat().filter(Boolean))];
|
|
129
|
+
A(t);
|
|
129
130
|
},
|
|
130
|
-
onAiSuggestionIgnore:
|
|
131
|
+
onAiSuggestionIgnore: v,
|
|
131
132
|
onAiSuggestionReplace: () => A(r),
|
|
132
133
|
type: l
|
|
133
|
-
}), !c &&
|
|
134
|
-
onAccept:
|
|
135
|
-
onClear:
|
|
134
|
+
}), !c && F && /* @__PURE__ */ m(uo, {
|
|
135
|
+
onAccept: _,
|
|
136
|
+
onClear: b
|
|
136
137
|
})]
|
|
137
|
-
},
|
|
138
|
+
}, o.key);
|
|
138
139
|
}));
|
|
139
140
|
export {
|
|
140
|
-
|
|
141
|
+
Vo as MetadataEditorFieldWrapper
|
|
141
142
|
};
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Tooltip as
|
|
2
|
-
import { BoxAiAdvancedLogo24 as
|
|
3
|
-
import { useLocalStorageAIAgents as
|
|
4
|
-
import { useFormikContext as
|
|
5
|
-
import { useEffect as
|
|
6
|
-
import { useIntl as
|
|
7
|
-
import { EXTRACT_AI_AGENT_LOCAL_STORAGE_KEY as
|
|
8
|
-
import { autofillMessages as
|
|
9
|
-
import { useAutofill as
|
|
10
|
-
import { getTooltipContent as
|
|
1
|
+
import { Tooltip as N, Button as E, LoadingIndicator as R, IconButton as v, SplitButton as x, DropdownMenu as G, Text as D } from "@box/blueprint-web";
|
|
2
|
+
import { BoxAiAdvancedLogo24 as K, BoxAiLogo24 as O } from "@box/blueprint-web-assets/icons/Logo";
|
|
3
|
+
import { useLocalStorageAIAgents as j } from "@box/box-ai-agent-selector";
|
|
4
|
+
import { useFormikContext as w, getIn as f } from "formik";
|
|
5
|
+
import { useEffect as F, useMemo as P, forwardRef as Y, useState as V } from "react";
|
|
6
|
+
import { useIntl as k } from "react-intl";
|
|
7
|
+
import { EXTRACT_AI_AGENT_LOCAL_STORAGE_KEY as X, EXTRACT_AGENTS_MAP as M } from "../../../../constants.js";
|
|
8
|
+
import { autofillMessages as q } from "../../../../messages.js";
|
|
9
|
+
import { useAutofill as z } from "../../../../utils/autofill-context.js";
|
|
10
|
+
import { getTooltipContent as H } from "../../../../utils/utils.js";
|
|
11
11
|
import p from "./messages.js";
|
|
12
|
-
import { jsx as t, jsxs as
|
|
13
|
-
import '../../../../../../styles/metadata-instance-form-autofill-button.css';const
|
|
14
|
-
loadingIndicator:
|
|
15
|
-
actionMenuItem:
|
|
16
|
-
splitButtonIcon:
|
|
17
|
-
},
|
|
12
|
+
import { jsx as t, jsxs as J } from "react/jsx-runtime";
|
|
13
|
+
import '../../../../../../styles/metadata-instance-form-autofill-button.css';const Q = "_loadingIndicator_i1hyy_1", U = "_actionMenuItem_i1hyy_11", W = "_splitButtonIcon_i1hyy_17", T = {
|
|
14
|
+
loadingIndicator: Q,
|
|
15
|
+
actionMenuItem: U,
|
|
16
|
+
splitButtonIcon: W
|
|
17
|
+
}, Z = /* @__PURE__ */ Y(({
|
|
18
18
|
isButtonDisabled: I,
|
|
19
19
|
onAutofill: A,
|
|
20
|
-
onAgentChange:
|
|
20
|
+
onAgentChange: c,
|
|
21
21
|
storedAgent: B,
|
|
22
22
|
icon: e,
|
|
23
23
|
..._
|
|
24
24
|
}, h) => {
|
|
25
|
-
const n =
|
|
26
|
-
a(o),
|
|
25
|
+
const n = k(), [u, a] = V(B || "standard"), i = (o) => {
|
|
26
|
+
a(o), c(o), setTimeout(() => {
|
|
27
27
|
A(o);
|
|
28
28
|
}, 0);
|
|
29
29
|
};
|
|
30
|
-
return /* @__PURE__ */ t(
|
|
30
|
+
return /* @__PURE__ */ t(x, {
|
|
31
31
|
..._,
|
|
32
32
|
ref: h,
|
|
33
33
|
disabled: I,
|
|
@@ -36,19 +36,19 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
|
|
|
36
36
|
label: n.formatMessage(p.autofillButton),
|
|
37
37
|
onClick: () => A(),
|
|
38
38
|
variant: "secondary",
|
|
39
|
-
children: /* @__PURE__ */ t(
|
|
39
|
+
children: /* @__PURE__ */ t(G.RadioGroup, {
|
|
40
40
|
onValueChange: (o) => i(o),
|
|
41
|
-
value:
|
|
41
|
+
value: u,
|
|
42
42
|
children: Object.entries(M).map(([o, s]) => {
|
|
43
|
-
const
|
|
44
|
-
return /* @__PURE__ */ t(
|
|
43
|
+
const m = s.ICON;
|
|
44
|
+
return /* @__PURE__ */ t(G.RadioSelectItem, {
|
|
45
45
|
value: s.AGENT_TYPE,
|
|
46
|
-
children: /* @__PURE__ */
|
|
46
|
+
children: /* @__PURE__ */ J("div", {
|
|
47
47
|
className: T.actionMenuItem,
|
|
48
|
-
children: [/* @__PURE__ */ t(
|
|
48
|
+
children: [/* @__PURE__ */ t(m, {
|
|
49
49
|
"aria-hidden": !0,
|
|
50
50
|
className: T.splitButtonIcon
|
|
51
|
-
}), /* @__PURE__ */ t(
|
|
51
|
+
}), /* @__PURE__ */ t(D, {
|
|
52
52
|
as: "span",
|
|
53
53
|
children: n.formatMessage(p[s.DISPLAY_MSG])
|
|
54
54
|
})]
|
|
@@ -57,10 +57,10 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
|
|
|
57
57
|
})
|
|
58
58
|
})
|
|
59
59
|
});
|
|
60
|
-
}),
|
|
60
|
+
}), mt = ({
|
|
61
61
|
areAiSuggestionsAvailable: I,
|
|
62
62
|
isBetaLanguageEnabled: A,
|
|
63
|
-
isLoading:
|
|
63
|
+
isLoading: c,
|
|
64
64
|
variant: B = "secondary-button",
|
|
65
65
|
isAdvancedExtractAgentEnabled: e = !1,
|
|
66
66
|
onAutofill: _
|
|
@@ -68,37 +68,39 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
|
|
|
68
68
|
const {
|
|
69
69
|
isSubmitting: h,
|
|
70
70
|
values: n,
|
|
71
|
-
setFieldValue:
|
|
72
|
-
} =
|
|
71
|
+
setFieldValue: u
|
|
72
|
+
} = w(), a = k(), [i, o] = j(X), {
|
|
73
73
|
suggestions: s,
|
|
74
|
-
confidenceScores:
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
confidenceScores: m,
|
|
75
|
+
targetLocations: b
|
|
76
|
+
} = z();
|
|
77
|
+
F(() => {
|
|
77
78
|
if (s) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
return
|
|
79
|
+
const d = f(n, "metadata.fields"), l = f(n, "metadata.templateKey");
|
|
80
|
+
u("metadata.fields", d?.map((r) => {
|
|
81
|
+
const g = s?.[l]?.[r.key];
|
|
82
|
+
return g ? {
|
|
82
83
|
...r,
|
|
83
|
-
aiSuggestion:
|
|
84
|
-
aiSuggestionConfidenceScore:
|
|
84
|
+
aiSuggestion: g,
|
|
85
|
+
aiSuggestionConfidenceScore: m?.[l]?.[r.key],
|
|
86
|
+
aiSuggestionTargetLocation: b?.[l]?.[r.key]
|
|
85
87
|
} : r;
|
|
86
88
|
}));
|
|
87
89
|
}
|
|
88
|
-
}, [s,
|
|
89
|
-
const S = (
|
|
90
|
-
const
|
|
91
|
-
_(
|
|
92
|
-
}, y = !I || h ||
|
|
93
|
-
return B === "secondary-button" ? /* @__PURE__ */ t(
|
|
94
|
-
content:
|
|
95
|
-
children: e ? /* @__PURE__ */ t(
|
|
90
|
+
}, [s, m, b, u]);
|
|
91
|
+
const S = (d) => {
|
|
92
|
+
const l = f(n, "metadata.templateKey"), r = f(n, "metadata.scope"), g = d ? M[d]?.AGENT_ID : M[i]?.AGENT_ID;
|
|
93
|
+
_(l, r, e ? g : void 0);
|
|
94
|
+
}, y = !I || h || c, C = i === "enhanced" && e ? K : O, L = P(() => H(e, i, a), [e, i, a]);
|
|
95
|
+
return B === "secondary-button" ? /* @__PURE__ */ t(N, {
|
|
96
|
+
content: L,
|
|
97
|
+
children: e ? /* @__PURE__ */ t(Z, {
|
|
96
98
|
icon: C,
|
|
97
99
|
isButtonDisabled: y,
|
|
98
100
|
onAgentChange: o,
|
|
99
101
|
onAutofill: S,
|
|
100
102
|
storedAgent: i
|
|
101
|
-
}) : /* @__PURE__ */ t(
|
|
103
|
+
}) : /* @__PURE__ */ t(E, {
|
|
102
104
|
disabled: y,
|
|
103
105
|
icon: C,
|
|
104
106
|
onClick: () => S(),
|
|
@@ -106,13 +108,13 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
|
|
|
106
108
|
"data-target-id": "Button-autofillButton",
|
|
107
109
|
children: a.formatMessage(p.autofillButton)
|
|
108
110
|
})
|
|
109
|
-
}) : /* @__PURE__ */ t(
|
|
110
|
-
content:
|
|
111
|
-
children:
|
|
111
|
+
}) : /* @__PURE__ */ t(N, {
|
|
112
|
+
content: L,
|
|
113
|
+
children: c ? /* @__PURE__ */ t(R, {
|
|
112
114
|
"aria-label": a.formatMessage(p.loadingButtonAriaLabel),
|
|
113
115
|
className: T.loadingIndicator
|
|
114
|
-
}) : /* @__PURE__ */ t(
|
|
115
|
-
"aria-label": a.formatMessage(
|
|
116
|
+
}) : /* @__PURE__ */ t(v, {
|
|
117
|
+
"aria-label": a.formatMessage(q.autofillButtonAriaLabel),
|
|
116
118
|
disabled: y,
|
|
117
119
|
icon: C,
|
|
118
120
|
onClick: () => S(),
|
|
@@ -122,5 +124,5 @@ import '../../../../../../styles/metadata-instance-form-autofill-button.css';con
|
|
|
122
124
|
});
|
|
123
125
|
};
|
|
124
126
|
export {
|
|
125
|
-
|
|
127
|
+
mt as MetadataInstanceFormAutofillButton
|
|
126
128
|
};
|
|
@@ -1,64 +1,68 @@
|
|
|
1
|
-
import A, { createContext as
|
|
2
|
-
import { TEMPLATE_CUSTOM_PROPERTIES as
|
|
3
|
-
import { jsx as
|
|
4
|
-
const
|
|
5
|
-
children:
|
|
6
|
-
isAiSuggestionsFeatureEnabled:
|
|
1
|
+
import A, { createContext as P, useState as n, useCallback as h, useMemo as _, useContext as p } from "react";
|
|
2
|
+
import { TEMPLATE_CUSTOM_PROPERTIES as I } from "../constants.js";
|
|
3
|
+
import { jsx as M } from "react/jsx-runtime";
|
|
4
|
+
const j = 1e4, w = /* @__PURE__ */ P(null), y = ({
|
|
5
|
+
children: r,
|
|
6
|
+
isAiSuggestionsFeatureEnabled: i,
|
|
7
7
|
fetchSuggestions: l
|
|
8
8
|
}) => {
|
|
9
|
-
const [
|
|
9
|
+
const [c, g] = n({}), [S, m] = n({}), [C, d] = n({}), [a, u] = n(!1), [E, f] = n(!1);
|
|
10
10
|
A.useEffect(() => {
|
|
11
|
-
let
|
|
12
|
-
return
|
|
11
|
+
let t;
|
|
12
|
+
return a ? t = setTimeout(() => {
|
|
13
13
|
f(!0);
|
|
14
|
-
},
|
|
15
|
-
}, [
|
|
16
|
-
const
|
|
17
|
-
let
|
|
18
|
-
if (!
|
|
14
|
+
}, j) : (f(!1), clearTimeout(t)), () => clearTimeout(t);
|
|
15
|
+
}, [a]);
|
|
16
|
+
const T = h(async (t, O, x) => {
|
|
17
|
+
let s = [];
|
|
18
|
+
if (!i)
|
|
19
19
|
throw new Error("AI Suggestions feature not available.");
|
|
20
|
-
if (
|
|
20
|
+
if (t === I)
|
|
21
21
|
throw new Error("Can't fetch suggestions for Custom Metadata instance");
|
|
22
|
-
|
|
22
|
+
u(!0);
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
...
|
|
26
|
-
[
|
|
27
|
-
...Object.fromEntries(
|
|
24
|
+
s = await l(t, O, x || void 0), g({
|
|
25
|
+
...c,
|
|
26
|
+
[t]: {
|
|
27
|
+
...Object.fromEntries(s.map((o) => [o.key, o.aiSuggestion]))
|
|
28
28
|
}
|
|
29
|
-
}), m((
|
|
30
|
-
...
|
|
31
|
-
[
|
|
29
|
+
}), m((o) => ({
|
|
30
|
+
...o,
|
|
31
|
+
[t]: Object.fromEntries(s.filter((e) => e.aiSuggestionConfidenceScore).map((e) => [e.key, e.aiSuggestionConfidenceScore]))
|
|
32
|
+
})), d((o) => ({
|
|
33
|
+
...o,
|
|
34
|
+
[t]: Object.fromEntries(s.filter((e) => e.targetLocation).map((e) => [e.key, e.targetLocation]))
|
|
32
35
|
}));
|
|
33
36
|
} catch {
|
|
34
37
|
} finally {
|
|
35
|
-
|
|
38
|
+
u(!1);
|
|
36
39
|
}
|
|
37
|
-
return
|
|
38
|
-
}, [
|
|
39
|
-
g({}), m({}),
|
|
40
|
-
}, []),
|
|
41
|
-
clearState:
|
|
40
|
+
return s;
|
|
41
|
+
}, [i, c, l]), L = h(() => {
|
|
42
|
+
g({}), m({}), d({}), u(!1), f(!1);
|
|
43
|
+
}, []), v = _(() => ({
|
|
44
|
+
clearState: L,
|
|
42
45
|
confidenceScores: S,
|
|
43
|
-
getAiSuggestions:
|
|
44
|
-
isAiSuggestionsFeatureEnabled:
|
|
45
|
-
isFetchingSuggestions:
|
|
46
|
-
isLongLoading:
|
|
47
|
-
suggestions:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
getAiSuggestions: T,
|
|
47
|
+
isAiSuggestionsFeatureEnabled: i,
|
|
48
|
+
isFetchingSuggestions: a,
|
|
49
|
+
isLongLoading: E,
|
|
50
|
+
suggestions: c,
|
|
51
|
+
targetLocations: C
|
|
52
|
+
}), [L, S, T, i, a, E, c, C]);
|
|
53
|
+
return /* @__PURE__ */ M(w.Provider, {
|
|
54
|
+
value: v,
|
|
55
|
+
children: r
|
|
52
56
|
});
|
|
53
|
-
},
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
57
|
+
}, U = () => {
|
|
58
|
+
const r = p(w);
|
|
59
|
+
if (!r)
|
|
56
60
|
throw new Error("useAutofill should be wrapped inside AutofillProvider");
|
|
57
|
-
return
|
|
61
|
+
return r;
|
|
58
62
|
};
|
|
59
63
|
export {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
w as AutofillContext,
|
|
65
|
+
y as AutofillContextProvider,
|
|
66
|
+
j as TIMEOUT_10_SECONDS,
|
|
67
|
+
U as useAutofill
|
|
64
68
|
};
|
|
@@ -75,6 +75,7 @@ export type MetadataTemplateField = {
|
|
|
75
75
|
aiSuggestionState?: AiSuggestionState;
|
|
76
76
|
confidenceScore?: ConfidenceScoreData;
|
|
77
77
|
aiSuggestionConfidenceScore?: ConfidenceScoreData;
|
|
78
|
+
aiSuggestionTargetLocation?: MetadataTargetLocationEntry[];
|
|
78
79
|
displayName?: string;
|
|
79
80
|
hidden: boolean;
|
|
80
81
|
id?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { AutofillSuggestions, ConfidenceScoreData, MetadataTemplateField, MetadataTemplateInstance } from '../types';
|
|
2
|
+
import { AutofillSuggestions, ConfidenceScoreData, MetadataTargetLocationEntry, MetadataTemplateField, MetadataTemplateInstance } from '../types';
|
|
3
3
|
export interface AutofillContextType {
|
|
4
4
|
clearState: () => void;
|
|
5
5
|
getAiSuggestions: (templateKey: MetadataTemplateInstance['templateKey'], scope: MetadataTemplateInstance['scope'], agentId?: string) => Promise<MetadataTemplateField[]>;
|
|
@@ -8,6 +8,7 @@ export interface AutofillContextType {
|
|
|
8
8
|
isLongLoading: boolean;
|
|
9
9
|
confidenceScores: Record<string, Record<string, ConfidenceScoreData>>;
|
|
10
10
|
suggestions: AutofillSuggestions;
|
|
11
|
+
targetLocations: Record<string, Record<string, MetadataTargetLocationEntry[]>>;
|
|
11
12
|
}
|
|
12
13
|
export interface AutofillContextProviderProps {
|
|
13
14
|
children: React.ReactNode;
|