From 895d50fe7c6af7690c63eeaed0956e0f10d2afff Mon Sep 17 00:00:00 2001 From: Tetiana <98550542+Nelliney@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:44:21 -0700 Subject: [PATCH] Show summary stats on homepage (#4952) --- src/shared/components/query/QueryStore.ts | 8 ++++ .../components/query/StudySelectorStats.tsx | 43 ++++++++++++++++--- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/shared/components/query/QueryStore.ts b/src/shared/components/query/QueryStore.ts index 13e878d188b..0ffabd04c6e 100644 --- a/src/shared/components/query/QueryStore.ts +++ b/src/shared/components/query/QueryStore.ts @@ -1170,6 +1170,10 @@ export class QueryStore { return _.sumBy(this.selectableSelectedStudies, s => s.allSampleCount); } + @computed get sampleCountForAllStudies() { + return _.sumBy(this.selectableStudies, s => s.allSampleCount); + } + readonly sampleLists = remoteData({ invoke: async () => { if (!this.isSingleNonVirtualStudySelected) { @@ -1578,6 +1582,10 @@ export class QueryStore { .filter(_.identity); } + @computed get selectableStudies() { + return Array.from(this.treeData.map_studyId_cancerStudy.values()); + } + public isVirtualStudy(studyId: string): boolean { // if the study id doesn't correspond to one in this.cancerStudies, then its a virtual Study return !this.cancerStudyIdsSet.result[studyId]; diff --git a/src/shared/components/query/StudySelectorStats.tsx b/src/shared/components/query/StudySelectorStats.tsx index 732c6454e26..cedbddc6000 100644 --- a/src/shared/components/query/StudySelectorStats.tsx +++ b/src/shared/components/query/StudySelectorStats.tsx @@ -18,6 +18,10 @@ export const StudySelectorStats: React.FunctionComponent<{ let numSelectedStudies = expr( () => props.store.selectableSelectedStudyIds.length ); + let numAllStudies = expr( + () => props.store.selectableStudies.length + ); + return ( <> - {numSelectedStudies}{' '} - {numSelectedStudies === 1 ? 'study' : 'studies'}{' '} - selected ( - - {props.store.sampleCountForSelectedStudies} - {' '} - samples) + {props.store.selectableSelectedStudies.length == + 0 && ( +
+ {numAllStudies} studies available + ( + + { + props.store + .sampleCountForAllStudies + } + {' '} + samples) +
+ )} + + {props.store.selectableSelectedStudies.length > + 0 && ( +
+ {numSelectedStudies}{' '} + {numSelectedStudies === 1 + ? 'study' + : 'studies'}{' '} + selected ( + + { + props.store + .sampleCountForSelectedStudies + } + {' '} + samples) +
+ )}
{props.store.selectableSelectedStudies.length > 0 && (