feat: view to ui and fix some ui promblem

This commit is contained in:
Joel 2024-10-12 18:15:11 +08:00
parent b8cd6ea478
commit 0e5c16d0c2
4 changed files with 36 additions and 19 deletions

View File

@ -75,6 +75,7 @@ const AllTools = ({
showWorkflowEmpty={activeTab === ToolTypeEnum.Workflow} showWorkflowEmpty={activeTab === ToolTypeEnum.Workflow}
tools={tools} tools={tools}
onSelect={onSelect} onSelect={onSelect}
viewType={activeView}
/> />
</div> </div>
) )

View File

@ -47,9 +47,10 @@ const IndexBar: FC<IndexBarProps> = ({ letters, itemRefs }) => {
element.scrollIntoView({ behavior: 'smooth' }) element.scrollIntoView({ behavior: 'smooth' })
} }
return ( return (
<div className="index-bar absolute right-4 top-36 flex flex-col items-center text-xs font-medium text-gray-500"> <div className="index-bar absolute right-4 top-36 flex flex-col items-center w-6 justify-center text-xs font-medium text-text-quaternary ">
<div className='absolute left-0 top-0 h-full w-px bg-[linear-gradient(270deg,rgba(255,255,255,0)_0%,rgba(16,24,40,0.08)_30%,rgba(16,24,40,0.08)_50%,rgba(16,24,40,0.08)_70.5%,rgba(255,255,255,0)_100%)]'></div>
{letters.map(letter => ( {letters.map(letter => (
<div className="hover:text-gray-900 cursor-pointer" key={letter} onClick={() => handleIndexClick(letter)}> <div className="hover:text-text-secondary cursor-pointer" key={letter} onClick={() => handleIndexClick(letter)}>
{letter} {letter}
</div> </div>
))} ))}

View File

@ -1,7 +1,7 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React from 'react' import React from 'react'
import { RiArrowRightSLine } from '@remixicon/react' import { RiArrowDownSLine, RiArrowRightSLine } from '@remixicon/react'
import { useBoolean } from 'ahooks' import { useBoolean } from 'ahooks'
import BlockIcon from '../block-icon' import BlockIcon from '../block-icon'
import type { ToolWithProvider } from '../types' import type { ToolWithProvider } from '../types'
@ -10,8 +10,10 @@ import type { ToolDefaultValue } from './types'
import Tooltip from '@/app/components/base/tooltip' import Tooltip from '@/app/components/base/tooltip'
import type { Tool } from '@/app/components/tools/types' import type { Tool } from '@/app/components/tools/types'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
import cn from '@/utils/classnames'
type Props = { type Props = {
className?: string
isToolPlugin: boolean // Tool plugin should choose action isToolPlugin: boolean // Tool plugin should choose action
provider: ToolWithProvider provider: ToolWithProvider
payload: Tool payload: Tool
@ -19,6 +21,7 @@ type Props = {
} }
const ToolItem: FC<Props> = ({ const ToolItem: FC<Props> = ({
className,
isToolPlugin, isToolPlugin,
provider, provider,
payload, payload,
@ -27,7 +30,9 @@ const ToolItem: FC<Props> = ({
const language = useGetLanguage() const language = useGetLanguage()
const [isFold, { const [isFold, {
toggle: toggleFold, toggle: toggleFold,
}] = useBoolean(true) }] = useBoolean(false)
const FoldIcon = isFold ? RiArrowDownSLine : RiArrowRightSLine
const actions = [ const actions = [
'DuckDuckGo AI Search', 'DuckDuckGo AI Search',
@ -52,9 +57,9 @@ const ToolItem: FC<Props> = ({
</div> </div>
)} )}
> >
<div> <div className={cn(className)}>
<div <div
className='flex items-center px-3 w-full h-8 rounded-lg hover:bg-gray-50 cursor-pointer' className='flex items-center justify-between pl-3 pr-1 w-full rounded-lg hover:bg-gray-50 cursor-pointer'
onClick={() => { onClick={() => {
if (isToolPlugin) { if (isToolPlugin) {
toggleFold() toggleFold()
@ -70,22 +75,24 @@ const ToolItem: FC<Props> = ({
}) })
}} }}
> >
<div className='flex items-center h-8'>
<BlockIcon
className='shrink-0'
type={BlockEnum.Tool}
toolIcon={provider.icon}
/>
<div className='ml-2 text-sm text-gray-900 flex-1 min-w-0 truncate'>{payload.label[language]}</div>
</div>
{isToolPlugin && ( {isToolPlugin && (
<RiArrowRightSLine className='mr-1 w-4 h-4 text-text-quaternary shrink-0' /> <FoldIcon className={cn('w-4 h-4 text-text-quaternary shrink-0', isFold && 'text-text-tertiary')} />
)} )}
<BlockIcon
className='mr-2 shrink-0'
type={BlockEnum.Tool}
toolIcon={provider.icon}
/>
<div className='text-sm text-gray-900 flex-1 min-w-0 truncate'>{payload.label[language]}</div>
</div> </div>
{(!isFold && isToolPlugin) && ( {(!isFold && isToolPlugin) && (
<div> <div>
{actions.map(action => ( {actions.map(action => (
<div <div
key={action} key={action}
className='rounded-lg pl-[37px] hover:bg-state-base-hover cursor-pointer' className='rounded-lg pl-[21px] hover:bg-state-base-hover cursor-pointer'
onClick={() => { onClick={() => {
onSelect(BlockEnum.Tool, { onSelect(BlockEnum.Tool, {
provider_id: provider.id, provider_id: provider.id,
@ -97,7 +104,7 @@ const ToolItem: FC<Props> = ({
}) })
}} }}
> >
<div className='h-8 leading-8 border-l-2 border-divider-subtle pl-[19px] truncate text-text-secondary system-sm-medium'>{action}</div> <div className='h-8 leading-8 border-l-2 border-divider-subtle pl-4 truncate text-text-secondary system-sm-medium'>{action}</div>
</div> </div>
))} ))}
</div> </div>

View File

@ -9,6 +9,7 @@ import { CollectionType } from '../../tools/types'
import IndexBar, { groupItems } from './index-bar' import IndexBar, { groupItems } from './index-bar'
import type { ToolDefaultValue } from './types' import type { ToolDefaultValue } from './types'
import ToolItem from './tool-item' import ToolItem from './tool-item'
import { ViewType } from './view-type-select'
import Empty from '@/app/components/tools/add-tool-modal/empty' import Empty from '@/app/components/tools/add-tool-modal/empty'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
@ -16,14 +17,18 @@ type ToolsProps = {
showWorkflowEmpty: boolean showWorkflowEmpty: boolean
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
tools: ToolWithProvider[] tools: ToolWithProvider[]
viewType: ViewType
} }
const Blocks = ({ const Blocks = ({
showWorkflowEmpty, showWorkflowEmpty,
onSelect, onSelect,
tools, tools,
viewType,
}: ToolsProps) => { }: ToolsProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const language = useGetLanguage() const language = useGetLanguage()
const isListView = viewType === ViewType.list
const isTreeView = viewType === ViewType.tree
const { letters, groups: groupedTools } = groupItems(tools, tool => tool.label[language][0]) const { letters, groups: groupedTools } = groupItems(tools, tool => tool.label[language][0])
const toolRefs = useRef({}) const toolRefs = useRef({})
@ -36,13 +41,16 @@ const Blocks = ({
key={toolWithProvider.id} key={toolWithProvider.id}
className='mb-1 last-of-type:mb-0' className='mb-1 last-of-type:mb-0'
> >
<div className='flex items-start px-3 h-[22px] text-xs font-medium text-gray-500'> {isTreeView && (
{toolWithProvider.label[language]} <div className='flex items-start px-3 h-[22px] text-xs font-medium text-gray-500'>
</div> {toolWithProvider.label[language]}
</div>
)}
{ {
list.map(tool => ( list.map(tool => (
<ToolItem <ToolItem
key={tool.name} key={tool.name}
className={isListView && 'mr-6'}
isToolPlugin={toolWithProvider.type === CollectionType.builtIn} isToolPlugin={toolWithProvider.type === CollectionType.builtIn}
provider={toolWithProvider} provider={toolWithProvider}
payload={tool} payload={tool}
@ -79,7 +87,7 @@ const Blocks = ({
</div> </div>
)} )}
{!!tools.length && letters.map(renderLetterGroup)} {!!tools.length && letters.map(renderLetterGroup)}
{tools.length > 10 && <IndexBar letters={letters} itemRefs={toolRefs} />} {isListView && tools.length > 10 && <IndexBar letters={letters} itemRefs={toolRefs} />}
</div> </div>
) )
} }