@truedat/dd 7.11.1 → 7.11.3

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 (51) hide show
  1. package/package.json +3 -3
  2. package/src/api/queries.js +278 -8
  3. package/src/components/ImplementationStructuresLoader.js +6 -6
  4. package/src/components/StructureGrants.js +50 -7
  5. package/src/components/StructureSelectorInputField.js +7 -5
  6. package/src/components/StructureVersions.js +15 -2
  7. package/src/components/__tests__/ImplementationStructuresLoader.spec.js +5 -5
  8. package/src/components/__tests__/ProfileExecutionLoader.spec.js +1 -1
  9. package/src/components/__tests__/ProfileGroupLoader.spec.js +1 -1
  10. package/src/components/__tests__/StructureGrants.spec.js +26 -0
  11. package/src/components/__tests__/StructureVersions.spec.js +26 -0
  12. package/src/reducers/__tests__/graph.spec.js +3 -3
  13. package/src/reducers/__tests__/graphLoading.spec.js +3 -3
  14. package/src/reducers/__tests__/graphRedirect.spec.js +3 -3
  15. package/src/reducers/__tests__/structureFields.spec.js +7 -7
  16. package/src/reducers/__tests__/structureImpactGraph.spec.js +3 -3
  17. package/src/reducers/__tests__/structureImpactId.spec.js +3 -3
  18. package/src/reducers/__tests__/structureLineageGraph.spec.js +3 -3
  19. package/src/reducers/__tests__/structureLineageId.spec.js +3 -3
  20. package/src/reducers/__tests__/structureLinks.spec.js +5 -5
  21. package/src/reducers/__tests__/structureRedirect.spec.js +1 -1
  22. package/src/reducers/__tests__/structureRelations.spec.js +3 -3
  23. package/src/reducers/__tests__/structureSystem.spec.js +3 -3
  24. package/src/reducers/__tests__/structureVersions.spec.js +3 -3
  25. package/src/reducers/graph.js +2 -2
  26. package/src/reducers/graphLoading.js +2 -2
  27. package/src/reducers/graphRedirect.js +2 -2
  28. package/src/reducers/structure.js +3 -1
  29. package/src/reducers/structureFields.js +4 -4
  30. package/src/reducers/structureImpactGraph.js +2 -2
  31. package/src/reducers/structureImpactId.js +2 -2
  32. package/src/reducers/structureLineageGraph.js +2 -2
  33. package/src/reducers/structureLineageId.js +2 -2
  34. package/src/reducers/structureLinks.js +3 -3
  35. package/src/reducers/structureRelations.js +4 -4
  36. package/src/reducers/structureSiblings.js +7 -1
  37. package/src/reducers/structureSystem.js +2 -2
  38. package/src/reducers/structureVersions.js +3 -3
  39. package/src/routines.js +4 -0
  40. package/src/sagas/__tests__/legacyFetchStructure.spec.js +148 -0
  41. package/src/sagas/__tests__/requestGrantRemoval.spec.js +132 -0
  42. package/src/sagas/createGrantRequestStatus.js +1 -0
  43. package/src/sagas/fetchStructureChildrens.js +48 -0
  44. package/src/sagas/fetchStructureParents.js +48 -0
  45. package/src/sagas/fetchStructureVersions.js +46 -0
  46. package/src/sagas/index.js +3 -0
  47. package/src/sagas/legacyFetchStructure.js +55 -0
  48. package/src/sagas/requestGrantRemoval.js +2 -2
  49. package/src/selectors/__tests__/getTabVisibility.spec.js +6 -6
  50. package/src/selectors/getStructuresFields.js +3 -2
  51. package/src/selectors/getTabVisibility.js +8 -5
