@box/metadata-editor 0.50.8 → 0.51.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.
@@ -1,26 +1,27 @@
1
- import { createContext as w, useState as g, useCallback as C, useMemo as A, useContext as v } from "react";
1
+ import { createContext as w, useState as f, useCallback as C, useMemo as A, useContext as v } from "react";
2
2
  import { TEMPLATE_CUSTOM_PROPERTIES as x } from "../constants.js";
3
- import "formik";
4
- import { jsx as E } from "react/jsx-runtime";
5
- import "../test-utils/sample-data.js";
6
- import { fetchSuggestions as P } from "../test-utils/test-utils.js";
7
- const m = /* @__PURE__ */ w(null), O = ({
8
- children: e,
9
- isAiSuggestionsFeatureEnabled: n
3
+ import { jsx as y } from "react/jsx-runtime";
4
+ import "@storybook/test";
5
+ const E = async (o, s) => s.map((t) => ({
6
+ ...t,
7
+ aiSuggestion: `${t.key} suggestion`
8
+ })), m = /* @__PURE__ */ w(null), I = ({
9
+ children: o,
10
+ isAiSuggestionsFeatureEnabled: s
10
11
  }) => {
11
- const [t, h] = g({}), [i, u] = g(!1), a = C(async (r, l, p = !1) => {
12
- let s = [];
13
- if (!n)
12
+ const [t, S] = f({}), [i, u] = f(!1), a = C(async (n, c, p = !1) => {
13
+ let r = [];
14
+ if (!s)
14
15
  throw new Error("AI Suggestions feature not available.");
15
- if (r === x)
16
+ if (n === x)
16
17
  throw new Error("Can't fetch suggestions for Custom Metadata instance");
17
- if (!t[r] || p) {
18
+ if (!t[n] || p) {
18
19
  u(!0);
19
20
  try {
20
- s = await P(r, l), h({
21
+ r = await E(n, c), S({
21
22
  ...t,
22
- [r]: {
23
- ...Object.fromEntries(s.map((o) => [o.key, o.aiSuggestion]))
23
+ [n]: {
24
+ ...Object.fromEntries(r.map((e) => [e.key, e.aiSuggestion]))
24
25
  }
25
26
  });
26
27
  } catch {
@@ -28,35 +29,35 @@ const m = /* @__PURE__ */ w(null), O = ({
28
29
  u(!1);
29
30
  }
30
31
  } else
31
- s = l.map((o) => {
32
- var f;
33
- const c = (f = t == null ? void 0 : t.templateKey) == null ? void 0 : f[o.key];
32
+ r = c.map((e) => {
33
+ var g;
34
+ const l = (g = t == null ? void 0 : t.templateKey) == null ? void 0 : g[e.key];
34
35
  return {
35
- ...o,
36
- ...c ? {
37
- aiSuggestion: c
36
+ ...e,
37
+ ...l ? {
38
+ aiSuggestion: l
38
39
  } : null
39
40
  };
40
41
  });
41
- return s;
42
- }, [t]), S = A(() => ({
42
+ return r;
43
+ }, [t]), h = A(() => ({
43
44
  getAiSuggestions: a,
44
- isAiSuggestionsFeatureEnabled: n,
45
+ isAiSuggestionsFeatureEnabled: s,
45
46
  isFetchingSuggestions: i,
46
47
  suggestions: t
47
- }), [a, n, i, t]);
48
- return /* @__PURE__ */ E(m.Provider, {
49
- value: S,
50
- children: e
48
+ }), [a, s, i, t]);
49
+ return /* @__PURE__ */ y(m.Provider, {
50
+ value: h,
51
+ children: o
51
52
  });
52
- }, b = () => {
53
- const e = v(m);
54
- if (!e)
53
+ }, O = () => {
54
+ const o = v(m);
55
+ if (!o)
55
56
  throw new Error("useAutofill should be wrapped inside AutofillProvider");
56
- return e;
57
+ return o;
57
58
  };
58
59
  export {
59
60
  m as AutofillContext,
60
- O as AutofillContextProvider,
61
- b as useAutofill
61
+ I as AutofillContextProvider,
62
+ O as useAutofill
62
63
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-editor",
3
- "version": "0.50.8",
3
+ "version": "0.51.0",
4
4
  "peerDependencies": {
5
5
  "@ariakit/react": "0.4.5",
6
6
  "@box/blueprint-web": "^7.20.0",
@@ -13,8 +13,8 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@ariakit/react": "0.4.5",
16
- "@box/blueprint-web": "^7.25.3",
17
- "@box/blueprint-web-assets": "^4.22.0",
16
+ "@box/blueprint-web": "^7.25.4",
17
+ "@box/blueprint-web-assets": "^4.23.0",
18
18
  "@box/storybook-utils": "^0.6.1",
19
19
  "@testing-library/react": "^15.0.6",
20
20
  "react": "^18.3.0",
@@ -52,5 +52,5 @@
52
52
  "**/*.css"
53
53
  ],
54
54
  "license": "SEE LICENSE IN LICENSE",
55
- "gitHead": "93743d21d2e1213f9596085f664989972a58dbca"
55
+ "gitHead": "9088f58268c90960efb20ef3c5c4f03d66af30b8"
56
56
  }
@@ -1,3 +1,4 @@
1
+ export type { JSONPatchOperations } from './components/metadata-instance-editor/subcomponents/metadata-instance-form/types';
1
2
  export type MetadataEmptyStateProps = {
2
3
  isBoxAiSuggestionsFeatureEnabled?: boolean;
3
4
  isAnyEmptyValueHidden?: boolean;
@@ -1,26 +0,0 @@
1
- import { Formik as l, Form as d } from "formik";
2
- import { defaultInitialValues as n } from "../defaults.js";
3
- import { mapDataFromTemplate as p } from "../mappers.js";
4
- import { jsx as a } from "react/jsx-runtime";
5
- const F = (e) => {
6
- const {
7
- children: i,
8
- selectedMetadataTemplate: t = null,
9
- onSubmit: o = () => {
10
- },
11
- withUpdateMode: r = !1
12
- } = e, m = t ? p(t, r) : n;
13
- return /* @__PURE__ */ a(l, {
14
- initialValues: {
15
- metadata: m
16
- },
17
- onSubmit: o,
18
- children: /* @__PURE__ */ a(d, {
19
- "data-testid": "formik-form",
20
- children: i
21
- })
22
- });
23
- };
24
- export {
25
- F as FormikWrapper
26
- };
@@ -1,41 +0,0 @@
1
- import { FormikWrapper as l } from "./formik-wrapper.js";
2
- import { allFieldsSuggestions as a, allFieldsTemplate as n, allFieldsTemplateInstance as i, allFieldsWithAiSuggestions as m, customTemplate as p, customTemplateInstance as o, customTemplateInstanceWithAllFieldsEmpty as d, customTemplateInstanceWithoutEmptyValues as c, dateField as u, emptyCustomTemplateInstance as F, emptyTemplateInstance as T, enumField as r, fields as g, firstTemplateInstance as I, firstTemplateInstanceFieldsWithSuggestions as f, firstTemplateSuggestions as h, floatField as S, multiSelectField as W, noFieldsTemplate as y, noValueField as x, nonHiddenFieldsTemplate as A, secondTemplateInstance as E, secondTemplateInstanceFieldsWithSuggestions as V, secondTemplateSuggestions as b, stringField as k, templateInstanceWithAllFieldsEmpty as B, templateInstanceWithoutEmptyValues as C, templateInstancesList as D, templateOptions as H, templates as L } from "./sample-data.js";
3
- import { blur as j, checkIfFormFieldsAreDisabled as q, fetchSuggestions as v, updateText as w, updateTextAndBlur as z } from "./test-utils.js";
4
- export {
5
- l as FormikWrapper,
6
- a as allFieldsSuggestions,
7
- n as allFieldsTemplate,
8
- i as allFieldsTemplateInstance,
9
- m as allFieldsWithAiSuggestions,
10
- j as blur,
11
- q as checkIfFormFieldsAreDisabled,
12
- p as customTemplate,
13
- o as customTemplateInstance,
14
- d as customTemplateInstanceWithAllFieldsEmpty,
15
- c as customTemplateInstanceWithoutEmptyValues,
16
- u as dateField,
17
- F as emptyCustomTemplateInstance,
18
- T as emptyTemplateInstance,
19
- r as enumField,
20
- v as fetchSuggestions,
21
- g as fields,
22
- I as firstTemplateInstance,
23
- f as firstTemplateInstanceFieldsWithSuggestions,
24
- h as firstTemplateSuggestions,
25
- S as floatField,
26
- W as multiSelectField,
27
- y as noFieldsTemplate,
28
- x as noValueField,
29
- A as nonHiddenFieldsTemplate,
30
- E as secondTemplateInstance,
31
- V as secondTemplateInstanceFieldsWithSuggestions,
32
- b as secondTemplateSuggestions,
33
- k as stringField,
34
- B as templateInstanceWithAllFieldsEmpty,
35
- C as templateInstanceWithoutEmptyValues,
36
- D as templateInstancesList,
37
- H as templateOptions,
38
- L as templates,
39
- w as updateText,
40
- z as updateTextAndBlur
41
- };
@@ -1,327 +0,0 @@
1
- import { mapTemplateOptionsFromTemplates as h } from "../mappers.js";
2
- const n = {
3
- id: "1",
4
- type: "string",
5
- key: "signature",
6
- hidden: !1,
7
- displayName: "Signature"
8
- }, d = {
9
- id: "2",
10
- type: "date",
11
- key: "effectiveDate",
12
- hidden: !1,
13
- displayName: "Effective Date"
14
- }, l = {
15
- id: "3",
16
- type: "enum",
17
- key: "country",
18
- hidden: !1,
19
- displayName: "Country",
20
- options: [{
21
- id: "1",
22
- key: "US"
23
- }, {
24
- id: "2",
25
- key: "UK"
26
- }]
27
- }, p = {
28
- id: "4",
29
- type: "float",
30
- key: "caseNumber",
31
- hidden: !1,
32
- displayName: "Number of Cases"
33
- }, m = {
34
- id: "5",
35
- type: "multiSelect",
36
- key: "orgs",
37
- hidden: !1,
38
- displayName: "Organizations",
39
- options: [{
40
- id: "Sales",
41
- key: "Sales"
42
- }, {
43
- id: "Marketing",
44
- key: "Marketing"
45
- }, {
46
- id: "Engineering",
47
- key: "Engineering"
48
- }]
49
- }, k = {
50
- id: "6",
51
- type: "string",
52
- key: "hidden",
53
- displayName: "Hidden",
54
- hidden: !0
55
- }, F = {
56
- id: "7",
57
- type: "string",
58
- key: "noValue",
59
- hidden: !1,
60
- displayName: "No value"
61
- }, o = {
62
- id: "1",
63
- displayName: "All metadata fields",
64
- scope: "enterprise_1",
65
- templateKey: "allFields",
66
- type: "metadata_template",
67
- hidden: !1,
68
- fields: [n, l, p, d, m, k, F]
69
- }, H = {
70
- hidden: !1,
71
- id: "2",
72
- displayName: "Non hidden metadata fields",
73
- scope: "enterprise_1",
74
- templateKey: "nonHiddenFields",
75
- type: "metadata_template",
76
- fields: [n, l, p, d, m]
77
- }, N = {
78
- id: "3",
79
- displayName: "No metadata fields",
80
- scope: "enterprise_3",
81
- templateKey: "noFields",
82
- type: "metadata_template",
83
- fields: [],
84
- hidden: !1
85
- }, _ = {
86
- id: "4",
87
- displayName: "Hidden template",
88
- scope: "enterprise_3",
89
- templateKey: "hiddenTemplate",
90
- type: "metadata_template",
91
- fields: [],
92
- hidden: !0
93
- }, I = [o, N, _], O = {
94
- id: "5",
95
- scope: "enterprise_3",
96
- templateKey: "properties",
97
- type: "metadata_template",
98
- fields: [],
99
- hidden: !1
100
- }, U = h(I), J = [n, l, p, d, m], y = {
101
- id: "1",
102
- type: "string",
103
- key: "signature",
104
- hidden: !1,
105
- displayName: "Signature",
106
- value: "Jan Kowalski"
107
- }, c = {
108
- id: "2",
109
- type: "enum",
110
- key: "country",
111
- hidden: !1,
112
- displayName: "Country",
113
- options: [{
114
- id: "1",
115
- key: "US"
116
- }, {
117
- id: "2",
118
- key: "UK"
119
- }],
120
- value: "US"
121
- }, r = {
122
- id: "3",
123
- type: "float",
124
- key: "caseNumber",
125
- hidden: !1,
126
- displayName: "Number of Cases",
127
- value: "25"
128
- }, u = {
129
- id: "4",
130
- type: "date",
131
- key: "effectiveDate",
132
- hidden: !1,
133
- displayName: "Effective Date",
134
- value: "2024-02-08T00:00:00.000Z"
135
- }, f = {
136
- id: "5",
137
- type: "multiSelect",
138
- key: "orgs",
139
- hidden: !1,
140
- displayName: "Organizations",
141
- options: [{
142
- id: "Sales",
143
- key: "Sales"
144
- }, {
145
- id: "Marketing",
146
- key: "Marketing"
147
- }, {
148
- id: "Engineering",
149
- key: "Engineering"
150
- }],
151
- value: ["Sales", "Marketing"]
152
- }, g = {
153
- id: "6",
154
- type: "string",
155
- key: "hidden",
156
- displayName: "Hidden",
157
- hidden: !0,
158
- value: "should be hidden"
159
- }, a = {
160
- id: "7",
161
- type: "string",
162
- key: "noValue",
163
- hidden: !1,
164
- displayName: "No value",
165
- value: null
166
- }, T = {
167
- ...a,
168
- key: "noValue1"
169
- }, E = {
170
- ...a,
171
- key: "noValue2"
172
- }, S = {
173
- canEdit: !0,
174
- id: "1",
175
- displayName: "All metadata fields",
176
- scope: "enterprise_1",
177
- templateKey: "allFields",
178
- type: "metadata_template",
179
- hidden: !1,
180
- fields: [y, c, r, u, f, g, a]
181
- }, K = {
182
- canEdit: !0,
183
- id: "2",
184
- displayName: "Without Empty Values",
185
- scope: "enterprise_1",
186
- templateKey: "withoutEmptyFields",
187
- type: "metadata_template",
188
- hidden: !1,
189
- fields: [y, c, r, u, f, g]
190
- }, v = {
191
- canEdit: !0,
192
- id: "3",
193
- displayName: "Empty Template",
194
- scope: "enterprise_1",
195
- templateKey: "emptyFields",
196
- type: "metadata_template",
197
- hidden: !1,
198
- fields: []
199
- }, V = {
200
- canEdit: !0,
201
- id: "4",
202
- displayName: "All Fields Empty Template",
203
- scope: "enterprise_1",
204
- templateKey: "emptyFields",
205
- type: "metadata_template",
206
- hidden: !1,
207
- fields: [a, T, E]
208
- }, i = {
209
- id: "1",
210
- type: "string",
211
- key: "signature",
212
- hidden: !1,
213
- value: "Jan Kowalski"
214
- }, s = {
215
- id: "2",
216
- type: "string",
217
- key: "version number",
218
- hidden: !1,
219
- value: "2.1"
220
- }, t = {
221
- id: "3",
222
- type: "string",
223
- key: "empty field",
224
- hidden: !1
225
- }, A = {
226
- canEdit: !0,
227
- id: "5",
228
- scope: "enterprise_1",
229
- templateKey: "properties",
230
- type: "metadata_template",
231
- fields: [i, s, t],
232
- hidden: !1
233
- }, b = {
234
- canEdit: !0,
235
- id: "6",
236
- scope: "enterprise_1",
237
- templateKey: "properties",
238
- type: "metadata_template",
239
- fields: [i, s],
240
- hidden: !1
241
- }, C = {
242
- canEdit: !0,
243
- id: "7",
244
- scope: "enterprise_1",
245
- templateKey: "properties",
246
- type: "metadata_template",
247
- fields: [],
248
- hidden: !1
249
- }, W = {
250
- canEdit: !0,
251
- id: "8",
252
- scope: "enterprise_1",
253
- templateKey: "properties",
254
- type: "metadata_template",
255
- fields: [t, t, t],
256
- hidden: !1
257
- }, w = [S, K, V, v, A, b, C, W], M = o.fields.map((e) => ({
258
- ...e,
259
- aiSuggestion: "mock suggestion"
260
- })), B = {
261
- [o.templateKey]: {
262
- ...Object.fromEntries(M.map((e) => [e.key, e.aiSuggestion]))
263
- }
264
- }, z = {
265
- id: "1",
266
- canEdit: !0,
267
- displayName: "Metadata Template A",
268
- scope: "enterprise_1",
269
- templateKey: "templateA",
270
- type: "metadata_template",
271
- hidden: !1,
272
- fields: [i]
273
- }, j = {
274
- templateA: {
275
- signature: "John Doe"
276
- }
277
- }, x = [{
278
- ...i,
279
- aiSuggestion: "John Doe"
280
- }], L = {
281
- id: "1",
282
- displayName: "Metadata Template B",
283
- scope: "enterprise_1",
284
- templateKey: "templateB",
285
- type: "metadata_template",
286
- hidden: !1,
287
- fields: [s]
288
- }, Z = {
289
- templateB: {
290
- "version number": "3.0"
291
- }
292
- }, q = [{
293
- ...s,
294
- aiSuggestion: "3.0"
295
- }];
296
- export {
297
- B as allFieldsSuggestions,
298
- o as allFieldsTemplate,
299
- S as allFieldsTemplateInstance,
300
- M as allFieldsWithAiSuggestions,
301
- O as customTemplate,
302
- A as customTemplateInstance,
303
- W as customTemplateInstanceWithAllFieldsEmpty,
304
- b as customTemplateInstanceWithoutEmptyValues,
305
- d as dateField,
306
- C as emptyCustomTemplateInstance,
307
- v as emptyTemplateInstance,
308
- l as enumField,
309
- J as fields,
310
- z as firstTemplateInstance,
311
- x as firstTemplateInstanceFieldsWithSuggestions,
312
- j as firstTemplateSuggestions,
313
- p as floatField,
314
- m as multiSelectField,
315
- N as noFieldsTemplate,
316
- F as noValueField,
317
- H as nonHiddenFieldsTemplate,
318
- L as secondTemplateInstance,
319
- q as secondTemplateInstanceFieldsWithSuggestions,
320
- Z as secondTemplateSuggestions,
321
- n as stringField,
322
- V as templateInstanceWithAllFieldsEmpty,
323
- K as templateInstanceWithoutEmptyValues,
324
- w as templateInstancesList,
325
- U as templateOptions,
326
- I as templates
327
- };
@@ -1,30 +0,0 @@
1
- import { userEvent as s, within as d, expect as l } from "@storybook/test";
2
- const r = async (e, t) => {
3
- await s.click(e), await s.clear(e), await s.type(e, t);
4
- }, y = async () => {
5
- await s.click(document.body);
6
- }, u = async (e, t) => {
7
- await r(e, t), await y();
8
- }, g = async (e, t) => {
9
- const a = d(e);
10
- t.filter((i) => !i.hidden).forEach((i) => {
11
- const c = a.queryByTestId(`${i.displayName}-field`);
12
- if (i.type === "date") {
13
- const o = d(c).getByRole("group");
14
- l(o).toHaveAttribute("aria-disabled");
15
- } else
16
- [...c.getElementsByTagName("input")].filter((n) => n.type !== "hidden").forEach((n) => {
17
- l(n).toBeDisabled();
18
- });
19
- });
20
- }, m = async (e, t) => t.map((a) => ({
21
- ...a,
22
- aiSuggestion: `${a.key} suggestion`
23
- }));
24
- export {
25
- y as blur,
26
- g as checkIfFormFieldsAreDisabled,
27
- m as fetchSuggestions,
28
- r as updateText,
29
- u as updateTextAndBlur
30
- };