Skip to content

Commit

Permalink
Merge pull request #4762 from alisman/summaryFull
Browse files Browse the repository at this point in the history
Refactor to allow pie and table charts to download both full and summ…
  • Loading branch information
alisman authored Oct 30, 2023
2 parents 104869a + 674c888 commit da668f6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -162,15 +172,7 @@ export default class DownloadControls extends React.Component<
if (isPromiseLike<string | null>(result)) {
result.then(data => {
if (data) {
fileDownload(
data,
`${this.props.filename}.` +
`${
this.props.dataExtension
? this.props.dataExtension
: 'txt'
}`
);
fileDownload(data, this.buildFileName(dataType));
}
});
} else {
Expand Down
74 changes: 43 additions & 31 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8562,41 +8562,34 @@ export class StudyViewPageStore
default: [],
});

public async getPieChartDataDownload(
public async getChartSummaryDataDownload(
chartMeta: ChartMeta,
dataType?: DownloadDataType
): Promise<string> {
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!
);
}
}

Expand All @@ -8623,9 +8616,15 @@ export class StudyViewPageStore
return data.join('\n');
}

public async getChartDownloadableData(
chartMeta: ChartMeta
): Promise<string> {
// 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(
Expand Down Expand Up @@ -8696,6 +8695,19 @@ export class StudyViewPageStore
return data.join('\n');
}

public async getChartDownloadableData(
chartMeta: ChartMeta,
dataType?: DownloadDataType
): Promise<string> {
switch (dataType) {
case 'summary':
return this.getChartSummaryDataDownload(chartMeta, dataType);
break;
default:
return this.getChartAllDataDownload(chartMeta);
}
}

@computed get molecularProfileMapByType(): _.Dictionary<
MolecularProfile[]
> {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/studyView/tabs/SummaryTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit da668f6

Please sign in to comment.