mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 22:35:55 +08:00
fix: dynamically generate the category menu on the create app page
This commit is contained in:
parent
0e68e8b40a
commit
bfe2d79295
@ -191,7 +191,7 @@ const Apps = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className='relative flex flex-1 overflow-y-auto'>
|
<div className='relative flex flex-1 overflow-y-auto'>
|
||||||
{!searchKeywords && <div className='h-full w-[200px] p-4'>
|
{!searchKeywords && <div className='h-full w-[200px] p-4'>
|
||||||
<Sidebar current={currCategory as AppCategories} onClick={(category) => { setCurrCategory(category) }} onCreateFromBlank={onCreateFromBlank} />
|
<Sidebar current={currCategory as AppCategories} categories={categories} onClick={(category) => { setCurrCategory(category) }} onCreateFromBlank={onCreateFromBlank} />
|
||||||
</div>}
|
</div>}
|
||||||
<div className='h-full flex-1 shrink-0 grow overflow-auto border-l border-divider-burn p-6 pt-2'>
|
<div className='h-full flex-1 shrink-0 grow overflow-auto border-l border-divider-burn p-6 pt-2'>
|
||||||
{searchFilteredList && searchFilteredList.length > 0 && <>
|
{searchFilteredList && searchFilteredList.length > 0 && <>
|
||||||
|
@ -1,26 +1,21 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { RiAppsFill, RiChatSmileAiFill, RiExchange2Fill, RiPassPendingFill, RiQuillPenAiFill, RiSpeakAiFill, RiStickyNoteAddLine, RiTerminalBoxFill, RiThumbUpFill } from '@remixicon/react'
|
import { RiStickyNoteAddLine, RiThumbUpFill } from '@remixicon/react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import classNames from '@/utils/classnames'
|
import classNames from '@/utils/classnames'
|
||||||
import Divider from '@/app/components/base/divider'
|
import Divider from '@/app/components/base/divider'
|
||||||
|
|
||||||
export enum AppCategories {
|
export enum AppCategories {
|
||||||
RECOMMENDED = 'Recommended',
|
RECOMMENDED = 'Recommended',
|
||||||
ASSISTANT = 'Assistant',
|
|
||||||
AGENT = 'Agent',
|
|
||||||
HR = 'HR',
|
|
||||||
PROGRAMMING = 'Programming',
|
|
||||||
WORKFLOW = 'Workflow',
|
|
||||||
WRITING = 'Writing',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SidebarProps = {
|
type SidebarProps = {
|
||||||
current: AppCategories
|
current: AppCategories | string
|
||||||
onClick?: (category: AppCategories) => void
|
categories: string[]
|
||||||
|
onClick?: (category: AppCategories | string) => void
|
||||||
onCreateFromBlank?: () => void
|
onCreateFromBlank?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Sidebar({ current, onClick, onCreateFromBlank }: SidebarProps) {
|
export default function Sidebar({ current, categories, onClick, onCreateFromBlank }: SidebarProps) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
return <div className="flex h-full w-full flex-col">
|
return <div className="flex h-full w-full flex-col">
|
||||||
<ul>
|
<ul>
|
||||||
@ -28,12 +23,7 @@ export default function Sidebar({ current, onClick, onCreateFromBlank }: Sidebar
|
|||||||
</ul>
|
</ul>
|
||||||
<div className='system-xs-medium-uppercase px-3 pb-1 pt-2 text-text-tertiary'>{t('app.newAppFromTemplate.byCategories')}</div>
|
<div className='system-xs-medium-uppercase px-3 pb-1 pt-2 text-text-tertiary'>{t('app.newAppFromTemplate.byCategories')}</div>
|
||||||
<ul className='flex grow flex-col gap-0.5'>
|
<ul className='flex grow flex-col gap-0.5'>
|
||||||
<CategoryItem category={AppCategories.ASSISTANT} active={current === AppCategories.ASSISTANT} onClick={onClick} />
|
{categories.map(category => (<CategoryItem key={category} category={category} active={current === category} onClick={onClick} />))}
|
||||||
<CategoryItem category={AppCategories.AGENT} active={current === AppCategories.AGENT} onClick={onClick} />
|
|
||||||
<CategoryItem category={AppCategories.HR} active={current === AppCategories.HR} onClick={onClick} />
|
|
||||||
<CategoryItem category={AppCategories.PROGRAMMING} active={current === AppCategories.PROGRAMMING} onClick={onClick} />
|
|
||||||
<CategoryItem category={AppCategories.WORKFLOW} active={current === AppCategories.WORKFLOW} onClick={onClick} />
|
|
||||||
<CategoryItem category={AppCategories.WRITING} active={current === AppCategories.WRITING} onClick={onClick} />
|
|
||||||
</ul>
|
</ul>
|
||||||
<Divider bgStyle='gradient' />
|
<Divider bgStyle='gradient' />
|
||||||
<div className='flex cursor-pointer items-center gap-1 px-3 py-1 text-text-tertiary' onClick={onCreateFromBlank}>
|
<div className='flex cursor-pointer items-center gap-1 px-3 py-1 text-text-tertiary' onClick={onCreateFromBlank}>
|
||||||
@ -45,47 +35,25 @@ export default function Sidebar({ current, onClick, onCreateFromBlank }: Sidebar
|
|||||||
|
|
||||||
type CategoryItemProps = {
|
type CategoryItemProps = {
|
||||||
active: boolean
|
active: boolean
|
||||||
category: AppCategories
|
category: AppCategories | string
|
||||||
onClick?: (category: AppCategories) => void
|
onClick?: (category: AppCategories | string) => void
|
||||||
}
|
}
|
||||||
function CategoryItem({ category, active, onClick }: CategoryItemProps) {
|
function CategoryItem({ category, active, onClick }: CategoryItemProps) {
|
||||||
return <li
|
return <li
|
||||||
className={classNames('p-1 pl-3 rounded-lg flex items-center gap-2 group cursor-pointer hover:bg-state-base-hover [&.active]:bg-state-base-active', active && 'active')}
|
className={classNames('p-1 pl-3 rounded-lg flex items-center gap-2 group cursor-pointer hover:bg-state-base-hover [&.active]:bg-state-base-active', active && 'active')}
|
||||||
onClick={() => { onClick?.(category) }}>
|
onClick={() => { onClick?.(category) }}>
|
||||||
<div className='inline-flex h-5 w-5 items-center justify-center rounded-md border border-divider-regular bg-components-icon-bg-midnight-solid group-[.active]:bg-components-icon-bg-blue-solid'>
|
{category === AppCategories.RECOMMENDED && <div className='inline-flex h-5 w-5 items-center justify-center rounded-md border border-divider-regular bg-components-icon-bg-midnight-solid group-[.active]:bg-components-icon-bg-blue-solid'>
|
||||||
<AppCategoryIcon category={category} />
|
<RiThumbUpFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
||||||
</div>
|
</div>}
|
||||||
<AppCategoryLabel category={category}
|
<AppCategoryLabel category={category}
|
||||||
className={classNames('system-sm-medium text-components-menu-item-text group-[.active]:text-components-menu-item-text-active group-hover:text-components-menu-item-text-hover', active && 'system-sm-semibold')} />
|
className={classNames('system-sm-medium text-components-menu-item-text group-[.active]:text-components-menu-item-text-active group-hover:text-components-menu-item-text-hover', active && 'system-sm-semibold')} />
|
||||||
</li >
|
</li >
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppCategoryLabelProps = {
|
type AppCategoryLabelProps = {
|
||||||
category: AppCategories
|
category: AppCategories | string
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
export function AppCategoryLabel({ category, className }: AppCategoryLabelProps) {
|
export function AppCategoryLabel({ category, className }: AppCategoryLabelProps) {
|
||||||
const { t } = useTranslation()
|
return <span className={className}>{category}</span>
|
||||||
return <span className={className}>{t(`app.newAppFromTemplate.sidebar.${category}`)}</span>
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppCategoryIconProps = {
|
|
||||||
category: AppCategories
|
|
||||||
}
|
|
||||||
function AppCategoryIcon({ category }: AppCategoryIconProps) {
|
|
||||||
if (category === AppCategories.AGENT)
|
|
||||||
return <RiSpeakAiFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
if (category === AppCategories.ASSISTANT)
|
|
||||||
return <RiChatSmileAiFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
if (category === AppCategories.HR)
|
|
||||||
return <RiPassPendingFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
if (category === AppCategories.PROGRAMMING)
|
|
||||||
return <RiTerminalBoxFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
if (category === AppCategories.RECOMMENDED)
|
|
||||||
return <RiThumbUpFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
if (category === AppCategories.WRITING)
|
|
||||||
return <RiQuillPenAiFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
if (category === AppCategories.WORKFLOW)
|
|
||||||
return <RiExchange2Fill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
return <RiAppsFill className='h-3.5 w-3.5 text-components-avatar-shape-fill-stop-100' />
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user