Fix: conversation id display & support copy (#5195)

This commit is contained in:
KVOJJJin 2024-06-14 13:58:51 +08:00 committed by GitHub
parent ed53ef29f4
commit e68d1b88de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 1 deletions

View File

@ -44,6 +44,8 @@ import MessageLogModal from '@/app/components/base/message-log-modal'
import { useStore as useAppStore } from '@/app/components/app/store'
import { useAppContext } from '@/context/app-context'
import useTimestamp from '@/hooks/use-timestamp'
import TooltipPlus from '@/app/components/base/tooltip-plus'
import { CopyIcon } from '@/app/components/base/copy-icon'
dayjs.extend(utc)
dayjs.extend(timezone)
@ -281,7 +283,19 @@ function DetailPanel<T extends ChatConversationFullDetailResponse | CompletionCo
<div className='border-b border-gray-100 py-4 px-6 flex items-center justify-between'>
<div>
<div className='text-gray-500 text-[10px] leading-[14px]'>{isChatMode ? t('appLog.detail.conversationId') : t('appLog.detail.time')}</div>
<div className='text-gray-700 text-[13px] leading-[18px]'>{isChatMode ? detail.id?.split('-').slice(-1)[0] : formatTime(detail.created_at, t('appLog.dateTimeFormat') as string)}</div>
{isChatMode && (
<div className='flex items-center text-gray-700 text-[13px] leading-[18px]'>
<TooltipPlus
hideArrow
popupContent={detail.id}>
<div className='max-w-[105px] truncate'>{detail.id}</div>
</TooltipPlus>
<CopyIcon content={detail.id} />
</div>
)}
{!isChatMode && (
<div className='text-gray-700 text-[13px] leading-[18px]'>{formatTime(detail.created_at, t('appLog.dateTimeFormat') as string)}</div>
)}
</div>
<div className='flex items-center flex-wrap gap-y-1 justify-end'>
{!isAdvanced && (

View File

@ -0,0 +1,50 @@
'use client'
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { debounce } from 'lodash-es'
import copy from 'copy-to-clipboard'
import TooltipPlus from '../tooltip-plus'
import { Clipboard, ClipboardCheck } from '@/app/components/base/icons/src/vender/line/files'
type Props = {
content: string
}
const prefixEmbedded = 'appOverview.overview.appInfo.embedded'
export const CopyIcon = ({ content }: Props) => {
const { t } = useTranslation()
const [isCopied, setIsCopied] = useState<boolean>(false)
const onClickCopy = debounce(() => {
copy(content)
setIsCopied(true)
}, 100)
const onMouseLeave = debounce(() => {
setIsCopied(false)
}, 100)
return (
<TooltipPlus
popupContent={
(isCopied
? t(`${prefixEmbedded}.copied`)
: t(`${prefixEmbedded}.copy`)) || ''
}
>
<div onMouseLeave={onMouseLeave}>
{!isCopied
? (
<Clipboard className='mx-1 w-3 h-3 text-gray-500 cursor-pointer' onClick={onClickCopy} />
)
: (
<ClipboardCheck className='mx-1 w-3 h-3 text-gray-500' />
)
}
</div>
</TooltipPlus>
)
}
export default CopyIcon