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

[Platform]: Dynamic route fallback #289

Merged
merged 1 commit into from
Nov 16, 2023
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
49 changes: 21 additions & 28 deletions apps/platform/src/pages/DiseasePage/DiseasePage.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Suspense, lazy } from 'react';
import { useQuery } from '@apollo/client';
import { Box, Tab, Tabs } from '@mui/material';
import { Link, Route, Switch, useLocation, useParams } from 'react-router-dom';
import { LoadingBackdrop, BasePage, NewChip, ScrollToTop } from 'ui';
import { Suspense, lazy } from "react";
import { useQuery } from "@apollo/client";
import { Box, Tab, Tabs } from "@mui/material";
import { Link, Redirect, Route, Switch, useLocation, useParams } from "react-router-dom";
import { LoadingBackdrop, BasePage, NewChip, ScrollToTop } from "ui";

import Header from './Header';
import NotFoundPage from '../NotFoundPage';
import Header from "./Header";
import NotFoundPage from "../NotFoundPage";

import DISEASE_PAGE_QUERY from './DiseasePage.gql';
import DISEASE_PAGE_QUERY from "./DiseasePage.gql";

const Profile = lazy(() => import('./Profile'));
const Associations = lazy(() => import('./DiseaseAssociations'));
const ClassicAssociations = lazy(() => import('./ClassicAssociations'));
const Profile = lazy(() => import("./Profile"));
const Associations = lazy(() => import("./DiseaseAssociations"));
const ClassicAssociations = lazy(() => import("./ClassicAssociations"));

