From 981643bb9f887958ba72f6bc650390f6a61654f8 Mon Sep 17 00:00:00 2001 From: warren Date: Mon, 23 Dec 2024 23:45:50 +0800 Subject: [PATCH] fix --- api/controllers/console/app/workflow.py | 2 +- .../workflow/header/version-history-modal.tsx | 40 ++++++++++++------- web/service/workflow.ts | 16 ++++---- web/types/workflow.ts | 6 +++ 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/api/controllers/console/app/workflow.py b/api/controllers/console/app/workflow.py index 4e736682f2f2bf..f07140e4aac0a5 100644 --- a/api/controllers/console/app/workflow.py +++ b/api/controllers/console/app/workflow.py @@ -25,7 +25,7 @@ from services.errors.app import WorkflowHashNotEqualError from services.workflow_service import WorkflowService -from api.fields.workflow_fields import workflow_pagination_fields +from fields.workflow_fields import workflow_pagination_fields logger = logging.getLogger(__name__) diff --git a/web/app/components/workflow/header/version-history-modal.tsx b/web/app/components/workflow/header/version-history-modal.tsx index be676e2b1a66eb..2babbeade08f14 100644 --- a/web/app/components/workflow/header/version-history-modal.tsx +++ b/web/app/components/workflow/header/version-history-modal.tsx @@ -7,7 +7,7 @@ import type { VersionHistory } from '@/types/workflow' import { useStore as useAppStore } from '@/app/components/app/store' import { fetchPublishedAllWorkflow } from '@/service/workflow' import Loading from '@/app/components/base/loading' -import InfiniteScroll from '@/app/components/base/infinite-scroll' +import Button from '@/app/components/base/button' const limit = 10 @@ -18,9 +18,8 @@ const VersionHistoryModal = () => { const appDetail = useAppStore.getState().appDetail const { - data, + data: versionHistory, isLoading, - mutate, } = useSWR( `/apps/${appDetail?.id}/workflows/publish/all?page=${page}&limit=${limit}`, fetchPublishedAllWorkflow @@ -33,26 +32,22 @@ const VersionHistoryModal = () => { } } - const loadMore = useCallback(() => { - if (data?.has_more) { - setPage(prev => prev + 1) + const handleNextPage = () => { + if (versionHistory?.has_more) { + setPage(page => page + 1) } - }, [data?.has_more]) + } return ( -
- +
+
{isLoading && page === 1 ? (
) : ( <> - {data?.items.map(item => ( + {versionHistory?.items?.map(item => ( {
)} + {!isLoading && versionHistory?.has_more && ( +
+ +
+ )} + {!isLoading && !versionHistory?.items?.length && ( +
+ 暂无历史版本 +
+ )} )} - +
) } diff --git a/web/service/workflow.ts b/web/service/workflow.ts index 82aab8c2b4acc2..10b5eac7cc5f29 100644 --- a/web/service/workflow.ts +++ b/web/service/workflow.ts @@ -1,12 +1,12 @@ import type { Fetcher } from 'swr' import { get, post } from './base' import type { CommonResponse } from '@/models/common' -import type { - ChatRunHistoryResponse, - ConversationVariableResponse, - FetchWorkflowDraftResponse, - NodesDefaultConfigsResponse, - WorkflowRunHistoryResponse, +import { + ChatRunHistoryResponse, + ConversationVariableResponse, FetchWorkflowDraftPageResponse, + FetchWorkflowDraftResponse, + NodesDefaultConfigsResponse, + WorkflowRunHistoryResponse, } from '@/types/workflow' import type { BlockEnum } from '@/app/components/workflow/types' @@ -46,8 +46,8 @@ export const fetchPublishedWorkflow: Fetcher return get(url) } -export const fetchPublishedAllWorkflow: Fetcher = (url) => { - return get(url) +export const fetchPublishedAllWorkflow: Fetcher = (url) => { + return get(url) } export const stopWorkflowRun = (url: string) => { diff --git a/web/types/workflow.ts b/web/types/workflow.ts index 0f234408bbe297..74ba458c825ed6 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -84,6 +84,12 @@ export type FetchWorkflowDraftResponse = { export type VersionHistory = FetchWorkflowDraftResponse +export type FetchWorkflowDraftPageResponse = { + items: VersionHistory[] + has_more: boolean + page: number +} + export type NodeTracingListResponse = { data: NodeTracing[] }