Skip to content

Commit

Permalink
Added Vus submissions to core (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkonecn authored Oct 8, 2024
1 parent dafac59 commit 82dfe1a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Firebase Gene Review Service', () => {
});

mockVusService.getVusUpdateObject.mockImplementation((path, variants) => {
const originalVusService = new FirebaseVusService(mockFirebaseRepository, mockAuthStore);
const originalVusService = new FirebaseVusService(mockFirebaseRepository, mockEvidenceClient, mockAuthStore);
return originalVusService.getVusUpdateObject(path, variants);
});

Expand Down
10 changes: 8 additions & 2 deletions src/main/webapp/app/service/firebase/firebase-vus-service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { EvidenceApi } from 'app/shared/api/manual/evidence-api';
import { Vus } from 'app/shared/model/firebase/firebase.model';
import { getUserFullName } from 'app/shared/util/utils';
import { AuthStore } from 'app/stores';
import { FirebaseRepository } from 'app/stores/firebase/firebase-repository';
import { push } from 'firebase/database';
import _ from 'lodash';

export class FirebaseVusService {
firebaseRepository: FirebaseRepository;
evidenceClient: EvidenceApi;
authStore: AuthStore;

constructor(firebaseRepository: FirebaseRepository, authStore: AuthStore) {
constructor(firebaseRepository: FirebaseRepository, evidenceClient: EvidenceApi, authStore: AuthStore) {
this.firebaseRepository = firebaseRepository;
this.evidenceClient = evidenceClient;
this.authStore = authStore;
}

Expand Down Expand Up @@ -45,4 +47,8 @@ export class FirebaseVusService {
deleteVus = async (path: string) => {
await this.firebaseRepository.delete(path);
};

async sendVusToCore(hugoSymbol: string, vus: Vus[]) {
await this.evidenceClient.updateVus(hugoSymbol, vus);
}
}
45 changes: 45 additions & 0 deletions src/main/webapp/app/shared/api/manual/evidence-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Configuration } from '../generated/core';
import { createRequestFunction } from '../generated/core/common';
import { DUMMY_BASE_URL, assertParamExists, serializeDataIfNeeded, setSearchParams, toPathString } from '../generated/core/common';
import { NonUndefined } from 'react-hook-form';
import { Vus } from 'app/shared/model/firebase/firebase.model';

export const EvidenceAxiosParamCreator = function (configuration?: Configuration) {
return {
Expand Down Expand Up @@ -36,6 +37,7 @@ export const EvidenceAxiosParamCreator = function (configuration?: Configuration
options: localVarRequestOptions,
};
},

// eslint-disable-next-line @typescript-eslint/require-await
async deleteEvidences(
deleteEvidencesPayload: NonUndefined<ReturnType<typeof pathToDeleteEvidenceArgs>>,
Expand Down Expand Up @@ -67,6 +69,36 @@ export const EvidenceAxiosParamCreator = function (configuration?: Configuration
options: localVarRequestOptions,
};
},

// eslint-disable-next-line @typescript-eslint/require-await
async updateVus(hugoSymbol: string, vus: Vus[], options: AxiosRequestConfig = {}): Promise<RequestArgs> {
// verify required parameter 'requestBody' is not null or undefined
assertParamExists('updateVus', 'hugoSymbol', hugoSymbol);
assertParamExists('updateVus', 'vus', vus);
const localVarPath = `/legacy-api/vus/update/${hugoSymbol}`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions: { headers: any } | undefined = undefined;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
const headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
localVarRequestOptions.data = serializeDataIfNeeded(vus, localVarRequestOptions, configuration);

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
};
};

Expand All @@ -87,6 +119,14 @@ export const EvidenceApiFp = function (configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.deleteEvidences(deleteEvidencesPayload, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
async updateVus(
hugoSymbol: string,
vus: Vus[],
options: AxiosRequestConfig = {},
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.updateVus(hugoSymbol, vus, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
};
};

Expand All @@ -101,4 +141,9 @@ export class EvidenceApi extends BaseAPI {
.deleteEvidences(deleteEvidencesPayload, options)
.then(request => request(this.axios, this.basePath));
}
public updateVus(hugoSymbol: string, vus: Vus[], options?: AxiosRequestConfig) {
return EvidenceApiFp(this.configuration)
.updateVus(hugoSymbol, vus, options)
.then(request => request(this.axios, this.basePath));
}
}
21 changes: 20 additions & 1 deletion src/main/webapp/app/shared/table/VusTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { observer } from 'mobx-react';
import { notifyError, notifySuccess } from 'app/oncokb-commons/components/util/NotificationUtils';
import classNames from 'classnames';
import AddButton from 'app/pages/curation/button/AddButton';
import { onValue, ref } from 'firebase/database';
import { get, onValue, ref } from 'firebase/database';
import { downloadFile } from 'app/shared/util/file-utils';
import { VusRecencyInfoIcon } from 'app/shared/icons/VusRecencyInfoIcon';
import DefaultBadge from 'app/shared/badge/DefaultBadge';
Expand All @@ -33,6 +33,7 @@ import MutationConvertIcon from '../icons/MutationConvertIcon';
import AddMutationModal from '../modal/AddMutationModal';
import { Unsubscribe } from 'firebase/database';
import { VUS_TABLE_ID } from 'app/config/constants/html-id';
import { SentryError } from 'app/config/sentry-error';

export interface IVusTableProps extends StoreProps {
hugoSymbol: string | undefined;
Expand All @@ -56,6 +57,7 @@ const VusTable = ({
mutationsSectionRef,
isGermline,
account,
sendVusToCore,
addVus,
refreshVus,
deleteVus,
Expand Down Expand Up @@ -112,6 +114,7 @@ const VusTable = ({
try {
if (vusData) {
await refreshVus?.(`${firebaseVusPath}/${uuid}`, vusData[uuid]);
syncVusWithCore();
}
} catch (error) {
notifyError(error);
Expand All @@ -121,6 +124,7 @@ const VusTable = ({
async function handleDelete() {
try {
await deleteVus?.(`${firebaseVusPath}/${currentActionVusUuid.current}`);
syncVusWithCore();
} catch (error) {
notifyError(error);
}
Expand All @@ -129,6 +133,20 @@ const VusTable = ({
async function handleAddVus(variants: string[]) {
await addVus?.(firebaseVusPath, variants);
setShowAddVusModal(false);
syncVusWithCore();
}

async function syncVusWithCore() {
try {
if (firebaseDb && hugoSymbol) {
const firebaseVus = (await get(ref(firebaseDb, firebaseVusPath))).val() as Record<string, Vus>;
const vus = Object.values(firebaseVus);
await sendVusToCore?.(hugoSymbol, vus);
}
} catch (e) {
const error = new SentryError('Fail to submit VUS data to core.', { exception: e, hugoSymbol });
console.error(error);
}
}

const columns: SearchColumn<VusTableData>[] = [
Expand Down Expand Up @@ -306,6 +324,7 @@ const mapStoreToProps = ({
fullName: authStore.fullName,
addMutation: firebaseGeneService.addMutation,
setOpenMutationCollapsibleIndex: openMutationCollapsibleStore.setOpenMutationCollapsibleIndex,
sendVusToCore: firebaseVusService.sendVusToCore.bind(firebaseVusService),
});

type StoreProps = Partial<ReturnType<typeof mapStoreToProps>>;
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/stores/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export function createStores(history: History): IRootStore {
/* Firebase Services */
const firebaseMetaService = new FirebaseMetaService(firebaseRepository, rootStore.authStore);
const firebaseHistoryService = new FirebaseHistoryService(firebaseRepository);
const firebaseVusService = new FirebaseVusService(firebaseRepository, rootStore.authStore);
const firebaseVusService = new FirebaseVusService(firebaseRepository, evidenceClient, rootStore.authStore);
const firebaseGeneReviewService = new FirebaseGeneReviewService(
firebaseRepository,
rootStore.authStore,
Expand Down

0 comments on commit 82dfe1a

Please sign in to comment.