@truedat/bg 7.8.6 → 7.9.1
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/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.9.1",
|
|
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.9.1",
|
|
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": "aa5c7a47f252393e66ebfb6ea31981221fe641bb"
|
|
85
85
|
}
|
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 () => {
|