@truedat/dd 7.0.2 → 7.0.4

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.2",
3
+ "version": "7.0.4",
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.2",
37
+ "@truedat/test": "7.0.4",
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.2",
92
- "@truedat/core": "7.0.2",
93
- "@truedat/df": "7.0.2",
91
+ "@truedat/auth": "7.0.4",
92
+ "@truedat/core": "7.0.4",
93
+ "@truedat/df": "7.0.4",
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": "09343887ddeed9a87dffd993a089458eb9d06363"
118
+ "gitHead": "b2c0938fa6ea458e3009c82e4e91b7bc79c8ffed"
119
119
  }
@@ -4,7 +4,7 @@ import PropTypes from "prop-types";
4
4
  import { connect } from "react-redux";
5
5
  import { Link } from "react-router-dom";
6
6
  import { linkTo } from "@truedat/core/routes";
7
- import { FormattedMessage, useIntl } from "react-intl";
7
+ import { useIntl } from "react-intl";
8
8
  import { Grid, Segment, List, Label } from "semantic-ui-react";
9
9
  import GenericCrumbs from "@truedat/core/components/GenericCrumbs";
10
10
  import { getGrantRequestTemplate } from "../selectors";
@@ -1,7 +1,7 @@
1
1
  import _ from "lodash/fp";
2
2
  import React, { useState, useEffect } from "react";
3
3
  import PropTypes from "prop-types";
4
- import { connect } from "react-redux";
4
+ import { connect, useSelector } from "react-redux";
5
5
  import { Segment } from "semantic-ui-react";
6
6
  import SearchWidget from "@truedat/core/search/SearchWidget";
7
7
  import {
@@ -13,6 +13,8 @@ import {
13
13
  useDataStructureFilters,
14
14
  useDataStructureSearch,
15
15
  } from "../hooks/useStructures";
16
+ import { defaultColumnsForStructureSelector } from "../selectors";
17
+
16
18
  import StructuresSearchResults from "./StructuresSearchResults";
17
19
 
18
20
  function StructureSelectorContent({
@@ -70,6 +72,13 @@ export const StructureSelector = (props) => {
70
72
  const pageSize = _.prop("pageSize")(props);
71
73
  const withGrantRequests = _.prop("withGrantRequests")(props);
72
74
  const withDataFields = _.prop("withDataFields")(props);
75
+ const defaultOverwriteColumns = useSelector(
76
+ defaultColumnsForStructureSelector
77
+ );
78
+ const overwriteColumns = _.propOr(
79
+ defaultOverwriteColumns,
80
+ "overwriteColumns"
81
+ )(props);
73
82
 
74
83
  const enrichSearchPayload = {
75
84
  my_grant_requests: !!withGrantRequests,
@@ -90,10 +99,12 @@ export const StructureSelector = (props) => {
90
99
  enrichSearchPayload,
91
100
  };
92
101
 
102
+ const selectorProps = { ...props, overwriteColumns };
103
+
93
104
  return (
94
105
  <>
95
106
  <SearchContextProvider {...searchProps}>
96
- <StructureSelectorContent {...props} />
107
+ <StructureSelectorContent {...selectorProps} />
97
108
  </SearchContextProvider>
98
109
  </>
99
110
  );
@@ -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
  };
@@ -142,12 +142,7 @@ exports[`<StructureSelector /> matches the latest snapshot 1`] = `
142
142
  <td
143
143
  class="structure-cell-overflow"
144
144
  >
145
- <a
146
- href="/structures/1"
147
- title="1"
148
- >
149
- 1
150
- </a>
145
+ 1
151
146
  </td>
152
147
  <td
153
148
  class=""
@@ -179,12 +174,7 @@ exports[`<StructureSelector /> matches the latest snapshot 1`] = `
179
174
  <td
180
175
  class="structure-cell-overflow"
181
176
  >
182
- <a
183
- href="/structures/2"
184
- title="2"
185
- >
186
- 2
187
- </a>
177
+ 2
188
178
  </td>
189
179
  <td
190
180
  class=""
@@ -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", () => {
@@ -1,4 +1,7 @@
1
- import { structureColumnsSelector } from "..";
1
+ import {
2
+ defaultColumnsForStructureSelector,
3
+ structureColumnsSelector,
4
+ } from "..";
2
5
 
3
6
  describe("selectors: structureColumnsSelector", () => {
4
7
  it("should return default structuresColumns when present", () => {
@@ -28,3 +31,28 @@ describe("selectors: structureColumnsSelector", () => {
28
31
  expect(res).toEqual([{ name: "foo" }, { name: "bar" }]);
29
32
  });
30
33
  });
34
+
35
+ describe("selectors: defaultColumnsForStructureSelector", () => {
36
+ it("should replace name from object with decorator ", () => {
37
+ const structuresColumns = [
38
+ {
39
+ name: "name",
40
+ sort: { name: "name.sort" },
41
+ fieldDecorator: { foo: "bar" },
42
+ width: 2,
43
+ },
44
+ { name: "group", width: 1 },
45
+ ];
46
+ const res = defaultColumnsForStructureSelector({ structuresColumns }, {});
47
+
48
+ expect(res).toHaveLength(2);
49
+ expect(res).toEqual([
50
+ {
51
+ name: "name",
52
+ sort: { name: "name.sort" },
53
+ width: 2,
54
+ },
55
+ { name: "group", width: 1 },
56
+ ]);
57
+ });
58
+ });
@@ -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")],
@@ -1,6 +1,7 @@
1
1
  export {
2
2
  defaultStructureColumns,
3
3
  structureColumnsSelector,
4
+ defaultColumnsForStructureSelector,
4
5
  } from "./structureColumnsSelector";
5
6
  export {
6
7
  defaultBusinessConceptsLinksToStructuresColumns,
@@ -81,3 +81,14 @@ export const structureColumnsSelector = (state, defaultFilters, ownColumns) =>
81
81
  )(columns);
82
82
  return res;
83
83
  })(state);
84
+
85
+ const rawName = {
86
+ name: "name",
87
+ sort: { name: "name.sort" },
88
+ width: 2,
89
+ };
90
+ export const defaultColumnsForStructureSelector = (state) =>
91
+ createSelector(
92
+ (state) => structureColumnsSelector(state, null, null),
93
+ _.map((item) => (item?.name === "name" ? rawName : item))
94
+ )(state);