diff --git a/src/component/TabBar.jsx b/src/component/TabBar.jsx index f8382e6..6ce73f1 100644 --- a/src/component/TabBar.jsx +++ b/src/component/TabBar.jsx @@ -18,6 +18,7 @@ const TabBar = ({ superState, dispatcher }) => { dispatcher({ type: T.REMOVE_GRAPH, payload: i }); if (!superState.curGraphIndex && superState.graphs.length === 1) { dispatcher({ type: T.SET_CUR_INSTANCE, payload: null }); + dispatcher({ type: T.SET_CUR_INDEX, payload: -1 }); } }; const editCur = (e) => { diff --git a/src/graph-builder/graph-core/6-server.js b/src/graph-builder/graph-core/6-server.js index 2dd3f1e..0201162 100644 --- a/src/graph-builder/graph-core/6-server.js +++ b/src/graph-builder/graph-core/6-server.js @@ -72,6 +72,12 @@ class GraphServer extends GraphLoadSave { 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}¶ms=${this.superState.params}&octave=${this.superState.octave}`) .then((res) => { // eslint-disable-next-line toast.success(res.data['message']) + this.dispatcher({ + type: T.SET_FUNCTIONS, + payload: { + built: false, ran: false, debugged: true, cleared: false, stopped: false, destroyed: true, + }, + }); this.dispatcher({ type: T.SET_LOADER, payload: false }); }).catch((err) => { // eslint-disable-next-line toast.error(err.message); @@ -86,6 +92,12 @@ class GraphServer extends GraphLoadSave { Axios.post(`http://127.0.0.1:5000/debug/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`) .then((res) => { // eslint-disable-next-line toast.success(res.data['message']) + this.dispatcher({ + type: T.SET_FUNCTIONS, + payload: { + built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true, + }, + }); this.dispatcher({ type: T.SET_LOADER, payload: false }); }).catch((err) => { // eslint-disable-next-line toast.error(err.message); @@ -100,6 +112,12 @@ class GraphServer extends GraphLoadSave { Axios.post(`http://127.0.0.1:5000/run/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`) .then((res) => { // eslint-disable-next-line toast.success(res.data['message']) + this.dispatcher({ + type: T.SET_FUNCTIONS, + payload: { + built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true, + }, + }); this.dispatcher({ type: T.SET_LOADER, payload: false }); }).catch((err) => { // eslint-disable-next-line toast.error(err.message); @@ -115,6 +133,12 @@ class GraphServer extends GraphLoadSave { ?unlock=${this.superState.unlockCheck}&maxtime=${this.superState.maxTime}¶ms=${this.superState.params}`) .then((res) => { // eslint-disable-next-line toast.success(res.data['message']); + this.dispatcher({ + type: T.SET_FUNCTIONS, + payload: { + built: false, ran: true, debugged: true, cleared: false, stopped: true, destroyed: true, + }, + }); this.dispatcher({ type: T.SET_LOADER, payload: false }); }).catch((err) => { // eslint-disable-next-line toast.error(err.message); @@ -129,6 +153,12 @@ class GraphServer extends GraphLoadSave { Axios.post(`http://127.0.0.1:5000/stop/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`) .then((res) => { // eslint-disable-next-line toast.success(res.data['message']) + this.dispatcher({ + type: T.SET_FUNCTIONS, + payload: { + built: false, ran: false, debugged: false, cleared: true, stopped: false, destroyed: true, + }, + }); this.dispatcher({ type: T.SET_LOADER, payload: false }); }).catch((err) => { // eslint-disable-next-line toast.error(err.message); @@ -143,6 +173,12 @@ class GraphServer extends GraphLoadSave { Axios.delete(`http://127.0.0.1:5000/destroy/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`) .then((res) => { // eslint-disable-next-line toast.success(res.data['message']) + this.dispatcher({ + type: T.SET_FUNCTIONS, + payload: { + built: true, ran: false, debugged: false, cleared: false, stopped: false, destroyed: false, + }, + }); this.dispatcher({ type: T.SET_LOADER, payload: false }); }).catch((err) => { // eslint-disable-next-line toast.error(err.message); diff --git a/src/reducer/actionType.js b/src/reducer/actionType.js index 017a512..56ba940 100644 --- a/src/reducer/actionType.js +++ b/src/reducer/actionType.js @@ -29,6 +29,7 @@ const actionType = { SET_AUTHOR: 'SET_AUTHOR', IS_WORKFLOW_ON_SERVER: 'IS_WORKFLOW_ON_SERVER', SET_CUR_INSTANCE: 'SET_CUR_INSTANCE', + SET_CUR_INDEX: 'SET_CUR_INDEX', SET_ZOOM_LEVEL: 'SET_ZOOM_LEVEL', SET_EDIT_DETAILS_MODAL: 'SET_EDIT_DETAILS_MODAL', SET_NEW_GRAPH_MODAL: 'SET_NEW_GRAPH_MODAL', @@ -40,6 +41,7 @@ const actionType = { SET_INPUT_FILE: 'SET_INPUT_FILE', SET_OPTIONS: 'SET_OPTIONS', SET_LOADER: 'SET_LOADER', + SET_FUNCTIONS: 'SET_FUNCTIONS', }; export default zealit(actionType); diff --git a/src/reducer/initialState.js b/src/reducer/initialState.js index bce5a06..5768401 100644 --- a/src/reducer/initialState.js +++ b/src/reducer/initialState.js @@ -20,7 +20,7 @@ const initialState = { undoEnabled: false, redoEnabled: false, graphs: [], - curGraphIndex: 0, + curGraphIndex: -1, viewHistory: false, isWorkflowOnServer: false, curGraphInstance: null, @@ -48,6 +48,12 @@ const initialGraphState = { id: null, fileHandle: null, fileName: null, + built: true, + debugged: false, + ran: false, + destroyed: false, + cleared: false, + stopped: false, }; export { initialState, initialGraphState }; diff --git a/src/reducer/reducer.js b/src/reducer/reducer.js index 9bdbc23..1afdb7f 100644 --- a/src/reducer/reducer.js +++ b/src/reducer/reducer.js @@ -110,6 +110,9 @@ const reducer = (state, action) => { case T.SET_CUR_INSTANCE: { return { ...state, curGraphInstance: action.payload }; } + case T.SET_CUR_INDEX: { + return { ...state, curGraphIndex: action.payload }; + } case T.CHANGE_TAB: return { ...state, curGraphIndex: action.payload }; case T.NEW_GRAPH: return { ...state, newGraphModal: true }; @@ -223,6 +226,17 @@ const reducer = (state, action) => { return { ...state, uploadedDirName: action.payload }; } + case T.SET_FUNCTIONS: { + const newState = { ...state }; + newState.graphs[state.curGraphIndex].built = action.payload.built; + newState.graphs[state.curGraphIndex].debugged = action.payload.debugged; + newState.graphs[state.curGraphIndex].ran = action.payload.ran; + newState.graphs[state.curGraphIndex].cleared = action.payload.cleared; + newState.graphs[state.curGraphIndex].destroyed = action.payload.destroyed; + newState.graphs[state.curGraphIndex].stopped = action.payload.stopped; + return { ...newState }; + } + default: return state; } diff --git a/src/toolbarActions/toolbarList.js b/src/toolbarActions/toolbarList.js index e7ed160..b041d45 100644 --- a/src/toolbarActions/toolbarList.js +++ b/src/toolbarActions/toolbarList.js @@ -132,7 +132,7 @@ const toolbarList = (state, dispatcher) => [ text: 'Server', icon: state.isWorkflowOnServer ? FaToggleOn : FiToggleLeft, action: () => toggleServer(state, dispatcher), - active: true, + active: state.curGraphInstance, visibility: true, }, { @@ -141,55 +141,67 @@ const toolbarList = (state, dispatcher) => [ icon: FaCogs, action: () => optionModalToggle(state, dispatcher), active: state.isWorkflowOnServer, - visibility: state.isWorkflowOnServer, + visibility: state.isWorkflowOnServer && state.curGraphInstance, }, { type: 'action', text: 'Build', icon: FaHammer, action: () => state.curGraphInstance && state.curGraphInstance.build(), - active: state.isWorkflowOnServer, - visibility: state.isWorkflowOnServer, + active: state.curGraphIndex !== -1 + ? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].built + : state.isWorkflowOnServer, + visibility: state.isWorkflowOnServer && state.curGraphInstance, }, { type: 'action', text: 'Debug', icon: FaBug, action: () => state.curGraphInstance && state.curGraphInstance.debug(), - active: state.isWorkflowOnServer, - visibility: state.isWorkflowOnServer, + active: state.curGraphIndex !== -1 + ? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].debugged + : state.isWorkflowOnServer, + visibility: state.isWorkflowOnServer && state.curGraphInstance, }, { type: 'action', text: 'Run', icon: FiPlay, action: () => state.curGraphInstance && state.curGraphInstance.run(), - active: state.isWorkflowOnServer, - visibility: state.isWorkflowOnServer, + active: state.curGraphIndex !== -1 + ? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].ran + : state.isWorkflowOnServer, + visibility: state.isWorkflowOnServer && state.curGraphInstance, }, { type: 'action', text: 'Clear', icon: FaRegTimesCircle, action: () => state.curGraphInstance && state.curGraphInstance.clear(), - active: state.isWorkflowOnServer, - visibility: state.isWorkflowOnServer, + active: state.curGraphIndex !== -1 + ? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].cleared + : state.isWorkflowOnServer, + visibility: state.isWorkflowOnServer && state.curGraphInstance, }, { type: 'action', text: 'Stop', icon: FiStopCircle, action: () => state.curGraphInstance && state.curGraphInstance.stop(), - active: state.isWorkflowOnServer, - visibility: state.isWorkflowOnServer, + active: state.curGraphIndex !== -1 + ? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].stopped + : state.isWorkflowOnServer, + visibility: state.isWorkflowOnServer && state.curGraphInstance, }, { type: 'action', text: 'Destroy', icon: FaBomb, action: () => state.curGraphInstance && state.curGraphInstance.destroy(), - active: state.isWorkflowOnServer, - visibility: state.isWorkflowOnServer, + active: state.curGraphIndex !== -1 + ? state.isWorkflowOnServer && state.graphs[state.curGraphIndex].destroyed + : state.isWorkflowOnServer, + visibility: state.isWorkflowOnServer && state.curGraphInstance, }, // Not being implemented in version 1