@truedat/dd 7.6.2 → 7.6.4

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 (38) hide show
  1. package/package.json +3 -3
  2. package/src/api.js +2 -2
  3. package/src/components/GrantRoutes.js +2 -16
  4. package/src/components/Grants.js +43 -16
  5. package/src/components/GrantsDownloadButton.js +34 -23
  6. package/src/components/GrantsLabelResults.js +8 -14
  7. package/src/components/GrantsPagination.js +12 -10
  8. package/src/components/GrantsTable.js +23 -27
  9. package/src/components/__tests__/GrantsDownloadButton.spec.js +150 -9
  10. package/src/components/__tests__/GrantsLabelResults.spec.js +12 -1
  11. package/src/components/__tests__/GrantsTable.spec.js +31 -10
  12. package/src/components/__tests__/__snapshots__/GrantRoutes.spec.js.snap +0 -18
  13. package/src/components/__tests__/__snapshots__/GrantsDownloadButton.spec.js.snap +1 -3
  14. package/src/components/__tests__/__snapshots__/GrantsTable.spec.js.snap +0 -37
  15. package/src/components/index.js +0 -2
  16. package/src/hooks/useGrant.js +49 -2
  17. package/src/messages/en.js +1 -1
  18. package/src/messages/es.js +1 -1
  19. package/src/reducers/index.js +0 -2
  20. package/src/routines.js +0 -3
  21. package/src/sagas/index.js +0 -3
  22. package/src/selectors/getGrantsColumns.js +6 -12
  23. package/src/selectors/index.js +0 -4
  24. package/src/components/GrantDateFilter.js +0 -27
  25. package/src/components/GrantSelectedFilters.js +0 -59
  26. package/src/components/GrantsSearch.js +0 -50
  27. package/src/components/__tests__/GrantDateFilter.spec.js +0 -18
  28. package/src/components/__tests__/__snapshots__/GrantDateFilter.spec.js.snap +0 -34
  29. package/src/reducers/__tests__/grantDateFilter.spec.js +0 -54
  30. package/src/reducers/grantDateFilter.js +0 -30
  31. package/src/sagas/__tests__/downloadGrants.spec.js +0 -85
  32. package/src/sagas/downloadGrants.js +0 -46
  33. package/src/selectors/__tests__/getGrantSelectedFilterActiveValues.spec.js +0 -16
  34. package/src/selectors/__tests__/getGrantSelectedFilterValues.spec.js +0 -15
  35. package/src/selectors/getGrantFilterTypes.js +0 -7
  36. package/src/selectors/getGrantSelectedFilterActiveValues.js +0 -8
  37. package/src/selectors/getGrantSelectedFilterValues.js +0 -12
  38. package/src/selectors/getPreviousGrantQuery.js +0 -1
@@ -2,6 +2,7 @@ import userEvent from "@testing-library/user-event";
2
2
  import { render, waitForLoad } from "@truedat/test/render";
3
3
  import { GrantsTable } from "../GrantsTable";
4
4
  import { defaultGrantsTableColumns } from "../../selectors/getGrantsColumns";
5
+ import SearchContext from "@truedat/core/search/SearchContext";
5
6
 