@@ -0,0 +1,148 @@
1
+ import { testSaga } from "redux-saga-test-plan";
2
+ import {
3
+ legacyFetchStructureRequestSaga,
4
+ legacyFetchStructureSaga,
5
+ } from "../legacyFetchStructure";
6
+
7
+ import { legacyFetchStructure } from "../../routines";
8
+ import { LEGACY_DATA_STRUCTURE_VERSION_QUERY } from "../../api/queries";
9
+ import { getStructureFieldColumns } from "../../selectors";
10
+
11
+ describe("sagas: fetchStructureRequestSaga", () => {
12
+ it("should invoke fetchStructureSaga on trigger", () => {
13
+ expect(() => {
14
+ testSaga(legacyFetchStructureRequestSaga)
15
+ .next()
16
+ .takeLatest(legacyFetchStructure.TRIGGER, legacyFetchStructureSaga)
17
+ .finish()
18
+ .isDone();
19
+ }).not.toThrow();
20
+ });
21
+
22
+ it("should throw exception if an unhandled action is received", () => {
23
+ expect(() => {
24
+ testSaga(legacyFetchStructureRequestSaga)
25
+ .next()
26
+ .takeLatest("FOO", legacyFetchStructureSaga);
27
+ }).toThrow();
28
+ });
29
+ });
30
+
31
+ describe("sagas: legacyFetchStructureSaga", () => {
32
+ const client = { query: jest.fn() };
33
+ const id = 1;
34
+ const version = "latest";
35
+ const payload = { id };
36
+ const variables = {
37
+ dataStructureId: id,
38
+ version,
39
+ note_fields: ["note_field"],
40
+ };
41
+
42
+ const structureFieldColumns = [{ name: "id" }, { name: "note.note_field" }];
43
+
44
+ const _actions = { test: true };
45
+ const user_permissions = { permission1: true };
46
+
47
+ const dataStructureVersion = {
48
+ id,
49
+ name: "Structure 1",
50
+ description: "desc1",
51
+ _actions,
52
+ user_permissions,
53
+ };
54
+
55
+ const data = {
56
+ data: dataStructureVersion,
57
+ _actions,
58
+ user_permissions,
59
+ };
60
+
61
+ it("should put a success action when a response is returned", () => {
62
+ const meta = { version };
63
+
64
+ expect(() => {
65
+ testSaga(legacyFetchStructureSaga, { payload })
66
+ .next()
67
+ .select(getStructureFieldColumns)
68
+ .next(structureFieldColumns)
69
+ .getContext("client")
70
+ .next(client)
71
+ .put(legacyFetchStructure.request())
72
+ .next()
73
+
74
+ .call(client.query, {
75
+ fetchPolicy: "network-only",
76
+ query: LEGACY_DATA_STRUCTURE_VERSION_QUERY,
77
+ variables,
78
+ })
79
+ .next({ data: { dataStructureVersion } })
80
+ .put({ meta, ...legacyFetchStructure.success(data) })
81
+ .next()
82
+ .put(legacyFetchStructure.fulfill())
83
+ .next()
84
+ .isDone();
85
+ }).not.toThrow();
86
+ });
87
+
88
+ it("should put a success action when a response is returned - with version", () => {
89
+ const version = 23;
90
+ const payload = { id, version };
91
+ const meta = { version };
92
+
93
+ const variables = {
94
+ dataStructureId: id,
95
+ version,
96
+ note_fields: ["note_field"],
97
+ };
98
+
99
+ expect(() => {
100
+ testSaga(legacyFetchStructureSaga, { payload })
101
+ .next()
102
+ .select(getStructureFieldColumns)
103
+ .next(structureFieldColumns)
104
+ .getContext("client")
105
+ .next(client)
106
+ .put(legacyFetchStructure.request())
107
+ .next()
108
+ .call(client.query, {
109
+ fetchPolicy: "network-only",
110
+ query: LEGACY_DATA_STRUCTURE_VERSION_QUERY,
111
+ variables,
112
+ })
113
+ .next({ data: { dataStructureVersion } })
114
+ .put({ meta, ...legacyFetchStructure.success(data) })
115
+ .next()
116
+ .put(legacyFetchStructure.fulfill())
117
+ .next()
118
+ .isDone();
119
+ }).not.toThrow();
120
+ });
121
+
122
+ it("should put a failure action when the call returns an error", () => {
123
+ const message = "Request failed";
124
+ const error = { message };
125
+
126
+ expect(() => {
127
+ testSaga(legacyFetchStructureSaga, { payload })
128
+ .next()
129
+ .select(getStructureFieldColumns)
130
+ .next(structureFieldColumns)
131
+ .getContext("client")
132
+ .next(client)
133
+ .put(legacyFetchStructure.request())
134
+ .next()
135
+ .call(client.query, {
136
+ fetchPolicy: "network-only",
137
+ query: LEGACY_DATA_STRUCTURE_VERSION_QUERY,
138
+ variables,
139
+ })
140
+ .throw(error)
141
+ .put(legacyFetchStructure.failure(message))
142
+ .next()
143
+ .put(legacyFetchStructure.fulfill())
144
+ .next()
145
+ .isDone();
146
+ }).not.toThrow();
147
+ });
148
+ });
@@ -0,0 +1,132 @@
1
+ import { testSaga } from "redux-saga-test-plan";
2
+ import { compile } from "path-to-regexp";
3
+ import {
4
+ requestGrantRemovalSaga,
5
+ requestGrantRemovalRequestSaga,
6
+ } from "../requestGrantRemoval";
7
+ import {
8
+ requestGrantRemoval,
9
+ legacyFetchStructure,
10
+ fetchStructures,
11
+ } from "../../routines";
12
+ import { API_GRANT } from "../../api";
13
+ import { apiJsonPatch, JSON_OPTS } from "@truedat/core/services/api";
14
+
15
+ describe("sagas: requestGrantRemovalRequestSaga", () => {
16
+ it("should invoke requestGrantRemovalSaga on requestGrantRemoval.TRIGGER", () => {
17
+ expect(() => {
18
+ testSaga(requestGrantRemovalRequestSaga)
19
+ .next()
20
+ .takeLatest(requestGrantRemoval.TRIGGER, requestGrantRemovalSaga)
21
+ .finish()
22
+ .isDone();
23
+ }).not.toThrow();
24
+ });
25
+
26
+ it("should throw exception if an unhandled action is received", () => {
27
+ expect(() => {
28
+ testSaga(requestGrantRemovalRequestSaga)
29
+ .next()
30
+ .takeLatest("FOO", requestGrantRemovalSaga);
31
+ }).toThrow();
32
+ });
33
+ });
34
+
35
+ describe("sagas: requestGrantRemovalSaga", () => {
36
+ const id = "1";
37
+ const action = "REMOVE";
38
+ const data_structure_id = 2;
39
+ const version = "v3";
40
+ const previousStructureQuery = { foo: "bar" };
41
+ const payloadWithPrevQuery = {
42
+ id,
43
+ action,
44
+ data_structure_id,
45
+ version,
46
+ previousStructureQuery,
47
+ };
48
+ const payloadWithoutPrevQuery = {
49
+ id,
50
+ action,
51
+ data_structure_id,
52
+ version,
53
+ previousStructureQuery: undefined,
54
+ };
55
+ const requestData = { action };
56
+ const url = compile(API_GRANT)({ id: `${id}` });
57
+
58
+ it("should put a success action and fetchStructures.trigger when previousStructureQuery is provided", () => {
59
+ expect(() => {
60
+ testSaga(requestGrantRemovalSaga, { payload: payloadWithPrevQuery })
61
+ .next()
62
+ .put(requestGrantRemoval.request())
63
+ .next()
64
+ .call(apiJsonPatch, url, requestData, JSON_OPTS)
65
+ .next({ data: "result" })
66
+ .put(requestGrantRemoval.success("result"))
67
+ .next()
68
+ .put(fetchStructures.trigger(previousStructureQuery))
69
+ .next()
70
+ .put(requestGrantRemoval.fulfill())
71
+ .next()
72
+ .isDone();
73
+ }).not.toThrow();
74
+ });
75
+
76
+ it("should put a success action and legacyFetchStructure.trigger when previousStructureQuery is not provided", () => {
77
+ expect(() => {
78
+ testSaga(requestGrantRemovalSaga, { payload: payloadWithoutPrevQuery })
79
+ .next()
80
+ .put(requestGrantRemoval.request())
81
+ .next()
82
+ .call(apiJsonPatch, url, requestData, JSON_OPTS)
83
+ .next({ data: "result" })
84
+ .put(requestGrantRemoval.success("result"))
85
+ .next()
86
+ .put(
87
+ legacyFetchStructure.trigger({
88
+ id: data_structure_id,
89
+ version,
90
+ })
91
+ )
92
+ .next()
93
+ .put(requestGrantRemoval.fulfill())
94
+ .next()
95
+ .isDone();
96
+ }).not.toThrow();
97
+ });
98
+
99
+ it("should put a failure action with response when error.response exists", () => {
100
+ const error = { response: { status: 403, data: { err: "bad" } } };
101
+ expect(() => {
102
+ testSaga(requestGrantRemovalSaga, { payload: payloadWithPrevQuery })
103
+ .next()
104
+ .put(requestGrantRemoval.request())
105
+ .next()
106
+ .call(apiJsonPatch, url, requestData, JSON_OPTS)
107
+ .throw(error)
108
+ .put(requestGrantRemoval.failure({ status: 403, data: { err: "bad" } }))
109
+ .next()
110
+ .put(requestGrantRemoval.fulfill())
111
+ .next()
112
+ .isDone();
113
+ }).not.toThrow();
114
+ });
115
+
116
+ it("should put a failure action with error.message when error.response does not exist", () => {
117
+ const error = { message: "Some other error" };
118
+ expect(() => {
119
+ testSaga(requestGrantRemovalSaga, { payload: payloadWithoutPrevQuery })
120
+ .next()
121
+ .put(requestGrantRemoval.request())
122
+ .next()
123
+ .call(apiJsonPatch, url, requestData, JSON_OPTS)
124
+ .throw(error)
125
+ .put(requestGrantRemoval.failure("Some other error"))
126
+ .next()
127
+ .put(requestGrantRemoval.fulfill())
128
+ .next()
129
+ .isDone();
130
+ }).not.toThrow();
131
+ });
132
+ });
@@ -17,6 +17,7 @@ export function* createGrantRequestStatusSaga({ payload }) {
17
17
  structureId,
18
18
  previousStructureQuery,
19
19
  } = payload;
