@truedat/dd 8.5.1 → 8.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/dd",
3
- "version": "8.5.1",
3
+ "version": "8.5.3",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -51,7 +51,7 @@
51
51
  "@testing-library/jest-dom": "^6.6.3",
52
52
  "@testing-library/react": "^16.3.0",
53
53
  "@testing-library/user-event": "^14.6.1",
54
- "@truedat/test": "8.5.1",
54
+ "@truedat/test": "8.5.3",
55
55
  "identity-obj-proxy": "^3.0.0",
56
56
  "jest": "^29.7.0",
57
57
  "redux-saga-test-plan": "^4.0.6"
@@ -86,5 +86,5 @@
86
86
  "svg-pan-zoom": "^3.6.2",
87
87
  "swr": "^2.3.3"
88
88
  },
89
- "gitHead": "d29d6cba24bb1c464650348851cfaf1911bbedfd"
89
+ "gitHead": "9d67766fe0910fe519b6f1f2042b4a5dcc28fad5"
90
90
  }
@@ -485,7 +485,7 @@ export const LEGACY_DATA_STRUCTURE_VERSION_QUERY = gql`
485
485
  }
486
486
  `;
487
487
 
488
- export const DATA_STRUCTURE_VERSION_QUERY = gql`
488
+ export const buildDSVQuery = (loadStructureMetadata) => gql`
489
489
  query DataStructureVersion($dataStructureId: ID!, $version: String!) {
490
490
  dataStructureVersion(dataStructureId: $dataStructureId, version: $version) {
491
491
  id
@@ -496,6 +496,7 @@ export const DATA_STRUCTURE_VERSION_QUERY = gql`
496
496
  type
497
497
  group
498
498
  deleted_at
499
+ ${loadStructureMetadata ? `metadata` : ""}
499
500
  data_structure {
500
501
  alias
501
502
  confidential
@@ -4,13 +4,17 @@ import { connect } from "react-redux";
4
4
  import { useParams } from "react-router";
5
5
  import { clearStructure, fetchStructure } from "../routines";
6
6
 
7
+ import { useWebContext } from "@truedat/core/webContext";
8
+
7
9
  export const StructureLoader = ({ fetchStructure, clearStructure }) => {
8
10
  const { id, version } = useParams();
9
11
 
12
+ const { loadStructureMetadata } = useWebContext();
13
+
10
14
  useEffect(() => {
11
- fetchStructure({ id, version });
15
+ fetchStructure({ id, version, loadStructureMetadata });
12
16
  return () => clearStructure();
13
- }, [id, version]);
17
+ }, [id, version, loadStructureMetadata, fetchStructure, clearStructure]);
14
18
 
15
19
  return null;
16
20
  };
@@ -21,5 +25,5 @@ StructureLoader.propTypes = {
21
25
  };
22
26
 
23
27
  export default connect(null, { fetchStructure, clearStructure })(
24
- StructureLoader
28
+ StructureLoader,
25
29
  );
@@ -5,6 +5,11 @@ jest.mock("react-router", () => ({
5
5
  ...jest.requireActual("react-router"),
6
6
  useParams: () => ({ id: 1, version: 8 }),
7
7
  }));
8
+ jest.mock("@truedat/core/webContext", () => ({
9
+ useWebContext: jest.fn(),
10
+ }));
11
+
12
+ const { useWebContext } = require("@truedat/core/webContext");
8
13
 
9
14
  const props = {
10
15
  clearStructure: jest.fn(),
@@ -13,9 +18,26 @@ const props = {
13
18
 
14
19
  describe("<StructureLoader />", () => {
15
20
  it("matches the latest snapshot", () => {
21
+ useWebContext.mockReturnValue({ loadStructureMetadata: false });
16
22
  const { container } = render(<StructureLoader {...props} />);
17
23
  expect(container).toMatchSnapshot();
18
24
 
19
- expect(props.fetchStructure).toHaveBeenCalledWith({ id: 1, version: 8 });
25
+ expect(props.fetchStructure).toHaveBeenCalledWith({
26
+ id: 1,
27
+ version: 8,
28
+ loadStructureMetadata: false,
29
+ });
30
+ });
31
+
32
+ it("matches the latest snapshot", () => {
33
+ useWebContext.mockReturnValue({ loadStructureMetadata: true });
34
+
35
+ render(<StructureLoader {...props} />);
36
+
37
+ expect(props.fetchStructure).toHaveBeenCalledWith({
38
+ id: 1,
39
+ version: 8,
40
+ loadStructureMetadata: true,
41
+ });
20
42
  });
21
43
  });
@@ -5,7 +5,7 @@ import {
5
5
  } from "../fetchStructure";
6
6
 
7
7
  import { fetchStructure } from "../../routines";
8
- import { DATA_STRUCTURE_VERSION_QUERY } from "../../api/queries";
8
+ import { buildDSVQuery } from "../../api/queries";
9
9
  import { getStructureFieldColumns } from "../../selectors";
10
10
 
11
11
  describe("sagas: fetchStructureRequestSaga", () => {
@@ -60,7 +60,7 @@ describe("sagas: fetchStructureSaga", () => {
60
60
 
61
61
  it("should put a success action when a response is returned", () => {
62
62
  const meta = { version };
63
-
63
+ const payload = { id };
64
64
  expect(() => {
65
65
  testSaga(fetchStructureSaga, { payload })
66
66
  .next()
@@ -73,7 +73,7 @@ describe("sagas: fetchStructureSaga", () => {
73
73
 
74
74
  .call(client.query, {
75
75
  fetchPolicy: "network-only",
76
- query: DATA_STRUCTURE_VERSION_QUERY,
76
+ query: buildDSVQuery(false),
77
77
  variables,
78
78
  })
79
79
  .next({ data: { dataStructureVersion } })
@@ -107,7 +107,96 @@ describe("sagas: fetchStructureSaga", () => {
107
107
  .next()
108
108
  .call(client.query, {
109
109
  fetchPolicy: "network-only",
110
- query: DATA_STRUCTURE_VERSION_QUERY,
110
+ query: buildDSVQuery(false),
111
+ variables,
112
+ })
113
+ .next({ data: { dataStructureVersion } })
114
+ .put({ meta, ...fetchStructure.success(data) })
115
+ .next()
116
+ .put(fetchStructure.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
+ const payload = { id };
126
+ expect(() => {
127
+ testSaga(fetchStructureSaga, { payload })
128
+ .next()
129
+ .select(getStructureFieldColumns)
130
+ .next(structureFieldColumns)
131
+ .getContext("client")
132
+ .next(client)
133
+ .put(fetchStructure.request())
134
+ .next()
135
+ .call(client.query, {
136
+ fetchPolicy: "network-only",
137
+ query: buildDSVQuery(false),
138
+ variables,
139
+ })
140
+ .throw(error)
141
+ .put(fetchStructure.failure(message))
142
+ .next()
143
+ .put(fetchStructure.fulfill())
144
+ .next()
145
+ .isDone();
146
+ }).not.toThrow();
147
+ });
148
+
149
+ it("should put a success action when a response is returned", () => {
150
+ const meta = { version };
151
+ const payload = { id, loadStructureMetadata: true };
152
+
153
+ expect(() => {
154
+ testSaga(fetchStructureSaga, { payload })
155
+ .next()
156
+ .select(getStructureFieldColumns)
157
+ .next(structureFieldColumns)
158
+ .getContext("client")
159
+ .next(client)
160
+ .put(fetchStructure.request())
161
+ .next()
162
+
163
+ .call(client.query, {
164
+ fetchPolicy: "network-only",
165
+ query: buildDSVQuery(true),
166
+ variables,
167
+ })
168
+ .next({ data: { dataStructureVersion } })
169
+ .put({ meta, ...fetchStructure.success(data) })
170
+ .next()
171
+ .put(fetchStructure.fulfill())
172
+ .next()
173
+ .isDone();
174
+ }).not.toThrow();
175
+ });
176
+
177
+ it("should put a success action when a response is returned - with version", () => {
178
+ const version = 23;
179
+ const payload = { id, version, loadStructureMetadata: true };
180
+ const meta = { version };
181
+
182
+ const variables = {
183
+ dataStructureId: id,
184
+ version,
185
+ note_fields: ["note_field"],
186
+ };
187
+
188
+ expect(() => {
189
+ testSaga(fetchStructureSaga, { payload })
190
+ .next()
191
+ .select(getStructureFieldColumns)
192
+ .next(structureFieldColumns)
193
+ .getContext("client")
194
+ .next(client)
195
+ .put(fetchStructure.request())
196
+ .next()
197
+ .call(client.query, {
198
+ fetchPolicy: "network-only",
199
+ query: buildDSVQuery(true),
111
200
  variables,
112
201
  })
113
202
  .next({ data: { dataStructureVersion } })
@@ -122,6 +211,7 @@ describe("sagas: fetchStructureSaga", () => {
122
211
  it("should put a failure action when the call returns an error", () => {
123
212
  const message = "Request failed";
124
213
  const error = { message };
214
+ const payload = { id, loadStructureMetadata: true };
125
215
 
126
216
  expect(() => {
127
217
  testSaga(fetchStructureSaga, { payload })
@@ -134,7 +224,7 @@ describe("sagas: fetchStructureSaga", () => {
134
224
  .next()
135
225
  .call(client.query, {
136
226
  fetchPolicy: "network-only",
137
- query: DATA_STRUCTURE_VERSION_QUERY,
227
+ query: buildDSVQuery(true),
138
228
  variables,
139
229
  })
140
230
  .throw(error)
@@ -1,7 +1,7 @@
1
1
  import _ from "lodash/fp";
2
2
  import { call, put, takeLatest, select, getContext } from "redux-saga/effects";
3
3
  import { fetchStructure } from "../routines";
4
- import { DATA_STRUCTURE_VERSION_QUERY } from "../api/queries";
4
+ import { buildDSVQuery } from "../api/queries";
5
5
  import { getStructureFieldColumns } from "../selectors";
6
6
 
7
7
  export function* fetchStructureSaga({ payload }) {
@@ -9,19 +9,19 @@ export function* fetchStructureSaga({ payload }) {
9
9
  const structureFieldColumns = yield select(getStructureFieldColumns);
10
10
  const note_fields = _.flow(
11
11
  _.filter(({ name }) => name.startsWith("note.")),
12
- _.map(({ name }) => name.split(".")[1])
12
+ _.map(({ name }) => name.split(".")[1]),
13
13
  )(structureFieldColumns);
14
14
 
15
15
  const client = yield getContext("client");
16
16
 
17
17
  yield put(fetchStructure.request());
18
18
 
19
- const { id, version = "latest" } = payload;
19
+ const { id, version = "latest", loadStructureMetadata } = payload;
20
20
  const {
21
21
  data: { dataStructureVersion },
22
22
  } = yield call(client.query, {
23
23
  fetchPolicy: "network-only",
24
- query: DATA_STRUCTURE_VERSION_QUERY,
24
+ query: buildDSVQuery(loadStructureMetadata),
25
25
  variables: {
26
26
  dataStructureId: id,
27
27
  version,