index.tsx 1.7 KB

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