@truedat/dd 4.28.3 → 4.28.7

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 (72) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +6 -6
  3. package/src/api.js +8 -0
  4. package/src/components/DictionaryRoutes.js +27 -0
  5. package/src/components/EditDomainForm.js +1 -0
  6. package/src/components/GrantDateFilter.js +30 -0
  7. package/src/components/GrantFilters.js +28 -0
  8. package/src/components/GrantFiltersLoader.js +29 -0
  9. package/src/components/GrantSelectedFilters.js +63 -0
  10. package/src/components/Grants.js +54 -0
  11. package/src/components/GrantsLabelResults.js +32 -0
  12. package/src/components/GrantsLoader.js +47 -0
  13. package/src/components/GrantsPagination.js +14 -0
  14. package/src/components/GrantsSearch.js +51 -0
  15. package/src/components/GrantsTable.js +112 -0
  16. package/src/components/StructureGrantCart.js +16 -14
  17. package/src/components/StructureGrantCartCheckout.js +9 -9
  18. package/src/components/StructureSummary.js +5 -5
  19. package/src/components/StructureTabPane.js +3 -3
  20. package/src/components/StructureView.js +14 -6
  21. package/src/components/__tests__/GrantDateFilter.spec.js +11 -0
  22. package/src/components/__tests__/GrantsLabelResults.js +17 -0
  23. package/src/components/__tests__/GrantsLoader.spec.js +41 -0
  24. package/src/components/__tests__/GrantsTable.spec.js +185 -0
  25. package/src/components/__tests__/StructureGrantRequestButton.spec.js +20 -9
  26. package/src/components/__tests__/StructureSummary.spec.js +1 -1
  27. package/src/components/__tests__/__snapshots__/DictionaryRoutes.spec.js.snap +8 -0
  28. package/src/components/__tests__/__snapshots__/GrantDateFilter.spec.js.snap +16 -0
  29. package/src/components/__tests__/__snapshots__/GrantsLabelResults.js.snap +16 -0
  30. package/src/components/__tests__/__snapshots__/GrantsLoader.spec.js.snap +27 -0
  31. package/src/components/__tests__/__snapshots__/GrantsTable.spec.js.snap +231 -0
  32. package/src/components/index.js +4 -0
  33. package/src/messages/en.js +12 -2
  34. package/src/messages/es.js +12 -2
  35. package/src/reducers/__tests__/grantDateFilter.spec.js +54 -0
  36. package/src/reducers/__tests__/grantFilters.spec.js +37 -0
  37. package/src/reducers/__tests__/grantQuery.spec.js +113 -0
  38. package/src/reducers/__tests__/grants.spec.js +102 -0
  39. package/src/reducers/grantActiveFilters.js +48 -0
  40. package/src/reducers/grantCount.js +20 -0
  41. package/src/reducers/grantDateFilter.js +31 -0
  42. package/src/reducers/grantFilters.js +19 -0
  43. package/src/reducers/grantLoading.js +16 -0
  44. package/src/reducers/grantQuery.js +62 -0
  45. package/src/reducers/grantSelectedFilter.js +34 -0
  46. package/src/reducers/grants.js +24 -0
  47. package/src/reducers/grantsFilters.js +19 -0
  48. package/src/reducers/grantsPageSize.js +15 -0
  49. package/src/reducers/index.js +18 -0
  50. package/src/reducers/structureDateFilter.js +2 -2
  51. package/src/reducers/structureQuery.js +2 -2
  52. package/src/routines.js +20 -0
  53. package/src/sagas/__tests__/fetchGrantFilters.spec.js +97 -0
  54. package/src/sagas/__tests__/fetchGrants.spec.js +86 -0
  55. package/src/sagas/fetchGrantFilters.js +31 -0
  56. package/src/sagas/fetchGrants.js +26 -0
  57. package/src/sagas/index.js +6 -0
  58. package/src/selectors/__tests__/__snapshots__/getGrantsColumns.spec.js.snap +10 -0
  59. package/src/selectors/__tests__/getGrantAvailableFilters.spec.js +15 -0
  60. package/src/selectors/__tests__/getGrantSelectedFilterActiveValues.spec.js +16 -0
  61. package/src/selectors/__tests__/getGrantSelectedFilterValues.spec.js +15 -0
  62. package/src/selectors/__tests__/getGrantSelectedFilters.spec.js +15 -0
  63. package/src/selectors/__tests__/getGrantsColumns.spec.js +40 -0
  64. package/src/selectors/__tests__/getTabVisibility.spec.js +30 -30
  65. package/src/selectors/getGrantAvailableFilters.js +17 -0
  66. package/src/selectors/getGrantSelectedFilterActiveValues.js +8 -0
  67. package/src/selectors/getGrantSelectedFilterValues.js +13 -0
  68. package/src/selectors/getGrantSelectedFilters.js +7 -0
  69. package/src/selectors/getGrantsColumns.js +84 -8
  70. package/src/selectors/getStructureSelectedFilterValues.js +5 -3
  71. package/src/selectors/getTabVisibility.js +7 -7
  72. package/src/selectors/index.js +4 -0
