feat: edit var

pull/21369/head
Joel 1 year ago
parent 7dc24a3746
commit 0b21b74db4

@ -5,6 +5,7 @@ import {
useDeleteAllInspectorVars, useDeleteAllInspectorVars,
useDeleteInspectVar, useDeleteInspectVar,
useDeleteNodeInspectorVars, useDeleteNodeInspectorVars,
useEditInspectorVar,
useInvalidateConversationVarValues, useInvalidateConversationVarValues,
useInvalidateSysVarValues, useInvalidateSysVarValues,
useSysVarValues, useSysVarValues,
@ -16,7 +17,7 @@ const useInspectVarsCrud = () => {
appId, appId,
nodesWithInspectVars, nodesWithInspectVars,
getInspectVar, getInspectVar,
setInspectVar, setInspectVarValue,
deleteAllInspectVars: deleteAllInspectVarsInStore, deleteAllInspectVars: deleteAllInspectVarsInStore,
deleteNodeInspectVars: deleteNodeInspectVarsInStore, deleteNodeInspectVars: deleteNodeInspectVarsInStore,
deleteInspectVar: deleteInspectVarInStore, deleteInspectVar: deleteInspectVarInStore,
@ -32,6 +33,8 @@ const useInspectVarsCrud = () => {
const { mutate: doDeleteNodeInspectorVars } = useDeleteNodeInspectorVars(appId) const { mutate: doDeleteNodeInspectorVars } = useDeleteNodeInspectorVars(appId)
const { mutate: doDeleteInspectVar } = useDeleteInspectVar(appId) const { mutate: doDeleteInspectVar } = useDeleteInspectVar(appId)
const { mutate: doEditInspectorVar } = useEditInspectorVar(appId)
const fetchInspectVarValue = (selector: ValueSelector) => { const fetchInspectVarValue = (selector: ValueSelector) => {
const nodeId = selector[0] const nodeId = selector[0]
const isSystemVar = selector[1] === 'sys' const isSystemVar = selector[1] === 'sys'
@ -40,21 +43,6 @@ const useInspectVarsCrud = () => {
// fetch values under nodeId. system var and conversation var has different fetch method // fetch values under nodeId. system var and conversation var has different fetch method
} }
const editInspectVarValue = (varId: string, value: any) => {
console.log('edit var', varId, value)
// call api and update store
}
const editInspectVarSelector = (varId: string, selector: ValueSelector) => {
console.log('edit var selector', varId, selector)
// call api and update store
}
const editInspectVarValueType = (varId: string, valueType: VarType) => {
console.log('edit var value type', varId, valueType)
}
const deleteInspectVar = async (nodeId: string, varId: string) => { const deleteInspectVar = async (nodeId: string, varId: string) => {
await doDeleteInspectVar(varId) await doDeleteInspectVar(varId)
deleteInspectVarInStore(nodeId, varId) deleteInspectVarInStore(nodeId, varId)
@ -72,6 +60,24 @@ const useInspectVarsCrud = () => {
deleteAllInspectVarsInStore() deleteAllInspectVarsInStore()
} }
const editInspectVarValue = async (nodeId: string, varId: string, value: any) => {
await doEditInspectorVar({
nodeId,
varId,
value,
})
setInspectVarValue(nodeId, varId, value)
}
const editInspectVarSelector = (varId: string, selector: ValueSelector) => {
console.log('edit var selector', varId, selector)
// call api and update store
}
const editInspectVarValueType = (varId: string, valueType: VarType) => {
console.log('edit var value type', varId, valueType)
}
const isInspectVarEdited = (nodeId: string, key: string) => { const isInspectVarEdited = (nodeId: string, key: string) => {
return getInspectVar(nodeId, key) !== getLastRunVar(nodeId, key) return getInspectVar(nodeId, key) !== getLastRunVar(nodeId, key)
} }
@ -79,7 +85,7 @@ const useInspectVarsCrud = () => {
const resetToLastRunVar = (nodeId: string, key: string) => { const resetToLastRunVar = (nodeId: string, key: string) => {
const lastRunVar = getLastRunVar(nodeId, key) const lastRunVar = getLastRunVar(nodeId, key)
if (lastRunVar) if (lastRunVar)
setInspectVar(nodeId, key, lastRunVar) setInspectVarValue(nodeId, key, lastRunVar)
} }
console.log(conversationVars, systemVars) console.log(conversationVars, systemVars)

@ -17,7 +17,7 @@ type InspectVarsActions = {
deleteNodeInspectVars: (nodeId: string) => void deleteNodeInspectVars: (nodeId: string) => void
getNodeInspectVars: (nodeId: string) => NodeWithVar | undefined getNodeInspectVars: (nodeId: string) => NodeWithVar | undefined
hasNodeInspectVars: (nodeId: string) => boolean hasNodeInspectVars: (nodeId: string) => boolean
setInspectVar: (nodeId: string, name: string, value: any) => void setInspectVarValue: (nodeId: string, name: string, value: any) => void
deleteInspectVar: (nodeId: string, varId: string) => void deleteInspectVar: (nodeId: string, varId: string) => void
getInspectVar: (nodeId: string, name: string) => any // The big value is null getInspectVar: (nodeId: string, name: string) => any // The big value is null
} }
@ -77,13 +77,13 @@ export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set,
hasNodeInspectVars: (nodeId) => { hasNodeInspectVars: (nodeId) => {
return !!get().getNodeInspectVars(nodeId) return !!get().getNodeInspectVars(nodeId)
}, },
setInspectVar: (nodeId, name, value) => { setInspectVarValue: (nodeId, varId, value) => {
set(produce((state: InspectVarsSliceShape) => { set(produce((state: InspectVarsSliceShape) => {
const nodes = state.nodesWithInspectVars.map((node) => { const nodes = state.nodesWithInspectVars.map((node) => {
if (node.nodeId === nodeId) { if (node.nodeId === nodeId) {
return produce(node, (draft) => { return produce(node, (draft) => {
const needChangeVarIndex = draft.vars.findIndex((varItem) => { const needChangeVarIndex = draft.vars.findIndex((varItem) => {
return varItem.selector[1] === name return varItem.id === varId
}) })
if (needChangeVarIndex !== -1) if (needChangeVarIndex !== -1)
draft.vars[needChangeVarIndex].value = value draft.vars[needChangeVarIndex].value = value

@ -195,3 +195,18 @@ export const useDeleteInspectVar = (appId: string) => {
}, },
}) })
} }
// edit the name or value of the inspector var
export const useEditInspectorVar = (appId: string) => {
return useMutation({
mutationKey: [NAME_SPACE, 'edit inspector var', appId],
mutationFn: async (params: {
nodeId: string
varId: string
name?: string
value?: any
}) => {
console.log('edit inspector var', params)
},
})
}

Loading…
Cancel
Save