Skip to content

Commit

Permalink
move gene creation logic to gene page
Browse files Browse the repository at this point in the history
  • Loading branch information
bprize15 committed Nov 8, 2024
1 parent 8b4edf6 commit 183056f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 52 deletions.
34 changes: 30 additions & 4 deletions src/main/webapp/app/pages/curation/CurationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { connect } from 'app/shared/util/typed-inject';
import { IRootStore } from 'app/stores';
import { RouteComponentProps } from 'react-router-dom';
import { RouteComponentProps, useHistory } from 'react-router-dom';
import { getFirebaseGenePath, getFirebaseHistoryPath, getFirebaseMetaGenePath } from 'app/shared/util/firebase/firebase-utils';
import { Col, Row } from 'reactstrap';
import { getSectionClassName } from 'app/shared/util/utils';
import { GENE_TYPE, GENE_TYPE_KEY, INHERITANCE_MECHANISM_OPTIONS, READABLE_FIELD, PENETRANCE_OPTIONS } from 'app/config/constants/firebase';
import { GERMLINE_PATH, GET_ALL_DRUGS_PAGE_SIZE, RADIO_OPTION_NONE } from 'app/config/constants/constants';
import { GERMLINE_PATH, GET_ALL_DRUGS_PAGE_SIZE, PAGE_ROUTE, RADIO_OPTION_NONE } from 'app/config/constants/constants';
import CommentIcon from 'app/shared/icons/CommentIcon';
import GeneHistoryTooltip from 'app/components/geneHistoryTooltip/GeneHistoryTooltip';
import MutationsSection from './mutation/MutationsSection';
Expand All @@ -26,16 +26,18 @@ import { notifyError } from 'app/oncokb-commons/components/util/NotificationUtil
import LoadingIndicator, { LoaderSize } from 'app/oncokb-commons/components/loadingIndicator/LoadingIndicator';
import { FlattenedHistory, parseHistory } from 'app/shared/util/firebase/firebase-history-utils';
import { useMatchGeneEntity } from 'app/hooks/useMatchGeneEntity';
import { Unsubscribe } from 'firebase/database';
import { Unsubscribe, get, ref } from 'firebase/database';
import { getLocationIdentifier, getTooltipHistoryList } from 'app/components/geneHistoryTooltip/gene-history-tooltip-utils';

export interface ICurationPageProps extends StoreProps, RouteComponentProps<{ hugoSymbol: string }> {}

