Skip to content

Commit 8d816cf

Browse files
author
Adriána Kohanová
committed
#481 Undo/redo break if a doing an action that's not yet captured (e.g. Vector Selector, Controls)
1 parent 1e0e019 commit 8d816cf

File tree

1 file changed

+64
-43
lines changed

1 file changed

+64
-43
lines changed

js/reducers/tracking/dispatchActions.js

+64-43
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ import {
6161
} from '../../../js/reducers/ngl/actions';
6262
import * as listType from '../../constants/listTypes';
6363
import { assignRepresentationToComp } from '../../components/nglView/generatingObjects';
64-
import {
65-
deleteObject,
66-
setOrientation,
67-
setNglBckGrndColor,
68-
setNglClipNear,
69-
setNglClipFar,
70-
setNglClipDist,
64+
import {
65+
deleteObject,
66+
setOrientation,
67+
setNglBckGrndColor,
68+
setNglClipNear,
69+
setNglClipFar,
70+
setNglClipDist,
7171
setNglFogNear,
7272
setNglFogFar
7373
} from '../../../js/reducers/ngl/dispatchActions';
@@ -1707,34 +1707,18 @@ const addRepresentation = (action, parentKey, representation, nglView, update, s
17071707
dispatch(addComponentRepresentation(parentKey, newRepresentation, skipTracking));
17081708
};
17091709

1710-
const handleUpdateRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
1711-
if (action) {
1712-
dispatch(updateRepresentation(isAdd, action.change, action.object_id, action.representation, nglView));
1713-
}
1714-
};
1715-
1716-
const updateRepresentation = (isAdd, change, parentKey, representation, nglView) => (dispatch, getState) => {
1717-
const comp = nglView.stage.getComponentsByName(parentKey).first;
1718-
const r = comp.reprList.find(rep => rep.uuid === representation.uuid || rep.uuid === representation.lastKnownID);
1719-
if (r && change) {
1720-
let key = change.key;
1721-
let value = isAdd ? change.value : change.oldValue;
1722-
1723-
r.setParameters({ [key]: value });
1724-
representation.params[key] = value;
1725-
1726-
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation));
1727-
}
1728-
};
1729-
17301710
const removeRepresentation = (action, parentKey, representation, nglView, skipTracking = false) => (
17311711
dispatch,
17321712
getState
17331713
) => {
17341714
const comp = nglView.stage.getComponentsByName(parentKey).first;
17351715
let foundedRepresentation = undefined;
17361716
comp.eachRepresentation(r => {
1737-
if (r.uuid === representation.uuid || r.uuid === representation.lastKnownID) {
1717+
if (
1718+
r.uuid === representation.uuid ||
1719+
r.uuid === representation.lastKnownID ||
1720+
r.repr.type === representation.type
1721+
) {
17381722
foundedRepresentation = r;
17391723
}
17401724
});
@@ -1745,32 +1729,69 @@ const removeRepresentation = (action, parentKey, representation, nglView, skipTr
17451729
if (comp.reprList.length === 0) {
17461730
dispatch(deleteObject(nglView, nglView.stage, true));
17471731
} else {
1748-
dispatch(removeComponentRepresentation(parentKey, representation, skipTracking));
1732+
dispatch(removeComponentRepresentation(parentKey, foundedRepresentation, skipTracking));
17491733
}
1734+
} else {
1735+
console.log(`Not found representation:`, representation);
17501736
}
17511737
};
17521738

1753-
const handleChangeRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
1739+
const handleUpdateRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
17541740
if (action) {
1755-
dispatch(changeRepresentation(isAdd, action, nglView));
1741+
dispatch(updateRepresentation(isAdd, action.change, action.object_id, action.representation, nglView));
17561742
}
17571743
};
17581744

1759-
const changeRepresentation = (isAdd, action, nglView) => (dispatch, getState) => {
1760-
let oldRepresentation = action.oldRepresentation;
1761-
let newRepresentation = action.newRepresentation;
1745+
const updateRepresentation = (isAdd, change, parentKey, representation, nglView) => (dispatch, getState) => {
1746+
const comp = nglView.stage.getComponentsByName(parentKey).first;
1747+
const r = comp.reprList.find(rep => rep.uuid === representation.uuid || rep.uuid === representation.lastKnownID);
1748+
if (r && change) {
1749+
let key = change.key;
1750+
let value = isAdd ? change.value : change.oldValue;
1751+
1752+
r.setParameters({ [key]: value });
1753+
representation.params[key] = value;
17621754

1763-
if (isAdd === true) {
1764-
dispatch(changeComponentRepresentation(action.object_id, oldRepresentation, newRepresentation));
1765-
dispatch(addRepresentation(action, action.object_id, newRepresentation, nglView, isAdd, true));
1766-
dispatch(removeRepresentation(action, action.object_id, oldRepresentation, nglView, true));
1767-
} else {
1768-
dispatch(changeComponentRepresentation(action.object_id, newRepresentation, oldRepresentation));
1769-
dispatch(addRepresentation(action, action.object_id, oldRepresentation, nglView, isAdd, true));
1770-
dispatch(removeRepresentation(action, action.object_id, newRepresentation, nglView, true));
1755+
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation));
17711756
}
17721757
};
17731758

1759+
const handleChangeRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
1760+
if (action) {
1761+
let representation = action.newRepresentation;
1762+
let type = action.oldRepresentation.type;
1763+
dispatch(changeMolecularRepresentation(action, representation, type, action.object_id, nglView));
1764+
}
1765+
};
1766+
1767+
const changeMolecularRepresentation = (action, representation, type, parentKey, nglView) => (dispatch, getState) => {
1768+
const newRepresentationType = type;
1769+
1770+
//const newRepresentationType = e.target.value;
1771+
const oldRepresentation = JSON.parse(JSON.stringify(representation));
1772+
//const nglView = getNglView(objectsInView[parentKey].display_div);
1773+
const comp = nglView.stage.getComponentsByName(parentKey).first;
1774+
1775+
// add representation to NGL
1776+
const newRepresentation = assignRepresentationToComp(
1777+
newRepresentationType,
1778+
oldRepresentation.params,
1779+
comp,
1780+
oldRepresentation.lastKnownID
1781+
);
1782+
1783+
action.newRepresentation = newRepresentation;
1784+
action.oldRepresentation = representation;
1785+
1786+
// add new representation to redux
1787+
dispatch(addComponentRepresentation(parentKey, newRepresentation, true));
1788+
1789+
// remove previous representation from NGL
1790+
dispatch(removeRepresentation(action, parentKey, representation, nglView, true));
1791+
1792+
dispatch(changeComponentRepresentation(parentKey, oldRepresentation, newRepresentation));
1793+
};
1794+
17741795
const handleMoleculeGroupAction = (action, isSelected, stageSummaryView, majorViewStage) => (dispatch, getState) => {
17751796
const state = getState();
17761797
if (action) {
@@ -1921,7 +1942,7 @@ export const mergeActions = (trackAction, list) => {
19211942
}
19221943
};
19231944

1924-
const needsToBeMerged = (trackAction) => {
1945+
const needsToBeMerged = trackAction => {
19251946
return trackAction.merge !== undefined ? trackAction.merge : false;
19261947
};
19271948

0 commit comments

Comments
 (0)