Skip to content

Commit 24e43ed

Browse files
authored
Merge pull request #167 from Rahuljagwani/EditNode
Concore methods order implementation
2 parents 49659ce + ebc21b8 commit 24e43ed

File tree

6 files changed

+86
-15
lines changed

6 files changed

+86
-15
lines changed

src/component/TabBar.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const TabBar = ({ superState, dispatcher }) => {
1818
dispatcher({ type: T.REMOVE_GRAPH, payload: i });
1919
if (!superState.curGraphIndex && superState.graphs.length === 1) {
2020
dispatcher({ type: T.SET_CUR_INSTANCE, payload: null });
21+
dispatcher({ type: T.SET_CUR_INDEX, payload: -1 });
2122
}
2223
};
2324
const editCur = (e) => {

src/graph-builder/graph-core/6-server.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ class GraphServer extends GraphLoadSave {
7272
Axios.post(`http://127.0.0.1:5000/build/${this.superState.uploadedDirName}?fetch=${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}&unlock=${this.superState.unlockCheck}&docker=${this.superState.dockerCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}&octave=${this.superState.octave}`)
7373
.then((res) => { // eslint-disable-next-line
7474
toast.success(res.data['message'])
75+
this.dispatcher({
76+
type: T.SET_FUNCTIONS,
77+
payload: {
78+
built: false, ran: false, debugged: true, cleared: false, stopped: false, destroyed: true,
79+
},
80+
});
7581
this.dispatcher({ type: T.SET_LOADER, payload: false });
7682
}).catch((err) => { // eslint-disable-next-line
7783
toast.error(err.message);
@@ -86,6 +92,12 @@ class GraphServer extends GraphLoadSave {
8692
Axios.post(`http://127.0.0.1:5000/debug/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
8793
.then((res) => { // eslint-disable-next-line
8894
toast.success(res.data['message'])
95+
this.dispatcher({
96+
type: T.SET_FUNCTIONS,
97+
payload: {
98+
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
99+
},
100+
});
89101
this.dispatcher({ type: T.SET_LOADER, payload: false });
90102
}).catch((err) => { // eslint-disable-next-line
91103
toast.error(err.message);
@@ -100,6 +112,12 @@ class GraphServer extends GraphLoadSave {
100112
Axios.post(`http://127.0.0.1:5000/run/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
101113
.then((res) => { // eslint-disable-next-line
102114
toast.success(res.data['message'])
115+
this.dispatcher({
116+
type: T.SET_FUNCTIONS,
117+
payload: {
118+
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
119+
},
120+
});
103121
this.dispatcher({ type: T.SET_LOADER, payload: false });
104122
}).catch((err) => { // eslint-disable-next-line
105123
toast.error(err.message);
@@ -115,6 +133,12 @@ class GraphServer extends GraphLoadSave {
115133
?unlock=${this.superState.unlockCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}`)
116134
.then((res) => { // eslint-disable-next-line
117135
toast.success(res.data['message']);
136+
this.dispatcher({
137+
type: T.SET_FUNCTIONS,
138+
payload: {
139+
built: false, ran: true, debugged: true, cleared: false, stopped: true, destroyed: true,
140+
},
141+
});
118142
this.dispatcher({ type: T.SET_LOADER, payload: false });
119143
}).catch((err) => { // eslint-disable-next-line
120144
toast.error(err.message);
@@ -129,6 +153,12 @@ class GraphServer extends GraphLoadSave {
129153
Axios.post(`http://127.0.0.1:5000/stop/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
130154
.then((res) => { // eslint-disable-next-line
131155
toast.success(res.data['message'])
156+
this.dispatcher({
157+
type: T.SET_FUNCTIONS,
158+
payload: {
159+
built: false, ran: false, debugged: false, cleared: true, stopped: false, destroyed: true,
160+
},
161+
});
132162
this.dispatcher({ type: T.SET_LOADER, payload: false });
133163
}).catch((err) => { // eslint-disable-next-line
134164
toast.error(err.message);
@@ -143,6 +173,12 @@ class GraphServer extends GraphLoadSave {
143173
Axios.delete(`http://127.0.0.1:5000/destroy/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
144174
.then((res) => { // eslint-disable-next-line
145175
toast.success(res.data['message'])
176+
this.dispatcher({
177+
type: T.SET_FUNCTIONS,
178+
payload: {
179+
built: true, ran: false, debugged: false, cleared: false, stopped: false, destroyed: false,
180+
},
181+
});
146182
this.dispatcher({ type: T.SET_LOADER, payload: false });
147183
}).catch((err) => { // eslint-disable-next-line
148184
toast.error(err.message);

src/reducer/actionType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const actionType = {
2929
SET_AUTHOR: 'SET_AUTHOR',
3030
IS_WORKFLOW_ON_SERVER: 'IS_WORKFLOW_ON_SERVER',
3131
SET_CUR_INSTANCE: 'SET_CUR_INSTANCE',
32+
SET_CUR_INDEX: 'SET_CUR_INDEX',
3233
SET_ZOOM_LEVEL: 'SET_ZOOM_LEVEL',
3334
SET_EDIT_DETAILS_MODAL: 'SET_EDIT_DETAILS_MODAL',
3435
SET_NEW_GRAPH_MODAL: 'SET_NEW_GRAPH_MODAL',
@@ -40,6 +41,7 @@ const actionType = {
4041
SET_INPUT_FILE: 'SET_INPUT_FILE',
4142
SET_OPTIONS: 'SET_OPTIONS',
4243
SET_LOADER: 'SET_LOADER',
44+
SET_FUNCTIONS: 'SET_FUNCTIONS',
4345
};
4446

4547
export default zealit(actionType);

src/reducer/initialState.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const initialState = {
2020
undoEnabled: false,
2121
redoEnabled: false,
2222
graphs: [],
23-
curGraphIndex: 0,
23+
curGraphIndex: -1,
2424
viewHistory: false,
2525
isWorkflowOnServer: false,
2626
curGraphInstance: null,
@@ -48,6 +48,12 @@ const initialGraphState = {
4848
id: null,
4949
fileHandle: null,
5050
fileName: null,
51+
built: true,
52+
debugged: false,
53+
ran: false,
54+
destroyed: false,
55+
cleared: false,
56+
stopped: false,
5157
};
5258

5359
export { initialState, initialGraphState };

src/reducer/reducer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ const reducer = (state, action) => {
110110
case T.SET_CUR_INSTANCE: {
111111
return { ...state, curGraphInstance: action.payload };
112112
}
113+
case T.SET_CUR_INDEX: {
114+
return { ...state, curGraphIndex: action.payload };
115+
}
113116
case T.CHANGE_TAB: return { ...state, curGraphIndex: action.payload };
114117

115118
case T.NEW_GRAPH: return { ...state, newGraphModal: true };
@@ -223,6 +226,17 @@ const reducer = (state, action) => {
223226
return { ...state, uploadedDirName: action.payload };
224227
}
225228

229+
case T.SET_FUNCTIONS: {
230+
const newState = { ...state };
231+
newState.graphs[state.curGraphIndex].built = action.payload.built;
232+
newState.graphs[state.curGraphIndex].debugged = action.payload.debugged;
233+
newState.graphs[state.curGraphIndex].ran = action.payload.ran;
234+
newState.graphs[state.curGraphIndex].cleared = action.payload.cleared;
235+
newState.graphs[state.curGraphIndex].destroyed = action.payload.destroyed;
236+
newState.graphs[state.curGraphIndex].stopped = action.payload.stopped;
237+
return { ...newState };
238+
}
239+
226240
default:
227241
return state;
228242
}

src/toolbarActions/toolbarList.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const toolbarList = (state, dispatcher) => [
132132
text: 'Server',
133133
icon: state.isWorkflowOnServer ? FaToggleOn : FiToggleLeft,
134134
action: () => toggleServer(state, dispatcher),
135-
active: true,
135+
active: state.curGraphInstance,
136136
visibility: true,
137137
},
138138
{
@@ -141,55 +141,67 @@ const toolbarList = (state, dispatcher) => [
141141
icon: FaCogs,
142142
action: () => optionModalToggle(state, dispatcher),
143143
active: state.isWorkflowOnServer,
144-
visibility: state.isWorkflowOnServer,
144+
visibility: state.isWorkflowOnServer && state.curGraphInstance,
145145
},
146146
{
147147
type: 'action',
148148
text: 'Build',
149149
icon: FaHammer,
150150
action: () => state.curGraphInstance && state.curGraphInstance.build(),
151-
active: state.isWorkflowOnServer,
152-
visibility: state.isWorkflowOnServer,
151+
active: state.curGraphIndex !== -1
152+
? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].built
153+
: state.isWorkflowOnServer,
154+
visibility: state.isWorkflowOnServer && state.curGraphInstance,
153155
},
154156
{
155157
type: 'action',
156158
text: 'Debug',
157159
icon: FaBug,
158160
action: () => state.curGraphInstance && state.curGraphInstance.debug(),
159-
active: state.isWorkflowOnServer,
160-
visibility: state.isWorkflowOnServer,
161+
active: state.curGraphIndex !== -1
162+
? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].debugged
163+
: state.isWorkflowOnServer,
164+
visibility: state.isWorkflowOnServer && state.curGraphInstance,
161165
},
162166
{
163167
type: 'action',
164168
text: 'Run',
165169
icon: FiPlay,
166170
action: () => state.curGraphInstance && state.curGraphInstance.run(),
167-
active: state.isWorkflowOnServer,
168-
visibility: state.isWorkflowOnServer,
171+
active: state.curGraphIndex !== -1
172+
? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].ran
173+
: state.isWorkflowOnServer,
174+
visibility: state.isWorkflowOnServer && state.curGraphInstance,
169175
},
170176
{
171177
type: 'action',
172178
text: 'Clear',
173179
icon: FaRegTimesCircle,
174180
action: () => state.curGraphInstance && state.curGraphInstance.clear(),
175-
active: state.isWorkflowOnServer,
176-
visibility: state.isWorkflowOnServer,
181+
active: state.curGraphIndex !== -1
182+
? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].cleared
183+
: state.isWorkflowOnServer,
184+
visibility: state.isWorkflowOnServer && state.curGraphInstance,
177185
},
178186
{
179187
type: 'action',
180188
text: 'Stop',
181189
icon: FiStopCircle,
182190
action: () => state.curGraphInstance && state.curGraphInstance.stop(),
183-
active: state.isWorkflowOnServer,
184-
visibility: state.isWorkflowOnServer,
191+
active: state.curGraphIndex !== -1
192+
? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].stopped
193+
: state.isWorkflowOnServer,
194+
visibility: state.isWorkflowOnServer && state.curGraphInstance,
185195
},
186196
{
187197
type: 'action',
188198
text: 'Destroy',
189199
icon: FaBomb,
190200
action: () => state.curGraphInstance && state.curGraphInstance.destroy(),
191-
active: state.isWorkflowOnServer,
192-
visibility: state.isWorkflowOnServer,
201+
active: state.curGraphIndex !== -1
202+
? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].destroyed
203+
: state.isWorkflowOnServer,
204+
visibility: state.isWorkflowOnServer && state.curGraphInstance,
193205
},
194206

195207
// Not being implemented in version 1

0 commit comments

Comments
 (0)