@@ -0,0 +1,231 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<GrantsTable /> matches the latest snapshot 1`] = `
4
+ <Fragment>
5
+ <Table
6
+ as="table"
7
+ selectable={true}
8
+ sortable={true}
9
+ >
10
+ <TableHeader
11
+ as="thead"
12
+ >
13
+ <TableRow
14
+ as="tr"
15
+ cellAs="td"
16
+ >
17
+ <TableHeaderCell
18
+ as="th"
19
+ className=""
20
+ content="grant.header.user"
21
+ key="0"
22
+ onClick={[Function]}
23
+ sorted={null}
24
+ />
25
+ <TableHeaderCell
26
+ as="th"
27
+ className=""
28
+ content="grant.header.data_structure_version"
29
+ key="1"
30
+ onClick={[Function]}
31
+ sorted="ascending"
32
+ />
33
+ <TableHeaderCell
34
+ as="th"
35
+ className=""
36
+ content="grant.header.start_date"
37
+ key="2"
38
+ onClick={[Function]}
39
+ sorted={null}
40
+ />
41
+ <TableHeaderCell
42
+ as="th"
43
+ className=""
44
+ content="grant.header.end_date"
45
+ key="3"
46
+ onClick={[Function]}
47
+ sorted={null}
48
+ />
49
+ <TableHeaderCell
50
+ as="th"
51
+ className="disabled"
52
+ content="metadata"
53
+ key="4"
54
+ onClick={[Function]}
55
+ sorted={null}
56
+ />
57
+ </TableRow>
58
+ </TableHeader>
59
+ <TableBody
60
+ as="tbody"
61
+ >
62
+ <TableRow
63
+ as="tr"
64
+ cellAs="td"
65
+ key="0"
66
+ >
67
+ <TableCell
68
+ as="td"
69
+ content={
70
+ <userDecorator
71
+ user={
72
+ Object {
73
+ "email": "user1@example.com",
74
+ "full_name": "user_full_name_1",
75
+ "user_name": "user1",
76
+ }
77
+ }
78
+ />
79
+ }
80
+ key="0"
81
+ />
82
+ <TableCell
83
+ as="td"
84
+ content={
85
+ <GrantTableStructureDecorator
86
+ data_structure_version={
87
+ Object {
88
+ "data_structure_id": 22075,
89
+ "description": "DEscripción",
90
+ "domain": Object {
91
+ "external_id": "Demo Truedat",
92
+ "id": 3,
93
+ "name": "Demo Truedat",
94
+ "parent_ids": Array [],
95
+ "updated_at": "2020-07-21 07:45:41.068703Z",
96
+ },
97
+ "external_id": "sap:Clientes:KNA1",
98
+ "metadata": Object {},
99
+ "mutable_metadata": null,
100
+ "name": "KNA1",
101
+ }
102
+ }
103
+ />
104
+ }
105
+ key="1"
106
+ />
107
+ <TableCell
108
+ as="td"
109
+ content={
110
+ <StartDateDecorator
111
+ start_date="2020-05-17"
112
+ />
113
+ }
114
+ key="2"
115
+ />
116
+ <TableCell
117
+ as="td"
118
+ content={
119
+ <EndDateDecorator
120
+ end_date="2023-05-16"
121
+ />
122
+ }
123
+ key="3"
124
+ />
125
+ <TableCell
126
+ as="td"
127
+ content={
128
+ <GenericObjectDecorator
129
+ data_structure_version={
130
+ Object {
131
+ "metadata": Object {},
132
+ }
133
+ }
134
+ />
135
+ }
136
+ key="4"
137
+ />
138
+ </TableRow>
139
+ <TableRow
140
+ as="tr"
141
+ cellAs="td"
142
+ key="1"
143
+ >
144
+ <TableCell
145
+ as="td"
146
+ content={
147
+ <userDecorator
148
+ user={
149
+ Object {
150
+ "email": "user2@example.com",
151
+ "full_name": "user_full_name_2",
152
+ "user_name": "user2",
153
+ }
154
+ }
155
+ />
156
+ }
157
+ key="0"
158
+ />
159
+ <TableCell
160
+ as="td"
161
+ content={
162
+ <GrantTableStructureDecorator
163
+ data_structure_version={
164
+ Object {
165
+ "data_structure_id": 4570466,
166
+ "description": null,
167
+ "domain": Object {
168
+ "external_id": "Truedat",
169
+ "id": 2,
170
+ "name": "Truedat",
171
+ "parent_ids": Array [],
172
+ "updated_at": "2020-07-28 13:21:21.938189Z",
173
+ },
174
+ "external_id": "postgres://postgres/td_metrics/public/concepts",
175
+ "metadata": Object {
176
+ "alias": "Truedat-PostgreSQL",
177
+ "database": "td_metrics",
178
+ "host": "postgres",
179
+ "schema": "public",
180
+ "type": "BASE TABLE",
181
+ },
182
+ "mutable_metadata": null,
183
+ "name": "concepts",
184
+ }
185
+ }
186
+ />
187
+ }
188
+ key="1"
189
+ />
190
+ <TableCell
191
+ as="td"
192
+ content={
193
+ <StartDateDecorator
194
+ start_date="2011-05-17"
195
+ />
196
+ }
197
+ key="2"
198
+ />
199
+ <TableCell
200
+ as="td"
201
+ content={
202
+ <EndDateDecorator
203
+ end_date="2023-05-18"
204
+ />
205
+ }
206
+ key="3"
207
+ />
208
+ <TableCell
209
+ as="td"
210
+ content={
211
+ <GenericObjectDecorator
212
+ data_structure_version={
213
+ Object {
214
+ "metadata": Object {
215
+ "alias": "Truedat-PostgreSQL",
216
+ "database": "td_metrics",
217
+ "host": "postgres",
218
+ "schema": "public",
219
+ "type": "BASE TABLE",
220
+ },
221
+ }
222
+ }
223
+ />
224
+ }
225
+ key="4"
226
+ />
227
+ </TableRow>
228
+ </TableBody>
229
+ </Table>
230
+ </Fragment>
231
+ `;
@@ -1,5 +1,7 @@
1
1
  import DictionaryRoutes from "./DictionaryRoutes";
2
2
  import FilteredNav from "./FilteredNav";
3
+ import GrantSelectedFilters from "./GrantSelectedFilters";
4
+ import GrantsTable from "./GrantsTable";
3
5
  import LineageDefs from "./LineageDefs";
4
6
  import LineageDownloadButton from "./LineageDownloadButton";
5
7
  import LineageGroup from "./LineageGroup";
@@ -54,6 +56,8 @@ import ValueConditionStructure from "./ValueConditionStructure";
54
56
  export {
55
57
  DictionaryRoutes,
56
58
  FilteredNav,
59
+ GrantSelectedFilters,
60
+ GrantsTable,
57
61
  LineageDefs,
58
62
  LineageDownloadButton,
59
63
  LineageGroup,
@@ -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",
@@ -32,9 +34,17 @@ export default {
32
34
  "grant.cell.end_date.null": "No expiration set",
33
35
  "grant.cell.end_date.same_user": "It's you",
34
36
  "grant.header.user": "Account",
35
- "grant.header.data_structure": "Structure",
37
+ "grant.header.data_structure_version": "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.mine.header": "My grants",
43
+ "grants.mine.subheader": "Structures granted to me",
44
+ "grants.retrieved.results": "{count} grants found",
45
+ "grants.search.placeholder": "Search grants...",
46
+ "grants.search.results.empty": "No grants found",
47
+ "grants.subheader": "Granted access to structures",
38
48
  "filters.with_content.raw.true": "Extra Info",
39
49
  "graph.actions.download.popup": "Select a graph",
40
50
  "graph.actions.download.tooltip": "Download to csv",
@@ -375,5 +385,5 @@ export default {
375
385
  "updateSystem.error.df_content.invalid content": "Invalid template content",
376
386
  "structure.grant.has_grant": "You have granted access on this structure",
377
387
  "visualization.title.impact": "Impact Analysis",
378
- "visualization.title.lineage": "Lineage Analysis"
388
+ "visualization.title.lineage": "Lineage Analysis",
379
389
  };
@@ -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",
@@ -32,10 +34,18 @@ export default {
32
34
  "grant.cell.direct_access": "Acceso Directo",
33
35
  "grant.cell.end_date.null": "Sin fecha de expiración",
34
36
  "grant.cell.end_date.same_user": "Eres tú",
35
- "grant.header.data_structure": "Estructura",
37
+ "grant.header.data_structure_version": "Estructura",
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": "Accesos",
43
+ "grants.mine.header": "Mis accesos",
44
+ "grants.mine.subheader": "Estructuras a las que tengo acceso",
45
+ "grants.retrieved.results": "{count} grants encontrados",
46
+ "grants.search.placeholder": "Buscar accesos...",
47
+ "grants.search.results.empty": "Ningún grant encontrado",
48
+ "grants.subheader": "Accesos a estructuras",
39
49
  "filters.with_content.raw.true": "Contiene información extra",
40
50
  "graph.actions.download.popup": "Seleccione un grafo",
41
51
  "graph.actions.download.tooltip": "Descargar en csv",
@@ -382,5 +392,5 @@ export default {
382
392
  "Contenido de plantilla inválido",
383
393
  "structure.grant.has_grant": "Tienes acceso a la estructura",
384
394
  "visualization.title.impact": "Análisis de Impacto",
385
- "visualization.title.lineage": "Análisis de Linaje"
395
+ "visualization.title.lineage": "Análisis de Linaje",
386
396
  };
@@ -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,48 @@
1
+ import _ from "lodash/fp";
2
+ import {
3
+ addGrantFilter,
4
+ closeGrantFilter,
5
+ removeGrantFilter,
6
+ resetGrantFilters,
7
+ toggleGrantFilterValue,
8
+ clearGrantFilters,
9
+ } from "../routines";
10
+
11
+ export const initialState = {};
12
+
13
+ export const grantActiveFilters = (state = initialState, { type, payload }) => {
14
+ switch (type) {
15
+ case addGrantFilter.TRIGGER: {
16
+ const { filter } = payload;
17
+ return { ...state, [filter]: [] };
18
+ }
19
+ case closeGrantFilter.TRIGGER: {
20
+ const { filter } = payload;
21
+ const values = _.propOr([], filter)(state);
22
+ return _.isEmpty(values)
23
+ ? _.omit(filter)(state)
24
+ : { ...state, [filter]: values };
25
+ }
26
+ case removeGrantFilter.TRIGGER: {
27
+ const { filter } = payload;
28
+ return _.omit(filter)(state);
29
+ }
30
+ case clearGrantFilters.TRIGGER:
31
+ case resetGrantFilters.TRIGGER: {
32
+ return initialState;
33
+ }
34
+ case toggleGrantFilterValue.TRIGGER: {
35
+ const { filter, value } = payload;
36
+ if (_.isArray(value)) {
37
+ return { ...state, [filter]: value };
38
+ }
39
+ const values = _.propOr([], filter)(state);
40
+ const nextValues = _.includes(value)(values)
41
+ ? _.without([value])(values)
42
+ : _.union([value])(values);
43
+ return { ...state, [filter]: nextValues };
44
+ }
45
+ default:
46
+ return state;
47
+ }
48
+ };