Skip to content

Commit 0ecd61e

Browse files
committed
refactor: refactor links to remove deprecated legacyBehaviour prop
1 parent c824c91 commit 0ecd61e

File tree

12 files changed

+149
-205
lines changed

12 files changed

+149
-205
lines changed

src/components/ViewFilePopover/FilePlainTextViewerListItem.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,20 @@ export const FilePlainTextViewerListItem = ({
2222
path === undefined && (path = breadcrumbs.join("/"));
2323

2424
return (
25-
<A
26-
legacyBehavior
27-
passHref
25+
<ListItemButton
26+
component={A}
2827
href={{
2928
pathname: "/project/file",
3029
query: { project: router.query.project, file: fileName, path },
3130
}}
31+
rel="noopener noreferrer"
32+
target="_blank"
33+
onClick={() => onClick()}
3234
>
33-
<ListItemButton
34-
component="a"
35-
rel="noopener noreferrer"
36-
target="_blank"
37-
onClick={() => onClick()}
38-
>
39-
<ListItemText primary="Plaintext Viewer" secondary="Displays the file as plaintext" />
40-
<ListItemIcon sx={{ ml: 2 }}>
41-
<DescriptionIcon color="action" />
42-
</ListItemIcon>
43-
</ListItemButton>
44-
</A>
35+
<ListItemText primary="Plaintext Viewer" secondary="Displays the file as plaintext" />
36+
<ListItemIcon sx={{ ml: 2 }}>
37+
<DescriptionIcon color="action" />
38+
</ListItemIcon>
39+
</ListItemButton>
4540
);
4641
};

src/components/ViewFilePopover/SDFViewerListItem.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,25 @@ export const SDFViewerListItem = ({ fileName, path, onClick }: SDFViewerListItem
1818
path ??= breadcrumbs.join("/");
1919

2020
return (
21-
<A
22-
legacyBehavior
23-
passHref
21+
<ListItemButton
22+
component={A}
2423
href={{
2524
pathname: "/viewer/sdf",
2625
query: { project: router.query.project, file: fileName, path },
2726
}}
27+
rel="noopener noreferrer"
28+
target="_blank"
29+
onClick={() => onClick()}
2830
>
29-
<ListItemButton
30-
component="a"
31-
rel="noopener noreferrer"
32-
target="_blank"
33-
onClick={() => onClick()}
34-
>
35-
<ListItemText
36-
primary="SDF Viewer (alpha)"
37-
secondary="Displays SDF records as molecule cards containing the structure and properties,
31+
<ListItemText
32+
primary="SDF Viewer (alpha)"
33+
secondary="Displays SDF records as molecule cards containing the structure and properties,
3834
filterable with a scatter plot selector. This feature is under activate development and
3935
may not work as expected. Please provide us feedback."
40-
/>
41-
<ListItemIcon sx={{ ml: 2 }}>
42-
<BiotechIcon color="action" />
43-
</ListItemIcon>
44-
</ListItemButton>
45-
</A>
36+
/>
37+
<ListItemIcon sx={{ ml: 2 }}>
38+
<BiotechIcon color="action" />
39+
</ListItemIcon>
40+
</ListItemButton>
4641
);
4742
};

src/components/instances/JobDetails/JobLink.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export const JobLink = ({ projectId, path: originalPath, isFile }: JobLinkProps)
6868
<Box sx={{ alignItems: "center", display: "flex", gap: 1, wordBreak: "break-all" }}>
6969
<Tooltip title="Locate file in project">
7070
<A
71-
legacyBehavior
7271
passHref
7372
href={{ pathname: "/project", query: { ...query, project: projectId, path: filePath } }}
7473
>
@@ -87,7 +86,6 @@ export const JobLink = ({ projectId, path: originalPath, isFile }: JobLinkProps)
8786
<Box sx={{ alignItems: "center", display: "flex", gap: 1 }}>
8887
<Tooltip title="Show directory in project">
8988
<A
90-
legacyBehavior
9189
passHref
9290
href={{
9391
pathname: "/datasets",

src/components/results/AllResultsButton.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ export const AllResultsButton = ({ instanceId }: AllResultsButtonProps) => {
1111
const { data: instance, isLoading, isError } = useGetInstance(instanceId);
1212

1313
return (
14-
<A
15-
legacyBehavior
16-
passHref
17-
href={{ pathname: "/results", query: { project: instance?.project_id } }}
18-
>
14+
<A passHref href={{ pathname: "/results", query: { project: instance?.project_id } }}>
1915
<Button color="primary" disabled={isLoading || isError}>
2016
See all results
2117
</Button>

src/components/runCards/InstancesList.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,20 @@ export const InstancesList = ({ predicate }: InstancesListProps) => {
4949
dayjs(instanceA.launched).isBefore(dayjs(instanceB.launched)) ? 1 : -1,
5050
)
5151
.map((instance) => (
52-
<A
53-
legacyBehavior
54-
passHref
52+
<ListItemButton
53+
component={A}
5554
href={{
5655
pathname: "/results/instance/[instanceId]",
5756
query: { ...query, instanceId: instance.id, project: projectId },
5857
}}
5958
key={instance.id}
6059
>
61-
<ListItemButton component="a">
62-
<ListItemText
63-
primary={instance.name}
64-
secondary={<LocalTime utcTimestamp={instance.launched} />}
65-
slotProps={{ primary: { variant: "body1" } }}
66-
/>
67-
</ListItemButton>
68-
</A>
60+
<ListItemText
61+
primary={instance.name}
62+
secondary={<LocalTime utcTimestamp={instance.launched} />}
63+
slotProps={{ primary: { variant: "body1" } }}
64+
/>
65+
</ListItemButton>
6966
))}
7067
</List>
7168
);

src/features/DatasetsTable/DatasetDetails/VersionViewSection/DatasetPlainTextViewerListItem.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ export const DatasetPlainTextViewerListItem = ({
1212
version,
1313
}: DatasetPlainTextViewerListItemProps) => {
1414
return (
15-
<A
16-
legacyBehavior
17-
passHref
15+
<ListItemButton
16+
component={A}
1817
href={{
1918
pathname: "/dataset/[datasetId]/[datasetVersion]",
2019
query: { datasetId, datasetVersion: String(version) },
2120
}}
21+
rel="noopener noreferrer"
22+
target="_blank"
2223
>
23-
<ListItemButton component="a" rel="noopener noreferrer" target="_blank">
24-
<ListItemText
25-
primary="Plaintext Viewer"
26-
secondary="Displays the dataset version as plaintext"
27-
/>
28-
<Description color="action" />
29-
</ListItemButton>
30-
</A>
24+
<ListItemText
25+
primary="Plaintext Viewer"
26+
secondary="Displays the dataset version as plaintext"
27+
/>
28+
<Description color="action" />
29+
</ListItemButton>
3130
);
3231
};

src/hooks/useSyncUnitAndOrgFromProduct.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useGetProduct } from "@squonk/account-server-client/product";
1010
import { useSelectedOrganisation } from "../state/organisationSelection";
1111
import { useSelectedUnit } from "../state/unitSelection";
1212
import { useCurrentProject } from "./projectHooks";
13+
import { useDMAuthorizationStatus } from "./useIsAuthorized";
1314

1415
export const useSyncUnitAndOrgFromProduct = () => {
1516
const currentProject = useCurrentProject();
@@ -18,7 +19,8 @@ export const useSyncUnitAndOrgFromProduct = () => {
1819
});
1920
const product = data?.product;
2021

21-
const { data: defaultOrg } = useGetDefaultOrganisation();
22+
const isDMAuthorized = useDMAuthorizationStatus();
23+
const { data: defaultOrg } = useGetDefaultOrganisation({ query: { enabled: !!isDMAuthorized } });
2224

2325
const [, setUnit] = useSelectedUnit();
2426
const [, setOrganisation] = useSelectedOrganisation();

src/layouts/Footer.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,43 @@ export const Footer = () => {
3535
<Grid size={{ sm: 3, xs: 6 }} sx={{ textAlign: "right" }}>
3636
<List dense sx={{ p: 0 }}>
3737
<ListItem sx={itemStyles}>
38-
<A legacyBehavior passHref href={{ pathname: "/" }}>
39-
<Link>Home</Link>
40-
</A>
38+
<Link component={A} href={{ pathname: "/" }}>
39+
Home
40+
</Link>
4141
</ListItem>
4242
<ListItem sx={itemStyles}>
43-
<A legacyBehavior passHref href={{ pathname: "/datasets" }}>
44-
<Link>Datasets</Link>
45-
</A>
43+
<Link component={A} href={{ pathname: "/datasets" }}>
44+
Datasets
45+
</Link>
4646
</ListItem>
4747
<ListItem sx={itemStyles}>
48-
<A legacyBehavior passHref href={{ pathname: "/project" }}>
49-
<Link>Project</Link>
50-
</A>
48+
<Link component={A} href={{ pathname: "/project" }}>
49+
Project
50+
</Link>
5151
</ListItem>
5252
<ListItem sx={itemStyles}>
53-
<A legacyBehavior passHref href={{ pathname: "/run" }}>
54-
<Link>Apps/Jobs</Link>
55-
</A>
53+
<Link component={A} href={{ pathname: "/run" }}>
54+
Apps/Jobs
55+
</Link>
5656
</ListItem>
5757
</List>
5858
</Grid>
5959
<Grid size={{ sm: 3, xs: 6 }}>
6060
<List dense sx={{ p: 0 }}>
6161
<ListItem sx={itemStyles}>
62-
<A legacyBehavior passHref href={{ pathname: "/results" }}>
63-
<Link>Results</Link>
64-
</A>
62+
<Link component={A} href={{ pathname: "/results" }}>
63+
Results
64+
</Link>
6565
</ListItem>
6666
<ListItem sx={itemStyles}>
67-
<A legacyBehavior passHref href={{ pathname: "/products" }}>
68-
<Link>Products</Link>
69-
</A>
67+
<Link component={A} href={{ pathname: "/products" }}>
68+
Products
69+
</Link>
7070
</ListItem>
7171
<ListItem sx={itemStyles}>
72-
<A legacyBehavior passHref href={{ pathname: "/docs/guided-tour" }}>
73-
<Link>Docs</Link>
74-
</A>
72+
<Link component={A} href={{ pathname: "/docs/guided-tour" }}>
73+
Docs
74+
</Link>
7575
</ListItem>
7676
</List>
7777
</Grid>

src/layouts/navigation/MobileNavMenu.tsx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import {
1111
ListItemText,
1212
Typography,
1313
} from "@mui/material";
14+
import A from "next/link";
15+
import { useRouter } from "next/router";
1416

1517
import { ModalWrapper } from "../../components/modals/ModalWrapper";
1618
import { useDMAuthorizationStatus } from "../../hooks/useIsAuthorized";
17-
import { NavLink } from "./NavLink";
19+
import { NAV_LINKS, NAV_PARAMS_TO_STRIP, type NavLinkData } from "./navigationConstants";
1820
import { OUPContext } from "./OUPContext";
1921
import { UserMenuContent } from "./UserMenuContent";
2022

@@ -27,6 +29,7 @@ import { UserMenuContent } from "./UserMenuContent";
2729
export const MobileNavMenu = () => {
2830
const [open, setOpen] = useState(false);
2931
const isDMAuthorized = useDMAuthorizationStatus();
32+
const router = useRouter();
3033

3134
return (
3235
<>
@@ -43,34 +46,23 @@ export const MobileNavMenu = () => {
4346
Links
4447
</Typography>
4548
<List aria-label="main-mobile-navigation" component="nav">
46-
<NavLink stripQueryParameters={["taskId", "instanceId", "path"]} title="Datasets">
47-
{({ active }) => (
48-
<ListItemButton component="a" selected={active}>
49-
<ListItemText primary="Datasets" />
50-
</ListItemButton>
51-
)}
52-
</NavLink>
53-
<NavLink stripQueryParameters={["taskId", "instanceId", "path"]} title="Project">
54-
{({ active }) => (
55-
<ListItemButton component="a" selected={active}>
56-
<ListItemText primary="Project" />
57-
</ListItemButton>
58-
)}
59-
</NavLink>
60-
<NavLink stripQueryParameters={["taskId", "instanceId", "path"]} title="Run">
61-
{({ active }) => (
62-
<ListItemButton component="a" selected={active}>
63-
<ListItemText primary="Apps/Jobs" />
64-
</ListItemButton>
65-
)}
66-
</NavLink>
67-
<NavLink stripQueryParameters={["taskId", "instanceId", "path"]} title="Results">
68-
{({ active }) => (
69-
<ListItemButton component="a" selected={active}>
70-
<ListItemText primary="Results" />
49+
{NAV_LINKS.map(({ title, path, text }: NavLinkData) => {
50+
const active = router.pathname.startsWith(path);
51+
const query = { ...router.query };
52+
NAV_PARAMS_TO_STRIP.forEach((param: string) => delete query[param]);
53+
const href = { query, pathname: path };
54+
55+
return (
56+
<ListItemButton
57+
component={A}
58+
href={href}
59+
key={title}
60+
selected={active}
61+
>
62+
<ListItemText primary={text} />
7163
</ListItemButton>
72-
)}
73-
</NavLink>
64+
);
65+
})}
7466
</List>
7567
</Grid>
7668
<Grid

src/layouts/navigation/NavLink.tsx

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)