From 674c88853b2da19a181df16aa37a0556247bc7da Mon Sep 17 00:00:00 2001 From: lismana Date: Wed, 25 Oct 2023 17:29:21 -0400 Subject: [PATCH] Refactor to allow pie and table charts to download both full and summary data --- .../downloadControls/DownloadControls.tsx | 20 ++--- src/pages/studyView/StudyViewPageStore.ts | 74 +++++++++++-------- src/pages/studyView/tabs/SummaryTab.tsx | 8 +- 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/packages/cbioportal-frontend-commons/src/components/downloadControls/DownloadControls.tsx b/packages/cbioportal-frontend-commons/src/components/downloadControls/DownloadControls.tsx index 6a9b85f18a1..b049cc71d78 100644 --- a/packages/cbioportal-frontend-commons/src/components/downloadControls/DownloadControls.tsx +++ b/packages/cbioportal-frontend-commons/src/components/downloadControls/DownloadControls.tsx @@ -154,6 +154,16 @@ export default class DownloadControls extends React.Component< ); } + private buildFileName(dataType?: string) { + return ( + `${this.props.filename}${ + typeof dataType === 'string' ? `.${dataType}` : '' + }` + + `.` + + `${this.props.dataExtension ? this.props.dataExtension : 'txt'}` + ); + } + @autobind private downloadData(dataType?: DataType) { if (this.props.getData) { @@ -162,15 +172,7 @@ export default class DownloadControls extends React.Component< if (isPromiseLike(result)) { result.then(data => { if (data) { - fileDownload( - data, - `${this.props.filename}.` + - `${ - this.props.dataExtension - ? this.props.dataExtension - : 'txt' - }` - ); + fileDownload(data, this.buildFileName(dataType)); } }); } else { diff --git a/src/pages/studyView/StudyViewPageStore.ts b/src/pages/studyView/StudyViewPageStore.ts index 415251a0c70..52e65aac115 100644 --- a/src/pages/studyView/StudyViewPageStore.ts +++ b/src/pages/studyView/StudyViewPageStore.ts @@ -8562,41 +8562,34 @@ export class StudyViewPageStore default: [], }); - public async getPieChartDataDownload( + public async getChartSummaryDataDownload( chartMeta: ChartMeta, dataType?: DownloadDataType ): Promise { const isCustomChart = this.isUserDefinedCustomDataChart( chartMeta.uniqueKey ); - if (dataType && dataType === 'summary') { - if (isCustomChart) { - return this.getClinicalDataCountSummary( - chartMeta, - this.getCustomDataCount(chartMeta).result! - ); - } else if (this.isGenericAssayChart(chartMeta.uniqueKey)) { - return this.getClinicalDataCountSummary( - chartMeta, - this.getGenericAssayChartDataCount(chartMeta).result! - ); - } else if (this.isGeneSpecificChart(chartMeta.uniqueKey)) { - return this.getClinicalDataCountSummary( - chartMeta, - this.getGenomicChartDataCount(chartMeta).result! - ); - } else { - return this.getClinicalDataCountSummary( - chartMeta, - this.getClinicalDataCount(chartMeta).result! - ); - } + + if (isCustomChart) { + return this.getClinicalDataCountSummary( + chartMeta, + this.getCustomDataCount(chartMeta).result! + ); + } else if (this.isGenericAssayChart(chartMeta.uniqueKey)) { + return this.getClinicalDataCountSummary( + chartMeta, + this.getGenericAssayChartDataCount(chartMeta).result! + ); + } else if (this.isGeneSpecificChart(chartMeta.uniqueKey)) { + return this.getClinicalDataCountSummary( + chartMeta, + this.getGenomicChartDataCount(chartMeta).result! + ); } else { - if (isCustomChart) { - return this.getCustomChartDownloadData(chartMeta); - } else { - return this.getChartDownloadableData(chartMeta); - } + return this.getClinicalDataCountSummary( + chartMeta, + this.getClinicalDataCount(chartMeta).result! + ); } } @@ -8623,9 +8616,15 @@ export class StudyViewPageStore return data.join('\n'); } - public async getChartDownloadableData( - chartMeta: ChartMeta - ): Promise { + // this returns all/full data as opposed to summary + // "summary" means the frequency of various values + // "full" means the underlying data rows which are then aggregated into summary + public async getChartAllDataDownload(chartMeta: ChartMeta) { + // handle custom chart + if (this.isUserDefinedCustomDataChart(chartMeta.uniqueKey)) { + return this.getCustomChartDownloadData(chartMeta); + } + let clinicalDataList: ClinicalData[] = []; if (this.isGeneSpecificChart(chartMeta.uniqueKey)) { clinicalDataList = await getGenomicDataAsClinicalData( @@ -8696,6 +8695,19 @@ export class StudyViewPageStore return data.join('\n'); } + public async getChartDownloadableData( + chartMeta: ChartMeta, + dataType?: DownloadDataType + ): Promise { + switch (dataType) { + case 'summary': + return this.getChartSummaryDataDownload(chartMeta, dataType); + break; + default: + return this.getChartAllDataDownload(chartMeta); + } + } + @computed get molecularProfileMapByType(): _.Dictionary< MolecularProfile[] > { diff --git a/src/pages/studyView/tabs/SummaryTab.tsx b/src/pages/studyView/tabs/SummaryTab.tsx index e69eaf66dd2..db6b8d2d2ce 100644 --- a/src/pages/studyView/tabs/SummaryTab.tsx +++ b/src/pages/studyView/tabs/SummaryTab.tsx @@ -240,7 +240,7 @@ export class StudySummaryTab extends React.Component< } props.onChangeChartType = this.handlers.onChangeChartType; props.getData = (dataType?: DataType) => - this.store.getPieChartDataDownload(chartMeta, dataType); + this.store.getChartDownloadableData(chartMeta, dataType); props.downloadTypes = [ 'Summary Data', 'Full Data', @@ -374,9 +374,9 @@ export class StudySummaryTab extends React.Component< props.onResetSelection = this.handlers.onValueSelection; } props.onChangeChartType = this.handlers.onChangeChartType; - props.getData = () => - this.store.getChartDownloadableData(chartMeta); - props.downloadTypes = ['Data']; + props.getData = dataType => + this.store.getChartDownloadableData(chartMeta, dataType); + props.downloadTypes = ['Summary Data', 'Full Data']; break; } case ChartTypeEnum.MUTATED_GENES_TABLE: {