refactor(web): migrate workflow run history from useSWR to TanStack Query (#30077)

This commit is contained in:
yyh
2025-12-24 18:21:01 +08:00
committed by GitHub
parent 64a14dcdbc
commit 5896bc89f5
6 changed files with 19 additions and 45 deletions

View File

@ -58,16 +58,12 @@ vi.mock('@/app/components/app/store', () => ({
vi.mock('@/app/components/workflow/header', () => ({
__esModule: true,
default: (props: HeaderProps) => {
const historyFetcher = props.normal?.runAndHistoryProps?.viewHistoryProps?.historyFetcher
const hasHistoryFetcher = typeof historyFetcher === 'function'
return (
<div
data-testid="workflow-header"
data-show-run={String(Boolean(props.normal?.runAndHistoryProps?.showRunButton))}
data-show-preview={String(Boolean(props.normal?.runAndHistoryProps?.showPreviewButton))}
data-history-url={props.normal?.runAndHistoryProps?.viewHistoryProps?.historyUrl ?? ''}
data-has-history-fetcher={String(hasHistoryFetcher)}
>
<button
type="button"
@ -86,11 +82,6 @@ vi.mock('@/app/components/workflow/header', () => ({
},
}))
vi.mock('@/service/workflow', () => ({
__esModule: true,
fetchWorkflowRunHistory: vi.fn(),
}))
vi.mock('@/service/use-workflow', () => ({
__esModule: true,
useResetWorkflowVersionHistory: () => mockResetWorkflowVersionHistory,
@ -127,7 +118,6 @@ describe('WorkflowHeader', () => {
expect(header).toHaveAttribute('data-show-run', 'false')
expect(header).toHaveAttribute('data-show-preview', 'true')
expect(header).toHaveAttribute('data-history-url', '/apps/app-id/advanced-chat/workflow-runs')
expect(header).toHaveAttribute('data-has-history-fetcher', 'true')
})
it('should configure run mode when app is not in advanced chat mode', () => {
@ -142,7 +132,6 @@ describe('WorkflowHeader', () => {
expect(header).toHaveAttribute('data-show-run', 'true')
expect(header).toHaveAttribute('data-show-preview', 'false')
expect(header).toHaveAttribute('data-history-url', '/apps/app-id/workflow-runs')
expect(header).toHaveAttribute('data-has-history-fetcher', 'true')
})
})

View File

@ -8,9 +8,6 @@ import { useShallow } from 'zustand/react/shallow'
import { useStore as useAppStore } from '@/app/components/app/store'
import Header from '@/app/components/workflow/header'
import { useResetWorkflowVersionHistory } from '@/service/use-workflow'
import {
fetchWorkflowRunHistory,
} from '@/service/workflow'
import { useIsChatMode } from '../../hooks'
import ChatVariableTrigger from './chat-variable-trigger'
import FeaturesTrigger from './features-trigger'
@ -33,7 +30,6 @@ const WorkflowHeader = () => {
return {
onClearLogAndMessageModal: handleClearLogAndMessageModal,
historyUrl: isChatMode ? `/apps/${appDetail!.id}/advanced-chat/workflow-runs` : `/apps/${appDetail!.id}/workflow-runs`,
historyFetcher: fetchWorkflowRunHistory,
}
}, [appDetail, isChatMode, handleClearLogAndMessageModal])