Skip to content

Commit

Permalink
- additional fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Dec 1, 2020
1 parent b406141 commit 021aaa9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions js/components/datasets/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const setMoleculeListIsLoading = isLoading => ({
payload: isLoading
});

export const replaceAllMoleculeLists = allMoleculeLists => ({
type: constants.REPLACE_ALL_MOLECULELISTS,
payload: allMoleculeLists
});

export const setFilterSettings = (datasetID, filter) => ({
type: constants.SET_FILTER_SETTINGS,
payload: { datasetID, filter }
Expand Down
1 change: 1 addition & 0 deletions js/components/datasets/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const prefix = 'CUSTOM_DATASETS_';
export const constants = {
ADD_DATASET: prefix + 'ADD_DATASET',
SET_DATASET: prefix + 'SET_DATASET',
REPLACE_ALL_MOLECULELISTS: prefix + 'REPLACE_ALL_MOLECULELISTS',
ADD_MOLECULELIST: prefix + 'ADD_MOLECULELIST',
REMOVE_MOLECULELIST: prefix + 'REMOVE_MOLECULELIST',
SET_IS_LOADING_MOLECULE_LIST: prefix + 'SET_IS_LOADING_MOLECULE_LIST',
Expand Down
3 changes: 3 additions & 0 deletions js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
case constants.SET_DATASET:
return Object.assign({}, state, { datasets: action.payload });

case constants.REPLACE_ALL_MOLECULELISTS:
return {...state, moleculeLists: action.payload};

case constants.ADD_MOLECULELIST:
// initialize also control containers
const initializedState = initializeContainerLists(state, action.payload.datasetID);
Expand Down
34 changes: 31 additions & 3 deletions js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created by abradley on 14/04/2018.
*/

import React, { memo, useContext, useEffect, useRef, useState } from 'react';
import React, { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { Grid, makeStyles, useTheme, ButtonGroup, Button } from '@material-ui/core';
import NGLView from '../nglView/nglView';
import HitNavigator from './molecule/hitNavigator';
Expand Down Expand Up @@ -31,7 +31,7 @@ import { loadDatasetCompoundsWithScores, loadDataSets } from '../datasets/redux/
import { SelectedCompoundList } from '../datasets/selectedCompoundsList';
import { DatasetSelectorMenuButton } from '../datasets/datasetSelectorMenuButton';
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
import { setMoleculeListIsLoading } from '../datasets/redux/actions';
import { setMoleculeListIsLoading, replaceAllMoleculeLists } from '../datasets/redux/actions';

const hitNavigatorWidth = 504;

Expand Down Expand Up @@ -125,12 +125,40 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
const allMolsGroupsCount = Object.keys(all_mol_lists || {}).length;
const moleculeListsCount = Object.keys(moleculeLists || {}).length;
if (allMolsGroupsCount > 0 && moleculeListsCount > 0 && !isLoadingMoleculeList) {
const allDatasets = {};
const allMolsMap = linearizeMoleculesLists();
const keys = Object.keys(moleculeLists);
keys.forEach(key => {
let dataset = moleculeLists[key];
let mols = [];
dataset.forEach(dsMol => {
let inspirations = [];
dsMol.computed_inspirations.forEach(id => {
let lhsMol = allMolsMap[id];
inspirations.push(lhsMol);
});
dsMol.inspirations = inspirations;
mols.push(dsMol);
});
allDatasets[key] = mols;
});
dispatch(replaceAllMoleculeLists(allDatasets));
}
}, [all_mol_lists, moleculeLists, isLoadingMoleculeList]);
}, [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;
});
});

return allMolsMap;
}, [all_mol_lists]);

const [molGroupsHeight, setMolGroupsHeight] = useState(0);
const [filterItemsHeight, setFilterItemsHeight] = useState(0);
Expand Down

0 comments on commit 021aaa9

Please sign in to comment.