This commit is contained in:
StyleZhang 2024-03-20 16:24:38 +08:00
parent 18883d9faa
commit 2919cc9adf
9 changed files with 37 additions and 27 deletions

View File

@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'
import { useStore } from './store'
import {
useIsChatMode,
useNodesReadOnly,
useNodesSyncDraft,
} from './hooks'
import { XClose } from '@/app/components/base/icons/src/vender/line/general'
@ -18,7 +19,7 @@ const Features = () => {
const { t } = useTranslation()
const isChatMode = useIsChatMode()
const setShowFeaturesPanel = useStore(s => s.setShowFeaturesPanel)
const isRestoring = useStore(s => s.isRestoring)
const { nodesReadOnly } = useNodesReadOnly()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const handleFeaturesChange = useCallback(() => {
@ -34,7 +35,7 @@ const Features = () => {
isChatMode && (
<>
<FeaturesChoose
disabled={isRestoring}
disabled={nodesReadOnly}
onChange={handleFeaturesChange}
/>
<div className='mx-3 w-[1px] h-[14px] bg-gray-200'></div>
@ -51,7 +52,7 @@ const Features = () => {
</div>
<div className='p-4'>
<FeaturesPanel
disabled={isRestoring}
disabled={nodesReadOnly}
onChange={handleFeaturesChange}
openingStatementProps={{
onAutoAddPromptVariable: () => {},

View File

@ -10,6 +10,7 @@ import {
} from '../store'
import {
useNodesReadOnly,
useNodesSyncDraft,
useWorkflowRun,
} from '../hooks'
import RunAndHistory from './run-and-history'
@ -29,33 +30,31 @@ const Header: FC = () => {
const appSidebarExpand = useAppStore(s => s.appSidebarExpand)
const {
nodesReadOnly,
getNodesReadOnly,
} = useNodesReadOnly()
const isRestoring = useStore(s => s.isRestoring)
const {
handleLoadBackupDraft,
handleRunSetting,
handleRestoreFromPublishedWorkflow,
} = useWorkflowRun()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const handleShowFeatures = useCallback(() => {
if (getNodesReadOnly())
return
workflowStore.setState({ showFeaturesPanel: true })
}, [getNodesReadOnly, workflowStore])
}, [workflowStore])
const handleGoBackToEdit = useCallback(() => {
handleRunSetting(true)
}, [handleRunSetting])
const handleCancelRestore = useCallback(() => {
handleLoadBackupDraft()
workflowStore.setState({ isRestoring: false })
}, [workflowStore])
}, [workflowStore, handleLoadBackupDraft])
const handleRestore = useCallback(() => {
handleRestoreFromPublishedWorkflow()
workflowStore.setState({ isRestoring: false })
}, [handleRestoreFromPublishedWorkflow, workflowStore])
handleSyncWorkflowDraft(true)
}, [handleSyncWorkflowDraft, workflowStore])
return (
<div
@ -103,7 +102,6 @@ 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
${nodesReadOnly && '!cursor-not-allowed opacity-50'}
`}
onClick={handleShowFeatures}
>

View File

@ -30,7 +30,11 @@ const Publish = () => {
const [published, setPublished] = useState(false)
const workflowStore = useWorkflowStore()
const { formatTimeFromNow } = useWorkflow()
const { handleCheckBeforePublish } = useWorkflowRun()
const {
handleBackupDraft,
handleCheckBeforePublish,
handleRestoreFromPublishedWorkflow,
} = useWorkflowRun()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const {
nodesReadOnly,
@ -61,8 +65,10 @@ const Publish = () => {
const handleRestore = useCallback(() => {
workflowStore.getState().setIsRestoring(true)
handleBackupDraft()
handleRestoreFromPublishedWorkflow()
setOpen(false)
}, [workflowStore])
}, [workflowStore, handleBackupDraft, handleRestoreFromPublishedWorkflow])
const handleTrigger = useCallback(() => {
if (getNodesReadOnly())

View File

@ -240,7 +240,7 @@ export const useNodesInteractions = () => {
}, [store, getNodesReadOnly])
const handleNodeSelect = useCallback((nodeId: string, cancelSelection?: boolean) => {
if (getNodesReadOnly())
if (getNodesReadOnly() && !workflowStore.getState().isRestoring)
return
const {
@ -264,14 +264,14 @@ export const useNodesInteractions = () => {
})
setNodes(newNodes)
handleSyncWorkflowDraft()
}, [store, handleSyncWorkflowDraft, getNodesReadOnly])
}, [store, handleSyncWorkflowDraft, getNodesReadOnly, workflowStore])
const handleNodeClick = useCallback<NodeMouseHandler>((_, node) => {
if (getNodesReadOnly())
if (getNodesReadOnly() && !workflowStore.getState().isRestoring)
return
handleNodeSelect(node.id)
}, [handleNodeSelect, getNodesReadOnly])
}, [handleNodeSelect, getNodesReadOnly, workflowStore])
const handleNodeConnect = useCallback<OnConnect>(({
source,

View File

@ -63,8 +63,8 @@ export const useNodesSyncDraft = () => {
viewport: getViewport(),
},
features: {
opening_statement: features.opening.opening_statement,
suggested_questions: features.opening.suggested_questions,
opening_statement: features.opening?.opening_statement || '',
suggested_questions: features.opening?.suggested_questions || [],
suggested_questions_after_answer: features.suggested,
text_to_speech: features.text2speech,
speech_to_text: features.speech2text,

View File

@ -323,6 +323,7 @@ export const useWorkflowRun = () => {
return {
handleBackupDraft,
handleLoadBackupDraft,
handleRunSetting,
handleRun,
handleStopRun,

View File

@ -13,6 +13,7 @@ import {
NodeRunningStatus,
} from '../../types'
import { useStore } from '../../store'
import { useNodesReadOnly } from '../../hooks'
import {
NodeSourceHandle,
NodeTargetHandle,
@ -34,6 +35,7 @@ const BaseNode: FC<BaseNodeProps> = ({
data,
children,
}) => {
const { nodesReadOnly } = useNodesReadOnly()
const toolsets = useStore(s => s.toolsets)
const toolIcon = useMemo(() => {
if (data.type === BlockEnum.Tool)
@ -60,7 +62,7 @@ const BaseNode: FC<BaseNodeProps> = ({
`}
>
{
data.type !== BlockEnum.VariableAssigner && !data._runningStatus && (
data.type !== BlockEnum.VariableAssigner && !data._runningStatus && !nodesReadOnly && (
<NodeTargetHandle
id={id}
data={data}
@ -70,7 +72,7 @@ const BaseNode: FC<BaseNodeProps> = ({
)
}
{
data.type !== BlockEnum.IfElse && data.type !== BlockEnum.QuestionClassifier && !data._runningStatus && (
data.type !== BlockEnum.IfElse && data.type !== BlockEnum.QuestionClassifier && !data._runningStatus && !nodesReadOnly && (
<NodeSourceHandle
id={id}
data={data}
@ -80,7 +82,7 @@ const BaseNode: FC<BaseNodeProps> = ({
)
}
{
!data._runningStatus && (
!data._runningStatus && !nodesReadOnly && (
<NodeControl
id={id}
data={data}

View File

@ -23,6 +23,7 @@ import {
useNodeDataUpdate,
useNodesExtraData,
useNodesInteractions,
useNodesReadOnly,
useNodesSyncDraft,
} from '@/app/components/workflow/hooks'
import { useStore } from '@/app/components/workflow/store'
@ -45,6 +46,7 @@ const BasePanel: FC<BasePanelProps> = ({
const { t } = useTranslation()
const { handleNodeSelect } = useNodesInteractions()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const { nodesReadOnly } = useNodesReadOnly()
const nodesExtraData = useNodesExtraData()
const availableNextNodes = nodesExtraData[data.type].availableNextNodes
@ -82,7 +84,7 @@ const BasePanel: FC<BasePanelProps> = ({
/>
<div className='shrink-0 flex items-center text-gray-500'>
{
canRunBySingle(data.type) && (
canRunBySingle(data.type) && !nodesReadOnly && (
<TooltipPlus
popupContent={t('workflow.panel.runThisStep')}
>

View File

@ -38,8 +38,8 @@ const ChatWrapper = forwardRef<ChatWrapperRefType>((_, ref) => {
const config = useMemo(() => {
return {
opening_statement: features.opening.opening_statement,
suggested_questions: features.opening.suggested_questions,
opening_statement: features.opening?.opening_statement || '',
suggested_questions: features.opening?.suggested_questions || [],
suggested_questions_after_answer: features.suggested,
text_to_speech: features.text2speech,
speech_to_text: features.speech2text,