fix(frontend): 环境探测不再显示加载态,只在最终结果更新
探测期间保留上一次最终结果,移除正在探测提示;首次无结果时保持空状态;占位结果不参与自动回填,最终结果返回后一次性更新。
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
keepPreviousData,
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
@@ -225,6 +230,8 @@ export function TaskEditorModal({
|
||||
actionType === 'script' &&
|
||||
isPythonScript &&
|
||||
Boolean(debouncedWorkingDir.trim()),
|
||||
// 探测期间保留上一次最终结果,不显示“正在检测”这种中间状态。
|
||||
placeholderData: keepPreviousData,
|
||||
retry: false,
|
||||
staleTime: 15_000,
|
||||
})
|
||||
@@ -246,7 +253,9 @@ export function TaskEditorModal({
|
||||
onError: (error) => toast.error(error.message),
|
||||
})
|
||||
const linkedVenv =
|
||||
isPythonScript && venvProbe.data?.status === 'linked'
|
||||
isPythonScript &&
|
||||
!venvProbe.isPlaceholderData &&
|
||||
venvProbe.data?.status === 'linked'
|
||||
? venvProbe.data
|
||||
: null
|
||||
const previewVirtualEnv = isPythonScript
|
||||
@@ -289,7 +298,7 @@ export function TaskEditorModal({
|
||||
|
||||
// 探测到虚拟环境就自动填进「虚拟环境目录」,但用户自己改过就保留用户的值。
|
||||
useEffect(() => {
|
||||
if (!open || !isPythonScript) {
|
||||
if (!open || !isPythonScript || venvProbe.isPlaceholderData) {
|
||||
return
|
||||
}
|
||||
const probe = venvProbe.data
|
||||
@@ -318,7 +327,7 @@ export function TaskEditorModal({
|
||||
shouldDirty: true,
|
||||
shouldValidate: true,
|
||||
})
|
||||
}, [debouncedVenv, debouncedWorkingDir, getValues, isPythonScript, open, scriptPreview.working_dir, setValue, venvProbe.data])
|
||||
}, [debouncedVenv, debouncedWorkingDir, getValues, isPythonScript, open, scriptPreview.working_dir, setValue, venvProbe.data, venvProbe.isPlaceholderData])
|
||||
|
||||
// 打开后把焦点给第一个可编辑字段:新建时是任务标识,编辑时 ID 已锁定,跳名称。
|
||||
// 原生 dialog 默认聚焦关闭按钮,不符合编辑表单的节奏。
|
||||
@@ -626,7 +635,6 @@ export function TaskEditorModal({
|
||||
<VenvDetectorBar
|
||||
workingDir={scriptPreview.working_dir}
|
||||
probe={venvProbe.data}
|
||||
pending={venvProbe.isPending}
|
||||
failed={venvProbe.isError}
|
||||
creating={createVenvMutation.isPending}
|
||||
onCreate={() =>
|
||||
@@ -1026,7 +1034,6 @@ function formatScriptCommandPreview(
|
||||
interface VenvDetectorBarProps {
|
||||
workingDir: string
|
||||
probe: VenvProbeResponse | undefined
|
||||
pending: boolean
|
||||
failed: boolean
|
||||
creating: boolean
|
||||
onCreate: () => void
|
||||
@@ -1035,7 +1042,6 @@ interface VenvDetectorBarProps {
|
||||
function VenvDetectorBar({
|
||||
workingDir,
|
||||
probe,
|
||||
pending,
|
||||
failed,
|
||||
creating,
|
||||
onCreate,
|
||||
@@ -1048,21 +1054,17 @@ function VenvDetectorBar({
|
||||
)
|
||||
}
|
||||
|
||||
if (pending) {
|
||||
return (
|
||||
<div className="env-detector-bar" role="status">
|
||||
<span className="env-status-badge pending">⏳ 正在探测解释器...</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (failed || !probe) {
|
||||
if (!probe) {
|
||||
if (failed) {
|
||||
return (
|
||||
<div className="env-detector-bar" role="status">
|
||||
<span className="env-status-badge warn">● 环境探测失败,可稍后重试</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
// 还没有最终结果:保持空状态,不显示跳动的“正在检测”。
|
||||
return <div className="env-detector-bar" role="status" />
|
||||
}
|
||||
|
||||
if (probe.status === 'linked') {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user