diff --git a/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts b/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts index 8ba9bedad..35f6c0301 100644 --- a/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts +++ b/src/main/webapp/app/service/firebase/firebase-gene-review-service.spec.ts @@ -471,10 +471,12 @@ describe('Firebase Gene Review Service', () => { [FIREBASE_LIST_PATH_TYPE.MUTATION_LIST]: { mutations: [0, 1] }, [FIREBASE_LIST_PATH_TYPE.TUMOR_LIST]: { 'mutations/3/tumors': [3] }, [FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST]: { 'mutations/1/tumors/0/TIs/4/treatment': [0] }, + [FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST]: { genomic_indicators: [0, 1] }, }); expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(1, 'mutations/1/tumors/0/TIs/4/treatment', [0]); expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(2, 'mutations/3/tumors', [3]); expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(3, 'mutations', [0, 1]); + expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(4, 'genomic_indicators', [0, 1]); }); }); diff --git a/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts b/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts index fafaf6680..0cbd8d341 100644 --- a/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts +++ b/src/main/webapp/app/service/firebase/firebase-gene-review-service.ts @@ -144,6 +144,7 @@ export class FirebaseGeneReviewService { [FIREBASE_LIST_PATH_TYPE.MUTATION_LIST]: {}, [FIREBASE_LIST_PATH_TYPE.TUMOR_LIST]: {}, [FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST]: {}, + [FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST]: {}, }; let evidences: ReturnType = {}; @@ -267,7 +268,6 @@ export class FirebaseGeneReviewService { } else { throw new SentryError('Unexpect accept in review mode', { hugoSymbol, reviewLevel, isGermline, isAcceptAll }); } - const metaUpdateObject = this.firebaseMetaService.getUpdateObject(false, hugoSymbol, isGermline, uuid); updateObject = { ...updateObject, ...metaUpdateObject }; } @@ -284,25 +284,10 @@ export class FirebaseGeneReviewService { }); } - // We are deleting last because the indices will change after deleting from array. - let hasDeletion = false; try { // Todo: We should use multi-location updates for deletions once all our arrays use firebase auto-generated keys // instead of using sequential number indices. - for (const pathType of [ - FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST, - FIREBASE_LIST_PATH_TYPE.TUMOR_LIST, - FIREBASE_LIST_PATH_TYPE.MUTATION_LIST, - ]) { - for (const [firebasePath, deleteIndices] of Object.entries(itemsToDelete[pathType])) { - hasDeletion = true; - await this.firebaseRepository.deleteFromArray(firebasePath, deleteIndices); - } - } - // If user accepts a deletion individually, we need to refresh the ReviewPage with the latest data to make sure the indices are up to date. - if (reviewLevels.length === 1 && hasDeletion) { - return { shouldRefresh: true }; - } + this.processDeletion(reviewLevels.length, itemsToDelete); } catch (error) { throw new SentryError('Failed to accept deletions in review mode', { hugoSymbol, reviewLevels, isGermline, itemsToDelete }); } @@ -416,15 +401,16 @@ export class FirebaseGeneReviewService { processDeletion = async (reviewLevelLength: number, itemsToDelete: ItemsToDeleteMap) => { // We are deleting last because the indices will change after deleting from array. + // Be VERY careful, this order is important + const orderedPathTypesToDelete = [ + FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST, + FIREBASE_LIST_PATH_TYPE.TUMOR_LIST, + FIREBASE_LIST_PATH_TYPE.MUTATION_LIST, + ]; + let hasDeletion = false; try { - // Todo: We should use multi-location updates for deletions once all our arrays use firebase auto-generated keys - // instead of using sequential number indices. - for (const pathType of [ - FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST, - FIREBASE_LIST_PATH_TYPE.TUMOR_LIST, - FIREBASE_LIST_PATH_TYPE.MUTATION_LIST, - ]) { + for (const pathType of [...orderedPathTypesToDelete, FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST]) { for (const [firebasePath, deleteIndices] of Object.entries(itemsToDelete[pathType])) { hasDeletion = true; await this.firebaseRepository.deleteFromArray(firebasePath, deleteIndices); diff --git a/src/main/webapp/app/shared/util/firebase/firebase-path-utils.ts b/src/main/webapp/app/shared/util/firebase/firebase-path-utils.ts index 7ef3efc00..de98c9436 100644 --- a/src/main/webapp/app/shared/util/firebase/firebase-path-utils.ts +++ b/src/main/webapp/app/shared/util/firebase/firebase-path-utils.ts @@ -47,6 +47,7 @@ export enum FIREBASE_LIST_PATH_TYPE { MUTATION_LIST, TUMOR_LIST, TREATMENT_LIST, + GENOMIC_INDICATOR_LIST, } export const getFirebasePathType = (path: string) => { if (/mutations\/\d+$/i.test(path)) { @@ -58,4 +59,7 @@ export const getFirebasePathType = (path: string) => { if (/TIs\/\d+\/treatments\/\d+$/i.test(path)) { return FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST; } + if (/genomic_indicators\/\d+$/i.test(path)) { + return FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST; + } };