@truedat/cx 4.41.2 → 4.41.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 (108) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/package.json +4 -4
  3. package/src/jobs/components/Job.js +11 -11
  4. package/src/jobs/components/JobRoutes.js +2 -2
  5. package/src/jobs/components/JobRow.js +7 -3
  6. package/src/jobs/components/Jobs.js +16 -28
  7. package/src/jobs/components/JobsTable.js +80 -92
  8. package/src/jobs/components/JobsView.js +23 -0
  9. package/src/jobs/components/SourceJobs.js +29 -0
  10. package/src/jobs/components/__tests__/JobRow.spec.js +44 -23
  11. package/src/jobs/components/__tests__/Jobs.spec.js +33 -8
  12. package/src/jobs/components/__tests__/JobsTable.spec.js +50 -81
  13. package/src/jobs/components/__tests__/JobsView.spec.js +39 -0
  14. package/src/jobs/components/__tests__/SourceJobs.spec.js +38 -0
  15. package/src/jobs/components/__tests__/__snapshots__/Job.spec.js.snap +3 -4
  16. package/src/jobs/components/__tests__/__snapshots__/JobRow.spec.js.snap +40 -32
  17. package/src/jobs/components/__tests__/__snapshots__/Jobs.spec.js.snap +136 -35
  18. package/src/jobs/components/__tests__/__snapshots__/JobsTable.spec.js.snap +104 -227
  19. package/src/jobs/components/__tests__/__snapshots__/JobsView.spec.js.snap +167 -0
  20. package/src/jobs/components/__tests__/__snapshots__/SourceJobs.spec.js.snap +115 -0
  21. package/src/jobs/components/index.js +1 -3
  22. package/src/jobs/selectors/index.js +4 -2
  23. package/src/jobs/selectors/{getJobColumns.js → jobColumnsSelector.js} +11 -27
  24. package/src/jobs/selectors/jobRowsSelector.js +14 -0
  25. package/src/jobs/selectors/sourceJobColumnsSelector.js +35 -0
  26. package/src/messages/en.js +9 -1
  27. package/src/messages/es.js +9 -1
  28. package/src/reducers/cxMessage.js +15 -1
  29. package/src/sources/api/fragments.js +48 -0
  30. package/src/sources/api/mutations.js +51 -0
  31. package/src/sources/api/queries.js +52 -0
  32. package/src/sources/api.js +1 -2
  33. package/src/sources/components/EditSource.js +5 -29
  34. package/src/sources/components/JobForm.js +2 -2
  35. package/src/sources/components/NewJob.js +10 -23
  36. package/src/sources/components/Source.js +12 -76
  37. package/src/sources/components/SourceActions.js +13 -21
  38. package/src/sources/components/SourceBreadcrumbs.js +1 -1
  39. package/src/sources/components/SourceConfiguration.js +60 -0
  40. package/src/sources/components/SourceDetail.js +90 -0
  41. package/src/sources/components/SourceForm.js +50 -53
  42. package/src/sources/components/SourceHeader.js +29 -0
  43. package/src/sources/components/SourceRoutes.js +25 -89
  44. package/src/sources/components/SourceSelector.js +53 -44
  45. package/src/sources/components/SourceTabs.js +54 -0
  46. package/src/sources/components/Sources.js +7 -20
  47. package/src/sources/components/SourcesTable.js +3 -4
  48. package/src/sources/components/__tests__/EditSource.spec.js +1 -2
  49. package/src/sources/components/__tests__/Source.spec.js +1 -1
  50. package/src/sources/components/__tests__/SourceActions.spec.js +3 -1
  51. package/src/sources/components/__tests__/SourceDetail.spec.js +45 -0
  52. package/src/sources/components/__tests__/SourceForm.spec.js +16 -31
  53. package/src/sources/components/__tests__/SourceHeader.spec.js +16 -0
  54. package/src/sources/components/__tests__/SourceSelector.spec.js +44 -0
  55. package/src/sources/components/__tests__/SourceTabs.spec.js +21 -0
  56. package/src/sources/components/__tests__/Sources.spec.js +5 -2
  57. package/src/sources/components/__tests__/__snapshots__/EditSource.spec.js.snap +12 -35
  58. package/src/sources/components/__tests__/__snapshots__/NewSource.spec.js.snap +1 -1
  59. package/src/sources/components/__tests__/__snapshots__/Source.spec.js.snap +23 -65
  60. package/src/sources/components/__tests__/__snapshots__/SourceActions.spec.js.snap +1 -1
  61. package/src/sources/components/__tests__/__snapshots__/SourceDetail.spec.js.snap +154 -0
  62. package/src/sources/components/__tests__/__snapshots__/SourceForm.spec.js.snap +37 -14
  63. package/src/sources/components/__tests__/__snapshots__/SourceHeader.spec.js.snap +85 -0
  64. package/src/sources/components/__tests__/__snapshots__/SourceSelector.spec.js.snap +68 -0
  65. package/src/sources/components/__tests__/__snapshots__/SourceTabs.spec.js.snap +22 -0
  66. package/src/sources/components/__tests__/__snapshots__/Sources.spec.js.snap +2 -2
  67. package/src/sources/components/__tests__/__snapshots__/SourcesTable.spec.js.snap +5 -5
  68. package/src/sources/components/index.js +1 -4
  69. package/src/sources/reducers/__tests__/sourceRedirect.spec.js +26 -21
  70. package/src/sources/reducers/__tests__/sourceUpdateStatus.spec.js +9 -9
  71. package/src/sources/reducers/index.js +1 -12
  72. package/src/sources/reducers/sourceRedirect.js +20 -10
  73. package/src/sources/reducers/sourceUpdateStatus.js +5 -5
  74. package/src/sources/routines.js +0 -3
  75. package/src/sources/sagas/__tests__/createSource.spec.js +35 -20
  76. package/src/sources/sagas/__tests__/deleteSource.spec.js +29 -14
  77. package/src/sources/sagas/__tests__/disableSource.spec.js +2 -8
  78. package/src/sources/sagas/__tests__/enableSource.spec.js +2 -8
  79. package/src/sources/sagas/__tests__/updateSource.spec.js +33 -15
  80. package/src/sources/sagas/createSource.js +24 -14
  81. package/src/sources/sagas/deleteSource.js +14 -15
  82. package/src/sources/sagas/disableSource.js +1 -17
  83. package/src/sources/sagas/enableSource.js +1 -17
  84. package/src/sources/sagas/index.js +0 -9
  85. package/src/sources/sagas/updateSource.js +18 -15
  86. package/src/sources/components/DynamicSourceForm.js +0 -60
  87. package/src/sources/components/SourceLoader.js +0 -59
  88. package/src/sources/components/SourcesLoader.js +0 -39
  89. package/src/sources/components/__tests__/DynamicSourceForm.spec.js +0 -89
  90. package/src/sources/components/__tests__/SourceLoader.spec.js +0 -54
  91. package/src/sources/components/__tests__/SourcesLoader.spec.js +0 -53
  92. package/src/sources/components/__tests__/__snapshots__/DynamicSourceForm.spec.js.snap +0 -8
  93. package/src/sources/components/__tests__/__snapshots__/SourceLoader.spec.js.snap +0 -3
  94. package/src/sources/components/__tests__/__snapshots__/SourcesLoader.spec.js.snap +0 -3
  95. package/src/sources/reducers/__tests__/source.spec.js +0 -44
  96. package/src/sources/reducers/__tests__/sourceLoading.spec.js +0 -30
  97. package/src/sources/reducers/__tests__/sources.spec.js +0 -37
  98. package/src/sources/reducers/__tests__/sourcesLoading.spec.js +0 -30
  99. package/src/sources/reducers/source.js +0 -35
  100. package/src/sources/reducers/sourceLoading.js +0 -16
  101. package/src/sources/reducers/sources.js +0 -28
  102. package/src/sources/reducers/sourcesLoading.js +0 -16
  103. package/src/sources/sagas/__tests__/fetchSource.spec.js +0 -71
  104. package/src/sources/sagas/__tests__/fetchSources.spec.js +0 -69
  105. package/src/sources/sagas/__tests__/updateSourceConfig.spec.js +0 -73
  106. package/src/sources/sagas/fetchSource.js +0 -30
  107. package/src/sources/sagas/fetchSources.js +0 -26
  108. package/src/sources/sagas/updateSourceConfig.js +0 -29
