11import { createSlice } from "@reduxjs/toolkit" ;
22import { RE_INITIALIZE_STORE } from "../../constants/actions" ;
3+ import {
4+ ReadConfigFromLocalStorage ,
5+ WriteNewConfigToLocalStorage ,
6+ } from "../../services/utils" ;
37
48export const workflowSlice = createSlice ( {
59 name : "workflow" ,
610 initialState : {
711 currentWorkflow : undefined ,
812 currentWorkflowStepId : undefined ,
913 currentStepEllapsedTimeInSeconds : 0 ,
14+ lastWorkflowRunId :
15+ ReadConfigFromLocalStorage ( ) . workflows ?. lastWorkflowRunId ,
1016 } ,
1117 reducers : {
1218 setCurrentWorkflow : ( state , action ) => {
1319 state . currentWorkflow = action . payload ;
20+ const newLastWorkFlowRunId =
21+ action . payload ?. id || state . lastWorkflowRunId ;
22+ if ( newLastWorkFlowRunId !== state . lastWorkflowRunId ) {
23+ state . lastWorkflowRunId = newLastWorkFlowRunId ;
24+ const config = ReadConfigFromLocalStorage ( ) ;
25+ config . workflows . lastWorkflowRunId = newLastWorkFlowRunId ;
26+ WriteNewConfigToLocalStorage ( config ) ;
27+ }
1428 } ,
1529 setCurrentWorkflowStepId : ( state , action ) => {
1630 state . currentWorkflowStepId = action . payload ;
@@ -26,6 +40,8 @@ export const workflowSlice = createSlice({
2640 currentWorkflow : undefined ,
2741 currentWorkflowStepId : undefined ,
2842 currentStepEllapsedTimeInSeconds : 0 ,
43+ lastWorkflowRunId :
44+ ReadConfigFromLocalStorage ( ) . workflows ?. lastWorkflowRunId ,
2945 } ;
3046 } ) ;
3147 } ,
0 commit comments