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