@@ -1,14 +1,14 @@
1
- import { updateSourceConfig } from "../routines";
1
+ import { updateSource } from "../routines";
2
2
 
3
3
  const sourceUpdateStatus = (state = "none", { type }) => {
4
4
  switch (type) {
5
- case updateSourceConfig.TRIGGER:
5
+ case updateSource.TRIGGER:
6
6
  return "updating";
7
- case updateSourceConfig.SUCCESS:
7
+ case updateSource.SUCCESS:
8
8
  return "success";
9
- case updateSourceConfig.FAILURE:
9
+ case updateSource.FAILURE:
10
10
  return "fail";
11
- case updateSourceConfig.FULFILL:
11
+ case updateSource.FULFILL:
12
12
  return "none";
13
13
  default:
14
14
  return state;
@@ -1,13 +1,10 @@
1
1
  import { createRoutine } from "redux-saga-routines";
2
2
 
3
3
  export const clearSource = createRoutine("CLEAR_SOURCE");
4
- export const clearSources = createRoutine("CLEAR_SOURCES");
5
4
  export const createJob = createRoutine("CREATE_JOB");
6
5
  export const createSource = createRoutine("CREATE_SOURCE");
7
6
  export const deleteSource = createRoutine("DELETE_SOURCE");
8
7
  export const disableSource = createRoutine("DISABLE_SOURCE");
9
8
  export const enableSource = createRoutine("ENABLE_SOURCE");
10
9
  export const fetchSource = createRoutine("FETCH_SOURCE");
11
- export const fetchSources = createRoutine("FETCH_SOURCES");
12
10
  export const updateSource = createRoutine("UPDATE_SOURCE");
13
- export const updateSourceConfig = createRoutine("UPDATE_SOURCE_CONFIG");
@@ -1,9 +1,12 @@
1
1
  import _ from "lodash/fp";
2
2
  import { testSaga } from "redux-saga-test-plan";
3
- import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
4
- import { createSourceRequestSaga, createSourceSaga } from "../createSource";
3
+ import {
4
+ createSourceRequestSaga,
5
+ createSourceSaga,
6
+ onSuccess,
7
+ } from "../createSource";
8
+ import { CREATE_SOURCE } from "../../api/mutations";
5
9
  import { createSource } from "../../routines";
6
- import { API_SOURCES } from "../../api";
7
10
 
8
11
  describe("sagas: createSourceRequestSaga", () => {
9
12
  it("should invoke createSourceSaga on createSource.TRIGGER", () => {
@@ -26,30 +29,34 @@ describe("sagas: createSourceRequestSaga", () => {
26
29
  });
27
30
 
28
31
  describe("sagas: createSourceSaga", () => {
29
- const payload = {
30
- source: {
31
- type: "tag1",
32
- external_id: "Micro1",
33
- config: { a: 1 }
34
- }
32
+ const client = { mutate: jest.fn() };
33
+ const source = {
34
+ type: "tag1",
35
+ external_id: "Micro1",
36
+ config: { a: 1 },
35
37
  };
36
- const request_data = {
37
- source: {
38
- type: "tag1",
39
- external_id: "Micro1",
40
- config: { a: 1 }
41
- }
38
+ const payload = { source };
39
+ const variables = {
40
+ source: { ...source, config: "stringified config" },
42
41
  };
43
42
 
44
43
  it("should put a success action when a response is returned", () => {
45
44
  expect(() => {
46
45
  testSaga(createSourceSaga, { payload })
47
46
  .next()
48
- .put({ ...createSource.request() })
47
+ .getContext("client")
48
+ .next(client)
49
+ .put(createSource.request(payload))
49
50
  .next()
50
- .call(apiJsonPost, API_SOURCES, request_data, JSON_OPTS)
51
+ .call(_.update, "source.config", JSON.stringify, payload)
52
+ .next(variables)
53
+ .call(client.mutate, {
54
+ mutation: CREATE_SOURCE,
55
+ update: onSuccess,
56
+ variables,
57
+ })
51
58
  .next({ data: payload })
52
- .put({ ...createSource.success(payload) })
59
+ .put(createSource.success(payload))
53
60
  .next()
54
61
  .put(createSource.fulfill())
55
62
  .next()
@@ -64,9 +71,17 @@ describe("sagas: createSourceSaga", () => {
64
71
  expect(() => {
65
72
  testSaga(createSourceSaga, { payload })
66
73
  .next()
67
- .put({ ...createSource.request() })
74
+ .getContext("client")
75
+ .next(client)
76
+ .put(createSource.request(payload))
68
77
  .next()
69
- .call(apiJsonPost, API_SOURCES, request_data, JSON_OPTS)
78
+ .call(_.update, "source.config", JSON.stringify, payload)
79
+ .next(variables)
80
+ .call(client.mutate, {
81
+ mutation: CREATE_SOURCE,
82
+ update: onSuccess,
83
+ variables,
84
+ })
70
85
  .throw(error)
71
86
  .put(createSource.failure(message))
72
87
  .next()
@@ -1,12 +1,14 @@
1
- import { compile } from "path-to-regexp";
2
1
  import { testSaga } from "redux-saga-test-plan";
3
- import { apiJsonDelete, JSON_OPTS } from "@truedat/core/services/api";
4
- import { deleteSourceSaga, deleteSourceRequestSaga } from "../deleteSource";
2
+ import { DELETE_SOURCE } from "../../api/mutations";
5
3
  import { deleteSource } from "../../routines";
6
- import { API_SOURCE } from "../../api";
4
+ import {
5
+ deleteSourceRequestSaga,
6
+ deleteSourceSaga,
7
+ onSuccess,
8
+ } from "../deleteSource";
7
9
 
8
10
  describe("sagas: deleteSourceRequestSaga", () => {
9
- it("should invoke deleteSourceSaga on deleteSource.TRIGGER", () => {
11
+ it("should invoke deleteSourceSaga on trigger", () => {
10
12
  expect(() => {
11
13
  testSaga(deleteSourceRequestSaga)
12
14
  .next()
@@ -20,23 +22,29 @@ describe("sagas: deleteSourceRequestSaga", () => {
20
22
  expect(() => {
21
23
  testSaga(deleteSourceRequestSaga)
22
24
  .next()
23
- .takeLatest("FOO", deleteSourceRequestSaga);
25
+ .takeLatest("FOO", deleteSourceSaga);
24
26
  }).toThrow();
25
27
  });
26
28
  });
27
29
 
28
30
  describe("sagas: deleteSourceSaga", () => {
29
- const payload = { external_id: "Micro1" };
30
- const { external_id } = payload;
31
- const url = compile(API_SOURCE)({ external_id });
31
+ const id = 1;
32
+ const payload = { id };
33
+ const client = { mutate: jest.fn() };
32
34
 
33
35
  it("should put a success action when a response is returned", () => {
34
36
  expect(() => {
35
37
  testSaga(deleteSourceSaga, { payload })
36
38
  .next()
37
- .put(deleteSource.request())
39
+ .getContext("client")
40
+ .next(client)
41
+ .put(deleteSource.request(payload))
38
42
  .next()
39
- .call(apiJsonDelete, url, JSON_OPTS)
43
+ .call(client.mutate, {
44
+ mutation: DELETE_SOURCE,
45
+ update: onSuccess,
46
+ variables: payload,
47
+ })
40
48
  .next({ data: payload })
41
49
  .put(deleteSource.success(payload))
42
50
  .next()
@@ -46,16 +54,23 @@ describe("sagas: deleteSourceSaga", () => {
46
54
  }).not.toThrow();
47
55
  });
48
56
 
49
- it("should put a failure action when the call returns an error", () => {
57
+ it("should put a failure action when the call throws an error", () => {
50
58
  const message = "Request failed";
51
59
  const error = { message };
60
+ const client = { mutate: jest.fn() };
52
61
 
53
62
  expect(() => {
54
63
  testSaga(deleteSourceSaga, { payload })
55
64
  .next()
56
- .put(deleteSource.request())
65
+ .getContext("client")
66
+ .next(client)
67
+ .put(deleteSource.request(payload))
57
68
  .next()
58
- .call(apiJsonDelete, url, JSON_OPTS)
69
+ .call(client.mutate, {
70
+ mutation: DELETE_SOURCE,
71
+ update: onSuccess,
72
+ variables: payload,
73
+ })
59
74
  .throw(error)
60
75
  .put(deleteSource.failure(message))
61
76
  .next()
@@ -1,11 +1,7 @@
1
1
  import { testSaga } from "redux-saga-test-plan";
2
- import {
3
- DISABLE_SOURCE,
4
- disableSourceRequestSaga,
5
- disableSourceSaga,
6
- onSuccess,
7
- } from "../disableSource";
2
+ import { DISABLE_SOURCE } from "../../api/mutations";
8
3
  import { disableSource } from "../../routines";
4
+ import { disableSourceRequestSaga, disableSourceSaga } from "../disableSource";
9
5
 
10
6
  describe("sagas: disableSourceRequestSaga", () => {
11
7
  it("should invoke disableSourceSaga on trigger", () => {
@@ -42,7 +38,6 @@ describe("sagas: disableSourceSaga", () => {
42
38
  .next()
43
39
  .call(client.mutate, {
44
40
  mutation: DISABLE_SOURCE,
45
- update: onSuccess,
46
41
  variables: payload,
47
42
  })
48
43
  .next({ data: payload })
@@ -68,7 +63,6 @@ describe("sagas: disableSourceSaga", () => {
68
63
  .next()
69
64
  .call(client.mutate, {
70
65
  mutation: DISABLE_SOURCE,
71
- update: onSuccess,
72
66
  variables: payload,
73
67
  })
74
68
  .throw(error)
@@ -1,11 +1,7 @@
1
1
  import { testSaga } from "redux-saga-test-plan";
2
- import {
3
- ENABLE_SOURCE,
4
- enableSourceRequestSaga,
5
- enableSourceSaga,
6
- onSuccess,
7
- } from "../enableSource";
2
+ import { ENABLE_SOURCE } from "../../api/mutations";
8
3
  import { enableSource } from "../../routines";
4
+ import { enableSourceRequestSaga, enableSourceSaga } from "../enableSource";
9
5
 
10
6
  describe("sagas: enableSourceRequestSaga", () => {
11
7
  it("should invoke enableSourceSaga on trigger", () => {
@@ -42,7 +38,6 @@ describe("sagas: enableSourceSaga", () => {
42
38
  .next()
43
39
  .call(client.mutate, {
44
40
  mutation: ENABLE_SOURCE,
45
- update: onSuccess,
46
41
  variables: payload,
47
42
  })
48
43
  .next({ data: payload })
@@ -68,7 +63,6 @@ describe("sagas: enableSourceSaga", () => {
68
63
  .next()
69
64
  .call(client.mutate, {
70
65
  mutation: ENABLE_SOURCE,
71
- update: onSuccess,
72
66
  variables: payload,
73
67
  })
74
68
  .throw(error)
@@ -1,12 +1,11 @@
1
- import { compile } from "path-to-regexp";
1
+ import _ from "lodash/fp";
2
2
  import { testSaga } from "redux-saga-test-plan";
3
- import { apiJsonPut, JSON_OPTS } from "@truedat/core/services/api";
4
- import { updateSourceRequestSaga, updateSourceSaga } from "../updateSource";
3
+ import { UPDATE_SOURCE } from "../../api/mutations";
5
4
  import { updateSource } from "../../routines";
6
- import { API_SOURCE } from "../../api";
5
+ import { updateSourceRequestSaga, updateSourceSaga } from "../updateSource";
7
6
 
8
7
  describe("sagas: updateSourceRequestSaga", () => {
9
- it("should invoke updateSourceSaga on trigger", () => {
8
+ it("should invoke updateSourceSaga on updateSource.TRIGGER", () => {
10
9
  expect(() => {
11
10
  testSaga(updateSourceRequestSaga)
12
11
  .next()
@@ -20,27 +19,39 @@ describe("sagas: updateSourceRequestSaga", () => {
20
19
  expect(() => {
21
20
  testSaga(updateSourceRequestSaga)
22
21
  .next()
23
- .takeLatest("FOO", updateSourceSaga);
22
+ .takeLatest("FOO", updateSourceRequestSaga);
24
23
  }).toThrow();
25
24
  });
26
25
  });
27
26
 
28
27
  describe("sagas: updateSourceSaga", () => {
29
- const external_id = "Micro1";
30
- const url = compile(API_SOURCE)({ external_id });
31
- const source = { external_id, config: { a: 1 } };
28
+ const client = { mutate: jest.fn() };
29
+ const source = {
30
+ type: "tag1",
31
+ external_id: "Micro1",
32
+ config: { a: 1 },
33
+ };
32
34
  const payload = { source };
33
- const requestData = { source };
35
+ const variables = {
36
+ source: { ...source, config: "stringified config" },
37
+ };
34
38
 
35
39
  it("should put a success action when a response is returned", () => {
36
40
  expect(() => {
37
41
  testSaga(updateSourceSaga, { payload })
38
42
  .next()
39
- .put(updateSource.request())
43
+ .getContext("client")
44
+ .next(client)
45
+ .put(updateSource.request(payload))
40
46
  .next()
41
- .call(apiJsonPut, url, requestData, JSON_OPTS)
47
+ .call(_.update, "source.config", JSON.stringify, payload)
48
+ .next(variables)
49
+ .call(client.mutate, {
50
+ mutation: UPDATE_SOURCE,
51
+ variables,
52
+ })
42
53
  .next({ data: payload })
43
- .put(updateSource.success({ source }))
54
+ .put(updateSource.success(payload))
44
55
  .next()
45
56
  .put(updateSource.fulfill())
46
57
  .next()
@@ -55,9 +66,16 @@ describe("sagas: updateSourceSaga", () => {
55
66
  expect(() => {
56
67
  testSaga(updateSourceSaga, { payload })
57
68
  .next()
58
- .put(updateSource.request())
69
+ .getContext("client")
70
+ .next(client)
71
+ .put(updateSource.request(payload))
59
72
  .next()
60
- .call(apiJsonPut, url, requestData, JSON_OPTS)
73
+ .call(_.update, "source.config", JSON.stringify, payload)
74
+ .next(variables)
75
+ .call(client.mutate, {
76
+ mutation: UPDATE_SOURCE,
77
+ variables,
78
+ })
61
79
  .throw(error)
62
80
  .put(updateSource.failure(message))
63
81
  .next()
@@ -1,23 +1,33 @@
1
- import { call, put, takeLatest } from "redux-saga/effects";
2
- import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
1
+ import _ from "lodash/fp";
2
+ import { call, put, takeLatest, getContext } from "redux-saga/effects";
3
+ import { CREATE_SOURCE } from "../api/mutations";
3
4
  import { createSource } from "../routines";
4
- import { API_SOURCES } from "../api";
5
+
6
+ export const onSuccess = (cache) => {
7
+ cache.evict({ id: "ROOT_QUERY", fieldName: "sources" });
8
+ cache.gc();
9
+ };
5
10
 
6
11
  export function* createSourceSaga({ payload }) {
12
+ const client = yield getContext("client");
13
+ yield put(createSource.request(payload));
14
+ // GraphQL input object does not support JSON scalars, so source.config must
15
+ // be stringified before sending to the server.
16
+ const variables = yield call(
17
+ _.update,
18
+ "source.config",
19
+ JSON.stringify,
20
+ payload
21
+ );
7
22
  try {
8
- const { source } = payload;
9
- const url = API_SOURCES;
10
- const requestData = { source };
11
- yield put(createSource.request());
12
- const { data } = yield call(apiJsonPost, url, requestData, JSON_OPTS);
23
+ const { data } = yield call(client.mutate, {
24
+ mutation: CREATE_SOURCE,
25
+ update: onSuccess,
26
+ variables,
27
+ });
13
28
  yield put(createSource.success(data));
14
29
  } catch (error) {
15
- if (error.response) {
16
- const { status, data } = error.response;
17
- yield put(createSource.failure({ status, data }));
18
- } else {
19
- yield put(createSource.failure(error.message));
20
- }
30
+ yield put(createSource.failure(error.message));
21
31
  } finally {
22
32
  yield put(createSource.fulfill());
23
33
  }
@@ -1,25 +1,24 @@
1
- import { compile } from "path-to-regexp";
2
- import { call, put, takeLatest } from "redux-saga/effects";
3
- import { apiJsonDelete, JSON_OPTS } from "@truedat/core/services/api";
1
+ import { call, put, takeLatest, getContext } from "redux-saga/effects";
2
+ import { DELETE_SOURCE } from "../api/mutations";
4
3
  import { deleteSource } from "../routines";
5
- import { API_SOURCE } from "../api";
6
4
 
7
- const toApiPath = compile(API_SOURCE);
5
+ export const onSuccess = (cache, { data: { deleteSource } }) => {
6
+ cache.evict({ id: cache.identify(deleteSource) });
7
+ cache.gc();
8
+ };
8
9
 
9
10
  export function* deleteSourceSaga({ payload }) {
11
+ const client = yield getContext("client");
12
+ yield put(deleteSource.request(payload));
10
13
  try {
11
- const source = payload;
12
- const url = toApiPath(source);
13
- yield put(deleteSource.request());
14
- const { data } = yield call(apiJsonDelete, url, JSON_OPTS);
14
+ const { data } = yield call(client.mutate, {
15
+ mutation: DELETE_SOURCE,
16
+ update: onSuccess,
17
+ variables: payload,
18
+ });
15
19
  yield put(deleteSource.success(data));
16
20
  } catch (error) {
17
- if (error.response) {
18
- const { status, data } = error.response;
19
- yield put(deleteSource.failure({ status, data }));
20
- } else {
21
- yield put(deleteSource.failure(error.message));
22
- }
21
+ yield put(deleteSource.failure(error.message));
23
22
  } finally {
24
23
  yield put(deleteSource.fulfill());
25
24
  }
@@ -1,29 +1,13 @@
1
- import { gql } from "@apollo/client";
2
1
  import { call, put, takeLatest, getContext } from "redux-saga/effects";
2
+ import { DISABLE_SOURCE } from "../api/mutations";
3
3
  import { disableSource } from "../routines";
4
4
 
5
- export const DISABLE_SOURCE = gql`
6
- mutation DisableSource($id: ID!) {
7
- disableSource(id: $id) {
8
- id
9
- externalId
10
- }
11
- }
12
- `;
13
-
14
- export const onSuccess = (cache, { data: { disableSource } }) => {
15
- cache.evict({ id: "ROOT_QUERY", fieldName: "sources" });
16
- cache.evict({ id: cache.identify(disableSource) });
17
- cache.gc();
18
- };
19
-
20
5
  export function* disableSourceSaga({ payload }) {
21
6
  const client = yield getContext("client");
22
7
  yield put(disableSource.request(payload));
23
8
  try {
24
9
  const { data } = yield call(client.mutate, {
25
10
  mutation: DISABLE_SOURCE,
26
- update: onSuccess,
27
11
  variables: payload,
28
12
  });
29
13
  yield put(disableSource.success(data));
@@ -1,29 +1,13 @@
1
- import { gql } from "@apollo/client";
2
1
  import { call, put, takeLatest, getContext } from "redux-saga/effects";
2
+ import { ENABLE_SOURCE } from "../api/mutations";
3
3
  import { enableSource } from "../routines";
4
4
 
5
- export const ENABLE_SOURCE = gql`
6
- mutation EnableSource($id: ID!) {
7
- enableSource(id: $id) {
8
- id
9
- externalId
10
- }
11
- }
12
- `;
13
-
14
- export const onSuccess = (cache, { data: { enableSource } }) => {
15
- cache.evict({ id: "ROOT_QUERY", fieldName: "sources" });
16
- cache.evict({ id: cache.identify(enableSource) });
17
- cache.gc();
18
- };
19
-
20
5
  export function* enableSourceSaga({ payload }) {
21
6
  const client = yield getContext("client");
22
7
  yield put(enableSource.request(payload));
23
8
  try {
24
9
  const { data } = yield call(client.mutate, {
25
10
  mutation: ENABLE_SOURCE,
26
- update: onSuccess,
27
11
  variables: payload,
28
12
  });
29
13
  yield put(enableSource.success(data));
@@ -2,20 +2,14 @@ import { createSourceRequestSaga } from "./createSource";
2
2
  import { deleteSourceRequestSaga } from "./deleteSource";
3
3
  import { disableSourceRequestSaga } from "./disableSource";
4
4
  import { enableSourceRequestSaga } from "./enableSource";
5
- import { fetchSourceRequestSaga } from "./fetchSource";
6
- import { fetchSourcesRequestSaga } from "./fetchSources";
7
5
  import { updateSourceRequestSaga } from "./updateSource";
8
- import { updateSourceConfigRequestSaga } from "./updateSourceConfig";
9
6
 
10
7
  export {
11
8
  createSourceRequestSaga,
12
9
  deleteSourceRequestSaga,
13
10
  disableSourceRequestSaga,
14
11
  enableSourceRequestSaga,
15
- fetchSourceRequestSaga,
16
- fetchSourcesRequestSaga,
17
12
  updateSourceRequestSaga,
18
- updateSourceConfigRequestSaga,
19
13
  };
20
14
 
21
15
  export default [
@@ -23,8 +17,5 @@ export default [
23
17
  deleteSourceRequestSaga(),
24
18
  disableSourceRequestSaga(),
25
19
  enableSourceRequestSaga(),
26
- fetchSourceRequestSaga(),
27
- fetchSourcesRequestSaga(),
28
20
  updateSourceRequestSaga(),
29
- updateSourceConfigRequestSaga(),
30
21
  ];
@@ -1,24 +1,27 @@
1
- import { compile } from "path-to-regexp";
2
- import { call, put, takeLatest } from "redux-saga/effects";
3
- import { apiJsonPut, JSON_OPTS } from "@truedat/core/services/api";
1
+ import _ from "lodash/fp";
2
+ import { call, put, takeLatest, getContext } from "redux-saga/effects";
3
+ import { UPDATE_SOURCE } from "../api/mutations";
4
4
  import { updateSource } from "../routines";
5
- import { API_SOURCE } from "../api";
6
5
 
7
6
  export function* updateSourceSaga({ payload }) {
7
+ const client = yield getContext("client");
8
+ yield put(updateSource.request(payload));
9
+ // GraphQL input object does not support JSON scalars, so source.config must
10
+ // be stringified before sending to the server.
11
+ const variables = yield call(
12
+ _.update,
13
+ "source.config",
14
+ JSON.stringify,
15
+ payload
16
+ );
8
17
  try {
9
- const { source } = payload;
10
- const url = compile(API_SOURCE)(source);
11
- const requestData = { source };
12
- yield put(updateSource.request());
13
- const { data } = yield call(apiJsonPut, url, requestData, JSON_OPTS);
18
+ const { data } = yield call(client.mutate, {
19
+ mutation: UPDATE_SOURCE,
20
+ variables,
21
+ });
14
22
  yield put(updateSource.success(data));
15
23
  } catch (error) {
16
- if (error.response) {
17
- const { status, data } = error.response;
18
- yield put(updateSource.failure({ status, data }));
19
- } else {
20
- yield put(updateSource.failure(error.message));
21
- }
24
+ yield put(updateSource.failure(error.message));
22
25
  } finally {
23
26
  yield put(updateSource.fulfill());
24
27
  }
@@ -1,60 +0,0 @@
1
- import _ from "lodash/fp";
2
- import React from "react";
3
- import PropTypes from "prop-types";
4
- import { connect } from "react-redux";
5
- import { selectTemplate } from "@truedat/df/routines";
6
-
7
- const DynamicForm = React.lazy(() =>
8
- import("@truedat/df/components/DynamicForm")
9
- );
10
-
11
- const TemplateLoader = React.lazy(() =>
12
- import("@truedat/df/templates/components/TemplateLoader")
13
- );
14
-
15
- const initialState = {
16
- df_content: {},
17
- df_name: null,
18
- };
19
-
20
- export class DynamicSourceForm extends React.Component {
21
- state = initialState;
22
-
23
- componentDidMount() {
24
- const { template, selectTemplate } = this.props;
25
- if (template) selectTemplate({ id: template.id });
26
- }
27
-
28
- render() {
29
- const { dfContent, handleContentChange } = this.props;
30
- return (
31
- <>
32
- <TemplateLoader />
33
- <DynamicForm onChange={handleContentChange} content={dfContent} />
34
- </>
35
- );
36
- }
37
- }
38
-
39
- DynamicSourceForm.propTypes = {
40
- template: PropTypes.object,
41
- selectTemplate: PropTypes.func,
42
- dfContent: PropTypes.object,
43
- handleContentChange: PropTypes.func,
44
- };
45
-
46
- const findTemplate = ({ templates, source: { type } = {} }) => {
47
- return _.find(_.propEq("name", type))(templates);
48
- };
49
-
50
- const mapStateToProps = (state) => {
51
- return {
52
- source: state.source,
53
- templates: state.templates,
54
- template: _.isEmpty(state.template)
55
- ? findTemplate(state, state.source)
56
- : state.template,
57
- };
58
- };
59
-
60
- export default connect(mapStateToProps, { selectTemplate })(DynamicSourceForm);