Skip to content

Commit

Permalink
- checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed May 14, 2021
1 parent 8b0d54d commit ca1117e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 63 deletions.
11 changes: 3 additions & 8 deletions js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
}, [customDatasets.length, dispatch, target_on, isTrackingRestoring]);

useEffect(() => {
const allMolsGroupsCount = Object.keys(all_mol_lists || {}).length;
const moleculeListsCount = Object.keys(moleculeLists || {}).length;
if (allMolsGroupsCount > 0 && moleculeListsCount > 0 && !isLoadingMoleculeList) {
if (moleculeListsCount > 0 && !isLoadingMoleculeList) {
const allDatasets = {};
const allMolsMap = linearizeMoleculesLists();
const keys = Object.keys(moleculeLists);
Expand All @@ -163,14 +162,10 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
}, [all_mol_lists, moleculeLists, isLoadingMoleculeList, linearizeMoleculesLists, dispatch]);

const linearizeMoleculesLists = useCallback(() => {
const keys = Object.keys(all_mol_lists);
const allMolsMap = {};

keys.forEach(key => {
let molList = all_mol_lists[key];
molList.forEach(mol => {
allMolsMap[mol.id] = mol;
});
all_mol_lists.forEach(mol => {
allMolsMap[mol.id] = mol;
});

return allMolsMap;
Expand Down
76 changes: 38 additions & 38 deletions js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,44 +370,44 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
firstInitializationMolecule.current = first;
}

const loadAllMolecules = useCallback(() => {
if (
(proteinsHasLoaded === true || proteinsHasLoaded === null) &&
target_on &&
mol_group_list &&
mol_group_list.length > 0 &&
Object.keys(all_mol_lists).length <= 0 &&
isTrackingRestoring === false
) {
let promises = [];
mol_group_list.forEach(molGroup => {
let id = molGroup.id;
let url = getUrl({ list_type, target_on, mol_group_on: id });
promises.push(
loadAllMolsFromMolGroup({
url,
mol_group: id
})
);
});
Promise.all(promises)
.then(results => {
let listToSet = {};
let allMolecules = [];
results.forEach(molResult => {
listToSet[molResult.mol_group] = molResult.molecules;
allMolecules.push(...molResult.molecules);
});
dispatch(setAllMolLists(listToSet));
dispatch(setAllMolecules(allMolecules));
})
.catch(err => console.log(err));
}
}, [proteinsHasLoaded, mol_group_list, list_type, target_on, dispatch, all_mol_lists, isTrackingRestoring]);

useEffect(() => {
loadAllMolecules();
}, [proteinsHasLoaded, target_on, mol_group_list, loadAllMolecules]);
// const loadAllMolecules = useCallback(() => {
// if (
// (proteinsHasLoaded === true || proteinsHasLoaded === null) &&
// target_on &&
// mol_group_list &&
// mol_group_list.length > 0 &&
// Object.keys(all_mol_lists).length <= 0 &&
// isTrackingRestoring === false
// ) {
// let promises = [];
// mol_group_list.forEach(molGroup => {
// let id = molGroup.id;
// let url = getUrl({ list_type, target_on, mol_group_on: id });
// promises.push(
// loadAllMolsFromMolGroup({
// url,
// mol_group: id
// })
// );
// });
// Promise.all(promises)
// .then(results => {
// let listToSet = {};
// let allMolecules = [];
// results.forEach(molResult => {
// listToSet[molResult.mol_group] = molResult.molecules;
// allMolecules.push(...molResult.molecules);
// });
// dispatch(setAllMolLists(listToSet));
// dispatch(setAllMolecules(allMolecules));
// })
// .catch(err => console.log(err));
// }
// }, [proteinsHasLoaded, mol_group_list, list_type, target_on, dispatch, all_mol_lists, isTrackingRestoring]);

// useEffect(() => {
// loadAllMolecules();
// }, [proteinsHasLoaded, target_on, mol_group_list, loadAllMolecules]);

useEffect(() => {
const allMolsGroupsCount = Object.keys(all_mol_lists || {}).length;
Expand Down
32 changes: 17 additions & 15 deletions js/components/preview/molecule/redux/selectors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { createSelector } from 'reselect';

const getMoleculeGroupLists = state => state.apiReducers.mol_group_list;
const getMoleculeGroupSelection = state => state.selectionReducers.mol_group_selection;
//const getMoleculeGroupSelection = state => state.selectionReducers.mol_group_selection;
const getObjectSelection = state => state.selectionReducers.object_selection;
const getAllMolecules = state => state.apiReducers.all_mol_lists;
const getAllSelectedTags = state => state.selectionReducers.selectedTagList;

export const selectJoinedMoleculeList = createSelector(
getAllMolecules,
getMoleculeGroupLists,
getMoleculeGroupSelection,
getAllSelectedTags,
getObjectSelection,
(all_mol_lists, mol_group_list, mol_group_selection, obj_selection) => {
const object_selection = obj_selection || mol_group_selection;
(all_mol_lists, mol_group_list, selectedTagList, obj_selection) => {
const object_selection = obj_selection;
let joinedMoleculeLists = [];
if (object_selection) {
object_selection.forEach(obj => {
Expand Down Expand Up @@ -56,18 +57,19 @@ export const getMoleculeList = createSelector(
);
export const selectAllMoleculeList = createSelector(
getAllMolecules,
getMoleculeGroupLists,
(all_mol_lists, mol_group_list) => {
const groupList = mol_group_list || [];
getAllSelectedTags,
(all_mol_lists, selectedTagList) => {
const allMoleculesList = [];
groupList.forEach((site, index) => {
const siteMolecules = (all_mol_lists || {})[site.id];

if (siteMolecules) {
siteMolecules.forEach(r => {
allMoleculesList.push({ site: index + 1, ...r })
});
}
selectedTagList.forEach(tag => {
let filteredMols = all_mol_lists.filter(mol => mol?.tags_set.filter(t => t === tag.data[0].id));
filteredMols.forEach(mol => {
let found = allMoleculesList.filter(addedMol => addedMol.id === mol.id);
if (allMoleculesList.length === 0) {
allMoleculesList.push(mol);
} else if (!found || found.length === 0) {
allMoleculesList.push(mol);
}
});
});

return allMoleculesList;
Expand Down
5 changes: 3 additions & 2 deletions js/components/preview/tags/withLoadingMolecules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { getAllData } from './api/tagsApi';
import { setAllMolecules } from '../../../reducers/api/actions';
import { setAllMolecules, setAllMolLists } from '../../../reducers/api/actions';
import { setTagSelectorData } from '../tags/redux/dispatchActions';

export const withLoadingMolecules = WrappedComponent => {
Expand All @@ -20,7 +20,8 @@ export const withLoadingMolecules = WrappedComponent => {

allMolecules.push(molData);
});
dispatch(setAllMolecules(allMolecules));
dispatch(setAllMolecules([...allMolecules]));
dispatch(setAllMolLists([...allMolecules]));

const tags = data.tags_info;
const categories = data.tag_categories;
Expand Down

0 comments on commit ca1117e

Please sign in to comment.