Skip to content

Commit

Permalink
Merge pull request #2891 from Luke-Sikina/improved-routing
Browse files Browse the repository at this point in the history
Routing Improvements
  • Loading branch information
alisman authored Dec 19, 2019
2 parents 1a5786d + b6f1169 commit 7074172
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/pages/groupComparison/GroupComparisonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {MakeMobxView} from "../../shared/components/MobxView";
import LoadingIndicator from "../../shared/components/loadingIndicator/LoadingIndicator";
import ErrorMessage from "../../shared/components/ErrorMessage";
import GroupSelector from "./groupSelector/GroupSelector";
import {getTabId, GroupComparisonTab} from "./GroupComparisonUtils";
import { GroupComparisonTab } from "./GroupComparisonTabs"
import styles from "./styles.module.scss";
import {StudyLink} from "shared/components/StudyLink/StudyLink";
import {action, computed, IReactionDisposer, observable, reaction} from "mobx";
Expand Down
4 changes: 2 additions & 2 deletions src/pages/groupComparison/GroupComparisonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
getOverlapComputations,
getSampleIdentifiers,
getStudyIds,
GroupComparisonTab,
IOverlapComputations,
isGroupEmpty,
partitionCasesByGroupMembership,
getNumSamples
getNumSamples,
} from "./GroupComparisonUtils";
import { GroupComparisonTab } from "./GroupComparisonTabs"
import {remoteData} from "../../public-lib/api/remoteData";
import {
CancerStudy,
Expand Down
9 changes: 9 additions & 0 deletions src/pages/groupComparison/GroupComparisonTabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum GroupComparisonTab {
OVERLAP = "overlap",
MUTATIONS = "mutations",
CNA = "cna",
MRNA = "mrna",
PROTEIN = "protein",
SURVIVAL = "survival",
CLINICAL = "clinical"
}
3 changes: 2 additions & 1 deletion src/pages/groupComparison/GroupComparisonURLWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import URLWrapper from "../../shared/lib/URLWrapper";
import ExtendedRouterStore from "../../shared/lib/ExtendedRouterStore";
import {computed} from "mobx";
import {getTabId, GroupComparisonTab} from "./GroupComparisonUtils";
import {getTabId} from "./GroupComparisonUtils";
import { GroupComparisonTab } from "./GroupComparisonTabs"
import autobind from "autobind-decorator";
import {OverlapStrategy} from "./GroupComparisonStore";

Expand Down
11 changes: 1 addition & 10 deletions src/pages/groupComparison/GroupComparisonUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ import OverlapExclusionIndicator from "./OverlapExclusionIndicator";
import Loader from "../../shared/components/loadingIndicator/LoadingIndicator";
import ErrorMessage from "../../shared/components/ErrorMessage";
import {stringListToIndexSet} from "public-lib/lib/StringUtils";

export enum GroupComparisonTab {
OVERLAP = "overlap",
MUTATIONS = "mutations",
CNA = "cna",
MRNA = "mrna",
PROTEIN = "protein",
SURVIVAL = "survival",
CLINICAL = "clinical"
}
import { GroupComparisonTab } from "./GroupComparisonTabs"

type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

Expand Down
23 changes: 12 additions & 11 deletions src/pages/patientView/PatientViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { PagePath } from "shared/enums/PagePaths";
import { GeneFilterOption } from "./mutation/GeneFilterMenu";
import { checkNonProfiledGenesExist } from "./PatientViewPageUtils";
import PatientViewGenePanelModal from "./PatientViewGenePanelModal/PatientViewGenePanelModal";
import { PatientViewPageTabs } from "./PatientViewPageTabs";

export interface IPatientViewPageProps {
params: any; // react route
Expand Down Expand Up @@ -269,15 +270,15 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
this.patientViewPageStore.sampleToDiscreteGenePanelId.result,
this.patientViewPageStore.genePanelIdToEntrezGeneIds.result);
}

@autobind
@action toggleGenePanelModal(genePanelId?:string|undefined) {
this.genePanelModal = {
isOpen: !this.genePanelModal.isOpen,
genePanelId: genePanelId || ''
};
}

