@box/metadata-template-editor 1.19.1 → 1.20.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.
@@ -37,10 +37,10 @@ function re({
37
37
  a ? i(a) : d.current?.requestClose();
38
38
  }, _ = (a) => {
39
39
  g(a.displayName), C?.(a);
40
- }, M = (a) => async (x) => {
40
+ }, M = (a) => async (...x) => {
41
41
  y(!0);
42
42
  try {
43
- await a(x), i(!1);
43
+ await a(...x), i(!1);
44
44
  } finally {
45
45
  y(!1);
46
46
  }
@@ -1,4 +1,4 @@
1
- import { forwardRef as W, useState as n, useCallback as L, useImperativeHandle as G, useEffect as N, useMemo as Q } from "react";
1
+ import { forwardRef as Q, useState as n, useCallback as b, useImperativeHandle as W, useEffect as L, useMemo as G } from "react";
2
2
  import { Formik as X } from "formik";
3
3
  import { useIntl as Y } from "react-intl";
4
4
  import { useNotification as Z, LoadingIndicator as $, EmptyState as M, Text as P } from "@box/blueprint-web";
@@ -23,54 +23,54 @@ import '../../styles/metadata-template-editor.css';const fe = "_loading_1o2vk_8"
23
23
  templateKey: "",
24
24
  fields: [],
25
25
  hidden: !1
26
- }, Ue = /* @__PURE__ */ W(function({
27
- onCancel: d,
28
- onDirtyStateChange: u,
29
- onValidationChange: I,
30
- onSubmitError: S,
31
- onTemplateLoad: h,
32
- taxonomyOptions: F,
33
- fetchTaxonomies: _,
34
- formId: B,
35
- hideActions: K = !1,
26
+ }, Ue = /* @__PURE__ */ Q(function({
27
+ onCancel: m,
28
+ onDirtyStateChange: h,
29
+ onValidationChange: F,
30
+ onSubmitError: I,
31
+ onTemplateLoad: y,
32
+ taxonomyOptions: S,
33
+ fetchTaxonomies: K,
34
+ formId: _,
35
+ hideActions: B = !1,
36
36
  fieldExtensions: U,
37
37
  ...l
38
38
  }, w) {
39
39
  const x = oe(), {
40
40
  formatMessage: t
41
41
  } = Y(), {
42
- addNotification: y
43
- } = Z(), c = l.mode === ae.Edit, [g, k] = n(!1), [D, m] = n(!1), f = L(() => {
44
- g ? m(!0) : d?.();
45
- }, [g, d]);
46
- G(w, () => ({
47
- requestClose: f
48
- }), [f]);
49
- const O = L((e) => {
50
- k(e), u?.(e);
51
- }, [u]), [V, v] = n(c), [H, C] = n(!1), [R, j] = n(0), [o, T] = n(void 0), p = c ? l.fetchTemplate : void 0, q = () => {
42
+ addNotification: g
43
+ } = Z(), c = l.mode === ae.Edit, [v, k] = n(!1), [D, f] = n(!1), p = b(() => {
44
+ v ? f(!0) : m?.();
45
+ }, [v, m]);
46
+ W(w, () => ({
47
+ requestClose: p
48
+ }), [p]);
49
+ const O = b((e) => {
50
+ k(e), h?.(e);
51
+ }, [h]), [V, C] = n(c), [H, T] = n(!1), [R, j] = n(0), [o, E] = n(void 0), u = c ? l.fetchTemplate : void 0, q = () => {
52
52
  j((e) => e + 1);
53
53
  };
54
- N(() => {
55
- if (!p)
54
+ L(() => {
55
+ if (!u)
56
56
  return;
57
57
  let e = !1;
58
- return v(!0), C(!1), T(void 0), (async () => {
58
+ return C(!0), T(!1), E(void 0), (async () => {
59
59
  try {
60
- const s = await p();
61
- e || T(s);
60
+ const s = await u();
61
+ e || E(s);
62
62
  } catch {
63
- e || C(!0);
63
+ e || T(!0);
64
64
  } finally {
65
- e || v(!1);
65
+ e || C(!1);
66
66
  }
67
67
  })(), () => {
68
68
  e = !0;
69
69
  };
70
- }, [p, R]), N(() => {
71
- o !== void 0 && h?.(o);
72
- }, [o, h]);
73
- const E = c ? void 0 : l.namespace, b = Q(() => o ? {
70
+ }, [u, R]), L(() => {
71
+ o !== void 0 && y?.(o);
72
+ }, [o, y]);
73
+ const N = c ? void 0 : l.namespace, d = G(() => o ? {
74
74
  displayName: o.displayName,
75
75
  templateKey: o.templateKey,
76
76
  namespace: o.namespace,
@@ -78,12 +78,15 @@ import '../../styles/metadata-template-editor.css';const fe = "_loading_1o2vk_8"
78
78
  fields: o.fields.map((e) => ie(e))
79
79
  } : {
80
80
  ...ue,
81
- namespace: E ?? ""
82
- }, [o, E]), z = async (e) => {
81
+ namespace: N ?? ""
82
+ }, [o, N]), z = async (e) => {
83
83
  try {
84
84
  if (c) {
85
- const i = se(b, e);
86
- await l.onEditTemplate(i);
85
+ const i = se(d, e);
86
+ await l.onEditTemplate(i, {
87
+ namespaceFQN: d.namespace,
88
+ templateKey: d.templateKey
89
+ });
87
90
  } else {
88
91
  const i = re(e.fields), s = {
89
92
  namespace: e.namespace,
@@ -94,7 +97,7 @@ import '../../styles/metadata-template-editor.css';const fe = "_loading_1o2vk_8"
94
97
  };
95
98
  await l.onCreateTemplate(s);
96
99
  }
97
- y({
100
+ g({
98
101
  sensitivity: "foreground",
99
102
  variant: "success",
100
103
  styledText: t(a.saveSuccessNotification),
@@ -110,7 +113,7 @@ import '../../styles/metadata-template-editor.css';const fe = "_loading_1o2vk_8"
110
113
  s = t(J === ce ? a.displayNameUsedBefore : a.saveErrorNotification);
111
114
  } else
112
115
  s = t(a.saveErrorNotification);
113
- y({
116
+ g({
114
117
  sensitivity: "foreground",
115
118
  variant: "error",
116
119
  styledText: s,
@@ -118,7 +121,7 @@ import '../../styles/metadata-template-editor.css';const fe = "_loading_1o2vk_8"
118
121
  closeButtonAriaLabel: t(a.notificationCloseButtonAriaLabel)
119
122
  });
120
123
  try {
121
- S?.(i);
124
+ I?.(i);
122
125
  } catch {
123
126
  }
124
127
  throw i;
@@ -147,24 +150,24 @@ import '../../styles/metadata-template-editor.css';const fe = "_loading_1o2vk_8"
147
150
  })
148
151
  }) : /* @__PURE__ */ de(me, {
149
152
  children: [/* @__PURE__ */ r(X, {
150
- initialValues: b,
153
+ initialValues: d,
151
154
  validationSchema: x,
152
155
  onSubmit: z,
153
156
  children: /* @__PURE__ */ r(ne, {
154
- formId: B,
155
- onCancel: f,
156
- taxonomyOptions: F,
157
- fetchTaxonomies: _,
158
- hideActions: K,
157
+ formId: _,
158
+ onCancel: p,
159
+ taxonomyOptions: S,
160
+ fetchTaxonomies: K,
161
+ hideActions: B,
159
162
  isEditMode: c,
160
163
  onDirtyStateChange: O,
161
- onValidationChange: I,
164
+ onValidationChange: F,
162
165
  fieldExtensions: U
163
166
  })
164
167
  }), D && /* @__PURE__ */ r(le, {
165
- onClose: () => m(!1),
168
+ onClose: () => f(!1),
166
169
  onConfirm: () => {
167
- m(!1), d?.();
170
+ f(!1), m?.();
168
171
  },
169
172
  title: t(a.unsavedChangesTitle),
170
173
  body: t(a.unsavedChangesBody),
@@ -46,7 +46,7 @@ export type MetadataTemplateEditorModalProps = MetadataTemplateEditorProps & {
46
46
  * open={open}
47
47
  * onOpenChange={setOpen}
48
48
  * fetchTemplate={useCallback(() => api.getTemplate(templateKey), [templateKey])}
49
- * onEditTemplate={async patches => { await api.updateTemplate(patches); }}
49
+ * onEditTemplate={async (patches, { namespaceFQN, templateKey }) => { await api.updateTemplate(namespaceFQN, templateKey, patches); }}
50
50
  * onSubmitError={err => logger.error('save failed', err)}
51
51
  * title="Edit Template"
52
52
  * />
@@ -180,10 +180,15 @@ type EditModeProps = {
180
180
  /**
181
181
  * Called when the user saves changes to an **existing** template and the form
182
182
  * passes all validation. Receives the array of JSON Patch operations that
183
- * describe only the changes made since the template was loaded.
183
+ * describe only the changes made since the template was loaded, and the
184
+ * `{ namespaceFQN, templateKey }` identifier needed to target the correct
185
+ * Box API PATCH endpoint (`PUT /metadata_templates/{namespaceFQN}/{templateKey}/schema`).
184
186
  * `await` this if you need `isSubmitting` to remain `true` during the API call.
185
187
  */
186
- onEditTemplate: (patchItems: MetadataTemplatePatchItem[]) => Promise<void> | void;
188
+ onEditTemplate: (patchItems: MetadataTemplatePatchItem[], identifier: {
189
+ namespaceFQN: string;
190
+ templateKey: string;
191
+ }) => Promise<void> | void;
187
192
  onCreateTemplate?: never;
188
193
  /**
189
194
  * Called once (and re-called whenever the reference changes) to fetch the
@@ -255,7 +260,7 @@ export type MetadataTemplateEditorHandle = {
255
260
  * <MetadataTemplateEditor
256
261
  * mode={MetadataTemplateEditorMode.Edit}
257
262
  * fetchTemplate={useCallback(() => api.getTemplate(templateKey), [templateKey])}
258
- * onEditTemplate={async patches => { await api.updateTemplate(patches); }}
263
+ * onEditTemplate={async (patches, { namespaceFQN, templateKey }) => { await api.updateTemplate(namespaceFQN, templateKey, patches); }}
259
264
  * onCancel={() => navigate(-1)}
260
265
  * />
261
266
  * ```
@@ -269,7 +274,7 @@ export type MetadataTemplateEditorHandle = {
269
274
  * <MetadataTemplateEditor
270
275
  * mode={MetadataTemplateEditorMode.Edit}
271
276
  * fetchTemplate={() => api.getTemplate(templateKey)}
272
- * onEditTemplate={async patches => { await api.updateTemplate(patches); }}
277
+ * onEditTemplate={async (patches, { namespaceFQN, templateKey }) => { await api.updateTemplate(namespaceFQN, templateKey, patches); }}
273
278
  * onTemplateLoad={t => setPageTitle(t.displayName)}
274
279
  * onDirtyStateChange={setIsDirty}
275
280
  * onValidationChange={setIsFormValid}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/metadata-template-editor",
3
- "version": "1.19.1",
3
+ "version": "1.20.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "peerDependencies": {
6
6
  "@box/blueprint-web": "^14.2.0",