@truedat/core 7.6.3 → 7.7.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 +3 -3
- package/src/components/DateFilter.js +7 -1
- package/src/components/__tests__/SearchDateFilter.spec.js +18 -0
- package/src/components/__tests__/__snapshots__/SearchDateFilter.spec.js.snap +90 -0
- package/src/search/SearchDateFilter.js +7 -4
- package/src/search/SearchWidget.js +10 -2
- package/src/services/dateFilterFormatter.js +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.0",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@testing-library/jest-dom": "^6.6.3",
|
|
49
49
|
"@testing-library/react": "^16.3.0",
|
|
50
50
|
"@testing-library/user-event": "^14.6.1",
|
|
51
|
-
"@truedat/test": "7.
|
|
51
|
+
"@truedat/test": "7.7.0",
|
|
52
52
|
"identity-obj-proxy": "^3.0.0",
|
|
53
53
|
"jest": "^29.7.0",
|
|
54
54
|
"redux-saga-test-plan": "^4.0.6"
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"slate-react": "^0.22.10",
|
|
86
86
|
"swr": "^2.3.3"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "758c330b9a55bf81463dc4d97e4850d713ba8c76"
|
|
89
89
|
}
|
|
@@ -53,6 +53,7 @@ export const DateFilter = ({
|
|
|
53
53
|
defaultValues,
|
|
54
54
|
size = "small",
|
|
55
55
|
name = "date",
|
|
56
|
+
isGrantDateRange = false,
|
|
56
57
|
}) => {
|
|
57
58
|
const intl = useIntl();
|
|
58
59
|
const [type, setType] = useState(defaultValues?.type || "since");
|
|
@@ -68,6 +69,10 @@ export const DateFilter = ({
|
|
|
68
69
|
}
|
|
69
70
|
}, [name, type, unit, value, rangeStart, rangeEnd]);
|
|
70
71
|
|
|
72
|
+
const typeOpts = isGrantDateRange
|
|
73
|
+
? typeOptions(intl).filter((opt) => opt.key === "range")
|
|
74
|
+
: typeOptions(intl);
|
|
75
|
+
|
|
71
76
|
const currentDate = moment();
|
|
72
77
|
return (
|
|
73
78
|
<Form size={size} autoComplete="off">
|
|
@@ -77,7 +82,7 @@ export const DateFilter = ({
|
|
|
77
82
|
<Dropdown
|
|
78
83
|
selection
|
|
79
84
|
value={type}
|
|
80
|
-
options={
|
|
85
|
+
options={typeOpts}
|
|
81
86
|
onChange={(_e, { value }) => setType(value)}
|
|
82
87
|
/>
|
|
83
88
|
</Form.Field>
|
|
@@ -125,6 +130,7 @@ DateFilter.propTypes = {
|
|
|
125
130
|
name: PropTypes.string,
|
|
126
131
|
onChange: PropTypes.func,
|
|
127
132
|
size: PropTypes.string,
|
|
133
|
+
isGrantDateRange: PropTypes.bool,
|
|
128
134
|
};
|
|
129
135
|
|
|
130
136
|
export default DateFilter;
|
|
@@ -26,6 +26,7 @@ describe("<SearchDateFilter/>", () => {
|
|
|
26
26
|
"structures.search.placeholder": "placeholder",
|
|
27
27
|
"structures.loading.header": "loading",
|
|
28
28
|
"filter.updated_at": "Updated at",
|
|
29
|
+
"filter.start_date_end_date": "Period of validity:",
|
|
29
30
|
"dateFilter.years": "Years",
|
|
30
31
|
"dateFilter.months": "Months",
|
|
31
32
|
"dateFilter.weeks": "Weeks",
|
|
@@ -51,6 +52,23 @@ describe("<SearchDateFilter/>", () => {
|
|
|
51
52
|
expect(container).toMatchSnapshot();
|
|
52
53
|
});
|
|
53
54
|
|
|
55
|
+
it("matches the latest snapshot for grants", () => {
|
|
56
|
+
const grantDefaultValues = {
|
|
57
|
+
active: true,
|
|
58
|
+
name: "start_date,end_date",
|
|
59
|
+
type: "range",
|
|
60
|
+
rangeStart: "",
|
|
61
|
+
rangeEnd: "",
|
|
62
|
+
};
|
|
63
|
+
const { container } = render(
|
|
64
|
+
<SearchContextWrapper props={searchProps}>
|
|
65
|
+
<SearchDateFilter active={true} isGrantDateRange defaultValues={grantDefaultValues} />,
|
|
66
|
+
</SearchContextWrapper>,
|
|
67
|
+
renderOpts
|
|
68
|
+
);
|
|
69
|
+
expect(container).toMatchSnapshot();
|
|
70
|
+
});
|
|
71
|
+
|
|
54
72
|
it("active false", () => {
|
|
55
73
|
const { container } = render(
|
|
56
74
|
<SearchContextWrapper props={searchProps}>
|
|
@@ -181,3 +181,93 @@ exports[`<SearchDateFilter/> matches the latest snapshot 1`] = `
|
|
|
181
181
|
,
|
|
182
182
|
</div>
|
|
183
183
|
`;
|
|
184
|
+
|
|
185
|
+
exports[`<SearchDateFilter/> matches the latest snapshot for grants 1`] = `
|
|
186
|
+
<div>
|
|
187
|
+
<form
|
|
188
|
+
autocomplete="off"
|
|
189
|
+
class="ui small form"
|
|
190
|
+
>
|
|
191
|
+
<div
|
|
192
|
+
class="fields date filter"
|
|
193
|
+
>
|
|
194
|
+
<div
|
|
195
|
+
class="inline field"
|
|
196
|
+
>
|
|
197
|
+
<label>
|
|
198
|
+
Period of validity:
|
|
199
|
+
</label>
|
|
200
|
+
<div
|
|
201
|
+
aria-expanded="false"
|
|
202
|
+
class="ui selection dropdown"
|
|
203
|
+
role="listbox"
|
|
204
|
+
tabindex="0"
|
|
205
|
+
>
|
|
206
|
+
<div
|
|
207
|
+
aria-atomic="true"
|
|
208
|
+
aria-live="polite"
|
|
209
|
+
class="divider text"
|
|
210
|
+
role="alert"
|
|
211
|
+
>
|
|
212
|
+
Range
|
|
213
|
+
</div>
|
|
214
|
+
<i
|
|
215
|
+
aria-hidden="true"
|
|
216
|
+
class="dropdown icon"
|
|
217
|
+
/>
|
|
218
|
+
<div
|
|
219
|
+
class="menu transition"
|
|
220
|
+
>
|
|
221
|
+
<div
|
|
222
|
+
aria-checked="true"
|
|
223
|
+
aria-selected="true"
|
|
224
|
+
class="active selected item"
|
|
225
|
+
role="option"
|
|
226
|
+
style="pointer-events: all;"
|
|
227
|
+
>
|
|
228
|
+
<span
|
|
229
|
+
class="text"
|
|
230
|
+
>
|
|
231
|
+
Range
|
|
232
|
+
</span>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
<div
|
|
238
|
+
class="field range"
|
|
239
|
+
>
|
|
240
|
+
<div
|
|
241
|
+
class="fields"
|
|
242
|
+
>
|
|
243
|
+
<div
|
|
244
|
+
class="field"
|
|
245
|
+
>
|
|
246
|
+
<div
|
|
247
|
+
class="ui input"
|
|
248
|
+
>
|
|
249
|
+
<input
|
|
250
|
+
type="date"
|
|
251
|
+
value=""
|
|
252
|
+
/>
|
|
253
|
+
</div>
|
|
254
|
+
</div>
|
|
255
|
+
<div
|
|
256
|
+
class="field"
|
|
257
|
+
>
|
|
258
|
+
<div
|
|
259
|
+
class="ui input"
|
|
260
|
+
>
|
|
261
|
+
<input
|
|
262
|
+
type="date"
|
|
263
|
+
value=""
|
|
264
|
+
/>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
</form>
|
|
271
|
+
,
|
|
272
|
+
</div>
|
|
273
|
+
`;
|
|
@@ -9,23 +9,26 @@ const SearchDateFilter = ({
|
|
|
9
9
|
active,
|
|
10
10
|
defaultValues,
|
|
11
11
|
searchField = "updated_at",
|
|
12
|
+
isGrantDateRange = false,
|
|
12
13
|
}) => {
|
|
13
|
-
const dateFormatter = dateFilterFormatter();
|
|
14
|
-
const dateMust = (dateFilter) => omitBy(isEmpty)(dateFormatter(dateFilter));
|
|
14
|
+
const dateFormatter = dateFilterFormatter(isGrantDateRange ? "grantDateFilter" : undefined);
|
|
15
15
|
|
|
16
16
|
const { setDateFilters } = useSearchContext();
|
|
17
17
|
|
|
18
|
+
const dateMust = (dateFilter) => omitBy(isEmpty)(dateFormatter(dateFilter));
|
|
19
|
+
|
|
18
20
|
const onChangeDateFilter = (e) => {
|
|
19
|
-
const dateFilterFormatted = dateMust({ active, ...e });
|
|
21
|
+
const dateFilterFormatted = dateMust({ active, isGrantDateRange, ...e });
|
|
20
22
|
setDateFilters(dateFilterFormatted);
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
return active ? (
|
|
24
26
|
<DateFilter
|
|
25
|
-
label={<FormattedMessage id="filter.updated_at" />}
|
|
27
|
+
label={<FormattedMessage id={isGrantDateRange ? "filter.start_date_end_date" : "filter.updated_at"} />}
|
|
26
28
|
name={searchField}
|
|
27
29
|
onChange={onChangeDateFilter}
|
|
28
30
|
defaultValues={defaultValues}
|
|
31
|
+
isGrantDateRange={isGrantDateRange}
|
|
29
32
|
/>
|
|
30
33
|
) : null;
|
|
31
34
|
};
|
|
@@ -6,7 +6,7 @@ import SearchSelectedFilters from "./SearchSelectedFilters";
|
|
|
6
6
|
import { useSearchContext } from "./SearchContext";
|
|
7
7
|
import SearchDateFilter from "./SearchDateFilter";
|
|
8
8
|
|
|
9
|
-
export default function SearchWidget({ dateFilter = false, searchField }) {
|
|
9
|
+
export default function SearchWidget({ dateFilter = false, searchField, isGrantDateRange = false }) {
|
|
10
10
|
const { formatMessage } = useIntl();
|
|
11
11
|
|
|
12
12
|
const {
|
|
@@ -25,6 +25,13 @@ export default function SearchWidget({ dateFilter = false, searchField }) {
|
|
|
25
25
|
value: "1",
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
const defaultValuesGrants = {
|
|
29
|
+
name: "start_date,end_date",
|
|
30
|
+
type: "range",
|
|
31
|
+
rangeStart: "",
|
|
32
|
+
rangeEnd: "",
|
|
33
|
+
};
|
|
34
|
+
|
|
28
35
|
const onClickSearchDateFilter = () => {
|
|
29
36
|
setToggleDateFilter(!toggleDateFilter);
|
|
30
37
|
toggleDateFilter ? setDateFilters({}) : null;
|
|
@@ -56,8 +63,9 @@ export default function SearchWidget({ dateFilter = false, searchField }) {
|
|
|
56
63
|
<SearchSelectedFilters />
|
|
57
64
|
<SearchDateFilter
|
|
58
65
|
active={toggleDateFilter}
|
|
59
|
-
defaultValues={defaultValues}
|
|
66
|
+
defaultValues={isGrantDateRange ? defaultValuesGrants : defaultValues}
|
|
60
67
|
searchField={searchField}
|
|
68
|
+
isGrantDateRange={isGrantDateRange}
|
|
61
69
|
/>
|
|
62
70
|
</>
|
|
63
71
|
);
|
|
@@ -9,12 +9,15 @@ import {
|
|
|
9
9
|
} from "lodash/fp";
|
|
10
10
|
|
|
11
11
|
const relativeDate = ({ unit, value }) => `now-${value}${unit}`;
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
const sinceDate = ({ name, ...props }) => ({
|
|
13
14
|
[name]: { gte: relativeDate(props) },
|
|
14
15
|
});
|
|
16
|
+
|
|
15
17
|
const untilDate = ({ name, ...props }) => ({
|
|
16
18
|
[name]: { lt: relativeDate(props) },
|
|
17
19
|
});
|
|
20
|
+
|
|
18
21
|
const dateRange = ({ name, rangeStart, rangeEnd }) => ({
|
|
19
22
|
[name]: {
|
|
20
23
|
...(rangeStart ? { gte: rangeStart } : {}),
|