@computed get modalSelectedGenePanel() {
return this.patientViewPageStore.genePanelIdToPanel.result[this.genePanelModal.genePanelId];
}
Expand Down Expand Up @@ -403,8 +404,8 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
)
}
<div className="patientViewPage">
{this.genePanelModal.isOpen &&
<PatientViewGenePanelModal
{this.genePanelModal.isOpen &&
<PatientViewGenePanelModal
genePanel={this.modalSelectedGenePanel}
show={this.genePanelModal.isOpen}
onHide={this.toggleGenePanelModal}
Expand Down Expand Up @@ -448,7 +449,7 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
onTabClick={(id:string)=>this.urlWrapper.setTab(id)}
className="mainTabs"
>
<MSKTab key={0} id="summary" linkText="Summary">
<MSKTab key={0} id={PatientViewPageTabs.Summary} linkText="Summary">

<LoadingIndicator isLoading={this.patientViewPageStore.clinicalEvents.isPending} />

Expand Down Expand Up @@ -599,7 +600,7 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
}
</MSKTab>

<MSKTab key={2} id="clinicalData" linkText="Clinical Data">
<MSKTab key={2} id={PatientViewPageTabs.ClinicalData} linkText="Clinical Data">

<div className="clearfix">
<FeatureTitle title="Patient"
Expand All @@ -626,15 +627,15 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
</MSKTab>


<MSKTab key={3} id="pathologyReport" linkText="Pathology Report"
<MSKTab key={3} id={PatientViewPageTabs.PathologyReport} linkText="Pathology Report"
hide={!this.shouldShowPathologyReport(this.patientViewPageStore)}
>
<div>
<PathologyReport iframeHeight={WindowStore.size.height - 220} pdfs={this.patientViewPageStore.pathologyReport.result} />
</div>
</MSKTab>

<MSKTab key={5} id="tissueImage" linkText="Tissue Image"
<MSKTab key={5} id={PatientViewPageTabs.TissueImage} linkText="Tissue Image"
hide={this.hideTissueImageTab()}
>
<div>
Expand All @@ -643,7 +644,7 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
</MSKTab>

{(this.patientViewPageStore.studyId === "mskimpact" && this.wholeSlideViewerUrl.result) && (
<MSKTab key={6} id="MSKTissueImage" linkText="Tissue Image"
<MSKTab key={6} id={PatientViewPageTabs.MSKTissueImage} linkText="Tissue Image"
unmountOnHide = {false}
>
<div>
Expand All @@ -654,7 +655,7 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro

{
this.shouldShowTrialMatch(this.patientViewPageStore) && (
<MSKTab key={7} id="trialMatchTab" linkText="Matched Trials">
<MSKTab key={7} id={PatientViewPageTabs.TrialMatchTab} linkText="Matched Trials">
<TrialMatchTable
sampleManager={sampleManager}
detailedTrialMatches={this.patientViewPageStore.detailedTrialMatches.result}
Expand All @@ -664,7 +665,7 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
)
}

{/*<MSKTab key={5} id="mutationalSignatures" linkText="Mutational Signature Data" hide={true}>*/}
{/*<MSKTab key={5} id={{PatientViewPageTabs.MutationalSignatures}} linkText="Mutational Signature Data" hide={true}>*/}
{/*<div className="clearfix">*/}
{/*<FeatureTitle title="Mutational Signatures" isLoading={ this.patientViewPageStore.clinicalDataGroupedBySample.isPending } className="pull-left" />*/}
{/*<LoadingIndicator isLoading={this.patientViewPageStore.mutationalSignatureData.isPending}/>*/}
Expand Down
9 changes: 9 additions & 0 deletions src/pages/patientView/PatientViewPageTabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum PatientViewPageTabs {
Summary = "summary",
ClinicalData = "clinicalData",
PathologyReport = "pathologyReport",
TissueImage = "tissueImage",
MSKTissueImage = "MSKTissueImage",
TrialMatchTab = "trialMatchTab",
MutationalSignatures = "mutationalSignatures",
}
31 changes: 31 additions & 0 deletions src/pages/resultsView/ErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { inject } from 'mobx-react';
import { AppStore } from 'AppStore';
import PortalHeader from 'appShell/App/PortalHeader';
import PortalFooter from 'appShell/App/PortalFooter';
import UserMessager from 'shared/components/userMessager/UserMessage';
import ErrorScreen from 'shared/components/errorScreen/ErrorScreen';
import { formatErrorTitle } from 'shared/lib/errorFormatter';
import { buildCBioPortalPageUrl } from 'shared/api/urls';

@inject("appStore")
export default class ErrorPage extends React.Component<{appStore?: AppStore}, {}> {
render () {
return (
<div>
<div className="pageTopContainer">
<UserMessager />
<div className="contentWidth">
<PortalHeader appStore={this.props.appStore as AppStore}/>
</div>
</div>
<div className="contentWrapper">
<ErrorScreen
title={"Sorry, this page doesn't exist."}
body={<a href={buildCBioPortalPageUrl("/")}>Return to homepage</a>}
/>
</div>
</div>
)
}
}
2 changes: 1 addition & 1 deletion src/pages/studyView/StudyViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
CustomChart,
StudyViewPageStore,
StudyViewPageTabDescriptions,
StudyViewPageTabKeyEnum,
StudyViewURLQuery,
} from "pages/studyView/StudyViewPageStore";
import { StudyViewPageTabKeyEnum } from "pages/studyView/StudyViewPageTabs";
import LoadingIndicator from "shared/components/loadingIndicator/LoadingIndicator";
import { ClinicalDataTab } from "./tabs/ClinicalDataTab";
import getBrowserWindow from "../../public-lib/lib/getBrowserWindow";
Expand Down
8 changes: 1 addition & 7 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import {
} from "pages/studyView/TableUtils";
import { GeneTableRow } from './table/GeneTable';
import { getSelectedGroups, getGroupParameters } from '../groupComparison/comparisonGroupManager/ComparisonGroupManagerUtils';
import { StudyViewPageTabKeyEnum } from "pages/studyView/StudyViewPageTabs";

export type ChartUserSetting = {
id: string,
Expand All @@ -157,13 +158,6 @@ export type StudyPageSettings = {
origin:string[]
}

export enum StudyViewPageTabKeyEnum {
SUMMARY = 'summary',
CLINICAL_DATA = 'clinicalData',
HEATMAPS = 'heatmaps',
CN_SEGMENTS = 'cnSegments'
}

export type StudyViewPageTabKey =
StudyViewPageTabKeyEnum.CLINICAL_DATA | StudyViewPageTabKeyEnum.SUMMARY | StudyViewPageTabKeyEnum.HEATMAPS |
StudyViewPageTabKeyEnum.CN_SEGMENTS;
Expand Down
6 changes: 6 additions & 0 deletions src/pages/studyView/StudyViewPageTabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum StudyViewPageTabKeyEnum {
SUMMARY = 'summary',
CLINICAL_DATA = 'clinicalData',
HEATMAPS = 'heatmaps',
CN_SEGMENTS = 'cnSegments',
}
4 changes: 1 addition & 3 deletions src/pages/studyView/StudyViewUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ import {
StudyViewFilter
} from 'shared/api/generated/CBioPortalAPIInternal';
import {CancerStudy, ClinicalAttribute, Gene} from 'shared/api/generated/CBioPortalAPI';
import {
StudyViewPageTabKeyEnum
} from "./StudyViewPageStore";
import { StudyViewPageTabKeyEnum } from "pages/studyView/StudyViewPageTabs";
import {
UniqueKey
} from "./StudyViewUtils";
Expand Down
6 changes: 3 additions & 3 deletions src/pages/studyView/StudyViewUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import * as React from "react";
import {buildCBioPortalPageUrl} from "../../shared/api/urls";
import {IStudyViewScatterPlotData} from "./charts/scatterPlot/StudyViewScatterPlot";
import {BarDatum} from "./charts/barChart/BarChart";
import {
StudyViewPageTabKeyEnum, ChartUserSetting, CustomChart
} from "./StudyViewPageStore";
import { ChartUserSetting, CustomChart } from "./StudyViewPageStore";
import { StudyViewPageTabKeyEnum } from "pages/studyView/StudyViewPageTabs";

import {Layout} from 'react-grid-layout';
import internalClient from "shared/api/cbioportalInternalClientInstance";
import {VirtualStudy} from "shared/model/VirtualStudy";
Expand Down
5 changes: 3 additions & 2 deletions src/pages/studyView/addChartButton/AddChartButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {ChildButton, MainButton, Menu} from 'react-mfb';
import 'react-mfb/mfb.css';
import {
CustomChart,
StudyViewPageStore, StudyViewPageTabKey,
StudyViewPageTabKeyEnum
StudyViewPageStore,
StudyViewPageTabKey,
} from "../StudyViewPageStore";
import { StudyViewPageTabKeyEnum } from "pages/studyView/StudyViewPageTabs";
import autobind from 'autobind-decorator';
import * as _ from 'lodash';
import AddChartByType from "./addChartByType/AddChartByType";
Expand Down
3 changes: 2 additions & 1 deletion src/pages/studyView/tabs/CNSegments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import LoadingIndicator from "shared/components/loadingIndicator/LoadingIndicato
import CNSegmentsDownloader from "shared/components/cnSegments/CNSegmentsDownloader";
import WindowStore from "shared/components/window/WindowStore";

import {StudyViewPageStore, StudyViewPageTabKeyEnum} from "../StudyViewPageStore";
import { StudyViewPageTabKeyEnum } from "pages/studyView/StudyViewPageTabs";
import {StudyViewPageStore} from "../StudyViewPageStore";

@observer
export default class CNSegments extends React.Component<{ store: StudyViewPageStore }, {}> {
Expand Down
46 changes: 31 additions & 15 deletions src/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import PageNotFound from './shared/components/pageNotFound/PageNotFound';
/* HOW TO ADD A NEW ROUTE
* 1. Import the "page" component using the bundle-loader directives as seen in imports below
* 2. Add a Route element with getComponent set to the result the lazyLoadComponent function passed your new component
* If your route includes tabs, include `null, tabParamValidator(YourPageTabEnum) in the lazyLoadComponent call.
* This ensures that invalid sub routes 404 correctly
*/

// import page components here
Expand All @@ -39,27 +41,40 @@ import News from 'bundle-loader?lazy!babel-loader!./pages/staticPages/news/News'
import FAQ from 'bundle-loader?lazy!babel-loader!./pages/staticPages/faq/FAQ';
import OQL from 'bundle-loader?lazy!babel-loader!./pages/staticPages/oql/OQL';
import GroupComparisonPage from 'bundle-loader?lazy!babel-loader!./pages/groupComparison/GroupComparisonPage';
import ErrorPage from 'bundle-loader?lazy!babel-loader!./pages/resultsView/ErrorPage';

import AppConfig from 'appConfig';

import { getBasePath } from 'shared/api/urls';
import $ from 'jquery';
import ExtendedRouterStore from 'shared/lib/ExtendedRouterStore';
import getBrowserWindow from 'public-lib/lib/getBrowserWindow';
import { seekUrlHash } from 'shared/lib/seekUrlHash';
import queryString from 'query-string';
import { PagePath } from 'shared/enums/PagePaths';
import { ResultsViewTab } from 'pages/resultsView/ResultsViewPageHelpers'
import { StudyViewPageTabKeyEnum } from 'pages/studyView/StudyViewPageTabs'
import { PatientViewPageTabs } from 'pages/patientView/PatientViewPageTabs'
import { GroupComparisonTab } from 'pages/groupComparison/GroupComparisonTabs'

/**
* Validates that the parameters either do not have
* a tab parameter, or have a parameter that matches a
* value in `tabEnum`
* @param tabEnum a TypeScript string enum
*/
function tabParamValidator(tabEnum) {
return function(params) {
return !params.tab || Object.values(tabEnum).indexOf(params.tab) > -1;
}
}

// accepts bundle-loader's deferred loader function and defers execution of route's render
// until chunk is loaded
function lazyLoadComponent(loader, loadingCallback) {
function lazyLoadComponent(loader, loadingCallback, validator = (_) => {return true;}) {
return (location, cb) => {
if (location && !validator(location.params)) {
loader = ErrorPage;
}
loader(module => {
if (cb) cb(null, module.default);
if (loadingCallback) loadingCallback();
// if (typeof window.onReactAppReady === 'function') {
// window.onReactAppReady();
// }
if (cb) { cb(null, module.default); }
if (loadingCallback) { loadingCallback(); }
});
};
}
Expand Down Expand Up @@ -123,28 +138,29 @@ export const makeRoutes = routing => {
/>
<Route
path="/results(/:tab)"
getComponent={lazyLoadComponent(ResultsViewPage)}
onEnter={() => {}}
getComponent={lazyLoadComponent(ResultsViewPage, null, tabParamValidator(ResultsViewTab))}
/>
<Route
path={'/' + PagePath.Patient + '(/:tab)'}
onEnter={() => {
$(document).scrollTop(0);
}}
getComponent={lazyLoadComponent(PatientViewPage)}
getComponent={lazyLoadComponent(PatientViewPage, null, tabParamValidator(PatientViewPageTabs))}
/>
<Route
path="/study(/:tab)"
path={"/" + PagePath.Study + "(/:tab)" }
onEnter={() => {
$(document).scrollTop(0);
}}
getComponent={lazyLoadComponent(StudyViewPage)}
getComponent={lazyLoadComponent(StudyViewPage, null, tabParamValidator(StudyViewPageTabKeyEnum))}
/>
<Route
path="/comparison(/:tab)"
onEnter={() => {
$(document).scrollTop(0);
}}
getComponent={lazyLoadComponent(GroupComparisonPage)}
getComponent={lazyLoadComponent(GroupComparisonPage, null, tabParamValidator(GroupComparisonTab))}
/>

<Route
Expand Down
Loading

0 comments on commit 7074172

Please sign in to comment.