feat: add button place and view type control

This commit is contained in:
Joel 2025-05-09 10:49:08 +08:00
parent 27c27223e1
commit 30dbefd937
4 changed files with 27 additions and 22 deletions

View File

@ -3,6 +3,7 @@ import { RiCloseLine } from '@remixicon/react'
import TagsFilter from './tags-filter' import TagsFilter from './tags-filter'
import ActionButton from '@/app/components/base/action-button' import ActionButton from '@/app/components/base/action-button'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { RiAddLine } from '@remixicon/react'
type SearchBoxProps = { type SearchBoxProps = {
search: string search: string
@ -13,6 +14,9 @@ type SearchBoxProps = {
size?: 'small' | 'large' size?: 'small' | 'large'
placeholder?: string placeholder?: string
locale?: string locale?: string
supportAddCustomTool?: boolean
onShowAddCustomCollectionModal?: () => void
onAddedCustomTool?: () => void
} }
const SearchBox = ({ const SearchBox = ({
search, search,
@ -23,6 +27,8 @@ const SearchBox = ({
size = 'small', size = 'small',
placeholder = '', placeholder = '',
locale, locale,
supportAddCustomTool,
onShowAddCustomCollectionModal,
}: SearchBoxProps) => { }: SearchBoxProps) => {
return ( return (
<div <div
@ -63,6 +69,17 @@ const SearchBox = ({
size={size} size={size}
locale={locale} locale={locale}
/> />
{supportAddCustomTool && (
<div className='flex items-center'>
<div className='mr-1.5 h-3.5 w-px bg-divider-regular'></div>
<ActionButton
className='bg-components-button-primary-bg text-components-button-primary-text hover:bg-components-button-primary-bg hover:text-components-button-primary-text'
onClick={onShowAddCustomCollectionModal}
>
<RiAddLine className='h-4 w-4' />
</ActionButton>
</div>
)}
</div> </div>
) )
} }

View File

@ -184,6 +184,7 @@ const EditCustomCollectionModal: FC<Props> = ({
onClose={onHide} onClose={onHide}
closable closable
className='!h-[calc(100vh-16px)] !max-w-[630px] !p-0' className='!h-[calc(100vh-16px)] !max-w-[630px] !p-0'
wrapperClassName='z-[1000]'
> >
<div className='flex h-full flex-col'> <div className='flex h-full flex-col'>
<div className='ml-6 mt-6 text-base font-semibold text-text-primary'> <div className='ml-6 mt-6 text-base font-semibold text-text-primary'>

View File

@ -17,8 +17,6 @@ import cn from '@/utils/classnames'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
import type { ListRef } from '@/app/components/workflow/block-selector/market-place-plugin/list' import type { ListRef } from '@/app/components/workflow/block-selector/market-place-plugin/list'
import PluginList, { type ListProps } from '@/app/components/workflow/block-selector/market-place-plugin/list' import PluginList, { type ListProps } from '@/app/components/workflow/block-selector/market-place-plugin/list'
import ActionButton from '../../base/action-button'
import { RiAddLine } from '@remixicon/react'
import { PluginType } from '../../plugins/types' import { PluginType } from '../../plugins/types'
import { useMarketplacePlugins } from '../../plugins/marketplace/hooks' import { useMarketplacePlugins } from '../../plugins/marketplace/hooks'
import { useSelector as useAppContextSelector } from '@/context/app-context' import { useSelector as useAppContextSelector } from '@/context/app-context'
@ -33,9 +31,6 @@ type AllToolsProps = {
workflowTools: ToolWithProvider[] workflowTools: ToolWithProvider[]
mcpTools: ToolWithProvider[] mcpTools: ToolWithProvider[]
onSelect: OnSelectBlock onSelect: OnSelectBlock
supportAddCustomTool?: boolean
onAddedCustomTool?: () => void
onShowAddCustomCollectionModal?: () => void
selectedTools?: ToolValue[] selectedTools?: ToolValue[]
} }
@ -51,8 +46,6 @@ const AllTools = ({
workflowTools, workflowTools,
customTools, customTools,
mcpTools = [], mcpTools = [],
supportAddCustomTool,
onShowAddCustomCollectionModal,
selectedTools, selectedTools,
}: AllToolsProps) => { }: AllToolsProps) => {
const language = useGetLanguage() const language = useGetLanguage()
@ -107,6 +100,7 @@ const AllTools = ({
const pluginRef = useRef<ListRef>(null) const pluginRef = useRef<ListRef>(null)
const wrapElemRef = useRef<HTMLDivElement>(null) const wrapElemRef = useRef<HTMLDivElement>(null)
const isSupportGroupView = [ToolTypeEnum.All, ToolTypeEnum.BuiltIn].includes(activeTab)
return ( return (
<div className={cn(className)}> <div className={cn(className)}>
@ -128,17 +122,8 @@ const AllTools = ({
)) ))
} }
</div> </div>
{isSupportGroupView && (
<ViewTypeSelect viewType={activeView} onChange={setActiveView} /> <ViewTypeSelect viewType={activeView} onChange={setActiveView} />
{supportAddCustomTool && (
<div className='flex items-center'>
<div className='mr-1.5 h-3.5 w-px bg-divider-regular'></div>
<ActionButton
className='bg-components-button-primary-bg text-components-button-primary-text hover:bg-components-button-primary-bg hover:text-components-button-primary-text'
onClick={onShowAddCustomCollectionModal}
>
<RiAddLine className='h-4 w-4' />
</ActionButton>
</div>
)} )}
</div> </div>
<div <div
@ -151,7 +136,7 @@ const AllTools = ({
showWorkflowEmpty={activeTab === ToolTypeEnum.Workflow} showWorkflowEmpty={activeTab === ToolTypeEnum.Workflow}
tools={tools} tools={tools}
onSelect={onSelect} onSelect={onSelect}
viewType={activeView} viewType={isSupportGroupView ? activeView : ViewType.flat}
hasSearchText={!!searchText} hasSearchText={!!searchText}
selectedTools={selectedTools} selectedTools={selectedTools}
/> />

View File

@ -152,6 +152,10 @@ const ToolPicker: FC<Props> = ({
onTagsChange={setTags} onTagsChange={setTags}
size='small' size='small'
placeholder={t('plugin.searchTools')!} placeholder={t('plugin.searchTools')!}
supportAddCustomTool={supportAddCustomTool}
onAddedCustomTool={handleAddedCustomTool}
onShowAddCustomCollectionModal={showEditCustomCollectionModal}
/> />
</div> </div>
<AllTools <AllTools
@ -164,9 +168,7 @@ const ToolPicker: FC<Props> = ({
customTools={customToolList || []} customTools={customToolList || []}
workflowTools={workflowToolList || []} workflowTools={workflowToolList || []}
mcpTools={mcpTools || []} mcpTools={mcpTools || []}
supportAddCustomTool={supportAddCustomTool}
onAddedCustomTool={handleAddedCustomTool}
onShowAddCustomCollectionModal={showEditCustomCollectionModal}
selectedTools={selectedTools} selectedTools={selectedTools}
/> />
</div> </div>