6
7
  describe("<GrantsTable />", () => {
7
8
  const renderOpts = {
@@ -75,25 +76,40 @@ describe("<GrantsTable />", () => {
75
76
  },
76
77
  ];
77
78
 
78
- const grantsSorting = [{ "data_structure_version.name.raw": "asc" }];
79
79
  const sortGrants = jest.fn();
80
80
  const grantsLoading = false;
81
81
  const props = {
82
- grants,
83
82
  columns: defaultGrantsTableColumns,
84
- grantsLoading,
85
- sortGrants,
86
- grantsSorting,
83
+ setDownloading: jest.fn(),
84
+ };
85
+
86
+ const handleSortSelection = jest.fn();
87
+ const searchContext = {
88
+ searchData: { data: grants },
89
+ loading: grantsLoading,
90
+ sortColumn: "data_structure_version.name.raw",
91
+ sortDirection: "ascending",
92
+ handleSortSelection: handleSortSelection,
87
93
  };
88
94
 
89
95
  it("matches the latest snapshot", async () => {
90
- const rendered = render(<GrantsTable {...props} />, renderOpts);
96
+ const rendered = render(
97
+ <SearchContext value={searchContext}>
98
+ <GrantsTable {...props} />
99
+ </SearchContext>,
100
+ renderOpts
101
+ );
91
102
  await waitForLoad(rendered);
92
103
  expect(rendered.container).toMatchSnapshot();
93
104
  });
94
105
 
95
106
  it("sorts column in the direction specified", async () => {
96
- const rendered = render(<GrantsTable {...props} />, renderOpts);
107
+ const rendered = render(
108
+ <SearchContext value={searchContext}>
109
+ <GrantsTable {...props} />
110
+ </SearchContext>,
111
+ renderOpts
112
+ );
97
113
  await waitForLoad(rendered);
98
114
 
99
115
  const headers = rendered.container.querySelectorAll("th");
@@ -104,16 +120,21 @@ describe("<GrantsTable />", () => {
104
120
  });
105
121
 
106
122
  it("handles sort when column header is clicked", async () => {
107
- const rendered = render(<GrantsTable {...props} />, renderOpts);
123
+ const rendered = render(
124
+ <SearchContext value={searchContext}>
125
+ <GrantsTable {...props} />
126
+ </SearchContext>,
127
+ renderOpts
128
+ );
108
129
  await waitForLoad(rendered);
109
130
 
110
131
  const user = userEvent.setup({ delay: null });
111
132
  const headers = rendered.container.querySelectorAll("th");
112
133
 
113
134
  await user.click(headers[0]);
114
- expect(headers[0]).toHaveClass("ascending sorted");
135
+ expect(handleSortSelection).toHaveBeenCalled();
115
136
 
116
137
  await user.click(headers[0]);
117
- expect(headers[0]).toHaveClass("descending sorted");
138
+ expect(handleSortSelection).toHaveBeenCalled();
118
139
  });
119
140
  });
@@ -77,12 +77,6 @@ exports[`<GrantRoutes /> renders correctly with GRANT_REQUESTS_APPROVALS_RESULT
77
77
 
78
78
  exports[`<GrantRoutes /> renders correctly with GRANTS route 1`] = `
79
79
  <div>
80
- <div>
81
- GrantsLoader
82
- </div>
83
- <div>
84
- GrantFiltersLoader
85
- </div>
86
80
  <div>
87
81
  Grants
88
82
  </div>
@@ -110,12 +104,6 @@ exports[`<GrantRoutes /> renders correctly with MY_GRANT_REQUESTS route 1`] = `
110
104
 
111
105
  exports[`<GrantRoutes /> renders correctly with MY_GRANTS route 1`] = `
112
106
  <div>
113
- <div>
114
- GrantsLoader
115
- </div>
116
- <div>
117
- GrantFiltersLoader
118
- </div>
119
107
  <div>
120
108
  Grants
121
109
  </div>
@@ -132,12 +120,6 @@ exports[`<GrantRoutes /> renders correctly with STRUCTURES_GRANT_REQUEST route 1
132
120
 
133
121
  exports[`<GrantRoutes /> renders unauthorized component when not authorized 1`] = `
134
122
  <div>
135
- <div>
136
- GrantsLoader
137
- </div>
138
- <div>
139
- GrantFiltersLoader
140
- </div>
141
123
  <div>
142
124
  Grants
143
125
  </div>
@@ -7,9 +7,7 @@ exports[`<GrantsDownloadButton /> matches the latest snapshot 1`] = `
7
7
  class="trigger-right"
8
8
  >
9
9
  <button
10
- class="ui icon secondary disabled button"
11
- disabled=""
12
- tabindex="-1"
10
+ class="ui icon secondary button"
13
11
  >
14
12
  <i
15
13
  aria-hidden="true"
@@ -31,11 +31,6 @@ exports[`<GrantsTable /> matches the latest snapshot 1`] = `
31
31
  >
32
32
  end_date
33
33
  </th>
34
- <th
35
- class="disabled"
36
- >
37
- metadata
38
- </th>
39
34
  </tr>
40
35
  </thead>
41
36
  <tbody
@@ -91,9 +86,6 @@ exports[`<GrantsTable /> matches the latest snapshot 1`] = `
91
86
  </div>
92
87
  </div>
93
88
  </td>
94
- <td
95
- class=""
96
- />
97
89
  </tr>
98
90
  <tr
99
91
  class=""
@@ -145,35 +137,6 @@ exports[`<GrantsTable /> matches the latest snapshot 1`] = `
145
137
  </div>
146
138
  </div>
147
139
  </td>
148
- <td
149
- class=""
150
- >
151
- <div>
152
- alias
153
- :
154
- Truedat-PostgreSQL
155
- </div>
156
- <div>
157
- database
158
- :
159
- td_metrics
160
- </div>
161
- <div>
162
- host
163
- :
164
- postgres
165
- </div>
166
- <div>
167
- schema
168
- :
169
- public
170
- </div>
171
- <div>
172
- type
173
- :
174
- BASE TABLE
175
- </div>
176
- </td>
177
140
  </tr>
178
141
  </tbody>
179
142
  </table>
@@ -6,7 +6,6 @@ import GrantRoutes from "./GrantRoutes";
6
6
  import GrantRequestBulkActions from "./GrantRequestBulkActions";
7
7
  import GrantRequestsTable from "./GrantRequestsTable";
8
8
  import GrantRequestRow from "./GrantRequestRow";
9
- import GrantSelectedFilters from "./GrantSelectedFilters";
10
9
  import GrantsTable from "./GrantsTable";
11
10
  import LineageDefs from "./LineageDefs";
12
11
  import LineageDownloadButton from "./LineageDownloadButton";
@@ -60,7 +59,6 @@ export {
60
59
  GrantRequestsTable,
61
60
  GrantRequestRow,
62
61
  GrantRoutes,
63
- GrantSelectedFilters,
64
62
  GrantsTable,
65
63
  LineageDefs,
66
64
  LineageDownloadButton,
@@ -1,11 +1,34 @@
1
1
  import { compile } from "path-to-regexp";
2
2
  import useSWR from "swr";
3
3
  import useSWRMutations from "swr/mutation";
4
- import { apiJson, apiJsonPatch } from "@truedat/core/services/api";
5
- import { API_GRANT, API_DATA_STRUCTURE_VERSION } from "../api";
4
+ import FileSaver from "file-saver";
5
+ import {
6
+ apiJson,
7
+ apiJsonPost,
8
+ apiJsonPatch,
9
+ JSON_OPTS,
10
+ } from "@truedat/core/services/api";
11
+ import {
12
+ API_GRANT,
13
+ API_DATA_STRUCTURE_VERSION,
14
+ API_GRANT_FILTERS_SEARCH,
15
+ API_MY_GRANTS_SEARCH,
16
+ API_MY_GRANT_FILTERS_SEARCH,
17
+ API_GRANTS_DOWNLOAD,
18
+ API_GRANTS_SEARCH,
19
+ } from "../api";
6
20
 
7
21
  const toApiPath = compile(API_GRANT);
8
22
 
23
+ function saveFile({ data, headers }) {
24
+ const contentDisposition = headers["content-disposition"];
25
+ const regex = /filename=(.+)$/;
26
+ const match = regex.exec(contentDisposition);
27
+ const fileName = match ? match[1] : "grants.xlsx";
28
+
29
+ FileSaver.saveAs(data, fileName);
30
+ }
31
+
9
32
  export const useGrant = (id) => {
10
33
  const url = toApiPath({ id: `${id}` });
11
34
  const { data, error, mutate } = useSWR(url, apiJson);
@@ -25,3 +48,27 @@ export const useStructure = (id) => {
25
48
  const { data, error } = useSWR(url, apiJson);
26
49
  return { data: data?.data, error, loading: !error && !data };
27
50
  };
51
+
52
+ export const useGrantFilters = (onlyMyGrants) => () => {
53
+ const searchUrl = onlyMyGrants ? API_MY_GRANT_FILTERS_SEARCH : API_GRANT_FILTERS_SEARCH
54
+ return useSWRMutations(searchUrl, (url, { arg }) => {
55
+ return apiJsonPost(url, arg);
56
+ });
57
+ };
58
+
59
+ export const useGrantSearch = (onlyMyGrants) => () => {
60
+ const searchUrl = onlyMyGrants ? API_MY_GRANTS_SEARCH : API_GRANTS_SEARCH
61
+ return useSWRMutations(searchUrl, (url, { arg }) => {
62
+ return apiJsonPost(url, arg);
63
+ });
64
+ };
65
+
66
+ export const useGrantDownload = () => {
67
+ return useSWRMutations(API_GRANTS_DOWNLOAD, (url, { arg }) => {
68
+ return apiJsonPost(url, arg, { ...JSON_OPTS, responseType: "blob" }).then(
69
+ ({ data, headers }) => {
70
+ saveFile({ data, headers });
71
+ }
72
+ );
73
+ });
74
+ };
@@ -158,7 +158,7 @@ export default {
158
158
  "grantRequests.subheader.me": "Grant requests requested by me",
159
159
  "grantRequests.subheader": "Pending approval grant requests",
160
160
  "grants.actions.download.popup": "Select a grant",
161
- "grants.actions.download.tooltip": "Download to CSV",
161
+ "grants.actions.download.tooltip": "Download to XLSX",
162
162
  "grants.header": "Grants",
163
163
  "grants.mine.header": "My grants",
164
164
  "grants.mine.subheader": "Structures granted to me",
@@ -164,7 +164,7 @@ export default {
164
164
  "grantRequests.subheader.me": "Peticiones de acceso demandadas por mí",
165
165
  "grantRequests.subheader": "Peticiones de acceso pendientes de aprobación",
166
166
  "grants.actions.download.popup": "Seleccione un acceso",
167
- "grants.actions.download.tooltip": "Descargar a CSV",
167
+ "grants.actions.download.tooltip": "Descargar a XLSX",
168
168
  "grants.header": "Accesos",
169
169
  "grants.mine.header": "Mis accesos",
170
170
  "grants.mine.subheader": "Estructuras a las que tengo acceso",
@@ -5,7 +5,6 @@ import { csvGraphDownloading } from "./csvGraphDownloading";
5
5
  import { ddMessage } from "./ddMessage";
6
6
  import { grantActiveFilters } from "./grantActiveFilters";
7
7
  import { grantCount } from "./grantCount";
8
- import { grantDateFilter } from "./grantDateFilter";
9
8
  import { grantFilters } from "./grantFilters";
10
9
  import { grantFiltersLoading } from "./grantFiltersLoading";
11
10
  import { grantLoading } from "./grantLoading";
@@ -87,7 +86,6 @@ export {
87
86
  ddMessage,
88
87
  grantActiveFilters,
89
88
  grantCount,
90
- grantDateFilter,
91
89
  grantFilters,
92
90
  grantFiltersLoading,
93
91
  grantLoading,
package/src/routines.js CHANGED
@@ -6,7 +6,6 @@ export const addGrantRequestToCart = createRoutine("ADD_GRANT_REQUEST_TO_CART");
6
6
  export const addStructureSelectedFilter = createRoutine(
7
7
  "ADD_STRUCTURE_SELECTED_FILTER"
8
8
  );
9
- export const applyGrantDateFilter = createRoutine("APPLY_GRANT_DATE_FILTER");
10
9
  export const applyUserSearchFilter = createRoutine("APPLY_USER_SEARCH_FILTER");
11
10
  export const bulkUpdateStructures = createRoutine("BULK_UPDATE_STRUCTURES");
12
11
  export const cancelPoll = createRoutine("CANCEL_POLL");
@@ -70,7 +69,6 @@ export const deleteUserSearchFilter = createRoutine(
70
69
  );
71
70
  export const doStructureNoteAction = createRoutine("DO_STRUCTURE_NOTE_ACTION");
72
71
  export const downloadCsvGraph = createRoutine("DOWNLOAD_CSV_GRAPH");
73
- export const downloadGrants = createRoutine("DOWNLOAD_GRANTS");
74
72
  export const downloadReferenceDataset = createRoutine(
75
73
  "DOWNLOAD_REFERENCE_DATASET"
76
74
  );
@@ -145,7 +143,6 @@ export const setGrantRequestsQuery = createRoutine("SET_GRANT_REQUESTS_QUERY");
145
143
  export const sortGrants = createRoutine("SORT_GRANTS");
146
144
  export const tagStructure = createRoutine("TAG_STRUCTURE");
147
145
  export const structureSearchQuery = createRoutine("STRUCTURES_SEARCH_QUERY");
148
- export const toggleGrantDateFilter = createRoutine("TOGGLE_GRANT_DATE_FILTER");
149
146
  export const toggleGrantFilterValue = createRoutine(
150
147
  "TOGGLE_GRANT_FILTER_VALUE"
151
148
  );
@@ -18,7 +18,6 @@ import { deleteTagRequestSaga } from "./deleteTag";
18
18
  import { deleteUserSearchFilterRequestSaga } from "./deleteUserSearchFilter";
19
19
  import { doStructureNoteActionRequestSaga } from "./doStructureNoteAction";
20
20
  import { downloadCsvGraphRequestSaga } from "./downloadCsvGraph";
21
- import { downloadGrantsRequestSaga } from "./downloadGrants";
22
21
  import { downloadReferenceDatasetRequestSaga } from "./downloadReferenceDataset";
23
22
  import { fetchGrantFiltersRequestSaga } from "./fetchGrantFilters";
24
23
  import { fetchGrantRequestsFiltersRequestSaga } from "./fetchGrantRequestsFilters";
@@ -75,7 +74,6 @@ export {
75
74
  deleteUserSearchFilterRequestSaga,
76
75
  doStructureNoteActionRequestSaga,
77
76
  downloadCsvGraphRequestSaga,
78
- downloadGrantsRequestSaga,
79
77
  downloadReferenceDatasetRequestSaga,
80
78
  fetchGrantFiltersRequestSaga,
81
79
  fetchGrantRequestRequestSaga,
@@ -133,7 +131,6 @@ export default [
133
131
  deleteUserSearchFilterRequestSaga(),
134
132
  doStructureNoteActionRequestSaga(),
135
133
  downloadCsvGraphRequestSaga(),
136
- downloadGrantsRequestSaga(),
137
134
  downloadReferenceDatasetRequestSaga(),
138
135
  fetchGrantFiltersRequestSaga(),
139
136
  fetchGrantRequestRequestSaga(),
@@ -90,17 +90,16 @@ GrantTableStructureDecorator.propTypes = {
90
90
  data_structure_version: PropTypes.object,
91
91
  };
92
92
 
93
- export const GenericObjectDecorator = ({
94
- data_structure_version: { metadata },
95
- }) =>
96
- Object.entries(metadata).map(([k, v], i) => [
93
+ export const ObjectDecorator = (object) => {
94
+ return Object.entries(object).map(([k, v], i) => [
97
95
  <div key={i}>
98
96
  {k}: {`${v}`}
99
97
  </div>,
100
98
  ]);
99
+ };
101
100
 
102
- GenericObjectDecorator.propTypes = {
103
- metadata: PropTypes.object,
101
+ ObjectDecorator.propTypes = {
102
+ object: PropTypes.object,
104
103
  };
105
104
 
106
105
  export const StartDateDecorator = ({ start_date }) => {
@@ -199,7 +198,7 @@ export const getGrantsColumns = createSelector(
199
198
  export const defaultGrantsTableColumns = [
200
199
  {
201
200
  name: "user",
202
- sort: { name: "user.user_name.raw" },
201
+ sort: { name: "user.full_name.raw" },
203
202
  fieldSelector: _.pick(["user"]),
204
203
  fieldDecorator: userDecorator,
205
204
  },
@@ -221,11 +220,6 @@ export const defaultGrantsTableColumns = [
221
220
  fieldSelector: _.pick(["end_date", "pending_removal"]),
222
221
  fieldDecorator: EndDateDecorator,
223
222
  },
224
- {
225
- name: "metadata",
226
- fieldSelector: _.pick(["data_structure_version.metadata"]),
227
- fieldDecorator: GenericObjectDecorator,
228
- },
229
223
  ];
230
224
 
231
225
  export const getGrantsTableColumns = createSelector(
@@ -13,9 +13,6 @@ export {
13
13
  } from "./getGrantRequestsSearchColumns";
14
14
  export { getGrantAvailableFilters } from "./getGrantAvailableFilters";
15
15
  export { getGrantSelectedFilters } from "./getGrantSelectedFilters";
16
- export { getGrantFilterTypes } from "./getGrantFilterTypes";
17
- export { getGrantSelectedFilterValues } from "./getGrantSelectedFilterValues";
18
- export { getGrantSelectedFilterActiveValues } from "./getGrantSelectedFilterActiveValues";
19
16
  export {
20
17
  defaultStructureProperties,
21
18
  getStructureProperties,
@@ -26,7 +23,6 @@ export {
26
23
  defaultRelationColumns,
27
24
  } from "./getStructureRelations";
28
25
  export { getParsedEvents } from "./getParsedEvents";
29
- export { getPreviousGrantQuery } from "./getPreviousGrantQuery";
30
26
  export {
31
27
  getSortedChildrenRelations,
32
28
  getSortedParentRelations,
@@ -1,27 +0,0 @@
1
- import { propOr } from "lodash/fp";
2
- import PropTypes from "prop-types";
3
- import { FormattedMessage } from "react-intl";
4
- import { connect } from "react-redux";
5
- import DateRangeFilter from "@truedat/core/components/DateRangeFilter";
6
- import { applyGrantDateFilter } from "../routines";
7
-
8
- export const GrantDateFilter = ({ active, applyGrantDateFilter, ...props }) =>
9
- active ? (
10
- <DateRangeFilter
11
- label={<FormattedMessage id="grant.start_date" />}
12
- name="start_date,end_date"
13
- onChange={applyGrantDateFilter}
14
- defaultValues={props}
15
- />
16
- ) : null;
17
-
18
- GrantDateFilter.propTypes = {
19
- active: PropTypes.bool,
20
- applyGrantDateFilter: PropTypes.func,
21
- };
22
-
23
- export const mapStateToProps = propOr({}, "grantDateFilter");
24
-
25
- export default connect(mapStateToProps, { applyGrantDateFilter })(
26
- GrantDateFilter
27
- );
@@ -1,59 +0,0 @@
1
- import _ from "lodash/fp";
2
- import { bindActionCreators } from "redux";
3
- import { connect } from "react-redux";
4
- import { makeOption } from "@truedat/core/services/i18n";
5
- import { SelectedFilters } from "@truedat/core/components";
6
- import {
7
- closeGrantFilter,
8
- openGrantFilter,
9
- removeGrantFilter,
10
- resetGrantFilters,
11
- toggleGrantFilterValue,
12
- } from "../routines";
13
- import {
14
- getGrantSelectedFilterActiveValues,
15
- getGrantSelectedFilters,
16
- getGrantSelectedFilterValues,
17
- getGrantFilterTypes,
18
- } from "../selectors";
19
-
20
- const translations = (formatMessage) => ({
21
- "active.raw": (v) =>
22
- formatMessage({ id: `filters.active.raw.${v}`, defaultMessage: v }),
23
- "execution_result_info.result_text": (v) =>
24
- formatMessage({ id: v, defaultMessage: v }),
25
- });
26
-
27
- export const mapStateToProps = (state, ownProps) => {
28
- const formatMessage = _.pathOr(_.prop("id"), "intl.formatMessage")(ownProps);
29
- const { grantFiltersLoading: loading, grantSelectedFilter: selectedFilter } =
30
- state;
31
-
32
- const i18nValues = _.flow(
33
- getGrantSelectedFilterValues,
34
- _.map(makeOption(translations(formatMessage), selectedFilter))
35
- )(state);
36
-
37
- return {
38
- loading,
39
- filterTypes: getGrantFilterTypes(state),
40
- selectedFilter,
41
- selectedFilters: getGrantSelectedFilters(state),
42
- selectedFilterActiveValues: getGrantSelectedFilterActiveValues(state),
43
- selectedFilterValues: i18nValues,
44
- };
45
- };
46
-
47
- const mapDispatchToProps = (dispatch) =>
48
- bindActionCreators(
49
- {
50
- closeFilter: closeGrantFilter,
51
- openFilter: openGrantFilter,
52
- removeFilter: removeGrantFilter,
53
- resetFilters: resetGrantFilters,
54
- toggleFilterValue: toggleGrantFilterValue,
55
- },
56
- dispatch
57
- );
58
-
59
- export default connect(mapStateToProps, mapDispatchToProps)(SelectedFilters);
@@ -1,50 +0,0 @@
1
- import PropTypes from "prop-types";
2
- import { connect } from "react-redux";
3
- import { Button, Icon, Input } from "semantic-ui-react";
4
- import { useIntl } from "react-intl";
5
- import { searchGrants, toggleGrantDateFilter } from "../routines";
6
- import GrantFilters from "./GrantFilters";
7
-
8
- export const GrantsSearch = ({
9
- query,
10
- searchGrants,
11
- grantDateFilter,
12
- toggleGrantDateFilter,
13
- }) => {
14
- const { formatMessage } = useIntl();
15
-
16
- return (
17
- <Input
18
- value={query}
19
- onChange={(_e, data) => searchGrants({ query: data.value })}
20
- iconPosition="left"
21
- action
22
- placeholder={formatMessage({ id: "structures.search.placeholder" })}
23
- >
24
- <Icon name="search" link />
25
- <input />
26
- <Button
27
- icon="calendar alternate outline"
28
- active={grantDateFilter?.active}
29
- onClick={() => toggleGrantDateFilter()}
30
- />
31
- <GrantFilters />
32
- </Input>
33
- );
34
- };
35
-
36
- GrantsSearch.propTypes = {
37
- query: PropTypes.string,
38
- searchGrants: PropTypes.func,
39
- grantDateFilter: PropTypes.object,
40
- toggleGrantDateFilter: PropTypes.func,
41
- };
42
-
43
- const mapStateToProps = ({ grantQuery }) => ({
44
- query: grantQuery?.query,
45
- });
46
-
47
- export default connect(mapStateToProps, {
48
- searchGrants,
49
- toggleGrantDateFilter,
50
- })(GrantsSearch);
@@ -1,18 +0,0 @@
1
- import { render, waitForLoad } from "@truedat/test/render";
2
- import { GrantDateFilter } from "../GrantDateFilter";
3
-
4
- describe("<GrantDateFilter />", () => {
5
- it("matches the latest snapshot", async () => {
6
- const renderOpts = {
7
- state: {
8
- userPermissions: { update: true },
9
- },
10
- };
11
- const rendered = render(
12
- <GrantDateFilter active={true} applyGrantDateFilter={() => {}} />,
13
- renderOpts
14
- );
15
- await waitForLoad(rendered);
16
- expect(rendered.container).toMatchSnapshot();
17
- });
18
- });
@@ -1,34 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`<GrantDateFilter /> matches the latest snapshot 1`] = `
4
- <div>
5
- <div
6
- class="inline fields"
7
- >
8
- <div
9
- class="field"
10
- >
11
- <div
12
- class="ui input"
13
- >
14
- <input
15
- type="date"
16
- value=""
17
- />
18
- </div>
19
- </div>
20
- <div
21
- class="field"
22
- >
23
- <div
24
- class="ui input"
25
- >
26
- <input
27
- type="date"
28
- value=""
29
- />
30
- </div>
31
- </div>
32
- </div>
33
- </div>
34
- `;
@@ -1,54 +0,0 @@
1
- import {
2
- applyGrantDateFilter,
3
- clearGrantFilters,
4
- toggleGrantDateFilter,
5
- } from "../../routines";
6
- import { initialState, grantDateFilter } from "../grantDateFilter";
7
-
8
- const fooState = { foo: "bar" };
9
-
10
- describe("reducers: grantDateFilter", () => {
11
- it("should provide the initial state", () => {
12
- expect(grantDateFilter(undefined, {})).toBe(initialState);
13
- });
14
-
15
- it("should handle the clearGrantFilters.TRIGGER action", () => {
16
- expect(grantDateFilter(fooState, { type: clearGrantFilters.TRIGGER })).toBe(
17
- initialState
18
- );
19
- });
20
-
21
- it("should handle the toggleGrantDateFilter.TRIGGER action", () => {
22
- expect(
23
- grantDateFilter(
24
- { active: false },
25
- { type: toggleGrantDateFilter.TRIGGER }
26
- )
27
- ).toEqual({ active: true });
28
-
29
- expect(
30
- grantDateFilter({ active: true }, { type: toggleGrantDateFilter.TRIGGER })
31
- ).toEqual({ active: false });
32
- });
33
-
34
- it("should handle the applyGrantDateFilter.TRIGGER action", () => {
35
- const payload = {
36
- name: "some_date",
37
- type: "range",
38
- value: "2020-01-01 - 2020-02-02",
39
- };
40
- expect(
41
- grantDateFilter(
42
- { active: true },
43
- {
44
- type: applyGrantDateFilter.TRIGGER,
45
- payload,
46
- }
47
- )
48
- ).toEqual({ ...payload, active: true });
49
- });
50
-
51
- it("should ignore unknown actions", () => {
52
- expect(grantDateFilter(fooState, { type: "FOO" })).toBe(fooState);
53
- });
54
- });