@truedat/dd 5.5.2 → 5.6.1

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 (40) hide show
  1. package/package.json +6 -6
  2. package/src/components/GrantRemoval.js +6 -3
  3. package/src/components/GrantRequestCancel.js +4 -2
  4. package/src/components/GrantRoutes.js +27 -0
  5. package/src/components/StructureGrantCart.js +19 -12
  6. package/src/components/StructureGrantDropdown.js +25 -35
  7. package/src/components/StructureGrantListButton.js +85 -0
  8. package/src/components/StructureGrantRequestButton.js +1 -21
  9. package/src/components/StructureGrantSummaryButton.js +87 -0
  10. package/src/components/StructureRow.js +10 -6
  11. package/src/components/StructureSummary.js +4 -2
  12. package/src/components/StructuresGrantRequest.js +0 -0
  13. package/src/components/StructuresGrantRequestView.js +68 -0
  14. package/src/components/StructuresLoader.js +4 -2
  15. package/src/components/StructuresSearch.js +1 -0
  16. package/src/components/StructuresSearchResults.js +3 -0
  17. package/src/components/StructuresTable.js +37 -24
  18. package/src/components/StructuresView.js +9 -10
  19. package/src/components/__tests__/StructureGrantDropdown.spec.js +66 -29
  20. package/src/components/__tests__/StructureGrantListButton.spec.js +77 -0
  21. package/src/components/__tests__/{StructureGrantButton.spec.js → StructureGrantSummaryButton.spec.js} +9 -9
  22. package/src/components/__tests__/StructureRow.spec.js +10 -10
  23. package/src/components/__tests__/StructuresGrantRequestView.spec.js +83 -0
  24. package/src/components/__tests__/StructuresLoader.spec.js +1 -1
  25. package/src/components/__tests__/__snapshots__/GrantRoutes.spec.js.snap +4 -0
  26. package/src/components/__tests__/__snapshots__/StructureGrantListButton.spec.js.snap +159 -0
  27. package/src/components/__tests__/__snapshots__/{StructureGrantButton.spec.js.snap → StructureGrantSummaryButton.spec.js.snap} +5 -5
  28. package/src/components/__tests__/__snapshots__/StructureRow.spec.js.snap +4 -1
  29. package/src/components/__tests__/__snapshots__/StructuresGrantRequestView.spec.js.snap +310 -0
  30. package/src/components/__tests__/__snapshots__/StructuresLoader.spec.js.snap +3 -1
  31. package/src/components/__tests__/__snapshots__/StructuresTable.spec.js.snap +21 -12
  32. package/src/messages/en.js +4 -0
  33. package/src/messages/es.js +5 -0
  34. package/src/reducers/structureActiveFilters.js +10 -9
  35. package/src/reducers/structureSelectedFilter.js +1 -1
  36. package/src/reducers/structures.js +5 -0
  37. package/src/sagas/createGrantRequestStatus.js +12 -3
  38. package/src/sagas/requestGrantRemoval.js +13 -3
  39. package/src/selectors/structureColumnsSelector.js +16 -6
  40. package/src/components/StructureGrantButton.js +0 -43
