From 64735242ba911094799934c9e22f1f9bef85bbff Mon Sep 17 00:00:00 2001 From: Boris Kovar Date: Thu, 2 Dec 2021 15:19:06 +0100 Subject: [PATCH] - fixed #694 for the case when there are no tags - bumped version to 0.10.41 --- .../preview/molecule/moleculeList.js | 14 ++++++- .../preview/molecule/redux/dispatchActions.js | 26 +++++++++--- .../preview/tags/withLoadingMolecules.js | 40 +++++++++---------- package.json | 2 +- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/js/components/preview/molecule/moleculeList.js b/js/components/preview/molecule/moleculeList.js index 76ebfed9e..243ddb134 100644 --- a/js/components/preview/molecule/moleculeList.js +++ b/js/components/preview/molecule/moleculeList.js @@ -434,6 +434,17 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei dispatch(initializeMolecules(majorViewStage)); wereMoleculesInitialized.current = true; } + if ( + majorViewStage && + all_mol_lists && + target !== undefined && + wereMoleculesInitialized.current === false && + noTagsReceived + ) { + dispatch(initializeFilter(object_selection, joinedMoleculeLists)); + dispatch(initializeMolecules(majorViewStage)); + wereMoleculesInitialized.current = true; + } } }, [ list_type, @@ -449,7 +460,8 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei stageSummaryView, object_selection, tags, - categories + categories, + noTagsReceived ]); useEffect(() => { diff --git a/js/components/preview/molecule/redux/dispatchActions.js b/js/components/preview/molecule/redux/dispatchActions.js index a60182f30..69a3e3698 100644 --- a/js/components/preview/molecule/redux/dispatchActions.js +++ b/js/components/preview/molecule/redux/dispatchActions.js @@ -577,14 +577,20 @@ export const removeInformation = data => dispatch => { */ export const initializeMolecules = majorView => (dispatch, getState) => { if (majorView) { + const state = getState(); + const noTagsReceived = state.apiReducers.noTagsReceived; + const firstTag = dispatch(getFirstTag()); + let firstMolecule = null; if (firstTag) { dispatch(addSelectedTag(firstTag)); - const firstMolecule = dispatch(getFirstMoleculeForTag(firstTag.id)); - if (firstMolecule) { - dispatch(addHitProtein(majorView, firstMolecule, colourList[firstMolecule.id % colourList.length])); - dispatch(addLigand(majorView, firstMolecule, colourList[firstMolecule.id % colourList.length], true, true)); - } + firstMolecule = dispatch(getFirstMoleculeForTag(firstTag.id)); + } else if (noTagsReceived) { + firstMolecule = dispatch(getFirstMolecule()); + } + if (firstMolecule) { + dispatch(addHitProtein(majorView, firstMolecule, colourList[firstMolecule.id % colourList.length])); + dispatch(addLigand(majorView, firstMolecule, colourList[firstMolecule.id % colourList.length], true, true)); } } }; @@ -615,6 +621,16 @@ export const getFirstMoleculeForTag = tagId => (dispatch, getState) => { return molsForTag && molsForTag.length > 0 ? molsForTag[0] : null; }; +export const getFirstMolecule = () => (dispatch, getState) => { + const state = getState(); + const molList = state.apiReducers.all_mol_lists; + if (molList && molList.length > 0) { + return molList[0]; + } else { + return null; + } +}; + export const getSiteCategoryId = () => (dispatch, getState) => { const state = getState(); const categoriesList = state.selectionReducers.categoryList; diff --git a/js/components/preview/tags/withLoadingMolecules.js b/js/components/preview/tags/withLoadingMolecules.js index 11ec575f6..e551add3c 100644 --- a/js/components/preview/tags/withLoadingMolecules.js +++ b/js/components/preview/tags/withLoadingMolecules.js @@ -14,6 +14,26 @@ export const withLoadingMolecules = WrappedComponent => { useEffect(() => { if (target_on) { getAllData(target_on).then(data => { + let tags_info = []; + // if (data.tags_info && data.tags_info.length > 0) { + // dispatch(setNoTagsReceived(false)); + // data.tags_info.forEach(tag => { + // let newObject = {}; + // Object.keys(tag.data[0]).forEach(prop => { + // newObject[`${prop}`] = tag.data[0][`${prop}`]; + // }); + // let coords = {}; + // if (tag.coords && tag.coords.length > 1) { + // Object.keys(tag.coords[0]).forEach(prop => { + // coords[`${prop}`] = tag.coords[0][`${prop}`]; + // }); + // } + // newObject['coords'] = coords; + + // tags_info.push(newObject); + // }); + // } + let allMolecules = []; data.molecules.forEach(mol => { let newObject = {}; @@ -35,26 +55,6 @@ export const withLoadingMolecules = WrappedComponent => { }); dispatch(setAllMolLists([...allMolecules])); - let tags_info = []; - if (data.tags_info && data.tags_info.length > 0) { - dispatch(setNoTagsReceived(false)); - data.tags_info.forEach(tag => { - let newObject = {}; - Object.keys(tag.data[0]).forEach(prop => { - newObject[`${prop}`] = tag.data[0][`${prop}`]; - }); - let coords = {}; - if (tag.coords && tag.coords.length > 1) { - Object.keys(tag.coords[0]).forEach(prop => { - coords[`${prop}`] = tag.coords[0][`${prop}`]; - }); - } - newObject['coords'] = coords; - - tags_info.push(newObject); - }); - } - // const categories = data.tag_categories; //need to do this this way because only categories which have at least one tag assigned are sent from backend const categories = getCategoryIds(); diff --git a/package.json b/package.json index 2ecfe9034..6b02440ab 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fragalysis-frontend", - "version": "0.10.40", + "version": "0.10.41", "description": "Frontend for fragalysis", "main": "webpack.config.js", "scripts": {