@truedat/bg 7.9.0 → 7.10.0
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 +3 -3
- package/src/concepts/api.js +3 -2
- package/src/concepts/components/ConceptLinksUploadButton.js +61 -0
- package/src/concepts/components/ConceptsUploadEventsTable.js +55 -34
- package/src/concepts/components/__tests__/ConceptLinksUploadButton.spec.js +36 -0
- package/src/concepts/components/__tests__/__snapshots__/ConceptLinksUploadButton.spec.js.snap +15 -0
- package/src/concepts/hooks/useConcepts.js +7 -0
- package/src/concepts/relations/components/ConceptSelector.js +7 -3
- package/src/concepts/relations/components/__tests__/__snapshots__/ConceptSelector.spec.js.snap +9 -0
- package/src/concepts/routines.js +1 -0
- package/src/concepts/selectors/messages.js +41 -27
- package/src/hooks/useDomains.js +17 -1
- package/src/taxonomy/api.js +2 -1
- package/src/taxonomy/components/DomainForm.js +2 -2
- package/src/taxonomy/components/EditDomain.js +10 -2
- package/src/taxonomy/components/__tests__/DomainForm.spec.js +7 -2
- package/src/taxonomy/components/__tests__/EditDomain.spec.js +8 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/bg",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.10.0",
|
|
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.
|
|
51
|
+
"@truedat/test": "7.10.0",
|
|
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": "
|
|
84
|
+
"gitHead": "3686b363b2a2218fe3ddb5782df9fe51fabf75e1"
|
|
85
85
|
}
|
package/src/concepts/api.js
CHANGED
|
@@ -10,8 +10,8 @@ const API_BUSINESS_CONCEPT_VERSIONS_SEARCH =
|
|
|
10
10
|
const API_BUSINESS_CONCEPT_VERSIONS_UPLOAD =
|
|
11
11
|
"/api/business_concept_versions/upload";
|
|
12
12
|
const API_CONCEPT_ARCHIVE = "/api/business_concepts/:id/versions";
|
|
13
|
-
const API_CONCEPT_LINKS_DOWNLOAD =
|
|
14
|
-
|
|
13
|
+
const API_CONCEPT_LINKS_DOWNLOAD = "/api/business_concept_versions/links/download";
|
|
14
|
+
const API_CONCEPT_LINKS_UPLOAD = "/api/relations/links/upload";
|
|
15
15
|
const API_CONCEPT_FILTERS = "/api/business_concept_filters/search";
|
|
16
16
|
const API_CONCEPT_SHARED_DOMAINS = "/api/business_concepts/:id/shared_domains";
|
|
17
17
|
const API_BUSINESS_CONCEPT_BULK_UPDATE =
|
|
@@ -30,6 +30,7 @@ export {
|
|
|
30
30
|
API_BUSINESS_CONCEPT_VERSIONS_UPLOAD,
|
|
31
31
|
API_CONCEPT_ARCHIVE,
|
|
32
32
|
API_CONCEPT_LINKS_DOWNLOAD,
|
|
33
|
+
API_CONCEPT_LINKS_UPLOAD,
|
|
33
34
|
API_CONCEPT_FILTERS,
|
|
34
35
|
API_CONCEPT_SHARED_DOMAINS,
|
|
35
36
|
API_BUSINESS_CONCEPT_BULK_UPDATE,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Button } from "semantic-ui-react";
|
|
2
|
+
import { FormattedMessage, useIntl } from "react-intl";
|
|
3
|
+
import { UploadModal } from "@truedat/core/components";
|
|
4
|
+
import { useConceptLinksUpload } from "../hooks/useConcepts";
|
|
5
|
+
import { useWebContext } from "@truedat/core/webContext";
|
|
6
|
+
import { getUploadAlertMessage } from "../selectors/messages";
|
|
7
|
+
|
|
8
|
+
export const ConceptLinksUploadButton = () => {
|
|
9
|
+
const { formatMessage } = useIntl();
|
|
10
|
+
const { trigger: triggerUpload, isMutating: loading } =
|
|
11
|
+
useConceptLinksUpload();
|
|
12
|
+
const { setAlertMessage } = useWebContext();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<UploadModal
|
|
16
|
+
icon="upload"
|
|
17
|
+
trigger={
|
|
18
|
+
<Button
|
|
19
|
+
secondary
|
|
20
|
+
floated="right"
|
|
21
|
+
icon="upload"
|
|
22
|
+
loading={loading}
|
|
23
|
+
data-tooltip={formatMessage({
|
|
24
|
+
id: "concepts.actions.upload_links.tooltip",
|
|
25
|
+
})}
|
|
26
|
+
/>
|
|
27
|
+
}
|
|
28
|
+
header={
|
|
29
|
+
<FormattedMessage id="concepts.actions.upload_links.confirmation.header" />
|
|
30
|
+
}
|
|
31
|
+
content={
|
|
32
|
+
<FormattedMessage id="concepts.actions.upload.confirmation.content" />
|
|
33
|
+
}
|
|
34
|
+
param="relations"
|
|
35
|
+
handleSubmit={(data) => {
|
|
36
|
+
data.append("source", "business_concept");
|
|
37
|
+
data.append("target", "data_structure");
|
|
38
|
+
triggerUpload(data)
|
|
39
|
+
.then(({ status, data }) => {
|
|
40
|
+
const alertMessage = getUploadAlertMessage({ status, data });
|
|
41
|
+
console.log("alertMessage --->", alertMessage);
|
|
42
|
+
setAlertMessage(alertMessage);
|
|
43
|
+
})
|
|
44
|
+
.catch((error) => {
|
|
45
|
+
console.log("error --->", error);
|
|
46
|
+
if (error.response) {
|
|
47
|
+
const { status, data } = error.response;
|
|
48
|
+
const alertMessage = getUploadAlertMessage({ status, data });
|
|
49
|
+
console.log("error response alertMessage --->", alertMessage);
|
|
50
|
+
setAlertMessage(alertMessage);
|
|
51
|
+
} else {
|
|
52
|
+
console.log("error.message --->", error.message);
|
|
53
|
+
setAlertMessage(error.message);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default ConceptLinksUploadButton;
|
|
@@ -16,18 +16,21 @@ const getColumnsWithData = (conceptsResults, columns) =>
|
|
|
16
16
|
)(columns);
|
|
17
17
|
|
|
18
18
|
const messagesImp = (data) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
const errors = data?.errors ?? [];
|
|
20
|
+
return _.map((error) => {
|
|
21
|
+
if (!error || !error.body)
|
|
22
|
+
return {
|
|
23
|
+
id: "unknown_error",
|
|
24
|
+
context: {},
|
|
25
|
+
defaultMessage: "concepts.upload.failed.success.errors",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
id: error.body.message ?? "unknown_error",
|
|
30
|
+
context: { ...error.body.context } ?? {},
|
|
31
|
+
defaultMessage: "concepts.upload.failed.success.errors",
|
|
32
|
+
};
|
|
33
|
+
}, errors);
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
const ConceptsUploadEventsTable = ({ getColumns }) => {
|
|
@@ -38,33 +41,51 @@ const ConceptsUploadEventsTable = ({ getColumns }) => {
|
|
|
38
41
|
const events =
|
|
39
42
|
data && !loading
|
|
40
43
|
? _.reduce(
|
|
41
|
-
(acc, event) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
(acc, event) => {
|
|
45
|
+
const eventKey = `${event.task_reference}_${event.status}`;
|
|
46
|
+
|
|
47
|
+
const node = event.node ?? "";
|
|
48
|
+
const hasErrors =
|
|
49
|
+
event.response?.errors && !_.isEmpty(event.response.errors);
|
|
50
|
+
|
|
51
|
+
const messageId = _.startsWith("lm@", node)
|
|
52
|
+
? hasErrors
|
|
53
|
+
? "concepts.upload.success.header_with_errors_without_update"
|
|
54
|
+
: "concepts.upload.success.header"
|
|
55
|
+
: hasErrors
|
|
56
|
+
? "concepts.upload.success.header_with_errors"
|
|
57
|
+
: "concepts.upload.success.header";
|
|
58
|
+
|
|
59
|
+
const translatedHeader = event.response
|
|
60
|
+
? formatMessage(
|
|
61
|
+
{ id: messageId },
|
|
62
|
+
{
|
|
63
|
+
count_created: event.response.created?.length ?? 0,
|
|
64
|
+
count_updated: event.response.updated?.length ?? 0,
|
|
65
|
+
count_errors: event.response.errors?.length ?? 0,
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
: "";
|
|
69
|
+
|
|
70
|
+
const translatedErrors = _.map((error) =>
|
|
71
|
+
formatMessage(
|
|
72
|
+
{ id: error.id ?? "unknown_error" },
|
|
73
|
+
error.context ?? {}
|
|
74
|
+
)
|
|
75
|
+
)(messagesImp(event.response));
|
|
76
|
+
|
|
77
|
+
acc[eventKey] = {
|
|
44
78
|
...event,
|
|
45
79
|
response: {
|
|
46
80
|
...event.response,
|
|
47
|
-
translatedHeader
|
|
48
|
-
|
|
49
|
-
: formatMessage(
|
|
50
|
-
{
|
|
51
|
-
id: _.isEmpty(event.response.errors)
|
|
52
|
-
? "concepts.upload.success.header"
|
|
53
|
-
: "concepts.upload.success.header_with_errors",
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
count_created: event.response.created.length,
|
|
57
|
-
count_updated: event.response.updated.length,
|
|
58
|
-
count_errors: event.response.errors.length,
|
|
59
|
-
}
|
|
60
|
-
),
|
|
61
|
-
translatedErrors: _.map((error) =>
|
|
62
|
-
formatMessage({ id: error.id }, error.context)
|
|
63
|
-
)(messagesImp(event.response)),
|
|
81
|
+
translatedHeader,
|
|
82
|
+
translatedErrors,
|
|
64
83
|
},
|
|
65
84
|
expanded: false,
|
|
66
|
-
}
|
|
67
|
-
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return acc;
|
|
88
|
+
},
|
|
68
89
|
{},
|
|
69
90
|
data.data
|
|
70
91
|
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { waitFor } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { render, waitForLoad } from "@truedat/test/render";
|
|
4
|
+
import { ConceptLinksUploadButton } from "../ConceptLinksUploadButton";
|
|
5
|
+
|
|
6
|
+
jest.mock("react-dropzone", () => ({
|
|
7
|
+
useDropzone: jest.fn(() => ({
|
|
8
|
+
getRootProps: jest.fn(),
|
|
9
|
+
getInputProps: jest.fn(),
|
|
10
|
+
isDragActive: false,
|
|
11
|
+
open: jest.fn(),
|
|
12
|
+
})),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock("@truedat/core/hooks", () => ({
|
|
16
|
+
useAuthorized: jest.fn(() => true),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const props = {
|
|
20
|
+
loading: false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe("<ConceptLinksUploadButton />", () => {
|
|
24
|
+
it("matches the latest snapshot", async () => {
|
|
25
|
+
const user = userEvent.setup({ delay: null });
|
|
26
|
+
const rendered = render(<ConceptLinksUploadButton {...props} />);
|
|
27
|
+
await waitForLoad(rendered);
|
|
28
|
+
|
|
29
|
+
await user.click(rendered.getByRole("button"));
|
|
30
|
+
await waitFor(() =>
|
|
31
|
+
expect(rendered.getByRole("presentation")).toBeInTheDocument()
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect(rendered.container).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`<ConceptLinksUploadButton /> matches the latest snapshot 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<button
|
|
6
|
+
class="ui icon secondary right floated button"
|
|
7
|
+
data-tooltip="concepts.actions.upload_links.tooltip"
|
|
8
|
+
>
|
|
9
|
+
<i
|
|
10
|
+
aria-hidden="true"
|
|
11
|
+
class="upload icon"
|
|
12
|
+
/>
|
|
13
|
+
</button>
|
|
14
|
+
</div>
|
|
15
|
+
`;
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
API_BUSINESS_CONCEPT_VERSIONS_SEARCH,
|
|
10
10
|
API_BUSINESS_CONCEPT_VERSIONS_ACTIONS,
|
|
11
11
|
API_BUSINESS_CONCEPT_VERSIONS_UPLOAD,
|
|
12
|
+
API_CONCEPT_LINKS_UPLOAD,
|
|
12
13
|
} from "../api";
|
|
13
14
|
|
|
14
15
|
function saveFile({ data, headers }) {
|
|
@@ -60,3 +61,9 @@ export const useConceptsUpload = () => {
|
|
|
60
61
|
apiJsonPost(url, arg)
|
|
61
62
|
);
|
|
62
63
|
};
|
|
64
|
+
|
|
65
|
+
export const useConceptLinksUpload = () => {
|
|
66
|
+
return useSWRMutations(API_CONCEPT_LINKS_UPLOAD, (url, { arg }) =>
|
|
67
|
+
apiJsonPost(url, arg)
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import ConceptsPagination from "../../components/ConceptsPagination";
|
|
19
19
|
import { mapStatusColor } from "../../constants/mappings";
|
|
20
20
|
import { translations } from "../../utils/filterOptions";
|
|
21
|
+
import ConceptLinksUploadButton from "../../components/ConceptLinksUploadButton";
|
|
21
22
|
|
|
22
23
|
import {
|
|
23
24
|
useConceptLinksDownload,
|
|
@@ -103,7 +104,7 @@ export function ConceptSelectorContent({
|
|
|
103
104
|
)(concept)
|
|
104
105
|
: false;
|
|
105
106
|
};
|
|
106
|
-
|
|
107
|
+
|
|
107
108
|
return (
|
|
108
109
|
<>
|
|
109
110
|
{showTitle && (
|
|
@@ -112,7 +113,8 @@ export function ConceptSelectorContent({
|
|
|
112
113
|
</label>
|
|
113
114
|
)}
|
|
114
115
|
<Segment>
|
|
115
|
-
{conceptsActions?.downloadLinks && (
|
|
116
|
+
{conceptsActions?.downloadLinks && (
|
|
117
|
+
<>
|
|
116
118
|
<Button
|
|
117
119
|
icon="download"
|
|
118
120
|
floated="right"
|
|
@@ -122,7 +124,9 @@ export function ConceptSelectorContent({
|
|
|
122
124
|
data-tooltip={formatMessage({
|
|
123
125
|
id: "concepts.actions.downloadLinks.tooltip",
|
|
124
126
|
})}
|
|
125
|
-
/>
|
|
127
|
+
/>
|
|
128
|
+
<ConceptLinksUploadButton />
|
|
129
|
+
</>
|
|
126
130
|
)}
|
|
127
131
|
<SearchWidget />
|
|
128
132
|
{!_.isEmpty(concepts) || selectedConcept ? (
|
package/src/concepts/relations/components/__tests__/__snapshots__/ConceptSelector.spec.js.snap
CHANGED
|
@@ -17,6 +17,15 @@ exports[`<ConceptSelector /> matches the latest snapshot 1`] = `
|
|
|
17
17
|
class="download icon"
|
|
18
18
|
/>
|
|
19
19
|
</button>
|
|
20
|
+
<button
|
|
21
|
+
class="ui icon secondary right floated button"
|
|
22
|
+
data-tooltip="concepts.actions.upload_links.tooltip"
|
|
23
|
+
>
|
|
24
|
+
<i
|
|
25
|
+
aria-hidden="true"
|
|
26
|
+
class="upload icon"
|
|
27
|
+
/>
|
|
28
|
+
</button>
|
|
20
29
|
<div
|
|
21
30
|
class="ui action left icon input"
|
|
22
31
|
>
|
package/src/concepts/routines.js
CHANGED
|
@@ -5,6 +5,7 @@ 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");
|
|
8
9
|
|
|
9
10
|
export const bulkUpdate = createRoutine("BULK_UPDATE");
|
|
10
11
|
export const bulkUpdateQuery = createRoutine("BULK_UPDATE_QUERY");
|
|
@@ -2,31 +2,45 @@ import _ from "lodash/fp";
|
|
|
2
2
|
import { CONCEPTS_BULK_UPLOAD_EVENTS } from "@truedat/core/routes";
|
|
3
3
|
|
|
4
4
|
export const getUploadAlertMessage = ({ status, data }) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
if (status == 400 && !_.prop("errors")(data)) {
|
|
20
|
+
return {
|
|
21
|
+
error: true,
|
|
22
|
+
header: "concepts.upload.failed.header.default",
|
|
23
|
+
content: `concepts.upload.failed.${
|
|
24
|
+
_.path("error.error")(data) || _.prop("error")(data)
|
|
25
|
+
}`,
|
|
26
|
+
icon: "attention",
|
|
27
|
+
text: "",
|
|
28
|
+
fields: _.prop("error")(data),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (status != 500 && !_.prop("errors")(data)) {
|
|
33
|
+
return {
|
|
34
|
+
error: true,
|
|
35
|
+
header: "concepts.upload.failed.header",
|
|
36
|
+
content: `concepts.upload.failed.${
|
|
37
|
+
_.path("error.error")(data) || _.prop("error")(data)
|
|
38
|
+
}`,
|
|
39
|
+
icon: "attention",
|
|
40
|
+
text: "",
|
|
41
|
+
fields: _.prop("error")(data),
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
package/src/hooks/useDomains.js
CHANGED
|
@@ -8,7 +8,11 @@ import {
|
|
|
8
8
|
apiJsonPatch,
|
|
9
9
|
apiJsonDelete,
|
|
10
10
|
} from "@truedat/core/services/api";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
API_DOMAINS,
|
|
13
|
+
API_DOMAIN,
|
|
14
|
+
API_DOMAIN_PARENTABLE_IDS,
|
|
15
|
+
} from "../taxonomy/api";
|
|
12
16
|
|
|
13
17
|
export const useDomains = () => {
|
|
14
18
|
const toApiPath = compile(API_DOMAINS, "api");
|
|
@@ -34,6 +38,18 @@ export const useDomain = (id) => {
|
|
|
34
38
|
};
|
|
35
39
|
};
|
|
36
40
|
|
|
41
|
+
export const useDomainParentableIds = (id) => {
|
|
42
|
+
const toApiPath = compile(API_DOMAIN_PARENTABLE_IDS, "api");
|
|
43
|
+
const url = toApiPath({ id: `${id}` });
|
|
44
|
+
const { data, error } = useSWR(url, apiJson);
|
|
45
|
+
return {
|
|
46
|
+
data: data?.data?.data,
|
|
47
|
+
actions: data?.data?._actions,
|
|
48
|
+
error,
|
|
49
|
+
loading: !error && !data,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
37
53
|
export const useDomainCreate = () => {
|
|
38
54
|
const toApiPath = compile(API_DOMAINS, "api");
|
|
39
55
|
const url = toApiPath();
|
package/src/taxonomy/api.js
CHANGED
|
@@ -46,7 +46,7 @@ const DEFAULTS = {
|
|
|
46
46
|
domain_group: null,
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export const DomainForm = ({ domain = {}, onSubmit }) => {
|
|
49
|
+
export const DomainForm = ({ domain = {}, parentableIds = [], onSubmit }) => {
|
|
50
50
|
const { data: domains } = useDomains();
|
|
51
51
|
const { formatMessage } = useIntl();
|
|
52
52
|
const { handleSubmit, control, formState, watch } = useForm({
|
|
@@ -67,7 +67,6 @@ export const DomainForm = ({ domain = {}, onSubmit }) => {
|
|
|
67
67
|
domain?.domain_group?.status === "root" || !domain?.domain_group;
|
|
68
68
|
|
|
69
69
|
const { errors, isDirty, isValid } = formState;
|
|
70
|
-
const parentableIds = domain.parentable_ids || [];
|
|
71
70
|
const domainParentOptions =
|
|
72
71
|
domain?.id && domains ? getDomainParentOptions(parentableIds)(domains) : [];
|
|
73
72
|
|
|
@@ -232,6 +231,7 @@ export const DomainForm = ({ domain = {}, onSubmit }) => {
|
|
|
232
231
|
|
|
233
232
|
DomainForm.propTypes = {
|
|
234
233
|
domain: PropTypes.object,
|
|
234
|
+
parentableIds: PropTypes.array,
|
|
235
235
|
onSubmit: PropTypes.func.isRequired,
|
|
236
236
|
};
|
|
237
237
|
|
|
@@ -8,11 +8,15 @@ import { linkTo } from "@truedat/core/routes";
|
|
|
8
8
|
import { useQuery } from "@apollo/client";
|
|
9
9
|
import { DOMAINS_QUERY } from "@truedat/core/api/queries";
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
useDomainUpdate,
|
|
13
|
+
useDomainParentableIds,
|
|
14
|
+
} from "../../hooks/useDomains";
|
|
12
15
|
import DomainForm from "./DomainForm";
|
|
13
16
|
|
|
14
17
|
export const EditDomain = ({ domain }) => {
|
|
15
18
|
const { trigger: updateDomain } = useDomainUpdate(domain.id);
|
|
19
|
+
const { data: parentableIds } = useDomainParentableIds(domain.id);
|
|
16
20
|
|
|
17
21
|
const navigate = useNavigate();
|
|
18
22
|
const { client } = useQuery(DOMAINS_QUERY, {
|
|
@@ -36,7 +40,11 @@ export const EditDomain = ({ domain }) => {
|
|
|
36
40
|
<FormattedMessage id="domain.actions.edit.header" />
|
|
37
41
|
</Header.Content>
|
|
38
42
|
</Header>
|
|
39
|
-
<DomainForm
|
|
43
|
+
<DomainForm
|
|
44
|
+
onSubmit={handleUpdateDomain}
|
|
45
|
+
domain={domain}
|
|
46
|
+
parentableIds={parentableIds}
|
|
47
|
+
/>
|
|
40
48
|
</Container>
|
|
41
49
|
);
|
|
42
50
|
};
|
|
@@ -174,10 +174,15 @@ describe("<DomainForm />", () => {
|
|
|
174
174
|
|
|
175
175
|
it("should generate domain parent options", async () => {
|
|
176
176
|
useDomains.mockImplementation(() => ({ data }));
|
|
177
|
-
const domain = { id: 2
|
|
177
|
+
const domain = { id: 2 };
|
|
178
|
+
const parentableIds = [1, 5, 6, 7];
|
|
178
179
|
|
|
179
180
|
const rendered = render(
|
|
180
|
-
<DomainForm
|
|
181
|
+
<DomainForm
|
|
182
|
+
domain={domain}
|
|
183
|
+
parentableIds={parentableIds}
|
|
184
|
+
onSubmit={jest.fn()}
|
|
185
|
+
/>
|
|
181
186
|
);
|
|
182
187
|
await waitForLoad(rendered);
|
|
183
188
|
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { render, waitForLoad } from "@truedat/test/render";
|
|
2
2
|
import { domainsMock } from "@truedat/test/mocks";
|
|
3
3
|
import { EditDomain } from "../EditDomain";
|
|
4
|
+
import { useDomainParentableIds } from "../../../hooks/useDomains";
|
|
4
5
|
|
|
5
|
-
jest.mock("../../../hooks/useDomains")
|
|
6
|
+
jest.mock("../../../hooks/useDomains", () => ({
|
|
7
|
+
...jest.requireActual("../../../hooks/useDomains"),
|
|
8
|
+
useDomainParentableIds: jest.fn(() => {}),
|
|
9
|
+
}));
|
|
6
10
|
|
|
7
11
|
const renderOpts = {
|
|
8
12
|
mocks: [
|
|
@@ -14,6 +18,9 @@ const renderOpts = {
|
|
|
14
18
|
};
|
|
15
19
|
|
|
16
20
|
describe("<EditDomain />", () => {
|
|
21
|
+
useDomainParentableIds.mockImplementation(() => ({
|
|
22
|
+
data: [],
|
|
23
|
+
}));
|
|
17
24
|
const domain = { id: 1, name: "nn", description: "dd" };
|
|
18
25
|
|
|
19
26
|
it("matches the latest snapshot", async () => {
|