@truedat/dd 4.28.1 → 4.28.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.
- package/CHANGELOG.md +6 -0
- package/package.json +6 -6
- package/src/api.js +4 -0
- package/src/components/EditDomainForm.js +1 -0
- package/src/components/GrantDateFilter.js +30 -0
- package/src/components/GrantFilters.js +28 -0
- package/src/components/GrantFiltersLoader.js +24 -0
- package/src/components/GrantSelectedFilters.js +63 -0
- package/src/components/Grants.js +49 -0
- package/src/components/GrantsLabelResults.js +32 -0
- package/src/components/GrantsLoader.js +41 -0
- package/src/components/GrantsPagination.js +14 -0
- package/src/components/GrantsRoutes.js +33 -0
- package/src/components/GrantsSearch.js +51 -0
- package/src/components/GrantsTable.js +112 -0
- package/src/components/StructureGrantCart.js +16 -14
- package/src/components/StructureGrantCartCheckout.js +9 -9
- package/src/components/StructureSummary.js +5 -5
- package/src/components/StructureTabPane.js +3 -3
- package/src/components/StructureView.js +14 -6
- package/src/components/__tests__/GrantDateFilter.spec.js +11 -0
- package/src/components/__tests__/GrantsLabelResults.js +17 -0
- package/src/components/__tests__/GrantsLoader.spec.js +41 -0
- package/src/components/__tests__/GrantsRoutes.spec.js +19 -0
- package/src/components/__tests__/GrantsTable.spec.js +185 -0
- package/src/components/__tests__/StructureGrantRequestButton.spec.js +20 -9
- package/src/components/__tests__/StructureSummary.spec.js +1 -1
- package/src/components/__tests__/__snapshots__/GrantDateFilter.spec.js.snap +16 -0
- package/src/components/__tests__/__snapshots__/GrantsLabelResults.js.snap +16 -0
- package/src/components/__tests__/__snapshots__/GrantsLoader.spec.js.snap +24 -0
- package/src/components/__tests__/__snapshots__/GrantsRoutes.spec.js.snap +8 -0
- package/src/components/__tests__/__snapshots__/GrantsTable.spec.js.snap +231 -0
- package/src/components/index.js +6 -0
- package/src/messages/en.js +9 -1
- package/src/messages/es.js +9 -1
- package/src/reducers/__tests__/grantDateFilter.spec.js +54 -0
- package/src/reducers/__tests__/grantFilters.spec.js +37 -0
- package/src/reducers/__tests__/grantQuery.spec.js +113 -0
- package/src/reducers/__tests__/grants.spec.js +102 -0
- package/src/reducers/grantActiveFilters.js +46 -0
- package/src/reducers/grantCount.js +20 -0
- package/src/reducers/grantDateFilter.js +31 -0
- package/src/reducers/grantFilters.js +19 -0
- package/src/reducers/grantLoading.js +16 -0
- package/src/reducers/grantQuery.js +62 -0
- package/src/reducers/grantSelectedFilter.js +34 -0
- package/src/reducers/grants.js +24 -0
- package/src/reducers/grantsFilters.js +19 -0
- package/src/reducers/grantsPageSize.js +15 -0
- package/src/reducers/index.js +18 -0
- package/src/reducers/structureDateFilter.js +2 -2
- package/src/reducers/structureQuery.js +2 -2
- package/src/routines.js +20 -0
- package/src/sagas/__tests__/fetchGrants.spec.js +74 -0
- package/src/sagas/fetchGrantFilters.js +29 -0
- package/src/sagas/fetchGrants.js +26 -0
- package/src/sagas/index.js +6 -0
- package/src/selectors/__tests__/__snapshots__/getGrantsColumns.spec.js.snap +10 -0
- package/src/selectors/__tests__/getGrantAvailableFilters.spec.js +15 -0
- package/src/selectors/__tests__/getGrantSelectedFilterActiveValues.spec.js +16 -0
- package/src/selectors/__tests__/getGrantSelectedFilterValues.spec.js +15 -0
- package/src/selectors/__tests__/getGrantSelectedFilters.spec.js +15 -0
- package/src/selectors/__tests__/getGrantsColumns.spec.js +40 -0
- package/src/selectors/__tests__/getTabVisibility.spec.js +30 -30
- package/src/selectors/getGrantAvailableFilters.js +17 -0
- package/src/selectors/getGrantSelectedFilterActiveValues.js +8 -0
- package/src/selectors/getGrantSelectedFilterValues.js +13 -0
- package/src/selectors/getGrantSelectedFilters.js +7 -0
- package/src/selectors/getGrantsColumns.js +82 -8
- package/src/selectors/getStructureSelectedFilterValues.js +5 -3
- package/src/selectors/getTabVisibility.js +7 -7
- package/src/selectors/index.js +4 -0
package/src/components/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import DictionaryRoutes from "./DictionaryRoutes";
|
|
2
2
|
import FilteredNav from "./FilteredNav";
|
|
3
|
+
import GrantSelectedFilters from "./GrantSelectedFilters";
|
|
4
|
+
import GrantsRoutes from "./GrantsRoutes";
|
|
5
|
+
import GrantsTable from "./GrantsTable";
|
|
3
6
|
import LineageDefs from "./LineageDefs";
|
|
4
7
|
import LineageDownloadButton from "./LineageDownloadButton";
|
|
5
8
|
import LineageGroup from "./LineageGroup";
|
|
@@ -54,6 +57,9 @@ import ValueConditionStructure from "./ValueConditionStructure";
|
|
|
54
57
|
export {
|
|
55
58
|
DictionaryRoutes,
|
|
56
59
|
FilteredNav,
|
|
60
|
+
GrantsRoutes,
|
|
61
|
+
GrantSelectedFilters,
|
|
62
|
+
GrantsTable,
|
|
57
63
|
LineageDefs,
|
|
58
64
|
LineageDownloadButton,
|
|
59
65
|
LineageGroup,
|
package/src/messages/en.js
CHANGED
|
@@ -13,6 +13,7 @@ export default {
|
|
|
13
13
|
"execution.props.status": "Status",
|
|
14
14
|
"filters.class.raw": "Class",
|
|
15
15
|
"filters.confidential.raw": "Confidential",
|
|
16
|
+
"filters.data_structure_version.name.raw": "Structure",
|
|
16
17
|
"filters.domain.name.raw": "Domain",
|
|
17
18
|
"filters.field_type.raw": "Field Type",
|
|
18
19
|
"filters.group.raw": "Group",
|
|
@@ -23,6 +24,7 @@ export default {
|
|
|
23
24
|
"filters.system.name.raw": "System",
|
|
24
25
|
"filters.tags.raw": "Tags",
|
|
25
26
|
"filters.type.raw": "Type",
|
|
27
|
+
"filters.user_name": "User",
|
|
26
28
|
"filters.with_content.raw": "Extra Info",
|
|
27
29
|
"filters.with_content.raw.false": "Without extra info",
|
|
28
30
|
"filters.with_profiling.raw": "Profile",
|
|
@@ -35,6 +37,12 @@ export default {
|
|
|
35
37
|
"grant.header.data_structure": "Structure",
|
|
36
38
|
"grant.header.end_date": "Expires",
|
|
37
39
|
"grant.header.start_date": "Access granted",
|
|
40
|
+
"grant.updated_at": "Last changed",
|
|
41
|
+
"grants.header": "Grants",
|
|
42
|
+
"grants.retrieved.results": "{count} grants found",
|
|
43
|
+
"grants.search.placeholder": "Enter a search...",
|
|
44
|
+
"grants.search.results.empty": "No grants found",
|
|
45
|
+
"grants.subheader": "Grants",
|
|
38
46
|
"filters.with_content.raw.true": "Extra Info",
|
|
39
47
|
"graph.actions.download.popup": "Select a graph",
|
|
40
48
|
"graph.actions.download.tooltip": "Download to csv",
|
|
@@ -375,5 +383,5 @@ export default {
|
|
|
375
383
|
"updateSystem.error.df_content.invalid content": "Invalid template content",
|
|
376
384
|
"structure.grant.has_grant": "You have granted access on this structure",
|
|
377
385
|
"visualization.title.impact": "Impact Analysis",
|
|
378
|
-
"visualization.title.lineage": "Lineage Analysis"
|
|
386
|
+
"visualization.title.lineage": "Lineage Analysis",
|
|
379
387
|
};
|
package/src/messages/es.js
CHANGED
|
@@ -14,6 +14,7 @@ export default {
|
|
|
14
14
|
"execution.props.status": "Estado",
|
|
15
15
|
"filters.class.raw": "Clase",
|
|
16
16
|
"filters.confidential.raw": "Confidencial",
|
|
17
|
+
"filters.data_structure_version.name.raw": "Estructura",
|
|
17
18
|
"filters.domain.name.raw": "Dominio",
|
|
18
19
|
"filters.field_type.raw": "Tipo de Campo",
|
|
19
20
|
"filters.group.raw": "Grupo",
|
|
@@ -24,6 +25,7 @@ export default {
|
|
|
24
25
|
"filters.system.name.raw": "Sistema",
|
|
25
26
|
"filters.tags.raw": "Etiquetas",
|
|
26
27
|
"filters.type.raw": "Tipo",
|
|
28
|
+
"filters.user_name": "Usuario",
|
|
27
29
|
"filters.with_content.raw": "Extra Info",
|
|
28
30
|
"filters.with_content.raw.false": "Sin información extra",
|
|
29
31
|
"filters.with_profiling.raw": "Perfilado",
|
|
@@ -36,6 +38,12 @@ export default {
|
|
|
36
38
|
"grant.header.end_date": "Expira",
|
|
37
39
|
"grant.header.start_date": "Acceso desde",
|
|
38
40
|
"grant.header.user": "Cuenta",
|
|
41
|
+
"grant.updated_at": "Actualizada",
|
|
42
|
+
"grants.header": "Grants",
|
|
43
|
+
"grants.retrieved.results": "{count} grants encontrados",
|
|
44
|
+
"grants.search.placeholder": "Introduce una busqueda...",
|
|
45
|
+
"grants.search.results.empty": "Ningún grant encontrado",
|
|
46
|
+
"grants.subheader": "Grants",
|
|
39
47
|
"filters.with_content.raw.true": "Contiene información extra",
|
|
40
48
|
"graph.actions.download.popup": "Seleccione un grafo",
|
|
41
49
|
"graph.actions.download.tooltip": "Descargar en csv",
|
|
@@ -382,5 +390,5 @@ export default {
|
|
|
382
390
|
"Contenido de plantilla inválido",
|
|
383
391
|
"structure.grant.has_grant": "Tienes acceso a la estructura",
|
|
384
392
|
"visualization.title.impact": "Análisis de Impacto",
|
|
385
|
-
"visualization.title.lineage": "Análisis de Linaje"
|
|
393
|
+
"visualization.title.lineage": "Análisis de Linaje",
|
|
386
394
|
};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { clearGrantFilters, fetchGrantFilters } from "../../routines";
|
|
2
|
+
import { grantFilters } from "..";
|
|
3
|
+
|
|
4
|
+
const fooState = { foo: "bar" };
|
|
5
|
+
|
|
6
|
+
describe("reducers: grantFilters", () => {
|
|
7
|
+
const initialState = {};
|
|
8
|
+
|
|
9
|
+
it("should provide the initial state", () => {
|
|
10
|
+
expect(grantFilters(undefined, {})).toEqual(initialState);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should handle the clearGrantFilters.TRIGGER action", () => {
|
|
14
|
+
expect(grantFilters(fooState, { type: clearGrantFilters.TRIGGER })).toEqual(
|
|
15
|
+
initialState
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should handle the fetchGrantFilters.SUCCESS action", () => {
|
|
20
|
+
const filter1 = ["value1", "value2"];
|
|
21
|
+
const filter2 = ["value1", "value2"];
|
|
22
|
+
const data = { filter1, filter2: ["value1"] };
|
|
23
|
+
const payload = { data: { data } };
|
|
24
|
+
const state = { filter2 };
|
|
25
|
+
|
|
26
|
+
expect(
|
|
27
|
+
grantFilters(state, {
|
|
28
|
+
type: fetchGrantFilters.SUCCESS,
|
|
29
|
+
payload,
|
|
30
|
+
})
|
|
31
|
+
).toEqual(data);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should ignore unknown actions", () => {
|
|
35
|
+
expect(grantFilters(fooState, { type: "FOO" })).toBe(fooState);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearGrantFilters,
|
|
3
|
+
removeGrantFilter,
|
|
4
|
+
searchGrants,
|
|
5
|
+
selectGrantPage,
|
|
6
|
+
sortGrants,
|
|
7
|
+
toggleGrantFilterValue,
|
|
8
|
+
clearGrantsSort,
|
|
9
|
+
} from "../../routines";
|
|
10
|
+
import { initialState } from "../grantQuery";
|
|
11
|
+
import { grantQuery } from "..";
|
|
12
|
+
|
|
13
|
+
const fooState = { foo: "bar" };
|
|
14
|
+
|
|
15
|
+
describe("reducers: grantQuery", () => {
|
|
16
|
+
it("should provide the initial state", () => {
|
|
17
|
+
expect(grantQuery(undefined, {})).toEqual(initialState);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should handle the selectGrantPage.TRIGGER action", () => {
|
|
21
|
+
const activePage = 123;
|
|
22
|
+
const payload = { activePage };
|
|
23
|
+
expect(
|
|
24
|
+
grantQuery(fooState, { type: selectGrantPage.TRIGGER, payload })
|
|
25
|
+
).toEqual({ ...fooState, page: activePage });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should handle the clearGrantFilters.TRIGGER action", () => {
|
|
29
|
+
expect(grantQuery(fooState, { type: clearGrantFilters.TRIGGER })).toEqual({
|
|
30
|
+
...fooState,
|
|
31
|
+
page: 1,
|
|
32
|
+
query: "",
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should handle the clearGrantsSort.TRIGGER action", () => {
|
|
37
|
+
expect(grantQuery(fooState, { type: clearGrantsSort.TRIGGER })).toEqual({
|
|
38
|
+
...fooState,
|
|
39
|
+
sort: [{ "data_structure_version.name.raw": "asc" }],
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should return default page when filter is removed", () => {
|
|
44
|
+
expect(grantQuery(fooState, { type: removeGrantFilter.TRIGGER })).toEqual({
|
|
45
|
+
...fooState,
|
|
46
|
+
page: 1,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// // it("should return default page when user filter is applied", () => {
|
|
51
|
+
// // expect(
|
|
52
|
+
// // grantQuery(fooState, { type: applyStructureUserFilter.TRIGGER })
|
|
53
|
+
// // ).toEqual({
|
|
54
|
+
// // ...fooState,
|
|
55
|
+
// // page: 1
|
|
56
|
+
// // });
|
|
57
|
+
// // });
|
|
58
|
+
|
|
59
|
+
it("should return default page when filter is toggled", () => {
|
|
60
|
+
expect(
|
|
61
|
+
grantQuery(fooState, { type: toggleGrantFilterValue.TRIGGER })
|
|
62
|
+
).toEqual({
|
|
63
|
+
...fooState,
|
|
64
|
+
page: 1,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("action: sortGrants.TRIGGER", () => {
|
|
69
|
+
it("should set sort from payload and set page to 1", () => {
|
|
70
|
+
const payload = [{ name2: "asc" }];
|
|
71
|
+
expect(
|
|
72
|
+
grantQuery(fooState, { type: sortGrants.TRIGGER, payload })
|
|
73
|
+
).toMatchObject({ sort: [{ name2: "asc" }] });
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("action: searchGrants.TRIGGER", () => {
|
|
78
|
+
const query = "some query";
|
|
79
|
+
it("should set the query from the payload", () => {
|
|
80
|
+
const payload = { query };
|
|
81
|
+
expect(
|
|
82
|
+
grantQuery(fooState, { type: searchGrants.TRIGGER, payload })
|
|
83
|
+
).toMatchObject({ query });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("when query is not empty it should order by relevance and name", () => {
|
|
87
|
+
const payload = { query };
|
|
88
|
+
expect(
|
|
89
|
+
grantQuery(fooState, { type: searchGrants.TRIGGER, payload })
|
|
90
|
+
).toMatchObject({
|
|
91
|
+
query,
|
|
92
|
+
sort: [
|
|
93
|
+
{ _score: "desc" },
|
|
94
|
+
{ "data_structure_version.name.raw": "asc" },
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("when query is empty it should order by name", () => {
|
|
100
|
+
const payload = { query: "" };
|
|
101
|
+
expect(
|
|
102
|
+
grantQuery(fooState, { type: searchGrants.TRIGGER, payload })
|
|
103
|
+
).toMatchObject({
|
|
104
|
+
query: "",
|
|
105
|
+
sort: [{ "data_structure_version.name.raw": "asc" }],
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should ignore unknown actions", () => {
|
|
111
|
+
expect(grantQuery(fooState, { type: "FOO" })).toBe(fooState);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { clearGrants, fetchGrants, updateGrant } from "../../routines";
|
|
2
|
+
import { grants, initialState } from "../grants";
|
|
3
|
+
|
|
4
|
+
const fooState = { foo: "bar" };
|
|
5
|
+
const someGrants = [
|
|
6
|
+
{
|
|
7
|
+
data_structure_version: {
|
|
8
|
+
data_structure_id: 22075,
|
|
9
|
+
description: "DEscripción",
|
|
10
|
+
domain: {
|
|
11
|
+
external_id: "Demo Truedat",
|
|
12
|
+
id: 3,
|
|
13
|
+
name: "Demo Truedat",
|
|
14
|
+
parent_ids: [],
|
|
15
|
+
updated_at: "2020-07-21 07:45:41.068703Z",
|
|
16
|
+
},
|
|
17
|
+
external_id: "sap:Clientes:KNA1",
|
|
18
|
+
metadata: {},
|
|
19
|
+
mutable_metadata: null,
|
|
20
|
+
name: "KNA1",
|
|
21
|
+
},
|
|
22
|
+
detail: {},
|
|
23
|
+
end_date: "2023-05-16",
|
|
24
|
+
id: 6,
|
|
25
|
+
start_date: "2020-05-17",
|
|
26
|
+
user: {
|
|
27
|
+
email: "user1@example.com",
|
|
28
|
+
full_name: "user_full_name_1",
|
|
29
|
+
user_name: "user1",
|
|
30
|
+
},
|
|
31
|
+
user_id: 23,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
data_structure_version: {
|
|
35
|
+
data_structure_id: 4570466,
|
|
36
|
+
description: null,
|
|
37
|
+
domain: {
|
|
38
|
+
external_id: "Truedat",
|
|
39
|
+
id: 2,
|
|
40
|
+
name: "Truedat",
|
|
41
|
+
parent_ids: [],
|
|
42
|
+
updated_at: "2020-07-28 13:21:21.938189Z",
|
|
43
|
+
},
|
|
44
|
+
external_id: "postgres://postgres/td_metrics/public/concepts",
|
|
45
|
+
metadata: {
|
|
46
|
+
alias: "Truedat-PostgreSQL",
|
|
47
|
+
database: "td_metrics",
|
|
48
|
+
host: "postgres",
|
|
49
|
+
schema: "public",
|
|
50
|
+
type: "BASE TABLE",
|
|
51
|
+
},
|
|
52
|
+
mutable_metadata: null,
|
|
53
|
+
name: "concepts",
|
|
54
|
+
},
|
|
55
|
+
detail: {
|
|
56
|
+
access_type: "admin",
|
|
57
|
+
},
|
|
58
|
+
end_date: "2023-05-18",
|
|
59
|
+
id: 8,
|
|
60
|
+
start_date: "2011-05-17",
|
|
61
|
+
user: {
|
|
62
|
+
email: "user2@example.com",
|
|
63
|
+
full_name: "user_full_name_2",
|
|
64
|
+
user_name: "user2",
|
|
65
|
+
},
|
|
66
|
+
user_id: 171,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
describe("reducers: grants", () => {
|
|
71
|
+
it("should provide the initial state", () => {
|
|
72
|
+
expect(grants(undefined, {})).toBe(initialState);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should handle the clearGrants.SUCCESS action", () => {
|
|
76
|
+
expect(grants(fooState, { type: clearGrants.TRIGGER })).toBe(initialState);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should handle the fetchGrants.SUCCESS action", () => {
|
|
80
|
+
const data = { data: someGrants };
|
|
81
|
+
|
|
82
|
+
expect(
|
|
83
|
+
grants(fooState, {
|
|
84
|
+
type: fetchGrants.SUCCESS,
|
|
85
|
+
payload: { data },
|
|
86
|
+
})
|
|
87
|
+
).toMatchObject(someGrants);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should handle the updateGrant.SUCCESS action", () => {
|
|
91
|
+
const state = [{ id: 1 }, { id: 2 }];
|
|
92
|
+
const data = { id: 1, user_id: "123" };
|
|
93
|
+
const expected = [data, { id: 2 }];
|
|
94
|
+
expect(
|
|
95
|
+
grants(state, { type: updateGrant.SUCCESS, payload: { data } })
|
|
96
|
+
).toMatchObject(expected);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should ignore unknown actions", () => {
|
|
100
|
+
expect(grants(fooState, { type: "FOO" })).toBe(fooState);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import {
|
|
3
|
+
addGrantFilter,
|
|
4
|
+
closeGrantFilter,
|
|
5
|
+
removeGrantFilter,
|
|
6
|
+
resetGrantFilters,
|
|
7
|
+
toggleGrantFilterValue,
|
|
8
|
+
} from "../routines";
|
|
9
|
+
|
|
10
|
+
export const initialState = {};
|
|
11
|
+
|
|
12
|
+
export const grantActiveFilters = (state = initialState, { type, payload }) => {
|
|
13
|
+
switch (type) {
|
|
14
|
+
case addGrantFilter.TRIGGER: {
|
|
15
|
+
const { filter } = payload;
|
|
16
|
+
return { ...state, [filter]: [] };
|
|
17
|
+
}
|
|
18
|
+
case closeGrantFilter.TRIGGER: {
|
|
19
|
+
const { filter } = payload;
|
|
20
|
+
const values = _.propOr([], filter)(state);
|
|
21
|
+
return _.isEmpty(values)
|
|
22
|
+
? _.omit(filter)(state)
|
|
23
|
+
: { ...state, [filter]: values };
|
|
24
|
+
}
|
|
25
|
+
case removeGrantFilter.TRIGGER: {
|
|
26
|
+
const { filter } = payload;
|
|
27
|
+
return _.omit(filter)(state);
|
|
28
|
+
}
|
|
29
|
+
case resetGrantFilters.TRIGGER: {
|
|
30
|
+
return initialState;
|
|
31
|
+
}
|
|
32
|
+
case toggleGrantFilterValue.TRIGGER: {
|
|
33
|
+
const { filter, value } = payload;
|
|
34
|
+
if (_.isArray(value)) {
|
|
35
|
+
return { ...state, [filter]: value };
|
|
36
|
+
}
|
|
37
|
+
const values = _.propOr([], filter)(state);
|
|
38
|
+
const nextValues = _.includes(value)(values)
|
|
39
|
+
? _.without([value])(values)
|
|
40
|
+
: _.union([value])(values);
|
|
41
|
+
return { ...state, [filter]: nextValues };
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
return state;
|
|
45
|
+
}
|
|
46
|
+
};
|