@truedat/dd 7.0.1 → 7.0.3

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": "7.0.1",
3
+ "version": "7.0.3",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -34,7 +34,7 @@
34
34
  "@testing-library/jest-dom": "^5.16.5",
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/user-event": "^13.2.1",
37
- "@truedat/test": "7.0.1",
37
+ "@truedat/test": "7.0.3",
38
38
  "babel-jest": "^28.1.0",
39
39
  "babel-plugin-dynamic-import-node": "^2.3.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
@@ -88,9 +88,9 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "@apollo/client": "^3.7.1",
91
- "@truedat/auth": "7.0.1",
92
- "@truedat/core": "7.0.1",
93
- "@truedat/df": "7.0.1",
91
+ "@truedat/auth": "7.0.3",
92
+ "@truedat/core": "7.0.3",
93
+ "@truedat/df": "7.0.3",
94
94
  "lodash": "^4.17.21",
95
95
  "moment": "^2.29.4",
96
96
  "path-to-regexp": "^1.7.0",
@@ -115,5 +115,5 @@
115
115
  "react-dom": ">= 16.8.6 < 17",
116
116
  "semantic-ui-react": ">= 2.0.3 < 2.2"
117
117
  },
118
- "gitHead": "fff3313b142abb69e4d4139e0b6fd85d1af1a898"
118
+ "gitHead": "871005135545e304fa6ba9a5d49fa31b46e28a7c"
119
119
  }
@@ -25,40 +25,33 @@ export const StructureGrantCartUserSelector = ({
25
25
  const [domainIds, setDomainIds] = useState([]);
26
26
  const [selectedRoles, setSelectedRoles] = useState([]);
27
27
  const [selectedRoleIds, setSelectedRoleIds] = useState([]);
28
-
29
- const [userId, setUserId] = useState(_.path("user.id")(grantRequestsCart));
28
+ const [userId, setUserId] = useState(null);
30
29
 
31
30
  const { modificationGrant } = grantRequestsCart;
32
31
  const updateGrant = !_.isEmpty(modificationGrant);
33
-
34
32
  const domainActions = ["publishGrantRequest"];
35
33
 
36
34
  const { data: roles } = useRoles();
37
35
 
36
+ useEffect(() => {
37
+ if (!_.isNil(modificationGrant?.user_id)) {
38
+ selectUser(modificationGrant?.user_id);
39
+ } else if (!_.isNil(grantRequestsCart?.user?.id) && !_.isEmpty(options)) {
40
+ _.flow(
41
+ _.find({ value: userId }),
42
+ _.pathOr(null, "value"),
43
+ selectUser
44
+ )(options);
45
+ }
46
+ }, [grantRequestsCart?.user?.id, modificationGrant?.user_id, options]);
47
+
38
48
  useEffect(() => {
39
49
  updateGrantRequestUser({
40
50
  id: userId,
41
51
  valid:
42
52
  !thirdParty || (thirdParty && !(_.isNil(userId) && _.isEmpty(userId))),
43
53
  });
44
- if (updateGrant && modificationGrant.user_id)
45
- setUserId(modificationGrant.user_id);
46
- }, [
47
- modificationGrant,
48
- thirdParty,
49
- updateGrant,
50
- updateGrantRequestUser,
51
- userId,
52
- ]);
53
-
54
- useEffect(() => {
55
- _.flow(
56
- _.filter({ value: userId }),
57
- _.first,
58
- _.pathOr(null, "value"),
59
- selectUser
60
- )(options);
61
- }, [userId, options]);
54
+ }, [thirdParty, updateGrantRequestUser, userId]);
62
55
 
