Added max iterations update to state for loop

This commit is contained in:
Emir Karabeg
2025-02-11 21:49:41 -08:00
parent ddfa86641b
commit 06a360b2c8
2 changed files with 25 additions and 0 deletions

View File

@@ -114,6 +114,7 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
},
}
})
get().updateLastSaved()
},
addBlock: (id: string, type: string, name: string, position: Position) => {
@@ -229,6 +230,7 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
newLoops[loopId] = {
id: loopId,
nodes: path,
maxIterations: 5,
}
processedPaths.add(canonicalPath)
}
@@ -265,6 +267,7 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
newLoops[loopId] = {
id: loopId,
nodes: path,
maxIterations: 5,
}
processedPaths.add(canonicalPath)
}
@@ -414,6 +417,7 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
edges: [...state.edges],
loops: { ...get().loops },
}))
get().updateLastSaved()
},
updateBlockHeight: (id: string, height: number) => {
@@ -427,6 +431,25 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
},
edges: [...state.edges],
}))
get().updateLastSaved()
},
updateLoopMaxIterations: (loopId: string, maxIterations: number) => {
const newState = {
blocks: { ...get().blocks },
edges: [...get().edges],
loops: {
...get().loops,
[loopId]: {
...get().loops[loopId],
maxIterations: Math.max(1, Math.min(50, maxIterations)), // Clamp between 1-50
},
},
}
set(newState)
pushHistory(set, get, newState, 'Update loop max iterations')
get().updateLastSaved()
},
})),
{ name: 'workflow-store' }

View File

@@ -28,6 +28,7 @@ export interface SubBlockState {
export interface Loop {
id: string
nodes: string[]
maxIterations: number
}
export interface WorkflowState {
@@ -52,6 +53,7 @@ export interface WorkflowActions {
updateBlockName: (id: string, name: string) => void
toggleBlockWide: (id: string) => void
updateBlockHeight: (id: string, height: number) => void
updateLoopMaxIterations: (loopId: string, maxIterations: number) => void
}
export type WorkflowStore = WorkflowState & WorkflowActions