@truedat/dd 8.13.0 → 8.13.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/dd",
3
- "version": "8.13.0",
3
+ "version": "8.13.1",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -54,7 +54,7 @@
54
54
  "@testing-library/jest-dom": "^6.6.3",
55
55
  "@testing-library/react": "^16.3.0",
56
56
  "@testing-library/user-event": "^14.6.1",
57
- "@truedat/test": "8.13.0",
57
+ "@truedat/test": "8.13.1",
58
58
  "identity-obj-proxy": "^3.0.0",
59
59
  "jest": "^29.7.0",
60
60
  "redux-saga-test-plan": "^4.0.6"
@@ -90,5 +90,5 @@
90
90
  "svg-pan-zoom": "^3.6.2",
91
91
  "swr": "^2.3.3"
92
92
  },
93
- "gitHead": "b9d1c2133cea6293e6a5ce5d198a4cd49133b4c1"
93
+ "gitHead": "09ce6d3a8693835de75577e43d99d86addb2edf7"
94
94
  }
@@ -2,18 +2,40 @@ import PropTypes from "prop-types";
2
2
  import { Link } from "react-router";
3
3
  import { linkTo } from "@truedat/core/routes";
4
4
 
5
- export const StructureNoteLink = ({ data_structure_id, external_id }) =>
6
- data_structure_id ? (
7
- <Link to={linkTo.STRUCTURE_NOTES({ id: data_structure_id })}>
8
- {external_id}
9
- </Link>
10
- ) : (
11
- external_id
5
+ const preferredLabel = ({ alias, name, external_id }) =>
6
+ typeof alias === "string" && alias.trim() !== ""
7
+ ? alias.trim()
8
+ : name || external_id;
9
+
10
+ export const StructureNoteLink = ({
11
+ alias,
12
+ data_structure_id,
13
+ external_id,
14
+ name,
15
+ }) => {
16
+ const label = preferredLabel({ alias, name, external_id });
17
+ const hasSecondaryExternalId =
18
+ external_id != null && external_id !== "" && external_id !== label;
19
+
20
+ return (
21
+ <>
22
+ {data_structure_id ? (
23
+ <Link to={linkTo.STRUCTURE_NOTES({ id: data_structure_id })}>
24
+ {label}
25
+ </Link>
26
+ ) : (
27
+ label
28
+ )}
29
+ {hasSecondaryExternalId ? <small>{external_id}</small> : null}
30
+ </>
12
31
  );
32
+ };
13
33
 
14
34
  StructureNoteLink.propTypes = {
35
+ alias: PropTypes.string,
15
36
  data_structure_id: PropTypes.number,
16
37
  external_id: PropTypes.string,
38
+ name: PropTypes.string,
17
39
  };
18
40
 
19
41
  export default StructureNoteLink;
@@ -41,4 +41,36 @@ describe("<StructureNoteLink />", () => {
41
41
  ).toBeInTheDocument();
42
42
  expect(rendered.getByText(/structure-100/i)).toBeInTheDocument();
43
43
  });
44
+
45
+ it("prefers a non-empty alias and renders external_id as secondary text", () => {
46
+ const rendered = render(
47
+ <StructureNoteLink
48
+ alias="Structure alias"
49
+ data_structure_id={42}
50
+ external_id="EXT-001"
51
+ name="Structure name"
52
+ />,
53
+ );
54
+
55
+ expect(
56
+ rendered.getByRole("link", { name: "Structure alias" }),
57
+ ).toHaveAttribute("href", "/structures/42/notes");
58
+ expect(rendered.getByText("EXT-001")).toBeInTheDocument();
59
+ });
60
+
61
+ it("falls back to name for an empty alias without duplicating external_id", () => {
62
+ const rendered = render(
63
+ <StructureNoteLink
64
+ alias=" "
65
+ data_structure_id={42}
66
+ external_id="EXT-001"
67
+ name="Structure name"
68
+ />,
69
+ );
70
+
71
+ expect(
72
+ rendered.getByRole("link", { name: "Structure name" }),
73
+ ).toBeInTheDocument();
74
+ expect(rendered.getByText("EXT-001")).toBeInTheDocument();
75
+ });
44
76
  });