Skip to content

Commit

Permalink
Merge pull request #780 from uc-cdis/feat/explorer-download-formats
Browse files Browse the repository at this point in the history
(PXP-6540): Feat/explorer download formats
  • Loading branch information
cterrazas2 authored Jan 19, 2021
2 parents 29b9f29 + 46b9813 commit ce7bcae
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
31 changes: 29 additions & 2 deletions docs/portal_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,38 @@ Below is an example, with inline comments describing what each JSON block config
"buttons": [ // required; buttons for Data Explorer
{
"enabled": true, // required; if the button is enabled or disabled
"type": "data", // required; button type - what should it do? Data = downloading clinical data
"type": "data", // required; button data type sub-options (case insensitive): ["data" (default), "data-tsv", "data-csv", "data-json"] - what should it do? Data = downloading default clinical JSON data
"title": "Download All Clinical", // required; title of button
"leftIcon": "user", // optional; icon on left from /img/icons
"rightIcon": "download", // optional; icon on right from /img/icons
"fileName": "clinical.json", // required; file name when it is downloaded
"fileName": "clinical.json", // required; file name when it is downloaded (set file ext. to default json)
"dropdownId": "download" // optional; if putting into a dropdown, the dropdown id
},
{
"enabled": true, // required; if the button is enabled or disabled
"type": "data-tsv", // required; button data type - what should it do? Data = downloading clinical TSV data
"title": "TSV", // required; title of button
"leftIcon": "datafile", // optional; icon on left from /img/icons
"rightIcon": "download", // optional; icon on right from /img/icons
"fileName": "clinical.tsv", // required; file name when it is downloaded (file ext. should match data type)
"dropdownId": "download" // optional; if putting into a dropdown, the dropdown id
},
{
"enabled": true, // required; if the button is enabled or disabled
"type": "data-csv", // required; button data type - what should it do? Data = downloading clinical CSV data
"title": "CSV", // required; title of button
"leftIcon": "datafile", // optional; icon on left from /img/icons
"rightIcon": "download", // optional; icon on right from /img/icons
"fileName": "clinical.csv", // required; file name when it is downloaded (file ext. should match data type)
"dropdownId": "download" // optional; if putting into a dropdown, the dropdown id
},
{
"enabled": true, // required; if the button is enabled or disabled
"type": "data-json", // required; (equivalent to just "data" but we add it for consistency) button data type - what should it do? Data = downloading clinical JSON data
"title": "JSON", // required; title of button
"leftIcon": "datafile", // optional; icon on left from /img/icons
"rightIcon": "download", // optional; icon on right from /img/icons
"fileName": "clinical.json", // required; file name when it is downloaded (file ext. should match data type)
"dropdownId": "download" // optional; if putting into a dropdown, the dropdown id
},
{
Expand Down
33 changes: 17 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@fortawesome/free-brands-svg-icons": "^5.14.0",
"@fortawesome/free-solid-svg-icons": "^5.2.0",
"@fortawesome/react-fontawesome": "^0.1.0",
"@gen3/guppy": "^0.9.2",
"@gen3/guppy": "^0.10.0",
"@gen3/ui-component": "^0.6.4",
"@storybook/addon-actions": "^5.0.0",
"@storybook/react": "^5.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

.explorer-button-group__dropdown {
width: 200px;
margin-right: 10px;
}

.explorer-button-group__toaster-div {
Expand Down
12 changes: 7 additions & 5 deletions src/GuppyDataExplorer/ExplorerButtonGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class ExplorerButtonGroup extends React.Component {

getOnClickFunction = (buttonConfig) => {
let clickFunc = () => {};
if (buttonConfig.type === 'data') {
clickFunc = this.downloadData(buttonConfig.fileName);
if (buttonConfig.type.startsWith('data')) {
clickFunc = this.downloadData(buttonConfig.fileName, buttonConfig.type.split('-').pop());
}
if (buttonConfig.type === 'manifest') {
clickFunc = this.downloadManifest(buttonConfig.fileName, null);
Expand Down Expand Up @@ -343,10 +343,12 @@ class ExplorerButtonGroup extends React.Component {
});
};

downloadData = filename => () => {
this.props.downloadRawData().then((res) => {
downloadData = (filename, fileFormat) => () => {
const fileTypeKey = fileFormat.toUpperCase();
const isJsonFormat = fileTypeKey === 'JSON' || fileTypeKey === 'DATA';
this.props.downloadRawData({ format: fileTypeKey }).then((res) => {
if (res) {
const blob = new Blob([JSON.stringify(res, null, 2)], { type: 'text/json' });
const blob = new Blob([isJsonFormat ? JSON.stringify(res, null, 2) : res], { type: `text/${isJsonFormat ? 'json' : fileFormat.toLowerCase()}` });
FileSaver.saveAs(blob, filename);
} else {
throw Error('Error when downloading data');
Expand Down

0 comments on commit ce7bcae

Please sign in to comment.