@truedat/dd 7.6.3 → 7.6.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.
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
@@ -1,30 +0,0 @@
1
- import {
2
- applyGrantDateFilter,
3
- clearGrantFilters,
4
- toggleGrantDateFilter,
5
- } from "../routines";
6
-
7
- export const initialState = {
8
- active: false,
9
- name: "start_date,end_date",
10
- type: "range",
11
- rangeStart: "",
12
- rangeEnd: "",
13
- };
14
-
15
- export const grantDateFilter = (state = initialState, { type, payload }) => {
16
- switch (type) {
17
- case clearGrantFilters.TRIGGER:
18
- return initialState;
19
- case toggleGrantDateFilter.TRIGGER: {
20
- const { active } = state;
21
- return { ...state, active: !active };
22
- }
23
- case applyGrantDateFilter.TRIGGER: {
24
- const { active } = state;
25
- return { ...payload, active };
26
- }
27
- default:
28
- return state;
29
- }
30
- };
@@ -1,85 +0,0 @@
1
- import { testSaga } from "redux-saga-test-plan";
2
- import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
3
- import {
4
- downloadGrantsRequestSaga,
5
- downloadGrantsSaga,
6
- saveFile,
7
- } from "../downloadGrants";
8
- import { downloadGrants } from "../../routines";
9
- import { API_GRANTS_CSV } from "../../api";
10
- import { getPreviousGrantQuery } from "../../selectors";
11
-
12
- describe("sagas: downloadGrantsRequestSaga", () => {
13
- it("should invoke downloadGrantsSaga on downloadGrants.TRIGGER", () => {
14
- expect(() => {
15
- testSaga(downloadGrantsRequestSaga)
16
- .next()
17
- .takeLatest(downloadGrants.TRIGGER, downloadGrantsSaga)
18
- .finish()
19
- .isDone();
20
- }).not.toThrow();
21
- });
22
-
23
- it("should throw exception if an unhandled action is received", () => {
24
- expect(() => {
25
- testSaga(downloadGrantsRequestSaga)
26
- .next()
27
- .takeLatest("FOO", downloadGrantsRequestSaga);
28
- }).toThrow();
29
- });
30
- });
31
-
32
- describe("sagas: downloadGrantsSaga", () => {
33
- const headerLabels = { name: "Name" };
34
- const payload = { headerLabels, search_by: "permissions" };
35
-
36
- const query = { filters: {}, page: 0, query: {}, size: 20 };
37
- const data = "SOME CSV DATA";
38
-
39
- const body = {
40
- header_labels: headerLabels,
41
- search_by: "permissions",
42
- ...query,
43
- };
44
-
45
- it("should put a success action when a response is returned", () => {
46
- expect(() => {
47
- testSaga(downloadGrantsSaga, { payload })
48
- .next()
49
- .select(getPreviousGrantQuery)
50
- .next(query)
51
- .put(downloadGrants.request(body))
52
- .next()
53
- .call(apiJsonPost, API_GRANTS_CSV, body, JSON_OPTS)
54
- .next({ data })
55
- .call(saveFile, data)
56
- .next()
57
- .put(downloadGrants.success(data))
58
- .next()
59
- .put(downloadGrants.fulfill())
60
- .next()
61
- .isDone();
62
- }).not.toThrow();
63
- });
64
-
65
- it("should put a failure action when the call returns an error", () => {
66
- const message = "Request failed";
67
- const error = { message };
68
-
69
- expect(() => {
70
- testSaga(downloadGrantsSaga, { payload })
71
- .next()
72
- .select(getPreviousGrantQuery)
73
- .next(query)
74
- .put(downloadGrants.request(body))
75
- .next()
76
- .call(apiJsonPost, API_GRANTS_CSV, body, JSON_OPTS)
77
- .throw(error)
78
- .put(downloadGrants.failure(message))
79
- .next()
80
- .put(downloadGrants.fulfill())
81
- .next()
82
- .isDone();
83
- }).not.toThrow();
84
- });
85
- });
@@ -1,46 +0,0 @@
1
- import _ from "lodash/fp";
2
- import FileSaver from "file-saver";
3
- import { call, put, select, takeLatest } from "redux-saga/effects";
4
- import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
5
- import { downloadGrants } from "../routines";
6
- import { getPreviousGrantQuery } from "../selectors";
7
- import { API_GRANTS_CSV } from "../api";
8
-
9
- export function saveFile(data) {
10
- if (!_.isEmpty(data)) {
11
- const blob = new Blob([String.fromCharCode(0xfeff), data], {
12
- type: "text/csv;charset=utf-8",
13
- });
14
- FileSaver.saveAs(blob, "grants.csv");
15
- }
16
- }
17
-
18
- export function* downloadGrantsSaga({ payload }) {
19
- try {
20
- const headerLabels = _.propOr({}, "headerLabels")(payload);
21
- const query = yield select(getPreviousGrantQuery);
22
- const body = {
23
- header_labels: headerLabels,
24
- search_by: payload.search_by,
25
- ...query,
26
- };
27
- const url = API_GRANTS_CSV;
28
- yield put(downloadGrants.request(body));
29
- const { data } = yield call(apiJsonPost, url, body, JSON_OPTS);
30
- yield call(saveFile, data);
31
- yield put(downloadGrants.success(data));
32
- } catch (error) {
33
- if (error.response) {
34
- const { status, data } = error.response;
35
- yield put(downloadGrants.failure({ status, data }));
36
- } else {
37
- yield put(downloadGrants.failure(error.message));
38
- }
39
- } finally {
40
- yield put(downloadGrants.fulfill());
41
- }
42
- }
43
-
44
- export function* downloadGrantsRequestSaga() {
45
- yield takeLatest(downloadGrants.TRIGGER, downloadGrantsSaga);
46
- }
@@ -1,16 +0,0 @@
1
- import { getGrantSelectedFilterActiveValues } from "..";
2
-
3
- const foo = ["foo1", "foo2"];
4
- const bar = ["bar1", "bar2"];
5
- const baz = ["baz1", "baz2"];
6
-
7
- describe("selectors: getGrantSelectedFilterActiveValues", () => {
8
- const grantFilters = { foo, bar, baz };
9
- const grantActiveFilters = { foo: ["foo1"] };
10
- const grantSelectedFilter = "foo";
11
- const state = { grantFilters, grantActiveFilters, grantSelectedFilter };
12
-
13
- it("should return the active values of the currently selected grant filters", () => {
14
- expect(getGrantSelectedFilterActiveValues(state)).toEqual(["foo1"]);
15
- });
16
- });
@@ -1,15 +0,0 @@
1
- import { getGrantSelectedFilterValues } from "..";
2
-
3
- const foo = { values: ["foo1", "foo2"] };
4
- const bar = { values: ["bar1", "bar2"] };
5
- const baz = { values: ["baz1", "baz2"] };
6
-
7
- describe("selectors: getGrantSelectedFilterValues", () => {
8
- const grantFilters = { foo, bar, baz };
9
- const grantSelectedFilter = "foo";
10
- const state = { grantFilters, grantSelectedFilter };
11
-
12
- it("should return the values of the currently selected grant filters", () => {
13
- expect(getGrantSelectedFilterValues(state)).toEqual(foo.values);
14
- });
15
- });
@@ -1,7 +0,0 @@
1
- import _ from "lodash/fp";
2
- import { createSelector } from "reselect";
3
-
4
- export const getGrantFilterTypes = createSelector(
5
- _.prop("grantFilters"),
6
- _.mapValues("type")
7
- );
@@ -1,8 +0,0 @@
1
- import _ from "lodash/fp";
2
- import { createSelector } from "reselect";
3
-
4
- export const getGrantSelectedFilterActiveValues = createSelector(
5
- [_.prop("grantSelectedFilter"), _.prop("grantActiveFilters")],
6
- (grantSelectedFilter, grantActiveFilters) =>
7
- _.propOr([], grantSelectedFilter)(grantActiveFilters)
8
- );
@@ -1,12 +0,0 @@
1
- import _ from "lodash/fp";
2
- import { createSelector } from "reselect";
3
- import { formatFilterValues } from "@truedat/core/services/filters";
4
-
5
- export const getGrantSelectedFilterValues = createSelector(
6
- [_.prop("grantSelectedFilter"), _.prop("grantFilters")],
7
- (grantSelectedFilter, grantFilters) =>
8
- _.flow(
9
- _.propOr({ values: [] }, grantSelectedFilter),
10
- formatFilterValues
11
- )(grantFilters)
12
- );
@@ -1 +0,0 @@
1
- export const getPreviousGrantQuery = ({ previousGrantQuery: q = {} }) => q;