Skip to content

Commit d01ba6f

Browse files
briantangMarkLogic Builder
authored andcommitted
DHFPROD-8228: Make Hub Central Documentation Links Dynamic
1 parent e572a71 commit d01ba6f

File tree

6 files changed

+52
-36
lines changed

6 files changed

+52
-36
lines changed

marklogic-data-hub-central/ui/src/components/header/header.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {RouteComponentProps, withRouter, useHistory, Link} from "react-router-do
33
import axios from "axios";
44
import {Layout, Icon, Avatar, Menu, Dropdown} from "antd";
55
import {UserContext} from "../../util/user-context";
6+
import {parseVersion} from "../../util/environment";
67
import logo from "./logo.svg";
78
import styles from "./header.module.scss";
89
import {Application} from "../../config/application.config";
@@ -59,26 +60,6 @@ const Header:React.FC<Props> = (props) => {
5960
return "https://docs.marklogic.com/datahub/" + versionNum;
6061
};
6162

62-
const parseVersion = (value) => {
63-
if (value === "") {
64-
return "";
65-
} else {
66-
let version = "";
67-
let flag = false;
68-
for (let c in value) {
69-
if (value[c] !== "." && value[c] !== "-") {
70-
version += value[c];
71-
} else if (value[c] === "." && flag === false) {
72-
flag = true;
73-
version += value[c];
74-
} else {
75-
break;
76-
}
77-
}
78-
return version;
79-
}
80-
};
81-
8263
const logoutKeyDownHandler = (event) => {
8364
if (event.key === "Tab") {
8465
toggleUserDropdown(false);

marklogic-data-hub-central/ui/src/config/overview.config.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
const VERSION = "5.5";
22

3-
const documentationLinkRoot = "https://docs.marklogic.com/datahub/" + VERSION + "/";
3+
const documentationLinkRoot = "https://docs.marklogic.com/datahub/";
44
const documentationLinks = {
5-
load: documentationLinkRoot + "flows/loading-with-hubcentral.html",
6-
model: documentationLinkRoot + "entities/modeling-with-hubcentral.html",
7-
curate: documentationLinkRoot + "flows/curating-with-hubcentral.html",
8-
run: documentationLinkRoot + "flows/running-steps-with-hubcentral.html",
9-
explore: documentationLinkRoot + "tools/hubcentral/exploring-with-hubcentral.html",
5+
tileSpecificLink: function (versionNum, tile) {
6+
switch (tile) {
7+
case "load":
8+
return documentationLinkRoot + versionNum + "/" + "flows/loading-with-hubcentral.html"
9+
case "model":
10+
return documentationLinkRoot + versionNum + "/" + "entities/modeling-with-hubcentral.html"
11+
case "curate":
12+
return documentationLinkRoot + versionNum + "/" + "flows/curating-with-hubcentral.html"
13+
case "run":
14+
return documentationLinkRoot + versionNum + "/" + "flows/running-steps-with-hubcentral.html"
15+
case "explore":
16+
return documentationLinkRoot + versionNum + "/" + "tools/hubcentral/exploring-with-hubcentral.html"
17+
}
18+
}
1019
}
1120

1221
// TODO Video Tutorial links currently pegged to version 5.4, see: DHFPROD-7513

marklogic-data-hub-central/ui/src/pages/Overview.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import userEvent from "@testing-library/user-event";
55
import {render, fireEvent} from "@testing-library/react";
66
import Overview from "./Overview";
77
import overviewConfig from "../config/overview.config";
8+
import data from "../assets/mock-data/system-info.data";
89

910
describe("Overview component", () => {
1011

1112
it("Verify content display", async () => {
1213

13-
const {getByText, getByLabelText, getAllByText} = render(<Overview/>);
14+
let enabled = ["load", "model", "curate", "run", "explore"];
15+
const {getByText, getByLabelText, getAllByText} = render(<Overview enabled={enabled} environment={data.environment}/>);
1416

1517
expect(getByLabelText("overview")).toBeInTheDocument();
1618

@@ -35,7 +37,7 @@ describe("Overview component", () => {
3537
history.push("/tiles"); // initial state
3638

3739
let enabled = ["load", "model", "curate", "run", "explore"];
38-
const {getByLabelText, queryAllByText} = render(<Router history={history}><Overview enabled={enabled}/></Router>);
40+
const {getByLabelText, queryAllByText} = render(<Router history={history}><Overview enabled={enabled} environment={data.environment}/></Router>);
3941

4042
enabled.forEach((card, i) => {
4143
expect(getByLabelText(card + "-card")).toHaveClass(`enabled`);
@@ -52,7 +54,7 @@ describe("Overview component", () => {
5254
history.push("/tiles"); // initial state
5355

5456
let disabled = ["load", "model", "curate", "run", "explore"];
55-
const {getByLabelText, getAllByText} = render(<Router history={history}><Overview enabled={[]}/></Router>);
57+
const {getByLabelText, getAllByText} = render(<Router history={history}><Overview enabled={[]} environment={data.environment}/></Router>);
5658

5759
disabled.forEach((card, i) => {
5860
expect(getByLabelText(card + "-card")).toHaveClass(`disabled`);
@@ -70,7 +72,7 @@ describe("Overview component", () => {
7072
history.push("/tiles");
7173

7274
let enabled = ["load", "model", "curate", "run", "explore"];
73-
const {getByLabelText} = render(<Router history={history}><Overview enabled={enabled}/></Router>);
75+
const {getByLabelText} = render(<Router history={history}><Overview enabled={enabled} environment={data.environment}/></Router>);
7476

7577
enabled.forEach((id, i) => {
7678
let card = getByLabelText(id + "-card");
@@ -91,7 +93,7 @@ describe("Overview component", () => {
9193
history.push("/tiles");
9294

9395
let enabled = ["load", "model", "curate", "run", "explore"];
94-
const {getByLabelText} = render(<Router history={history}><Overview enabled={enabled}/></Router>);
96+
const {getByLabelText} = render(<Router history={history}><Overview enabled={enabled} environment={data.environment}/></Router>);
9597

9698
getByLabelText("load-card").focus();
9799
expect(getByLabelText("load-card")).toHaveFocus();
@@ -116,7 +118,7 @@ describe("Overview component", () => {
116118
history.push("/tiles");
117119

118120
let enabled = ["load", "model", "curate", "run", "explore"];
119-
const {getByLabelText} = render(<Router history={history}><Overview enabled={enabled}/></Router>);
121+
const {getByLabelText} = render(<Router history={history}><Overview enabled={enabled} environment={data.environment}/></Router>);
120122

121123
// map of which card to go next if up/down/left/right arrow keys are pressed on a card
122124
const directionMap = {
@@ -152,7 +154,7 @@ describe("Overview component", () => {
152154
history.push("/tiles"); // initial state
153155

154156
let enabled = ["load", "model", "curate", "run", "explore"];
155-
const {getAllByText} = render(<Router history={history}><Overview enabled={enabled}/></Router>);
157+
const {getAllByText} = render(<Router history={history}><Overview enabled={enabled} environment={data.environment}/></Router>);
156158

157159
// Mock method for opening links
158160
const mockedWindowOpen = jest.fn();
@@ -164,7 +166,7 @@ describe("Overview component", () => {
164166
expect(documentationLinks.length === enabled.length); // All cards should have Documentation links
165167
documentationLinks.forEach((docLink, i) => {
166168
fireEvent.click(docLink);
167-
expect(mockedWindowOpen).toBeCalledWith(overviewConfig.documentationLinks[enabled[i]], "_blank");
169+
expect(mockedWindowOpen).toBeCalledWith(overviewConfig.documentationLinks.tileSpecificLink(5.3, enabled[i]), "_blank");
168170
});
169171

170172
// Check Video Tutorial links

marklogic-data-hub-central/ui/src/pages/Overview.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import {Popover} from "antd";
77
import "./Overview.scss";
88
import modelingInfoIcon from "../assets/icon_helpInfo.png";
99
import {ToolbarBulbIconInfo} from "../config/tooltips.config";
10+
import {parseVersion} from "../util/environment";
1011

1112
interface Props {
1213
enabled: any;
14+
environment: any;
1315
}
1416

1517
const Overview: React.FC<Props> = (props) => {
@@ -29,7 +31,8 @@ const Overview: React.FC<Props> = (props) => {
2931

3032
const openDocumentation = (e, type) => {
3133
if (e) e.stopPropagation(); // Stop click from also opening tile
32-
window.open(overviewConfig.documentationLinks[type], "_blank");
34+
let versionNum = parseVersion(props.environment.dataHubVersion);
35+
window.open(overviewConfig.documentationLinks.tileSpecificLink(versionNum, type), "_blank");
3336
};
3437

3538
const openVideo = (e, type) => {

marklogic-data-hub-central/ui/src/pages/TilesView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Toolbar from "../components/tiles/toolbar";
44
import Tiles from "../components/tiles/tiles";
55
import styles from "./TilesView.module.scss";
66
import "./TilesView.scss";
7+
import {getEnvironment} from "../util/environment";
78

89
import Overview from "./Overview";
910
import Load from "./Load";
@@ -155,7 +156,7 @@ const TilesView = (props) => {
155156
</ConfigProvider>
156157
) : null }
157158
</div>) :
158-
<Overview enabled={enabled}/>
159+
<Overview enabled={enabled} environment={getEnvironment()}/>
159160
}
160161
<Toolbar tiles={tiles} enabled={enabled}/>
161162
</>

marklogic-data-hub-central/ui/src/util/environment.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ export function getEnvironment():any {
2727
}
2828
}
2929

30+
export function parseVersion(value):any {
31+
if (value === "") {
32+
return "";
33+
} else {
34+
let version = "";
35+
let flag = false;
36+
for (let c in value) {
37+
if (value[c] !== "." && value[c] !== "-") {
38+
version += value[c];
39+
} else if (value[c] === "." && flag === false) {
40+
flag = true;
41+
version += value[c];
42+
} else {
43+
break;
44+
}
45+
}
46+
return version;
47+
}
48+
}
49+
3050
export function resetEnvironment() {
3151
localStorage.setItem("environment", JSON.stringify(defaultEnv));
3252
}

0 commit comments

Comments
 (0)