From 3117c221f74d9c97051e1c641b9b8f2c869c5898 Mon Sep 17 00:00:00 2001 From: Boris Kovar Date: Tue, 28 May 2024 16:29:07 +0200 Subject: [PATCH] #1393 - file name part implemented --- js/components/datasets/compoundSetList.js | 8 +++++--- js/components/datasets/selectedCompoundsList.js | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/js/components/datasets/compoundSetList.js b/js/components/datasets/compoundSetList.js index c519a83d8..54301293a 100644 --- a/js/components/datasets/compoundSetList.js +++ b/js/components/datasets/compoundSetList.js @@ -72,6 +72,7 @@ export const CompoundSetList = () => { const greenInput = useSelector(state => state.previewReducers.compounds[compoundsColors.green.key]); const purpleInput = useSelector(state => state.previewReducers.compounds[compoundsColors.purple.key]); const apricotInput = useSelector(state => state.previewReducers.compounds[compoundsColors.apricot.key]); + const targetName = useSelector(state => state.apiReducers.target_on_name); const inputs = { [compoundsColors.blue.key]: blueInput, @@ -130,7 +131,7 @@ export const CompoundSetList = () => { const cmpColorsForDataset = compoundColors[datasetID]; if (cmpColorsForDataset) { shoppingCartColors = cmpColorsForDataset[compound.id]; - shoppingCartColors.forEach(color => { + shoppingCartColors?.forEach(color => { if (!colorsTemplate.hasOwnProperty(color)) { colorsTemplate[color] = ''; if (inputs.hasOwnProperty(color) && inputs[color]) { @@ -194,7 +195,8 @@ export const CompoundSetList = () => { listOfMols.push(molObj); }); - const reqObj = { title: datasetID, dict: listOfMols }; + const fileName = `${targetName}-RHS-selection.csv`; + const reqObj = { title: datasetID, filename: fileName, dict: listOfMols }; const jsonString = JSON.stringify(reqObj); api({ @@ -205,7 +207,7 @@ export const CompoundSetList = () => { var anchor = document.createElement('a'); anchor.href = `${base_url}/api/dicttocsv/?file_url=${resp.data['file_url']}`; anchor.target = '_blank'; - anchor.download = 'download'; + anchor.download = `${fileName}`; //'download'; anchor.click(); }); }; diff --git a/js/components/datasets/selectedCompoundsList.js b/js/components/datasets/selectedCompoundsList.js index 77cacdfdd..7cc277d8e 100644 --- a/js/components/datasets/selectedCompoundsList.js +++ b/js/components/datasets/selectedCompoundsList.js @@ -208,6 +208,8 @@ export const SelectedCompoundList = memo(() => { const moleculeLists = useSelector(state => state.datasetsReducers.moleculeLists); const allMoleculesList = useSelector(state => state.apiReducers.all_mol_lists); + const targetName = useSelector(state => state.apiReducers.target_on_name); + const compoundsToBuyList = useSelector(state => state.datasetsReducers.compoundsToBuyDatasetMap); let selectedMolecules = []; @@ -567,7 +569,9 @@ export const SelectedCompoundList = memo(() => { listOfMols.push(molObj); }); - const reqObj = { title: sharedSnapshot.url, dict: listOfMols }; + const fileName = `${targetName}-RHS-selection.csv`; + // console.log(`href - ${fileName}`); + const reqObj = { title: sharedSnapshot.url, filename: fileName, dict: listOfMols }; const jsonString = JSON.stringify(reqObj); api({ @@ -577,8 +581,9 @@ export const SelectedCompoundList = memo(() => { }).then(resp => { var anchor = document.createElement('a'); anchor.href = `${base_url}/api/dicttocsv/?file_url=${resp.data['file_url']}`; + // console.log(`href - ${base_url}/api/dicttocsv/?file_url=${resp.data['file_url']}`); anchor.target = '_blank'; - anchor.download = 'download'; + anchor.download = `${fileName}`; //'download'; anchor.click(); }); });