Skip to content

Commit cb691e7

Browse files
committed
automatically end review mode if no active reviewer for 5 minutes
1 parent aec2479 commit cb691e7

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

src/main/webapp/app/pages/curation/CurationPage.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const CurationPage = (props: ICurationPageProps) => {
4949
const genomicIndicatorsPath = `${firebaseGenePath}/genomic_indicators`;
5050
const firebaseMetaGeneReviewPath = `${getFirebaseMetaGenePath(isGermline, hugoSymbol)}/review`;
5151
const firebaseMetaCurrentReviewerPath = `${firebaseMetaGeneReviewPath}/currentReviewer`;
52+
const firebaseMetaLastActiveReviewPath = `${firebaseMetaGeneReviewPath}/lastActiveReview`;
5253

5354
useEffect(() => {
5455
async function checkIfGeneExists() {
@@ -119,6 +120,39 @@ export const CurationPage = (props: ICurationPageProps) => {
119120
return getTooltipHistoryList(tabHistoryList);
120121
}, [tabHistoryList]);
121122

123+
/* eslint-disable no-console */
124+
useEffect(() => {
125+
async function checkLastActiveReview() {
126+
if (
127+
props.firebaseDb === undefined ||
128+
props.clearCurrentReviwer === undefined ||
129+
hugoSymbol === undefined ||
130+
isGermline === undefined
131+
) {
132+
return;
133+
}
134+
135+
const lastActiveReviewSnapshot = await get(ref(props.firebaseDb, firebaseMetaLastActiveReviewPath));
136+
const lastActiveReview: number | undefined = lastActiveReviewSnapshot.val();
137+
138+
if (lastActiveReview !== undefined && Date.now() - lastActiveReview > 5 * 60 * 1000) {
139+
props.clearCurrentReviwer(hugoSymbol, isGermline);
140+
}
141+
}
142+
143+
checkLastActiveReview();
144+
const interval = setInterval(
145+
() => {
146+
checkLastActiveReview();
147+
},
148+
5 * 60 * 1000,
149+
);
150+
151+
return () => {
152+
clearTimeout(interval);
153+
};
154+
}, [props.firebaseDb, firebaseMetaLastActiveReviewPath, hugoSymbol, isGermline, props.clearCurrentReviwer]);
155+
122156
if (!geneIsFound) {
123157
return <div>the gene &quot;{hugoSymbolParam}&quot; was not found</div>;
124158
}
@@ -330,6 +364,7 @@ const mapStoreToProps = ({
330364
layoutStore,
331365
routerStore,
332366
curationPageStore,
367+
firebaseMetaService,
333368
}: IRootStore) => ({
334369
firebaseDb: firebaseAppStore.firebaseDb,
335370
firebaseInitSuccess: firebaseAppStore.firebaseInitSuccess,
@@ -353,6 +388,7 @@ const mapStoreToProps = ({
353388
setReadOnly: curationPageStore.setReadOnly,
354389
isMutationListRendered: curationPageStore.isMutationListRendered,
355390
setIsMutationListRendered: curationPageStore.setIsMutationListRendered,
391+
clearCurrentReviwer: firebaseMetaService.clearCurrentReviewer,
356392
});
357393

358394
type StoreProps = ReturnType<typeof mapStoreToProps>;

src/main/webapp/app/pages/curation/review/ReviewPage.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ const ReviewPage: React.FunctionComponent<IReviewPageProps> = (props: IReviewPag
122122
};
123123
}, [hugoSymbol, isGermline, props.firebaseDb]);
124124

125+
useEffect(() => {
126+
if (hugoSymbol === undefined || isGermline === undefined || props.updateGeneLastActiveReview === undefined) {
127+
return;
128+
}
129+
130+
props.updateGeneLastActiveReview?.(hugoSymbol, isGermline);
131+
const interval = setInterval(() => {
132+
props.updateGeneLastActiveReview?.(hugoSymbol, isGermline);
133+
}, 60 * 1000);
134+
135+
return () => {
136+
clearInterval(interval);
137+
};
138+
}, [hugoSymbol, isGermline]);
139+
125140
const acceptAllChangesFromEditors = async (editors: string[]) => {
126141
if (hugoSymbol === undefined) {
127142
notifyError(new SentryError('Cannot accept all changes because hugo symbol is unknown.', { hugoSymbol, geneData }));
@@ -299,7 +314,7 @@ const mapStoreToProps = ({
299314
loadingGenes: geneStore.loading,
300315
firebaseInitSuccess: firebaseAppStore.firebaseInitSuccess,
301316
isGermline: routerStore.isGermline,
302-
updateCurrentReviewer: firebaseMetaService.updateGeneCurrentReviewer,
317+
updateGeneLastActiveReview: firebaseMetaService.updateGeneLastActiveReview,
303318
});
304319

305320
type StoreProps = Partial<ReturnType<typeof mapStoreToProps>>;

src/main/webapp/app/service/firebase/firebase-meta-service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ export class FirebaseMetaService {
8787
});
8888
};
8989

90+
updateGeneLastActiveReview = async (hugoSymbol: string, isGermline: boolean) => {
91+
await this.firebaseRepository.update(`${getFirebaseMetaGenePath(isGermline, hugoSymbol)}/review`, {
92+
lastActiveReview: Date.now(),
93+
});
94+
};
95+
96+
clearCurrentReviewer = async (hugoSymbol: string, isGermline: boolean) => {
97+
await this.firebaseRepository.update(`${getFirebaseMetaGenePath(isGermline, hugoSymbol)}/review`, {
98+
currentReviewer: '',
99+
lastActiveReview: null,
100+
});
101+
};
102+
90103
createMetaGene = async (hugoSymbol: string, isGermline: boolean) => {
91104
await this.firebaseRepository.create(getFirebaseMetaGenePath(isGermline, hugoSymbol), new Meta());
92105
};

src/main/webapp/app/shared/model/firebase/firebase.model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ export class Meta {
419419

420420
export class MetaReview {
421421
currentReviewer = '';
422-
[key: string]: string | boolean;
422+
lastActiveReview?: number;
423+
[key: string]: string | boolean | number | undefined;
423424
}
424425

425426
export type CommentList = Record<string, Comment>;

0 commit comments

Comments
 (0)