Skip to content

Commit

Permalink
#481 Undo/redo break if a doing an action that's not yet captured (e.…
Browse files Browse the repository at this point in the history
…g. Vector Selector, Controls)
  • Loading branch information
Adriána Kohanová committed Jan 21, 2021
1 parent 1e0e019 commit 8d816cf
Showing 1 changed file with 64 additions and 43 deletions.
107 changes: 64 additions & 43 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ import {
} from '../../../js/reducers/ngl/actions';
import * as listType from '../../constants/listTypes';
import { assignRepresentationToComp } from '../../components/nglView/generatingObjects';
import {
deleteObject,
setOrientation,
setNglBckGrndColor,
setNglClipNear,
setNglClipFar,
setNglClipDist,
import {
deleteObject,
setOrientation,
setNglBckGrndColor,
setNglClipNear,
setNglClipFar,
setNglClipDist,
setNglFogNear,
setNglFogFar
} from '../../../js/reducers/ngl/dispatchActions';
Expand Down Expand Up @@ -1707,34 +1707,18 @@ const addRepresentation = (action, parentKey, representation, nglView, update, s
dispatch(addComponentRepresentation(parentKey, newRepresentation, skipTracking));
};

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

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) {
let key = change.key;
let value = isAdd ? change.value : change.oldValue;

r.setParameters({ [key]: value });
representation.params[key] = value;

dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation));
}
};

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) {
if (
r.uuid === representation.uuid ||
r.uuid === representation.lastKnownID ||
r.repr.type === representation.type
) {
foundedRepresentation = r;
}
});
Expand All @@ -1745,32 +1729,69 @@ const removeRepresentation = (action, parentKey, representation, nglView, skipTr
if (comp.reprList.length === 0) {
dispatch(deleteObject(nglView, nglView.stage, true));
} else {
dispatch(removeComponentRepresentation(parentKey, representation, skipTracking));
dispatch(removeComponentRepresentation(parentKey, foundedRepresentation, skipTracking));
}
} else {
console.log(`Not found representation:`, representation);
}
};

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

const changeRepresentation = (isAdd, action, nglView) => (dispatch, getState) => {
let oldRepresentation = action.oldRepresentation;
let newRepresentation = action.newRepresentation;
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) {
let key = change.key;
let value = isAdd ? change.value : change.oldValue;

r.setParameters({ [key]: value });
representation.params[key] = value;

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));
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation));
}
};

const handleChangeRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
if (action) {
let representation = action.newRepresentation;
let type = action.oldRepresentation.type;
dispatch(changeMolecularRepresentation(action, representation, type, action.object_id, nglView));
}
};

const changeMolecularRepresentation = (action, representation, type, parentKey, nglView) => (dispatch, getState) => {
const newRepresentationType = type;

//const newRepresentationType = e.target.value;
const oldRepresentation = JSON.parse(JSON.stringify(representation));
//const nglView = getNglView(objectsInView[parentKey].display_div);
const comp = nglView.stage.getComponentsByName(parentKey).first;

// add representation to NGL
const newRepresentation = assignRepresentationToComp(
newRepresentationType,
oldRepresentation.params,
comp,
oldRepresentation.lastKnownID
);

action.newRepresentation = newRepresentation;
action.oldRepresentation = representation;

// add new representation to redux
dispatch(addComponentRepresentation(parentKey, newRepresentation, true));

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

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

const handleMoleculeGroupAction = (action, isSelected, stageSummaryView, majorViewStage) => (dispatch, getState) => {
const state = getState();
if (action) {
Expand Down Expand Up @@ -1921,7 +1942,7 @@ export const mergeActions = (trackAction, list) => {
}
};

const needsToBeMerged = (trackAction) => {
const needsToBeMerged = trackAction => {
return trackAction.merge !== undefined ? trackAction.merge : false;
};

Expand Down

0 comments on commit 8d816cf

Please sign in to comment.