@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.
Files changed (183) hide show
  1. package/README.md +9 -2
  2. package/lib/components/EntityManager/Entity/Entity.js +1 -1
  3. package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
  4. package/lib/components/EntityManager/Entity/actions-handlers/create/submit.js +4 -15
  5. package/lib/components/EntityManager/Entity/actions-handlers/create/submit.js.map +1 -1
  6. package/lib/components/EntityManager/utils/entity.js +2 -3
  7. package/lib/components/EntityManager/utils/entity.js.map +1 -1
  8. package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +181 -0
  9. package/lib/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
  10. package/lib/components/ListingTable/SearchFilter/SearchContainer.js +348 -52
  11. package/lib/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -1
  12. package/lib/components/ListingTable/SearchFilter/SearchFilter.js +15 -3
  13. package/lib/components/ListingTable/SearchFilter/SearchFilter.js.map +1 -1
  14. package/lib/components/ListingTable/SearchFilter/helpers.js +41 -8
  15. package/lib/components/ListingTable/SearchFilter/helpers.js.map +1 -1
  16. package/lib/index.js +7 -0
  17. package/lib/index.js.map +1 -1
  18. package/lib/utils/build-create-entity-mutation.js +3 -19
  19. package/lib/utils/build-create-entity-mutation.js.map +1 -1
  20. package/lib/utils/get-default-query-params.js +17 -5
  21. package/lib/utils/get-default-query-params.js.map +1 -1
  22. package/lib-es/components/EntityDataListing/EntityDataListing.js +33 -0
  23. package/lib-es/components/EntityDataListing/EntityDataListing.js.map +1 -0
  24. package/lib-es/components/EntityDataListing/index.js +3 -0
  25. package/lib-es/components/EntityDataListing/index.js.map +1 -0
  26. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +30 -0
  27. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
  28. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
  29. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
  30. package/lib-es/components/EntityManager/Entity/Entity.js +453 -0
  31. package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -0
  32. package/lib-es/components/EntityManager/Entity/EntityHeader/EntityHeader.js +103 -0
  33. package/lib-es/components/EntityManager/Entity/EntityHeader/EntityHeader.js.map +1 -0
  34. package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js +47 -0
  35. package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/HeaderPreviewButton.js.map +1 -0
  36. package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/index.js +3 -0
  37. package/lib-es/components/EntityManager/Entity/EntityHeader/HeaderPreviewButton/index.js.map +1 -0
  38. package/lib-es/components/EntityManager/Entity/EntityHeader/index.js +3 -0
  39. package/lib-es/components/EntityManager/Entity/EntityHeader/index.js.map +1 -0
  40. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +30 -0
  41. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
  42. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +29 -0
  43. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
  44. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +49 -0
  45. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
  46. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +136 -0
  47. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -0
  48. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +36 -0
  49. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
  50. package/lib-es/components/EntityManager/Entity/actions-handlers/create/index.js +5 -0
  51. package/lib-es/components/EntityManager/Entity/actions-handlers/create/index.js.map +1 -0
  52. package/lib-es/components/EntityManager/Entity/actions-handlers/create/submit.js +36 -0
  53. package/lib-es/components/EntityManager/Entity/actions-handlers/create/submit.js.map +1 -0
  54. package/lib-es/components/EntityManager/Entity/actions-handlers/delete/delete.js +32 -0
  55. package/lib-es/components/EntityManager/Entity/actions-handlers/delete/delete.js.map +1 -0
  56. package/lib-es/components/EntityManager/Entity/actions-handlers/delete/index.js +5 -0
  57. package/lib-es/components/EntityManager/Entity/actions-handlers/delete/index.js.map +1 -0
  58. package/lib-es/components/EntityManager/Entity/actions-handlers/index.js +12 -0
  59. package/lib-es/components/EntityManager/Entity/actions-handlers/index.js.map +1 -0
  60. package/lib-es/components/EntityManager/Entity/actions-handlers/shared/index.js +5 -0
  61. package/lib-es/components/EntityManager/Entity/actions-handlers/shared/index.js.map +1 -0
  62. package/lib-es/components/EntityManager/Entity/actions-handlers/shared/publish.js +39 -0
  63. package/lib-es/components/EntityManager/Entity/actions-handlers/shared/publish.js.map +1 -0
  64. package/lib-es/components/EntityManager/Entity/actions-handlers/update/index.js +5 -0
  65. package/lib-es/components/EntityManager/Entity/actions-handlers/update/index.js.map +1 -0
  66. package/lib-es/components/EntityManager/Entity/actions-handlers/update/submit.js +53 -0
  67. package/lib-es/components/EntityManager/Entity/actions-handlers/update/submit.js.map +1 -0
  68. package/lib-es/components/EntityManager/Entity/index.js +3 -0
  69. package/lib-es/components/EntityManager/Entity/index.js.map +1 -0
  70. package/lib-es/components/EntityManager/EntityManager.js +133 -0
  71. package/lib-es/components/EntityManager/EntityManager.js.map +1 -0
  72. package/lib-es/components/EntityManager/index.js +3 -0
  73. package/lib-es/components/EntityManager/index.js.map +1 -0
  74. package/lib-es/components/EntityManager/utils/RecordEditContext/index.js +6 -0
  75. package/lib-es/components/EntityManager/utils/RecordEditContext/index.js.map +1 -0
  76. package/lib-es/components/EntityManager/utils/data-mappers.js +55 -0
  77. package/lib-es/components/EntityManager/utils/data-mappers.js.map +1 -0
  78. package/lib-es/components/EntityManager/utils/entity.js +69 -0
  79. package/lib-es/components/EntityManager/utils/entity.js.map +1 -0
  80. package/lib-es/components/EntityManager/utils/entityAvailableActions.js +56 -0
  81. package/lib-es/components/EntityManager/utils/entityAvailableActions.js.map +1 -0
  82. package/lib-es/components/EntityManager/utils/is-form-empty.js +9 -0
  83. package/lib-es/components/EntityManager/utils/is-form-empty.js.map +1 -0
  84. package/lib-es/components/EntityManager/utils/query.js +23 -0
  85. package/lib-es/components/EntityManager/utils/query.js.map +1 -0
  86. package/lib-es/components/InfoBoxes/InfoBoxTooltip.js +36 -0
  87. package/lib-es/components/InfoBoxes/InfoBoxTooltip.js.map +1 -0
  88. package/lib-es/components/InfoBoxes/InfoBoxes.js +28 -0
  89. package/lib-es/components/InfoBoxes/InfoBoxes.js.map +1 -0
  90. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +38 -0
  91. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  92. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +28 -0
  93. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  94. package/lib-es/components/InfoBoxes/hooks/useData.js +39 -0
  95. package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -0
  96. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +17 -0
  97. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  98. package/lib-es/components/InfoBoxes/index.js +3 -0
  99. package/lib-es/components/InfoBoxes/index.js.map +1 -0
  100. package/lib-es/components/InfoBoxes/presentational/InfoBox.js +40 -0
  101. package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  102. package/lib-es/components/InfoBoxes/presentational/InfoBoxLabel.js +12 -0
  103. package/lib-es/components/InfoBoxes/presentational/InfoBoxLabel.js.map +1 -0
  104. package/lib-es/components/InfoBoxes/presentational/InfoBoxValue.js +30 -0
  105. package/lib-es/components/InfoBoxes/presentational/InfoBoxValue.js.map +1 -0
  106. package/lib-es/components/ListingTable/ListingTable.js +208 -0
  107. package/lib-es/components/ListingTable/ListingTable.js.map +1 -0
  108. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js +72 -0
  109. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -0
  110. package/lib-es/components/ListingTable/ListingTableContent/index.js +3 -0
  111. package/lib-es/components/ListingTable/ListingTableContent/index.js.map +1 -0
  112. package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +173 -0
  113. package/lib-es/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js.map +1 -0
  114. package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js +503 -0
  115. package/lib-es/components/ListingTable/SearchFilter/SearchContainer.js.map +1 -0
  116. package/lib-es/components/ListingTable/SearchFilter/SearchFilter.js +52 -0
  117. package/lib-es/components/ListingTable/SearchFilter/SearchFilter.js.map +1 -0
  118. package/lib-es/components/ListingTable/SearchFilter/helpers.js +127 -0
  119. package/lib-es/components/ListingTable/SearchFilter/helpers.js.map +1 -0
  120. package/lib-es/components/ListingTable/SearchFilter/querys.js +8 -0
  121. package/lib-es/components/ListingTable/SearchFilter/querys.js.map +1 -0
  122. package/lib-es/components/ListingTable/TableActions/TableActions.js +34 -0
  123. package/lib-es/components/ListingTable/TableActions/TableActions.js.map +1 -0
  124. package/lib-es/components/ListingTable/TableActions/index.js +3 -0
  125. package/lib-es/components/ListingTable/TableActions/index.js.map +1 -0
  126. package/lib-es/components/ListingTable/index.js +3 -0
  127. package/lib-es/components/ListingTable/index.js.map +1 -0
  128. package/lib-es/components/ListingTable/mappers/populate-rows.js +140 -0
  129. package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -0
  130. package/lib-es/components/ListingTable/service/index.js +87 -0
  131. package/lib-es/components/ListingTable/service/index.js.map +1 -0
  132. package/lib-es/components/Tabs/index.js +38 -0
  133. package/lib-es/components/Tabs/index.js.map +1 -0
  134. package/lib-es/components/hooks/useCallbackDebounce.js +12 -0
  135. package/lib-es/components/hooks/useCallbackDebounce.js.map +1 -0
  136. package/lib-es/constants.js +42 -0
  137. package/lib-es/constants.js.map +1 -0
  138. package/lib-es/icons/ContentIcon.js +80 -0
  139. package/lib-es/icons/ContentIcon.js.map +1 -0
  140. package/lib-es/icons/SettingsIcon.js +36 -0
  141. package/lib-es/icons/SettingsIcon.js.map +1 -0
  142. package/lib-es/icons/TaxonomyIcon.js +60 -0
  143. package/lib-es/icons/TaxonomyIcon.js.map +1 -0
  144. package/lib-es/icons/UsersIcon.js +33 -0
  145. package/lib-es/icons/UsersIcon.js.map +1 -0
  146. package/lib-es/icons/index.js +6 -0
  147. package/lib-es/icons/index.js.map +1 -0
  148. package/lib-es/index.js +93 -0
  149. package/lib-es/index.js.map +1 -0
  150. package/lib-es/utils/add-content-menu-items.js +72 -0
  151. package/lib-es/utils/add-content-menu-items.js.map +1 -0
  152. package/lib-es/utils/build-create-entity-mutation.js +7 -0
  153. package/lib-es/utils/build-create-entity-mutation.js.map +1 -0
  154. package/lib-es/utils/build-delete-entity-mutation.js +18 -0
  155. package/lib-es/utils/build-delete-entity-mutation.js.map +1 -0
  156. package/lib-es/utils/build-listing-query.js +28 -0
  157. package/lib-es/utils/build-listing-query.js.map +1 -0
  158. package/lib-es/utils/build-update-data-query.js +24 -0
  159. package/lib-es/utils/build-update-data-query.js.map +1 -0
  160. package/lib-es/utils/build-update-publish-unpublish-mutation.js +22 -0
  161. package/lib-es/utils/build-update-publish-unpublish-mutation.js.map +1 -0
  162. package/lib-es/utils/get-default-query-params.js +29 -0
  163. package/lib-es/utils/get-default-query-params.js.map +1 -0
  164. package/lib-es/utils/hoc/withContext.js +8 -0
  165. package/lib-es/utils/hoc/withContext.js.map +1 -0
  166. package/lib-es/utils/hooks/useToggle.js +8 -0
  167. package/lib-es/utils/hooks/useToggle.js.map +1 -0
  168. package/lib-es/utils/index.js +3 -0
  169. package/lib-es/utils/index.js.map +1 -0
  170. package/package.json +16 -12
  171. package/src/components/EntityManager/Entity/Entity.js +1 -1
  172. package/src/components/EntityManager/Entity/actions-handlers/create/submit.js +4 -11
  173. package/src/components/EntityManager/utils/entity.js +4 -10
  174. package/src/components/ListingTable/SearchFilter/RelationMultiSelectFilter.js +160 -0
  175. package/src/components/ListingTable/SearchFilter/SearchContainer.js +407 -74
  176. package/src/components/ListingTable/SearchFilter/SearchFilter.js +14 -3
  177. package/src/components/ListingTable/SearchFilter/helpers.js +55 -8
  178. package/src/index.js +2 -0
  179. package/src/utils/build-create-entity-mutation.js +5 -28
  180. package/src/utils/get-default-query-params.js +21 -9
  181. package/CHANGELOG.md +0 -1932
  182. package/babel.config.js +0 -3
  183. 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 apolloClient = (0, _client.useApolloClient)();
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 = displaySelectFilters ? (0, _adminUiUtils.getDynamicQuery)('ADMIN_SEARCH')([schema], gqlFields, false, index) : _querys.NOOP_QUERY;
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: !displaySelectFilters,
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 filterData = (0, _react.useMemo)(() => {
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 proccessedData = [];
142
+ const processed = [];
75
143
  Object.entries(aggregations).forEach(([key, {
76
144
  buckets
77
145
  }]) => {
78
- proccessedData.push(Array.isArray(buckets) ? [key, buckets.map(b => b.key).filter(Boolean)] : []);
146
+ processed.push(Array.isArray(buckets) ? [key, buckets.map(bucket => bucket.key).filter(Boolean)] : []);
79
147
  });
80
- return proccessedData;
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 (!filterData.length) {
155
+ if (!aggregationsData.length) {
84
156
  setSelectOptions([]);
157
+ setMultiSelectOptions([]);
85
158
  return;
86
159
  }
87
160
  (async () => {
88
- const results = await Promise.all(filterData.map(async ([property, ids]) => {
161
+ const results = await Promise.all(aggregationsData.map(async ([property, ids]) => {
89
162
  try {
90
- if (!ids || !ids.length) return {};
91
- const [, selectionDetails] = selectFiltersToDisplay.find(([selectProperty]) => selectProperty === property) || [];
92
- if (!selectionDetails) return null;
93
- if (!selectionDetails.relation) {
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
- id: property,
96
- label: selectionDetails.label,
97
- options: ids.map(value => [value, value])
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 query = (0, _adminUiUtils.getQuery)('GET_ENTITY_SCHEMA');
182
+ const schemaQuery = (0, _adminUiUtils.getQuery)('GET_ENTITY_SCHEMA');
101
183
  const {
102
184
  data: {
103
185
  getEntitySchemas: [relationSchema]
104
186
  }
105
- } = await apolloClient.query({
106
- query,
187
+ } = await client.query({
188
+ query: schemaQuery,
107
189
  variables: {
108
- identifier: selectionDetails.relation.entityIdentifier
190
+ identifier: config.relation.entityIdentifier
109
191
  }
110
192
  });
111
193
  const {
112
194
  data: {
113
195
  result: selected = []
114
196
  }
115
- } = await apolloClient.query({
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(e => console.error(e));
212
+ .catch(error => console.error(error));
213
+ const baseOptions = selected.map(item => [item.id, (0, _helpers.getTidyLabel)(item.name, tidyLabel)]);
131
214
  return {
132
- id: property,
133
- label: selectionDetails.label,
134
- options: selected.map(item => [item.id, item.name])
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
- setSelectOptions(results.filter(Boolean));
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
- }, [apolloClient, filterData, schema, selectFiltersToDisplay]);
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)(e => setSearchTerm(e.target.value), []);
146
- const handleEnterKey = (0, _react.useCallback)(e => {
147
- if (e.key === _constants.ENTER_KEY) handleSearch();
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
- setSelectedFilters(Object.keys(selectedFilters).reduce((acc, key) => _objectSpread(_objectSpread({}, acc), {}, {
152
- [key]: _constants.DEFAULT_FILTER_OPTION_LABEL
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
- }, [selectedFilters, updateFilters]);
156
- const handleSelect = (0, _react.useCallback)((property, event) => {
157
- const {
158
- value
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
- updateFilters(searchTerm, next);
165
- }, [searchTerm, selectedFilters, updateFilters]);
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
- }) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, options && !!options.length && /*#__PURE__*/_react.default.createElement("div", {
186
- className: "search-container__select-wrapper"
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: event => handleSelect(id, event),
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
- })))), /*#__PURE__*/_react.default.createElement("div", {
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
- index: 'admin'
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