Skip to content

Commit

Permalink
- fixed #694 for the case when there are no tags
Browse files Browse the repository at this point in the history
- bumped version to 0.10.41
  • Loading branch information
boriskovar-m2ms committed Dec 2, 2021
1 parent aec57e1 commit 6473524
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
14 changes: 13 additions & 1 deletion js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -449,7 +460,8 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
stageSummaryView,
object_selection,
tags,
categories
categories,
noTagsReceived
]);

useEffect(() => {
Expand Down
26 changes: 21 additions & 5 deletions js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
};
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 20 additions & 20 deletions js/components/preview/tags/withLoadingMolecules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fragalysis-frontend",
"version": "0.10.40",
"version": "0.10.41",
"description": "Frontend for fragalysis",
"main": "webpack.config.js",
"scripts": {
Expand Down

0 comments on commit 6473524

Please sign in to comment.