mirror of
https://github.com/langgenius/dify.git
synced 2026-06-20 09:02:30 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jerryzai <jerryzh8710@protonmail.com> Co-authored-by: NVIDIAN <speedy.hpc@hotmail.com> Co-authored-by: ai-hpc <ai-hpc@users.noreply.github.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Junghwan <70629228+shaun0927@users.noreply.github.com> Co-authored-by: HeYinKazune <70251095+HeYin-OS@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
113 lines
3.6 KiB
TypeScript
113 lines
3.6 KiB
TypeScript
'use client'
|
|
import type { FC } from 'react'
|
|
import { cn } from '@langgenius/dify-ui/cn'
|
|
import {
|
|
RiDeleteBinLine,
|
|
RiEditLine,
|
|
} from '@remixicon/react'
|
|
import { useBoolean } from 'ahooks'
|
|
import * as React from 'react'
|
|
import { useEffect, useState } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from '@/app/components/base/ui/dropdown-menu'
|
|
import { Pin02 } from '../../base/icons/src/vender/line/general'
|
|
import s from './style.module.css'
|
|
|
|
type IItemOperationProps = {
|
|
className?: string
|
|
isItemHovering?: boolean
|
|
isPinned: boolean
|
|
isShowRenameConversation?: boolean
|
|
onRenameConversation?: () => void
|
|
isShowDelete: boolean
|
|
togglePin: () => void
|
|
onDelete: () => void
|
|
}
|
|
|
|
const ItemOperation: FC<IItemOperationProps> = ({
|
|
className,
|
|
isItemHovering,
|
|
isPinned,
|
|
togglePin,
|
|
isShowRenameConversation,
|
|
onRenameConversation,
|
|
isShowDelete,
|
|
onDelete,
|
|
}) => {
|
|
const { t } = useTranslation('explore')
|
|
const { t: tCommon } = useTranslation('common')
|
|
const [open, setOpen] = useState(false)
|
|
const [isHovering, { setTrue: setIsHovering, setFalse: setNotHovering }] = useBoolean(false)
|
|
useEffect(() => {
|
|
if (!isItemHovering && !isHovering)
|
|
setOpen(false)
|
|
}, [isItemHovering, isHovering])
|
|
return (
|
|
<DropdownMenu
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
>
|
|
<DropdownMenuTrigger
|
|
data-testid="item-operation-trigger"
|
|
className={cn(className, s.btn, 'h-6 w-6 rounded-md border-none py-1', (isItemHovering || open) && `${s.open} bg-components-actionbar-bg! shadow-none!`)}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
}}
|
|
>
|
|
<span className="sr-only">{tCommon('operation.more')}</span>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
placement="bottom-end"
|
|
sideOffset={4}
|
|
popupClassName="min-w-[120px]"
|
|
popupProps={{
|
|
onMouseEnter: setIsHovering,
|
|
onMouseLeave: setNotHovering,
|
|
onClick: e => e.stopPropagation(),
|
|
}}
|
|
>
|
|
<DropdownMenuItem
|
|
className={cn(s.actionItem, 'gap-2 px-3')}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
togglePin()
|
|
}}
|
|
>
|
|
<Pin02 className="h-4 w-4 shrink-0 text-text-secondary" />
|
|
<span className={s.actionName}>{isPinned ? t('sidebar.action.unpin') : t('sidebar.action.pin')}</span>
|
|
</DropdownMenuItem>
|
|
{isShowRenameConversation && (
|
|
<DropdownMenuItem
|
|
className={cn(s.actionItem, 'gap-2 px-3')}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onRenameConversation?.()
|
|
}}
|
|
>
|
|
<RiEditLine className="h-4 w-4 shrink-0 text-text-secondary" />
|
|
<span className={s.actionName}>{t('sidebar.action.rename')}</span>
|
|
</DropdownMenuItem>
|
|
)}
|
|
{isShowDelete && (
|
|
<DropdownMenuItem
|
|
className={cn(s.actionItem, s.deleteActionItem, 'gap-2 px-3 data-highlighted:bg-state-destructive-hover data-highlighted:text-text-destructive')}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onDelete()
|
|
}}
|
|
>
|
|
<RiDeleteBinLine className={cn(s.deleteActionItemChild, 'h-4 w-4 shrink-0 stroke-current stroke-2 text-inherit')} />
|
|
<span className={cn(s.actionName, s.deleteActionItemChild, 'text-inherit')}>{t('sidebar.action.delete')}</span>
|
|
</DropdownMenuItem>
|
|
)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|
|
export default React.memo(ItemOperation)
|