This commit is contained in:
StyleZhang
2024-03-20 13:49:02 +08:00
parent 2a75258836
commit 2697454a8e
22 changed files with 390 additions and 225 deletions

View File

@ -8,7 +8,10 @@ import {
useStore,
useWorkflowStore,
} from '../store'
import { useWorkflowRun } from '../hooks'
import {
useNodesReadOnly,
useWorkflowRun,
} from '../hooks'
import RunAndHistory from './run-and-history'
import EditingTitle from './editing-title'
import RunningTitle from './running-title'
@ -24,7 +27,10 @@ const Header: FC = () => {
const workflowStore = useWorkflowStore()
const appDetail = useAppStore(s => s.appDetail)
const appSidebarExpand = useAppStore(s => s.appSidebarExpand)
const runningStatus = useStore(s => s.runningStatus)
const {
nodesReadOnly,
getNodesReadOnly,
} = useNodesReadOnly()
const isRestoring = useStore(s => s.isRestoring)
const {
handleRunSetting,
@ -32,11 +38,11 @@ const Header: FC = () => {
} = useWorkflowRun()
const handleShowFeatures = useCallback(() => {
if (runningStatus)
if (getNodesReadOnly())
return
workflowStore.setState({ showFeaturesPanel: true })
}, [runningStatus, workflowStore])
}, [getNodesReadOnly, workflowStore])
const handleGoBackToEdit = useCallback(() => {
handleRunSetting(true)
@ -65,10 +71,10 @@ const Header: FC = () => {
)
}
{
!runningStatus && !isRestoring && <EditingTitle />
!nodesReadOnly && !isRestoring && <EditingTitle />
}
{
runningStatus && !isRestoring && <RunningTitle />
nodesReadOnly && !isRestoring && <RunningTitle />
}
{
isRestoring && <RestoringTitle />
@ -78,7 +84,7 @@ const Header: FC = () => {
!isRestoring && (
<div className='flex items-center'>
{
runningStatus && (
nodesReadOnly && (
<Button
className={`
mr-2 px-3 py-0 h-8 bg-white text-[13px] font-medium text-primary-600
@ -97,7 +103,7 @@ const Header: FC = () => {
className={`
mr-2 px-3 py-0 h-8 bg-white text-[13px] font-medium text-gray-700
border-[0.5px] border-gray-200 shadow-xs
${runningStatus && '!cursor-not-allowed opacity-50'}
${nodesReadOnly && '!cursor-not-allowed opacity-50'}
`}
onClick={handleShowFeatures}
>
@ -115,7 +121,6 @@ const Header: FC = () => {
className={`
px-3 py-0 h-8 bg-white text-[13px] font-medium text-gray-700
border-[0.5px] border-gray-200 shadow-xs
${runningStatus && '!cursor-not-allowed opacity-50'}
`}
onClick={handleShowFeatures}
>

View File

@ -9,6 +9,7 @@ import {
useWorkflowStore,
} from '../store'
import {
useNodesReadOnly,
useNodesSyncDraft,
useWorkflow,
useWorkflowRun,
@ -31,7 +32,10 @@ const Publish = () => {
const { formatTimeFromNow } = useWorkflow()
const { handleCheckBeforePublish } = useWorkflowRun()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const runningStatus = useStore(s => s.runningStatus)
const {
nodesReadOnly,
getNodesReadOnly,
} = useNodesReadOnly()
const draftUpdatedAt = useStore(s => s.draftUpdatedAt)
const publishedAt = useStore(s => s.publishedAt)
const [open, setOpen] = useState(false)
@ -61,7 +65,7 @@ const Publish = () => {
}, [workflowStore])
const handleTrigger = useCallback(() => {
if (runningStatus)
if (getNodesReadOnly())
return
if (open)
@ -72,7 +76,7 @@ const Publish = () => {
setOpen(true)
setPublished(false)
}
}, [runningStatus, open, handleSyncWorkflowDraft])
}, [getNodesReadOnly, open, handleSyncWorkflowDraft])
return (
<PortalToFollowElem
@ -89,7 +93,7 @@ const Publish = () => {
type='primary'
className={`
px-3 py-0 h-8 text-[13px] font-medium
${runningStatus && 'cursor-not-allowed opacity-50'}
${nodesReadOnly && 'cursor-not-allowed opacity-50'}
`}
>
{t('workflow.common.publish')}

View File

@ -7,6 +7,7 @@ import {
} from '../store'
import {
useIsChatMode,
useNodesReadOnly,
useNodesSyncDraft,
useWorkflowRun,
} from '../hooks'
@ -25,9 +26,9 @@ const RunMode = memo(() => {
const workflowStore = useWorkflowStore()
const { handleStopRun } = useWorkflowRun()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const runningStatus = useStore(s => s.runningStatus)
const workflowRunningData = useStore(s => s.workflowRunningData)
const showInputsPanel = useStore(s => s.showInputsPanel)
const isRunning = runningStatus === WorkflowRunningStatus.Running
const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running
const handleClick = () => {
workflowStore.setState({ showInputsPanel: true })
@ -65,7 +66,7 @@ const RunMode = memo(() => {
isRunning && (
<div
className='flex items-center justify-center ml-0.5 w-7 h-7 cursor-pointer hover:bg-black/5 rounded-md'
onClick={handleStopRun}
onClick={() => handleStopRun(workflowRunningData?.task_id || '')}
>
<StopCircle className='w-4 h-4 text-gray-500' />
</div>
@ -80,7 +81,7 @@ const PreviewMode = memo(() => {
const { t } = useTranslation()
const { handleRunSetting } = useWorkflowRun()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const runningStatus = useStore(s => s.runningStatus)
const { nodesReadOnly } = useNodesReadOnly()
const handleClick = () => {
handleSyncWorkflowDraft(true)
@ -92,12 +93,12 @@ const PreviewMode = memo(() => {
className={`
flex items-center px-1.5 h-7 rounded-md text-[13px] font-medium text-primary-600
hover:bg-primary-50 cursor-pointer
${runningStatus && 'bg-primary-50 opacity-50 !cursor-not-allowed'}
${nodesReadOnly && 'bg-primary-50 opacity-50 !cursor-not-allowed'}
`}
onClick={() => !runningStatus && handleClick()}
onClick={() => !nodesReadOnly && handleClick()}
>
{
runningStatus
nodesReadOnly
? (
<>
{t('workflow.common.inPreview')}
@ -140,7 +141,7 @@ const RunAndHistory: FC = () => {
${showRunHistory && 'bg-primary-50'}
`}
onClick={() => {
workflowStore.setState({ showRunHistory: !showRunHistory, workflowRunId: '' })
workflowStore.setState({ showRunHistory: !showRunHistory })
setCurrentLogItem()
setShowMessageLogModal(false)
}}