Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#429' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Nov 13, 2020
2 parents 740d42b + 35f73e9 commit 1274ab0
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 61 deletions.
10 changes: 9 additions & 1 deletion js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,15 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
return Object.assign({}, state, lists);

case constants.RESET_DATASETS_STATE:
return INITIAL_STATE;
const datasetsLists = {
ligandLists: reloadLists([], 'ligandLists'),
proteinLists: reloadLists([], 'proteinLists'),
complexLists: reloadLists([], 'complexLists'),
surfaceLists: reloadLists([], 'surfaceLists'),
inspirationLists: reloadLists([], 'inspirationLists'),
compoundsToBuyDatasetMap: reloadLists([], 'compoundsToBuyDatasetMap')
};
return Object.assign({}, state, { ...INITIAL_STATE, ...datasetsLists });

default:
return state;
Expand Down
5 changes: 3 additions & 2 deletions js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
const [selectedDatasetIndex, setSelectedDatasetIndex] = useState();
const currentDataset = customDatasets[selectedDatasetIndex];
const target_on = useSelector(state => state.apiReducers.target_on);
const isTrackingRestoring = useSelector(state => state.trackingReducers.isTrackingCompoundsRestoring);

/*
Loading datasets
*/
useEffect(() => {
if (customDatasets.length === 0) {
if (customDatasets.length === 0 && isTrackingRestoring === false) {
dispatch(setMoleculeListIsLoading(true));
dispatch(loadDataSets(target_on))
.then(results => {
Expand All @@ -115,7 +116,7 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
dispatch(setMoleculeListIsLoading(false));
});
}
}, [customDatasets.length, dispatch, target_on]);
}, [customDatasets.length, dispatch, target_on, isTrackingRestoring]);

const [molGroupsHeight, setMolGroupsHeight] = useState(0);
const [filterItemsHeight, setFilterItemsHeight] = useState(0);
Expand Down
43 changes: 23 additions & 20 deletions js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { useRouteMatch } from 'react-router-dom';
import { setSortDialogOpen } from './redux/actions';
import { setMoleculeList, setAllMolLists } from '../../../reducers/api/actions';
import { AlertModal } from '../../common/Modal/AlertModal';
import { onSelectMoleculeGroup } from '../moleculeGroups/redux/dispatchActions';
import { selectMoleculeGroup } from '../moleculeGroups/redux/dispatchActions';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -253,7 +253,8 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
const all_mol_lists = useSelector(state => state.apiReducers.all_mol_lists);
const directDisplay = useSelector(state => state.apiReducers.direct_access);
const directAccessProcessed = useSelector(state => state.apiReducers.direct_access_processed);

const isTrackingRestoring = useSelector(state => state.trackingReducers.isTrackingMoleculesRestoring);

const proteinsHasLoaded = useSelector(state => state.nglReducers.proteinsHasLoaded);

const [predefinedFilter, setPredefinedFilter] = useState(filter !== undefined ? filter.predefined : DEFAULT_FILTER);
Expand Down Expand Up @@ -315,26 +316,31 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
target_on &&
mol_group_list &&
mol_group_list.length > 0 &&
Object.keys(all_mol_lists).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
}))
promises.push(
loadAllMolsFromMolGroup({
url,
mol_group: id
})
);
});
Promise.all(promises).then((results) => {
let listToSet = {};
results.forEach(molResult => {
listToSet[molResult.mol_group] = molResult.molecules;
});
dispatch(setAllMolLists(listToSet))
}).catch((err) => console.log(err));
Promise.all(promises)
.then(results => {
let listToSet = {};
results.forEach(molResult => {
listToSet[molResult.mol_group] = molResult.molecules;
});
dispatch(setAllMolLists(listToSet));
})
.catch(err => console.log(err));
}
}, [proteinsHasLoaded, mol_group_list, list_type, target_on, dispatch, all_mol_lists]);
}, [proteinsHasLoaded, mol_group_list, list_type, target_on, dispatch, all_mol_lists, isTrackingRestoring]);

