@box/metadata-template-browser 1.16.17 → 1.17.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,246 +1,248 @@
1
1
  import Y from "lodash/debounce";
2
- import { useRef as T, useMemo as $ } from "react";
3
- import { SEARCH_DEBOUNCE_MS as R, emptyTemplatesResponse as b, PAGE_SIZE as C, emptyNamespacesResponse as v } from "../constants.js";
4
- import { BrowserActionType as t } from "./reducer.js";
5
- const P = (c) => new Promise((l, m) => {
6
- if (c.aborted) {
7
- m(new DOMException("Aborted", "AbortError"));
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
- c.addEventListener("abort", () => m(new DOMException("Aborted", "AbortError")), {
10
+ i.addEventListener("abort", () => w(new DOMException("Aborted", "AbortError")), {
11
11
  once: !0
12
12
  });
13
- }), N = (c) => {
13
+ }), u = (i) => {
14
14
  try {
15
- const l = c();
16
- l instanceof Promise && l.catch(() => {
15
+ const n = i();
16
+ n instanceof Promise && n.catch(() => {
17
17
  });
18
18
  } catch {
19
19
  }
20
- }, S = (c) => c instanceof Error ? c.message : typeof c == "string" ? c : "An unknown error occurred", E = async (c, l, m, a) => {
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 w = await l();
23
- c.aborted || m(w);
24
- } catch (w) {
25
- c.aborted || a(w);
22
+ const M = await n();
23
+ i.aborted || w(M);
24
+ } catch (M) {
25
+ i.aborted || o(M);
26
26
  }
27
27
  };
28
- function oe(c, l, m, a, w) {
29
- const f = T(null), d = T(null), F = T(Y(async (e) => {
30
- d.current?.abort();
31
- const r = new AbortController();
32
- d.current = r;
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: o
35
- } = r;
36
- N(() => l.current.onSearchChange?.(e)), await E(o, () => B(e, o), (n) => a({
37
- type: t.SearchLoaded,
38
- results: n.entries,
39
- nextMarker: n.next_marker
40
- }), (n) => a({
41
- type: t.SearchError,
42
- error: S(n)
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
- f.current?.abort();
46
- const e = new AbortController();
47
- return f.current = e, e.signal;
45
+ E.current?.abort();
46
+ const r = new AbortController();
47
+ return E.current = r, r.signal;
48
48
  }, G = () => {
49
- f.current?.abort(), f.current = null;
50
- }, Q = () => {
51
- d.current?.abort();
52
- const e = new AbortController();
53
- return d.current = e, e.signal;
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
- d.current?.abort(), d.current = null;
56
- }, I = (e, r, o) => {
57
- const n = c.current.getNamespaces;
58
- return n ? Promise.race([n(e, {
59
- limit: C,
60
- marker: o,
61
- signal: r
62
- }), P(r)]) : Promise.resolve(v);
63
- }, g = (e, r, o) => {
64
- const n = c.current.getTemplates;
65
- return n ? Promise.race([n(e, {
66
- limit: C,
67
- marker: o,
68
- signal: r
69
- }), P(r)]) : Promise.resolve(b);
70
- }, B = (e, r, o) => {
71
- const n = c.current.getSearchResults;
72
- return n ? Promise.race([n(e, {
73
- limit: C,
74
- marker: o,
75
- signal: r
76
- }), P(r)]) : Promise.resolve(b);
77
- }, U = (e, r) => {
78
- a({
79
- type: e,
80
- error: S(r)
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
- }, L = async (e, r, o) => {
83
- let n = !1;
84
- return await E(r, async () => {
85
- const i = await I(e, r), M = i.next_marker ? b : await g(e, r);
86
- return [i, M];
87
- }, ([i, M]) => {
88
- a({
89
- type: t.BrowseLoaded,
90
- namespaces: i.entries,
91
- namespaceNextMarker: i.next_marker,
92
- templates: M.entries,
93
- templateNextMarker: M.next_marker
94
- }), n = !0;
95
- }, (i) => U(o, i)), n;
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 e = h(), {
98
- namespaceFQN: r
99
- } = m.current;
100
- a({
101
- type: t.BrowseFetchStart
102
- }), await L(r, e, t.InitialLoadError);
103
- }, j = async (e) => {
104
- const r = h(), o = m.current;
105
- w.current.set(o.namespaceFQN, {
106
- namespaces: o.namespaces,
107
- templates: o.templates,
108
- namespaceNextMarker: o.namespaceNextMarker,
109
- templateNextMarker: o.templateNextMarker,
110
- isNamespacesExhausted: o.isNamespacesExhausted
111
- }), a({
112
- type: t.NavigateTo,
113
- namespace: e
114
- }), a({
115
- type: t.BrowseFetchStart
116
- }), await L(e.id, r, t.BrowseError) && N(() => l.current.onNamespaceChange?.(e.id));
117
- }, z = (e) => {
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 r = w.current.get(e);
120
- r && (a({
121
- type: t.NavigateBack,
122
- fqn: e,
123
- cached: r
124
- }), N(() => l.current.onNamespaceChange?.(e)));
125
- }, J = (e) => {
126
- if (a({
127
- type: t.SearchValueChange,
128
- value: e
129
- }), e.trim() === "") {
130
- F.current.cancel(), H(), a({
131
- type: t.SearchClear
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
- a({
136
- type: t.SearchFetchStart,
137
- query: e.trim()
138
- }), F.current(e.trim());
139
- }, O = async () => {
137
+ o({
138
+ type: a.SearchFetchStart,
139
+ query: r.trim()
140
+ }), P.current(r.trim());
141
+ }, I = async () => {
140
142
  const {
141
- namespaceFQN: e,
142
- searchQuery: r,
143
- searchNextMarker: o,
144
- namespaceNextMarker: n,
145
- templateNextMarker: i,
146
- isNamespacesExhausted: M
147
- } = m.current, k = !!r, x = k && !!o, D = !k && !M && !!n, q = !k && !!i;
148
- if (!(x || D || q))
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
- a({
151
- type: t.LoadMoreStart
152
+ o({
153
+ type: a.LoadMoreStart
152
154
  });
153
- const _ = (u) => {
154
- a({
155
- type: t.LoadMoreError,
156
- error: S(u)
155
+ const A = (l) => {
156
+ o({
157
+ type: a.LoadMoreError,
158
+ error: L(l)
157
159
  });
158
- }, V = (u) => {
159
- const s = w.current.get(e);
160
- s && u(s);
160
+ }, q = (l) => {
161
+ const c = M.current.get(r);
162
+ c && l(c);
161
163
  };
162
- if (x) {
163
- const u = Q();
164
- await E(u, () => B(r, u, o), (s) => a({
165
- type: t.LoadMoreSearchLoaded,
166
- entries: s.entries,
167
- nextMarker: s.next_marker
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 (D) {
172
- const u = h();
173
- await E(u, async () => {
174
- const s = await I(e, u, n), p = s.next_marker ? b : await g(e, u);
175
- return [s, p];
176
- }, ([s, p]) => {
177
- const A = !s.next_marker;
178
- a({
179
- type: t.LoadMoreNamespacesLoaded,
180
- entries: s.entries,
181
- nextMarker: s.next_marker,
182
- ...A && {
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
- }), V((y) => {
187
- y.namespaces = [...y.namespaces, ...s.entries], y.namespaceNextMarker = s.next_marker, y.isNamespacesExhausted = A, A && (y.templates = p.entries, y.templateNextMarker = p.next_marker);
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 (q) {
193
- const u = h();
194
- await E(u, () => g(e, u, i), (s) => {
195
- a({
196
- type: t.LoadMoreTemplatesLoaded,
197
- entries: s.entries,
198
- nextMarker: s.next_marker
199
- }), V((p) => {
200
- p.templates = [...p.templates, ...s.entries], p.templateNextMarker = s.next_marker;
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 (e) => {
205
- m.current.selectedTemplateId !== e.id && (a({
206
- type: t.TemplateSelect,
207
- template: e
208
- }), N(() => l.current.onTemplateSelect?.(e)));
209
- }, W = (e) => {
210
- N(() => l.current.onTemplateEdit?.(e));
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: e,
214
- searchQuery: r,
215
- loadMoreError: o,
216
- initialLoadError: n,
217
- browseError: i,
218
- namespaceFQN: M
219
- } = m.current;
220
- if (e) {
221
- const k = Q();
222
- a({
223
- type: t.SearchFetchStart,
224
- query: r
225
- }), await E(k, () => B(r, k), (x) => a({
226
- type: t.SearchLoaded,
227
- results: x.entries,
228
- nextMarker: x.next_marker
229
- }), (x) => a({
230
- type: t.SearchError,
231
- error: S(x)
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 (o) {
236
- await O();
237
+ if (s) {
238
+ await I();
237
239
  return;
238
240
  }
239
- if (n || i) {
240
- const k = h(), x = n ? t.InitialLoadError : t.BrowseError;
241
- a({
242
- type: t.BrowseFetchStart
243
- }), await L(M, k, x);
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: O,
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
- oe as useTemplateBrowserActions
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
- /** Fetches the next page of results for the current browse level or search query. */
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.16.17",
3
+ "version": "1.17.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "peerDependencies": {
6
- "@box/blueprint-web": "^14.1.0",
7
- "@box/blueprint-web-assets": "^4.111.18",
6
+ "@box/blueprint-web": "^14.3.0",
7
+ "@box/blueprint-web-assets": "^4.111.20",
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.1.0",
16
- "@box/blueprint-web-assets": "^4.111.18",
15
+ "@box/blueprint-web": "^14.3.0",
16
+ "@box/blueprint-web-assets": "^4.111.20",
17
17
  "@box/eslint-plugin-blueprint": "1.1.9",
18
- "@box/storybook-utils": "0.17.18",
18
+ "@box/storybook-utils": "0.17.20",
19
19
  "react-intl": "^6.4.2"
20
20
  },
21
21
  "publishConfig": {