@truedat/bg 7.8.1 → 7.8.2

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/bg",
3
- "version": "7.8.1",
3
+ "version": "7.8.2",
4
4
  "description": "Truedat Web Business Glossary",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -48,7 +48,7 @@
48
48
  "@testing-library/jest-dom": "^6.6.3",
49
49
  "@testing-library/react": "^16.3.0",
50
50
  "@testing-library/user-event": "^14.6.1",
51
- "@truedat/test": "7.7.2",
51
+ "@truedat/test": "7.8.2",
52
52
  "identity-obj-proxy": "^3.0.0",
53
53
  "jest": "^29.7.0",
54
54
  "redux-saga-test-plan": "^4.0.6"
@@ -81,5 +81,5 @@
81
81
  "semantic-ui-react": "^3.0.0-beta.2",
82
82
  "swr": "^2.3.3"
83
83
  },
84
- "gitHead": "c5687bea50fd81f4899bdadb4a25e459dacd58ec"
84
+ "gitHead": "666bad523fceed945598849935266d7c46a46432"
85
85
  }
@@ -6,7 +6,7 @@ import { connect } from "react-redux";
6
6
  import { Link } from "react-router";
7
7
  import { Button } from "semantic-ui-react";
8
8
  import { useSearchContext } from "@truedat/core/search/SearchContext";
9
- import { downloadConcepts, uploadConcepts } from "../routines";
9
+ import { downloadConcepts } from "../routines";
10
10
  import ConceptsUpdateButton from "./ConceptsUpdateButton";
11
11
  import ConceptsUploadButton from "./ConceptsUploadButton";
12
12
 
@@ -71,6 +71,6 @@ const mapStateToProps = ({ conceptsDownloading }) => ({
71
71
  conceptsDownloading: conceptsDownloading,
72
72
  });
73
73
 
