Skip to content

Commit aab6da6

Browse files
authored
web: Extract useRemotePath (#323)
1 parent e7ee2b8 commit aab6da6

File tree

12 files changed

+37
-43
lines changed

12 files changed

+37
-43
lines changed

mwdb/web/src/commons/remotes/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ export function useRemote() {
55
const match = useRouteMatch("/remote/:remote");
66
return match && match.params.remote;
77
}
8+
9+
export function useRemotePath() {
10+
const remote = useRemote();
11+
return remote ? `/remote/${remote}` : "";
12+
}

mwdb/web/src/commons/ui/ObjectLink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React, { useContext } from "react";
2-
import { Link, useParams } from "react-router-dom";
2+
import { Link } from "react-router-dom";
33

44
import { AuthContext } from "../auth";
55
import { mapObjectType } from "../helpers";
6+
import { useRemotePath } from "../remotes";
67

78
import Hash from "./Hash";
89

910
export default function ObjectLink(props) {
1011
const auth = useContext(AuthContext);
1112
const objectType = mapObjectType(props.type);
12-
const { remote } = useParams();
13-
const remotePath = remote ? `/remote/${remote}` : "";
13+
const remotePath = useRemotePath();
1414

1515
let linkElement = (
1616
<Link

mwdb/web/src/commons/ui/RefString.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from "react";
22
import { Link } from "react-router-dom";
3-
import { useRemote } from "@mwdb-web/commons/remotes";
3+
import { useRemotePath } from "@mwdb-web/commons/remotes";
44
import ObjectLink from "./ObjectLink";
55
import { makeSearchLink } from "../helpers";
66

77
export default function RefString(props) {
8-
const remote = useRemote();
9-
const remotePath = remote ? `remote/${remote}/` : "";
8+
const remotePath = useRemotePath();
109
const reasonText =
1110
props.reason_type.charAt(0).toUpperCase() +
1211
props.reason_type.slice(1).toLowerCase();

mwdb/web/src/components/ConfigStats.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { Link } from "react-router-dom";
44
import api from "@mwdb-web/commons/api";
55
import { DateString, SortedList, View } from "@mwdb-web/commons/ui";
66
import { makeSearchLink } from "@mwdb-web/commons/helpers";
7-
import { useRemote } from "@mwdb-web/commons/remotes";
7+
import { useRemotePath } from "@mwdb-web/commons/remotes";
88

99
function ConfigStatsItem(props) {
10-
const remote = useRemote();
11-
const remotePath = remote ? `remote/${remote}` : "";
10+
const remotePath = useRemotePath();
1211
return (
1312
<tr>
1413
<td>
@@ -17,7 +16,7 @@ function ConfigStatsItem(props) {
1716
"family",
1817
props.family,
1918
false,
20-
`${remotePath}/configs`
19+
`${remotePath}configs`
2120
)}
2221
>
2322
{props.family}

mwdb/web/src/components/ConfigTable.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
DateString,
1313
ObjectLink,
1414
} from "@mwdb-web/commons/ui";
15-
import { useRemote } from "@mwdb-web/commons/remotes";
15+
import { useRemotePath } from "@mwdb-web/commons/remotes";
1616

1717
export function ConfigRow(props) {
1818
const key = props.configKey;
@@ -28,8 +28,7 @@ export function ConfigRow(props) {
2828
Object.keys(value)[0] === "in-blob";
2929
const isRegularObject = isObject && !isEmbeddedBlob;
3030

31-
const remote = useRemote();
32-
const remotePath = remote ? `remote/${remote}/` : "";
31+
const remotePath = useRemotePath();
3332

3433
useEffect(() => {
3534
// Automatically expand all nested objects if parent has been expanded
@@ -153,8 +152,7 @@ export function ConfigRows(props) {
153152

154153
export default function ConfigTable(props) {
155154
const object = props.object;
156-
const remote = useRemote();
157-
const remotePath = remote ? `remote/${remote}/` : "";
155+
const remotePath = useRemotePath();
158156

159157
return (
160158
<DataTable>

mwdb/web/src/components/DagreD3Plot.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import ReactDOM from "react-dom";
33

44
import * as dagreD3 from "dagre-d3";
55
import * as d3 from "d3";
6-
import { useRemote } from "@mwdb-web/commons/remotes";
6+
import { useRemotePath } from "@mwdb-web/commons/remotes";
77

88
function DagreD3Plot(props) {
9-
const remote = useRemote();
10-
const remotePath = remote ? `/remote/${remote}` : "";
9+
const remotePath = useRemotePath();
1110

1211
const graph = new dagreD3.graphlib.Graph().setGraph({ compound: true });
1312
const renderer = new dagreD3.render();

mwdb/web/src/components/Navigation.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { AuthContext } from "@mwdb-web/commons/auth";
1515
import { ConfigContext } from "@mwdb-web/commons/config";
1616
import { fromPlugin, Extendable } from "@mwdb-web/commons/extensions";
1717
import { NavDropdown } from "@mwdb-web/commons/ui";
18-
import { useRemote } from "@mwdb-web/commons/remotes";
18+
import { useRemote, useRemotePath } from "@mwdb-web/commons/remotes";
1919

2020
import logo from "../assets/logo.png";
2121

@@ -116,7 +116,7 @@ export default function Navigation() {
116116
const auth = useContext(AuthContext);
117117
const config = useContext(ConfigContext);
118118
const remote = useRemote();
119-
const remotePath = remote ? `/remote/${remote}` : "";
119+
const remotePath = useRemotePath();
120120
const navItems = config.config ? (
121121
<Extendable ident="navbar">
122122
{!auth.isAuthenticated &&
@@ -242,7 +242,7 @@ export default function Navigation() {
242242
</Link>
243243
</li>
244244
<li className="nav-item">
245-
<Link className="nav-link" to={`${remotePath}/configs`}>
245+
<Link className="nav-link" to={`${remotePath}configs`}>
246246
<FontAwesomeIcon
247247
className="navbar-icon"
248248
icon={faTable}
@@ -251,7 +251,7 @@ export default function Navigation() {
251251
</Link>
252252
</li>
253253
<li className="nav-item">
254-
<Link className="nav-link" to={`${remotePath}/blobs`}>
254+
<Link className="nav-link" to={`${remotePath}blobs`}>
255255
<FontAwesomeIcon
256256
className="navbar-icon"
257257
icon={faScroll}
@@ -260,7 +260,7 @@ export default function Navigation() {
260260
</Link>
261261
</li>
262262
<li className="nav-item">
263-
<Link className="nav-link" to={`${remotePath}/search`}>
263+
<Link className="nav-link" to={`${remotePath}search`}>
264264
Search
265265
</Link>
266266
</li>

mwdb/web/src/components/RecentBlobs.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
77
import { RecentView, RecentRow, RecentInnerRow } from "./RecentView";
88
import { TagList } from "@mwdb-web/commons/ui";
99
import { DateString, ObjectLink, Hash } from "@mwdb-web/commons/ui";
10-
import { useRemote } from "@mwdb-web/commons/remotes";
10+
import { useRemotePath } from "@mwdb-web/commons/remotes";
1111

1212
export function RecentBlobRow(props) {
1313
let location = useLocation();
14-
const remote = useRemote();
15-
const remotePath = remote ? `/remote/${remote}` : "";
14+
const remotePath = useRemotePath();
1615
const diffWith = queryString.parse(location.search)["diff"];
1716
const blobType = (
1817
<a
@@ -29,7 +28,7 @@ export function RecentBlobRow(props) {
2928
props.id === diffWith ? (
3029
<Hash hash={props.id} />
3130
) : (
32-
<Link to={`${remotePath}/diff/${props.id}/${diffWith}`}>
31+
<Link to={`${remotePath}diff/${props.id}/${diffWith}`}>
3332
<Hash hash={props.id} />
3433
</Link>
3534
)

mwdb/web/src/components/ShowObject/Views/LatestConfigTab.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import ConfigTable from "../../ConfigTable";
44

55
import { ObjectContext } from "@mwdb-web/commons/context";
66
import { ObjectAction, ObjectTab } from "@mwdb-web/commons/ui";
7-
import { useRemote } from "@mwdb-web/commons/remotes";
7+
import { useRemotePath } from "@mwdb-web/commons/remotes";
88

99
export default function LatestConfigTab(props) {
1010
const context = useContext(ObjectContext);
11-
const remote = useRemote();
12-
const remotePath = remote ? `/remote/${remote}` : "";
11+
const remotePath = useRemotePath();
1312

1413
// Don't show tab if object doesn't have latest config
1514
if (!context.object.latest_config) return [];

mwdb/web/src/components/ShowObject/Views/SharesBox.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import { APIContext } from "@mwdb-web/commons/api/context";
66
import { ObjectContext } from "@mwdb-web/commons/context";
77
import { RefString, DateString, ConfirmationModal } from "@mwdb-web/commons/ui";
88
import { makeSearchLink } from "@mwdb-web/commons/helpers";
9-
import { useRemote } from "@mwdb-web/commons/remotes";
9+
import { useRemotePath } from "@mwdb-web/commons/remotes";
1010

1111
function ShareItem(props) {
1212
const context = useContext(ObjectContext);
13-
const remote = useRemote();
14-
const remotePath = remote ? `remote/${remote}/` : "";
13+
const remotePath = useRemotePath();
1514
let fieldStyle = {
1615
wordBreak: "break-all",
1716
};

0 commit comments

Comments
 (0)