useEffect(() => {
loadAllMolecules();
Expand All @@ -346,16 +352,13 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
mol_group_list.forEach(mg => {
molGroupMap[mg.description] = mg.id;
});
return molGroupMap;
return molGroupMap;
}
}, [mol_group_list]);

useEffect(() => {
const allMolsGroupsCount = Object.keys(all_mol_lists || {}).length;
if (
(proteinsHasLoaded === true || proteinsHasLoaded === null) &&
allMolsGroupsCount > 0
) {
if ((proteinsHasLoaded === true || proteinsHasLoaded === null) && allMolsGroupsCount > 0) {
dispatch(setMoleculeList({ ...(all_mol_lists[mol_group_on] || []) }));
if (!directAccessProcessed && directDisplay && directDisplay.molecules && directDisplay.molecules.length > 0) {
dispatch(applyDirectSelection(majorViewStage, stageSummaryView));
Expand Down
34 changes: 34 additions & 0 deletions js/components/preview/moleculeGroups/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ export const saveMoleculeGroupsToNglView = (molGroupList, stage, projectId) => d
}
};

export const saveMoleculeGroupsToNglViewWithoutProject = (molGroupList, stage) => dispatch => {
if (molGroupList) {
molGroupList.map(data =>
dispatch(loadObject({ target: Object.assign({ display_div: VIEWS.SUMMARY_VIEW }, generateSphere(data)), stage }))
);
}
};

export const selectMoleculeGroup = (moleculeGroup, summaryViewStage) => (dispatch, getState) => {
const state = getState();
const moleculeGroupSelection = state.selectionReducers.mol_group_selection.slice();
Expand Down Expand Up @@ -171,6 +179,32 @@ export const loadMoleculeGroups = ({ summaryView, setOldUrl, oldUrl, onCancel, i
return Promise.resolve();
};

export const loadMoleculeGroupsOfTarget = ({ summaryView, setOldUrl, isStateLoaded, target_on }) => (
dispatch,
getState
) => {
const state = getState();
const group_type = state.apiReducers.group_type;
const list_type = OBJECT_TYPE.MOLECULE_GROUP;

if (target_on && !isStateLoaded) {
return loadFromServer({
url: getUrl({ list_type, target_on, group_type }),
afterPush: data_list => dispatch(saveMoleculeGroupsToNglViewWithoutProject(data_list, summaryView)),
list_type,
setOldUrl,
setObjectList: mol_group_list => {
mol_group_list.sort((a, b) => a.id - b.id);
dispatch(setMolGroupList(mol_group_list));
}
});
} else if (target_on && isStateLoaded) {
// to enable user interaction with application
dispatch(setCountOfRemainingMoleculeGroups(0));
}
return Promise.resolve();
};

export const clearMoleculeGroupSelection = ({ getNglView }) => (dispatch, getState) => {
const state = getState();
const molGroupList = state.apiReducers.mol_group_list;
Expand Down
73 changes: 50 additions & 23 deletions js/components/tracking/trackingModal.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { memo } from 'react';
import { useSelector } from 'react-redux';
import React, { memo, useContext } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import Modal from '../common/Modal';
import { Grid, makeStyles } from '@material-ui/core';
import { Grid, makeStyles, IconButton, Tooltip } from '@material-ui/core';
import { Timeline, TimelineEvent } from 'react-event-timeline';
import { Check, Clear } from '@material-ui/icons';
import { Check, Clear, Save, Restore, Close } from '@material-ui/icons';
import palette from '../../theme/palette';
import { Panel } from '../common';
import { selectCurrentActionsList, restoreCurrentActionsList } from '../../reducers/tracking/dispatchActions';
import { NglContext } from '../nglView/nglProvider';

const useStyles = makeStyles(theme => ({
customModal: {
Expand Down Expand Up @@ -34,6 +36,9 @@ const useStyles = makeStyles(theme => ({

export const TrackingModal = memo(({ openModal, onModalClose }) => {
const classes = useStyles();
const dispatch = useDispatch();
const { nglViewList } = useContext(NglContext);

const actionList = useSelector(state => state.trackingReducers.truck_actions_list);
const orderedActionList = actionList.sort((a, b) => a.timestamp - b.timestamp);

Expand All @@ -42,37 +47,59 @@ export const TrackingModal = memo(({ openModal, onModalClose }) => {
onModalClose();
}

const actions = [
<IconButton color={'inherit'} onClick={() => dispatch(selectCurrentActionsList())}>
<Tooltip title="Save">
<Save />
</Tooltip>
</IconButton>,
<IconButton color={'inherit'} onClick={() => dispatch(restoreCurrentActionsList(nglViewList))}>
<Tooltip title="Restore">
<Restore />
</Tooltip>
</IconButton>,
<IconButton color={'inherit'} onClick={() => onModalClose()}>
<Tooltip title="Close">
<Close />
</Tooltip>
</IconButton>
];

return (
<Modal
otherClasses={classes.customModal}
otherContentClasses={classes.customContentModal}
open={openModal}
onClose={() => onModalClose()}
>
<Panel bodyOverflow={true} hasHeader={true} title="Action List">
<Panel bodyOverflow={true} hasHeader={true} title="Action List" headerActions={actions}>
<Grid container justify="space-between" className={classes.containerExpanded}>
<div className={classes.divContainer}>
<div className={classes.divScrollable}>
<Timeline>
{orderedActionList &&
orderedActionList.map((data, index) => (
<TimelineEvent
key={index}
title={data.text}
createdAt={new Date(data.timestamp).toLocaleString()}
icon={
data.type.includes('OFF') === true ||
data.type.includes('DESELECTED') === true ||
data.type.includes('REMOVED') === true ? (
<Clear />
) : (
<Check />
)
}
iconColor={palette.primary.main}
className={classes.timelineEvent}
></TimelineEvent>
))}
orderedActionList.map((data, index) => {
if (data && data != null) {
return (
<TimelineEvent
key={index}
title={data.text}
createdAt={new Date(data.timestamp).toLocaleString()}
icon={
data.type.includes('OFF') === true ||
data.type.includes('DESELECTED') === true ||
data.type.includes('REMOVED') === true ? (
<Clear />
) : (
<Check />
)
}
iconColor={palette.primary.main}
className={classes.timelineEvent}
></TimelineEvent>
);
}
})}
</Timeline>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions js/reducers/tracking/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ export const setCurrentActionsList = function(current_actions_list) {
current_actions_list: current_actions_list
};
};

export const setIsTrackingMoleculesRestoring = function(isTrackingMoleculesRestoring) {
return {
type: constants.SET_IS_TRACKING_MOLECULES_RESTORING,
isTrackingMoleculesRestoring: isTrackingMoleculesRestoring
};
};

export const setIsTrackingCompoundsRestoring = function(isTrackingCompoundsRestoring) {
return {
type: constants.SET_IS_TRACKING_COMPOUNDS_RESTORING,
isTrackingCompoundsRestoring: isTrackingCompoundsRestoring
};
};
4 changes: 3 additions & 1 deletion js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const prefix = 'REDUCERS_TRACKING_';
export const constants = {
SET_ACTIONS_LIST: prefix + 'SET_ACTIONS_LIST',
APPEND_ACTIONS_LIST: prefix + 'APPEND_ACTIONS_LIST',
SET_CURRENT_ACTIONS_LIST: prefix + 'SET_CURRENT_ACTIONS_LIST'
SET_CURRENT_ACTIONS_LIST: prefix + 'SET_CURRENT_ACTIONS_LIST',
SET_IS_TRACKING_COMPOUNDS_RESTORING: prefix + 'SET_IS_TRACKING_COMPOUNDS_RESTORING',
SET_IS_TRACKING_MOLECULES_RESTORING: prefix + 'SET_IS_TRACKING_MOLECULES_RESTORING'
};

export const actionType = {
Expand Down
Loading

0 comments on commit 1274ab0

Please sign in to comment.