@truedat/bg 7.13.5 → 7.13.7

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.13.5",
3
+ "version": "7.13.7",
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.13.5",
51
+ "@truedat/test": "7.13.7",
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": "a82fdfd07c75632206f6639dd7c3b3072a3a9379"
84
+ "gitHead": "7437522470d6e6eb11f9f5b472b822b23949cb74"
85
85
  }
@@ -5,6 +5,7 @@ import { Link } from "react-router";
5
5
  import { connect } from "react-redux";
6
6
  import { FormattedMessage } from "react-intl";
7
7
  import { useActiveRoute } from "@truedat/core/hooks";
8
+ import { config } from "@truedat/core/truedatConfig";
8
9
  import {
9
10
  CONCEPT_ARCHIVE,
10
11
  CONCEPT_EVENTS,
@@ -22,7 +23,12 @@ export const ConceptTabs = ({
22
23
  emptyImplementationLinks,
23
24
  createImplementation,
24
25
  createRawImplementation,
26
+ manageQualityRule,
27
+ viewQualityRule,
28
+ isAdmin,
25
29
  }) => {
30
+ const enableQualityRules = config?.enableQualityRules !== false;
31
+
26
32
  const archiveActive = useActiveRoute(CONCEPT_ARCHIVE);
27
33
  const conceptActive = useActiveRoute({
28
34
  path: CONCEPT_VERSION,
@@ -32,6 +38,13 @@ export const ConceptTabs = ({
32
38
  const rulesActive = useActiveRoute(CONCEPT_RULES);
33
39
  const implementationsActive = useActiveRoute(CONCEPT_LINKS_IMPLEMENTATIONS);
34
40
  const structureLinksActive = useActiveRoute(CONCEPT_LINKS_STRUCTURES);
41
+
42
+ console.clear();
43
+ console.log("enableQualityRules", enableQualityRules);
44
+ console.log("manageQualityRule", manageQualityRule);
45
+ console.log("viewQualityRule", viewQualityRule);
46
+ console.log("isAdmin", isAdmin);
47
+ console.log("rule_count", concept.rule_count);
35
48
 
36
49
  return _.isEmpty(concept) ? null : (
37
50
  <Menu attached="top" pointing secondary tabular>
@@ -61,14 +74,19 @@ export const ConceptTabs = ({
61
74
  <FormattedMessage id="tabs.bg.relations_business_concept" />
62
75
  </Menu.Item>
63
76
  )}
64
- <Menu.Item
65
- active={rulesActive}
66
- as={Link}
67
- to={linkTo.CONCEPT_RULES(concept)}
68
- replace
69
- >
70
- <FormattedMessage id="tabs.bg.qualityRules" />
71
- </Menu.Item>
77
+ {enableQualityRules &&
78
+ (isAdmin ||
79
+ manageQualityRule ||
80
+ (viewQualityRule && (concept?.rule_count ?? 0) > 0)) && (
81
+ <Menu.Item
82
+ active={rulesActive}
83
+ as={Link}
84
+ to={linkTo.CONCEPT_RULES(concept)}
85
+ replace
86
+ >
87
+ <FormattedMessage id="tabs.bg.qualityRules" />
88
+ </Menu.Item>
89
+ )}
72
90
  {(!emptyImplementationLinks ||
73
91
  createImplementation ||
74
92
  createRawImplementation) && (
@@ -107,6 +125,9 @@ ConceptTabs.propTypes = {
107
125
  emptyImplementationLinks: PropTypes.bool,
108
126
  createImplementation: PropTypes.object,
109
127
  createRawImplementation: PropTypes.object,
128
+ manageQualityRule: PropTypes.bool,
129
+ viewQualityRule: PropTypes.bool,
130
+ isAdmin: PropTypes.bool,
110
131
  };
111
132
 
112
133
  const mapStateToProps = ({
@@ -114,6 +135,7 @@ const mapStateToProps = ({
114
135
  conceptPermissions,
115
136
  conceptLinks,
116
137
  relationTags,
138
+ authentication,
117
139
  }) => ({
118
140
  emptyConceptTags: _.flow(
119
141
  _.filter(_.pathEq("value.target_type", "business_concept")),
@@ -128,6 +150,9 @@ const mapStateToProps = ({
128
150
  createRawImplementation: _.prop("create_raw_implementation")(
129
151
  conceptPermissions
130
152
  ),
153
+ manageQualityRule: _.prop("manage_quality_rule")(conceptPermissions),
154
+ viewQualityRule: _.prop("view_quality_rule")(conceptPermissions),
155
+ isAdmin: _.propEq("role", "admin")(authentication),
131
156
  });
132
157
 
133
158
  export default connect(mapStateToProps)(ConceptTabs);
@@ -1,33 +1,134 @@
1
- import { render } from "@truedat/test/render";
2
- import { ConceptTabs } from "../ConceptTabs";
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import ConceptTabs from "../ConceptTabs";
3
+ import { setConfig } from "@truedat/core/truedatConfig";
3
4
 
4
5
  describe("<ConceptTabs />", () => {
5
- const props = {
6
- concept: {
7
- id: "1",
8
- business_concept_id: "8",
9
- },
10
- emptyConceptTags: false,
11
- emptyImplementationLinks: false,
6
+ beforeEach(() => {
7
+ setConfig({ enableQualityRules: true });
8
+ });
9
+
10
+ afterEach(() => {
11
+ setConfig({});
12
+ });
13
+
14
+ const baseConcept = {
15
+ id: "1",
16
+ business_concept_id: "8",
12
17
  };
13
- it("matches the latest snapshot", () => {
14
- const { container } = render(<ConceptTabs {...props} />);
15
- expect(container).toMatchSnapshot();
18
+
19
+ const baseState = {
20
+ concept: baseConcept,
21
+ conceptLinks: [],
22
+ relationTags: [],
23
+ conceptPermissions: {},
24
+ authentication: { role: "user" },
25
+ };
26
+
27
+ it("matches the latest snapshot", async () => {
28
+ const rendered = render(<ConceptTabs />, { state: baseState });
29
+ await waitForLoad(rendered);
30
+ expect(rendered.container).toMatchSnapshot();
31
+ });
32
+
33
+ it("With concept tags and implementation links", async () => {
34
+ const state = {
35
+ ...baseState,
36
+ conceptLinks: [{ resource_type: "implementation" }],
37
+ relationTags: [{ value: { target_type: "business_concept" } }],
38
+ conceptPermissions: {
39
+ create_raw_implementation: { method: "POST" },
40
+ create_link_implementation: { method: "POST" },
41
+ create_implementation: { method: "POST" },
42
+ manage_quality_rule: { method: "POST" },
43
+ },
44
+ };
45
+ const rendered = render(<ConceptTabs />, { state });
46
+ await waitForLoad(rendered);
47
+ expect(rendered.container).toMatchSnapshot();
48
+ });
49
+
50
+ it("shows quality rules tab when user is admin", async () => {
51
+ const state = {
52
+ ...baseState,
53
+ authentication: { role: "admin" },
54
+ concept: { ...baseConcept, rule_count: 0 },
55
+ };
56
+ const rendered = render(<ConceptTabs />, { state });
57
+ await waitForLoad(rendered);
58
+ expect(rendered.queryByText(/tabs\.bg\.qualityRules/i)).toBeInTheDocument();
59
+ });
60
+
61
+ it("shows quality rules tab when user has manageQualityRule permission", async () => {
62
+ const state = {
63
+ ...baseState,
64
+ conceptPermissions: {
65
+ manage_quality_rule: { method: "POST" },
66
+ },
67
+ concept: { ...baseConcept, rule_count: 0 },
68
+ };
69
+ const rendered = render(<ConceptTabs />, { state });
70
+ await waitForLoad(rendered);
71
+ expect(rendered.queryByText(/tabs\.bg\.qualityRules/i)).toBeInTheDocument();
72
+ });
73
+
74
+ it("shows quality rules tab when user has viewQualityRule permission and rule_count > 0", async () => {
75
+ const state = {
76
+ ...baseState,
77
+ conceptPermissions: {
78
+ view_quality_rule: { method: "GET" },
79
+ },
80
+ concept: { ...baseConcept, rule_count: 5 },
81
+ };
82
+ const rendered = render(<ConceptTabs />, { state });
83
+ await waitForLoad(rendered);
84
+ expect(rendered.queryByText(/tabs\.bg\.qualityRules/i)).toBeInTheDocument();
16
85
  });
17
86
 
18
- it("With concept tags and implementation links", () => {
19
- const props = {
20
- concept: {
21
- id: "1",
22
- business_concept_id: "8",
87
+ it("does not show quality rules tab when user has viewQualityRule permission but rule_count is 0", async () => {
88
+ const state = {
89
+ ...baseState,
90
+ conceptPermissions: {
91
+ view_quality_rule: { method: "GET" },
23
92
  },
24
- emptyConceptTags: true,
25
- emptyImplementationLinks: true,
26
- createRawImplementation: { method: "POST" },
27
- createLinkImplementation: { method: "POST" },
28
- createImplementation: { method: "POST" },
29
- };
30
- const { container } = render(<ConceptTabs {...props} />);
31
- expect(container).toMatchSnapshot();
93
+ concept: { ...baseConcept, rule_count: 0 },
94
+ };
95
+ const rendered = render(<ConceptTabs />, { state });
96
+ await waitForLoad(rendered);
97
+ expect(rendered.queryByText(/tabs\.bg\.qualityRules/i)).not.toBeInTheDocument();
98
+ });
99
+
100
+ it("does not show quality rules tab when user has no permissions and no rules", async () => {
101
+ const state = {
102
+ ...baseState,
103
+ conceptPermissions: {},
104
+ concept: { ...baseConcept, rule_count: 0 },
105
+ };
106
+ const rendered = render(<ConceptTabs />, { state });
107
+ await waitForLoad(rendered);
108
+ expect(rendered.queryByText(/tabs\.bg\.qualityRules/i)).not.toBeInTheDocument();
109
+ });
110
+
111
+ it("does not show quality rules tab when enableQualityRules is false", async () => {
112
+ setConfig({ enableQualityRules: false });
113
+ const state = {
114
+ ...baseState,
115
+ authentication: { role: "admin" },
116
+ concept: { ...baseConcept, rule_count: 5 },
117
+ };
118
+ const rendered = render(<ConceptTabs />, { state });
119
+ await waitForLoad(rendered);
120
+ expect(rendered.queryByText(/tabs\.bg\.qualityRules/i)).not.toBeInTheDocument();
121
+ });
122
+
123
+ it("shows quality rules tab when enableQualityRules is undefined (defaults to true)", async () => {
124
+ setConfig({});
125
+ const state = {
126
+ ...baseState,
127
+ authentication: { role: "admin" },
128
+ concept: { ...baseConcept, rule_count: 0 },
129
+ };
130
+ const rendered = render(<ConceptTabs />, { state });
131
+ await waitForLoad(rendered);
132
+ expect(rendered.queryByText(/tabs\.bg\.qualityRules/i)).toBeInTheDocument();
32
133
  });
33
134
  });
@@ -137,13 +137,6 @@ exports[`<Concept /> matches the latest snapshot 1`] = `
137
137
  >
138
138
  tabs.bg.relations_data_field
139
139
  </a>
140
- <a
141
- class="item"
142
- data-discover="true"
143
- href="/concepts/1/versions/1/rules"
144
- >
145
- tabs.bg.qualityRules
146
- </a>
147
140
  <a
148
141
  class="item"
149
142
  data-discover="true"
@@ -527,13 +520,6 @@ exports[`<Concept /> matches the latest snapshot with grantView activated 1`] =
527
520
  >
528
521
  tabs.bg.relations_data_field
529
522
  </a>
530
- <a
531
- class="item"
532
- data-discover="true"
533
- href="/concepts/1/versions/1/rules"
534
- >
535
- tabs.bg.qualityRules
536
- </a>
537
523
  <a
538
524
  class="item"
539
525
  data-discover="true"
@@ -19,6 +19,13 @@ exports[`<ConceptTabs /> With concept tags and implementation links 1`] = `
19
19
  >
20
20
  tabs.bg.relations_data_field
21
21
  </a>
22
+ <a
23
+ class="item"
24
+ data-discover="true"
25
+ href="/concepts/8/versions/1/links/concepts"
26
+ >
27
+ tabs.bg.relations_business_concept
28
+ </a>
22
29
  <a
23
30
  class="item"
24
31
  data-discover="true"
@@ -70,27 +77,6 @@ exports[`<ConceptTabs /> matches the latest snapshot 1`] = `
70
77
  >
71
78
  tabs.bg.relations_data_field
72
79
  </a>
73
- <a
74
- class="item"
75
- data-discover="true"
76
- href="/concepts/8/versions/1/links/concepts"
77
- >
78
- tabs.bg.relations_business_concept
79
- </a>
80
- <a
81
- class="item"
82
- data-discover="true"
83
- href="/concepts/8/versions/1/rules"
84
- >
85
- tabs.bg.qualityRules
86
- </a>
87
- <a
88
- class="item"
89
- data-discover="true"
90
- href="/concepts/8/versions/1/links/implementations"
91
- >
92
- tabs.bg.qualityImplementations
93
- </a>
94
80
  <a
95
81
  class="item"
96
82
  data-discover="true"