74
- export default connect(mapStateToProps, { downloadConcepts, uploadConcepts })(
74
+ export default connect(mapStateToProps, { downloadConcepts })(
75
75
  ConceptsActions
76
76
  );
@@ -1,32 +1,34 @@
1
1
  import PropTypes from "prop-types";
2
- import { connect } from "react-redux";
3
2
  import { Button } from "semantic-ui-react";
4
3
  import { FormattedMessage, useIntl } from "react-intl";
5
4
  import { UploadModal } from "@truedat/core/components";
6
- import { API_BUSINESS_CONCEPT_VERSIONS_UPLOAD } from "../api";
7
- import { uploadConcepts } from "../routines";
5
+ import { useConceptsUpload } from "../hooks/useConcepts";
6
+ import { useWebContext } from "@truedat/core/webContext";
7
+ import { getUploadAlertMessage } from "../selectors/messages";
8
8
 
9
- const uploadAction = {
10
- method: "POST",
11
- href: API_BUSINESS_CONCEPT_VERSIONS_UPLOAD,
12
- };
13
- export const ConceptsUploadButton = ({
14
- uploadConcepts,
15
- loading,
16
- canAutoPublish,
17
- }) => {
9
+ export const ConceptsUploadButton = ({ canAutoPublish }) => {
18
10
  const { formatMessage, locale } = useIntl();
11
+ const { trigger: triggerUpload, isMutating: conceptsLoading } = useConceptsUpload();
12
+ const { setAlertMessage } = useWebContext();
13
+
19
14
  const extraAction = {
20
15
  key: "yesWithAutoPublish",
21
16
  primary: true,
22
17
  content: formatMessage({ id: "uploadModal.accept.publish" }),
23
18
  onClick: (data) => {
24
19
  data.append("auto_publish", canAutoPublish);
25
- return uploadConcepts({
26
- action: "upload",
27
- data,
28
- lang: locale,
29
- ...uploadAction,
20
+ data.append("lang", locale);
21
+ triggerUpload(data).then(({ status, data }) => {
22
+ const alertMessage = getUploadAlertMessage({ status, data });
23
+ setAlertMessage(alertMessage);
24
+ }).catch((error) => {
25
+ if (error.response) {
26
+ const { status, data } = error.response;
27
+ const alertMessage = getUploadAlertMessage({ status, data });
28
+ setAlertMessage(alertMessage);
29
+ } else {
30
+ setAlertMessage({ error: true, content: error.message });
31
+ }
30
32
  });
31
33
  },
32
34
  };
@@ -39,7 +41,7 @@ export const ConceptsUploadButton = ({
39
41
  secondary
40
42
  floated="right"
41
43
  icon="upload"
42
- loading={loading}
44
+ loading={conceptsLoading}
43
45
  data-tooltip={formatMessage({
44
46
  id: "concepts.actions.upload.tooltip",
45
47
  })}
@@ -52,28 +54,24 @@ export const ConceptsUploadButton = ({
52
54
  <FormattedMessage id="concepts.actions.upload.confirmation.content" />
53
55
  }
54
56
  param="business_concepts"
55
- handleSubmit={(data) =>
56
- uploadConcepts({
57
- action: "upload",
58
- data,
59
- lang: locale,
60
- ...uploadAction,
61
- })
62
- }
57
+ handleSubmit={(data) => {
58
+ triggerUpload(data).then(({ status, data }) => {
59
+ const alertMessage = getUploadAlertMessage({ status, data });
60
+ setAlertMessage(alertMessage);
61
+ }).catch((error) => {
62
+ if (error.response) {
63
+ const { status, data } = error.response;
64
+ const alertMessage = getUploadAlertMessage({ status, data });
65
+ setAlertMessage(alertMessage);
66
+ } else {
67
+ setAlertMessage(error.message);
68
+ }
69
+ });
70
+ }}
63
71
  />
64
72
  );
65
73
  };
66
74
 
67
- ConceptsUploadButton.propTypes = {
68
- uploadConcepts: PropTypes.func,
69
- loading: PropTypes.bool,
70
- canAutoPublish: PropTypes.bool,
71
- };
72
-
73
- const mapStateToProps = ({ uploadConceptsFile: { loading } }) => ({
74
- loading,
75
- });
75
+ ConceptsUploadButton.propTypes = { canAutoPublish: PropTypes.bool };
76
76
 
77
- export default connect(mapStateToProps, { uploadConcepts })(
78
- ConceptsUploadButton
79
- );
77
+ export default ConceptsUploadButton;
@@ -55,11 +55,6 @@ describe("<ConceptsActions />", () => {
55
55
  "uploadModal.accept.publish": "Upload and publish",
56
56
  },
57
57
  },
58
- state: {
59
- uploadConceptsFile: {
60
- loading: false,
61
- },
62
- },
63
58
  };
64
59
 
65
60
  it("matches the latest snapshot", async () => {
@@ -17,7 +17,6 @@ jest.mock("@truedat/core/hooks", () => ({
17
17
  }));
18
18
 
19
19
  const props = {
20
- uploadConcepts: jest.fn(),
21
20
  loading: false,
22
21
  canAutoPublish: false,
23
22
  };
@@ -8,6 +8,7 @@ import {
8
8
  API_CONCEPT_LINKS_DOWNLOAD,
9
9
  API_BUSINESS_CONCEPT_VERSIONS_SEARCH,
10
10
  API_BUSINESS_CONCEPT_VERSIONS_ACTIONS,
11
+ API_BUSINESS_CONCEPT_VERSIONS_UPLOAD,
11
12
  } from "../api";
12
13
 
13
14
  function saveFile({ data, headers }) {
@@ -53,3 +54,9 @@ export const useConceptLinksDownload = () => {
53
54
  );
54
55
  });
55
56
  };
57
+
58
+ export const useConceptsUpload = () => {
59
+ return useSWRMutations(API_BUSINESS_CONCEPT_VERSIONS_UPLOAD, (url, { arg }) =>
60
+ apiJsonPost(url, arg)
61
+ );
62
+ };
@@ -47,14 +47,6 @@ describe("reducers: conceptRedirect", () => {
47
47
  ).toBe(redirectUrl);
48
48
  });
49
49
 
50
- it("should be redirectUrl on uploadConcepts.SUCCESS", () => {
51
- expect(
52
- conceptRedirect(fooState, {
53
- type: bulkUpdate.SUCCESS,
54
- meta: { redirectUrl }
55
- })
56
- ).toBe(redirectUrl);
57
- });
58
50
 
59
51
  it("should be link to concept on updateSubscription.SUCCESS state otherwise", () => {
60
52
  expect(
@@ -10,7 +10,6 @@ import {
10
10
  bulkUpdate,
11
11
  conceptAction,
12
12
  linkConcept,
13
- uploadConcepts,
14
13
  } from "../routines";
15
14
 
16
15
  const initialState = "";
@@ -37,10 +36,6 @@ export const conceptRedirect = (
37
36
  const { redirectUrl } = meta;
38
37
  return redirectUrl;
39
38
  }
40
- case uploadConcepts.SUCCESS: {
41
- const { redirectUrl } = meta;
42
- return redirectUrl;
43
- }
44
39
  case updateSubscription.SUCCESS: {
45
40
  const { concept } = payload;
46
41
  return _.isNil(concept) ? state : linkTo.CONCEPT_VERSION(concept);
@@ -10,7 +10,6 @@ import { conceptLoading } from "./conceptLoading";
10
10
  import { conceptPermissions } from "./conceptPermissions";
11
11
  import { conceptRedirect } from "./conceptRedirect";
12
12
  import { conceptsDownloading } from "./conceptsDownloading";
13
- import { uploadConceptsFile } from "./uploadConceptsFile";
14
13
  import { bulkUpdateLoading } from "./bulkUpdateLoading";
15
14
  import { conceptUpdating } from "./conceptUpdating";
16
15
  import { sharedToDomains } from "./sharedToDomains";
@@ -31,7 +30,6 @@ export {
31
30
  conceptPermissions,
32
31
  conceptRedirect,
33
32
  conceptsDownloading,
34
- uploadConceptsFile,
35
33
  conceptUpdating,
36
34
  sharedToDomains,
37
35
  savingSharedTo,
@@ -5,7 +5,6 @@ export const conceptAction = createRoutine("CONCEPT_ACTION");
5
5
  export const downloadConcepts = createRoutine("DOWNLOAD_CONCEPTS");
6
6
  export const fetchConcept = createRoutine("FETCH_CONCEPT");
7
7
  export const fetchConceptArchive = createRoutine("FETCH_CONCEPT_ARCHIVE");
8
- export const uploadConcepts = createRoutine("UPLOAD_CONCEPTS");
9
8
 
10
9
  export const bulkUpdate = createRoutine("BULK_UPDATE");
11
10
  export const bulkUpdateQuery = createRoutine("BULK_UPDATE_QUERY");
@@ -3,7 +3,6 @@ import { conceptActionRequestSaga } from "./conceptAction";
3
3
  import { downloadConceptsRequestSaga } from "./downloadConcepts";
4
4
  import { fetchConceptArchiveRequestSaga } from "./fetchConceptArchive";
5
5
  import { fetchConceptRequestSaga } from "./fetchConcept";
6
- import { uploadConceptsRequestsSaga } from "./uploadConcepts";
7
6
  import { bulkUpdateRequestsSaga } from "./bulkUpdate";
8
7
  import { saveSharedToRequestSaga } from "./saveSharedTo";
9
8
  import { setConfidentialConceptRequestSaga } from "./setConfidentialConcept";
@@ -13,7 +12,6 @@ export {
13
12
  downloadConceptsRequestSaga,
14
13
  fetchConceptArchiveRequestSaga,
15
14
  fetchConceptRequestSaga,
16
- uploadConceptsRequestsSaga,
17
15
  bulkUpdateRequestsSaga,
18
16
  saveSharedToRequestSaga,
19
17
  setConfidentialConceptRequestSaga,
@@ -24,7 +22,6 @@ export default [
24
22
  downloadConceptsRequestSaga(),
25
23
  fetchConceptArchiveRequestSaga(),
26
24
  fetchConceptRequestSaga(),
27
- uploadConceptsRequestsSaga(),
28
25
  bulkUpdateRequestsSaga(),
29
26
  saveSharedToRequestSaga(),
30
27
  setConfidentialConceptRequestSaga(),
@@ -0,0 +1,32 @@
1
+ import _ from "lodash/fp";
2
+ import { CONCEPTS_BULK_UPLOAD_EVENTS } from "@truedat/core/routes";
3
+
4
+ export const getUploadAlertMessage = ({ status, data }) => {
5
+ if (status === 202) {
6
+ return {
7
+ error: false,
8
+ header: "concepts.upload.success.accepted.header",
9
+ icon: "check",
10
+ color: "blue",
11
+ text: "",
12
+ anchor: {
13
+ reference: CONCEPTS_BULK_UPLOAD_EVENTS,
14
+ label: "sidemenu.concepts_upload_events",
15
+ },
16
+ };
17
+ }
18
+
19
+ if (status != 500 && !_.prop("errors")(data)) {
20
+ return {
21
+ error: true,
22
+ header: "concepts.upload.failed.header",
23
+ content: `concepts.upload.failed.${_.path("error.error")(payload) || _.prop("error")(payload)
24
+ }`,
25
+ icon: "attention",
26
+ text: "",
27
+ fields: _.prop("error")(payload),
28
+ };
29
+ } else {
30
+ return null;
31
+ }
32
+ }
@@ -1,53 +1,9 @@
1
- import { CONCEPTS_BULK_UPLOAD_EVENTS } from "@truedat/core/routes";
2
- import { uploadConcepts } from "../../routines";
3
1
  import { bgMessage } from "..";
4
2
 
5
- const fooState = { foo: "bar" };
6
-
7
3
  describe("reducers: bgMessage", () => {
8
4
  const initialState = {};
9
5
 
10
6
  it("should provide the initial state", () => {
11
7
  expect(bgMessage(undefined, {})).toEqual(initialState);
12
8
  });
13
-
14
- it("should handle the uploadConcepts.SUCCESS action", () => {
15
- expect(
16
- bgMessage(fooState, {
17
- type: uploadConcepts.SUCCESS,
18
- payload: { data: { message: { length: 5 } } },
19
- })
20
- ).toEqual({
21
- error: false,
22
- header: "concepts.upload.success.accepted.header",
23
- icon: "check",
24
- color: "blue",
25
- text: "",
26
- anchor: {
27
- reference: CONCEPTS_BULK_UPLOAD_EVENTS,
28
- label: "sidemenu.concepts_upload_events",
29
- },
30
- });
31
- });
32
-
33
- it("should handle the uploadConcepts.FAILURE action", () => {
34
- expect(
35
- bgMessage(fooState, {
36
- type: uploadConcepts.FAILURE,
37
- payload: {
38
- data: {
39
- error: { error: "unprocessable_entity", field: "What a field!!" },
40
- },
41
- status: 422,
42
- },
43
- })
44
- ).toEqual({
45
- error: true,
46
- header: "concepts.upload.failed.header",
47
- content: `concepts.upload.failed.unprocessable_entity`,
48
- icon: "attention",
49
- text: "",
50
- fields: { error: "unprocessable_entity", field: "What a field!!" },
51
- });
52
- });
53
9
  });
@@ -1,7 +1,5 @@
1
1
  import _ from "lodash/fp";
2
2
  import { dismissAlert } from "@truedat/core/routines";
3
- import { CONCEPTS_BULK_UPLOAD_EVENTS } from "@truedat/core/routes";
4
- import { uploadConcepts } from "../routines";
5
3
  import { bulkUpdate } from "../concepts/routines";
6
4
 
7
5
  const initialState = {};
@@ -10,33 +8,6 @@ const bgMessage = (state = initialState, { type, payload }) => {
10
8
  switch (type) {
11
9
  case dismissAlert.TRIGGER:
12
10
  return initialState;
13
- case uploadConcepts.SUCCESS:
14
- return {
15
- error: false,
16
- header: "concepts.upload.success.accepted.header",
17
- icon: "check",
18
- color: "blue",
19
- text: "",
20
- anchor: {
21
- reference: CONCEPTS_BULK_UPLOAD_EVENTS,
22
- label: "sidemenu.concepts_upload_events",
23
- },
24
- };
25
- case uploadConcepts.FAILURE:
26
- if (payload.status != 500 && !_.path("data.errors")(payload)) {
27
- return {
28
- error: true,
29
- header: "concepts.upload.failed.header",
30
- content: `concepts.upload.failed.${
31
- _.path("data.error.error")(payload) || _.path("data.error")(payload)
32
- }`,
33
- icon: "attention",
34
- text: "",
35
- fields: _.path("data.error")(payload),
36
- };
37
- } else {
38
- return null;
39
- }
40
11
  case bulkUpdate.SUCCESS:
41
12
  return {
42
13
  error: false,
@@ -1,24 +0,0 @@
1
- import { uploadConcepts } from "../routines";
2
-
3
- const initialState = {
4
- loading: false,
5
- };
6
-
7
- export const uploadConceptsFile = (state = initialState, { type, payload }) => {
8
- switch (type) {
9
- case uploadConcepts.TRIGGER:
10
- return state;
11
- case uploadConcepts.REQUEST:
12
- return { ...state, loading: true };
13
- case uploadConcepts.SUCCESS:
14
- return state;
15
- case uploadConcepts.FAILURE:
16
- return { ...state, error: payload };
17
- case uploadConcepts.FULFILL:
18
- return { ...state, loading: false };
19
- default:
20
- return state;
21
- }
22
- };
23
-
24
- export default uploadConceptsFile;
@@ -1,30 +0,0 @@
1
- import { call, put, takeLatest } from "redux-saga/effects";
2
- import { CONCEPTS } from "@truedat/core/routes";
3
- import { apiJsonPost, UPLOAD_JSON_OPTS } from "@truedat/core/services/api";
4
- import { uploadConcepts } from "../routines";
5
-
6
- export function* uploadConceptsSaga({ payload }) {
7
- try {
8
- const { action, method, href, lang, ...rest } = payload;
9
- const meta = { action, method, href, redirectUrl: CONCEPTS };
10
- yield put(uploadConcepts.request({ method, href, ...rest }));
11
- const { data: body } = rest || {};
12
- body.append("lang", lang);
13
- const { data } = yield call(apiJsonPost, href, body, UPLOAD_JSON_OPTS);
14
-
15
- yield put({ meta, ...uploadConcepts.success(data) });
16
- } catch (error) {
17
- if (error.response) {
18
- const { status, data } = error.response;
19
- yield put(uploadConcepts.failure({ status, data }));
20
- } else {
21
- yield put(uploadConcepts.failure(error.message));
22
- }
23
- } finally {
24
- yield put(uploadConcepts.fulfill());
25
- }
26
- }
27
-
28
- export function* uploadConceptsRequestsSaga() {
29
- yield takeLatest(uploadConcepts.TRIGGER, uploadConceptsSaga);
30
- }