20
+
20
21
  const url = compile(API_GRANT_REQUEST_STATUS)({
21
22
  id: `${grantRequest.id}`,
22
23
  });
@@ -0,0 +1,48 @@
1
+ import _ from "lodash/fp";
2
+ import { call, put, takeLatest, select, getContext } from "redux-saga/effects";
3
+ import { fetchStructureChildrens } from "../routines";
4
+ import { DATA_STRUCTURE_CHILDREN_QUERY } from "../api/queries";
5
+ import { getStructureFieldColumns } from "../selectors";
6
+
7
+ export function* fetchStructureChildrenSaga({ payload }) {
8
+ try {
9
+ const client = yield getContext("client");
10
+
11
+ yield put(fetchStructureChildrens.request());
12
+
13
+ const { id, version = "latest" } = payload;
14
+ const {
15
+ data: { dataStructureVersion },
16
+ } = yield call(client.query, {
17
+ fetchPolicy: "network-only",
18
+ query: DATA_STRUCTURE_CHILDREN_QUERY,
19
+ variables: {
20
+ dataStructureId: id,
21
+ version,
22
+ },
23
+ });
24
+
25
+ const data = {
26
+ data: dataStructureVersion,
27
+ _actions: dataStructureVersion._actions,
28
+ user_permissions: dataStructureVersion.user_permissions,
29
+ };
30
+
31
+ const meta = { version };
32
+
33
+ yield put({ meta, ...fetchStructureChildrens.success(data) });
34
+ } catch (error) {
35
+ if (error.response) {
36
+ const { status, data } = error.response;
37
+ yield put(fetchStructureChildrens.failure({ status, data }));
38
+ } else {
39
+ yield put(fetchStructureChildrens.failure(error.message));
40
+ }
41
+ } finally {
42
+ yield put(fetchStructureChildrens.fulfill());
43
+ }
44
+ }
45
+
46
+ export function* fetchStructureChildrensRequestSaga() {
47
+ yield takeLatest(fetchStructureChildrens.TRIGGER, fetchStructureChildrensSaga);
48
+ }
@@ -0,0 +1,48 @@
1
+ import _ from "lodash/fp";
2
+ import { call, put, takeLatest, select, getContext } from "redux-saga/effects";
3
+ import { fetchStructureParents } from "../routines";
4
+ import { DATA_STRUCTURE_PARENTS_QUERY } from "../api/queries";
5
+ import { getStructureFieldColumns } from "../selectors";
6
+
7
+ export function* fetchStructureParentsSaga({ payload }) {
8
+ try {
9
+ const client = yield getContext("client");
10
+
11
+ yield put(fetchStructureParents.request());
12
+
13
+ const { id, version = "latest" } = payload;
14
+ const {
15
+ data: { dataStructureVersion },
16
+ } = yield call(client.query, {
17
+ fetchPolicy: "network-only",
18
+ query: DATA_STRUCTURE_PARENTS_QUERY,
19
+ variables: {
20
+ dataStructureId: id,
21
+ version,
22
+ },
23
+ });
24
+
25
+ const data = {
26
+ data: dataStructureVersion,
27
+ _actions: dataStructureVersion._actions,
28
+ user_permissions: dataStructureVersion.user_permissions,
29
+ };
30
+
31
+ const meta = { version };
32
+
33
+ yield put({ meta, ...fetchStructureParents.success(data) });
34
+ } catch (error) {
35
+ if (error.response) {
36
+ const { status, data } = error.response;
37
+ yield put(fetchStructureParents.failure({ status, data }));
38
+ } else {
39
+ yield put(fetchStructureParents.failure(error.message));
40
+ }
41
+ } finally {
42
+ yield put(fetchStructureParents.fulfill());
43
+ }
44
+ }
45
+
46
+ export function* fetchStructureParentsRequestSaga() {
47
+ yield takeLatest(fetchStructureParents.TRIGGER, fetchStructureParentsSaga);
48
+ }
@@ -0,0 +1,46 @@
1
+ import { call, put, takeLatest, getContext } from "redux-saga/effects";
2
+ import { fetchStructureVersions } from "../routines";
3
+ import { DATA_STRUCTURE_VERSION_VERSIONS_QUERY } from "../api/queries";
4
+
5
+ export function* fetchStructureVersionsSaga({ payload }) {
6
+ try {
7
+ const client = yield getContext("client");
8
+
9
+ yield put(fetchStructureVersions.request());
10
+
11
+ const { id, version = "latest" } = payload;
12
+ const {
13
+ data: { dataStructureVersion },
14
+ } = yield call(client.query, {
15
+ fetchPolicy: "network-only",
16
+ query: DATA_STRUCTURE_VERSION_VERSIONS_QUERY,
17
+ variables: {
18
+ dataStructureId: id,
19
+ version,
20
+ },
21
+ });
22
+
23
+ const data = {
24
+ data: dataStructureVersion,
25
+ _actions: dataStructureVersion._actions,
26
+ user_permissions: dataStructureVersion.user_permissions,
27
+ };
28
+
29
+ const meta = { version };
30
+
31
+ yield put({ meta, ...fetchStructureVersions.success(data) });
32
+ } catch (error) {
33
+ if (error.response) {
34
+ const { status, data } = error.response;
35
+ yield put(fetchStructureVersions.failure({ status, data }));
36
+ } else {
37
+ yield put(fetchStructureVersions.failure(error.message));
38
+ }
39
+ } finally {
40
+ yield put(fetchStructureVersions.fulfill());
41
+ }
42
+ }
43
+
44
+ export function* fetchStructureVersionsRequestSaga() {
45
+ yield takeLatest(fetchStructureVersions.TRIGGER, fetchStructureVersionsSaga);
46
+ }
@@ -32,6 +32,7 @@ import { fetchProfileGroupRequestSaga } from "./fetchProfileGroup";
32
32
  import { fetchStructureGraphRequestSaga } from "./fetchStructureGraph";
