Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#481' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Dec 18, 2020
2 parents ac99d74 + 0ca9ba1 commit 2fe8723
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 30 deletions.
13 changes: 8 additions & 5 deletions js/components/preview/viewerControls/displayControls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { NglContext } from '../../../nglView/nglProvider';
import {
addComponentRepresentation,
removeComponentRepresentation,
updateComponentRepresentation
updateComponentRepresentation,
changeComponentRepresentation
} from '../../../../reducers/ngl/actions';
import { deleteObject } from '../../../../reducers/ngl/dispatchActions';
import { MOL_REPRESENTATION, OBJECT_TYPE, SELECTION_TYPE } from '../../../nglView/constants';
Expand Down Expand Up @@ -71,10 +72,12 @@ export default memo(({ open, onClose }) => {
oldRepresentation.lastKnownID
);
// add new representation to redux
dispatch(addComponentRepresentation(parentKey, newRepresentation));
dispatch(addComponentRepresentation(parentKey, newRepresentation, true));

// remove previous representation from NGL
removeRepresentation(representation, parentKey);
removeRepresentation(representation, parentKey, true);

dispatch(changeComponentRepresentation(parentKey, oldRepresentation, newRepresentation));
};

const addMolecularRepresentation = (parentKey, e) => {
Expand All @@ -88,7 +91,7 @@ export default memo(({ open, onClose }) => {
dispatch(addComponentRepresentation(parentKey, newRepresentation));
};

const removeRepresentation = (representation, parentKey) => {
const removeRepresentation = (representation, parentKey, skipTracking) => {
const nglView = getNglView(objectsInView[parentKey].display_div);
const comp = nglView.stage.getComponentsByName(parentKey).first;
let foundedRepresentation = undefined;
Expand All @@ -107,7 +110,7 @@ export default memo(({ open, onClose }) => {
// remove from nglReducer and selectionReducer
dispatch(deleteObject(targetObject, nglView.stage, true));
} else {
dispatch(removeComponentRepresentation(parentKey, representation));
dispatch(removeComponentRepresentation(parentKey, representation, skipTracking));
}
}
};
Expand Down
17 changes: 13 additions & 4 deletions js/reducers/ngl/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ export const updateComponentRepresentation = (objectInViewID, representationID,
change
});

export const addComponentRepresentation = (objectInViewID, newRepresentation) => ({
export const addComponentRepresentation = (objectInViewID, newRepresentation, skipTracking = false) => ({
type: CONSTANTS.ADD_COMPONENT_REPRESENTATION,
newRepresentation,
objectInViewID
objectInViewID,
skipTracking
});

export const removeComponentRepresentation = (objectInViewID, representation) => ({
export const removeComponentRepresentation = (objectInViewID, representation, skipTracking = false) => ({
type: CONSTANTS.REMOVE_COMPONENT_REPRESENTATION,
representation,
objectInViewID,
skipTracking
});

export const changeComponentRepresentation = (objectInViewID, oldRepresentation, newRepresentation) => ({
type: CONSTANTS.CHANGE_COMPONENT_REPRESENTATION,
oldRepresentation,
newRepresentation,
objectInViewID
});

Expand Down Expand Up @@ -91,5 +100,5 @@ export const removeMoleculeOrientation = moleculeGroupID => ({

export const addToPdbCache = (name, cacheItem) => ({
type: CONSTANTS.ADD_TO_PDB_CACHE,
payload: {name: name, cacheItem: cacheItem}
payload: { name: name, cacheItem: cacheItem }
});
1 change: 1 addition & 0 deletions js/reducers/ngl/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CONSTANTS = {
UPDATE_COMPONENT_REPRESENTATION: prefix + 'UPDATE_COMPONENT_REPRESENTATION',
REMOVE_COMPONENT_REPRESENTATION: prefix + 'REMOVE_COMPONENT_REPRESENTATION',
ADD_COMPONENT_REPRESENTATION: prefix + 'ADD_COMPONENT_REPRESENTATION',
CHANGE_COMPONENT_REPRESENTATION: prefix + 'CHANGE_COMPONENT_REPRESENTATION',

SET_NGL_VIEW_PARAMS: prefix + 'SET_NGL_VIEW_PARAMS',
SET_ORIENTATION: prefix + 'SET_ORIENTATION',
Expand Down
4 changes: 3 additions & 1 deletion js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export const actionType = {
MOLECULE_REMOVED_FROM_SHOPPING_CART: 'MOLECULE_REMOVED_FROM_SHOPPING_CART',
COMPOUND_SELECTED: 'COMPOUND_SELECTED',
COMPOUND_DESELECTED: 'COMPOUND_DESELECTED',
REPRESENTATION_CHANGED: 'REPRESENTATION_CHANGED',
REPRESENTATION_UPDATED: 'REPRESENTATION_UPDATED',
REPRESENTATION_ADDED: 'REPRESENTATION_ADDED',
REPRESENTATION_REMOVED: 'REPRESENTATION_REMOVED',
REPRESENTATION_CHANGED: 'REPRESENTATION_CHANGED',
NGL_STATE: 'NGL_STATE',
UNDO: 'UNDO',
REDO: 'REDO',
Expand All @@ -65,6 +66,7 @@ export const actionDescription = {
ADDED: 'was added',
REMOVED: 'was removed',
CHANGED: 'was changed',
UPDATED: 'was updated',
TO_SHOPPING_CART: 'to shopping cart',
FROM_SHOPPING_CART: 'from shopping cart',
LIGAND: 'Ligand',
Expand Down
76 changes: 58 additions & 18 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ import { getUrl, loadAllMolsFromMolGroup } from '../../../js/utils/genericList';
import {
removeComponentRepresentation,
addComponentRepresentation,
updateComponentRepresentation
updateComponentRepresentation,
changeComponentRepresentation
} from '../../../js/reducers/ngl/actions';
import * as listType from '../../constants/listTypes';
import { assignRepresentationToComp } from '../../components/nglView/generatingObjects';
Expand Down Expand Up @@ -341,7 +342,7 @@ const saveActionsList = (project, snapshot, actionList, nglViewList) => async (d

getCurrentActionList(
orderedActionList,
actionType.REPRESENTATION_CHANGED,
actionType.REPRESENTATION_UPDATED,
getCollectionOfDatasetOfRepresentation(currentobjectsInView),
currentActions
);
Expand Down Expand Up @@ -860,7 +861,6 @@ const restoreAllSelectionActions = (moleculesAction, stage, isSelection) => (dis
};

const restoreAllSelectionByTypeActions = (moleculesAction, stage, isSelection) => (dispatch, getState) => {

let actions =
isSelection === true
? moleculesAction.filter(
Expand Down Expand Up @@ -933,11 +933,11 @@ const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, get
}

let representationsChangesActions = moleculesAction.filter(
action => action.type === actionType.REPRESENTATION_CHANGED
action => action.type === actionType.REPRESENTATION_UPDATED
);
if (representationsChangesActions) {
representationsChangesActions.forEach(action => {
dispatch(changeRepresentation(true, action.change, action.object_id, action.representation, nglView));
dispatch(updateRepresentation(true, action.change, action.object_id, action.representation, nglView));
});
}
};
Expand Down Expand Up @@ -1239,15 +1239,18 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {
case actionType.COMPOUND_DESELECTED:
dispatch(handleCompoundAction(action, true));
break;
case actionType.REPRESENTATION_CHANGED:
dispatch(handleChangeRepresentationAction(action, false, majorView));
case actionType.REPRESENTATION_UPDATED:
dispatch(handleUpdateRepresentationAction(action, false, majorView));
break;
case actionType.REPRESENTATION_ADDED:
dispatch(handleRepresentationAction(action, false, majorView));
break;
case actionType.REPRESENTATION_REMOVED:
dispatch(handleRepresentationAction(action, true, majorView));
break;
case actionType.REPRESENTATION_CHANGED:
dispatch(handleChangeRepresentationAction(action, false, majorView));
break;
default:
break;
}
Expand Down Expand Up @@ -1337,15 +1340,18 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {
case actionType.COMPOUND_DESELECTED:
dispatch(handleCompoundAction(action, false));
break;
case actionType.REPRESENTATION_CHANGED:
dispatch(handleChangeRepresentationAction(action, true, majorView));
case actionType.REPRESENTATION_UPDATED:
dispatch(handleUpdateRepresentationAction(action, true, majorView));
break;
case actionType.REPRESENTATION_ADDED:
dispatch(handleRepresentationAction(action, true, majorView));
break;
case actionType.REPRESENTATION_REMOVED:
dispatch(handleRepresentationAction(action, false, majorView));
break;
case actionType.REPRESENTATION_CHANGED:
dispatch(handleChangeRepresentationAction(action, true, majorView));
break;
default:
break;
}
Expand Down Expand Up @@ -1582,14 +1588,17 @@ const handleShoppingCartAction = (action, isAdd) => (dispatch, getState) => {
const handleRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
if (action) {
if (isAdd === true) {
dispatch(addRepresentation(action.object_id, action.representation, nglView));
dispatch(addRepresentation(action, action.object_id, action.representation, nglView));
} else {
dispatch(removeRepresentation(action.object_id, action.representation, nglView));
dispatch(removeRepresentation(action, action.object_id, action.representation, nglView));
}
}
};

const addRepresentation = (parentKey, representation, nglView) => (dispatch, getState) => {
const addRepresentation = (action, parentKey, representation, nglView, update, skipTracking = false) => (
dispatch,
getState
) => {
const oldRepresentation = representation;
const newRepresentationType = oldRepresentation.type;
const comp = nglView.stage.getComponentsByName(parentKey).first;
Expand All @@ -1599,16 +1608,22 @@ const addRepresentation = (parentKey, representation, nglView) => (dispatch, get
comp,
oldRepresentation.lastKnownID
);
dispatch(addComponentRepresentation(parentKey, newRepresentation));
action.representation = newRepresentation;
if (update === true) {
action.newRepresentation = newRepresentation;
} else {
action.oldRepresentation = newRepresentation;
}
dispatch(addComponentRepresentation(parentKey, newRepresentation, skipTracking));
};

const handleChangeRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
const handleUpdateRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
if (action) {
dispatch(changeRepresentation(isAdd, action.change, action.object_id, action.representation, nglView));
dispatch(updateRepresentation(isAdd, action.change, action.object_id, action.representation, nglView));
}
};

const changeRepresentation = (isAdd, change, parentKey, representation, nglView) => (dispatch, getState) => {
const updateRepresentation = (isAdd, change, parentKey, representation, nglView) => (dispatch, getState) => {
const comp = nglView.stage.getComponentsByName(parentKey).first;
const r = comp.reprList.find(rep => rep.uuid === representation.uuid || rep.uuid === representation.lastKnownID);
if (r && change) {
Expand All @@ -1622,25 +1637,50 @@ const changeRepresentation = (isAdd, change, parentKey, representation, nglView)
}
};

const removeRepresentation = (parentKey, representation, nglView) => (dispatch, getState) => {
const removeRepresentation = (action, parentKey, representation, nglView, skipTracking = false) => (
dispatch,
getState
) => {
const comp = nglView.stage.getComponentsByName(parentKey).first;
let foundedRepresentation = undefined;
comp.eachRepresentation(r => {
if (r.uuid === representation.uuid || r.uuid === representation.lastKnownID) {
foundedRepresentation = r;
}
});

if (foundedRepresentation) {
comp.removeRepresentation(foundedRepresentation);

if (comp.reprList.length === 0) {
dispatch(deleteObject(nglView, nglView.stage, true));
} else {
dispatch(removeComponentRepresentation(parentKey, representation));
dispatch(removeComponentRepresentation(parentKey, representation, skipTracking));
}
}
};

const handleChangeRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
if (action) {
dispatch(changeRepresentation(isAdd, action, nglView));
}
};

const changeRepresentation = (isAdd, action, nglView) => (dispatch, getState) => {
let oldRepresentation = action.oldRepresentation;
let newRepresentation = action.newRepresentation;

if (isAdd === true) {
dispatch(changeComponentRepresentation(action.object_id, oldRepresentation, newRepresentation));
dispatch(addRepresentation(action, action.object_id, newRepresentation, nglView, isAdd, true));
dispatch(removeRepresentation(action, action.object_id, oldRepresentation, nglView, true));
} else {
dispatch(changeComponentRepresentation(action.object_id, newRepresentation, oldRepresentation));
dispatch(addRepresentation(action, action.object_id, oldRepresentation, nglView, isAdd, true));
dispatch(removeRepresentation(action, action.object_id, newRepresentation, nglView, true));
}
};

const handleMoleculeGroupAction = (action, isSelected, stageSummaryView, majorViewStage) => (dispatch, getState) => {
const state = getState();
if (action) {
Expand Down
21 changes: 19 additions & 2 deletions js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ export const findTrackAction = (action, state) => {
let objectType = actionObjectType.REPRESENTATION;

trackAction = {
type: actionType.REPRESENTATION_CHANGED,
type: actionType.REPRESENTATION_UPDATED,
annotation: actionAnnotation.CHECK,
timestamp: Date.now(),
username: username,
Expand All @@ -681,7 +681,7 @@ export const findTrackAction = (action, state) => {
representation_id: action.representationID,
representation: action.newRepresentation,
change: action.change,
text: `${objectType} '${action.change?.key}' of ${action.objectInViewID} ${actionDescription.CHANGED} from value: ${action.change?.oldValue} to value: ${action.change?.value}`
text: `${objectType} '${action.change?.key}' of ${action.objectInViewID} ${actionDescription.UPDATED} from value: ${action.change?.oldValue} to value: ${action.change?.value}`
};
} else if (action.type.includes(nglConstants.ADD_COMPONENT_REPRESENTATION)) {
let objectType = actionObjectType.REPRESENTATION;
Expand Down Expand Up @@ -713,6 +713,23 @@ export const findTrackAction = (action, state) => {
representation: action.representation,
text: `${objectType} '${representationName}' of ${action.objectInViewID} ${actionDescription.REMOVED}`
};
} else if (action.type.includes(nglConstants.CHANGE_COMPONENT_REPRESENTATION)) {
let objectType = actionObjectType.REPRESENTATION;
let oldRepresentationName = action.oldRepresentation && action.oldRepresentation.type;
let newRepresentationName = action.newRepresentation && action.newRepresentation.type;

trackAction = {
type: actionType.REPRESENTATION_CHANGED,
annotation: actionAnnotation.CHECK,
timestamp: Date.now(),
username: username,
object_type: objectType,
object_name: action.objectInViewID,
object_id: action.objectInViewID,
oldRepresentation: action.oldRepresentation,
newRepresentation: action.newRepresentation,
text: `${objectType} of ${action.objectInViewID} ${actionDescription.CHANGED} from value: ${oldRepresentationName} to value: ${newRepresentationName}`
};
}
}
return trackAction;
Expand Down

0 comments on commit 2fe8723

Please sign in to comment.