import type { FC } from 'react' import { memo, useCallback, } from 'react' import { useTranslation } from 'react-i18next' import { useStore, useWorkflowStore, } from '../store' import { useNodesReadOnly, useNodesSyncDraft, useWorkflowRun, } from '../hooks' import RunAndHistory from './run-and-history' import EditingTitle from './editing-title' import RunningTitle from './running-title' import RestoringTitle from './restoring-title' import Publish from './publish' import { Grid01 } from '@/app/components/base/icons/src/vender/line/layout' import Button from '@/app/components/base/button' import { ArrowNarrowLeft } from '@/app/components/base/icons/src/vender/line/arrows' import { useStore as useAppStore } from '@/app/components/app/store' const Header: FC = () => { const { t } = useTranslation() const workflowStore = useWorkflowStore() const appDetail = useAppStore(s => s.appDetail) const appSidebarExpand = useAppStore(s => s.appSidebarExpand) const { nodesReadOnly, getNodesReadOnly, } = useNodesReadOnly() const isRestoring = useStore(s => s.isRestoring) const { handleLoadBackupDraft, handleRunSetting, } = useWorkflowRun() const { handleSyncWorkflowDraft } = useNodesSyncDraft() const handleShowFeatures = useCallback(() => { const { isRestoring, setShowFeaturesPanel, } = workflowStore.getState() if (getNodesReadOnly() && !isRestoring) return setShowFeaturesPanel(true) }, [workflowStore, getNodesReadOnly]) const handleGoBackToEdit = useCallback(() => { handleRunSetting(true) }, [handleRunSetting]) const handleCancelRestore = useCallback(() => { handleLoadBackupDraft() workflowStore.setState({ isRestoring: false }) }, [workflowStore, handleLoadBackupDraft]) const handleRestore = useCallback(() => { workflowStore.setState({ isRestoring: false }) handleSyncWorkflowDraft(true) }, [handleSyncWorkflowDraft, workflowStore]) return (
{ appSidebarExpand === 'collapse' && (
{appDetail?.name}
) } { !nodesReadOnly && !isRestoring && } { nodesReadOnly && !isRestoring && } { isRestoring && }
{ !isRestoring && (
{ nodesReadOnly && ( ) }
) } { isRestoring && (
) }
) } export default memo(Header)