@@ -1,3 +1,4 @@
1
+ import _ from "lodash/fp";
1
2
  import {
2
3
  includes,
3
4
  isArray,
@@ -7,6 +8,7 @@ import {
7
8
  propOr,
8
9
  union,
9
10
  without,
11
+ tap,
10
12
  } from "lodash/fp";
11
13
  import {
12
14
  addStructureFilter,
@@ -24,6 +26,13 @@ export const structureActiveFilters = (
24
26
  state = initialState,
25
27
  { type, payload }
26
28
  ) => {
29
+ const toggle = (state, filter, value) =>
30
+ _.flow(
31
+ () => state[filter] || [],
32
+ (currentValues) => _.xor(isArray(value) ? value : [value], currentValues),
33
+ (newValues) => ({ ...state, [filter]: newValues })
34
+ );
35
+
27
36
  switch (type) {
28
37
  case clearStructureFilters.TRIGGER:
29
38
  return initialState;
@@ -50,15 +59,7 @@ export const structureActiveFilters = (
50
59
  return initialState;
51
60
  }
52
61
  case toggleStructureFilterValue.TRIGGER: {
53
- const { filter, value } = payload;
54
- if (isArray(value)) {
55
- return { ...state, [filter]: value };
56
- }
57
- const values = propOr([], filter)(state);
58
- const nextValues = includes(value)(values)
59
- ? without([value])(values)
60
- : union([value])(values);
61
- return { ...state, [filter]: nextValues };
62
+ return toggle(state, payload.filter, payload.value)();
62
63
  }
63
64
  default:
64
65
  return state;
@@ -3,7 +3,7 @@ import {
3
3
  closeStructureFilter,
4
4
  openStructureFilter,
5
5
  removeStructureFilter,
6
- resetStructureFilters
6
+ resetStructureFilters,
7
7
  } from "../routines";
8
8
 
9
9
  /** @type {string} */
@@ -7,6 +7,7 @@ const pickFields = _.pick([
7
7
  "id",
8
8
  "domain_id",
9
9
  "name",
10
+ "grants",
10
11
  "group",
11
12
  "description",
12
13
  "path",
@@ -21,6 +22,10 @@ const pickFields = _.pick([
21
22
  "mutable_metadata",
22
23
  "note",
23
24
  "original_name",
25
+ "my_grants",
26
+ "my_grant_request",
27
+ "data_fields",
28
+ "user_permissions",
24
29
  ]);
25
30
 
26
31
  const structures = (state = initialState, { type, payload }) => {
@@ -1,17 +1,26 @@
1
1
  import { compile } from "path-to-regexp";
2
2
  import { call, put, takeLatest } from "redux-saga/effects";
3
3
  import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
4
- import { createGrantRequestStatus, fetchStructure } from "../routines";
4
+ import {
5
+ createGrantRequestStatus,
6
+ fetchStructure,
7
+ fetchStructures,
8
+ } from "../routines";
5
9
  import { API_GRANT_REQUEST_STATUS } from "../api";
6
10
 
7
11
  export function* createGrantRequestStatusSaga({ payload }) {
8
12
  try {
9
- const { grantRequestId, status, structureId } = payload;
13
+ const { grantRequestId, status, structureId, previousStructureQuery } =
14
+ payload;
10
15
  const url = compile(API_GRANT_REQUEST_STATUS)({ id: grantRequestId });
11
16
  yield put(createGrantRequestStatus.request({ status }));
12
17
  const { data } = yield call(apiJsonPost, url, { status }, JSON_OPTS);
13
18
  yield put(createGrantRequestStatus.success(data));
14
- yield put(fetchStructure.trigger({ id: structureId }));
19
+ yield put(
20
+ previousStructureQuery
21
+ ? fetchStructures.trigger(previousStructureQuery)
22
+ : fetchStructure.trigger({ id: structureId })
23
+ );
15
24
  } catch (error) {
16
25
  if (error.response) {
17
26
  const { status, data } = error.response;
@@ -1,18 +1,28 @@
1
1
  import { compile } from "path-to-regexp";
2
2
  import { call, put, takeLatest } from "redux-saga/effects";
3
3
  import { apiJsonPatch, JSON_OPTS } from "@truedat/core/services/api";
4
- import { requestGrantRemoval, fetchStructure } from "../routines";
4
+ import {
5
+ requestGrantRemoval,
6
+ fetchStructure,
7
+ fetchStructures,
8
+ } from "../routines";
5
9
  import { API_GRANT } from "../api";
6
10
 
7
11
  export function* requestGrantRemovalSaga({ payload }) {
8
12
  try {
9
- const { id, action, data_structure_id, version } = payload;
13
+ const { id, action, data_structure_id, version, previousStructureQuery } =
14
+ payload;
10
15
  const url = compile(API_GRANT)({ id });
11
16
  const requestData = { action };
12
17
  yield put(requestGrantRemoval.request());
13
18
  const { data } = yield call(apiJsonPatch, url, requestData, JSON_OPTS);
14
19
  yield put(requestGrantRemoval.success(data));
15
- yield put(fetchStructure.trigger({ id: data_structure_id, version }));
20
+
21
+ yield put(
22
+ previousStructureQuery
23
+ ? fetchStructures.trigger(previousStructureQuery)
24
+ : fetchStructure.trigger({ id: data_structure_id, version })
25
+ );
16
26
  } catch (error) {
17
27
  if (error.response) {
18
28
  const { status, data } = error.response;
@@ -80,9 +80,19 @@ const getStructureColumnNames = createSelector(
80
80
  (columns) => _.concat("structure_type")(_.map("name")(columns))
81
81
  );
82
82
 
83
- export const structureRowsSelector = createSelector(
84
- getStructures,
85
- getStructureColumnNames,
86
- (structures, columnNames) =>
87
- _.map(_.pick([...columnNames, "id", "domain_id", "note"]))(structures)
88
- );
83
+ export const structureRowsSelector = (state, props, extraColumns = []) =>
84
+ createSelector(
85
+ getStructures,
86
+ getStructureColumnNames,
87
+ (structures, columnNames) =>
88
+ _.map(
89
+ _.pick([
90
+ ...columnNames,
91
+ "id",
92
+ "domain_id",
93
+ "note",
94
+ "grants",
95
+ ...extraColumns,
96
+ ])
97
+ )(structures)
98
+ )(state, props);
@@ -1,43 +0,0 @@
1
- import _ from "lodash/fp";
2
- import React from "react";
3
- import PropTypes from "prop-types";
4
- import { useQuery } from "@apollo/client";
5
- import { connect } from "react-redux";
6
- import { Loading } from "@truedat/core/components";
7
- import { LATEST_GRANT_REQUEST_QUERY } from "../api/queries";
8
- import StructureGrantRequestButton from "./StructureGrantRequestButton";
9
- import StructureGrantDropdown from "./StructureGrantDropdown";
10
-
11
- export const StructureGrantButton = ({ structure }) => {
12
- const { grant, id } = structure;
13
-
14
- const { loading, error, data } = useQuery(LATEST_GRANT_REQUEST_QUERY, {
15
- fetchPolicy: "cache-and-network",
16
- variables: { id },
17
- });
18
- if (error) return null;
19
- if (loading) return <Loading />;
20
-
21
- const grantRequest = _.prop("latestGrantRequest")(data);
22
- const isActiveRequest = _.includes(_.prop("status.status")(grantRequest))([
23
- "pending",
24
- "approved",
25
- "processing",
26
- ]);
27
-
28
- return grant || isActiveRequest ? (
29
- <StructureGrantDropdown
30
- grantRequest={isActiveRequest ? grantRequest : null}
31
- />
32
- ) : (
33
- <StructureGrantRequestButton />
34
- );
35
- };
36
-
37
- StructureGrantButton.propTypes = {
38
- structure: PropTypes.object,
39
- };
40
-
41
- const mapStateToProps = ({ structure }) => ({ structure });
42
-
43
- export default connect(mapStateToProps)(StructureGrantButton);