-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] Support Multi-Version Workflows #11990
Open
warren830
wants to merge
22
commits into
langgenius:main
Choose a base branch
from
warren830:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+271
−52
Open
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4e41b8a
feat: support workflow multi version recovery
hobo-l-20230331 b1397e2
feat: support workflow multi version recovery
hobo-l-20230331 0c91279
resolve conflict
crazywoola 7004656
resolve conflict
crazywoola 0853f66
resolve conflict
crazywoola 03af025
fix: ui
crazywoola a20f15d
chore: make linter happy
crazywoola b7bf30b
Merge remote-tracking branch 'origin-2/main' into feat/multi_version_…
warren830 73cb902
modify
warren830 fad1bbb
Merge branch 'langgenius:main' into main
warren830 82de0ee
fix
warren830 957fa7f
fix
warren830 02ed307
fix
warren830 2599646
Merge branch 'langgenius:main' into main
warren830 8ee8a21
Merge branch 'main' of github.com:warren830/dify
warren830 981643b
fix
warren830 a3b1df5
fix lint
warren830 52de345
reformat api
warren830 bf0118a
Merge remote-tracking branch 'remote/main'
warren830 440141a
fix
warren830 427fb24
fix
warren830 24186ae
add created by
warren830 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
web/app/components/workflow/header/version-history-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react' | ||
import dayjs from 'dayjs' | ||
import { WorkflowVersion } from '../types' | ||
import cn from '@/utils/classnames' | ||
import type { VersionHistory } from '@/types/workflow' | ||
|
||
type VersionHistoryItemProps = { | ||
item: VersionHistory | ||
selectedVersion: string | ||
onClick: (item: VersionHistory) => void | ||
} | ||
|
||
const VersionHistoryItem: React.FC<VersionHistoryItemProps> = ({ item, selectedVersion, onClick }) => { | ||
const formatTime = (time: number) => dayjs.unix(time).format('YYYY-MM-DD HH:mm:ss') | ||
|
||
const renderVersionLabel = (version: string) => ( | ||
(version === WorkflowVersion.Draft || version === WorkflowVersion.Latest) | ||
? ( | ||
<div className="shrink-0 px-1 border bg-white border-[rgba(0,0,0,0.08)] rounded-[5px] truncate"> | ||
{version} | ||
</div> | ||
) | ||
: null | ||
) | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
'flex items-center p-2 h-9 text-xs font-medium text-gray-700 justify-between', | ||
item.version === selectedVersion ? '' : 'hover:bg-gray-100', | ||
item.version === WorkflowVersion.Draft ? 'cursor-not-allowed' : 'cursor-pointer', | ||
)} | ||
onClick={() => item.version !== WorkflowVersion.Draft && onClick(item)} | ||
> | ||
<div>{formatTime(item.version === WorkflowVersion.Draft ? item.updated_at : item.created_at)}</div> | ||
{renderVersionLabel(item.version)} | ||
</div> | ||
) | ||
} | ||
|
||
export default React.memo(VersionHistoryItem) |
85 changes: 85 additions & 0 deletions
85
web/app/components/workflow/header/version-history-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
'use client' | ||
import React, { useState, useCallback } from 'react' | ||
import useSWR from 'swr' | ||
import { useWorkflowRun } from '../hooks' | ||
import VersionHistoryItem from './version-history-item' | ||
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 Button from '@/app/components/base/button' | ||
|
||
const limit = 10 | ||
|
||
const VersionHistoryModal = () => { | ||
const [selectedVersion, setSelectedVersion] = useState('draft') | ||
const [page, setPage] = useState(1) | ||
const { handleRestoreFromPublishedWorkflow } = useWorkflowRun() | ||
const appDetail = useAppStore.getState().appDetail | ||
|
||
const { | ||
data: versionHistory, | ||
isLoading, | ||
} = useSWR( | ||
`/apps/${appDetail?.id}/workflows/publish/all?page=${page}&limit=${limit}`, | ||
fetchPublishedAllWorkflow | ||
) | ||
|
||
const handleVersionClick = (item: VersionHistory) => { | ||
if (item.version !== selectedVersion) { | ||
setSelectedVersion(item.version) | ||
handleRestoreFromPublishedWorkflow(item) | ||
} | ||
} | ||
|
||
const handleNextPage = () => { | ||
if (versionHistory?.has_more) { | ||
setPage(page => page + 1) | ||
} | ||
} | ||
|
||
return ( | ||
<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> | ||
) : ( | ||
<> | ||
{versionHistory?.items?.map(item => ( | ||
<VersionHistoryItem | ||
key={item.version} | ||
item={item} | ||
selectedVersion={selectedVersion} | ||
onClick={handleVersionClick} | ||
/> | ||
))} | ||
{isLoading && page > 1 && ( | ||
<div className='flex items-center justify-center h-10'> | ||
<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> | ||
)} | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default React.memo(VersionHistoryModal) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid using comments in any language other than English.