@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.
Files changed (72) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +6 -6
  3. package/src/api.js +4 -0
  4. package/src/components/EditDomainForm.js +1 -0
  5. package/src/components/GrantDateFilter.js +30 -0
  6. package/src/components/GrantFilters.js +28 -0
  7. package/src/components/GrantFiltersLoader.js +24 -0
  8. package/src/components/GrantSelectedFilters.js +63 -0
  9. package/src/components/Grants.js +49 -0
  10. package/src/components/GrantsLabelResults.js +32 -0
  11. package/src/components/GrantsLoader.js +41 -0
  12. package/src/components/GrantsPagination.js +14 -0
  13. package/src/components/GrantsRoutes.js +33 -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__/GrantsRoutes.spec.js +19 -0
  25. package/src/components/__tests__/GrantsTable.spec.js +185 -0
  26. package/src/components/__tests__/StructureGrantRequestButton.spec.js +20 -9
  27. package/src/components/__tests__/StructureSummary.spec.js +1 -1
  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 +24 -0
  31. package/src/components/__tests__/__snapshots__/GrantsRoutes.spec.js.snap +8 -0
  32. package/src/components/__tests__/__snapshots__/GrantsTable.spec.js.snap +231 -0
  33. package/src/components/index.js +6 -0
  34. package/src/messages/en.js +9 -1
  35. package/src/messages/es.js +9 -1
  36. package/src/reducers/__tests__/grantDateFilter.spec.js +54 -0
  37. package/src/reducers/__tests__/grantFilters.spec.js +37 -0
  38. package/src/reducers/__tests__/grantQuery.spec.js +113 -0
  39. package/src/reducers/__tests__/grants.spec.js +102 -0
  40. package/src/reducers/grantActiveFilters.js +46 -0
  41. package/src/reducers/grantCount.js +20 -0
  42. package/src/reducers/grantDateFilter.js +31 -0
  43. package/src/reducers/grantFilters.js +19 -0
  44. package/src/reducers/grantLoading.js +16 -0
  45. package/src/reducers/grantQuery.js +62 -0
  46. package/src/reducers/grantSelectedFilter.js +34 -0
  47. package/src/reducers/grants.js +24 -0
  48. package/src/reducers/grantsFilters.js +19 -0
  49. package/src/reducers/grantsPageSize.js +15 -0
  50. package/src/reducers/index.js +18 -0
  51. package/src/reducers/structureDateFilter.js +2 -2
  52. package/src/reducers/structureQuery.js +2 -2
  53. package/src/routines.js +20 -0
  54. package/src/sagas/__tests__/fetchGrants.spec.js +74 -0
  55. package/src/sagas/fetchGrantFilters.js +29 -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 +82 -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,185 @@
