mirror of
				https://github.com/langgenius/dify.git
				synced 2025-11-04 04:43:09 +00:00 
			
		
		
		
	feat: introduce useInputFieldPanel hook to manage input field panel state and refactor related components
This commit is contained in:
		
							parent
							
								
									6faa4b107b
								
							
						
					
					
						commit
						ec6fabb222
					
				@ -12,7 +12,7 @@ import { useBoolean } from 'ahooks'
 | 
				
			|||||||
import Toast from '@/app/components/base/toast'
 | 
					import Toast from '@/app/components/base/toast'
 | 
				
			||||||
import { usePipeline } from '../../../../hooks/use-pipeline'
 | 
					import { usePipeline } from '../../../../hooks/use-pipeline'
 | 
				
			||||||
import { useTranslation } from 'react-i18next'
 | 
					import { useTranslation } from 'react-i18next'
 | 
				
			||||||
import { useStore } from '@/app/components/workflow/store'
 | 
					import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const VARIABLE_PREFIX = 'rag'
 | 
					const VARIABLE_PREFIX = 'rag'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -30,7 +30,7 @@ export const useFieldList = ({
 | 
				
			|||||||
  allVariableNames,
 | 
					  allVariableNames,
 | 
				
			||||||
}: useFieldListProps) => {
 | 
					}: useFieldListProps) => {
 | 
				
			||||||
  const { t } = useTranslation()
 | 
					  const { t } = useTranslation()
 | 
				
			||||||
  const setInputFieldEditPanelProps = useStore(s => s.setInputFieldEditPanelProps)
 | 
					  const { toggleInputFieldEditPanel } = useInputFieldPanel()
 | 
				
			||||||
  const [inputFields, setInputFields] = useState<InputVar[]>(initialInputFields)
 | 
					  const [inputFields, setInputFields] = useState<InputVar[]>(initialInputFields)
 | 
				
			||||||
  const inputFieldsRef = useRef<InputVar[]>(inputFields)
 | 
					  const inputFieldsRef = useRef<InputVar[]>(inputFields)
 | 
				
			||||||
  const [removedVar, setRemovedVar] = useState<ValueSelector>([])
 | 
					  const [removedVar, setRemovedVar] = useState<ValueSelector>([])
 | 
				
			||||||
@ -60,9 +60,9 @@ export const useFieldList = ({
 | 
				
			|||||||
  const editingFieldIndex = useRef<number>(-1)
 | 
					  const editingFieldIndex = useRef<number>(-1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleCloseInputFieldEditor = useCallback(() => {
 | 
					  const handleCloseInputFieldEditor = useCallback(() => {
 | 
				
			||||||
    setInputFieldEditPanelProps?.(null)
 | 
					    toggleInputFieldEditPanel?.(null)
 | 
				
			||||||
    editingFieldIndex.current = -1
 | 
					    editingFieldIndex.current = -1
 | 
				
			||||||
  }, [setInputFieldEditPanelProps])
 | 
					  }, [toggleInputFieldEditPanel])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleRemoveField = useCallback((index: number) => {
 | 
					  const handleRemoveField = useCallback((index: number) => {
 | 
				
			||||||
    const itemToRemove = inputFieldsRef.current[index]
 | 
					    const itemToRemove = inputFieldsRef.current[index]
 | 
				
			||||||
@ -112,7 +112,7 @@ export const useFieldList = ({
 | 
				
			|||||||
  const handleOpenInputFieldEditor = useCallback((id?: string) => {
 | 
					  const handleOpenInputFieldEditor = useCallback((id?: string) => {
 | 
				
			||||||
    const index = inputFieldsRef.current.findIndex(field => field.variable === id)
 | 
					    const index = inputFieldsRef.current.findIndex(field => field.variable === id)
 | 
				
			||||||
    editingFieldIndex.current = index
 | 
					    editingFieldIndex.current = index
 | 
				
			||||||
    setInputFieldEditPanelProps?.({
 | 
					    toggleInputFieldEditPanel?.({
 | 
				
			||||||
      onClose: handleCloseInputFieldEditor,
 | 
					      onClose: handleCloseInputFieldEditor,
 | 
				
			||||||
      onSubmit: handleSubmitField,
 | 
					      onSubmit: handleSubmitField,
 | 
				
			||||||
      initialData: inputFieldsRef.current[index],
 | 
					      initialData: inputFieldsRef.current[index],
 | 
				
			||||||
 | 
				
			|||||||
@ -21,17 +21,19 @@ import Button from '@/app/components/base/button'
 | 
				
			|||||||
import Divider from '@/app/components/base/divider'
 | 
					import Divider from '@/app/components/base/divider'
 | 
				
			||||||
import Tooltip from '@/app/components/base/tooltip'
 | 
					import Tooltip from '@/app/components/base/tooltip'
 | 
				
			||||||
import cn from '@/utils/classnames'
 | 
					import cn from '@/utils/classnames'
 | 
				
			||||||
 | 
					import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const InputFieldPanel = () => {
 | 
					const InputFieldPanel = () => {
 | 
				
			||||||
  const { t } = useTranslation()
 | 
					  const { t } = useTranslation()
 | 
				
			||||||
  const nodes = useNodes<DataSourceNodeType>()
 | 
					  const nodes = useNodes<DataSourceNodeType>()
 | 
				
			||||||
  const setShowInputFieldPanel = useStore(state => state.setShowInputFieldPanel)
 | 
					  const {
 | 
				
			||||||
 | 
					    closeAllInputFieldPanels,
 | 
				
			||||||
 | 
					    toggleInputFieldPreviewPanel,
 | 
				
			||||||
 | 
					    isPreviewing,
 | 
				
			||||||
 | 
					    isEditing,
 | 
				
			||||||
 | 
					  } = useInputFieldPanel()
 | 
				
			||||||
  const ragPipelineVariables = useStore(state => state.ragPipelineVariables)
 | 
					  const ragPipelineVariables = useStore(state => state.ragPipelineVariables)
 | 
				
			||||||
  const setRagPipelineVariables = useStore(state => state.setRagPipelineVariables)
 | 
					  const setRagPipelineVariables = useStore(state => state.setRagPipelineVariables)
 | 
				
			||||||
  const showInputFieldPreviewPanel = useStore(state => state.showInputFieldPreviewPanel)
 | 
					 | 
				
			||||||
  const setShowInputFieldPreviewPanel = useStore(state => state.setShowInputFieldPreviewPanel)
 | 
					 | 
				
			||||||
  const inputFieldEditPanelProps = useStore(state => state.inputFieldEditPanelProps)
 | 
					 | 
				
			||||||
  const setInputFieldEditPanelProps = useStore(state => state.setInputFieldEditPanelProps)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const getInputFieldsMap = () => {
 | 
					  const getInputFieldsMap = () => {
 | 
				
			||||||
    const inputFieldsMap: Record<string, InputVar[]> = {}
 | 
					    const inputFieldsMap: Record<string, InputVar[]> = {}
 | 
				
			||||||
@ -86,14 +88,12 @@ const InputFieldPanel = () => {
 | 
				
			|||||||
  }, [setRagPipelineVariables, handleSyncWorkflowDraft])
 | 
					  }, [setRagPipelineVariables, handleSyncWorkflowDraft])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const closePanel = useCallback(() => {
 | 
					  const closePanel = useCallback(() => {
 | 
				
			||||||
    setShowInputFieldPanel?.(false)
 | 
					    closeAllInputFieldPanels()
 | 
				
			||||||
    setShowInputFieldPreviewPanel?.(false)
 | 
					  }, [closeAllInputFieldPanels])
 | 
				
			||||||
    setInputFieldEditPanelProps?.(null)
 | 
					 | 
				
			||||||
  }, [setShowInputFieldPanel, setShowInputFieldPreviewPanel, setInputFieldEditPanelProps])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const togglePreviewPanel = useCallback(() => {
 | 
					  const togglePreviewPanel = useCallback(() => {
 | 
				
			||||||
    setShowInputFieldPreviewPanel?.(!showInputFieldPreviewPanel)
 | 
					    toggleInputFieldPreviewPanel()
 | 
				
			||||||
  }, [showInputFieldPreviewPanel, setShowInputFieldPreviewPanel])
 | 
					  }, [toggleInputFieldPreviewPanel])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const allVariableNames = useMemo(() => {
 | 
					  const allVariableNames = useMemo(() => {
 | 
				
			||||||
    return ragPipelineVariables?.map(variable => variable.variable) || []
 | 
					    return ragPipelineVariables?.map(variable => variable.variable) || []
 | 
				
			||||||
@ -110,10 +110,10 @@ const InputFieldPanel = () => {
 | 
				
			|||||||
          size='small'
 | 
					          size='small'
 | 
				
			||||||
          className={cn(
 | 
					          className={cn(
 | 
				
			||||||
            'shrink-0 gap-x-px px-1.5',
 | 
					            'shrink-0 gap-x-px px-1.5',
 | 
				
			||||||
            showInputFieldPreviewPanel && 'bg-state-accent-active text-text-accent',
 | 
					            isPreviewing && 'bg-state-accent-active text-text-accent',
 | 
				
			||||||
          )}
 | 
					          )}
 | 
				
			||||||
          onClick={togglePreviewPanel}
 | 
					          onClick={togglePreviewPanel}
 | 
				
			||||||
          disabled={!!inputFieldEditPanelProps}
 | 
					          disabled={isEditing}
 | 
				
			||||||
        >
 | 
					        >
 | 
				
			||||||
          <RiEyeLine className='size-3.5' />
 | 
					          <RiEyeLine className='size-3.5' />
 | 
				
			||||||
          <span className='px-[3px]'>{t('datasetPipeline.operations.preview')}</span>
 | 
					          <span className='px-[3px]'>{t('datasetPipeline.operations.preview')}</span>
 | 
				
			||||||
@ -151,7 +151,7 @@ const InputFieldPanel = () => {
 | 
				
			|||||||
                  nodeId={key}
 | 
					                  nodeId={key}
 | 
				
			||||||
                  LabelRightContent={<Datasource nodeData={datasourceNodeDataMap[key]} />}
 | 
					                  LabelRightContent={<Datasource nodeData={datasourceNodeDataMap[key]} />}
 | 
				
			||||||
                  inputFields={inputFields}
 | 
					                  inputFields={inputFields}
 | 
				
			||||||
                  readonly={showInputFieldPreviewPanel || !!inputFieldEditPanelProps}
 | 
					                  readonly={isPreviewing || isEditing}
 | 
				
			||||||
                  labelClassName='pt-1 pb-1'
 | 
					                  labelClassName='pt-1 pb-1'
 | 
				
			||||||
                  handleInputFieldsChange={updateInputFields}
 | 
					                  handleInputFieldsChange={updateInputFields}
 | 
				
			||||||
                  allVariableNames={allVariableNames}
 | 
					                  allVariableNames={allVariableNames}
 | 
				
			||||||
@ -165,7 +165,7 @@ const InputFieldPanel = () => {
 | 
				
			|||||||
          nodeId='shared'
 | 
					          nodeId='shared'
 | 
				
			||||||
          LabelRightContent={<GlobalInputs />}
 | 
					          LabelRightContent={<GlobalInputs />}
 | 
				
			||||||
          inputFields={inputFieldsMap.current.shared || []}
 | 
					          inputFields={inputFieldsMap.current.shared || []}
 | 
				
			||||||
          readonly={showInputFieldPreviewPanel || !!inputFieldEditPanelProps}
 | 
					          readonly={isPreviewing || isEditing}
 | 
				
			||||||
          labelClassName='pt-2 pb-1'
 | 
					          labelClassName='pt-2 pb-1'
 | 
				
			||||||
          handleInputFieldsChange={updateInputFields}
 | 
					          handleInputFieldsChange={updateInputFields}
 | 
				
			||||||
          allVariableNames={allVariableNames}
 | 
					          allVariableNames={allVariableNames}
 | 
				
			||||||
 | 
				
			|||||||
@ -6,16 +6,16 @@ import DataSource from './data-source'
 | 
				
			|||||||
import Divider from '@/app/components/base/divider'
 | 
					import Divider from '@/app/components/base/divider'
 | 
				
			||||||
import ProcessDocuments from './process-documents'
 | 
					import ProcessDocuments from './process-documents'
 | 
				
			||||||
import type { Datasource } from '../../test-run/types'
 | 
					import type { Datasource } from '../../test-run/types'
 | 
				
			||||||
import { useStore } from '@/app/components/workflow/store'
 | 
					import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const PreviewPanel = () => {
 | 
					const PreviewPanel = () => {
 | 
				
			||||||
  const { t } = useTranslation()
 | 
					  const { t } = useTranslation()
 | 
				
			||||||
  const [datasource, setDatasource] = useState<Datasource>()
 | 
					  const [datasource, setDatasource] = useState<Datasource>()
 | 
				
			||||||
  const setShowInputFieldPreviewPanel = useStore(state => state.setShowInputFieldPreviewPanel)
 | 
					  const { toggleInputFieldPreviewPanel } = useInputFieldPanel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleClosePreviewPanel = useCallback(() => {
 | 
					  const handleClosePreviewPanel = useCallback(() => {
 | 
				
			||||||
    setShowInputFieldPreviewPanel(false)
 | 
					    toggleInputFieldPreviewPanel()
 | 
				
			||||||
  }, [setShowInputFieldPreviewPanel])
 | 
					  }, [toggleInputFieldPreviewPanel])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className='mr-1 flex h-full w-[480px] flex-col overflow-y-auto rounded-2xl border-y-[0.5px] border-l-[0.5px] border-components-panel-border bg-components-panel-bg shadow-xl shadow-shadow-shadow-5'>
 | 
					    <div className='mr-1 flex h-full w-[480px] flex-col overflow-y-auto rounded-2xl border-y-[0.5px] border-l-[0.5px] border-components-panel-border bg-components-panel-bg shadow-xl shadow-shadow-shadow-5'>
 | 
				
			||||||
 | 
				
			|||||||
@ -7,9 +7,11 @@ import { useTranslation } from 'react-i18next'
 | 
				
			|||||||
const InputFieldButton = () => {
 | 
					const InputFieldButton = () => {
 | 
				
			||||||
  const { t } = useTranslation()
 | 
					  const { t } = useTranslation()
 | 
				
			||||||
  const setShowInputFieldPanel = useStore(state => state.setShowInputFieldPanel)
 | 
					  const setShowInputFieldPanel = useStore(state => state.setShowInputFieldPanel)
 | 
				
			||||||
 | 
					  const setShowEnvPanel = useStore(state => state.setShowEnvPanel)
 | 
				
			||||||
  const handleClick = useCallback(() => {
 | 
					  const handleClick = useCallback(() => {
 | 
				
			||||||
    setShowInputFieldPanel?.(true)
 | 
					    setShowInputFieldPanel?.(true)
 | 
				
			||||||
  }, [setShowInputFieldPanel])
 | 
					    setShowEnvPanel(false)
 | 
				
			||||||
 | 
					  }, [setShowInputFieldPanel, setShowEnvPanel])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <Button
 | 
					    <Button
 | 
				
			||||||
 | 
				
			|||||||
@ -6,3 +6,4 @@ export * from './use-pipeline-start-run'
 | 
				
			|||||||
export * from './use-pipeline-init'
 | 
					export * from './use-pipeline-init'
 | 
				
			||||||
export * from './use-get-run-and-trace-url'
 | 
					export * from './use-get-run-and-trace-url'
 | 
				
			||||||
export * from './use-DSL'
 | 
					export * from './use-DSL'
 | 
				
			||||||
 | 
					export * from './use-input-field-panel'
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,54 @@
 | 
				
			|||||||
 | 
					import { useCallback, useMemo } from 'react'
 | 
				
			||||||
 | 
					import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
 | 
				
			||||||
 | 
					import type { InputFieldEditorProps } from '../components/panel/input-field/editor'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const useInputFieldPanel = () => {
 | 
				
			||||||
 | 
					  const workflowStore = useWorkflowStore()
 | 
				
			||||||
 | 
					  const showInputFieldPreviewPanel = useStore(state => state.showInputFieldPreviewPanel)
 | 
				
			||||||
 | 
					  const inputFieldEditPanelProps = useStore(state => state.inputFieldEditPanelProps)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const isPreviewing = useMemo(() => {
 | 
				
			||||||
 | 
					    return showInputFieldPreviewPanel
 | 
				
			||||||
 | 
					  }, [showInputFieldPreviewPanel])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const isEditing = useMemo(() => {
 | 
				
			||||||
 | 
					    return !!inputFieldEditPanelProps
 | 
				
			||||||
 | 
					  }, [inputFieldEditPanelProps])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const closeAllInputFieldPanels = useCallback(() => {
 | 
				
			||||||
 | 
					    const {
 | 
				
			||||||
 | 
					      setShowInputFieldPanel,
 | 
				
			||||||
 | 
					      setShowInputFieldPreviewPanel,
 | 
				
			||||||
 | 
					      setInputFieldEditPanelProps,
 | 
				
			||||||
 | 
					    } = workflowStore.getState()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    setShowInputFieldPanel?.(false)
 | 
				
			||||||
 | 
					    setShowInputFieldPreviewPanel?.(false)
 | 
				
			||||||
 | 
					    setInputFieldEditPanelProps?.(null)
 | 
				
			||||||
 | 
					  }, [workflowStore])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const toggleInputFieldPreviewPanel = useCallback(() => {
 | 
				
			||||||
 | 
					    const {
 | 
				
			||||||
 | 
					      showInputFieldPreviewPanel,
 | 
				
			||||||
 | 
					      setShowInputFieldPreviewPanel,
 | 
				
			||||||
 | 
					    } = workflowStore.getState()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    setShowInputFieldPreviewPanel?.(!showInputFieldPreviewPanel)
 | 
				
			||||||
 | 
					  }, [workflowStore])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const toggleInputFieldEditPanel = useCallback((editContent: InputFieldEditorProps | null) => {
 | 
				
			||||||
 | 
					    const {
 | 
				
			||||||
 | 
					      setInputFieldEditPanelProps,
 | 
				
			||||||
 | 
					    } = workflowStore.getState()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    setInputFieldEditPanelProps?.(editContent)
 | 
				
			||||||
 | 
					  }, [workflowStore])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return {
 | 
				
			||||||
 | 
					    closeAllInputFieldPanels,
 | 
				
			||||||
 | 
					    toggleInputFieldPreviewPanel,
 | 
				
			||||||
 | 
					    toggleInputFieldEditPanel,
 | 
				
			||||||
 | 
					    isPreviewing,
 | 
				
			||||||
 | 
					    isEditing,
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -5,6 +5,7 @@ import {
 | 
				
			|||||||
} from '@/app/components/workflow/types'
 | 
					} from '@/app/components/workflow/types'
 | 
				
			||||||
import { useWorkflowInteractions } from '@/app/components/workflow/hooks'
 | 
					import { useWorkflowInteractions } from '@/app/components/workflow/hooks'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
 | 
					  useInputFieldPanel,
 | 
				
			||||||
  useNodesSyncDraft,
 | 
					  useNodesSyncDraft,
 | 
				
			||||||
} from '.'
 | 
					} from '.'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -12,6 +13,7 @@ export const usePipelineStartRun = () => {
 | 
				
			|||||||
  const workflowStore = useWorkflowStore()
 | 
					  const workflowStore = useWorkflowStore()
 | 
				
			||||||
  const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions()
 | 
					  const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions()
 | 
				
			||||||
  const { doSyncWorkflowDraft } = useNodesSyncDraft()
 | 
					  const { doSyncWorkflowDraft } = useNodesSyncDraft()
 | 
				
			||||||
 | 
					  const { closeAllInputFieldPanels } = useInputFieldPanel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleWorkflowStartRunInWorkflow = useCallback(async () => {
 | 
					  const handleWorkflowStartRunInWorkflow = useCallback(async () => {
 | 
				
			||||||
    const {
 | 
					    const {
 | 
				
			||||||
@ -28,6 +30,7 @@ export const usePipelineStartRun = () => {
 | 
				
			|||||||
    } = workflowStore.getState()
 | 
					    } = workflowStore.getState()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setShowEnvPanel(false)
 | 
					    setShowEnvPanel(false)
 | 
				
			||||||
 | 
					    closeAllInputFieldPanels()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (showDebugAndPreviewPanel) {
 | 
					    if (showDebugAndPreviewPanel) {
 | 
				
			||||||
      handleCancelDebugAndPreviewPanel()
 | 
					      handleCancelDebugAndPreviewPanel()
 | 
				
			||||||
 | 
				
			|||||||
@ -4,17 +4,20 @@ import { Env } from '@/app/components/base/icons/src/vender/line/others'
 | 
				
			|||||||
import { useStore } from '@/app/components/workflow/store'
 | 
					import { useStore } from '@/app/components/workflow/store'
 | 
				
			||||||
import useTheme from '@/hooks/use-theme'
 | 
					import useTheme from '@/hooks/use-theme'
 | 
				
			||||||
import cn from '@/utils/classnames'
 | 
					import cn from '@/utils/classnames'
 | 
				
			||||||
 | 
					import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const EnvButton = ({ disabled }: { disabled: boolean }) => {
 | 
					const EnvButton = ({ disabled }: { disabled: boolean }) => {
 | 
				
			||||||
  const { theme } = useTheme()
 | 
					  const { theme } = useTheme()
 | 
				
			||||||
  const setShowChatVariablePanel = useStore(s => s.setShowChatVariablePanel)
 | 
					  const setShowChatVariablePanel = useStore(s => s.setShowChatVariablePanel)
 | 
				
			||||||
  const setShowEnvPanel = useStore(s => s.setShowEnvPanel)
 | 
					  const setShowEnvPanel = useStore(s => s.setShowEnvPanel)
 | 
				
			||||||
  const setShowDebugAndPreviewPanel = useStore(s => s.setShowDebugAndPreviewPanel)
 | 
					  const setShowDebugAndPreviewPanel = useStore(s => s.setShowDebugAndPreviewPanel)
 | 
				
			||||||
 | 
					  const { closeAllInputFieldPanels } = useInputFieldPanel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleClick = () => {
 | 
					  const handleClick = () => {
 | 
				
			||||||
    setShowEnvPanel(true)
 | 
					    setShowEnvPanel(true)
 | 
				
			||||||
    setShowChatVariablePanel(false)
 | 
					    setShowChatVariablePanel(false)
 | 
				
			||||||
    setShowDebugAndPreviewPanel(false)
 | 
					    setShowDebugAndPreviewPanel(false)
 | 
				
			||||||
 | 
					    closeAllInputFieldPanels()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,7 @@ import RunAndHistory from './run-and-history'
 | 
				
			|||||||
import EditingTitle from './editing-title'
 | 
					import EditingTitle from './editing-title'
 | 
				
			||||||
import EnvButton from './env-button'
 | 
					import EnvButton from './env-button'
 | 
				
			||||||
import VersionHistoryButton from './version-history-button'
 | 
					import VersionHistoryButton from './version-history-button'
 | 
				
			||||||
 | 
					import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type HeaderInNormalProps = {
 | 
					export type HeaderInNormalProps = {
 | 
				
			||||||
  components?: {
 | 
					  components?: {
 | 
				
			||||||
@ -41,6 +42,7 @@ const HeaderInNormal = ({
 | 
				
			|||||||
  const nodes = useNodes<StartNodeType>()
 | 
					  const nodes = useNodes<StartNodeType>()
 | 
				
			||||||
  const selectedNode = nodes.find(node => node.data.selected)
 | 
					  const selectedNode = nodes.find(node => node.data.selected)
 | 
				
			||||||
  const { handleBackupDraft } = useWorkflowRun()
 | 
					  const { handleBackupDraft } = useWorkflowRun()
 | 
				
			||||||
 | 
					  const { closeAllInputFieldPanels } = useInputFieldPanel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const onStartRestoring = useCallback(() => {
 | 
					  const onStartRestoring = useCallback(() => {
 | 
				
			||||||
    workflowStore.setState({ isRestoring: true })
 | 
					    workflowStore.setState({ isRestoring: true })
 | 
				
			||||||
@ -53,6 +55,7 @@ const HeaderInNormal = ({
 | 
				
			|||||||
    setShowDebugAndPreviewPanel(false)
 | 
					    setShowDebugAndPreviewPanel(false)
 | 
				
			||||||
    setShowVariableInspectPanel(false)
 | 
					    setShowVariableInspectPanel(false)
 | 
				
			||||||
    setShowChatVariablePanel(false)
 | 
					    setShowChatVariablePanel(false)
 | 
				
			||||||
 | 
					    closeAllInputFieldPanels()
 | 
				
			||||||
  }, [workflowStore, handleBackupDraft, selectedNode, handleNodeSelect, setShowWorkflowVersionHistoryPanel, setShowEnvPanel, setShowDebugAndPreviewPanel, setShowVariableInspectPanel, setShowChatVariablePanel])
 | 
					  }, [workflowStore, handleBackupDraft, selectedNode, handleNodeSelect, setShowWorkflowVersionHistoryPanel, setShowEnvPanel, setShowDebugAndPreviewPanel, setShowVariableInspectPanel, setShowChatVariablePanel])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
 | 
				
			|||||||
@ -38,6 +38,7 @@ import {
 | 
				
			|||||||
  useWorkflowStore,
 | 
					  useWorkflowStore,
 | 
				
			||||||
} from '@/app/components/workflow/store'
 | 
					} from '@/app/components/workflow/store'
 | 
				
			||||||
import type { WorkflowRunHistoryResponse } from '@/types/workflow'
 | 
					import type { WorkflowRunHistoryResponse } from '@/types/workflow'
 | 
				
			||||||
 | 
					import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type ViewHistoryProps = {
 | 
					export type ViewHistoryProps = {
 | 
				
			||||||
  withText?: boolean
 | 
					  withText?: boolean
 | 
				
			||||||
@ -65,6 +66,7 @@ const ViewHistory = ({
 | 
				
			|||||||
  const setControlMode = useStore(s => s.setControlMode)
 | 
					  const setControlMode = useStore(s => s.setControlMode)
 | 
				
			||||||
  const historyWorkflowData = useStore(s => s.historyWorkflowData)
 | 
					  const historyWorkflowData = useStore(s => s.historyWorkflowData)
 | 
				
			||||||
  const { handleBackupDraft } = useWorkflowRun()
 | 
					  const { handleBackupDraft } = useWorkflowRun()
 | 
				
			||||||
 | 
					  const { closeAllInputFieldPanels } = useInputFieldPanel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const fetcher = historyFetcher ?? (noop as Fetcher<WorkflowRunHistoryResponse, string>)
 | 
					  const fetcher = historyFetcher ?? (noop as Fetcher<WorkflowRunHistoryResponse, string>)
 | 
				
			||||||
  const {
 | 
					  const {
 | 
				
			||||||
@ -168,6 +170,7 @@ const ViewHistory = ({
 | 
				
			|||||||
                            showInputsPanel: false,
 | 
					                            showInputsPanel: false,
 | 
				
			||||||
                            showEnvPanel: false,
 | 
					                            showEnvPanel: false,
 | 
				
			||||||
                          })
 | 
					                          })
 | 
				
			||||||
 | 
					                          closeAllInputFieldPanels()
 | 
				
			||||||
                          handleBackupDraft()
 | 
					                          handleBackupDraft()
 | 
				
			||||||
                          setOpen(false)
 | 
					                          setOpen(false)
 | 
				
			||||||
                          handleNodesCancelSelected()
 | 
					                          handleNodesCancelSelected()
 | 
				
			||||||
 | 
				
			|||||||
@ -44,7 +44,6 @@ import {
 | 
				
			|||||||
import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants'
 | 
					import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants'
 | 
				
			||||||
import { CUSTOM_LOOP_START_NODE } from '@/app/components/workflow/nodes/loop-start/constants'
 | 
					import { CUSTOM_LOOP_START_NODE } from '@/app/components/workflow/nodes/loop-start/constants'
 | 
				
			||||||
import { basePath } from '@/utils/var'
 | 
					import { basePath } from '@/utils/var'
 | 
				
			||||||
import { canFindTool } from '@/utils'
 | 
					 | 
				
			||||||
import { MAX_PARALLEL_LIMIT } from '@/config'
 | 
					import { MAX_PARALLEL_LIMIT } from '@/config'
 | 
				
			||||||
import { useNodesMetaData } from '.'
 | 
					import { useNodesMetaData } from '.'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -527,6 +526,7 @@ export const useWorkflowReadOnly = () => {
 | 
				
			|||||||
    getWorkflowReadOnly,
 | 
					    getWorkflowReadOnly,
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const useNodesReadOnly = () => {
 | 
					export const useNodesReadOnly = () => {
 | 
				
			||||||
  const workflowStore = useWorkflowStore()
 | 
					  const workflowStore = useWorkflowStore()
 | 
				
			||||||
  const workflowRunningData = useStore(s => s.workflowRunningData)
 | 
					  const workflowRunningData = useStore(s => s.workflowRunningData)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user