feat: introduce useInputFieldPanel hook to manage input field panel state and refactor related components

This commit is contained in:
twwu
2025-08-06 10:32:57 +08:00
parent 6faa4b107b
commit ec6fabb222
11 changed files with 95 additions and 26 deletions

View File

@ -4,17 +4,20 @@ import { Env } from '@/app/components/base/icons/src/vender/line/others'
import { useStore } from '@/app/components/workflow/store'
import useTheme from '@/hooks/use-theme'
import cn from '@/utils/classnames'
import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
const EnvButton = ({ disabled }: { disabled: boolean }) => {
const { theme } = useTheme()
const setShowChatVariablePanel = useStore(s => s.setShowChatVariablePanel)
const setShowEnvPanel = useStore(s => s.setShowEnvPanel)
const setShowDebugAndPreviewPanel = useStore(s => s.setShowDebugAndPreviewPanel)
const { closeAllInputFieldPanels } = useInputFieldPanel()
const handleClick = () => {
setShowEnvPanel(true)
setShowChatVariablePanel(false)
setShowDebugAndPreviewPanel(false)
closeAllInputFieldPanels()
}
return (

View File

@ -18,6 +18,7 @@ import RunAndHistory from './run-and-history'
import EditingTitle from './editing-title'
import EnvButton from './env-button'
import VersionHistoryButton from './version-history-button'
import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
export type HeaderInNormalProps = {
components?: {
@ -41,6 +42,7 @@ const HeaderInNormal = ({
const nodes = useNodes<StartNodeType>()
const selectedNode = nodes.find(node => node.data.selected)
const { handleBackupDraft } = useWorkflowRun()
const { closeAllInputFieldPanels } = useInputFieldPanel()
const onStartRestoring = useCallback(() => {
workflowStore.setState({ isRestoring: true })
@ -53,6 +55,7 @@ const HeaderInNormal = ({
setShowDebugAndPreviewPanel(false)
setShowVariableInspectPanel(false)
setShowChatVariablePanel(false)
closeAllInputFieldPanels()
}, [workflowStore, handleBackupDraft, selectedNode, handleNodeSelect, setShowWorkflowVersionHistoryPanel, setShowEnvPanel, setShowDebugAndPreviewPanel, setShowVariableInspectPanel, setShowChatVariablePanel])
return (

View File

@ -38,6 +38,7 @@ import {
useWorkflowStore,
} from '@/app/components/workflow/store'
import type { WorkflowRunHistoryResponse } from '@/types/workflow'
import { useInputFieldPanel } from '@/app/components/rag-pipeline/hooks'
export type ViewHistoryProps = {
withText?: boolean
@ -65,6 +66,7 @@ const ViewHistory = ({
const setControlMode = useStore(s => s.setControlMode)
const historyWorkflowData = useStore(s => s.historyWorkflowData)
const { handleBackupDraft } = useWorkflowRun()
const { closeAllInputFieldPanels } = useInputFieldPanel()
const fetcher = historyFetcher ?? (noop as Fetcher<WorkflowRunHistoryResponse, string>)
const {
@ -168,6 +170,7 @@ const ViewHistory = ({
showInputsPanel: false,
showEnvPanel: false,
})
closeAllInputFieldPanels()
handleBackupDraft()
setOpen(false)
handleNodesCancelSelected()

View File

@ -44,7 +44,6 @@ import {
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 { basePath } from '@/utils/var'
import { canFindTool } from '@/utils'
import { MAX_PARALLEL_LIMIT } from '@/config'
import { useNodesMetaData } from '.'
@ -527,6 +526,7 @@ export const useWorkflowReadOnly = () => {
getWorkflowReadOnly,
}
}
export const useNodesReadOnly = () => {
const workflowStore = useWorkflowStore()
const workflowRunningData = useStore(s => s.workflowRunningData)