diff --git a/web/app/components/rag-pipeline/components/panel/input-field/field-list/hooks.ts b/web/app/components/rag-pipeline/components/panel/input-field/field-list/hooks.ts index dd5e3107db..d5c0797c9b 100644 --- a/web/app/components/rag-pipeline/components/panel/input-field/field-list/hooks.ts +++ b/web/app/components/rag-pipeline/components/panel/input-field/field-list/hooks.ts @@ -12,7 +12,7 @@ import { useBoolean } from 'ahooks' import Toast from '@/app/components/base/toast' import { usePipeline } from '../../../../hooks/use-pipeline' import { useTranslation } from 'react-i18next' -import { useStore } from '@/app/components/workflow/store' +import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks' const VARIABLE_PREFIX = 'rag' @@ -30,7 +30,7 @@ export const useFieldList = ({ allVariableNames, }: useFieldListProps) => { const { t } = useTranslation() - const setInputFieldEditPanelProps = useStore(s => s.setInputFieldEditPanelProps) + const { toggleInputFieldEditPanel } = useInputFieldPanel() const [inputFields, setInputFields] = useState(initialInputFields) const inputFieldsRef = useRef(inputFields) const [removedVar, setRemovedVar] = useState([]) @@ -60,9 +60,9 @@ export const useFieldList = ({ const editingFieldIndex = useRef(-1) const handleCloseInputFieldEditor = useCallback(() => { - setInputFieldEditPanelProps?.(null) + toggleInputFieldEditPanel?.(null) editingFieldIndex.current = -1 - }, [setInputFieldEditPanelProps]) + }, [toggleInputFieldEditPanel]) const handleRemoveField = useCallback((index: number) => { const itemToRemove = inputFieldsRef.current[index] @@ -112,7 +112,7 @@ export const useFieldList = ({ const handleOpenInputFieldEditor = useCallback((id?: string) => { const index = inputFieldsRef.current.findIndex(field => field.variable === id) editingFieldIndex.current = index - setInputFieldEditPanelProps?.({ + toggleInputFieldEditPanel?.({ onClose: handleCloseInputFieldEditor, onSubmit: handleSubmitField, initialData: inputFieldsRef.current[index], diff --git a/web/app/components/rag-pipeline/components/panel/input-field/index.tsx b/web/app/components/rag-pipeline/components/panel/input-field/index.tsx index 44722e2fc3..eec18bb471 100644 --- a/web/app/components/rag-pipeline/components/panel/input-field/index.tsx +++ b/web/app/components/rag-pipeline/components/panel/input-field/index.tsx @@ -21,17 +21,19 @@ import Button from '@/app/components/base/button' import Divider from '@/app/components/base/divider' import Tooltip from '@/app/components/base/tooltip' import cn from '@/utils/classnames' +import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks' const InputFieldPanel = () => { const { t } = useTranslation() const nodes = useNodes() - const setShowInputFieldPanel = useStore(state => state.setShowInputFieldPanel) + const { + closeAllInputFieldPanels, + toggleInputFieldPreviewPanel, + isPreviewing, + isEditing, + } = useInputFieldPanel() const ragPipelineVariables = useStore(state => state.ragPipelineVariables) 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 inputFieldsMap: Record = {} @@ -86,14 +88,12 @@ const InputFieldPanel = () => { }, [setRagPipelineVariables, handleSyncWorkflowDraft]) const closePanel = useCallback(() => { - setShowInputFieldPanel?.(false) - setShowInputFieldPreviewPanel?.(false) - setInputFieldEditPanelProps?.(null) - }, [setShowInputFieldPanel, setShowInputFieldPreviewPanel, setInputFieldEditPanelProps]) + closeAllInputFieldPanels() + }, [closeAllInputFieldPanels]) const togglePreviewPanel = useCallback(() => { - setShowInputFieldPreviewPanel?.(!showInputFieldPreviewPanel) - }, [showInputFieldPreviewPanel, setShowInputFieldPreviewPanel]) + toggleInputFieldPreviewPanel() + }, [toggleInputFieldPreviewPanel]) const allVariableNames = useMemo(() => { return ragPipelineVariables?.map(variable => variable.variable) || [] @@ -110,10 +110,10 @@ const InputFieldPanel = () => { size='small' className={cn( '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} - disabled={!!inputFieldEditPanelProps} + disabled={isEditing} > {t('datasetPipeline.operations.preview')} @@ -151,7 +151,7 @@ const InputFieldPanel = () => { nodeId={key} LabelRightContent={} inputFields={inputFields} - readonly={showInputFieldPreviewPanel || !!inputFieldEditPanelProps} + readonly={isPreviewing || isEditing} labelClassName='pt-1 pb-1' handleInputFieldsChange={updateInputFields} allVariableNames={allVariableNames} @@ -165,7 +165,7 @@ const InputFieldPanel = () => { nodeId='shared' LabelRightContent={} inputFields={inputFieldsMap.current.shared || []} - readonly={showInputFieldPreviewPanel || !!inputFieldEditPanelProps} + readonly={isPreviewing || isEditing} labelClassName='pt-2 pb-1' handleInputFieldsChange={updateInputFields} allVariableNames={allVariableNames} diff --git a/web/app/components/rag-pipeline/components/panel/input-field/preview/index.tsx b/web/app/components/rag-pipeline/components/panel/input-field/preview/index.tsx index a7868f067c..42fa0b6ddd 100644 --- a/web/app/components/rag-pipeline/components/panel/input-field/preview/index.tsx +++ b/web/app/components/rag-pipeline/components/panel/input-field/preview/index.tsx @@ -6,16 +6,16 @@ import DataSource from './data-source' import Divider from '@/app/components/base/divider' import ProcessDocuments from './process-documents' 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 { t } = useTranslation() const [datasource, setDatasource] = useState() - const setShowInputFieldPreviewPanel = useStore(state => state.setShowInputFieldPreviewPanel) + const { toggleInputFieldPreviewPanel } = useInputFieldPanel() const handleClosePreviewPanel = useCallback(() => { - setShowInputFieldPreviewPanel(false) - }, [setShowInputFieldPreviewPanel]) + toggleInputFieldPreviewPanel() + }, [toggleInputFieldPreviewPanel]) return (
diff --git a/web/app/components/rag-pipeline/components/rag-pipeline-header/input-field-button.tsx b/web/app/components/rag-pipeline/components/rag-pipeline-header/input-field-button.tsx index 8e67130c32..a5008f9d71 100644 --- a/web/app/components/rag-pipeline/components/rag-pipeline-header/input-field-button.tsx +++ b/web/app/components/rag-pipeline/components/rag-pipeline-header/input-field-button.tsx @@ -7,9 +7,11 @@ import { useTranslation } from 'react-i18next' const InputFieldButton = () => { const { t } = useTranslation() const setShowInputFieldPanel = useStore(state => state.setShowInputFieldPanel) + const setShowEnvPanel = useStore(state => state.setShowEnvPanel) const handleClick = useCallback(() => { setShowInputFieldPanel?.(true) - }, [setShowInputFieldPanel]) + setShowEnvPanel(false) + }, [setShowInputFieldPanel, setShowEnvPanel]) return (