@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.
- package/dist/esm/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.js +2 -2
- package/dist/esm/lib/metadata-template-editor.js +51 -48
- package/dist/types/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.d.ts +1 -1
- package/dist/types/lib/metadata-template-editor.d.ts +9 -4
- package/package.json +1 -1
package/dist/esm/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.js
CHANGED
|
@@ -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
|
|
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__ */
|
|
27
|
-
onCancel:
|
|
28
|
-
onDirtyStateChange:
|
|
29
|
-
onValidationChange:
|
|
30
|
-
onSubmitError:
|
|
31
|
-
onTemplateLoad:
|
|
32
|
-
taxonomyOptions:
|
|
33
|
-
fetchTaxonomies:
|
|
34
|
-
formId:
|
|
35
|
-
hideActions:
|
|
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:
|
|
43
|
-
} = Z(), c = l.mode === ae.Edit, [
|
|
44
|
-
|
|
45
|
-
}, [
|
|
46
|
-
|
|
47
|
-
requestClose:
|
|
48
|
-
}), [
|
|
49
|
-
const O =
|
|
50
|
-
k(e),
|
|
51
|
-
}, [
|
|
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
|
-
|
|
55
|
-
if (!
|
|
54
|
+
L(() => {
|
|
55
|
+
if (!u)
|
|
56
56
|
return;
|
|
57
57
|
let e = !1;
|
|
58
|
-
return
|
|
58
|
+
return C(!0), T(!1), E(void 0), (async () => {
|
|
59
59
|
try {
|
|
60
|
-
const s = await
|
|
61
|
-
e ||
|
|
60
|
+
const s = await u();
|
|
61
|
+
e || E(s);
|
|
62
62
|
} catch {
|
|
63
|
-
e ||
|
|
63
|
+
e || T(!0);
|
|
64
64
|
} finally {
|
|
65
|
-
e ||
|
|
65
|
+
e || C(!1);
|
|
66
66
|
}
|
|
67
67
|
})(), () => {
|
|
68
68
|
e = !0;
|
|
69
69
|
};
|
|
70
|
-
}, [
|
|
71
|
-
o !== void 0 &&
|
|
72
|
-
}, [o,
|
|
73
|
-
const
|
|
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:
|
|
82
|
-
}, [o,
|
|
81
|
+
namespace: N ?? ""
|
|
82
|
+
}, [o, N]), z = async (e) => {
|
|
83
83
|
try {
|
|
84
84
|
if (c) {
|
|
85
|
-
const i = se(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
153
|
+
initialValues: d,
|
|
151
154
|
validationSchema: x,
|
|
152
155
|
onSubmit: z,
|
|
153
156
|
children: /* @__PURE__ */ r(ne, {
|
|
154
|
-
formId:
|
|
155
|
-
onCancel:
|
|
156
|
-
taxonomyOptions:
|
|
157
|
-
fetchTaxonomies:
|
|
158
|
-
hideActions:
|
|
157
|
+
formId: _,
|
|
158
|
+
onCancel: p,
|
|
159
|
+
taxonomyOptions: S,
|
|
160
|
+
fetchTaxonomies: K,
|
|
161
|
+
hideActions: B,
|
|
159
162
|
isEditMode: c,
|
|
160
163
|
onDirtyStateChange: O,
|
|
161
|
-
onValidationChange:
|
|
164
|
+
onValidationChange: F,
|
|
162
165
|
fieldExtensions: U
|
|
163
166
|
})
|
|
164
167
|
}), D && /* @__PURE__ */ r(le, {
|
|
165
|
-
onClose: () =>
|
|
168
|
+
onClose: () => f(!1),
|
|
166
169
|
onConfirm: () => {
|
|
167
|
-
|
|
170
|
+
f(!1), m?.();
|
|
168
171
|
},
|
|
169
172
|
title: t(a.unsavedChangesTitle),
|
|
170
173
|
body: t(a.unsavedChangesBody),
|
package/dist/types/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.d.ts
CHANGED
|
@@ -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[]
|
|
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}
|