Chore/slice workflow (#18351)
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { useContext } from 'react'
|
||||
import type {
|
||||
StateCreator,
|
||||
} from 'zustand'
|
||||
import {
|
||||
useStore as useZustandStore,
|
||||
} from 'zustand'
|
||||
@@ -26,6 +29,7 @@ import { createWorkflowDraftSlice } from './workflow-draft-slice'
|
||||
import type { WorkflowSliceShape } from './workflow-slice'
|
||||
import { createWorkflowSlice } from './workflow-slice'
|
||||
import { WorkflowContext } from '@/app/components/workflow/context'
|
||||
import type { WorkflowSliceShape as WorkflowAppSliceShape } from '@/app/components/workflow-app/store/workflow/workflow-slice'
|
||||
|
||||
export type Shape =
|
||||
ChatVariableSliceShape &
|
||||
@@ -38,9 +42,16 @@ export type Shape =
|
||||
ToolSliceShape &
|
||||
VersionSliceShape &
|
||||
WorkflowDraftSliceShape &
|
||||
WorkflowSliceShape
|
||||
WorkflowSliceShape &
|
||||
WorkflowAppSliceShape
|
||||
|
||||
type CreateWorkflowStoreParams = {
|
||||
injectWorkflowStoreSliceFn?: StateCreator<WorkflowAppSliceShape>
|
||||
}
|
||||
|
||||
export const createWorkflowStore = (params: CreateWorkflowStoreParams) => {
|
||||
const { injectWorkflowStoreSliceFn } = params || {}
|
||||
|
||||
export const createWorkflowStore = () => {
|
||||
return createStore<Shape>((...args) => ({
|
||||
...createChatVariableSlice(...args),
|
||||
...createEnvVariableSlice(...args),
|
||||
@@ -53,6 +64,7 @@ export const createWorkflowStore = () => {
|
||||
...createVersionSlice(...args),
|
||||
...createWorkflowDraftSlice(...args),
|
||||
...createWorkflowSlice(...args),
|
||||
...(injectWorkflowStoreSliceFn?.(...args) || {} as WorkflowAppSliceShape),
|
||||
}))
|
||||
}
|
||||
|
||||
|
@@ -12,8 +12,6 @@ import type {
|
||||
export type NodeSliceShape = {
|
||||
showSingleRunPanel: boolean
|
||||
setShowSingleRunPanel: (showSingleRunPanel: boolean) => void
|
||||
nodesDefaultConfigs: Record<string, any>
|
||||
setNodesDefaultConfigs: (nodesDefaultConfigs: Record<string, any>) => void
|
||||
nodeAnimation: boolean
|
||||
setNodeAnimation: (nodeAnimation: boolean) => void
|
||||
candidateNode?: Node
|
||||
@@ -55,8 +53,6 @@ export type NodeSliceShape = {
|
||||
export const createNodeSlice: StateCreator<NodeSliceShape> = set => ({
|
||||
showSingleRunPanel: false,
|
||||
setShowSingleRunPanel: showSingleRunPanel => set(() => ({ showSingleRunPanel })),
|
||||
nodesDefaultConfigs: {},
|
||||
setNodesDefaultConfigs: nodesDefaultConfigs => set(() => ({ nodesDefaultConfigs })),
|
||||
nodeAnimation: false,
|
||||
setNodeAnimation: nodeAnimation => set(() => ({ nodeAnimation })),
|
||||
candidateNode: undefined,
|
||||
|
@@ -10,11 +10,8 @@ type PreviewRunningData = WorkflowRunningData & {
|
||||
}
|
||||
|
||||
export type WorkflowSliceShape = {
|
||||
appId: string
|
||||
workflowRunningData?: PreviewRunningData
|
||||
setWorkflowRunningData: (workflowData: PreviewRunningData) => void
|
||||
notInitialWorkflow: boolean
|
||||
setNotInitialWorkflow: (notInitialWorkflow: boolean) => void
|
||||
clipboardElements: Node[]
|
||||
setClipboardElements: (clipboardElements: Node[]) => void
|
||||
selection: null | { x1: number; y1: number; x2: number; y2: number }
|
||||
@@ -33,14 +30,13 @@ export type WorkflowSliceShape = {
|
||||
setShowImportDSLModal: (showImportDSLModal: boolean) => void
|
||||
showTips: string
|
||||
setShowTips: (showTips: string) => void
|
||||
workflowConfig?: Record<string, any>
|
||||
setWorkflowConfig: (workflowConfig: Record<string, any>) => void
|
||||
}
|
||||
|
||||
export const createWorkflowSlice: StateCreator<WorkflowSliceShape> = set => ({
|
||||
appId: '',
|
||||
workflowRunningData: undefined,
|
||||
setWorkflowRunningData: workflowRunningData => set(() => ({ workflowRunningData })),
|
||||
notInitialWorkflow: false,
|
||||
setNotInitialWorkflow: notInitialWorkflow => set(() => ({ notInitialWorkflow })),
|
||||
clipboardElements: [],
|
||||
setClipboardElements: clipboardElements => set(() => ({ clipboardElements })),
|
||||
selection: null,
|
||||
@@ -62,4 +58,6 @@ export const createWorkflowSlice: StateCreator<WorkflowSliceShape> = set => ({
|
||||
setShowImportDSLModal: showImportDSLModal => set(() => ({ showImportDSLModal })),
|
||||
showTips: '',
|
||||
setShowTips: showTips => set(() => ({ showTips })),
|
||||
workflowConfig: undefined,
|
||||
setWorkflowConfig: workflowConfig => set(() => ({ workflowConfig })),
|
||||
})
|
||||
|
Reference in New Issue
Block a user