@truedat/core 6.3.4 → 6.3.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/package.json +3 -3
- package/src/search/SearchContext.js +28 -0
- package/src/search/SearchFilters.js +32 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/core",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.6",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@testing-library/react": "^12.0.0",
|
|
37
37
|
"@testing-library/react-hooks": "^8.0.1",
|
|
38
38
|
"@testing-library/user-event": "^13.2.1",
|
|
39
|
-
"@truedat/test": "6.3.
|
|
39
|
+
"@truedat/test": "6.3.6",
|
|
40
40
|
"babel-jest": "^28.1.0",
|
|
41
41
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
42
42
|
"babel-plugin-lodash": "^3.3.4",
|
|
@@ -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": "
|
|
121
|
+
"gitHead": "3e628f8ac355fc31c1fed6265473c1b5cb678cb2"
|
|
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
|
-
|
|
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
|
-
{_.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
);
|