mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-06 00:36:11 +08:00
feat: rename var in inspector
This commit is contained in:
parent
0b21b74db4
commit
3ab5af39a0
@ -18,6 +18,7 @@ const useInspectVarsCrud = () => {
|
||||
nodesWithInspectVars,
|
||||
getInspectVar,
|
||||
setInspectVarValue,
|
||||
renameInspectVarName: renameInspectVarNameInStore,
|
||||
deleteAllInspectVars: deleteAllInspectVarsInStore,
|
||||
deleteNodeInspectVars: deleteNodeInspectVarsInStore,
|
||||
deleteInspectVar: deleteInspectVarInStore,
|
||||
@ -69,9 +70,13 @@ const useInspectVarsCrud = () => {
|
||||
setInspectVarValue(nodeId, varId, value)
|
||||
}
|
||||
|
||||
const editInspectVarSelector = (varId: string, selector: ValueSelector) => {
|
||||
console.log('edit var selector', varId, selector)
|
||||
// call api and update store
|
||||
const renameInspectVarName = async (nodeId: string, varId: string, selector: ValueSelector) => {
|
||||
await doEditInspectorVar({
|
||||
nodeId,
|
||||
varId,
|
||||
name: selector[1],
|
||||
})
|
||||
renameInspectVarNameInStore(nodeId, varId, selector)
|
||||
}
|
||||
|
||||
const editInspectVarValueType = (varId: string, valueType: VarType) => {
|
||||
@ -96,7 +101,7 @@ const useInspectVarsCrud = () => {
|
||||
nodesWithInspectVars,
|
||||
fetchInspectVarValue,
|
||||
editInspectVarValue,
|
||||
editInspectVarSelector,
|
||||
renameInspectVarName,
|
||||
editInspectVarValueType,
|
||||
deleteInspectVar,
|
||||
deleteNodeInspectorVars,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import type { StateCreator } from 'zustand'
|
||||
import produce from 'immer'
|
||||
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
||||
import type { ValueSelector } from '../../../types'
|
||||
|
||||
type InspectVarsState = {
|
||||
currentFocusNodeId: string | null
|
||||
@ -18,6 +19,7 @@ type InspectVarsActions = {
|
||||
getNodeInspectVars: (nodeId: string) => NodeWithVar | undefined
|
||||
hasNodeInspectVars: (nodeId: string) => boolean
|
||||
setInspectVarValue: (nodeId: string, name: string, value: any) => void
|
||||
renameInspectVarName: (nodeId: string, varId: string, selector: ValueSelector) => void
|
||||
deleteInspectVar: (nodeId: string, varId: string) => void
|
||||
getInspectVar: (nodeId: string, name: string) => any // The big value is null
|
||||
}
|
||||
@ -94,6 +96,23 @@ export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set,
|
||||
state.nodesWithInspectVars = nodes
|
||||
}))
|
||||
},
|
||||
renameInspectVarName: (nodeId, varId, selector) => {
|
||||
set(produce((state: InspectVarsSliceShape) => {
|
||||
const nodes = state.nodesWithInspectVars.map((node) => {
|
||||
if (node.nodeId === nodeId) {
|
||||
return produce(node, (draft) => {
|
||||
const needChangeVarIndex = draft.vars.findIndex((varItem) => {
|
||||
return varItem.id === varId
|
||||
})
|
||||
if (needChangeVarIndex !== -1)
|
||||
draft.vars[needChangeVarIndex].selector = selector
|
||||
})
|
||||
}
|
||||
return node
|
||||
})
|
||||
state.nodesWithInspectVars = nodes
|
||||
}))
|
||||
},
|
||||
deleteInspectVar: (nodeId, varId) => {
|
||||
set(produce((state: InspectVarsSliceShape) => {
|
||||
const nodes = state.nodesWithInspectVars.map((node) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user