Skip to content

Commit 6469799

Browse files
author
Adriána Kohanová
committed
#453 Undo/Redo Actions
1 parent 78156fc commit 6469799

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

js/components/preview/viewerControls/displayControls/editRepresentationMenu.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ export const EditRepresentationMenu = memo(
4040
const handleRepresentationPropertyChange = throttle((key, value) => {
4141
const r = comp.reprList.find(rep => rep.uuid === representation.uuid || rep.uuid === representation.lastKnownID);
4242
if (r) {
43+
let oldValue = oldRepresentation.params[key];
44+
let change = { key, value, oldValue };
45+
4346
// update in ngl
4447
r.setParameters({ [key]: value });
4548
//update in redux
4649
oldRepresentation.params[key] = value;
47-
dispatch(updateComponentRepresentation(parentKey, oldRepresentation.uuid, oldRepresentation));
50+
51+
dispatch(updateComponentRepresentation(parentKey, oldRepresentation.uuid, oldRepresentation, change));
4852
}
4953
}, 250);
5054

js/reducers/ngl/actions.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ export const deleteNglObject = target => ({
1010
target
1111
});
1212

13-
export const updateComponentRepresentation = (objectInViewID, representationID, newRepresentation) => ({
13+
export const updateComponentRepresentation = (objectInViewID, representationID, newRepresentation, change) => ({
1414
type: CONSTANTS.UPDATE_COMPONENT_REPRESENTATION,
1515
representationID,
1616
newRepresentation,
17-
objectInViewID
17+
objectInViewID,
18+
change
1819
});
1920

2021
export const addComponentRepresentation = (objectInViewID, newRepresentation) => ({

js/reducers/tracking/dispatchActions.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {
603603
dispatch(handleCompoundAction(action, true));
604604
break;
605605
case actionType.REPRESENTATION_CHANGED:
606+
dispatch(handleChangeRepresentationAction(action, false, majorView));
606607
break;
607608
case actionType.REPRESENTATION_ADDED:
608609
dispatch(handleRepresentationAction(action, false, majorView));
@@ -685,6 +686,7 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {
685686
dispatch(handleCompoundAction(action, false));
686687
break;
687688
case actionType.REPRESENTATION_CHANGED:
689+
dispatch(handleChangeRepresentationAction(action, true, majorView));
688690
break;
689691
case actionType.REPRESENTATION_ADDED:
690692
dispatch(handleRepresentationAction(action, true, majorView));
@@ -728,12 +730,12 @@ const handleCompoundAction = (action, isSelected) => (dispatch, getState) => {
728730
};
729731

730732
const handleShoppingCartAction = (action, isAdd) => (dispatch, getState) => {
731-
const state = getState();
732733
if (action) {
734+
let data = action.item;
733735
if (isAdd) {
734-
//dispatch(appendToBuyList(data));
736+
dispatch(appendToBuyList(data));
735737
} else {
736-
//dispatch(removeFromToBuyList(data));
738+
dispatch(removeFromToBuyList(data));
737739
}
738740
}
739741
};
@@ -752,7 +754,6 @@ const addRepresentation = (parentKey, representation, nglView) => (dispatch, get
752754
const oldRepresentation = representation;
753755
const newRepresentationType = oldRepresentation.type;
754756
const comp = nglView.stage.getComponentsByName(parentKey).first;
755-
// add representation to NGL
756757
const newRepresentation = assignRepresentationToComp(
757758
newRepresentationType,
758759
oldRepresentation.params,
@@ -762,6 +763,26 @@ const addRepresentation = (parentKey, representation, nglView) => (dispatch, get
762763
dispatch(addComponentRepresentation(parentKey, newRepresentation));
763764
};
764765

766+
const handleChangeRepresentationAction = (action, isAdd, nglView) => (dispatch, getState) => {
767+
if (action) {
768+
dispatch(changeRepresentation(isAdd, action.change, action.object_id, action.representation, nglView));
769+
}
770+
};
771+
772+
const changeRepresentation = (isAdd, change, parentKey, representation, nglView) => (dispatch, getState) => {
773+
const comp = nglView.stage.getComponentsByName(parentKey).first;
774+
const r = comp.reprList.find(rep => rep.uuid === representation.uuid || rep.uuid === representation.lastKnownID);
775+
if (r && change) {
776+
let key = change.key;
777+
let value = isAdd ? change.value : change.oldValue;
778+
779+
r.setParameters({ [key]: value });
780+
representation.params[key] = value;
781+
782+
dispatch(updateComponentRepresentation(parentKey, representation.uuid, representation));
783+
}
784+
};
785+
765786
const removeRepresentation = (parentKey, representation, nglView) => (dispatch, getState) => {
766787
const comp = nglView.stage.getComponentsByName(parentKey).first;
767788
let foundedRepresentation = undefined;

js/reducers/tracking/trackingActions.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export const findTruckAction = (action, state) => {
248248
object_type: actionObjectType.MOLECULE,
249249
object_name: objectName,
250250
object_id: objectName,
251+
item: action.item,
251252
text: `${objectType} ${objectName} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}`
252253
};
253254
}
@@ -263,6 +264,7 @@ export const findTruckAction = (action, state) => {
263264
object_type: objectType,
264265
object_name: objectName,
265266
object_id: objectName,
267+
item: action.item,
266268
text: `${objectType} ${objectName} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}`
267269
};
268270
}
@@ -461,7 +463,8 @@ export const findTruckAction = (action, state) => {
461463
object_id: action.objectInViewID,
462464
representation_id: action.representationID,
463465
representation: action.newRepresentation,
464-
text: `${objectType} parameter of ${action.objectInViewID} ${actionDescription.CHANGED}`
466+
change: action.change,
467+
text: `${objectType} '${action.change?.key}' of ${action.objectInViewID} ${actionDescription.CHANGED} from value: ${action.change?.oldValue} to value: ${action.change?.value}`
465468
};
466469
} else if (action.type.includes(nglConstants.ADD_COMPONENT_REPRESENTATION)) {
467470
let objectType = actionObjectType.REPRESENTATION;
@@ -475,7 +478,7 @@ export const findTruckAction = (action, state) => {
475478
object_name: representationName,
476479
object_id: action.objectInViewID,
477480
representation: action.newRepresentation,
478-
text: `${objectType} ${representationName} of ${action.objectInViewID} ${actionDescription.ADDED}`
481+
text: `${objectType} '${representationName}' of ${action.objectInViewID} ${actionDescription.ADDED}`
479482
};
480483
} else if (action.type.includes(nglConstants.REMOVE_COMPONENT_REPRESENTATION)) {
481484
let objectType = actionObjectType.REPRESENTATION;
@@ -489,7 +492,7 @@ export const findTruckAction = (action, state) => {
489492
object_name: representationName,
490493
object_id: action.objectInViewID,
491494
representation: action.representation,
492-
text: `${objectType} ${representationName} of ${action.objectInViewID} ${actionDescription.REMOVED}`
495+
text: `${objectType} '${representationName}' of ${action.objectInViewID} ${actionDescription.REMOVED}`
493496
};
494497
}
495498
}

0 commit comments

Comments
 (0)