function DiseasePage() {
const location = useLocation();
Expand All @@ -29,12 +29,12 @@ function DiseasePage() {
return (
<BasePage
title={
location.pathname.includes('associations')
location.pathname.includes("associations")
? `Targets associated with ${name}`
: `${name} profile page`
}
description={
location.pathname.includes('associations')
location.pathname.includes("associations")
? `Ranked list of targets associated with ${name}`
: `Annotation information for ${name}`
}
Expand All @@ -45,17 +45,11 @@ function DiseasePage() {
<Route
path="/"
render={history => (
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={
history.location.pathname !== '/'
? history.location.pathname
: false
}
>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<Tabs value={history.location.pathname !== "/" ? history.location.pathname : false}>
<Tab
label={
<Box sx={{ textTransform: 'capitalize' }}>
<Box sx={{ textTransform: "capitalize" }}>
<div>
Associated targets
<NewChip />
Expand All @@ -67,17 +61,13 @@ function DiseasePage() {
to={`/disease/${efoId}/associations`}
/>
<Tab
label={
<Box sx={{ textTransform: 'capitalize' }}>
Associated targets
</Box>
}
label={<Box sx={{ textTransform: "capitalize" }}>Associated targets</Box>}
value={`/disease/${efoId}/classic-associations`}
component={Link}
to={`/disease/${efoId}/classic-associations`}
/>
<Tab
label={<Box sx={{ textTransform: 'capitalize' }}>Profile</Box>}
label={<Box sx={{ textTransform: "capitalize" }}>Profile</Box>}
value={`/disease/${efoId}`}
component={Link}
to={`/disease/${efoId}`}
Expand All @@ -97,6 +87,9 @@ function DiseasePage() {
<Route path="/disease/:efoId/classic-associations">
<ClassicAssociations efoId={efoId} name={name} />
</Route>
<Route path="*">
<Redirect to={`/disease/${efoId}`} />
</Route>
</Switch>
</Suspense>
</BasePage>
Expand Down
41 changes: 17 additions & 24 deletions apps/platform/src/pages/DrugPage/DrugPage.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { lazy, Suspense } from 'react';
import { useQuery } from '@apollo/client';
import { BasePage, ScrollToTop, LoadingBackdrop } from 'ui';
import { Box, Tabs, Tab } from '@mui/material';
import { lazy, Suspense } from "react";
import { useQuery } from "@apollo/client";
import { BasePage, ScrollToTop, LoadingBackdrop } from "ui";
import { Box, Tabs, Tab } from "@mui/material";
import {
useLocation,
useParams,
Switch,
Route,
useRouteMatch,
Link,
} from 'react-router-dom';
Redirect,
} from "react-router-dom";

import Header from './Header';
import NotFoundPage from '../NotFoundPage';
import DRUG_PAGE_QUERY from './DrugPage.gql';
import Header from "./Header";
import NotFoundPage from "../NotFoundPage";
import DRUG_PAGE_QUERY from "./DrugPage.gql";

const Profile = lazy(() => import('./Profile'));
const Profile = lazy(() => import("./Profile"));

function DrugPage() {
const location = useLocation();
Expand All @@ -38,27 +39,16 @@ function DrugPage() {
description={`Annotation information for ${name || chemblId}`}
location={location}
>
<Header
loading={loading}
chemblId={chemblId}
name={name}
crossReferences={crossReferences}
/>
<Header loading={loading} chemblId={chemblId} name={name} crossReferences={crossReferences} />
<ScrollToTop />

<Route
path="/"
render={history => (
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={
history.location.pathname !== '/'
? history.location.pathname
: false
}
>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<Tabs value={history.location.pathname !== "/" ? history.location.pathname : false}>
<Tab
label={<Box sx={{ textTransform: 'capitalize' }}>Profile</Box>}
label={<Box sx={{ textTransform: "capitalize" }}>Profile</Box>}
value={`/drug/${chemblId}`}
component={Link}
to={`/drug/${chemblId}`}
Expand All @@ -72,6 +62,9 @@ function DrugPage() {
<Route exact path={path}>
<Profile chemblId={chemblId} name={name} />
</Route>
<Route path="*">
<Redirect to={`/drug/${chemblId}`} />
</Route>
</Switch>
</Suspense>
</BasePage>
Expand Down
56 changes: 24 additions & 32 deletions apps/platform/src/pages/TargetPage/TargetPage.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { Suspense, lazy } from 'react';
import { useQuery } from '@apollo/client';
import { Box, Tab, Tabs } from '@mui/material';
import { Suspense, lazy } from "react";
import { useQuery } from "@apollo/client";
import { Box, Tab, Tabs } from "@mui/material";
import {
Link,
Route,
Switch,
useLocation,
useRouteMatch,
useParams,
} from 'react-router-dom';
import { LoadingBackdrop, BasePage, ScrollToTop, NewChip } from 'ui';
Redirect,
} from "react-router-dom";
import { LoadingBackdrop, BasePage, ScrollToTop, NewChip } from "ui";

import Header from './Header';
import NotFoundPage from '../NotFoundPage';
import { getUniprotIds } from '../../utils/global';
import TARGET_PAGE_QUERY from './TargetPage.gql';
import Header from "./Header";
import NotFoundPage from "../NotFoundPage";
import { getUniprotIds } from "../../utils/global";
import TARGET_PAGE_QUERY from "./TargetPage.gql";

const Profile = lazy(() => import('./Profile'));
const Associations = lazy(() => import('./TargetAssociations'));
const ClassicAssociations = lazy(() => import('./ClassicAssociations'));
const Profile = lazy(() => import("./Profile"));
const Associations = lazy(() => import("./TargetAssociations"));
const ClassicAssociations = lazy(() => import("./ClassicAssociations"));

function TargetPage() {
const location = useLocation();
Expand All @@ -35,19 +36,17 @@ function TargetPage() {

const { approvedSymbol: symbol, approvedName } = data?.target || {};
const uniprotIds = loading ? null : getUniprotIds(data.target.proteinIds);
const crisprId = data?.target.dbXrefs.find(
p => p.source === 'ProjectScore'
)?.id;
const crisprId = data?.target.dbXrefs.find(p => p.source === "ProjectScore")?.id;

return (
<BasePage
title={
location.pathname.includes('associations')
location.pathname.includes("associations")
? `Diseases associated with ${symbol}`
: `${symbol} profile page`
}
description={
location.pathname.includes('associations')
location.pathname.includes("associations")
? `Ranked list of diseases and phenotypes associated with ${symbol}`
: `Annotation information for ${symbol}`
}
Expand All @@ -66,17 +65,11 @@ function TargetPage() {
<Route
path="/"
render={history => (
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={
history.location.pathname !== '/'
? history.location.pathname
: false
}
>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<Tabs value={history.location.pathname !== "/" ? history.location.pathname : false}>
<Tab
label={
<Box sx={{ textTransform: 'capitalize' }}>
<Box sx={{ textTransform: "capitalize" }}>
<div>
Associated diseases
<NewChip />
Expand All @@ -88,17 +81,13 @@ function TargetPage() {
to={`/target/${ensgId}/associations`}
/>
<Tab
label={
<Box sx={{ textTransform: 'capitalize' }}>
Associated diseases
</Box>
}
label={<Box sx={{ textTransform: "capitalize" }}>Associated diseases</Box>}
value={`/target/${ensgId}/classic-associations`}
component={Link}
to={`/target/${ensgId}/classic-associations`}
/>
<Tab
label={<Box sx={{ textTransform: 'capitalize' }}>Profile</Box>}
label={<Box sx={{ textTransform: "capitalize" }}>Profile</Box>}
value={`/target/${ensgId}`}
component={Link}
to={`/target/${ensgId}`}
Expand All @@ -118,6 +107,9 @@ function TargetPage() {
<Route path={`${path}/classic-associations`}>
<ClassicAssociations ensgId={ensgId} symbol={symbol} />
</Route>
<Route path="*">
<Redirect to={`/target/${ensgId}`} />
</Route>
</Switch>
</Suspense>
</BasePage>
Expand Down
Loading