Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
warren830 committed Dec 23, 2024
1 parent 8ee8a21 commit 981643b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api/controllers/console/app/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
40 changes: 25 additions & 15 deletions web/app/components/workflow/header/version-history-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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 (
<div className='w-[240px] bg-white rounded-2xl border-[0.5px] border-gray-200 shadow-xl p-2'>
<InfiniteScroll
className="max-h-[400px] overflow-auto"
hasMore={!!data?.has_more}
loadMore={loadMore}
>
<div className='w-[336px] bg-white rounded-2xl border-[0.5px] border-gray-200 shadow-xl p-2'>
<div className="max-h-[400px] overflow-auto">
{isLoading && page === 1 ? (
<div className='flex items-center justify-center h-10'>
<Loading/>
</div>
) : (
<>
{data?.items.map(item => (
{versionHistory?.items?.map(item => (
<VersionHistoryItem
key={item.version}
item={item}
Expand All @@ -65,9 +60,24 @@ const VersionHistoryModal = () => {
<Loading/>
</div>
)}
{!isLoading && versionHistory?.has_more && (
<div className='flex items-center justify-center h-10 mt-2'>
<Button
className='text-sm'
onClick={handleNextPage}
>
加载更多
</Button>
</div>
)}
{!isLoading && !versionHistory?.items?.length && (
<div className='flex items-center justify-center h-10 text-gray-500'>
暂无历史版本
</div>
)}
</>
)}
</InfiniteScroll>
</div>
</div>
)
}
Expand Down
16 changes: 8 additions & 8 deletions web/service/workflow.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -46,8 +46,8 @@ export const fetchPublishedWorkflow: Fetcher<FetchWorkflowDraftResponse, string>
return get<FetchWorkflowDraftResponse>(url)
}

export const fetchPublishedAllWorkflow: Fetcher<FetchWorkflowDraftResponse[], string> = (url) => {
return get<FetchWorkflowDraftResponse[]>(url)
export const fetchPublishedAllWorkflow: Fetcher<FetchWorkflowDraftPageResponse, string> = (url) => {
return get<FetchWorkflowDraftPageResponse>(url)
}

export const stopWorkflowRun = (url: string) => {
Expand Down
6 changes: 6 additions & 0 deletions web/types/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
Expand Down

0 comments on commit 981643b

Please sign in to comment.