index.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 z-10 flex flex-col rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg py-3 shadow-xl')}
  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='text-md shrink-0 px-4 py-1 font-semibold text-text-primary'>{t('appLog.runDetail.workflowTitle')}</h1>
  44. <span className='absolute right-3 top-4 z-20 cursor-pointer p-1' onClick={onCancel}>
  45. <RiCloseLine className='h-4 w-4 text-text-tertiary' />
  46. </span>
  47. <AgentLogDetail
  48. conversationID={currentLogItem.conversationId}
  49. messageID={currentLogItem.id}
  50. log={currentLogItem}
  51. />
  52. </div>
  53. )
  54. }
  55. export default AgentLogModal