box-ui-elements 23.4.0-beta.29 → 23.4.0-beta.30
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/explorer.js +1 -1
- package/dist/preview.js +1 -1
- package/dist/sidebar.js +1 -1
- package/es/elements/content-sidebar/fetchers/metadataTaxonomyFetcher.js +11 -4
- package/es/elements/content-sidebar/fetchers/metadataTaxonomyFetcher.js.map +1 -1
- package/package.json +1 -1
- package/src/elements/content-sidebar/__tests__/metadataTaxonomyFetcher.test.ts +174 -10
- package/src/elements/content-sidebar/fetchers/metadataTaxonomyFetcher.ts +6 -1
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
const _excluded = ["display_name", "displayName"];
|
|
2
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
2
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
6
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
7
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
8
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
-
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
9
9
|
export const metadataTaxonomyFetcher = async (api, fileId, scope, templateKey, fieldKey, level, options) => {
|
|
10
10
|
const metadataOptions = await api.getMetadataAPI(false).getMetadataOptions(fileId, scope, templateKey, fieldKey, level, options);
|
|
11
11
|
const {
|
|
12
12
|
marker = null
|
|
13
13
|
} = options;
|
|
14
|
-
return {
|
|
14
|
+
return _objectSpread(_objectSpread({
|
|
15
15
|
options: metadataOptions.entries.map(metadataOption => ({
|
|
16
16
|
value: metadataOption.id,
|
|
17
17
|
displayValue: metadataOption.display_name || metadataOption.displayName,
|
|
18
18
|
level: metadataOption.level,
|
|
19
|
+
parentId: metadataOption.parentId,
|
|
20
|
+
nodePath: metadataOption.nodePath,
|
|
21
|
+
deprecated: metadataOption.deprecated,
|
|
19
22
|
ancestors: metadataOption.ancestors?.map(_ref => {
|
|
20
23
|
let {
|
|
21
24
|
display_name,
|
|
@@ -29,7 +32,11 @@ export const metadataTaxonomyFetcher = async (api, fileId, scope, templateKey, f
|
|
|
29
32
|
selectable: metadataOption.selectable
|
|
30
33
|
})),
|
|
31
34
|
marker
|
|
32
|
-
}
|
|
35
|
+
}, metadataOptions.total_result_count !== undefined && {
|
|
36
|
+
totalResultCount: metadataOptions.total_result_count
|
|
37
|
+
}), metadataOptions.limit !== undefined && {
|
|
38
|
+
limit: metadataOptions.limit
|
|
39
|
+
});
|
|
33
40
|
};
|
|
34
41
|
export const metadataTaxonomyNodeAncestorsFetcher = async (api, fileID, scope, taxonomyKey, nodeID) => {
|
|
35
42
|
const [metadataTaxonomy, metadataTaxonomyNode] = await Promise.all([api.getMetadataAPI(false).getMetadataTaxonomy(fileID, scope, taxonomyKey), api.getMetadataAPI(false).getMetadataTaxonomyNode(fileID, scope, taxonomyKey, nodeID, true)]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadataTaxonomyFetcher.js","names":["metadataTaxonomyFetcher","api","fileId","scope","templateKey","fieldKey","level","options","metadataOptions","getMetadataAPI","getMetadataOptions","marker","entries","map","metadataOption","value","id","displayValue","display_name","displayName","ancestors","_ref","rest","_objectWithoutProperties","_excluded","
|
|
1
|
+
{"version":3,"file":"metadataTaxonomyFetcher.js","names":["metadataTaxonomyFetcher","api","fileId","scope","templateKey","fieldKey","level","options","metadataOptions","getMetadataAPI","getMetadataOptions","marker","_objectSpread","entries","map","metadataOption","value","id","displayValue","display_name","displayName","parentId","nodePath","deprecated","ancestors","_ref","rest","_objectWithoutProperties","_excluded","selectable","total_result_count","undefined","totalResultCount","limit","metadataTaxonomyNodeAncestorsFetcher","fileID","taxonomyKey","nodeID","metadataTaxonomy","metadataTaxonomyNode","Promise","all","getMetadataTaxonomy","getMetadataTaxonomyNode","levels","levelsMap","Map","item","levelData","levelName","description","set","levelValue","length","ancestor","get","hydratedLevels","Array","from","values","filter"],"sources":["../../../../src/elements/content-sidebar/fetchers/metadataTaxonomyFetcher.ts"],"sourcesContent":["import { TreeQueryInput, TreeOptionType, FetcherResponse } from '@box/combobox-with-api';\nimport type API from '../../../api';\nimport type { MetadataOptionEntry } from '../../../common/types/metadata';\n\nexport const metadataTaxonomyFetcher = async (\n api: API,\n fileId: string,\n scope: string,\n templateKey: string,\n fieldKey: string,\n level: number,\n options: TreeQueryInput,\n): Promise<FetcherResponse<TreeOptionType>> => {\n const metadataOptions = await api\n .getMetadataAPI(false)\n .getMetadataOptions(fileId, scope, templateKey, fieldKey, level, options);\n const { marker = null } = options;\n\n return {\n options: metadataOptions.entries.map((metadataOption: MetadataOptionEntry) => ({\n value: metadataOption.id,\n displayValue: metadataOption.display_name || metadataOption.displayName,\n level: metadataOption.level,\n parentId: metadataOption.parentId,\n nodePath: metadataOption.nodePath,\n deprecated: metadataOption.deprecated,\n ancestors: metadataOption.ancestors?.map(({display_name, displayName, ...rest}) => ({...rest, displayName: display_name || displayName })),\n selectable: metadataOption.selectable,\n })),\n marker,\n ...(metadataOptions.total_result_count !== undefined && { totalResultCount: metadataOptions.total_result_count }),\n ...(metadataOptions.limit !== undefined && { limit: metadataOptions.limit }),\n } as FetcherResponse<TreeOptionType>;\n};\n\ntype HydratedMetadataTaxonomyLevel = {\n level: number;\n levelName: string;\n description: string;\n levelValue: string;\n id: string;\n};\n\nexport const metadataTaxonomyNodeAncestorsFetcher = async (\n api: API,\n fileID: string,\n scope: string,\n taxonomyKey: string,\n nodeID: string,\n): Promise<HydratedMetadataTaxonomyLevel[]> => {\n const [metadataTaxonomy, metadataTaxonomyNode] = await Promise.all([\n api.getMetadataAPI(false).getMetadataTaxonomy(fileID, scope, taxonomyKey),\n api.getMetadataAPI(false).getMetadataTaxonomyNode(fileID, scope, taxonomyKey, nodeID, true),\n ]);\n\n if (!metadataTaxonomy?.levels) {\n return [];\n }\n\n // Create a hashmap of levels to easily hydrate with data from metadataTaxonomyNode\n const levelsMap = new Map();\n for (const item of metadataTaxonomy.levels) {\n const levelData = {\n level: item.level,\n levelName: item.displayName || item.display_name,\n description: item.description,\n };\n\n // If the level matches the metadataTaxonomyNode level, hydrate the level with the node data\n if (metadataTaxonomyNode.level === item.level) {\n levelsMap.set(item.level, {\n ...levelData,\n id: metadataTaxonomyNode.id,\n levelValue: metadataTaxonomyNode.displayName || metadataTaxonomyNode.display_name,\n });\n // If the level is not the metadataTaxonomyNode level, just add the level data\n } else {\n levelsMap.set(item.level, levelData);\n }\n }\n // Hydrate the levels with the ancestors data from the metadataTaxonomyNode\n if (metadataTaxonomyNode.ancestors?.length) {\n for (const ancestor of metadataTaxonomyNode.ancestors) {\n const levelData = levelsMap.get(ancestor.level);\n\n if (levelData) {\n levelsMap.set(ancestor.level, { ...levelData, levelValue: ancestor.displayName || ancestor.display_name, id: ancestor.id });\n }\n }\n }\n\n // Filter out levels that were not hydrated by metadataTaxonomyNode\n const hydratedLevels = Array.from(levelsMap.values()).filter(level => !!level.id);\n\n // Return the hydrated levels as an array\n return hydratedLevels;\n};\n"],"mappings":";;;;;;;;AAIA,OAAO,MAAMA,uBAAuB,GAAG,MAAAA,CACnCC,GAAQ,EACRC,MAAc,EACdC,KAAa,EACbC,WAAmB,EACnBC,QAAgB,EAChBC,KAAa,EACbC,OAAuB,KACoB;EAC3C,MAAMC,eAAe,GAAG,MAAMP,GAAG,CAC5BQ,cAAc,CAAC,KAAK,CAAC,CACrBC,kBAAkB,CAACR,MAAM,EAAEC,KAAK,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,CAAC;EAC7E,MAAM;IAAEI,MAAM,GAAG;EAAK,CAAC,GAAGJ,OAAO;EAEjC,OAAAK,aAAA,CAAAA,aAAA;IACIL,OAAO,EAAEC,eAAe,CAACK,OAAO,CAACC,GAAG,CAAEC,cAAmC,KAAM;MAC3EC,KAAK,EAAED,cAAc,CAACE,EAAE;MACxBC,YAAY,EAAEH,cAAc,CAACI,YAAY,IAAIJ,cAAc,C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AAI,CAACb,SAAS,CAACc,MAAM,CAAC,CAAC,CAAC,CAACC,MAAM,CAACtD,KAAK,IAAI,CAAC,CAACA,KAAK,CAACW,EAAE,CAAC;;EAEjF;EACA,OAAOuC,cAAc;AACzB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -22,9 +22,29 @@ describe('metadataTaxonomyFetcher', () => {
|
|
|
22
22
|
test('should fetch metadata options and return formatted data - new naming convention', async () => {
|
|
23
23
|
const mockMetadataOptions = {
|
|
24
24
|
entries: [
|
|
25
|
-
{
|
|
26
|
-
|
|
25
|
+
{
|
|
26
|
+
id: 'opt1',
|
|
27
|
+
display_name: 'Option 1',
|
|
28
|
+
level: '1',
|
|
29
|
+
parentId: 'parent1',
|
|
30
|
+
nodePath: ['node1', 'node2'],
|
|
31
|
+
deprecated: false,
|
|
32
|
+
ancestors: null,
|
|
33
|
+
selectable: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'opt2',
|
|
37
|
+
display_name: 'Option 2',
|
|
38
|
+
level: '2',
|
|
39
|
+
parentId: 'parent2',
|
|
40
|
+
nodePath: ['node1', 'node3'],
|
|
41
|
+
deprecated: true,
|
|
42
|
+
ancestors: [{ display_name: 'Option 1', foo: 'bar' }],
|
|
43
|
+
selectable: true
|
|
44
|
+
},
|
|
27
45
|
],
|
|
46
|
+
limit: 100,
|
|
47
|
+
total_result_count: 2,
|
|
28
48
|
};
|
|
29
49
|
|
|
30
50
|
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);
|
|
@@ -33,10 +53,30 @@ describe('metadataTaxonomyFetcher', () => {
|
|
|
33
53
|
|
|
34
54
|
const expectedResult = {
|
|
35
55
|
options: [
|
|
36
|
-
{
|
|
37
|
-
|
|
56
|
+
{
|
|
57
|
+
value: 'opt1',
|
|
58
|
+
displayValue: 'Option 1',
|
|
59
|
+
level: '1',
|
|
60
|
+
parentId: 'parent1',
|
|
61
|
+
nodePath: ['node1', 'node2'],
|
|
62
|
+
deprecated: false,
|
|
63
|
+
ancestors: undefined,
|
|
64
|
+
selectable: false
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
value: 'opt2',
|
|
68
|
+
displayValue: 'Option 2',
|
|
69
|
+
level: '2',
|
|
70
|
+
parentId: 'parent2',
|
|
71
|
+
nodePath: ['node1', 'node3'],
|
|
72
|
+
deprecated: true,
|
|
73
|
+
ancestors: [{ displayName: 'Option 1', foo: 'bar' }],
|
|
74
|
+
selectable: true
|
|
75
|
+
},
|
|
38
76
|
],
|
|
39
77
|
marker: 'marker_1',
|
|
78
|
+
totalResultCount: 2,
|
|
79
|
+
limit: 100,
|
|
40
80
|
};
|
|
41
81
|
|
|
42
82
|
expect(apiMock.getMetadataAPI).toHaveBeenCalledWith(false);
|
|
@@ -54,9 +94,29 @@ describe('metadataTaxonomyFetcher', () => {
|
|
|
54
94
|
test('should fetch metadata options and return formatted data - old naming convention', async () => {
|
|
55
95
|
const mockMetadataOptions = {
|
|
56
96
|
entries: [
|
|
57
|
-
{
|
|
58
|
-
|
|
97
|
+
{
|
|
98
|
+
id: 'opt1',
|
|
99
|
+
displayName: 'Option 1',
|
|
100
|
+
level: '1',
|
|
101
|
+
parentId: 'parent1',
|
|
102
|
+
nodePath: ['node1', 'node2'],
|
|
103
|
+
deprecated: false,
|
|
104
|
+
ancestors: null,
|
|
105
|
+
selectable: false
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: 'opt2',
|
|
109
|
+
displayName: 'Option 2',
|
|
110
|
+
level: '2',
|
|
111
|
+
parentId: 'parent2',
|
|
112
|
+
nodePath: ['node1', 'node3'],
|
|
113
|
+
deprecated: true,
|
|
114
|
+
ancestors: [{ displayName: 'Option 1', foo: 'bar' }],
|
|
115
|
+
selectable: true
|
|
116
|
+
},
|
|
59
117
|
],
|
|
118
|
+
limit: 50,
|
|
119
|
+
total_result_count: 15,
|
|
60
120
|
};
|
|
61
121
|
|
|
62
122
|
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);
|
|
@@ -65,10 +125,30 @@ describe('metadataTaxonomyFetcher', () => {
|
|
|
65
125
|
|
|
66
126
|
const expectedResult = {
|
|
67
127
|
options: [
|
|
68
|
-
{
|
|
69
|
-
|
|
128
|
+
{
|
|
129
|
+
value: 'opt1',
|
|
130
|
+
displayValue: 'Option 1',
|
|
131
|
+
level: '1',
|
|
132
|
+
parentId: 'parent1',
|
|
133
|
+
nodePath: ['node1', 'node2'],
|
|
134
|
+
deprecated: false,
|
|
135
|
+
ancestors: undefined,
|
|
136
|
+
selectable: false
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
value: 'opt2',
|
|
140
|
+
displayValue: 'Option 2',
|
|
141
|
+
level: '2',
|
|
142
|
+
parentId: 'parent2',
|
|
143
|
+
nodePath: ['node1', 'node3'],
|
|
144
|
+
deprecated: true,
|
|
145
|
+
ancestors: [{ displayName: 'Option 1', foo: 'bar' }],
|
|
146
|
+
selectable: true
|
|
147
|
+
},
|
|
70
148
|
],
|
|
71
149
|
marker: 'marker_1',
|
|
150
|
+
totalResultCount: 15,
|
|
151
|
+
limit: 50,
|
|
72
152
|
};
|
|
73
153
|
|
|
74
154
|
expect(apiMock.getMetadataAPI).toHaveBeenCalledWith(false);
|
|
@@ -100,9 +180,51 @@ describe('metadataTaxonomyFetcher', () => {
|
|
|
100
180
|
expect(result).toEqual(expectedResult);
|
|
101
181
|
});
|
|
102
182
|
|
|
183
|
+
test('should not include limit and totalResultCount when not provided in metadataOptions', async () => {
|
|
184
|
+
const mockMetadataOptions = {
|
|
185
|
+
entries: [
|
|
186
|
+
{
|
|
187
|
+
id: 'opt1',
|
|
188
|
+
display_name: 'Option 1',
|
|
189
|
+
level: '1',
|
|
190
|
+
parentId: 'parent1',
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);
|
|
196
|
+
|
|
197
|
+
const result = await metadataTaxonomyFetcher(apiMock, fileId, scope, templateKey, fieldKey, level, options);
|
|
198
|
+
|
|
199
|
+
expect(result).toEqual({
|
|
200
|
+
options: [
|
|
201
|
+
{
|
|
202
|
+
value: 'opt1',
|
|
203
|
+
displayValue: 'Option 1',
|
|
204
|
+
level: '1',
|
|
205
|
+
parentId: 'parent1',
|
|
206
|
+
nodePath: undefined,
|
|
207
|
+
deprecated: undefined,
|
|
208
|
+
ancestors: undefined,
|
|
209
|
+
selectable: undefined,
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
marker: 'marker_1',
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
expect(result).not.toHaveProperty('limit');
|
|
216
|
+
expect(result).not.toHaveProperty('totalResultCount');
|
|
217
|
+
});
|
|
218
|
+
|
|
103
219
|
test('should set marker to null if not provided in options', async () => {
|
|
104
220
|
const mockMetadataOptions = {
|
|
105
|
-
entries: [{
|
|
221
|
+
entries: [{
|
|
222
|
+
id: 'opt1',
|
|
223
|
+
display_name: 'Option 1',
|
|
224
|
+
parentId: undefined,
|
|
225
|
+
nodePath: undefined,
|
|
226
|
+
deprecated: undefined,
|
|
227
|
+
}],
|
|
106
228
|
};
|
|
107
229
|
|
|
108
230
|
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);
|
|
@@ -110,13 +232,55 @@ describe('metadataTaxonomyFetcher', () => {
|
|
|
110
232
|
const result = await metadataTaxonomyFetcher(apiMock, fileId, scope, templateKey, fieldKey, level, {});
|
|
111
233
|
|
|
112
234
|
const expectedResult = {
|
|
113
|
-
options: [{
|
|
235
|
+
options: [{
|
|
236
|
+
value: 'opt1',
|
|
237
|
+
displayValue: 'Option 1',
|
|
238
|
+
parentId: undefined,
|
|
239
|
+
nodePath: undefined,
|
|
240
|
+
deprecated: undefined,
|
|
241
|
+
}],
|
|
114
242
|
marker: null,
|
|
115
243
|
};
|
|
116
244
|
|
|
117
245
|
expect(result).toEqual(expectedResult);
|
|
118
246
|
});
|
|
119
247
|
|
|
248
|
+
test('should handle missing new fields for backward compatibility', async () => {
|
|
249
|
+
const mockMetadataOptions = {
|
|
250
|
+
entries: [
|
|
251
|
+
{
|
|
252
|
+
id: 'opt1',
|
|
253
|
+
display_name: 'Option 1',
|
|
254
|
+
level: '1',
|
|
255
|
+
ancestors: null,
|
|
256
|
+
selectable: false
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);
|
|
262
|
+
|
|
263
|
+
const result = await metadataTaxonomyFetcher(apiMock, fileId, scope, templateKey, fieldKey, level, options);
|
|
264
|
+
|
|
265
|
+
const expectedResult = {
|
|
266
|
+
options: [
|
|
267
|
+
{
|
|
268
|
+
value: 'opt1',
|
|
269
|
+
displayValue: 'Option 1',
|
|
270
|
+
level: '1',
|
|
271
|
+
parentId: undefined,
|
|
272
|
+
nodePath: undefined,
|
|
273
|
+
deprecated: undefined,
|
|
274
|
+
ancestors: undefined,
|
|
275
|
+
selectable: false
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
marker: 'marker_1',
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
expect(result).toEqual(expectedResult);
|
|
282
|
+
});
|
|
283
|
+
|
|
120
284
|
test('should throw an error if getMetadataOptions fails', async () => {
|
|
121
285
|
const error = new Error('API Error');
|
|
122
286
|
apiMock.getMetadataAPI(false).getMetadataOptions.mockRejectedValue(error);
|
|
@@ -21,11 +21,16 @@ export const metadataTaxonomyFetcher = async (
|
|
|
21
21
|
value: metadataOption.id,
|
|
22
22
|
displayValue: metadataOption.display_name || metadataOption.displayName,
|
|
23
23
|
level: metadataOption.level,
|
|
24
|
+
parentId: metadataOption.parentId,
|
|
25
|
+
nodePath: metadataOption.nodePath,
|
|
26
|
+
deprecated: metadataOption.deprecated,
|
|
24
27
|
ancestors: metadataOption.ancestors?.map(({display_name, displayName, ...rest}) => ({...rest, displayName: display_name || displayName })),
|
|
25
28
|
selectable: metadataOption.selectable,
|
|
26
29
|
})),
|
|
27
30
|
marker,
|
|
28
|
-
|
|
31
|
+
...(metadataOptions.total_result_count !== undefined && { totalResultCount: metadataOptions.total_result_count }),
|
|
32
|
+
...(metadataOptions.limit !== undefined && { limit: metadataOptions.limit }),
|
|
33
|
+
} as FetcherResponse<TreeOptionType>;
|
|
29
34
|
};
|
|
30
35
|
|
|
31
36
|
type HydratedMetadataTaxonomyLevel = {
|