Revert "fix(frontend): 稳定虚拟环境探测状态,避免输入时闪烁"
This reverts commit 78ddc17fce.
This commit is contained in:
@@ -1,10 +1,5 @@
|
|||||||
import { zodResolver } from '@hookform/resolvers/zod'
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
import {
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
keepPreviousData,
|
|
||||||
useMutation,
|
|
||||||
useQuery,
|
|
||||||
useQueryClient,
|
|
||||||
} from '@tanstack/react-query'
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -214,7 +209,6 @@ export function TaskEditorModal({
|
|||||||
actionType === 'script' &&
|
actionType === 'script' &&
|
||||||
isPythonScript &&
|
isPythonScript &&
|
||||||
Boolean(debouncedWorkingDir.trim()),
|
Boolean(debouncedWorkingDir.trim()),
|
||||||
placeholderData: keepPreviousData,
|
|
||||||
retry: false,
|
retry: false,
|
||||||
staleTime: 15_000,
|
staleTime: 15_000,
|
||||||
})
|
})
|
||||||
@@ -236,9 +230,7 @@ export function TaskEditorModal({
|
|||||||
onError: (error) => toast.error(error.message),
|
onError: (error) => toast.error(error.message),
|
||||||
})
|
})
|
||||||
const linkedVenv =
|
const linkedVenv =
|
||||||
isPythonScript &&
|
isPythonScript && venvProbe.data?.status === 'linked'
|
||||||
!venvProbe.isPlaceholderData &&
|
|
||||||
venvProbe.data?.status === 'linked'
|
|
||||||
? venvProbe.data
|
? venvProbe.data
|
||||||
: null
|
: null
|
||||||
const previewVirtualEnv = isPythonScript
|
const previewVirtualEnv = isPythonScript
|
||||||
@@ -278,7 +270,7 @@ export function TaskEditorModal({
|
|||||||
|
|
||||||
// 探测到虚拟环境就自动填进「虚拟环境目录」,但用户自己改过就保留用户的值。
|
// 探测到虚拟环境就自动填进「虚拟环境目录」,但用户自己改过就保留用户的值。
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open || !isPythonScript || venvProbe.isPlaceholderData) {
|
if (!open || !isPythonScript) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const probe = venvProbe.data
|
const probe = venvProbe.data
|
||||||
@@ -303,7 +295,7 @@ export function TaskEditorModal({
|
|||||||
shouldDirty: true,
|
shouldDirty: true,
|
||||||
shouldValidate: true,
|
shouldValidate: true,
|
||||||
})
|
})
|
||||||
}, [debouncedVenv, debouncedWorkingDir, getValues, isPythonScript, open, setValue, venvProbe.data, venvProbe.isPlaceholderData])
|
}, [debouncedVenv, debouncedWorkingDir, getValues, isPythonScript, open, setValue, venvProbe.data])
|
||||||
|
|
||||||
// 打开后把焦点给第一个可编辑字段:新建时是任务标识,编辑时 ID 已锁定,跳名称。
|
// 打开后把焦点给第一个可编辑字段:新建时是任务标识,编辑时 ID 已锁定,跳名称。
|
||||||
// 原生 dialog 默认聚焦关闭按钮,不符合编辑表单的节奏。
|
// 原生 dialog 默认聚焦关闭按钮,不符合编辑表单的节奏。
|
||||||
@@ -603,7 +595,7 @@ export function TaskEditorModal({
|
|||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<VenvDetectorBar
|
<VenvDetectorBar
|
||||||
workingDir={scriptPreview.working_dir}
|
workingDir={debouncedWorkingDir}
|
||||||
probe={venvProbe.data}
|
probe={venvProbe.data}
|
||||||
pending={venvProbe.isPending}
|
pending={venvProbe.isPending}
|
||||||
failed={venvProbe.isError}
|
failed={venvProbe.isError}
|
||||||
@@ -1021,29 +1013,25 @@ function VenvDetectorBar({
|
|||||||
if (!workingDir.trim()) {
|
if (!workingDir.trim()) {
|
||||||
return (
|
return (
|
||||||
<div className="env-detector-bar" role="status">
|
<div className="env-detector-bar" role="status">
|
||||||
<span className="env-detector-hint">填写工作目录后自动检测环境</span>
|
<span className="env-status-badge warn">
|
||||||
|
● 请输入有效的工作目录以探测环境
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!probe) {
|
if (pending) {
|
||||||
if (pending) {
|
|
||||||
return (
|
|
||||||
<div className="env-detector-bar" role="status">
|
|
||||||
<span className="env-status-badge pending">⏳ 正在检测环境...</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (failed) {
|
|
||||||
return (
|
|
||||||
<div className="env-detector-bar" role="status">
|
|
||||||
<span className="env-status-badge warn">● 环境探测失败,可稍后重试</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div className="env-detector-bar" role="status">
|
<div className="env-detector-bar" role="status">
|
||||||
<span className="env-detector-hint">正在检测环境...</span>
|
<span className="env-status-badge pending">⏳ 正在探测解释器...</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed || !probe) {
|
||||||
|
return (
|
||||||
|
<div className="env-detector-bar" role="status">
|
||||||
|
<span className="env-status-badge warn">● 环境探测失败,可稍后重试</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user