1
+ import _ from "lodash/fp";
2
+ import React from "react";
3
+ import { shallow } from "enzyme";
4
+ import { intl } from "@truedat/test/intl-stub";
5
+ import { GrantsTable } from "../GrantsTable";
6
+ import {
7
+ userDecorator,
8
+ GrantTableStructureDecorator,
9
+ StartDateDecorator,
10
+ EndDateDecorator,
11
+ GenericObjectDecorator,
12
+ } from "../../selectors/getGrantsColumns";
13
+
14
+ // workaround for enzyme issue with React.useContext
15
+ // see https://github.com/airbnb/enzyme/issues/2176#issuecomment-532361526
16
+ jest.spyOn(React, "useContext").mockImplementation(() => intl);
17
+
18
+ describe("<GrantsTable />", () => {
19
+ const defaultGrantsTableColumns = [
20
+ {
21
+ name: "user",
22
+ sort: { name: "user.user_name.raw" },
23
+ fieldSelector: _.pick(["user"]),
24
+ fieldDecorator: userDecorator,
25
+ },
26
+ {
27
+ name: "data_structure_version",
28
+ sort: { name: "data_structure_version.name.raw" },
29
+ fieldSelector: _.pick(["data_structure", "data_structure_version"]),
30
+ fieldDecorator: GrantTableStructureDecorator,
31
+ },
32
+ {
33
+ name: "start_date",
34
+ sort: { name: "start_date" },
35
+ fieldSelector: _.pick(["start_date"]),
36
+ fieldDecorator: StartDateDecorator,
37
+ },
38
+ {
39
+ name: "end_date",
40
+ sort: { name: "end_date" },
41
+ fieldSelector: _.pick(["end_date"]),
42
+ fieldDecorator: EndDateDecorator,
43
+ },
44
+ {
45
+ name: "metadata",
46
+ fieldSelector: _.pick(["data_structure_version.metadata"]),
47
+ fieldDecorator: GenericObjectDecorator,
48
+ },
49
+ ];
50
+
51
+ const grants = [
52
+ {
53
+ data_structure_version: {
54
+ data_structure_id: 22075,
55
+ description: "DEscripción",
56
+ domain: {
57
+ external_id: "Demo Truedat",
58
+ id: 3,
59
+ name: "Demo Truedat",
60
+ parent_ids: [],
61
+ updated_at: "2020-07-21 07:45:41.068703Z",
62
+ },
63
+ external_id: "sap:Clientes:KNA1",
64
+ metadata: {},
65
+ mutable_metadata: null,
66
+ name: "KNA1",
67
+ },
68
+ detail: {},
69
+ end_date: "2023-05-16",
70
+ id: 6,
71
+ start_date: "2020-05-17",
72
+ user: {
73
+ email: "user1@example.com",
74
+ full_name: "user_full_name_1",
75
+ user_name: "user1",
76
+ },
77
+ user_id: 23,
78
+ },
79
+ {
80
+ data_structure_version: {
81
+ data_structure_id: 4570466,
82
+ description: null,
83
+ domain: {
84
+ external_id: "Truedat",
85
+ id: 2,
86
+ name: "Truedat",
87
+ parent_ids: [],
88
+ updated_at: "2020-07-28 13:21:21.938189Z",
89
+ },
90
+ external_id: "postgres://postgres/td_metrics/public/concepts",
91
+ metadata: {
92
+ alias: "Truedat-PostgreSQL",
93
+ database: "td_metrics",
94
+ host: "postgres",
95
+ schema: "public",
96
+ type: "BASE TABLE",
97
+ },
98
+ mutable_metadata: null,
99
+ name: "concepts",
100
+ },
101
+ detail: {
102
+ access_type: "admin",
103
+ },
104
+ end_date: "2023-05-18",
105
+ id: 8,
106
+ start_date: "2011-05-17",
107
+ user: {
108
+ email: "user2@example.com",
109
+ full_name: "user_full_name_2",
110
+ user_name: "user2",
111
+ },
112
+ user_id: 171,
113
+ },
114
+ ];
115
+
116
+ const grantsSorting = [{ "data_structure_version.name.raw": "asc" }];
117
+ const sortGrants = jest.fn();
118
+ const grantsLoading = false;
119
+ const props = {
120
+ grants,
121
+ columns: defaultGrantsTableColumns,
122
+ grantsLoading,
123
+ sortGrants,
124
+ grantsSorting,
125
+ };
126
+
127
+ it("matches the latest snapshot", () => {
128
+ const wrapper = shallow(<GrantsTable {...props} />);
129
+ expect(wrapper).toMatchSnapshot();
130
+ });
131
+
132
+ it("sorts column in the direction specified", () => {
133
+ const wrapper = shallow(<GrantsTable {...props} />);
134
+
135
+ const tableHeaderCells = wrapper
136
+ .find("TableHeader")
137
+ .find("TableRow")
138
+ .dive()
139
+ .find("TableHeaderCell");
140
+
141
+ expect(tableHeaderCells.at(0).props().sorted).toEqual(null);
142
+ expect(tableHeaderCells.at(1).props().sorted).toEqual("ascending");
143
+ expect(tableHeaderCells.at(2).props().sorted).toEqual(null);
144
+ expect(tableHeaderCells.at(3).props().sorted).toEqual(null);
145
+ });
146
+
147
+ it("handles sort when column header is clicked", () => {
148
+ const wrapper = shallow(<GrantsTable {...props} />);
149
+
150
+ wrapper
151
+ .find("TableHeader")
152
+ .find("TableRow")
153
+ .dive()
154
+ .find("TableHeaderCell")
155
+ .at(0)
156
+ .simulate("click");
157
+
158
+ expect(
159
+ wrapper
160
+ .find("TableHeader")
161
+ .find("TableRow")
162
+ .dive()
163
+ .find("TableHeaderCell")
164
+ .at(0)
165
+ .props().sorted
166
+ ).toEqual("ascending");
167
+
168
+ wrapper
169
+ .find("TableHeader")
170
+ .find("TableRow")
171
+ .dive()
172
+ .find("TableHeaderCell")
173
+ .at(0)
174
+ .simulate("click");
175
+ expect(
176
+ wrapper
177
+ .find("TableHeader")
178
+ .find("TableRow")
179
+ .dive()
180
+ .find("TableHeaderCell")
181
+ .at(0)
182
+ .props().sorted
183
+ ).toEqual("descending");
184
+ });
185
+ });
@@ -8,17 +8,19 @@ import { StructureGrantRequestButton } from "../StructureGrantRequestButton";
8
8
  import messages from "../../messages/en";
9
9
 
10
10
  const renderOpts = {
11
- messages: { en: messages }
11
+ messages: { en: messages },
12
12
  };
13
13
 
