fix: prompt editor not update data

This commit is contained in:
Joel 2024-08-29 14:25:04 +08:00
parent dae62bef78
commit 76a07513ba
2 changed files with 9 additions and 1 deletions

View File

@ -27,6 +27,7 @@ const Panel: FC<NodePanelProps<HttpNodeType>> = ({
const { const {
readOnly, readOnly,
isDataReady,
inputs, inputs,
handleMethodChange, handleMethodChange,
handleUrlChange, handleUrlChange,
@ -53,6 +54,9 @@ const Panel: FC<NodePanelProps<HttpNodeType>> = ({
setInputVarValues, setInputVarValues,
runResult, runResult,
} = useConfig(id, data) } = useConfig(id, data)
// To prevent prompt editor in body not update data.
if (!isDataReady)
return null
return ( return (
<div className='mt-2'> <div className='mt-2'>

View File

@ -1,4 +1,4 @@
import { useCallback, useEffect } from 'react' import { useCallback, useEffect, useState } from 'react'
import produce from 'immer' import produce from 'immer'
import { useBoolean } from 'ahooks' import { useBoolean } from 'ahooks'
import useVarList from '../_base/hooks/use-var-list' import useVarList from '../_base/hooks/use-var-list'
@ -26,6 +26,8 @@ const useConfig = (id: string, payload: HttpNodeType) => {
setInputs, setInputs,
}) })
const [isDataReady, setIsDataReady] = useState(false)
useEffect(() => { useEffect(() => {
const isReady = defaultConfig && Object.keys(defaultConfig).length > 0 const isReady = defaultConfig && Object.keys(defaultConfig).length > 0
if (isReady) { if (isReady) {
@ -38,6 +40,7 @@ const useConfig = (id: string, payload: HttpNodeType) => {
newInputs.body.data = transformToBodyPayload(bodyData, [BodyType.formData, BodyType.xWwwFormUrlencoded].includes(newInputs.body.type)) newInputs.body.data = transformToBodyPayload(bodyData, [BodyType.formData, BodyType.xWwwFormUrlencoded].includes(newInputs.body.type))
setInputs(newInputs) setInputs(newInputs)
setIsDataReady(true)
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultConfig]) }, [defaultConfig])
@ -151,6 +154,7 @@ const useConfig = (id: string, payload: HttpNodeType) => {
return { return {
readOnly, readOnly,
isDataReady,
inputs, inputs,
handleVarListChange, handleVarListChange,
handleAddVariable, handleAddVariable,