Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#462' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Nov 27, 2020
2 parents 2d017f2 + e0c3756 commit 2e92f21
Show file tree
Hide file tree
Showing 24 changed files with 648 additions and 366 deletions.
2 changes: 1 addition & 1 deletion js/components/datasets/inspirationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const InspirationDialog = memo(
const removeSelectedType = (type, skipTracking = false) => {
if (type === 'ligand') {
moleculeList.forEach(molecule => {
dispatch(removeType[type](stage, molecule, colourList[molecule.id % colourList.length], false, skipTracking));
dispatch(removeType[type](stage, molecule, skipTracking));
});
} else {
moleculeList.forEach(molecule => {
Expand Down
8 changes: 4 additions & 4 deletions js/components/datasets/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ export const removeOrAddAllHitProteinsOfList = (areAllSelected, moleculeList = [

if (areAllSelected) {
let molecules = dispatch(getSelectedMoleculesByType(type, false, moleculeList));
dispatch(setDeselectedAllByType(type, molecules));
dispatch(setDeselectedAllByType(type, null, molecules, true));
dispatch(removeAllHitProteins(moleculeList, stage, true));
} else {
let molecules = dispatch(getSelectedMoleculesByType(type, true, moleculeList));
dispatch(setSelectedAllByType(type, molecules));
dispatch(setSelectedAllByType(type, null, molecules, true));
dispatch(addAllHitProteins(moleculeList, stage, true));
}
};
Expand Down Expand Up @@ -497,11 +497,11 @@ export const removeOrAddAllComplexesOfList = (areAllSelected, moleculeList = [],

if (areAllSelected) {
let molecules = dispatch(getSelectedMoleculesByType(type, false, moleculeList));
dispatch(setDeselectedAllByType(type, molecules));
dispatch(setDeselectedAllByType(type, null, molecules, true));
dispatch(removeAllComplexes(moleculeList, stage, true));
} else {
let molecules = dispatch(getSelectedMoleculesByType(type, true, moleculeList));
dispatch(setSelectedAllByType(type, molecules));
dispatch(setSelectedAllByType(type, null, molecules, true));
dispatch(addAllComplexes(moleculeList, stage, true));
}
};
Expand Down
20 changes: 7 additions & 13 deletions js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ export const INITIAL_STATE = {
surfaceLists: {}, // map of $datasetID and its $list
inspirationLists: {}, // map of $datasetID and its $list

molecule_all_selection: null,
molecule_all_deselection: null,

molecule_all_type_selection: {},
molecule_all_type_deselection: {},
moleculeAllSelection: {},
moleculeAllTypeSelection: {},

// search
searchString: null,
Expand Down Expand Up @@ -123,6 +120,7 @@ const initializeContainerLists = (state, datasetID) => {
state.complexLists[datasetID] = state.complexLists[datasetID] || [];
state.surfaceLists[datasetID] = state.surfaceLists[datasetID] || [];
state.inspirationLists[datasetID] = state.inspirationLists[datasetID] || [];
state.moleculeAllSelection[datasetID] = state.moleculeAllSelection[datasetID] || [];
return state;
};

Expand Down Expand Up @@ -380,23 +378,19 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
return Object.assign({}, state, { ...INITIAL_STATE, ...datasetsLists });

case constants.SET_SELECTED_ALL:
return Object.assign({}, state, {
molecule_all_selection: action.payload
});
return appendToList(state, 'moleculeAllSelection', action.payload.datasetID, action.payload.item.id);

case constants.SET_DESELECTED_ALL:
return Object.assign({}, state, {
molecule_all_deselection: action.payload
});
return removeFromList(state, 'moleculeAllSelection', action.payload.datasetID, action.payload.item.id);

case constants.SET_SELECTED_ALL_BY_TYPE:
return Object.assign({}, state, {
molecule_all_type_selection: action.payload
moleculeAllTypeSelection: action.payload.type
});

case constants.SET_DESELECTED_ALL_BY_TYPE:
return Object.assign({}, state, {
molecule_all_type_deselection: action.payload
moleculeAllTypeSelection: action.payload.type
});
default:
return state;
Expand Down
2 changes: 1 addition & 1 deletion js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
const dispatch = useDispatch();

const customDatasets = useSelector(state => state.datasetsReducers.datasets);
const [selectedDatasetIndex, setSelectedDatasetIndex] = useState();
const [selectedDatasetIndex, setSelectedDatasetIndex] = useState(0);
const currentDataset = customDatasets[selectedDatasetIndex];
const target_on = useSelector(state => state.apiReducers.target_on);
const isTrackingRestoring = useSelector(state => state.trackingReducers.isTrackingCompoundsRestoring);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { OBJECT_TYPE } from '../../../nglView/constants';
import { setSortDialogOpen } from '../../molecule/redux/actions';
import { resetCurrentCompoundsSettings } from '../../compounds/redux/actions';
import { reloadSession } from '../../../snapshot/redux/dispatchActions';
import { restoreCurrentActionsList } from '../../../../reducers/tracking/dispatchActions';

export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup, majorViewStage }) => (
dispatch,
Expand Down Expand Up @@ -246,10 +247,13 @@ export const clearMoleculeGroupSelection = ({ getNglView }) => (dispatch, getSta

export const restoreFromCurrentSnapshot = ({ nglViewList }) => (dispatch, getState) => {
const snapshot = getState().projectReducers.currentSnapshot.data;

dispatch(reloadSession(snapshot, nglViewList));
};

export const restoreSnapshotActions = ({ nglViewList }) => (dispatch, getState) => {
dispatch(restoreCurrentActionsList(nglViewList));
};

export const onDeselectMoleculeGroup = ({ moleculeGroup, stageSummaryView, majorViewStage }) => (
dispatch,
getState
Expand Down
9 changes: 0 additions & 9 deletions js/components/preview/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ export const shouldLoadProtein = ({
});
}

// decide to load existing snapshot
else if (
currentSnapshotID !== null &&
(!routeSnapshotID || routeSnapshotID === currentSnapshotID.toString()) &&
currentSnapshotData !== null
) {
dispatch(reloadSession(currentSnapshotData, nglViewList));
}

if (targetOnName !== undefined) {
document.title = targetOnName + ': Fragalysis';
}
Expand Down
16 changes: 12 additions & 4 deletions js/components/projects/addProjectDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Autocomplete } from '@material-ui/lab';
import { Button } from '../../common/Inputs/Button';
import { useDispatch, useSelector } from 'react-redux';
import { createProjectFromSnapshotDialog } from '../redux/dispatchActions';
import { manageSendTrackingActions } from '../../../reducers/tracking/dispatchActions';

const useStyles = makeStyles(theme => ({
body: {
Expand All @@ -34,6 +35,7 @@ export const AddProjectDetail = memo(({ handleCloseModal }) => {

const dispatch = useDispatch();
const targetId = useSelector(state => state.apiReducers.target_on);
const projectID = useSelector(state => state.projectReducers.currentProject.projectID);
const isProjectModalLoading = useSelector(state => state.projectReducers.isProjectModalLoading);

const [tags, setTags] = React.useState([]);
Expand Down Expand Up @@ -65,11 +67,17 @@ export const AddProjectDetail = memo(({ handleCloseModal }) => {
author: DJANGO_CONTEXT['pk'] || null,
tags: JSON.stringify(tags)
};
dispatch(createProjectFromSnapshotDialog(data)).catch(error => {
setState(() => {
throw error;

const oldProjectID = projectID;
dispatch(createProjectFromSnapshotDialog(data))
.then(() => {
dispatch(manageSendTrackingActions(oldProjectID, true));
})
.catch(error => {
setState(() => {
throw error;
});
});
});
}}
>
{({ submitForm, isSubmitting }) => (
Expand Down
47 changes: 30 additions & 17 deletions js/components/projects/projectPreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ import { useRouteMatch } from 'react-router-dom';
import { loadCurrentSnapshotByID, loadSnapshotByProjectID } from '../redux/dispatchActions';
import { HeaderContext } from '../../header/headerContext';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
import { restoreCurrentActionsList, restoreAfterTargetActions } from '../../../reducers/tracking/dispatchActions';
import { NglContext } from '../../nglView/nglProvider';

export const ProjectPreview = memo(({}) => {
const { setSnackBarTitle } = useContext(HeaderContext);
const [canShow, setCanShow] = useState(undefined);
const isSnapshotLoaded = useRef(undefined);
let match = useRouteMatch();
const dispatch = useDispatch();
const { nglViewList } = useContext(NglContext);

const projectId = match && match.params && match.params.projectId;
const snapshotId = match && match.params && match.params.snapshotId;
const currentSnapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
const currentProject = useSelector(state => state.projectReducers.currentProject);
const isActionRestoring = useSelector(state => state.trackingReducers.isActionRestoring);

useEffect(() => {
if (!snapshotId && currentSnapshotID === null) {
Expand All @@ -31,28 +36,36 @@ export const ProjectPreview = memo(({}) => {
throw new Error(error);
});
} else {
dispatch(loadCurrentSnapshotByID(snapshotId || currentSnapshotID))
.then(response => {
if (response !== false) {
if (response) {
if (response.session_project && `${response.session_project.id}` === projectId) {
isSnapshotLoaded.current = response.id;
setCanShow(true);
if (currentSnapshotID === null) {
dispatch(loadCurrentSnapshotByID(snapshotId))
.then(response => {
if (response !== false) {
if (response) {
if (response.session_project && `${response.session_project.id}` === projectId) {
isSnapshotLoaded.current = response.id;
setCanShow(true);
} else {
setCanShow(false);
}
} else {
isSnapshotLoaded.current = response;
setCanShow(false);
}
} else {
isSnapshotLoaded.current = response;
setCanShow(false);
}
}
})
.catch(error => {
setCanShow(false);
throw new Error(error);
});
})
.catch(error => {
setCanShow(false);
throw new Error(error);
});
} else {
if (isActionRestoring === false) {
dispatch(restoreCurrentActionsList(nglViewList));
} else if (nglViewList && nglViewList.length > 0) {
dispatch(restoreAfterTargetActions(nglViewList));
}
}
}
}, [currentSnapshotID, dispatch, projectId, snapshotId]);
}, [currentSnapshotID, dispatch, projectId, snapshotId, isActionRestoring, nglViewList, canShow]);

if (canShow === false) {
setSnackBarTitle('Not valid snapshot!');
Expand Down
8 changes: 4 additions & 4 deletions js/components/projects/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const assignSnapshotToProject = ({ projectID, snapshotID, ...rest }) => (
created: response.data.created,
children: response.data.children,
parent: response.data.parent,
data: JSON.parse(response.data.data)
data: '[]'
})
)
)
Expand Down Expand Up @@ -147,7 +147,7 @@ export const loadSnapshotByProjectID = projectID => (dispatch, getState) => {
created: response.data.results[0].created,
children: response.data.results[0].children,
parent: response.data.results[0].parent,
data: JSON.parse(response.data.results[0].data)
data: '[]'
})
);
return Promise.resolve(response.data.results[0].id);
Expand Down Expand Up @@ -184,7 +184,7 @@ export const loadCurrentSnapshotByID = snapshotID => (dispatch, getState) => {
created: response.data.created,
children: response.data.children,
parent: response.data.parent,
data: JSON.parse(response.data.data)
data: '[]'
})
);
return Promise.resolve(response.data);
Expand Down Expand Up @@ -294,7 +294,7 @@ const copySnapshot = (selectedSnapshot, projectID, history) => dispatch => {
title: selectedSnapshot.title,
author: (selectedSnapshot && selectedSnapshot.author && selectedSnapshot.author.id) || null,
description: selectedSnapshot.description,
data: JSON.parse(selectedSnapshot.data),
data: '[]',
created: selectedSnapshot.created,
parent: null,
children: selectedSnapshot.children,
Expand Down
26 changes: 11 additions & 15 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import { base_url, URLS } from '../../routes/constants';
import { resetCurrentSnapshot, setCurrentSnapshot, setForceCreateProject } from '../../projects/redux/actions';
import { selectFirstMolGroup } from '../../preview/moleculeGroups/redux/dispatchActions';
import { reloadDatasetsReducer } from '../../datasets/redux/actions';
import {
sendTruckingActionsByProjectId,
appendAndSendTruckingActions
} from '../../../reducers/tracking/dispatchActions';
import { saveCurrentActionsList } from '../../../reducers/tracking/dispatchActions';
import { sendTrackingActionsByProjectId, manageSendTrackingActions } from '../../../reducers/tracking/dispatchActions';

export const getListOfSnapshots = () => (dispatch, getState) => {
const userID = DJANGO_CONTEXT['pk'] || null;
Expand Down Expand Up @@ -86,7 +84,7 @@ export const saveCurrentSnapshot = ({
dispatch(resetCurrentSnapshot());
return api({
url: `${base_url}/api/snapshots/`,
data: { type, title, author, description, data: JSON.stringify(data), created, parent, children, session_project },
data: { type, title, author, description, created, parent, data: '[]', children, session_project },
method: METHOD.POST
})
.then(response =>
Expand Down Expand Up @@ -185,8 +183,6 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
getState
) => {
const state = getState();
const { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers } = state;
const data = { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers };
const selectedSnapshotToSwitch = state.snapshotReducers.selectedSnapshotToSwitch;
const disableRedirect = state.snapshotReducers.disableRedirect;

Expand All @@ -212,13 +208,15 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
author,
parent,
session_project,
data: JSON.stringify(data),
data: '[]',
children: []
},
method: METHOD.POST
}).then(res => {
// redirect to project with newest created snapshot /:projectID/:snapshotID
if (res.data.id && session_project) {
dispatch(saveCurrentActionsList(res.data.id, session_project));

if (disableRedirect === false) {
// Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
// use react-router !
Expand Down Expand Up @@ -253,6 +251,7 @@ export const activateSnapshotDialog = (loggedInUserID = undefined, finallyShareS
const projectID = state.projectReducers.currentProject.projectID;
const currentSnapshotAuthor = state.projectReducers.currentSnapshot.author;

dispatch(manageSendTrackingActions());
dispatch(setDisableRedirect(finallyShareSnapshot));

if (!loggedInUserID && targetId) {
Expand All @@ -265,7 +264,7 @@ export const activateSnapshotDialog = (loggedInUserID = undefined, finallyShareS
};
dispatch(createProjectFromSnapshotDialog(data))
.then(() => {
dispatch(appendAndSendTruckingActions(null));
dispatch(manageSendTrackingActions(projectID, true));
dispatch(setOpenSnapshotSavingDialog(true));
})
.catch(error => {
Expand All @@ -287,10 +286,6 @@ export const createNewSnapshotWithoutStateModification = ({
parent,
session_project
}) => (dispatch, getState) => {
const state = getState();
const { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers } = state;
const data = { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers };

if (!session_project) {
return Promise.reject('Project ID is missing!');
}
Expand All @@ -311,7 +306,7 @@ export const createNewSnapshotWithoutStateModification = ({
author,
parent,
session_project,
data: JSON.stringify(data),
data: '[]',
children: []
},
method: METHOD.POST
Expand All @@ -325,6 +320,7 @@ export const createNewSnapshotWithoutStateModification = ({
disableRedirect: true
})
);
dispatch(saveCurrentActionsList(res.data.id, session_project));
}
});
});
Expand Down Expand Up @@ -358,7 +354,7 @@ export const saveAndShareSnapshot = (target = undefined) => (dispatch, getState)
const parent = null;
const session_project = projectID;

dispatch(sendTruckingActionsByProjectId(projectID, author));
dispatch(sendTrackingActionsByProjectId(projectID, author));

return dispatch(
createNewSnapshotWithoutStateModification({ title, description, type, author, parent, session_project })
Expand Down
Loading

0 comments on commit 2e92f21

Please sign in to comment.