mirror of https://github.com/langgenius/dify.git
feat: enhance block selector and change block components with flow type handling
This commit is contained in:
parent
16ac05ebd5
commit
d71200ee32
|
|
@ -1,5 +1,10 @@
|
|||
'use client'
|
||||
import { useCallback, useRef, useState } from 'react'
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { BlockEnum, OnSelectBlock } from '../types'
|
||||
import type { TriggerDefaultValue } from './types'
|
||||
|
|
@ -12,6 +17,7 @@ import { RiArrowRightUpLine } from '@remixicon/react'
|
|||
import { getMarketplaceUrl } from '@/utils/var'
|
||||
import Button from '@/app/components/base/button'
|
||||
import { SearchMenu } from '@/app/components/base/icons/src/vender/line/general'
|
||||
import { BlockEnum as BlockEnumValue } from '../types'
|
||||
|
||||
type AllStartBlocksProps = {
|
||||
className?: string
|
||||
|
|
@ -25,6 +31,7 @@ const AllStartBlocks = ({
|
|||
className,
|
||||
searchText,
|
||||
onSelect,
|
||||
availableBlocksTypes,
|
||||
tags = [],
|
||||
}: AllStartBlocksProps) => {
|
||||
const { t } = useTranslation()
|
||||
|
|
@ -32,6 +39,11 @@ const AllStartBlocks = ({
|
|||
const [hasStartBlocksContent, setHasStartBlocksContent] = useState(false)
|
||||
const [hasPluginContent, setHasPluginContent] = useState(false)
|
||||
|
||||
const entryNodeTypes = availableBlocksTypes?.length
|
||||
? availableBlocksTypes
|
||||
: ENTRY_NODE_TYPES
|
||||
const enableTriggerPlugin = entryNodeTypes.includes(BlockEnumValue.TriggerPlugin)
|
||||
|
||||
const handleStartBlocksContentChange = useCallback((hasContent: boolean) => {
|
||||
setHasStartBlocksContent(hasContent)
|
||||
}, [])
|
||||
|
|
@ -43,6 +55,11 @@ const AllStartBlocks = ({
|
|||
const hasAnyContent = hasStartBlocksContent || hasPluginContent
|
||||
const shouldShowEmptyState = searchText && !hasAnyContent
|
||||
|
||||
useEffect(() => {
|
||||
if (!enableTriggerPlugin && hasPluginContent)
|
||||
setHasPluginContent(false)
|
||||
}, [enableTriggerPlugin, hasPluginContent])
|
||||
|
||||
return (
|
||||
<div className={cn('min-w-[400px] max-w-[500px]', className)}>
|
||||
<div
|
||||
|
|
@ -75,16 +92,18 @@ const AllStartBlocks = ({
|
|||
<StartBlocks
|
||||
searchText={searchText}
|
||||
onSelect={onSelect as OnSelectBlock}
|
||||
availableBlocksTypes={ENTRY_NODE_TYPES as unknown as BlockEnum[]}
|
||||
availableBlocksTypes={entryNodeTypes as unknown as BlockEnum[]}
|
||||
onContentStateChange={handleStartBlocksContentChange}
|
||||
/>
|
||||
|
||||
<TriggerPluginSelector
|
||||
onSelect={onSelect}
|
||||
searchText={searchText}
|
||||
onContentStateChange={handlePluginContentChange}
|
||||
tags={tags}
|
||||
/>
|
||||
{ (
|
||||
<TriggerPluginSelector
|
||||
onSelect={onSelect}
|
||||
searchText={searchText}
|
||||
onContentStateChange={handlePluginContentChange}
|
||||
tags={tags}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@ import {
|
|||
useIsChatMode,
|
||||
useNodesInteractions,
|
||||
} from '@/app/components/workflow/hooks'
|
||||
import { useHooksStore } from '@/app/components/workflow/hooks-store'
|
||||
import type {
|
||||
Node,
|
||||
OnSelectBlock,
|
||||
} from '@/app/components/workflow/types'
|
||||
import { FlowType } from '@/types/common'
|
||||
|
||||
type ChangeBlockProps = {
|
||||
nodeId: string
|
||||
|
|
@ -33,6 +35,8 @@ const ChangeBlock = ({
|
|||
availableNextBlocks,
|
||||
} = useAvailableBlocks(nodeData.type, nodeData.isInIteration || nodeData.isInLoop)
|
||||
const isChatMode = useIsChatMode()
|
||||
const flowType = useHooksStore(s => s.configsMap?.flowType)
|
||||
const showStartTab = flowType !== FlowType.ragPipeline && !isChatMode
|
||||
|
||||
const availableNodes = useMemo(() => {
|
||||
if (availablePrevBlocks.length && availableNextBlocks.length)
|
||||
|
|
@ -66,7 +70,7 @@ const ChangeBlock = ({
|
|||
trigger={renderTrigger}
|
||||
popupClassName='min-w-[240px]'
|
||||
availableBlocksTypes={availableNodes}
|
||||
showStartTab={!isChatMode}
|
||||
showStartTab={showStartTab}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
useNodesReadOnly,
|
||||
usePanelInteractions,
|
||||
} from '../hooks'
|
||||
import { useHooksStore } from '../hooks-store'
|
||||
import { useWorkflowStore } from '../store'
|
||||
import TipPopup from './tip-popup'
|
||||
import cn from '@/utils/classnames'
|
||||
|
|
@ -28,6 +29,7 @@ import type {
|
|||
import {
|
||||
BlockEnum,
|
||||
} from '@/app/components/workflow/types'
|
||||
import { FlowType } from '@/types/common'
|
||||
|
||||
type AddBlockProps = {
|
||||
renderTrigger?: (open: boolean) => React.ReactNode
|
||||
|
|
@ -46,6 +48,8 @@ const AddBlock = ({
|
|||
const [open, setOpen] = useState(false)
|
||||
const { availableNextBlocks } = useAvailableBlocks(BlockEnum.Start, false)
|
||||
const { nodesMap: nodesMetaDataMap } = useNodesMetaData()
|
||||
const flowType = useHooksStore(s => s.configsMap?.flowType)
|
||||
const showStartTab = flowType !== FlowType.ragPipeline && !isChatMode
|
||||
|
||||
const handleOpenChange = useCallback((open: boolean) => {
|
||||
setOpen(open)
|
||||
|
|
@ -110,7 +114,7 @@ const AddBlock = ({
|
|||
trigger={renderTrigger || renderTriggerElement}
|
||||
popupClassName='!min-w-[256px]'
|
||||
availableBlocksTypes={availableNextBlocks}
|
||||
showStartTab={!isChatMode}
|
||||
showStartTab={showStartTab}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue