2024-05-09 17:18:51 +08:00
|
|
|
import { memo } from 'react'
|
2024-04-08 18:51:46 +08:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-06-20 11:05:08 +08:00
|
|
|
import {
|
2024-07-22 15:29:39 +08:00
|
|
|
RiPlayLargeLine,
|
2024-06-20 11:05:08 +08:00
|
|
|
} from '@remixicon/react'
|
2024-04-08 18:51:46 +08:00
|
|
|
import {
|
2024-07-22 15:29:39 +08:00
|
|
|
useNodesReadOnly,
|
2024-05-09 17:18:51 +08:00
|
|
|
useWorkflowStartRun,
|
2024-04-08 18:51:46 +08:00
|
|
|
} from '../hooks'
|
2025-09-18 12:49:10 +08:00
|
|
|
import type { ViewHistoryProps } from './view-history'
|
2024-04-08 18:51:46 +08:00
|
|
|
import ViewHistory from './view-history'
|
2024-07-22 15:29:39 +08:00
|
|
|
import Checklist from './checklist'
|
2024-07-09 15:05:40 +08:00
|
|
|
import cn from '@/utils/classnames'
|
2025-09-18 12:49:10 +08:00
|
|
|
import RunMode from './run-mode'
|
2024-04-08 18:51:46 +08:00
|
|
|
|
|
|
|
|
const PreviewMode = memo(() => {
|
|
|
|
|
const { t } = useTranslation()
|
2024-05-09 17:18:51 +08:00
|
|
|
const { handleWorkflowStartRunInChatflow } = useWorkflowStartRun()
|
2024-04-08 18:51:46 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
2024-04-28 17:09:56 +08:00
|
|
|
className={cn(
|
2025-03-21 17:41:03 +08:00
|
|
|
'flex h-7 items-center rounded-md px-2.5 text-[13px] font-medium text-components-button-secondary-accent-text',
|
|
|
|
|
'cursor-pointer hover:bg-state-accent-hover',
|
2024-04-28 17:09:56 +08:00
|
|
|
)}
|
2024-05-09 17:18:51 +08:00
|
|
|
onClick={() => handleWorkflowStartRunInChatflow()}
|
2024-04-08 18:51:46 +08:00
|
|
|
>
|
2025-03-21 17:41:03 +08:00
|
|
|
<RiPlayLargeLine className='mr-1 h-4 w-4' />
|
2024-04-28 17:09:56 +08:00
|
|
|
{t('workflow.common.debugAndPreview')}
|
2024-04-08 18:51:46 +08:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2025-09-18 12:49:10 +08:00
|
|
|
export type RunAndHistoryProps = {
|
|
|
|
|
showRunButton?: boolean
|
|
|
|
|
runButtonText?: string
|
|
|
|
|
isRunning?: boolean
|
|
|
|
|
showPreviewButton?: boolean
|
|
|
|
|
viewHistoryProps?: ViewHistoryProps
|
|
|
|
|
components?: {
|
|
|
|
|
RunMode?: React.ComponentType<
|
|
|
|
|
{
|
|
|
|
|
text?: string
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const RunAndHistory = ({
|
|
|
|
|
showRunButton,
|
|
|
|
|
runButtonText,
|
|
|
|
|
showPreviewButton,
|
|
|
|
|
viewHistoryProps,
|
|
|
|
|
components,
|
|
|
|
|
}: RunAndHistoryProps) => {
|
2024-07-22 15:29:39 +08:00
|
|
|
const { nodesReadOnly } = useNodesReadOnly()
|
2025-09-18 12:49:10 +08:00
|
|
|
const { RunMode: CustomRunMode } = components || {}
|
2024-04-08 18:51:46 +08:00
|
|
|
|
|
|
|
|
return (
|
2025-09-18 12:49:10 +08:00
|
|
|
<div className='flex h-8 items-center rounded-lg border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg px-0.5 shadow-xs'>
|
|
|
|
|
{
|
|
|
|
|
showRunButton && (
|
|
|
|
|
CustomRunMode ? <CustomRunMode text={runButtonText} /> : <RunMode text={runButtonText} />
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
showPreviewButton && <PreviewMode />
|
|
|
|
|
}
|
|
|
|
|
<div className='mx-0.5 h-3.5 w-[1px] bg-divider-regular'></div>
|
|
|
|
|
<ViewHistory {...viewHistoryProps} />
|
|
|
|
|
<Checklist disabled={nodesReadOnly} />
|
|
|
|
|
</div>
|
2024-04-08 18:51:46 +08:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default memo(RunAndHistory)
|