63
56
  useEffect(() => {
64
57
  _.flow(
@@ -145,7 +138,6 @@ export const StructureGrantCartUserSelector = ({
145
138
  domains={domainIds}
146
139
  roles={selectedRoleIds}
147
140
  permission="allow_foreign_grant_request"
148
- hideLoading
149
141
  />
150
142
  <Form.Dropdown
151
143
  placeholder={formatMessage({
@@ -98,9 +98,12 @@ StructureTabPane.propTypes = {
98
98
  tabVisibility: PropTypes.object,
99
99
  };
100
100
 
101
- const mapStateToProps = (state, { match: { path } }) => {
101
+ const mapStateToProps = (
102
+ { structureTabsOrder, ...state },
103
+ { match: { path } }
104
+ ) => {
102
105
  const tabVisibility = getTabVisibility(state);
103
- const activeTab = getActiveTab(tabVisibility, path);
106
+ const activeTab = getActiveTab(tabVisibility, path, structureTabsOrder);
104
107
  return {
105
108
  tabVisibility,
106
109
  activeTab,
@@ -3,6 +3,8 @@ import { Route, Switch } from "react-router-dom";
3
3
  import {
4
4
  STRUCTURE,
5
5
  STRUCTURE_CHILDREN,
6
+ STRUCTURE_FIELDS,
7
+ STRUCTURE_VERSION_FIELDS,
6
8
  STRUCTURE_EVENTS,
7
9
  STRUCTURE_GRANTS,
8
10
  STRUCTURE_IMPACT,
@@ -24,6 +26,7 @@ import StructureTabPane from "./StructureTabPane";
24
26
  export const StructureTabPaneRoutes = ({}) => (
25
27
  <Switch>
26
28
  <Route path={STRUCTURE_VERSION_VERSIONS} component={StructureTabPane} />
29
+ <Route path={STRUCTURE_VERSION_FIELDS} component={StructureTabPane} />
27
30
  <Route path={STRUCTURE_VERSION} component={StructureTabPane} />
28
31
  <Route path={STRUCTURE_PROFILE} component={StructureTabPane} />
29
32
  <Route path={STRUCTURE_STRUCTURE_LINKS} component={StructureTabPane} />
@@ -36,6 +39,7 @@ export const StructureTabPaneRoutes = ({}) => (
36
39
  <Route path={STRUCTURE_MEMBERS} component={StructureTabPane} />
37
40
  <Route path={STRUCTURE_RULES} component={StructureTabPane} />
38
41
  <Route path={STRUCTURE_CHILDREN} component={StructureTabPane} />
42
+ <Route path={STRUCTURE_FIELDS} component={StructureTabPane} />
39
43
  <Route path={STRUCTURE_PARENTS} component={StructureTabPane} />
40
44
  <Route path={STRUCTURE_LINEAGE} component={StructureTabPane} />
41
45
  <Route path={STRUCTURE_IMPACT} component={StructureTabPane} />
@@ -3,6 +3,8 @@ import { Route, Switch } from "react-router-dom";
3
3
  import {
4
4
  STRUCTURE,
5
5
  STRUCTURE_CHILDREN,
6
+ STRUCTURE_FIELDS,
7
+ STRUCTURE_VERSION_FIELDS,
6
8
  STRUCTURE_EVENTS,
7
9
  STRUCTURE_GRANTS,
8
10
  STRUCTURE_IMPACT,
@@ -24,6 +26,7 @@ import StructureTabs from "./StructureTabs";
24
26
  export const StructureTabRoutes = () => (
25
27
  <Switch>
26
28
  <Route path={STRUCTURE_VERSION_VERSIONS} component={StructureTabs} />
29
+ <Route path={STRUCTURE_VERSION_FIELDS} component={StructureTabs} />
27
30
  <Route path={STRUCTURE_VERSION} component={StructureTabs} />
28
31
  <Route path={STRUCTURE_PROFILE} component={StructureTabs} />
29
32
  <Route path={STRUCTURE_LINKS} component={StructureTabs} />
@@ -36,6 +39,7 @@ export const StructureTabRoutes = () => (
36
39
  <Route path={STRUCTURE_RULES} component={StructureTabs} />
37
40
  <Route path={STRUCTURE_LINEAGE} component={StructureTabs} />
38
41
  <Route path={STRUCTURE_CHILDREN} component={StructureTabs} />
42
+ <Route path={STRUCTURE_FIELDS} component={StructureTabs} />
39
43
  <Route path={STRUCTURE_PARENTS} component={StructureTabs} />
40
44
  <Route path={STRUCTURE_IMPACT} component={StructureTabs} />
41
45
  <Route path={STRUCTURE} component={StructureTabs} exact />
@@ -10,10 +10,11 @@ import { linkTo } from "@truedat/core/routes";
10
10
  import { getActiveTab } from "../selectors/getActiveTab";
11
11
  import { getTabVisibility } from "../selectors/getTabVisibility";
12
12
 
13
- const structureLink = ({ id }, version) =>
14
- _.isNil(version)
15
- ? linkTo.STRUCTURE({ id })
16
- : linkTo.STRUCTURE_VERSION({ id, version });
13
+ const structureFields = ({ id }, version) => {
14
+ return _.isNil(version)
15
+ ? linkTo.STRUCTURE_FIELDS({ id })
16
+ : linkTo.STRUCTURE_VERSION_FIELDS({ id, version });
17
+ };
17
18
 
18
19
  const versionsLink = ({ id }, version) =>
19
20
  _.isNil(version)
@@ -40,6 +41,7 @@ export const StructureTabs = ({
40
41
  versions,
41
42
  } = {},
42
43
  structure,
44
+ structureTabsOrder,
43
45
  version,
44
46
  }) => {
45
47
  const { formatMessage } = useIntl();
@@ -48,7 +50,7 @@ export const StructureTabs = ({
48
50
  {
49
51
  active: activeTab === "fields",
50
52
  as: Link,
51
- to: structureLink(structure, version),
53
+ to: structureFields(structure, version),
52
54
  content: fields ? formatMessage({ id: "tabs.dd.fields" }) : false,
53
55
  key: "fields",
54
56
  },
@@ -154,6 +156,24 @@ export const StructureTabs = ({
154
156
  },
155
157
  ])
156
158
  : null;
159
+
160
+ structureTabsOrder
161
+ ? items.sort((a, b) => {
162
+ const aIndex = _.indexOf(a.key)(structureTabsOrder);
163
+ const bIndex = _.indexOf(b.key)(structureTabsOrder);
164
+ if (aIndex !== -1 && bIndex !== -1) {
165
+ return aIndex - bIndex;
166
+ }
167
+ if (aIndex !== -1) {
168
+ return -1;
169
+ }
170
+ if (bIndex !== -1) {
171
+ return 1;
172
+ }
173
+ return 0;
174
+ })
175
+ : items;
176
+
157
177
  return (
158
178
  <>
159
179
  <Menu
@@ -171,22 +191,24 @@ export const StructureTabs = ({
171
191
 
172
192
  StructureTabs.propTypes = {
173
193
  structure: PropTypes.object,
194
+ structureTabsOrder: PropTypes.array,
174
195
  version: PropTypes.string,
175
196
  activeTab: PropTypes.string,
176
197
  tabVisibility: PropTypes.object,
177
198
  };
178
199
 
179
- const mapStateToProps = (state, ownProps) => {
200
+ const mapStateToProps = ({ structureTabsOrder, ...state }, ownProps) => {
180
201
  const {
181
202
  match: { path },
182
203
  } = ownProps;
183
204
  const { structureVersion: version, structure } = state;
184
205
  const tabVisibility = getTabVisibility(state, path);
185
- const activeTab = getActiveTab(tabVisibility, path);
206
+ const activeTab = getActiveTab(tabVisibility, path, structureTabsOrder);
186
207
 
187
208
  return {
188
209
  activeTab,
189
210
  structure,
211
+ structureTabsOrder,
190
212
  tabVisibility,
191
213
  version,
192
214
  };
@@ -6,6 +6,10 @@ exports[`<StructureTabRoutes /> matches the latest snapshot 1`] = `
6
6
  component={[Function]}
7
7
  path="/structures/:id/versions/:version/versions"
8
8
  />
9
+ <Route
10
+ component={[Function]}
11
+ path="/structures/:id/versions/:version/fields"
12
+ />
9
13
  <Route
10
14
  component={[Function]}
11
15
  path="/structures/:id/versions/:version"
@@ -54,6 +58,10 @@ exports[`<StructureTabRoutes /> matches the latest snapshot 1`] = `
54
58
  component={[Function]}
55
59
  path="/structures/:id/children"
56
60
  />
61
+ <Route
62
+ component={[Function]}
63
+ path="/structures/:id/fields"
64
+ />
57
65
  <Route
58
66
  component={[Function]}
59
67
  path="/structures/:id/parents"
@@ -7,7 +7,7 @@ exports[`<StructureTabs /> matches the latest snapshot: metadata 1`] = `
7
7
  >
8
8
  <a
9
9
  class="item"
10
- href="/structures/123/versions/1"
10
+ href="/structures/123/versions/1/fields"
11
11
  >
12
12
  Fields
13
13
  </a>
@@ -32,7 +32,7 @@ describe("selectors: defaultTab", () => {
32
32
  const versions = truthy;
33
33
  const grants = truthy;
34
34
 
35
- it("should determine value according to precedence", () => {
35
+ it("should determine value according to precedence without custom order", () => {
36
36
  expect(defaultTab({ children, fields })).toBe("fields");
37
37
  expect(defaultTab({ children, notes })).toBe("children");
38
38
  expect(defaultTab({ notes, parents })).toBe("notes");
@@ -45,6 +45,34 @@ describe("selectors: defaultTab", () => {
45
45
  expect(defaultTab({ versions })).toBe("versions");
46
46
  expect(defaultTab({})).toBe(undefined);
47
47
  });
48
+
49
+ it("should determine value according to precedence with custom order", () => {
50
+ const tabsOrder = [
51
+ "versions",
52
+ "links",
53
+ "roles",
54
+ "rules",
55
+ "profile",
56
+ "parents",
57
+ "metadata",
58
+ "grants",
59
+ "notes",
60
+ "children",
61
+ "fields",
62
+ ];
63
+ expect(defaultTab({ children, fields }, tabsOrder)).toBe("children");
64
+ expect(defaultTab({ children, notes }, tabsOrder)).toBe("notes");
65
+ expect(defaultTab({ notes, parents }, tabsOrder)).toBe("parents");
66
+ expect(defaultTab({ grants, parents }, tabsOrder)).toBe("parents");
67
+ expect(defaultTab({ parents, profile }, tabsOrder)).toBe("profile");
68
+ expect(defaultTab({ profile, rules }, tabsOrder)).toBe("rules");
69
+ expect(defaultTab({ links, rules }, tabsOrder)).toBe("links");
70
+ expect(defaultTab({ links, roles }, tabsOrder)).toBe("links");
71
+ expect(defaultTab({ links, versions }, tabsOrder)).toBe("versions");
72
+ expect(defaultTab({ versions }, tabsOrder)).toBe("versions");
73
+ expect(defaultTab({ fields }, tabsOrder)).toBe("fields");
74
+ expect(defaultTab({}, tabsOrder)).toBe(undefined);
75
+ });
48
76
  });
49
77
 
50
78
  describe("selectors: getActiveTab", () => {
@@ -3,6 +3,8 @@ import {
3
3
  STRUCTURE,
4
4
  STRUCTURE_VERSION,
5
5
  STRUCTURE_CHILDREN,
6
+ STRUCTURE_FIELDS,
7
+ STRUCTURE_VERSION_FIELDS,
6
8
  STRUCTURE_METADATA,
7
9
  STRUCTURE_NOTES,
8
10
  STRUCTURE_NOTES_EDIT,
@@ -21,24 +23,30 @@ import {
21
23
  STRUCTURE_IMPACT,
22
24
  } from "@truedat/core/routes";
23
25
 
24
- export const defaultTab = _.cond([
25
- [_.conformsTo({ fields: _.identity }), _.constant("fields")],
26
- [_.conformsTo({ children: _.identity }), _.constant("children")],
27
- [_.conformsTo({ notes: _.identity }), _.constant("notes")],
28
- [_.conformsTo({ grants: _.identity }), _.constant("grants")],
29
- [_.conformsTo({ metadata: _.identity }), _.constant("metadata")],
30
- [_.conformsTo({ parents: _.identity }), _.constant("parents")],
31
- [_.conformsTo({ profile: _.identity }), _.constant("profile")],
32
- [_.conformsTo({ rules: _.identity }), _.constant("rules")],
33
- [_.conformsTo({ roles: _.identity }), _.constant("roles")],
34
- [_.conformsTo({ links: _.identity }), _.constant("links")],
35
- [_.conformsTo({ versions: _.identity }), _.constant("versions")],
36
- ]);
26
+ export const defaultTab = (tabVisibility, tabsOrder = []) => {
27
+ const defaultOrder = [
28
+ "fields",
29
+ "children",
30
+ "notes",
31
+ "grants",
32
+ "metadata",
33
+ "parents",
34
+ "profile",
35
+ "rules",
36
+ "roles",
37
+ "links",
38
+ "versions",
39
+ ];
37
40
 
38
- export const getActiveTab = (tabVisibility, path) => {
41
+ return _.find((tab) => tabVisibility[tab])([...tabsOrder, ...defaultOrder]);
42
+ };
43
+
44
+ export const getActiveTab = (tabVisibility, path, tabsOrder) => {
39
45
  return _.cond([
40
- [_.eq(STRUCTURE), _.constant(defaultTab(tabVisibility))],
41
- [_.eq(STRUCTURE_VERSION), _.constant(defaultTab(tabVisibility))],
46
+ [_.eq(STRUCTURE), _.constant(defaultTab(tabVisibility, tabsOrder))],
47
+ [_.eq(STRUCTURE_VERSION), _.constant(defaultTab(tabVisibility, tabsOrder))],
48
+ [_.eq(STRUCTURE_VERSION_FIELDS), _.constant("fields")],
49
+ [_.eq(STRUCTURE_FIELDS), _.constant("fields")],
42
50
  [_.eq(STRUCTURE_CHILDREN), _.constant("children")],
43
51
  [_.eq(STRUCTURE_NOTES), _.constant("notes")],
44
52
  [_.eq(STRUCTURE_NOTES_EDIT), _.constant("notes")],