@box/metadata-template-browser 1.16.18 → 1.17.1
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,246 +1,248 @@
|
|
|
1
1
|
import Y from "lodash/debounce";
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { SEARCH_DEBOUNCE_MS as R, emptyTemplatesResponse as b, PAGE_SIZE as
|
|
4
|
-
import { BrowserActionType as
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
|
|
2
|
+
import { useRef as C, useMemo as $ } from "react";
|
|
3
|
+
import { SEARCH_DEBOUNCE_MS as R, emptyTemplatesResponse as b, PAGE_SIZE as V, emptyNamespacesResponse as v } from "../constants.js";
|
|
4
|
+
import { BrowserActionType as a } from "./reducer.js";
|
|
5
|
+
const S = (i) => new Promise((n, w) => {
|
|
6
|
+
if (i.aborted) {
|
|
7
|
+
w(new DOMException("Aborted", "AbortError"));
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
i.addEventListener("abort", () => w(new DOMException("Aborted", "AbortError")), {
|
|
11
11
|
once: !0
|
|
12
12
|
});
|
|
13
|
-
}),
|
|
13
|
+
}), u = (i) => {
|
|
14
14
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const n = i();
|
|
16
|
+
n instanceof Promise && n.catch(() => {
|
|
17
17
|
});
|
|
18
18
|
} catch {
|
|
19
19
|
}
|
|
20
|
-
},
|
|
20
|
+
}, L = (i) => i instanceof Error ? i.message : typeof i == "string" ? i : "An unknown error occurred", g = async (i, n, w, o) => {
|
|
21
21
|
try {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
22
|
+
const M = await n();
|
|
23
|
+
i.aborted || w(M);
|
|
24
|
+
} catch (M) {
|
|
25
|
+
i.aborted || o(M);
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
28
|
+
function or(i, n, w, o, M) {
|
|
29
|
+
const E = C(null), k = C(null), P = C(Y(async (r) => {
|
|
30
|
+
k.current?.abort();
|
|
31
|
+
const e = new AbortController();
|
|
32
|
+
k.current = e;
|
|
33
33
|
const {
|
|
34
|
-
signal:
|
|
35
|
-
} =
|
|
36
|
-
|
|
37
|
-
type:
|
|
38
|
-
results:
|
|
39
|
-
nextMarker:
|
|
40
|
-
}), (
|
|
41
|
-
type:
|
|
42
|
-
error:
|
|
43
|
-
}));
|
|
34
|
+
signal: s
|
|
35
|
+
} = e;
|
|
36
|
+
u(() => n.current.onSearchChange?.(r)), u(() => n.current.onNewViewLoading?.(!0)), await g(s, () => B(r, s), (t) => o({
|
|
37
|
+
type: a.SearchLoaded,
|
|
38
|
+
results: t.entries,
|
|
39
|
+
nextMarker: t.next_marker
|
|
40
|
+
}), (t) => o({
|
|
41
|
+
type: a.SearchError,
|
|
42
|
+
error: L(t)
|
|
43
|
+
})), s.aborted || u(() => n.current.onNewViewLoading?.(!1));
|
|
44
44
|
}, R)), h = () => {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
return
|
|
45
|
+
E.current?.abort();
|
|
46
|
+
const r = new AbortController();
|
|
47
|
+
return E.current = r, r.signal;
|
|
48
48
|
}, G = () => {
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
return
|
|
49
|
+
E.current?.abort(), E.current = null;
|
|
50
|
+
}, F = () => {
|
|
51
|
+
k.current?.abort();
|
|
52
|
+
const r = new AbortController();
|
|
53
|
+
return k.current = r, r.signal;
|
|
54
54
|
}, H = () => {
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
const
|
|
58
|
-
return
|
|
59
|
-
limit:
|
|
60
|
-
marker:
|
|
61
|
-
signal:
|
|
62
|
-
}),
|
|
63
|
-
},
|
|
64
|
-
const
|
|
65
|
-
return
|
|
66
|
-
limit:
|
|
67
|
-
marker:
|
|
68
|
-
signal:
|
|
69
|
-
}),
|
|
70
|
-
}, B = (
|
|
71
|
-
const
|
|
72
|
-
return
|
|
73
|
-
limit:
|
|
74
|
-
marker:
|
|
75
|
-
signal:
|
|
76
|
-
}),
|
|
77
|
-
}, U = (
|
|
78
|
-
|
|
79
|
-
type:
|
|
80
|
-
error:
|
|
55
|
+
k.current?.abort(), k.current = null;
|
|
56
|
+
}, Q = (r, e, s) => {
|
|
57
|
+
const t = i.current.getNamespaces;
|
|
58
|
+
return t ? Promise.race([t(r, {
|
|
59
|
+
limit: V,
|
|
60
|
+
marker: s,
|
|
61
|
+
signal: e
|
|
62
|
+
}), S(e)]) : Promise.resolve(v);
|
|
63
|
+
}, f = (r, e, s) => {
|
|
64
|
+
const t = i.current.getTemplates;
|
|
65
|
+
return t ? Promise.race([t(r, {
|
|
66
|
+
limit: V,
|
|
67
|
+
marker: s,
|
|
68
|
+
signal: e
|
|
69
|
+
}), S(e)]) : Promise.resolve(b);
|
|
70
|
+
}, B = (r, e, s) => {
|
|
71
|
+
const t = i.current.getSearchResults;
|
|
72
|
+
return t ? Promise.race([t(r, {
|
|
73
|
+
limit: V,
|
|
74
|
+
marker: s,
|
|
75
|
+
signal: e
|
|
76
|
+
}), S(e)]) : Promise.resolve(b);
|
|
77
|
+
}, U = (r, e) => {
|
|
78
|
+
o({
|
|
79
|
+
type: r,
|
|
80
|
+
error: L(e)
|
|
81
81
|
});
|
|
82
|
-
},
|
|
83
|
-
let
|
|
84
|
-
return await
|
|
85
|
-
const
|
|
86
|
-
return [
|
|
87
|
-
}, ([
|
|
88
|
-
|
|
89
|
-
type:
|
|
90
|
-
namespaces:
|
|
91
|
-
namespaceNextMarker:
|
|
92
|
-
templates:
|
|
93
|
-
templateNextMarker:
|
|
94
|
-
}),
|
|
95
|
-
}, (
|
|
82
|
+
}, _ = async (r, e, s) => {
|
|
83
|
+
let t = !1;
|
|
84
|
+
return await g(e, async () => {
|
|
85
|
+
const m = await Q(r, e), x = m.next_marker ? b : await f(r, e);
|
|
86
|
+
return [m, x];
|
|
87
|
+
}, ([m, x]) => {
|
|
88
|
+
o({
|
|
89
|
+
type: a.BrowseLoaded,
|
|
90
|
+
namespaces: m.entries,
|
|
91
|
+
namespaceNextMarker: m.next_marker,
|
|
92
|
+
templates: x.entries,
|
|
93
|
+
templateNextMarker: x.next_marker
|
|
94
|
+
}), t = !0;
|
|
95
|
+
}, (m) => U(s, m)), t;
|
|
96
96
|
}, Z = async () => {
|
|
97
|
-
const
|
|
98
|
-
namespaceFQN:
|
|
99
|
-
} =
|
|
100
|
-
|
|
101
|
-
type:
|
|
102
|
-
}),
|
|
103
|
-
}, j = async (
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
namespaces:
|
|
107
|
-
templates:
|
|
108
|
-
namespaceNextMarker:
|
|
109
|
-
templateNextMarker:
|
|
110
|
-
isNamespacesExhausted:
|
|
111
|
-
}),
|
|
112
|
-
type:
|
|
113
|
-
namespace:
|
|
114
|
-
}),
|
|
115
|
-
type:
|
|
116
|
-
}),
|
|
117
|
-
|
|
97
|
+
const r = h(), {
|
|
98
|
+
namespaceFQN: e
|
|
99
|
+
} = w.current;
|
|
100
|
+
o({
|
|
101
|
+
type: a.BrowseFetchStart
|
|
102
|
+
}), u(() => n.current.onNewViewLoading?.(!0)), await _(e, r, a.InitialLoadError), r.aborted || u(() => n.current.onNewViewLoading?.(!1));
|
|
103
|
+
}, j = async (r) => {
|
|
104
|
+
const e = h(), s = w.current;
|
|
105
|
+
M.current.set(s.namespaceFQN, {
|
|
106
|
+
namespaces: s.namespaces,
|
|
107
|
+
templates: s.templates,
|
|
108
|
+
namespaceNextMarker: s.namespaceNextMarker,
|
|
109
|
+
templateNextMarker: s.templateNextMarker,
|
|
110
|
+
isNamespacesExhausted: s.isNamespacesExhausted
|
|
111
|
+
}), o({
|
|
112
|
+
type: a.NavigateTo,
|
|
113
|
+
namespace: r
|
|
114
|
+
}), o({
|
|
115
|
+
type: a.BrowseFetchStart
|
|
116
|
+
}), u(() => n.current.onNewViewLoading?.(!0));
|
|
117
|
+
const t = await _(r.id, e, a.BrowseError);
|
|
118
|
+
e.aborted || (u(() => n.current.onNewViewLoading?.(!1)), t && u(() => n.current.onNamespaceChange?.(r.id)));
|
|
119
|
+
}, z = (r) => {
|
|
118
120
|
G();
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
type:
|
|
122
|
-
fqn:
|
|
123
|
-
cached:
|
|
124
|
-
}),
|
|
125
|
-
}, J = (
|
|
126
|
-
if (
|
|
127
|
-
type:
|
|
128
|
-
value:
|
|
129
|
-
}),
|
|
130
|
-
|
|
131
|
-
type:
|
|
132
|
-
});
|
|
121
|
+
const e = M.current.get(r);
|
|
122
|
+
e && (o({
|
|
123
|
+
type: a.NavigateBack,
|
|
124
|
+
fqn: r,
|
|
125
|
+
cached: e
|
|
126
|
+
}), u(() => n.current.onNamespaceChange?.(r)));
|
|
127
|
+
}, J = (r) => {
|
|
128
|
+
if (o({
|
|
129
|
+
type: a.SearchValueChange,
|
|
130
|
+
value: r
|
|
131
|
+
}), r.trim() === "") {
|
|
132
|
+
P.current.cancel(), H(), o({
|
|
133
|
+
type: a.SearchClear
|
|
134
|
+
}), u(() => n.current.onSearchChange?.("")), u(() => n.current.onNewViewLoading?.(!1));
|
|
133
135
|
return;
|
|
134
136
|
}
|
|
135
|
-
|
|
136
|
-
type:
|
|
137
|
-
query:
|
|
138
|
-
}),
|
|
139
|
-
},
|
|
137
|
+
o({
|
|
138
|
+
type: a.SearchFetchStart,
|
|
139
|
+
query: r.trim()
|
|
140
|
+
}), P.current(r.trim());
|
|
141
|
+
}, I = async () => {
|
|
140
142
|
const {
|
|
141
|
-
namespaceFQN:
|
|
142
|
-
searchQuery:
|
|
143
|
-
searchNextMarker:
|
|
144
|
-
namespaceNextMarker:
|
|
145
|
-
templateNextMarker:
|
|
146
|
-
isNamespacesExhausted:
|
|
147
|
-
} =
|
|
148
|
-
if (!(
|
|
143
|
+
namespaceFQN: r,
|
|
144
|
+
searchQuery: e,
|
|
145
|
+
searchNextMarker: s,
|
|
146
|
+
namespaceNextMarker: t,
|
|
147
|
+
templateNextMarker: m,
|
|
148
|
+
isNamespacesExhausted: x
|
|
149
|
+
} = w.current, d = !!e, N = d && !!s, O = !d && !x && !!t, D = !d && !!m;
|
|
150
|
+
if (!(N || O || D))
|
|
149
151
|
return;
|
|
150
|
-
|
|
151
|
-
type:
|
|
152
|
+
o({
|
|
153
|
+
type: a.LoadMoreStart
|
|
152
154
|
});
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
type:
|
|
156
|
-
error:
|
|
155
|
+
const A = (l) => {
|
|
156
|
+
o({
|
|
157
|
+
type: a.LoadMoreError,
|
|
158
|
+
error: L(l)
|
|
157
159
|
});
|
|
158
|
-
},
|
|
159
|
-
const
|
|
160
|
-
|
|
160
|
+
}, q = (l) => {
|
|
161
|
+
const c = M.current.get(r);
|
|
162
|
+
c && l(c);
|
|
161
163
|
};
|
|
162
|
-
if (
|
|
163
|
-
const
|
|
164
|
-
await
|
|
165
|
-
type:
|
|
166
|
-
entries:
|
|
167
|
-
nextMarker:
|
|
168
|
-
}),
|
|
164
|
+
if (N) {
|
|
165
|
+
const l = F();
|
|
166
|
+
await g(l, () => B(e, l, s), (c) => o({
|
|
167
|
+
type: a.LoadMoreSearchLoaded,
|
|
168
|
+
entries: c.entries,
|
|
169
|
+
nextMarker: c.next_marker
|
|
170
|
+
}), A);
|
|
169
171
|
return;
|
|
170
172
|
}
|
|
171
|
-
if (
|
|
172
|
-
const
|
|
173
|
-
await
|
|
174
|
-
const
|
|
175
|
-
return [
|
|
176
|
-
}, ([
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
type:
|
|
180
|
-
entries:
|
|
181
|
-
nextMarker:
|
|
182
|
-
...
|
|
173
|
+
if (O) {
|
|
174
|
+
const l = h();
|
|
175
|
+
await g(l, async () => {
|
|
176
|
+
const c = await Q(r, l, t), p = c.next_marker ? b : await f(r, l);
|
|
177
|
+
return [c, p];
|
|
178
|
+
}, ([c, p]) => {
|
|
179
|
+
const T = !c.next_marker;
|
|
180
|
+
o({
|
|
181
|
+
type: a.LoadMoreNamespacesLoaded,
|
|
182
|
+
entries: c.entries,
|
|
183
|
+
nextMarker: c.next_marker,
|
|
184
|
+
...T && {
|
|
183
185
|
templates: p.entries,
|
|
184
186
|
templateNextMarker: p.next_marker
|
|
185
187
|
}
|
|
186
|
-
}),
|
|
187
|
-
y.namespaces = [...y.namespaces, ...
|
|
188
|
+
}), q((y) => {
|
|
189
|
+
y.namespaces = [...y.namespaces, ...c.entries], y.namespaceNextMarker = c.next_marker, y.isNamespacesExhausted = T, T && (y.templates = p.entries, y.templateNextMarker = p.next_marker);
|
|
188
190
|
});
|
|
189
|
-
},
|
|
191
|
+
}, A);
|
|
190
192
|
return;
|
|
191
193
|
}
|
|
192
|
-
if (
|
|
193
|
-
const
|
|
194
|
-
await
|
|
195
|
-
|
|
196
|
-
type:
|
|
197
|
-
entries:
|
|
198
|
-
nextMarker:
|
|
199
|
-
}),
|
|
200
|
-
p.templates = [...p.templates, ...
|
|
194
|
+
if (D) {
|
|
195
|
+
const l = h();
|
|
196
|
+
await g(l, () => f(r, l, m), (c) => {
|
|
197
|
+
o({
|
|
198
|
+
type: a.LoadMoreTemplatesLoaded,
|
|
199
|
+
entries: c.entries,
|
|
200
|
+
nextMarker: c.next_marker
|
|
201
|
+
}), q((p) => {
|
|
202
|
+
p.templates = [...p.templates, ...c.entries], p.templateNextMarker = c.next_marker;
|
|
201
203
|
});
|
|
202
|
-
},
|
|
204
|
+
}, A);
|
|
203
205
|
}
|
|
204
|
-
}, K = async (
|
|
205
|
-
|
|
206
|
-
type:
|
|
207
|
-
template:
|
|
208
|
-
}),
|
|
209
|
-
}, W = (
|
|
210
|
-
|
|
206
|
+
}, K = async (r) => {
|
|
207
|
+
w.current.selectedTemplateId !== r.id && (o({
|
|
208
|
+
type: a.TemplateSelect,
|
|
209
|
+
template: r
|
|
210
|
+
}), u(() => n.current.onTemplateSelect?.(r)));
|
|
211
|
+
}, W = (r) => {
|
|
212
|
+
u(() => n.current.onTemplateEdit?.(r));
|
|
211
213
|
}, X = async () => {
|
|
212
214
|
const {
|
|
213
|
-
searchError:
|
|
214
|
-
searchQuery:
|
|
215
|
-
loadMoreError:
|
|
216
|
-
initialLoadError:
|
|
217
|
-
browseError:
|
|
218
|
-
namespaceFQN:
|
|
219
|
-
} =
|
|
220
|
-
if (
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
type:
|
|
224
|
-
query:
|
|
225
|
-
}), await
|
|
226
|
-
type:
|
|
227
|
-
results:
|
|
228
|
-
nextMarker:
|
|
229
|
-
}), (
|
|
230
|
-
type:
|
|
231
|
-
error:
|
|
232
|
-
}));
|
|
215
|
+
searchError: r,
|
|
216
|
+
searchQuery: e,
|
|
217
|
+
loadMoreError: s,
|
|
218
|
+
initialLoadError: t,
|
|
219
|
+
browseError: m,
|
|
220
|
+
namespaceFQN: x
|
|
221
|
+
} = w.current;
|
|
222
|
+
if (r) {
|
|
223
|
+
const d = F();
|
|
224
|
+
o({
|
|
225
|
+
type: a.SearchFetchStart,
|
|
226
|
+
query: e
|
|
227
|
+
}), u(() => n.current.onNewViewLoading?.(!0)), await g(d, () => B(e, d), (N) => o({
|
|
228
|
+
type: a.SearchLoaded,
|
|
229
|
+
results: N.entries,
|
|
230
|
+
nextMarker: N.next_marker
|
|
231
|
+
}), (N) => o({
|
|
232
|
+
type: a.SearchError,
|
|
233
|
+
error: L(N)
|
|
234
|
+
})), d.aborted || u(() => n.current.onNewViewLoading?.(!1));
|
|
233
235
|
return;
|
|
234
236
|
}
|
|
235
|
-
if (
|
|
236
|
-
await
|
|
237
|
+
if (s) {
|
|
238
|
+
await I();
|
|
237
239
|
return;
|
|
238
240
|
}
|
|
239
|
-
if (
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
type:
|
|
243
|
-
}), await
|
|
241
|
+
if (t || m) {
|
|
242
|
+
const d = h(), N = t ? a.InitialLoadError : a.BrowseError;
|
|
243
|
+
o({
|
|
244
|
+
type: a.BrowseFetchStart
|
|
245
|
+
}), u(() => n.current.onNewViewLoading?.(!0)), await _(x, d, N), d.aborted || u(() => n.current.onNewViewLoading?.(!1));
|
|
244
246
|
}
|
|
245
247
|
};
|
|
246
248
|
return $(
|
|
@@ -249,7 +251,7 @@ function oe(c, l, m, a, w) {
|
|
|
249
251
|
navigateTo: j,
|
|
250
252
|
navigateBack: z,
|
|
251
253
|
setSearchValue: J,
|
|
252
|
-
loadMore:
|
|
254
|
+
loadMore: I,
|
|
253
255
|
selectTemplate: K,
|
|
254
256
|
editTemplate: W,
|
|
255
257
|
retry: X
|
|
@@ -259,5 +261,5 @@ function oe(c, l, m, a, w) {
|
|
|
259
261
|
);
|
|
260
262
|
}
|
|
261
263
|
export {
|
|
262
|
-
|
|
264
|
+
or as useTemplateBrowserActions
|
|
263
265
|
};
|
|
@@ -52,6 +52,12 @@ export interface EventService {
|
|
|
52
52
|
onSearchChange?: (query: string) => Promise<void>;
|
|
53
53
|
onTemplateSelect?: (template: MetadataTemplate) => Promise<void>;
|
|
54
54
|
onTemplateEdit?: (templateId: string) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Called when an **initial-load, navigation, or search** fetch starts (`true`) or
|
|
57
|
+
* settles (`false`). Not called during `loadMore` pagination — that operation is
|
|
58
|
+
* tracked separately by the `isFetchingMore` flag in `BrowseStateContextValue`.
|
|
59
|
+
*/
|
|
60
|
+
onNewViewLoading?: (isFetching: boolean) => void;
|
|
55
61
|
}
|
|
56
62
|
export interface BreadcrumbEntry {
|
|
57
63
|
fqn: string;
|
|
@@ -98,7 +104,11 @@ export interface BrowserActionsContextValue {
|
|
|
98
104
|
navigateBack: (fqn: string) => void;
|
|
99
105
|
/** Updates the search query; an empty string exits search mode and returns to browse. */
|
|
100
106
|
setSearchValue: (value: string) => void;
|
|
101
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Fetches the next page of results for the current browse level or search query.
|
|
109
|
+
* Progress is tracked by `isFetchingMore` in `BrowseStateContextValue`;
|
|
110
|
+
* `onNewViewLoading` is intentionally not called during pagination.
|
|
111
|
+
*/
|
|
102
112
|
loadMore: () => Promise<void>;
|
|
103
113
|
/** Notifies the event service that the user has selected a template. */
|
|
104
114
|
selectTemplate: (template: MetadataTemplate) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/metadata-template-browser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@box/blueprint-web": "^14.
|
|
7
|
-
"@box/blueprint-web-assets": "^4.111.
|
|
6
|
+
"@box/blueprint-web": "^14.3.1",
|
|
7
|
+
"@box/blueprint-web-assets": "^4.111.21",
|
|
8
8
|
"lodash": "^4.17.15",
|
|
9
9
|
"react": "^18.0.0",
|
|
10
10
|
"react-dom": "^18.0.0",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"react-aria-components": "1.16.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@box/blueprint-web": "^14.
|
|
16
|
-
"@box/blueprint-web-assets": "^4.111.
|
|
15
|
+
"@box/blueprint-web": "^14.3.1",
|
|
16
|
+
"@box/blueprint-web-assets": "^4.111.21",
|
|
17
17
|
"@box/eslint-plugin-blueprint": "1.1.9",
|
|
18
|
-
"@box/storybook-utils": "0.17.
|
|
18
|
+
"@box/storybook-utils": "0.17.21",
|
|
19
19
|
"react-intl": "^6.4.2"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|