index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { RiCloseLine } from '@remixicon/react'
  4. import { useEffect, useRef, useState } from 'react'
  5. import { useClickAway } from 'ahooks'
  6. import AgentLogDetail from './detail'
  7. import cn from '@/utils/classnames'
  8. import type { IChatItem } from '@/app/components/base/chat/chat/type'
  9. type AgentLogModalProps = {
  10. currentLogItem?: IChatItem
  11. width: number
  12. onCancel: () => void
  13. }
  14. const AgentLogModal: FC<AgentLogModalProps> = ({
  15. currentLogItem,
  16. width,
  17. onCancel,
  18. }) => {
  19. const { t } = useTranslation()
  20. const ref = useRef(null)
  21. const [mounted, setMounted] = useState(false)
  22. useClickAway(() => {
  23. if (mounted)
  24. onCancel()
  25. }, ref)
  26. useEffect(() => {
  27. setMounted(true)
  28. }, [])
  29. if (!currentLogItem || !currentLogItem.conversationId)
  30. return null
  31. return (
  32. <div
  33. className={cn('relative flex flex-col py-3 bg-white border-[0.5px] border-gray-200 rounded-xl shadow-xl z-10')}
  34. style={{
  35. width: 480,
  36. position: 'fixed',
  37. top: 56 + 8,
  38. left: 8 + (width - 480),
  39. bottom: 16,
  40. }}
  41. ref={ref}
  42. >
  43. <h1 className='shrink-0 px-4 py-1 text-md font-semibold text-gray-900'>{t('appLog.runDetail.workflowTitle')}</h1>
  44. <span className='absolute right-3 top-4 p-1 cursor-pointer z-20' onClick={onCancel}>
  45. <RiCloseLine className='w-4 h-4 text-gray-500' />
  46. </span>
  47. <AgentLogDetail
  48. conversationID={currentLogItem.conversationId}
  49. messageID={currentLogItem.id}
  50. log={currentLogItem}
  51. />
  52. </div>
  53. )
  54. }
  55. export default AgentLogModal