Skip to content

Commit 30503ad

Browse files
authored
Merge pull request #154 from Rahuljagwani/main
issue #153 resolved
2 parents abad339 + 51ab6de commit 30503ad

7 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/graph-builder/graph-core/2-canvas.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class GraphCanvas extends Core {
3232
// eslint-disable-next-line no-alert
3333
if (!window.confirm('Do want to clear all elements?')) return false;
3434
this.cy.elements().forEach((el) => this.deleteElem(el.id(), 0));
35-
this.actionArr = [];
35+
// this.actionArr = [];
36+
this.dispatcher({ type: T.CHANGE_RESET, payload: true });
3637
this.cy.emit('graph-modified');
3738
return true;
3839
}

src/graph-builder/graph-core/4-undo-redo.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ class GraphUndoRedo extends GraphComponent {
138138
this.informUI();
139139
}
140140

141+
resetAfterClear() {
142+
const limit = this.curActionIndex;
143+
this.curActionIndex = 0;
144+
while (this.curActionIndex !== this.actionArr.length && this.curActionIndex !== limit) {
145+
this.performAction(this.actionArr[this.curActionIndex].equivalent);
146+
this.curActionIndex += 1;
147+
}
148+
this.informUI();
149+
this.dispatcher({ type: T.CHANGE_RESET, payload: false });
150+
return true;
151+
}
152+
141153
setCurStatus() {
142154
super.setCurStatus();
143155
this.informUI();

src/reducer/actionType.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const actionType = {
1818
ADD_GRAPH: 'ADD_GRAPH',
1919
ADD_GRAPH_BULK: 'ADD_GRAPH_BULK',
2020
CHANGE_TAB: 'CHANGE_TAB',
21+
CHANGE_RESET: 'CHANGE_RESET',
2122
REMOVE_GRAPH: 'REMOVE_GRAPH',
2223
NEW_GRAPH: 'NEW_GRAPH',
2324
SET_SHARE_MODAL: 'SET_SHARE_MODAL',

src/reducer/initialState.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const initialState = {
2525
curGraphInstance: null,
2626
zoomLevel: 100,
2727
uploadedDirName: null,
28+
resetEnabled: false,
2829
};
2930

3031
const initialGraphState = {

src/reducer/reducer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ const reducer = (state, action) => {
173173
case T.SET_NEW_GRAPH_MODAL: {
174174
return { ...state, newGraphModal: action.payload };
175175
}
176+
case T.CHANGE_RESET: {
177+
return { ...state, resetEnabled: action.payload };
178+
}
176179

177180
case T.EDIT_TEXTFILE: {
178181
return {

src/toolbarActions/toolbarFunctions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ const clearAll = (state) => {
145145
getGraphFun(state).clearAll();
146146
};
147147

148+
const resetAfterClear = (state) => {
149+
getGraphFun(state).resetAfterClear();
150+
};
151+
148152
const editDetails = (state, setState) => {
149153
setState({
150154
type: T.SET_EDIT_DETAILS_MODAL,
@@ -182,6 +186,6 @@ const toggleServer = (state, dispatcher) => {
182186
export {
183187
createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile,
184188
createFile, readFile, readTextFile, newProject, clearAll, editDetails, undo, redo,
185-
openShareModal, openSettingModal, viewHistory,
189+
openShareModal, openSettingModal, viewHistory, resetAfterClear,
186190
toggleServer,
187191
};

src/toolbarActions/toolbarList.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-alert */
22
import {
33
FaSave, FaUndo, FaRedo, FaTrash, FaFileImport, FaPlus, FaDownload, FaEdit, FaRegTimesCircle, FaHistory,
4-
FaHammer, FaBug, FaBomb, FaToggleOn, FaThermometerEmpty,
4+
FaHammer, FaBug, FaBomb, FaToggleOn, FaThermometerEmpty, FaUndoAlt,
55
} from 'react-icons/fa';
66

77
import {
@@ -11,7 +11,7 @@ import {
1111

1212
import {
1313
createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile,
14-
createFile, readFile, clearAll, undo, redo, viewHistory,
14+
createFile, readFile, clearAll, undo, redo, viewHistory, resetAfterClear,
1515
toggleServer,
1616
// openSettingModal,
1717
} from './toolbarFunctions';
@@ -65,17 +65,26 @@ const toolbarList = (state, dispatcher) => [
6565
text: 'Empty',
6666
icon: FaThermometerEmpty,
6767
action: clearAll,
68-
active: state.curGraphInstance,
68+
active: state.curGraphInstance && !state.resetEnabled,
6969
visibility: true,
7070
hotkey: 'Ctrl+Backspace',
7171
},
72+
{
73+
type: 'action',
74+
text: 'Reset',
75+
icon: FaUndoAlt,
76+
action: resetAfterClear,
77+
active: state.curGraphInstance && state.resetEnabled,
78+
visibility: true,
79+
hotkey: 'Ctrl+I',
80+
},
7281
{ type: 'vsep' },
7382
{
7483
type: 'action',
7584
text: 'Undo',
7685
icon: FaUndo,
7786
action: undo,
78-
active: state.undoEnabled && state.curGraphInstance,
87+
active: state.undoEnabled && state.curGraphInstance && !state.resetEnabled,
7988
visibility: true,
8089
hotkey: 'Ctrl+Z',
8190
},
@@ -84,7 +93,7 @@ const toolbarList = (state, dispatcher) => [
8493
text: 'Redo',
8594
icon: FaRedo,
8695
action: redo,
87-
active: state.redoEnabled && state.curGraphInstance,
96+
active: state.redoEnabled && state.curGraphInstance && !state.resetEnabled,
8897
visibility: true,
8998
hotkey: 'Ctrl+Shift+Z,Ctrl+Y',
9099
},

0 commit comments

Comments
 (0)