@truedat/core 6.3.4 → 6.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/core",
3
- "version": "6.3.4",
3
+ "version": "6.3.5",
4
4
  "description": "Truedat Web Core",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -118,5 +118,5 @@
118
118
  "react-dom": ">= 16.8.6 < 17",
119
119
  "semantic-ui-react": ">= 2.0.3 < 2.2"
120
120
  },
121
- "gitHead": "e7d4c50cf2989fde79b5d1a46c83e6c6ce34f54d"
121
+ "gitHead": "2cacdf1fc99746cb4f8dca7d770662c0d96c5bb7"
122
122
  }
@@ -28,6 +28,7 @@ export const SearchContextProvider = (props) => {
28
28
  const userFilterScope = _.prop("userFilterScope")(props);
29
29
  const omitFilters = _.propOr([], "omitFilters")(props);
30
30
  const translations = _.propOr(() => ({}), "translations")(props);
31
+ const filtersGroup = _.propOr([], "filtersGroup")(props);
31
32
 
32
33
  const { formatMessage } = useIntl();
33
34
 
@@ -191,11 +192,38 @@ export const SearchContextProvider = (props) => {
191
192
  });
192
193
  }, [query, searchMust, sort, defaultFilters, page, size]);
193
194
 
195
+ const makeFiltersGroup = (filters, groups) =>
196
+ _.groupBy((filter) =>
197
+ _.flow(
198
+ _.find(([_group, fields]) => _.contains(filter)(fields)),
199
+ _.prop("[0]")
200
+ )(groups)
201
+ )(filters);
202
+
203
+ const filtersByGroup = makeFiltersGroup(availableFilters, filtersGroup);
204
+
205
+ const groupWithoutFilters = (groups) =>
206
+ _.flow(
207
+ _.prop("[0]"),
208
+ (groupName) => _.prop(groupName)(filtersByGroup),
209
+ _.isEmpty
210
+ )(groups);
211
+
212
+ const availableGroupedFilters = _.flow(
213
+ (groups) => _.concat(groups, [[undefined, []]]),
214
+ _.reject(groupWithoutFilters),
215
+ _.map(([groupName, _filters]) => [
216
+ groupName,
217
+ _.prop(groupName)(filtersByGroup),
218
+ ])
219
+ )(filtersGroup);
220
+
194
221
  const context = {
195
222
  disabled: false,
196
223
  loadingFilters,
197
224
 
198
225
  availableFilters,
226
+ availableGroupedFilters,
199
227
  selectedFilters,
200
228
  filterTypes,
201
229
 
@@ -1,5 +1,5 @@
1
1
  import _ from "lodash/fp";
2
- import React from "react";
2
+ import React, { Fragment } from "react";
3
3
  import { Dropdown } from "semantic-ui-react";
4
4
  import { FormattedMessage, useIntl } from "react-intl";
5
5
  import { i18nOrder } from "@truedat/core/services/sort";
@@ -10,7 +10,7 @@ const removePrefix = _.replace(/^.*\./, "");
10
10
  export default function SearchFilters() {
11
11
  const {
12
12
  disabled,
13
- availableFilters,
13
+ availableGroupedFilters,
14
14
  addFilter,
15
15
  resetFilters,
16
16
  loadingFilters: loading,
@@ -40,20 +40,36 @@ export default function SearchFilters() {
40
40
  />
41
41
  </em>
42
42
  </Dropdown.Item>
43
- {_.flow(
44
- _.defaultTo([]),
45
- _.sortBy(i18nOrder(formatMessage, "filters")),
46
- _.map((filter) => (
47
- <Dropdown.Item
48
- key={filter}
49
- text={formatMessage({
50
- id: `filters.${filter}`,
51
- defaultMessage: removePrefix(filter),
52
- })}
53
- onClick={() => addFilter({ filter })}
54
- />
55
- ))
56
- )(availableFilters)}
43
+ {_.map.convert({ cap: false })(([groupName, filters], idx) => (
44
+ <Fragment key={idx}>
45
+ {idx == 0 ? null : <Dropdown.Divider />}
46
+ {groupName ? (
47
+ <Dropdown.Header key={groupName}>
48
+ <b>
49
+ <FormattedMessage
50
+ id={`filters.group.header.${groupName}`}
51
+ defaultMessage={groupName}
52
+ />
53
+ </b>
54
+ </Dropdown.Header>
55
+ ) : null}
56
+
57
+ {_.flow(
58
+ _.defaultTo([]),
59
+ _.sortBy(i18nOrder(formatMessage, "filters")),
60
+ _.map((filter) => (
61
+ <Dropdown.Item
62
+ key={filter}
63
+ text={formatMessage({
64
+ id: `filters.${filter}`,
65
+ defaultMessage: removePrefix(filter),
66
+ })}
67
+ onClick={() => addFilter({ filter })}
68
+ />
69
+ ))
70
+ )(filters)}
71
+ </Fragment>
72
+ ))(availableGroupedFilters)}
57
73
  </Dropdown.Menu>
58
74
  </Dropdown>
59
75
  );