fix: use last run call api timing

This commit is contained in:
Joel 2025-05-22 15:44:37 +08:00
parent bbfdab53dd
commit c1bc464e9e
3 changed files with 13 additions and 3 deletions

View File

@ -148,6 +148,7 @@ const BasePanel: FC<BasePanelProps> = ({
getInputVars, getInputVars,
toVarInputs, toVarInputs,
tabType, tabType,
isRunAfterSingleRun,
setTabType, setTabType,
singleRunParams, singleRunParams,
nodeInfo, nodeInfo,
@ -326,6 +327,7 @@ const BasePanel: FC<BasePanelProps> = ({
nodeId={id} nodeId={id}
canSingleRun={isSupportSingleRun} canSingleRun={isSupportSingleRun}
runningStatus={runningStatus} runningStatus={runningStatus}
isRunAfterSingleRun={isRunAfterSingleRun}
onSingleRunClicked={handleSingleRun} onSingleRunClicked={handleSingleRun}
nodeInfo={nodeInfo} nodeInfo={nodeInfo}
singleRunResult={runResult!} singleRunResult={runResult!}

View File

@ -13,6 +13,7 @@ type Props = {
appId: string appId: string
nodeId: string nodeId: string
canSingleRun: boolean canSingleRun: boolean
isRunAfterSingleRun: boolean
nodeInfo?: NodeTracing nodeInfo?: NodeTracing
runningStatus?: NodeRunningStatus runningStatus?: NodeRunningStatus
onSingleRunClicked: () => void onSingleRunClicked: () => void
@ -23,6 +24,7 @@ const LastRun: FC<Props> = ({
appId, appId,
nodeId, nodeId,
canSingleRun, canSingleRun,
isRunAfterSingleRun,
nodeInfo, nodeInfo,
runningStatus: oneStepRunRunningStatus, runningStatus: oneStepRunRunningStatus,
onSingleRunClicked, onSingleRunClicked,
@ -30,10 +32,11 @@ const LastRun: FC<Props> = ({
...otherResultPanelProps ...otherResultPanelProps
}) => { }) => {
const isRunning = oneStepRunRunningStatus === NodeRunningStatus.Running const isRunning = oneStepRunRunningStatus === NodeRunningStatus.Running
const isOneStepRunFailed = oneStepRunRunningStatus === NodeRunningStatus.Failed const isOneStepRunSucceed = oneStepRunRunningStatus === NodeRunningStatus.Succeeded
const { data: lastRunResult, isFetching, error } = useLastRun(appId, nodeId, !isOneStepRunFailed) const canRunLastRun = !isRunAfterSingleRun || isOneStepRunSucceed
const { data: lastRunResult, isFetching, error } = useLastRun(appId, nodeId, canRunLastRun)
const noLastRun = (error as any)?.status === 404 const noLastRun = (error as any)?.status === 404
const runResult = (isOneStepRunFailed ? singleRunResult : lastRunResult) || {} const runResult = (canRunLastRun ? lastRunResult : singleRunResult) || {}
if (isFetching) { if (isFetching) {
return ( return (

View File

@ -154,13 +154,16 @@ const useLastRun = <T>({
} }
const [tabType, setTabType] = useState<TabType>(TabType.settings) const [tabType, setTabType] = useState<TabType>(TabType.settings)
const [isRunAfterSingleRun, setIsRunAfterSingleRun] = useState(false)
const handleRunWithParams = async (data: Record<string, any>) => { const handleRunWithParams = async (data: Record<string, any>) => {
setIsRunAfterSingleRun(true)
setTabType(TabType.lastRun) setTabType(TabType.lastRun)
callRunApi(data) callRunApi(data)
hideSingleRun() hideSingleRun()
} }
const handleTabClicked = useCallback((type: TabType) => { const handleTabClicked = useCallback((type: TabType) => {
setIsRunAfterSingleRun(false)
setTabType(type) setTabType(type)
}, []) }, [])
@ -219,6 +222,7 @@ const useLastRun = <T>({
// no need to input params // no need to input params
if (isAllVarsHasValue(singleRunParams?.getDependentVars?.())) { if (isAllVarsHasValue(singleRunParams?.getDependentVars?.())) {
callRunApi({}) callRunApi({})
setIsRunAfterSingleRun(true)
setTabType(TabType.lastRun) setTabType(TabType.lastRun)
} }
else { else {
@ -229,6 +233,7 @@ const useLastRun = <T>({
return { return {
...oneStepRunRes, ...oneStepRunRes,
tabType, tabType,
isRunAfterSingleRun,
setTabType: handleTabClicked, setTabType: handleTabClicked,
singleRunParams, singleRunParams,
nodeInfo, nodeInfo,