@truedat/core 8.9.0 → 8.10.0

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": "8.9.0",
3
+ "version": "8.10.0",
4
4
  "description": "Truedat Web Core",
5
5
  "sideEffects": [
6
6
  "**/*.css",
@@ -54,7 +54,7 @@
54
54
  "@testing-library/jest-dom": "^6.6.3",
55
55
  "@testing-library/react": "^16.3.0",
56
56
  "@testing-library/user-event": "^14.6.1",
57
- "@truedat/test": "8.9.0",
57
+ "@truedat/test": "8.10.0",
58
58
  "identity-obj-proxy": "^3.0.0",
59
59
  "jest": "^29.7.0",
60
60
  "redux-saga-test-plan": "^4.0.6"
@@ -95,5 +95,5 @@
95
95
  "swr": "^2.3.3",
96
96
  "turndown": "^7.2.2"
97
97
  },
98
- "gitHead": "beff9d7e01556d63d42e54c9f7b641503ee658b2"
98
+ "gitHead": "f18f60e317c52a90197068ed60908966ca7f58f0"
99
99
  }
@@ -34,6 +34,10 @@ export const SearchContextProvider = (props) => {
34
34
  const omitFilters = _.propOr([], "omitFilters")(props);
35
35
  const translations = _.propOr(() => ({}), "translations")(props);
36
36
  const filtersGroup = _.propOr([], "filtersGroup")(props);
37
+ const searchFiltersPropsMapping = _.propOr(
38
+ {},
39
+ "searchFiltersPropsMapping",
40
+ )(props);
37
41
  const enrichSearchPayload = useState(_.prop("enrichSearchPayload")(props))[0];
38
42
 
39
43
  const { formatMessage } = useIntl();
@@ -47,7 +51,8 @@ export const SearchContextProvider = (props) => {
47
51
  const [activeFilterName, setActiveFilterName] = useState([]);
48
52
  const [allActiveFilters, setAllActiveFilters] =
49
53
  useState(initialActiveFilters);
50
- const [hiddenFilters, setHiddenFilters] = useState({});
54
+ const initialHiddenFilters = _.propOr({}, "initialHiddenFilters")(props);
55
+ const [hiddenFilters, setHiddenFilters] = useState(initialHiddenFilters);
51
56
  const [dateFilters, setDateFilters] = useState({});
52
57
  const [toggleDateFilter, setToggleDateFilter] = useState(false);
53
58
  const [defaultFilters, setDefaultFilters] = useState(initialDefaultFilters);
@@ -147,7 +152,16 @@ export const SearchContextProvider = (props) => {
147
152
  const filters = _.flow(
148
153
  _.propOr({}, "data"),
149
154
  _.omit(omitFilters),
150
- _.omitBy(_.flow(_.propOr([], "values"), (values) => _.size(values) < 2)),
155
+ _.omitBy(
156
+ _.cond([
157
+ [_.matches({ type: "search" }), _.stubFalse],
158
+ [
159
+ _.flow(_.propOr([], "values"), (values) => _.size(values) < 2),
160
+ _.stubTrue,
161
+ ],
162
+ [_.stubTrue, _.stubFalse],
163
+ ]),
164
+ ),
151
165
  )(filtersPayload);
152
166
 
153
167
  const allFilters = _.flow(
@@ -320,6 +334,8 @@ export const SearchContextProvider = (props) => {
320
334
  sortDirection === "ascending" ? "descending" : "ascending",
321
335
  );
322
336
  }
337
+
338
+ setPage(1);
323
339
  };
324
340
 
325
341
  const setQueryAndScoreSort = (query) => {
@@ -388,6 +404,7 @@ export const SearchContextProvider = (props) => {
388
404
  userFiltersType,
389
405
  userFilterScope,
390
406
  useDomainSearchFilter,
407
+ searchFiltersPropsMapping,
391
408
 
392
409
  setOnSearchChange,
393
410
  };
@@ -2,7 +2,9 @@ import _ from "lodash/fp";
2
2
  import { useState } from "react";
3
3
  import { FormattedMessage } from "react-intl";
4
4
  import { useLocation } from "react-router";
5
+ import { useDispatch } from "react-redux";
5
6
  import DomainSearchFilter from "../components/DomainSearchFilter";
7
+ import SearchFilterDropdown from "../components/SearchFilterDropdown";
6
8
  import ModalSaveFilter from "./ModalSaveFilter";
7
9
  import UserFilters from "./UserFilters";
8
10
  import FilterDropdown from "./FilterDropdown";
@@ -15,6 +17,7 @@ const MIN_LENGTH_FOR_QUERY_DROPDOWN = 8;
15
17
 
16
18
  export default function SearchSelectedFilters() {
17
19
  const context = useSearchContext();
20
+ const dispatch = useDispatch();
18
21
  const {
19
22
  selectedFilters,
20
23
  resetFilters,
@@ -23,6 +26,7 @@ export default function SearchSelectedFilters() {
23
26
  activeFilterValues,
24
27
  userFiltersType,
25
28
  useDomainSearchFilter,
29
+ searchFiltersPropsMapping,
26
30
  } = context;
27
31
  const [selectedUserFilter, setSelectedUserFilter] = useState();
28
32
  const { pathname } = useLocation();
@@ -75,6 +79,20 @@ export default function SearchSelectedFilters() {
75
79
  )
76
80
  ) : filterType === "hierarchy" ? (
77
81
  <HierarchyFilterDropdown />
82
+ ) : filterType === "search" &&
83
+ _.prop(filter)(searchFiltersPropsMapping) ? (
84
+ <SearchFilterDropdown
85
+ filter={filter}
86
+ loading={context.loadingFilters}
87
+ openFilter={context.openFilter}
88
+ closeFilter={context.closeFilter}
89
+ removeFilter={context.removeFilter}
90
+ toggleFilterValue={context.toggleFilterValue}
91
+ activeValues={context.activeFilterSelectedValues}
92
+ open={_.isEqual(filter, activeFilterName)}
93
+ searchFilterDispacher={(action) => dispatch(action)}
94
+ {..._.prop(filter)(searchFiltersPropsMapping)}
95
+ />
78
96
  ) : _.size(options) >= MIN_LENGTH_FOR_QUERY_DROPDOWN ? (
79
97
  <FilterQueryDropdown />
80
98
  ) : (
@@ -311,6 +311,38 @@ describe("<SearchContextProvider />", () => {
311
311
  jest.useRealTimers();
312
312
  });
313
313
 
314
+ it("keeps search type filters without values in available filters", async () => {
315
+ jest.useFakeTimers();
316
+ const triggerFiltersSpy = jest.fn().mockReturnValue({
317
+ then: (callback) =>
318
+ callback({
319
+ data: {
320
+ data: {
321
+ status: { type: "term", values: ["draft", "published"] },
322
+ linked_structures_ids: { type: "search", index: "structures" },
323
+ },
324
+ },
325
+ }),
326
+ });
327
+ const useFiltersSpy = () => ({ trigger: triggerFiltersSpy });
328
+
329
+ const rendered = render(
330
+ <SearchContextProvider {...searchProps} useFilters={useFiltersSpy}>
331
+ <ContextConsumer onSearchChangeSpy={jest.fn()} />
332
+ </SearchContextProvider>,
333
+ renderOpts,
334
+ );
335
+
336
+ jest.runAllTimers();
337
+
338
+ await waitFor(() =>
339
+ expect(
340
+ rendered.getByText(/available:\["status","linked_structures_ids"\]/i),
341
+ ).toBeInTheDocument(),
342
+ );
343
+ jest.useRealTimers();
344
+ });
345
+
314
346
  it("handles active and hidden filter toggles and removals", async () => {
315
347
  jest.useFakeTimers();
316
348
  const user = userEvent.setup({
@@ -53,6 +53,17 @@ jest.mock("../HierarchyFilterDropdown", () => ({
53
53
  default: () => <div data-testid="hierarchy-filter-dropdown" />,
54
54
  }));
55
55
 
56
+ jest.mock("../../components/SearchFilterDropdown", () => ({
57
+ __esModule: true,
58
+ default: ({ filter, placeholder }) => (
59
+ <div
60
+ data-testid="search-filter-dropdown"
61
+ data-filter={filter}
62
+ data-placeholder={placeholder}
63
+ />
64
+ ),
65
+ }));
66
+
56
67
  jest.mock("../../components/DomainSearchFilter", () => ({
57
68
  __esModule: true,
58
69
  default: ({ filter, options }) => (