@truedat/lm 7.7.0 → 7.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/lm",
3
- "version": "7.7.0",
3
+ "version": "7.7.1",
4
4
  "description": "Truedat Link Manager",
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.0",
51
+ "@truedat/test": "7.7.1",
52
52
  "identity-obj-proxy": "^3.0.0",
53
53
  "jest": "^29.7.0",
54
54
  "redux-saga-test-plan": "^4.0.6"
@@ -82,5 +82,5 @@
82
82
  "semantic-ui-react": "^3.0.0-beta.2",
83
83
  "swr": "^2.3.3"
84
84
  },
85
- "gitHead": "758c330b9a55bf81463dc4d97e4850d713ba8c76"
85
+ "gitHead": "b0bbab1ace5acb5a0c670137a51d21456f5eecae"
86
86
  }
@@ -1,18 +1,25 @@
1
1
  import { Link } from "react-router";
2
2
  import PropTypes from "prop-types";
3
+ import OriginLabel from "@truedat/core/components/OriginLabel";
3
4
  import { linkTo } from "@truedat/core/routes";
4
5
 
5
- export const ConceptLink = ({ resource_id: business_concept_id, name }) => (
6
+ export const ConceptLink = ({
7
+ resource_id: business_concept_id,
8
+ name,
9
+ origin,
10
+ }) => (
6
11
  <Link
7
12
  to={linkTo.CONCEPT_LINKS_STRUCTURES({ business_concept_id, id: "current" })}
8
13
  >
9
14
  {name}
15
+ <OriginLabel origin={origin} />
10
16
  </Link>
11
17
  );
12
18
 
13
19
  ConceptLink.propTypes = {
14
20
  resource_id: PropTypes.number,
15
21
  name: PropTypes.string,
22
+ origin: PropTypes.string,
16
23
  };
17
24
 
18
25
  export default ConceptLink;
@@ -12,8 +12,8 @@ import { Button } from "semantic-ui-react";
12
12
  import { createRelation, clearSelectedRelationTags } from "../routines";
13
13
  import TagTypeDropdownSelector from "./TagTypeDropdownSelector";
14
14
 
15
- const StructureSuggestions = React.lazy(() =>
16
- import("@truedat/dd/components/StructureSuggestions")
15
+ const StructureSuggestions = React.lazy(
16
+ () => import("@truedat/dd/components/StructureSuggestions")
17
17
  );
18
18
 
19
19
  const selectTagOptions = makeTagOptionsSelector("data_field");
@@ -45,6 +45,7 @@ export const ConceptSuggestionLinkForm = () => {
45
45
  target_id: selectedStructure.id,
46
46
  target_type: "data_structure",
47
47
  tag_ids: selectedRelationTags ? selectedRelationTags : [],
48
+ origin: "suggested",
48
49
  };
49
50
  dispatch(createRelation.trigger(structureLink));
50
51
  };
@@ -5,111 +5,120 @@ import { useParams } from "react-router";
5
5
  import { createRelation, clearSelectedRelationTags } from "../../routines";
6
6
 
7
7
  jest.mock("react-redux", () => ({
8
- useSelector: jest.fn(),
9
- useDispatch: jest.fn(),
8
+ useSelector: jest.fn(),
9
+ useDispatch: jest.fn(),
10
10
  }));
11
11
 
12
12
  jest.mock("react-router", () => ({
13
- useParams: jest.fn(),
13
+ useParams: jest.fn(),
14
14
  }));
15
15
 
16
16
  jest.mock("react-intl", () => ({
17
- useIntl: () => ({
18
- formatMessage: ({ id }) => id, // mock translated strings
19
- }),
17
+ useIntl: () => ({
18
+ formatMessage: ({ id }) => id, // mock translated strings
19
+ }),
20
20
  }));
21
21
 
22
22
  // Mock selector factory
23
23
  jest.mock("@truedat/core/selectors", () => ({
24
- makeTagOptionsSelector: jest.fn(() => jest.fn(() => [{ id: "tag1", name: "Tag 1" }])),
24
+ makeTagOptionsSelector: jest.fn(() =>
25
+ jest.fn(() => [{ id: "tag1", name: "Tag 1" }])
26
+ ),
25
27
  }));
26
28
 
27
29
  // Mock components
28
30
  jest.mock("@truedat/dd/components/StructureSuggestions", () =>
29
- jest.fn((props) => {
30
- // Include a button to simulate structure selection
31
- return (
32
- <div>
33
- <div>MockStructureSuggestions</div>
34
- <button onClick={() => props.handleSelectedStructure({ id: "structure123" })}>
35
- Select Structure
36
- </button>
37
- </div>
38
- );
39
- })
31
+ jest.fn((props) => {
32
+ // Include a button to simulate structure selection
33
+ return (
34
+ <div>
35
+ <div>MockStructureSuggestions</div>
36
+ <button
37
+ onClick={() => props.handleSelectedStructure({ id: "structure123" })}
38
+ >
39
+ Select Structure
40
+ </button>
41
+ </div>
42
+ );
43
+ })
40
44
  );
41
45
 
42
46
  jest.mock("../TagTypeDropdownSelector", () =>
43
- jest.fn(() => <div>MockTagTypeDropdownSelector</div>)
47
+ jest.fn(() => <div>MockTagTypeDropdownSelector</div>)
44
48
  );
45
49
 
46
50
  jest.mock("@truedat/core/components", () => ({
47
- HistoryBackButton: (props) => <button>{props.content}</button>,
51
+ HistoryBackButton: (props) => <button>{props.content}</button>,
48
52
  }));
49
53
 
50
54
  jest.mock("@truedat/core/routes", () => ({
51
- linkTo: {
52
- CONCEPT_LINKS_STRUCTURES: jest.fn(() => "/mocked/redirect/url"),
53
- },
55
+ linkTo: {
56
+ CONCEPT_LINKS_STRUCTURES: jest.fn(() => "/mocked/redirect/url"),
57
+ },
54
58
  }));
55
59
 
56
60
  describe("ConceptSuggestionLinkForm", () => {
57
- const mockDispatch = jest.fn();
58
-
59
- beforeEach(() => {
60
- jest.clearAllMocks();
61
-
62
- useParams.mockReturnValue({ business_concept_id: "bc1", id: "v1" });
63
- useDispatch.mockReturnValue(mockDispatch);
64
- useSelector.mockImplementation((selector) =>
65
- selector({
66
- selectedRelationTags: ["tag1"],
67
- })
68
- );
69
-
70
- clearSelectedRelationTags.trigger = jest.fn(() => ({ type: "CLEAR_TAGS" }));
71
- createRelation.trigger = jest.fn((payload) => ({ type: "CREATE_RELATION", payload }));
72
- });
73
-
74
- it("renders structure suggestions and tag dropdown", async () => {
75
- render(<ConceptSuggestionLinkForm />);
76
-
77
- await waitFor(() => {
78
- expect(screen.getByText("MockStructureSuggestions")).toBeInTheDocument();
79
- expect(screen.getByText("actions.create")).toBeDisabled();
80
- });
81
-
61
+ const mockDispatch = jest.fn();
62
+
63
+ beforeEach(() => {
64
+ jest.clearAllMocks();
65
+
66
+ useParams.mockReturnValue({ business_concept_id: "bc1", id: "v1" });
67
+ useDispatch.mockReturnValue(mockDispatch);
68
+ useSelector.mockImplementation((selector) =>
69
+ selector({
70
+ selectedRelationTags: ["tag1"],
71
+ })
72
+ );
73
+
74
+ clearSelectedRelationTags.trigger = jest.fn(() => ({ type: "CLEAR_TAGS" }));
75
+ createRelation.trigger = jest.fn((payload) => ({
76
+ type: "CREATE_RELATION",
77
+ payload,
78
+ }));
79
+ });
80
+
81
+ it("renders structure suggestions and tag dropdown", async () => {
82
+ render(<ConceptSuggestionLinkForm />);
83
+
84
+ await waitFor(() => {
85
+ expect(screen.getByText("MockStructureSuggestions")).toBeInTheDocument();
86
+ expect(screen.getByText("actions.create")).toBeDisabled();
82
87
  });
88
+ });
83
89
 
84
- it("dispatches createRelation on submit", async () => {
85
- render(<ConceptSuggestionLinkForm />);
86
-
87
- // Simulate structure selection
88
- fireEvent.click(screen.getByText("Select Structure"));
90
+ it("dispatches createRelation on submit", async () => {
91
+ render(<ConceptSuggestionLinkForm />);
89
92
 
90
- // Now the submit button should be enabled
91
- const createBtn = screen.getByText("actions.create");
92
- expect(createBtn).not.toBeDisabled();
93
+ // Simulate structure selection
94
+ fireEvent.click(screen.getByText("Select Structure"));
93
95
 
94
- fireEvent.click(createBtn);
96
+ // Now the submit button should be enabled
97
+ const createBtn = screen.getByText("actions.create");
98
+ expect(createBtn).not.toBeDisabled();
95
99
 
96
- expect(createRelation.trigger).toHaveBeenCalledWith({
97
- redirectUrl: "/mocked/redirect/url",
98
- source_id: "bc1",
99
- source_type: "business_concept",
100
- target_id: "structure123",
101
- target_type: "data_structure",
102
- tag_ids: ["tag1"],
103
- });
100
+ fireEvent.click(createBtn);
104
101
 
105
- expect(mockDispatch).toHaveBeenCalledWith(expect.objectContaining({ type: "CREATE_RELATION" }));
102
+ expect(createRelation.trigger).toHaveBeenCalledWith({
103
+ redirectUrl: "/mocked/redirect/url",
104
+ source_id: "bc1",
105
+ source_type: "business_concept",
106
+ target_id: "structure123",
107
+ target_type: "data_structure",
108
+ tag_ids: ["tag1"],
109
+ origin: "suggested",
106
110
  });
107
111
 
108
- it("dispatches clearSelectedRelationTags on unmount", () => {
109
- const { unmount } = render(<ConceptSuggestionLinkForm />);
110
- unmount();
112
+ expect(mockDispatch).toHaveBeenCalledWith(
113
+ expect.objectContaining({ type: "CREATE_RELATION" })
114
+ );
115
+ });
111
116
 
112
- expect(clearSelectedRelationTags.trigger).toHaveBeenCalled();
113
- expect(mockDispatch).toHaveBeenCalledWith({ type: "CLEAR_TAGS" });
114
- });
117
+ it("dispatches clearSelectedRelationTags on unmount", () => {
118
+ const { unmount } = render(<ConceptSuggestionLinkForm />);
119
+ unmount();
120
+
121
+ expect(clearSelectedRelationTags.trigger).toHaveBeenCalled();
122
+ expect(mockDispatch).toHaveBeenCalledWith({ type: "CLEAR_TAGS" });
123
+ });
115
124
  });
@@ -16,6 +16,7 @@ const pickFields = _.pick([
16
16
  "target_type",
17
17
  "context",
18
18
  "tags",
19
+ "origin",
19
20
  ]);
20
21
 
21
22
  const relations = (state = initialState, { type, payload, meta }) => {
@@ -39,6 +39,7 @@ describe("sagas: createRelationSaga", () => {
39
39
  context: {},
40
40
  tag_ids: [],
41
41
  redirectUrl,
42
+ origin: "some origin",
42
43
  };
43
44
  const meta = { redirectUrl };
44
45
  const relation = _.pick([
@@ -48,6 +49,7 @@ describe("sagas: createRelationSaga", () => {
48
49
  "target_id",
49
50
  "target_type",
50
51
  "tag_ids",
52
+ "origin",
51
53
  ])(payload);
52
54
  const request_data = {
53
55
  relation,
@@ -13,6 +13,7 @@ export function* createRelationSaga({ payload }) {
13
13
  "target_id",
14
14
  "target_type",
15
15
  "tag_ids",
16
+ "origin",
16
17
  ])(payload);
17
18
 
18
19
  const redirectUrl = _.prop("redirectUrl")(payload);