14
14
  describe("<StructureGrantRequestButton />", () => {
15
-
16
15
  it("render a button", async () => {
17
16
  const props = {
18
17
  requested: false,
19
18
  authorized: true,
20
19
  };
21
- const { getByText } = render(<StructureGrantRequestButton {...props} />, renderOpts);
20
+ const { getByText } = render(
21
+ <StructureGrantRequestButton {...props} />,
22
+ renderOpts
23
+ );
22
24
  expect(getByText("Request grant")).toMatchSnapshot();
23
25
  });
24
26
 
@@ -31,13 +33,16 @@ describe("<StructureGrantRequestButton />", () => {
31
33
  removeGrantRequestFromCart: removeRequest,
32
34
  authorized: true,
33
35
  };
34
- const { findByText } = render(<StructureGrantRequestButton {...props} />, renderOpts);
36
+ const { findByText } = render(
37
+ <StructureGrantRequestButton {...props} />,
38
+ renderOpts
39
+ );
35
40
  userEvent.click(await findByText("Request grant"));
36
41
  await waitFor(() => {
37
42
  expect(addRequest.mock.calls.length).toBe(1);
38
43
  expect(removeRequest.mock.calls.length).toBe(0);
39
44
  });
40
- })
45
+ });
41
46
 
42
47
  it("can be clickable", async () => {
43
48
  const addRequest = jest.fn();
@@ -48,13 +53,16 @@ describe("<StructureGrantRequestButton />", () => {
48
53
  removeGrantRequestFromCart: removeRequest,
49
54
  authorized: true,
50
55
  };
51
- const { findByText } = render(<StructureGrantRequestButton {...props} />, renderOpts);
56
+ const { findByText } = render(
57
+ <StructureGrantRequestButton {...props} />,
58
+ renderOpts
59
+ );
52
60
  userEvent.click(await findByText("Pending request"));
53
61
  await waitFor(() => {
54
62
  expect(addRequest.mock.calls.length).toBe(0);
55
63
  expect(removeRequest.mock.calls.length).toBe(1);
56
64
  });
57
- })
65
+ });
58
66
 
59
67
  it("renders nothing if does not have permissions", async () => {
60
68
  const addRequest = jest.fn();
@@ -65,10 +73,13 @@ describe("<StructureGrantRequestButton />", () => {
65
73
  removeGrantRequestFromCart: removeRequest,
66
74
  authorized: false,
67
75
  };
68
- const component = render(<StructureGrantRequestButton {...props} />, renderOpts);
76
+ const component = render(
77
+ <StructureGrantRequestButton {...props} />,
78
+ renderOpts
79
+ );
69
80
  const { queryAllByText } = component;
70
81
  expect(queryAllByText("Request grant")).toHaveLength(0);
71
82
  expect(queryAllByText("Pending request")).toHaveLength(0);
72
83
  expect(component).toMatchSnapshot();
73
- })
84
+ });
74
85
  });
@@ -22,7 +22,7 @@ describe("<StructureSummary />", () => {
22
22
  userPermissions: {
23
23
  update: true,
24
24
  confidential: true,
25
- request_grant: true
25
+ request_grant: true,
26
26
  },
27
27
  class: "table",
28
28
  type: "foo",
@@ -0,0 +1,16 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<GrantDateFilter/> matches the latest snapshot 1`] = `
4
+ <Fragment>
5
+ <DateRangeFilter
6
+ defaultValues={Object {}}
7
+ label={
8
+ <FormattedMessage
9
+ id="grant.start_date"
10
+ values={Object {}}
11
+ />
12
+ }
13
+ name="start_date,end_date"
14
+ />
15
+ </Fragment>
16
+ `;
@@ -0,0 +1,16 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<GrantsLabelResults /> matches the latest snapshot 1`] = `
4
+ <Label
5
+ className="grants-label-results"
6
+ >
7
+ <FormattedMessage
8
+ id="grants.retrieved.results"
9
+ values={
10
+ Object {
11
+ "count": 22,
12
+ }
13
+ }
14
+ />
15
+ </Label>
16
+ `;
@@ -0,0 +1,24 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<GrantsLoader /> matches the latest snapshot 1`] = `
4
+ <GrantsLoader
5
+ clearGrants={[MockFunction]}
6
+ fetchGrants={
7
+ [MockFunction] {
8
+ "calls": Array [
9
+ Array [
10
+ Object {},
11
+ ],
12
+ ],
13
+ "results": Array [
14
+ Object {
15
+ "type": "return",
16
+ "value": undefined,
17
+ },
18
+ ],
19
+ }
20
+ }
21
+ grantsLoading={false}
22
+ payload={Object {}}
23
+ />
24
+ `;
@@ -0,0 +1,8 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<GrantsRoutes /> matches the latest snapshot 1`] = `
4
+ <Route
5
+ path="/grants"
6
+ render={[Function]}
7
+ />
8
+ `;
@@ -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="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
+ `;