index.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { useEffect, useRef, useState } from 'react'
  4. import { useClickAway } from 'ahooks'
  5. import { RiCloseLine } from '@remixicon/react'
  6. import cn from '@/utils/classnames'
  7. import type { IChatItem } from '@/app/components/base/chat/chat/type'
  8. import Run from '@/app/components/workflow/run'
  9. type MessageLogModalProps = {
  10. currentLogItem?: IChatItem
  11. defaultTab?: string
  12. width: number
  13. fixedWidth?: boolean
  14. onCancel: () => void
  15. }
  16. const MessageLogModal: FC<MessageLogModalProps> = ({
  17. currentLogItem,
  18. defaultTab = 'DETAIL',
  19. width,
  20. fixedWidth,
  21. onCancel,
  22. }) => {
  23. const { t } = useTranslation()
  24. const ref = useRef(null)
  25. const [mounted, setMounted] = useState(false)
  26. useClickAway(() => {
  27. if (mounted)
  28. onCancel()
  29. }, ref)
  30. useEffect(() => {
  31. setMounted(true)
  32. }, [])
  33. if (!currentLogItem || !currentLogItem.workflow_run_id)
  34. return null
  35. return (
  36. <div
  37. className={cn('relative flex flex-col pt-3 bg-components-panel-bg border-[0.5px] border-components-panel-border rounded-xl shadow-xl z-10')}
  38. style={{
  39. width: fixedWidth ? width : 480,
  40. ...(!fixedWidth
  41. ? {
  42. position: 'fixed',
  43. top: 56 + 8,
  44. left: 8 + (width - 480),
  45. bottom: 16,
  46. }
  47. : {
  48. marginRight: 8,
  49. }),
  50. }}
  51. ref={ref}
  52. >
  53. <h1 className='shrink-0 px-4 py-1 text-text-primary system-xl-semibold'>{t('appLog.runDetail.title')}</h1>
  54. <span className='absolute right-3 top-4 p-1 cursor-pointer z-20' onClick={onCancel}>
  55. <RiCloseLine className='w-4 h-4 text-text-tertiary' />
  56. </span>
  57. <Run
  58. hideResult
  59. activeTab={defaultTab as any}
  60. runID={currentLogItem.workflow_run_id}
  61. />
  62. </div>
  63. )
  64. }
  65. export default MessageLogModal