export const CurationPage = (props: ICurationPageProps) => {
const history = useHistory();
const pathname = props.location.pathname;
const isGermline = pathname.includes(GERMLINE_PATH);
const hugoSymbolParam = props.match.params.hugoSymbol;

const [firebaseGeneExists, setFirebaseGeneExists] = useState(false);
const [mutationListRendered, setMutationListRendered] = useState(false);
const mutationsSectionRef = useRef<HTMLDivElement>(null);

Expand All @@ -48,6 +50,29 @@ export const CurationPage = (props: ICurationPageProps) => {
const firebaseMetaGeneReviewPath = `${getFirebaseMetaGenePath(isGermline, hugoSymbol)}/review`;
const firebaseMetaCurrentReviewerPath = `${firebaseMetaGeneReviewPath}/currentReviewer`;

useEffect(() => {
async function checkIfGeneExists() {
if (props.firebaseDb && hugoSymbol) {
const snapshot = await get(ref(props.firebaseDb, firebaseGenePath));
if (!snapshot.exists()) {
try {
await props.createGene(hugoSymbol, isGermline);
} catch (error) {
notifyError(error);
if (isGermline) {
history.push(PAGE_ROUTE.CURATION_GERMLINE);
} else {
history.push(PAGE_ROUTE.CURATION_SOMATIC);
}
}
}
setFirebaseGeneExists(true);
}
}

checkIfGeneExists();
}, [firebaseGenePath, setFirebaseGeneExists, props.firebaseDb, hugoSymbol, isGermline]);

useEffect(() => {
props.getDrugs({ page: 0, size: GET_ALL_DRUGS_PAGE_SIZE, sort: ['id,asc'] });
return () => {
Expand Down Expand Up @@ -85,7 +110,7 @@ export const CurationPage = (props: ICurationPageProps) => {
return getTooltipHistoryList(tabHistoryList);
}, [tabHistoryList]);

return props.firebaseInitSuccess && !props.loadingGenes && props.drugList.length > 0 && !!geneEntity ? (
return props.firebaseInitSuccess && !props.loadingGenes && props.drugList.length > 0 && !!geneEntity && firebaseGeneExists ? (
<>
<div style={{ visibility: mutationListRendered ? 'visible' : 'hidden' }}>
<GeneHeader
Expand Down Expand Up @@ -296,6 +321,7 @@ const mapStoreToProps = ({
relevantCancerTypesModalStore,
fullName: authStore.fullName,
updateRelevantCancerTypes: firebaseGeneService.updateRelevantCancerTypes,
createGene: firebaseGeneService.createGene,
setOpenMutationCollapsibleIndex: openMutationCollapsibleStore.setOpenMutationCollapsibleIndex,
toggleOncoKBSidebar: layoutStore.toggleOncoKBSidebar,
});
Expand Down
23 changes: 2 additions & 21 deletions src/main/webapp/app/pages/curation/GeneListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect } from 'app/shared/util/typed-inject';
import { IRootStore } from 'app/stores';
import { Col, Row } from 'reactstrap';
import LoadingIndicator, { LoaderSize } from 'app/oncokb-commons/components/loadingIndicator/LoadingIndicator';
import { createGeneIfDoesNotExist, geneNeedsReview } from 'app/shared/util/firebase/firebase-utils';
import { geneNeedsReview } from 'app/shared/util/firebase/firebase-utils';
import { Link, RouteComponentProps, generatePath, useHistory } from 'react-router-dom';
import { APP_DATETIME_FORMAT, GERMLINE_PATH, PAGE_ROUTE } from 'app/config/constants/constants';
import OncoKBTable, { SearchColumn } from 'app/shared/table/OncoKBTable';
Expand Down Expand Up @@ -70,26 +70,7 @@ const GeneListPage = (props: IGeneListPage) => {
accessor: 'hugoSymbol',
Header: 'Hugo Symbol',
Cell(cell: { value: string }): any {
const link = getCurationPageLink(cell.value, isGermline);

return (
<Link
to={undefined}
onClick={async event => {
event.preventDefault();
if (props.firebaseDb) {
try {
await createGeneIfDoesNotExist(cell.value, isGermline, props.firebaseDb, props.createGene);
history.push(link);
} catch (error) {
notifyError(error);
}
}
}}
>
{cell.value}
</Link>
);
return <Link to={getCurationPageLink(cell.value, isGermline)}>{cell.value}</Link>;
},
onFilter: (data: GeneMetaInfo, keyword) => (data.hugoSymbol ? filterByKeyword(data.hugoSymbol, keyword) : false),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { notifyError } from 'app/oncokb-commons/components/util/NotificationUtils';
import { createGeneIfDoesNotExist, getFirebasePath } from 'app/shared/util/firebase/firebase-utils';
import { componentInject } from 'app/shared/util/typed-inject';
import { IRootStore } from 'app/stores';
import { get, ref } from 'firebase/database';
import { observer } from 'mobx-react';
import React from 'react';
import { FaCheckCircle } from 'react-icons/fa';
Expand All @@ -25,18 +23,7 @@ function SomaticGermlineToggleButton({ hugoSymbol, firebaseDb, createGene }: ISo
const currentVariantType = isSomatic ? SOMATIC_PATH : GERMLINE_PATH;
const newVariantType = isSomatic ? GERMLINE_PATH : SOMATIC_PATH;

async function handleToggle() {
if (!firebaseDb) {
return;
}
if (hugoSymbol && createGene) {
// On curation page
try {
await createGeneIfDoesNotExist(hugoSymbol, newVariantType === 'germline', firebaseDb, createGene);
} catch (error) {
notifyError(error);
}
}
function handleToggle() {
localStorage.setItem(SOMATIC_GERMLINE_SETTING_KEY, newVariantType);
window.location.href = pathname.replace(currentVariantType, newVariantType);
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/webapp/app/shared/util/firebase/firebase-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -963,16 +963,3 @@ export function areCancerTypePropertiesEqual(a: string | undefined, b: string |
export function isStringEmpty(string: string | undefined | null) {
return string === '' || _.isNil(string);
}

export async function createGeneIfDoesNotExist(
hugoSymbol: string,
isGermline: boolean,
firebaseDb: Database,
createGene: typeof FirebaseGeneService.prototype.createGene,
) {
const genePath = getFirebasePath(isGermline ? 'GERMLINE_GENE' : 'GENE', hugoSymbol);
const snapshot = await get(ref(firebaseDb, genePath));
if (!snapshot.exists()) {
await createGene?.(hugoSymbol, isGermline);
}
}

0 comments on commit 183056f

Please sign in to comment.