@blaze-cms/plugin-data-ui 0.147.0-rc-eagle.2 → 0.147.0-rc-eagle.6
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/README.md +9 -2
- package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +181 -0
- package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
- package/lib/components/ListingTable/SearchFilter/SearchContainer.js +338 -49
- package/lib/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -1
- package/lib/components/ListingTable/SearchFilter/SearchFilter.js +6 -2
- package/lib/components/ListingTable/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/ListingTable/SearchFilter/helpers.js +41 -8
- package/lib/components/ListingTable/SearchFilter/helpers.js.map +1 -1
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/get-default-query-params.js +17 -5
- package/lib/utils/get-default-query-params.js.map +1 -1
- package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
- package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +173 -0
- package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
- package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js +340 -51
- package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -1
- package/lib-es/components/ListingTable/SearchFilter/SearchFilter.js +7 -3
- package/lib-es/components/ListingTable/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/ListingTable/SearchFilter/helpers.js +39 -8
- package/lib-es/components/ListingTable/SearchFilter/helpers.js.map +1 -1
- package/lib-es/index.js +1 -0
- package/lib-es/index.js.map +1 -1
- package/lib-es/utils/get-default-query-params.js +17 -5
- package/lib-es/utils/get-default-query-params.js.map +1 -1
- package/package.json +11 -12
- package/src/components/EntityManager/Entity/Entity.js +2 -3
- package/src/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +160 -0
- package/src/components/ListingTable/SearchFilter/SearchContainer.js +396 -71
- package/src/components/ListingTable/SearchFilter/SearchFilter.js +5 -2
- package/src/components/ListingTable/SearchFilter/helpers.js +55 -8
- package/src/index.js +2 -0
- package/src/utils/get-default-query-params.js +21 -9
|
@@ -9,10 +9,15 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
var _select = _interopRequireDefault(require("@blaze-react/select"));
|
|
12
|
+
var _multiselect = _interopRequireDefault(require("@blaze-react/multiselect"));
|
|
13
|
+
var _lodash = _interopRequireDefault(require("lodash.debounce"));
|
|
14
|
+
var _lodash2 = _interopRequireDefault(require("lodash.unionby"));
|
|
12
15
|
var _client = require("@apollo/client");
|
|
13
16
|
var _adminUiUtils = require("@blaze-cms/admin-ui-utils");
|
|
17
|
+
var _utils = require("@blaze-cms/utils");
|
|
14
18
|
var _bs = require("react-icons/bs");
|
|
15
19
|
var _helpers = require("./helpers");
|
|
20
|
+
var _RelationMultiSelectFilter = _interopRequireDefault(require("./RelationMultiSelectFilter"));
|
|
16
21
|
var _querys = require("./querys");
|
|
17
22
|
var _constants = require("../../../constants");
|
|
18
23
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
@@ -22,15 +27,36 @@ const SearchContainer = ({
|
|
|
22
27
|
setListFilters,
|
|
23
28
|
keywordFiltersToUse = [],
|
|
24
29
|
selectFiltersToDisplay = [],
|
|
30
|
+
multiSelectFiltersToDisplay = [],
|
|
25
31
|
schema,
|
|
26
|
-
index
|
|
32
|
+
index,
|
|
33
|
+
values
|
|
27
34
|
}) => {
|
|
28
|
-
const
|
|
35
|
+
const client = (0, _client.useApolloClient)();
|
|
29
36
|
const [searchTerm, setSearchTerm] = (0, _react.useState)('');
|
|
30
37
|
const [selectedFilters, setSelectedFilters] = (0, _react.useState)({});
|
|
31
38
|
const [selectOptions, setSelectOptions] = (0, _react.useState)([]);
|
|
39
|
+
const [multiSelectOptions, setMultiSelectOptions] = (0, _react.useState)([]);
|
|
40
|
+
const [allEntitySchemas, setAllEntitySchemas] = (0, _react.useState)([]);
|
|
32
41
|
const displaySearchFilter = keywordFiltersToUse.length > 0;
|
|
33
42
|
const displaySelectFilters = selectFiltersToDisplay.length > 0;
|
|
43
|
+
const displayMultiSelectFilters = multiSelectFiltersToDisplay.length > 0;
|
|
44
|
+
const displayAggregations = displaySelectFilters || displayMultiSelectFilters;
|
|
45
|
+
(0, _react.useEffect)(() => {
|
|
46
|
+
(async () => {
|
|
47
|
+
try {
|
|
48
|
+
const all = await (0, _adminUiUtils.fetchAllEntities)({
|
|
49
|
+
client
|
|
50
|
+
});
|
|
51
|
+
setAllEntitySchemas(all || []);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
setAllEntitySchemas([]);
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
56
|
+
}, [client]);
|
|
57
|
+
const multiSelectPropertySet = (0, _react.useMemo)(() => new Set(multiSelectFiltersToDisplay.map(([property]) => property)), [multiSelectFiltersToDisplay]);
|
|
58
|
+
const relationMultiSelectFilters = (0, _react.useMemo)(() => multiSelectFiltersToDisplay.filter(([, config]) => config && config.relation), [multiSelectFiltersToDisplay]);
|
|
59
|
+
const nonRelationMultiSelectFilters = (0, _react.useMemo)(() => multiSelectFiltersToDisplay.filter(([, config]) => !config || !config.relation), [multiSelectFiltersToDisplay]);
|
|
34
60
|
const {
|
|
35
61
|
keywordSearchProperties,
|
|
36
62
|
keywordSearchLabels
|
|
@@ -51,19 +77,60 @@ const SearchContainer = ({
|
|
|
51
77
|
const {
|
|
52
78
|
gqlFields,
|
|
53
79
|
rawQuery
|
|
54
|
-
} = (0, _react.useMemo)(() => (0, _helpers.buildQueryFields)(selectFiltersToDisplay, schema.id), [selectFiltersToDisplay, schema.id]);
|
|
55
|
-
const action =
|
|
80
|
+
} = (0, _react.useMemo)(() => (0, _helpers.buildQueryFields)([...selectFiltersToDisplay, ...nonRelationMultiSelectFilters], schema.id), [selectFiltersToDisplay, nonRelationMultiSelectFilters, schema.id]);
|
|
81
|
+
const action = displayAggregations ? (0, _adminUiUtils.getDynamicQuery)('ADMIN_SEARCH')([schema], gqlFields, false, index) : _querys.NOOP_QUERY;
|
|
56
82
|
const {
|
|
57
83
|
data
|
|
58
84
|
} = (0, _client.useQuery)(action, {
|
|
59
|
-
skip: !
|
|
85
|
+
skip: !displayAggregations,
|
|
60
86
|
variables: {
|
|
61
87
|
where: rawQuery,
|
|
62
88
|
limit: 0
|
|
63
89
|
},
|
|
64
90
|
fetchPolicy: 'cache-and-network'
|
|
65
91
|
});
|
|
66
|
-
const
|
|
92
|
+
const buildRelationsIndex = (0, _react.useCallback)(schemaObj => {
|
|
93
|
+
const items = [];
|
|
94
|
+
if (schemaObj.properties) {
|
|
95
|
+
Object.entries(schemaObj.properties).forEach(([propName, definition]) => {
|
|
96
|
+
const {
|
|
97
|
+
relation
|
|
98
|
+
} = definition || {};
|
|
99
|
+
if (!relation) return;
|
|
100
|
+
const {
|
|
101
|
+
localField: relationLocalField,
|
|
102
|
+
entityIdentifier
|
|
103
|
+
} = relation;
|
|
104
|
+
const localField = relationLocalField || propName;
|
|
105
|
+
if (localField) items.push({
|
|
106
|
+
localField,
|
|
107
|
+
entityIdentifier
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(schemaObj.relations)) {
|
|
112
|
+
schemaObj.relations.forEach(relation => {
|
|
113
|
+
if (!relation.localField) return;
|
|
114
|
+
const {
|
|
115
|
+
localField,
|
|
116
|
+
entityIdentifier
|
|
117
|
+
} = relation;
|
|
118
|
+
items.push({
|
|
119
|
+
localField,
|
|
120
|
+
entityIdentifier
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const byKey = new Map();
|
|
125
|
+
items.forEach(item => {
|
|
126
|
+
const key = `${item.localField}|${item.entityIdentifier || ''}`;
|
|
127
|
+
if (!byKey.has(key)) byKey.set(key, item);
|
|
128
|
+
});
|
|
129
|
+
return Array.from(byKey.values());
|
|
130
|
+
}, []);
|
|
131
|
+
const relationsIndex = (0, _react.useMemo)(() => buildRelationsIndex(schema), [schema, buildRelationsIndex]);
|
|
132
|
+
const stringTypeProps = (0, _react.useMemo)(() => (0, _utils.getStringTypeProps)(schema.id, relationsIndex, allEntitySchemas), [schema.id, relationsIndex, allEntitySchemas]);
|
|
133
|
+
const aggregationsData = (0, _react.useMemo)(() => {
|
|
67
134
|
const {
|
|
68
135
|
searchResults: {
|
|
69
136
|
rawResults: {
|
|
@@ -71,48 +138,61 @@ const SearchContainer = ({
|
|
|
71
138
|
} = {}
|
|
72
139
|
} = {}
|
|
73
140
|
} = data || {};
|
|
74
|
-
const
|
|
141
|
+
const processed = [];
|
|
75
142
|
Object.entries(aggregations).forEach(([key, {
|
|
76
143
|
buckets
|
|
77
144
|
}]) => {
|
|
78
|
-
|
|
145
|
+
processed.push(Array.isArray(buckets) ? [key, buckets.map(bucket => bucket.key).filter(Boolean)] : []);
|
|
79
146
|
});
|
|
80
|
-
return
|
|
147
|
+
return processed;
|
|
81
148
|
}, [data]);
|
|
149
|
+
const findFilterConfig = (0, _react.useCallback)(property => {
|
|
150
|
+
var _selectFiltersToDispl, _multiSelectFiltersTo;
|
|
151
|
+
return ((_selectFiltersToDispl = selectFiltersToDisplay.find(([prop]) => prop === property)) === null || _selectFiltersToDispl === void 0 ? void 0 : _selectFiltersToDispl[1]) || ((_multiSelectFiltersTo = multiSelectFiltersToDisplay.find(([prop]) => prop === property)) === null || _multiSelectFiltersTo === void 0 ? void 0 : _multiSelectFiltersTo[1]);
|
|
152
|
+
}, [selectFiltersToDisplay, multiSelectFiltersToDisplay]);
|
|
82
153
|
(0, _react.useEffect)(() => {
|
|
83
|
-
if (!
|
|
154
|
+
if (!aggregationsData.length) {
|
|
84
155
|
setSelectOptions([]);
|
|
156
|
+
setMultiSelectOptions([]);
|
|
85
157
|
return;
|
|
86
158
|
}
|
|
87
159
|
(async () => {
|
|
88
|
-
const results = await Promise.all(
|
|
160
|
+
const results = await Promise.all(aggregationsData.map(async ([property, ids]) => {
|
|
89
161
|
try {
|
|
90
|
-
if (!ids || !ids.length) return
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
93
|
-
|
|
162
|
+
if (!ids || !ids.length) return null;
|
|
163
|
+
const config = findFilterConfig(property);
|
|
164
|
+
if (!config) return null;
|
|
165
|
+
const {
|
|
166
|
+
adminListingOptions: {
|
|
167
|
+
tidyLabel
|
|
168
|
+
} = {}
|
|
169
|
+
} = config;
|
|
170
|
+
if (!config.relation) {
|
|
171
|
+
const baseOptions = ids.map(value => [value, (0, _helpers.getTidyLabel)(value, tidyLabel)]);
|
|
94
172
|
return {
|
|
95
|
-
|
|
96
|
-
label:
|
|
97
|
-
|
|
173
|
+
property,
|
|
174
|
+
label: config.label,
|
|
175
|
+
type: multiSelectPropertySet.has(property) ? 'multi' : 'single',
|
|
176
|
+
options: baseOptions,
|
|
177
|
+
selected: values && values[property]
|
|
98
178
|
};
|
|
99
179
|
}
|
|
100
|
-
const
|
|
180
|
+
const schemaQuery = (0, _adminUiUtils.getQuery)('GET_ENTITY_SCHEMA');
|
|
101
181
|
const {
|
|
102
182
|
data: {
|
|
103
183
|
getEntitySchemas: [relationSchema]
|
|
104
184
|
}
|
|
105
|
-
} = await
|
|
106
|
-
query,
|
|
185
|
+
} = await client.query({
|
|
186
|
+
query: schemaQuery,
|
|
107
187
|
variables: {
|
|
108
|
-
identifier:
|
|
188
|
+
identifier: config.relation.entityIdentifier
|
|
109
189
|
}
|
|
110
190
|
});
|
|
111
191
|
const {
|
|
112
192
|
data: {
|
|
113
193
|
result: selected = []
|
|
114
194
|
}
|
|
115
|
-
} = await
|
|
195
|
+
} = await client.query({
|
|
116
196
|
query: (0, _adminUiUtils.getDynamicQuery)('GET_ALL_ENTITIES')(relationSchema),
|
|
117
197
|
variables: {
|
|
118
198
|
where: {
|
|
@@ -127,45 +207,183 @@ const SearchContainer = ({
|
|
|
127
207
|
}
|
|
128
208
|
})
|
|
129
209
|
// eslint-disable-next-line no-console
|
|
130
|
-
.catch(
|
|
210
|
+
.catch(error => console.error(error));
|
|
211
|
+
const baseOptions = selected.map(item => [item.id, (0, _helpers.getTidyLabel)(item.name, tidyLabel)]);
|
|
131
212
|
return {
|
|
132
|
-
|
|
133
|
-
label:
|
|
134
|
-
|
|
213
|
+
property,
|
|
214
|
+
label: config.label || config.relation.label,
|
|
215
|
+
type: multiSelectPropertySet.has(property) ? 'multi' : 'single',
|
|
216
|
+
options: baseOptions,
|
|
217
|
+
selected: values && values[property]
|
|
135
218
|
};
|
|
136
219
|
} catch {
|
|
137
220
|
return null;
|
|
138
221
|
}
|
|
139
222
|
}));
|
|
140
|
-
|
|
223
|
+
const valid = results.filter(Boolean);
|
|
224
|
+
setSelectOptions(valid.filter(option => option.type === 'single').map(({
|
|
225
|
+
property,
|
|
226
|
+
label,
|
|
227
|
+
options,
|
|
228
|
+
selected
|
|
229
|
+
}) => ({
|
|
230
|
+
id: property,
|
|
231
|
+
label,
|
|
232
|
+
options,
|
|
233
|
+
selected
|
|
234
|
+
})));
|
|
235
|
+
setMultiSelectOptions(valid.filter(option => option.type === 'multi').map(({
|
|
236
|
+
property,
|
|
237
|
+
label,
|
|
238
|
+
options,
|
|
239
|
+
selected
|
|
240
|
+
}) => ({
|
|
241
|
+
id: property,
|
|
242
|
+
label,
|
|
243
|
+
items: options.map(([id, name]) => ({
|
|
244
|
+
id,
|
|
245
|
+
name
|
|
246
|
+
})),
|
|
247
|
+
selected
|
|
248
|
+
})));
|
|
141
249
|
})();
|
|
142
|
-
}, [
|
|
250
|
+
}, [client, aggregationsData, findFilterConfig, multiSelectPropertySet, values]);
|
|
143
251
|
const updateFilters = (0, _react.useCallback)((term, filters) => (0, _helpers.updateListFilters)(term, filters, setListFilters, keywordSearchProperties), [setListFilters, keywordSearchProperties]);
|
|
252
|
+
const debouncedUpdateFilters = (0, _react.useMemo)(() => (0, _lodash.default)((term, filters) => updateFilters(term, filters), 300), [updateFilters]);
|
|
253
|
+
(0, _react.useEffect)(() => () => debouncedUpdateFilters.cancel(), [debouncedUpdateFilters]);
|
|
144
254
|
const handleSearch = (0, _react.useCallback)(() => updateFilters(searchTerm, selectedFilters), [searchTerm, selectedFilters, updateFilters]);
|
|
145
|
-
const handleSearchChange = (0, _react.useCallback)(
|
|
146
|
-
|
|
147
|
-
|
|
255
|
+
const handleSearchChange = (0, _react.useCallback)(({
|
|
256
|
+
target: {
|
|
257
|
+
value
|
|
258
|
+
}
|
|
259
|
+
}) => setSearchTerm(value), []);
|
|
260
|
+
const handleEnterKey = (0, _react.useCallback)(({
|
|
261
|
+
key
|
|
262
|
+
}) => {
|
|
263
|
+
if (key === _constants.ENTER_KEY) handleSearch();
|
|
148
264
|
}, [handleSearch]);
|
|
149
265
|
const handleReset = (0, _react.useCallback)(() => {
|
|
150
266
|
setSearchTerm('');
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
267
|
+
debouncedUpdateFilters.cancel();
|
|
268
|
+
setSelectedFilters(prev => Object.keys(prev).reduce((acc, key) => {
|
|
269
|
+
acc[key] = multiSelectPropertySet.has(key) ? [] : _constants.DEFAULT_FILTER_OPTION_LABEL;
|
|
270
|
+
return acc;
|
|
271
|
+
}, {}));
|
|
154
272
|
updateFilters('', {});
|
|
155
|
-
}, [
|
|
156
|
-
const handleSelect = (0, _react.useCallback)((property,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
} = event;
|
|
273
|
+
}, [multiSelectPropertySet, updateFilters, debouncedUpdateFilters]);
|
|
274
|
+
const handleSelect = (0, _react.useCallback)((property, {
|
|
275
|
+
value
|
|
276
|
+
}) => {
|
|
160
277
|
const next = _objectSpread(_objectSpread({}, selectedFilters), {}, {
|
|
161
278
|
[property]: value
|
|
162
279
|
});
|
|
163
280
|
setSelectedFilters(next);
|
|
164
|
-
|
|
165
|
-
}, [searchTerm, selectedFilters,
|
|
281
|
+
debouncedUpdateFilters(searchTerm, next);
|
|
282
|
+
}, [searchTerm, selectedFilters, debouncedUpdateFilters]);
|
|
283
|
+
const handleMultiSelect = (0, _react.useCallback)((property, ids) => {
|
|
284
|
+
const next = _objectSpread(_objectSpread({}, selectedFilters), {}, {
|
|
285
|
+
[property]: ids
|
|
286
|
+
});
|
|
287
|
+
setSelectedFilters(next);
|
|
288
|
+
debouncedUpdateFilters(searchTerm, next);
|
|
289
|
+
}, [searchTerm, selectedFilters, debouncedUpdateFilters]);
|
|
290
|
+
const findRelationByLocalField = (0, _react.useCallback)(localField => relationsIndex.find(relation => relation.localField === localField), [relationsIndex]);
|
|
291
|
+
const resolveAggProp = (0, _react.useCallback)((property, config) => {
|
|
292
|
+
if (!config.relation) return property;
|
|
293
|
+
if (property.includes('.')) return property;
|
|
294
|
+
const localField = config.relation.localField || property;
|
|
295
|
+
return `${localField}.name`;
|
|
296
|
+
}, []);
|
|
297
|
+
const resolveEntityIdentifier = (0, _react.useCallback)((property, config) => {
|
|
298
|
+
if (!config.relation) return undefined;
|
|
299
|
+
if (config.relation.entityIdentifier) return config.relation.entityIdentifier;
|
|
300
|
+
const localField = property.includes('.') ? property.split('.')[0] : config.relation.localField || property;
|
|
301
|
+
return findRelationByLocalField(localField).entityIdentifier;
|
|
302
|
+
}, [findRelationByLocalField]);
|
|
303
|
+
const addEntitySuffixIfNeeded = (0, _react.useCallback)((aggProp, entityIdentifier, config) => {
|
|
304
|
+
if (!config.relation || !entityIdentifier) return aggProp;
|
|
305
|
+
return `${aggProp}/${entityIdentifier}`;
|
|
306
|
+
}, []);
|
|
307
|
+
const makeOnSearchChange = (0, _react.useCallback)(property => async ({
|
|
308
|
+
event: {
|
|
309
|
+
value
|
|
310
|
+
},
|
|
311
|
+
currentOffset
|
|
312
|
+
}) => {
|
|
313
|
+
try {
|
|
314
|
+
var _config$relation, _aggregations$key, _multiSelectOptions$f;
|
|
315
|
+
if (!value || currentOffset) return [];
|
|
316
|
+
const config = findFilterConfig(property);
|
|
317
|
+
if (!config) return [];
|
|
318
|
+
let aggProp = resolveAggProp(property, config);
|
|
319
|
+
if (config.relation && !config.relation.localField && !property.includes('.')) {
|
|
320
|
+
const matchingRelation = findRelationByLocalField(property);
|
|
321
|
+
if (matchingRelation.localField) aggProp = `${matchingRelation.localField}.name`;
|
|
322
|
+
}
|
|
323
|
+
const entityIdentifier = resolveEntityIdentifier(property, config) || ((_config$relation = config.relation) === null || _config$relation === void 0 ? void 0 : _config$relation.entityIdentifier);
|
|
324
|
+
const filterByEntry = addEntitySuffixIfNeeded(aggProp, entityIdentifier, config);
|
|
325
|
+
const currentValues = {
|
|
326
|
+
entity: schema.id,
|
|
327
|
+
filterByProperty: [filterByEntry]
|
|
328
|
+
};
|
|
329
|
+
const aggregations = await (0, _adminUiUtils.fetchFilterByDataFromElastic)(client, currentValues, relationsIndex, stringTypeProps, value);
|
|
330
|
+
const key = aggProp;
|
|
331
|
+
const buckets = (aggregations === null || aggregations === void 0 ? void 0 : (_aggregations$key = aggregations[key]) === null || _aggregations$key === void 0 ? void 0 : _aggregations$key.buckets) || [];
|
|
332
|
+
let items = [];
|
|
333
|
+
if (config.relation) {
|
|
334
|
+
const names = buckets.map(bucket => bucket.key).filter(Boolean);
|
|
335
|
+
if (names.length) {
|
|
336
|
+
const schemaQuery = (0, _adminUiUtils.getQuery)('GET_ENTITY_SCHEMA');
|
|
337
|
+
const {
|
|
338
|
+
data: {
|
|
339
|
+
getEntitySchemas: [relationSchema]
|
|
340
|
+
}
|
|
341
|
+
} = await client.query({
|
|
342
|
+
query: schemaQuery,
|
|
343
|
+
variables: {
|
|
344
|
+
identifier: entityIdentifier
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
const {
|
|
348
|
+
data: {
|
|
349
|
+
result: selected = []
|
|
350
|
+
}
|
|
351
|
+
} = await client.query({
|
|
352
|
+
query: (0, _adminUiUtils.getDynamicQuery)('GET_ALL_ENTITIES')(relationSchema),
|
|
353
|
+
variables: {
|
|
354
|
+
where: {
|
|
355
|
+
name: {
|
|
356
|
+
_in: names
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
sort: [{
|
|
360
|
+
property: 'name',
|
|
361
|
+
direction: 'asc'
|
|
362
|
+
}]
|
|
363
|
+
}
|
|
364
|
+
})
|
|
365
|
+
// eslint-disable-next-line no-console
|
|
366
|
+
.catch(error => console.error(error));
|
|
367
|
+
items = selected.map(item => ({
|
|
368
|
+
id: item.id,
|
|
369
|
+
name: item.name
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
items = buckets.map(bucket => ({
|
|
374
|
+
id: bucket.key,
|
|
375
|
+
name: bucket.key
|
|
376
|
+
})).filter(option => option.id != null);
|
|
377
|
+
}
|
|
378
|
+
const existingItems = ((_multiSelectOptions$f = multiSelectOptions.find(opt => opt.id === property)) === null || _multiSelectOptions$f === void 0 ? void 0 : _multiSelectOptions$f.items) || [];
|
|
379
|
+
return (0, _lodash2.default)(items, existingItems, 'id');
|
|
380
|
+
} catch (error) {
|
|
381
|
+
return [];
|
|
382
|
+
}
|
|
383
|
+
}, [client, schema.id, relationsIndex, stringTypeProps, multiSelectOptions, findFilterConfig, resolveAggProp, resolveEntityIdentifier, addEntitySuffixIfNeeded, findRelationByLocalField]);
|
|
166
384
|
const placeholderText = `Search ${keywordSearchLabels.join(', ')}`;
|
|
167
385
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
168
|
-
className: "search-container"
|
|
386
|
+
className: "search-container ms-filter"
|
|
169
387
|
}, displaySearchFilter && /*#__PURE__*/_react.default.createElement("div", {
|
|
170
388
|
className: "search-container__search-input-container"
|
|
171
389
|
}, /*#__PURE__*/_react.default.createElement("input", {
|
|
@@ -181,18 +399,87 @@ const SearchContainer = ({
|
|
|
181
399
|
}, /*#__PURE__*/_react.default.createElement(_bs.BsSearch, null))), displaySelectFilters && selectOptions.map(({
|
|
182
400
|
id,
|
|
183
401
|
options,
|
|
184
|
-
label
|
|
185
|
-
|
|
186
|
-
|
|
402
|
+
label,
|
|
403
|
+
selected
|
|
404
|
+
}) => options && options.length ? /*#__PURE__*/_react.default.createElement("div", {
|
|
405
|
+
className: "search-container__select-wrapper",
|
|
406
|
+
key: `select-${id}`
|
|
187
407
|
}, /*#__PURE__*/_react.default.createElement(_select.default, {
|
|
188
408
|
label: label,
|
|
189
409
|
id: id,
|
|
190
410
|
name: id,
|
|
191
|
-
onChange:
|
|
411
|
+
onChange: ({
|
|
412
|
+
value
|
|
413
|
+
}) => handleSelect(id, {
|
|
414
|
+
value
|
|
415
|
+
}),
|
|
192
416
|
options: options,
|
|
193
|
-
value: selectedFilters[id],
|
|
417
|
+
value: selectedFilters[id] !== undefined ? selectedFilters[id] : selected,
|
|
194
418
|
defaultTextValue: _constants.DEFAULT_FILTER_OPTION_LABEL
|
|
195
|
-
})))
|
|
419
|
+
})) : null), displayMultiSelectFilters && multiSelectOptions.map(({
|
|
420
|
+
id,
|
|
421
|
+
label,
|
|
422
|
+
items
|
|
423
|
+
}) => {
|
|
424
|
+
const selectedIds = selectedFilters[id] ? selectedFilters[id] : [];
|
|
425
|
+
const multiSelectData = {
|
|
426
|
+
filterBy: ['name'],
|
|
427
|
+
identification: 'id',
|
|
428
|
+
keyValue: 'name',
|
|
429
|
+
data: items.map(({
|
|
430
|
+
id: itemId,
|
|
431
|
+
name
|
|
432
|
+
}) => ({
|
|
433
|
+
id: itemId,
|
|
434
|
+
name,
|
|
435
|
+
description: '',
|
|
436
|
+
checked: selectedIds.includes(itemId),
|
|
437
|
+
show: true
|
|
438
|
+
}))
|
|
439
|
+
};
|
|
440
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
441
|
+
className: "search-container__select-wrapper",
|
|
442
|
+
key: `multiselect-${id}`
|
|
443
|
+
}, /*#__PURE__*/_react.default.createElement(_multiselect.default, {
|
|
444
|
+
onChange: ({
|
|
445
|
+
value,
|
|
446
|
+
currentOffset
|
|
447
|
+
}) => makeOnSearchChange(id)({
|
|
448
|
+
event: {
|
|
449
|
+
value
|
|
450
|
+
},
|
|
451
|
+
currentOffset
|
|
452
|
+
}),
|
|
453
|
+
name: id,
|
|
454
|
+
label: label,
|
|
455
|
+
data: multiSelectData,
|
|
456
|
+
limit: 10,
|
|
457
|
+
getSelected: ({
|
|
458
|
+
event: {
|
|
459
|
+
target: {
|
|
460
|
+
value
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}) => handleMultiSelect(id, value),
|
|
464
|
+
required: false,
|
|
465
|
+
checkedPreviewCount: 1,
|
|
466
|
+
formatMoreLabel: n => `${n} more`
|
|
467
|
+
}));
|
|
468
|
+
}), relationMultiSelectFilters.map(([property, config]) => {
|
|
469
|
+
var _config$relation2;
|
|
470
|
+
const entityIdentifier = resolveEntityIdentifier(property, config) || ((_config$relation2 = config.relation) === null || _config$relation2 === void 0 ? void 0 : _config$relation2.entityIdentifier);
|
|
471
|
+
if (!entityIdentifier) return null;
|
|
472
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
473
|
+
className: "search-container__select-wrapper",
|
|
474
|
+
key: `relation-multiselect-${property}`
|
|
475
|
+
}, /*#__PURE__*/_react.default.createElement(_RelationMultiSelectFilter.default, {
|
|
476
|
+
id: property,
|
|
477
|
+
label: config.label || config.relation.label,
|
|
478
|
+
entityIdentifier: entityIdentifier,
|
|
479
|
+
selectedIds: selectedFilters[property] || [],
|
|
480
|
+
onChange: handleMultiSelect
|
|
481
|
+
}));
|
|
482
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
196
483
|
className: "search-container__reset-button"
|
|
197
484
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
198
485
|
role: "button",
|
|
@@ -203,12 +490,14 @@ SearchContainer.propTypes = {
|
|
|
203
490
|
setListFilters: _propTypes.default.func.isRequired,
|
|
204
491
|
keywordFiltersToUse: _propTypes.default.array,
|
|
205
492
|
selectFiltersToDisplay: _propTypes.default.array,
|
|
493
|
+
multiSelectFiltersToDisplay: _propTypes.default.array,
|
|
206
494
|
schema: _propTypes.default.object.isRequired,
|
|
207
495
|
index: _propTypes.default.string
|
|
208
496
|
};
|
|
209
497
|
SearchContainer.defaultProps = {
|
|
210
498
|
keywordFiltersToUse: [],
|
|
211
499
|
selectFiltersToDisplay: [],
|
|
500
|
+
multiSelectFiltersToDisplay: [],
|
|
212
501
|
index: 'admin'
|
|
213
502
|
};
|
|
214
503
|
var _default = exports.default = SearchContainer;
|