mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
feat: support toggle set tool when the texts changes
This commit is contained in:
parent
e842a46fe2
commit
19dc983d30
|
@ -131,6 +131,7 @@ const AllTools = ({
|
||||||
tools={tools}
|
tools={tools}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
viewType={activeView}
|
viewType={activeView}
|
||||||
|
hasSearchText={!!searchText}
|
||||||
/>
|
/>
|
||||||
{/* Plugins from marketplace */}
|
{/* Plugins from marketplace */}
|
||||||
<PluginList
|
<PluginList
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import type { ToolWithProvider } from '../../../types'
|
import type { ToolWithProvider } from '../../../types'
|
||||||
import type { BlockEnum } from '../../../types'
|
import type { BlockEnum } from '../../../types'
|
||||||
import type { ToolDefaultValue } from '../../types'
|
import type { ToolDefaultValue } from '../../types'
|
||||||
|
@ -10,14 +10,26 @@ import { ViewType } from '../../view-type-select'
|
||||||
type Props = {
|
type Props = {
|
||||||
payload: ToolWithProvider[]
|
payload: ToolWithProvider[]
|
||||||
isShowLetterIndex: boolean
|
isShowLetterIndex: boolean
|
||||||
|
hasSearchText: boolean
|
||||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ToolViewFlatView: FC<Props> = ({
|
const ToolViewFlatView: FC<Props> = ({
|
||||||
payload,
|
payload,
|
||||||
isShowLetterIndex,
|
isShowLetterIndex,
|
||||||
|
hasSearchText,
|
||||||
onSelect,
|
onSelect,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [fold, setFold] = React.useState<boolean>(true)
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasSearchText && fold) {
|
||||||
|
setFold(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!hasSearchText && !fold)
|
||||||
|
setFold(true)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [hasSearchText])
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{payload.map(tool => (
|
{payload.map(tool => (
|
||||||
|
@ -26,6 +38,8 @@ const ToolViewFlatView: FC<Props> = ({
|
||||||
payload={tool}
|
payload={tool}
|
||||||
viewType={ViewType.flat}
|
viewType={ViewType.flat}
|
||||||
isShowLetterIndex={isShowLetterIndex}
|
isShowLetterIndex={isShowLetterIndex}
|
||||||
|
isFold={fold}
|
||||||
|
onFoldChange={setFold}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import type { ToolWithProvider } from '../../../types'
|
import type { ToolWithProvider } from '../../../types'
|
||||||
import Tool from '../tool'
|
import Tool from '../tool'
|
||||||
import type { BlockEnum } from '../../../types'
|
import type { BlockEnum } from '../../../types'
|
||||||
|
@ -10,14 +10,26 @@ import type { ToolDefaultValue } from '../../types'
|
||||||
type Props = {
|
type Props = {
|
||||||
groupName: string
|
groupName: string
|
||||||
toolList: ToolWithProvider[]
|
toolList: ToolWithProvider[]
|
||||||
|
hasSearchText: boolean
|
||||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const Item: FC<Props> = ({
|
const Item: FC<Props> = ({
|
||||||
groupName,
|
groupName,
|
||||||
toolList,
|
toolList,
|
||||||
|
hasSearchText,
|
||||||
onSelect,
|
onSelect,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [fold, setFold] = React.useState<boolean>(true)
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasSearchText && fold) {
|
||||||
|
setFold(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!hasSearchText && !fold)
|
||||||
|
setFold(true)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [hasSearchText])
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className='flex items-center px-3 h-[22px] text-xs font-medium text-gray-500'>
|
<div className='flex items-center px-3 h-[22px] text-xs font-medium text-gray-500'>
|
||||||
|
@ -30,6 +42,8 @@ const Item: FC<Props> = ({
|
||||||
payload={tool}
|
payload={tool}
|
||||||
viewType={ViewType.tree}
|
viewType={ViewType.tree}
|
||||||
isShowLetterIndex={false}
|
isShowLetterIndex={false}
|
||||||
|
isFold={fold}
|
||||||
|
onFoldChange={setFold}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -10,11 +10,13 @@ import { CUSTOM_GROUP_NAME, WORKFLOW_GROUP_NAME } from '../../index-bar'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
payload: Record<string, ToolWithProvider[]>
|
payload: Record<string, ToolWithProvider[]>
|
||||||
|
hasSearchText: boolean
|
||||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ToolListTreeView: FC<Props> = ({
|
const ToolListTreeView: FC<Props> = ({
|
||||||
payload,
|
payload,
|
||||||
|
hasSearchText,
|
||||||
onSelect,
|
onSelect,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
@ -37,6 +39,7 @@ const ToolListTreeView: FC<Props> = ({
|
||||||
key={groupName}
|
key={groupName}
|
||||||
groupName={getI18nGroupName(groupName)}
|
groupName={getI18nGroupName(groupName)}
|
||||||
toolList={payload[groupName]}
|
toolList={payload[groupName]}
|
||||||
|
hasSearchText={hasSearchText}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -11,8 +11,6 @@ import type { ToolDefaultValue } from '../types'
|
||||||
import { ViewType } from '../view-type-select'
|
import { ViewType } from '../view-type-select'
|
||||||
import ActonItem from './action-item'
|
import ActonItem from './action-item'
|
||||||
import BlockIcon from '../../block-icon'
|
import BlockIcon from '../../block-icon'
|
||||||
|
|
||||||
import { useBoolean } from 'ahooks'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -20,6 +18,8 @@ type Props = {
|
||||||
payload: ToolWithProvider
|
payload: ToolWithProvider
|
||||||
viewType: ViewType
|
viewType: ViewType
|
||||||
isShowLetterIndex: boolean
|
isShowLetterIndex: boolean
|
||||||
|
isFold: boolean
|
||||||
|
onFoldChange: (fold: boolean) => void
|
||||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ const Tool: FC<Props> = ({
|
||||||
payload,
|
payload,
|
||||||
viewType,
|
viewType,
|
||||||
isShowLetterIndex,
|
isShowLetterIndex,
|
||||||
|
isFold,
|
||||||
|
onFoldChange,
|
||||||
onSelect,
|
onSelect,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
@ -35,10 +37,8 @@ const Tool: FC<Props> = ({
|
||||||
const isFlatView = viewType === ViewType.flat
|
const isFlatView = viewType === ViewType.flat
|
||||||
const actions = payload.tools
|
const actions = payload.tools
|
||||||
const hasAction = true // Now always support actions
|
const hasAction = true // Now always support actions
|
||||||
const [isFold, {
|
|
||||||
toggle: toggleFold,
|
const FoldIcon = isFold ? RiArrowRightSLine : RiArrowDownSLine
|
||||||
}] = useBoolean(false)
|
|
||||||
const FoldIcon = isFold ? RiArrowDownSLine : RiArrowRightSLine
|
|
||||||
|
|
||||||
const groupName = useMemo(() => {
|
const groupName = useMemo(() => {
|
||||||
if (payload.type === CollectionType.builtIn)
|
if (payload.type === CollectionType.builtIn)
|
||||||
|
@ -63,7 +63,7 @@ const Tool: FC<Props> = ({
|
||||||
className='flex items-center justify-between pl-3 pr-1 w-full rounded-lg hover:bg-gray-50 cursor-pointer select-none'
|
className='flex items-center justify-between pl-3 pr-1 w-full rounded-lg hover:bg-gray-50 cursor-pointer select-none'
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (hasAction)
|
if (hasAction)
|
||||||
toggleFold()
|
onFoldChange(!isFold)
|
||||||
|
|
||||||
// Now always support actions
|
// Now always support actions
|
||||||
// if (payload.parameters) {
|
// if (payload.parameters) {
|
||||||
|
@ -101,7 +101,7 @@ const Tool: FC<Props> = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{hasAction && isFold && (
|
{hasAction && !isFold && (
|
||||||
actions.map(action => (
|
actions.map(action => (
|
||||||
<ActonItem
|
<ActonItem
|
||||||
key={action.name}
|
key={action.name}
|
||||||
|
|
|
@ -18,12 +18,14 @@ type ToolsProps = {
|
||||||
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
|
||||||
tools: ToolWithProvider[]
|
tools: ToolWithProvider[]
|
||||||
viewType: ViewType
|
viewType: ViewType
|
||||||
|
hasSearchText: boolean
|
||||||
}
|
}
|
||||||
const Blocks = ({
|
const Blocks = ({
|
||||||
showWorkflowEmpty,
|
showWorkflowEmpty,
|
||||||
onSelect,
|
onSelect,
|
||||||
tools,
|
tools,
|
||||||
viewType,
|
viewType,
|
||||||
|
hasSearchText,
|
||||||
}: ToolsProps) => {
|
}: ToolsProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const language = useGetLanguage()
|
const language = useGetLanguage()
|
||||||
|
@ -89,11 +91,13 @@ const Blocks = ({
|
||||||
<ToolListFlatView
|
<ToolListFlatView
|
||||||
payload={listViewToolData}
|
payload={listViewToolData}
|
||||||
isShowLetterIndex={isShowLetterIndex}
|
isShowLetterIndex={isShowLetterIndex}
|
||||||
|
hasSearchText={hasSearchText}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<ToolListTreeView
|
<ToolListTreeView
|
||||||
payload={treeViewToolsData}
|
payload={treeViewToolsData}
|
||||||
|
hasSearchText={hasSearchText}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user