Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remaining relative links in react codebase. #1198

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import * as Yup from "yup";

import { generateLegacyURL } from "app/utils";
import { machine as machineActions } from "app/base/actions";
import {
machine as machineSelectors,
Expand All @@ -23,11 +24,19 @@ const generateFailedTestsMessage = (numFailedTests, selectedMachines) => {
numFailedTests
)}.`;
if (singleMachine) {
const url = `${process.env.REACT_APP_BASENAME}${process.env.REACT_APP_ANGULAR_BASENAME}/machine/${singleMachine.system_id}`;
const url = generateLegacyURL(`/machine/${singleMachine.system_id}`);
return (
<span>
Machine <strong>{singleMachine.hostname}</strong> has{" "}
<a href={url}>{numFailedTestsString}</a>
<a
href={url}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(null, null, url);
}}
>
{numFailedTestsString}
</a>
</span>
);
}
Expand Down Expand Up @@ -160,7 +169,19 @@ export const OverrideTestForm = ({
<br />
{selectedMachines.length === 1 ? (
<a
href={`${process.env.REACT_APP_BASENAME}${process.env.REACT_APP_ANGULAR_BASENAME}/machine/${selectedMachines[0].system_id}`}
href={generateLegacyURL(
`/machine/${selectedMachines[0].system_id}`
)}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(
null,
null,
generateLegacyURL(
`/machine/${selectedMachines[0].system_id}`
)
);
}}
>
Machine > Hardware tests
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const FabricColumn = ({ systemId }) => {

const fabricID = machine.vlan && machine.vlan.fabric_id;
const fabricName = machine.vlan && machine.vlan.fabric_name;
const fabricURL = generateLegacyURL(`/fabric/${fabricID}`);
const vlan = machine.vlan && machine.vlan.name ? machine.vlan.name : "";

return (
Expand All @@ -30,6 +31,10 @@ export const FabricColumn = ({ systemId }) => {
<a
className="p-link--soft"
href={generateLegacyURL(`/fabric/${fabricID}`)}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(null, null, fabricURL);
}}
>
{fabricName}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports[`FabricColumn renders 1`] = `
<a
className="p-link--soft"
href="/MAAS/l/fabric/0"
onClick={[Function]}
>
fabric-0
</a>
Expand Down Expand Up @@ -68,6 +69,7 @@ exports[`FabricColumn renders 1`] = `
<a
className="p-link--soft"
href="/MAAS/l/fabric/0"
onClick={[Function]}
>
fabric-0
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelector } from "react-redux";
import React from "react";
import PropTypes from "prop-types";

import { generateLegacyURL } from "app/utils";
import { machine as machineSelectors } from "app/base/selectors";
import DoubleRow from "app/base/components/DoubleRow";
import Tooltip from "app/base/components/Tooltip";
Expand All @@ -13,11 +14,7 @@ const generateFQDN = (machine, machineURL) => {
href={machineURL}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(
null,
null,
`${process.env.REACT_APP_BASENAME}${machineURL}`
);
window.history.pushState(null, null, machineURL);
}}
title={machine.fqdn}
>
Expand Down Expand Up @@ -87,11 +84,27 @@ const generateIPAddresses = (machine) => {
const generateMAC = (machine, machineURL) => {
return (
<>
<a href={machineURL} title={machine.pxe_mac_vendor}>
<a
href={machineURL}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(null, null, machineURL);
}}
title={machine.pxe_mac_vendor}
>
{machine.pxe_mac}
</a>
{machine.extra_macs && machine.extra_macs.length > 0 ? (
<a href={machineURL}> (+{machine.extra_macs.length})</a>
<a
href={machineURL}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(null, null, machineURL);
}}
>
{" "}
(+{machine.extra_macs.length})
</a>
) : null}
</>
);
Expand All @@ -101,7 +114,9 @@ export const NameColumn = ({ handleCheckbox, selected, showMAC, systemId }) => {
const machine = useSelector((state) =>
machineSelectors.getBySystemId(state, systemId)
);
const machineURL = `${process.env.REACT_APP_ANGULAR_BASENAME}/${machine.link_type}/${machine.system_id}`;
const machineURL = generateLegacyURL(
`/${machine.link_type}/${machine.system_id}`
);
const primaryRow = showMAC
? generateMAC(machine, machineURL)
: generateFQDN(machine, machineURL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`NameColumn renders 1`] = `
id="abc123"
label={
<a
href="/l/undefined/abc123"
href="/MAAS/l/undefined/abc123"
onClick={[Function]}
>
<strong>
Expand Down Expand Up @@ -50,7 +50,7 @@ exports[`NameColumn renders 1`] = `
id="abc123"
label={
<a
href="/l/undefined/abc123"
href="/MAAS/l/undefined/abc123"
onClick={[Function]}
>
<strong>
Expand All @@ -71,7 +71,7 @@ exports[`NameColumn renders 1`] = `
forId="abc123"
label={
<a
href="/l/undefined/abc123"
href="/MAAS/l/undefined/abc123"
onClick={[Function]}
>
<strong>
Expand Down Expand Up @@ -105,7 +105,7 @@ exports[`NameColumn renders 1`] = `
htmlFor="abc123"
>
<a
href="/l/undefined/abc123"
href="/MAAS/l/undefined/abc123"
onClick={[Function]}
>
<strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const ZoneColumn = ({ onToggleMenu, systemId }) => {
}
}, [updating, machine.zone.id]);

const zoneURL = generateLegacyURL(`/zone/${machine.zone.id}`);

return (
<DoubleRow
menuLinks={zoneLinks}
Expand All @@ -74,7 +76,11 @@ export const ZoneColumn = ({ onToggleMenu, systemId }) => {
) : null}
<a
className="p-link--soft"
href={generateLegacyURL(`/zone/${machine.zone.id}`)}
href={zoneURL}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(null, null, zoneURL);
}}
>
{machine.zone.name}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports[`ZoneColumn renders 1`] = `
<a
className="p-link--soft"
href="/MAAS/l/zone/0"
onClick={[Function]}
>
zone-north
</a>
Expand Down Expand Up @@ -57,6 +58,7 @@ exports[`ZoneColumn renders 1`] = `
<a
className="p-link--soft"
href="/MAAS/l/zone/0"
onClick={[Function]}
>
zone-north
</a>
Expand Down
18 changes: 13 additions & 5 deletions ui/src/app/settings/views/Dhcp/DhcpTarget/DhcpTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { Link, Spinner } from "@canonical/react-components";
import PropTypes from "prop-types";
import React from "react";

import { generateLegacyURL } from "app/utils";
import { useDhcpTarget } from "app/settings/hooks";

const generateURL = (url) =>
`${process.env.REACT_APP_BASENAME}${process.env.REACT_APP_ANGULAR_BASENAME}${url}`;

const DhcpTarget = ({ nodeId, subnetId }) => {
const { loading, loaded, target, type } = useDhcpTarget(nodeId, subnetId);

Expand All @@ -22,8 +20,18 @@ const DhcpTarget = ({ nodeId, subnetId }) => {
<small>.{target.domain.name}</small>
</>
);
const url = generateURL(`/${type}/${nodeId || subnetId}`);
return <Link href={url}>{name}</Link>;
const url = generateLegacyURL(`/${type}/${nodeId || subnetId}`);
return (
<Link
href={url}
onClick={(evt) => {
evt.preventDefault();
window.history.pushState(null, null, url);
}}
>
{name}
</Link>
);
};

DhcpTarget.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
exports[`DhcpTarget can display a node link 1`] = `
<Link
href="/MAAS/l/machine/xyz"
onClick={[Function]}
>
<a
className=""
href="/MAAS/l/machine/xyz"
onClick={[Function]}
>
machine1
<small>
Expand Down