33
33
  import { fetchStructureNotesRequestSaga } from "./fetchStructureNotes";
34
34
  import { fetchStructureRequestSaga } from "./fetchStructure";
35
+ import { legacyFetchStructureRequestSaga } from "./legacyFetchStructure";
35
36
  import { fetchStructureTypeRequestSaga } from "./fetchStructureType";
36
37
  import { fetchStructureTypesRequestSaga } from "./fetchStructureTypes";
37
38
  import { fetchStructuresRequestSaga } from "./fetchStructures";
@@ -96,6 +97,7 @@ export {
96
97
  fetchSystemStructuresRequestSaga,
97
98
  fetchUserSearchFiltersRequestSaga,
98
99
  linkStructureToStructureRequestSaga,
100
+ legacyFetchStructureRequestSaga,
99
101
  tagStructureRequestSaga,
100
102
  operateGrantRequestToCartRequestSaga,
101
103
  requestGrantRemovalRequestSaga,
@@ -153,6 +155,7 @@ export default [
153
155
  fetchSystemStructuresRequestSaga(),
154
156
  fetchUserSearchFiltersRequestSaga(),
155
157
  linkStructureToStructureRequestSaga(),
158
+ legacyFetchStructureRequestSaga(),
156
159
  tagStructureRequestSaga(),
157
160
  operateGrantRequestToCartRequestSaga(),
158
161
  requestGrantRemovalRequestSaga(),
@@ -0,0 +1,55 @@
1
+ import _ from "lodash/fp";
2
+ import { call, put, takeLatest, select, getContext } from "redux-saga/effects";
3
+ import { legacyFetchStructure } from "../routines";
4
+ import { LEGACY_DATA_STRUCTURE_VERSION_QUERY } from "../api/queries";
5
+ import { getStructureFieldColumns } from "../selectors";
6
+
7
+ export function* legacyFetchStructureSaga({ payload }) {
8
+ try {
9
+ const structureFieldColumns = yield select(getStructureFieldColumns);
10
+ const note_fields = _.flow(
11
+ _.filter(({ name }) => name.startsWith("note.")),
12
+ _.map(({ name }) => name.split(".")[1])
13
+ )(structureFieldColumns);
14
+
15
+ const client = yield getContext("client");
16
+
17
+ yield put(legacyFetchStructure.request());
18
+
19
+ const { id, version = "latest" } = payload;
20
+ const {
21
+ data: { dataStructureVersion },
22
+ } = yield call(client.query, {
23
+ fetchPolicy: "network-only",
24
+ query: LEGACY_DATA_STRUCTURE_VERSION_QUERY,
25
+ variables: {
26
+ dataStructureId: id,
27
+ version,
28
+ note_fields,
29
+ },
30
+ });
31
+
32
+ const data = {
33
+ data: dataStructureVersion,
34
+ _actions: dataStructureVersion._actions,
35
+ user_permissions: dataStructureVersion.user_permissions,
36
+ };
37
+
38
+ const meta = { version };
39
+
40
+ yield put({ meta, ...legacyFetchStructure.success(data) });
41
+ } catch (error) {
42
+ if (error.response) {
43
+ const { status, data } = error.response;
44
+ yield put(legacyFetchStructure.failure({ status, data }));
45
+ } else {
46
+ yield put(legacyFetchStructure.failure(error.message));
47
+ }
48
+ } finally {
49
+ yield put(legacyFetchStructure.fulfill());
50
+ }
51
+ }
52
+
53
+ export function* legacyFetchStructureRequestSaga() {
54
+ yield takeLatest(legacyFetchStructure.TRIGGER, legacyFetchStructureSaga);
55
+ }
@@ -3,7 +3,7 @@ import { call, put, takeLatest } from "redux-saga/effects";
3
3
  import { apiJsonPatch, JSON_OPTS } from "@truedat/core/services/api";
4
4
  import {
5
5
  requestGrantRemoval,
6
- fetchStructure,
6
+ legacyFetchStructure,
7
7
  fetchStructures,
8
8
  } from "../routines";
9
9
  import { API_GRANT } from "../api";
@@ -21,7 +21,7 @@ export function* requestGrantRemovalSaga({ payload }) {
21
21
  yield put(
22
22
  previousStructureQuery
23
23
  ? fetchStructures.trigger(previousStructureQuery)
24
- : fetchStructure.trigger({ id: data_structure_id, version })
24
+ : legacyFetchStructure.trigger({ id: data_structure_id, version })
25
25
  );
26
26
  } catch (error) {
27
27
  if (error.response) {
@@ -2,10 +2,10 @@ import { getTabVisibility } from "../getTabVisibility";
2
2
 
3
3
  describe("selectors: getTabVisibility", () => {
4
4
  it("should include fields iff structureFields is not empty", () => {
5
- expect(getTabVisibility({ structureFields: [1] })).toMatchObject({
5
+ expect(getTabVisibility({ structure: { data_fields_count: 1 } })).toMatchObject({
6
6
  fields: true,
7
7
  });
8
- expect(getTabVisibility({ structureFields: [] })).toMatchObject({
8
+ expect(getTabVisibility({ structure: { data_fields_count: 0 } })).toMatchObject({
9
9
  fields: false,
10
10
  });
11
11
  });
@@ -122,10 +122,10 @@ describe("selectors: getTabVisibility", () => {
122
122
 
123
123
  it("should include versions iff structureVersions is not empty", () => {
124
124
  expect(getTabVisibility({})).toMatchObject({ versions: false });
125
- expect(getTabVisibility({ structureVersions: [] })).toMatchObject({
125
+ expect(getTabVisibility({ structure: { version_count: 0 } })).toMatchObject({
126
126
  versions: false,
127
127
  });
128
- expect(getTabVisibility({ structureVersions: [{}] })).toMatchObject({
128
+ expect(getTabVisibility({ structure: { version_count: 1 } })).toMatchObject({
129
129
  versions: true,
130
130
  });
131
131
  });
@@ -224,10 +224,10 @@ describe("selectors: getTabVisibility", () => {
224
224
  expect(getTabVisibility({ structure: {} })).toMatchObject({
225
225
  grants: false,
226
226
  });
227
- expect(getTabVisibility({ structure: { grants: [] } })).toMatchObject({
227
+ expect(getTabVisibility({ structure: { grants_count: 0 } })).toMatchObject({
228
228
  grants: false,
229
229
  });
230
- expect(getTabVisibility({ structure: { grants: [{}] } })).toMatchObject({
230
+ expect(getTabVisibility({ structure: { grants_count: 1 } })).toMatchObject({
231
231
  grants: true,
232
232
  });
233
233
  });
@@ -43,6 +43,7 @@ const getFieldsFromStructures = (structuresFields, parentStructures) =>
43
43
 
44
44
  export const getStructuresFields = createSelector(
45
45
  [_.propOr([], "structuresFields"), _.propOr([], "parentStructures")],
46
- (structuresFields, parentStructures) =>
47
- getFieldsFromStructures(structuresFields, parentStructures)
46
+ (structuresFields, parentStructures) => {
47
+ return getFieldsFromStructures(structuresFields, parentStructures);
48
+ }
48
49
  );
@@ -6,7 +6,7 @@ const notEmpty = _.negate(_.isEmpty);
6
6
  const notEmptyPath = (path) => _.flow(_.path(path), notEmpty);
7
7
  const hasProfile = notEmptyPath("profile");
8
8
 
9
- const fieldsTabVisible = _.conformsTo({ structureFields: notEmpty });
9
+ const fieldsTabVisible = (state) => state?.structure?.data_fields_count > 0;
10
10
 
11
11
  const profileTabVisible = ({
12
12
  userPermissions,
@@ -36,7 +36,8 @@ const notesTabVisible = ({ templatesLoading, templates, structure }) =>
36
36
  _.negate(_.isNil)
37
37
  )(templates);
38
38
 
39
- const versionsTabVisible = notEmptyPath("structureVersions");
39
+ // const versionsTabVisible = notEmptyPath("structureVersions");
40
+ const versionsTabVisible = (state) => state?.structure?.version_count > 0;
40
41
 
41
42
  const structureLinksTabVisible = (state) =>
42
43
  _.has("create_struct_to_struct_link", state?.structureActions) ||
@@ -56,10 +57,12 @@ const eventsTabVisible = _.flow(
56
57
  _.prop("structureVersion"),
57
58
  _.isEqual("latest")
58
59
  );
59
- const grantsTabVisible = _.flow(_.path("structure.grants"), notEmpty);
60
- const metatadaVisible = (state) => !_.isEmpty(_.path(["structure", "structure_type", "metadata_views"])(state))
60
+ const grantsTabVisible = (state) => state?.structure?.grants_count > 0;
61
61
 
62
- export const getTabVisibility = createSelector([state => state], (state) => ({
62
+ const metatadaVisible = (state) =>
63
+ !_.isEmpty(_.path(["structure", "structure_type", "metadata_views"])(state));
64
+
65
+ export const getTabVisibility = createSelector([(state) => state], (state) => ({
63
66
  fields: fieldsTabVisible(state),
64
67
  profile: profileTabVisible(state),
65
68
  links: linksTabVisible(state),