Skip to content

Commit

Permalink
Create gene on gene link click if does not exist (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
bprize15 authored Nov 7, 2024
1 parent 8708e25 commit 8b4edf6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
32 changes: 28 additions & 4 deletions src/main/webapp/app/pages/curation/GeneListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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 { geneNeedsReview } from 'app/shared/util/firebase/firebase-utils';
import { Link, RouteComponentProps, generatePath } from 'react-router-dom';
import { createGeneIfDoesNotExist, 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';
import { filterByKeyword } from 'app/shared/util/utils';
Expand All @@ -22,6 +22,7 @@ const getCurationPageLink = (hugoSymbol: string, isGermline: boolean) => {
};
import CurationDataImportTab from 'app/components/tabs/curation-data-import-tab/CurationDataImportTab';
import { DATA_IMPORT_TAB_ID, GENE_LIST_TABLE_ID } from 'app/config/constants/html-id';
import { notifyError } from 'app/oncokb-commons/components/util/NotificationUtils';

type GeneMetaInfo = {
hugoSymbol: string;
Expand All @@ -33,6 +34,8 @@ type GeneMetaInfo = {
export interface IGeneListPage extends StoreProps, RouteComponentProps {}

const GeneListPage = (props: IGeneListPage) => {
const history = useHistory();

const pathname = props.location.pathname;
const isGermline = pathname.includes(GERMLINE_PATH);

Expand Down Expand Up @@ -67,7 +70,26 @@ const GeneListPage = (props: IGeneListPage) => {
accessor: 'hugoSymbol',
Header: 'Hugo Symbol',
Cell(cell: { value: string }): any {
return <Link to={getCurationPageLink(cell.value, isGermline)}>{cell.value}</Link>;
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>
);
},
onFilter: (data: GeneMetaInfo, keyword) => (data.hugoSymbol ? filterByKeyword(data.hugoSymbol, keyword) : false),
},
Expand Down Expand Up @@ -161,12 +183,14 @@ const GeneListPage = (props: IGeneListPage) => {
);
};

const mapStoreToProps = ({ firebaseMetaStore, firebaseAppStore }: IRootStore) => ({
const mapStoreToProps = ({ firebaseMetaStore, firebaseAppStore, firebaseGeneService }: IRootStore) => ({
firebaseDb: firebaseAppStore.firebaseDb,
firebaseReady: firebaseAppStore.firebaseReady,
firebaseInitError: firebaseAppStore.firebaseInitError,
firebaseLoginError: firebaseAppStore.firebaseLoginError,
addMetaListener: firebaseMetaStore.addListener,
metaData: firebaseMetaStore.data,
createGene: firebaseGeneService.createGene,
});

type StoreProps = ReturnType<typeof mapStoreToProps>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { notifyError } from 'app/oncokb-commons/components/util/NotificationUtils';
import { getFirebasePath } from 'app/shared/util/firebase/firebase-utils';
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';
Expand Down Expand Up @@ -29,14 +29,10 @@ function SomaticGermlineToggleButton({ hugoSymbol, firebaseDb, createGene }: ISo
if (!firebaseDb) {
return;
}
if (hugoSymbol) {
if (hugoSymbol && createGene) {
// On curation page
const genePath = getFirebasePath(isSomatic ? 'GENE' : 'GERMLINE_GENE', hugoSymbol);
try {
const snapshot = await get(ref(firebaseDb, genePath));
if (!snapshot.exists()) {
await createGene?.(hugoSymbol, !isSomatic);
}
await createGeneIfDoesNotExist(hugoSymbol, newVariantType === 'germline', firebaseDb, createGene);
} catch (error) {
notifyError(error);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/webapp/app/shared/util/firebase/firebase-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { extractPositionFromSingleNucleotideAlteration, getCancerTypeName, isUui
import { isTxLevelPresent } from './firebase-level-utils';
import { parseFirebaseGenePath } from './firebase-path-utils';
import { hasReview } from './firebase-review-utils';
import { Database, ref, get } from 'firebase/database';
import { FirebaseGeneService } from 'app/service/firebase/firebase-gene-service';

export const getValueByNestedKey = (obj: any, nestedKey = '') => {
return nestedKey.split('/').reduce((currObj, currKey) => {
Expand Down Expand Up @@ -961,3 +963,16 @@ 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 8b4edf6

Please sign in to comment.