Skip to content

Commit

Permalink
MIDRC-921: disable "download manifest" for more terms than the ES lim…
Browse files Browse the repository at this point in the history
…it (#1670)
  • Loading branch information
paulineribeyre authored Feb 11, 2025
1 parent 68dc9f5 commit e841054
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/GuppyDataExplorer/ExplorerButtonGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { manifestServiceApiPath, guppyGraphQLUrl, terraExportWarning } from '../
import './ExplorerButtonGroup.css';
import Popup from '../../components/Popup';

const ES_MAX_QUERY_TERMS = 65536; // max number of terms supported in ES queries

// template variable for export-pfb-to-url/export-file-pfb-to-url button config.
// see docs/export_pfb_to_url.md
const PRESIGNED_URL_TEMPLATE_VARIABLE = '{{PRESIGNED_URL}}';
Expand Down Expand Up @@ -709,11 +711,17 @@ Currently, in order to export a File PFB, \`enableLimitedFilePFBExport\` must be
} else {
let caseIDList = caseIDResult.map((i) => i[caseField]);
caseIDList = _.uniq(caseIDList);
const countResult = await this.props.getTotalCountsByTypeAndFilter(fileType, {
[caseFieldInFileIndex]: {
selectedValues: caseIDList,
},
});
let countResult;
if (caseIDList.length <= ES_MAX_QUERY_TERMS) {
countResult = await this.props.getTotalCountsByTypeAndFilter(fileType, {
[caseFieldInFileIndex]: {
selectedValues: caseIDList,
},
});
} else {
// this will disable the button, preventing download attemps that would fail
countResult = 'too-many-terms';
}
this.setState({
manifestEntryCount: countResult, downloadingInProgress: { manifest: false },
});
Expand Down Expand Up @@ -779,7 +787,7 @@ Currently, in order to export a File PFB, \`enableLimitedFilePFBExport\` must be
if (buttonConfig.type.startsWith('data') || buttonConfig.type === 'manifest' || buttonConfig.type === 'file-manifest') {
let isEnabled = Object.values(this.state.downloadingInProgress).every((x) => x === false);
if (buttonConfig.type === 'manifest') {
isEnabled = isEnabled && this.state.manifestEntryCount > 0;
isEnabled = isEnabled && this.state.manifestEntryCount != 0 && this.state.manifestEntryCount != 'too-many-terms';
}
return isEnabled;
}
Expand Down Expand Up @@ -862,7 +870,7 @@ Currently, in order to export a File PFB, \`enableLimitedFilePFBExport\` must be
}
}
if (buttonConfig.type === 'export-to-workspace') {
return this.state.manifestEntryCount > 0;
return this.state.manifestEntryCount != 0 && this.state.manifestEntryCount != 'too-many-terms';
}

return this.props.totalCount > 0;
Expand Down Expand Up @@ -922,8 +930,12 @@ Currently, in order to export a File PFB, \`enableLimitedFilePFBExport\` must be
if (buttonConfig.type === 'data') {
const buttonCount = (this.props.totalCount >= 0) ? this.props.totalCount : 0;
buttonTitle = `${buttonConfig.title} (${buttonCount})`;
} else if (buttonConfig.type === 'manifest' && this.state.manifestEntryCount > 0) {
buttonTitle = `${buttonConfig.title} (${humanizeNumber(this.state.manifestEntryCount)})`;
} else if (buttonConfig.type === 'manifest' && this.state.manifestEntryCount != 0) {
if (this.state.manifestEntryCount != 'too-many-terms') {
buttonTitle = `${buttonConfig.title} (${humanizeNumber(this.state.manifestEntryCount)})`;
} else {
buttonTitle = `${buttonConfig.title} (cohort too large; make a smaller selection)`;
}
}

let tooltipEnabled = buttonConfig.tooltipText ? !this.isButtonEnabled(buttonConfig) : false;
Expand Down

0 comments on commit e841054

Please sign in to comment.