index.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import cn from 'classnames'
  4. import { useCallback, useEffect, useRef, useState } from 'react'
  5. import { useBoolean, useClickAway } from 'ahooks'
  6. import { RiCloseLine } from '@remixicon/react'
  7. import IterationResultPanel from '../../workflow/run/iteration-result-panel'
  8. import type { IChatItem } from '@/app/components/base/chat/chat/type'
  9. import Run from '@/app/components/workflow/run'
  10. import type { NodeTracing } from '@/types/workflow'
  11. type MessageLogModalProps = {
  12. currentLogItem?: IChatItem
  13. defaultTab?: string
  14. width: number
  15. fixedWidth?: boolean
  16. onCancel: () => void
  17. }
  18. const MessageLogModal: FC<MessageLogModalProps> = ({
  19. currentLogItem,
  20. defaultTab = 'DETAIL',
  21. width,
  22. fixedWidth,
  23. onCancel,
  24. }) => {
  25. const { t } = useTranslation()
  26. const ref = useRef(null)
  27. const [mounted, setMounted] = useState(false)
  28. useClickAway(() => {
  29. if (mounted)
  30. onCancel()
  31. }, ref)
  32. useEffect(() => {
  33. setMounted(true)
  34. }, [])
  35. const [iterationRunResult, setIterationRunResult] = useState<NodeTracing[][]>([])
  36. const [isShowIterationDetail, {
  37. setTrue: doShowIterationDetail,
  38. setFalse: doHideIterationDetail,
  39. }] = useBoolean(false)
  40. const handleShowIterationDetail = useCallback((detail: NodeTracing[][]) => {
  41. setIterationRunResult(detail)
  42. doShowIterationDetail()
  43. }, [doShowIterationDetail])
  44. if (!currentLogItem || !currentLogItem.workflow_run_id)
  45. return null
  46. return (
  47. <div
  48. className={cn('relative flex flex-col py-3 bg-white border-[0.5px] border-gray-200 rounded-xl shadow-xl z-10')}
  49. style={{
  50. width: fixedWidth ? width : 480,
  51. ...(!fixedWidth
  52. ? {
  53. position: 'fixed',
  54. top: 56 + 8,
  55. left: 8 + (width - 480),
  56. bottom: 16,
  57. }
  58. : {
  59. marginRight: 8,
  60. }),
  61. }}
  62. ref={ref}
  63. >
  64. {isShowIterationDetail
  65. ? (
  66. <IterationResultPanel
  67. list={iterationRunResult}
  68. onHide={doHideIterationDetail}
  69. onBack={doHideIterationDetail}
  70. />
  71. )
  72. : (
  73. <>
  74. <h1 className='shrink-0 px-4 py-1 text-md font-semibold text-gray-900'>{t('appLog.runDetail.title')}</h1>
  75. <span className='absolute right-3 top-4 p-1 cursor-pointer z-20' onClick={onCancel}>
  76. <RiCloseLine className='w-4 h-4 text-gray-500' />
  77. </span>
  78. <Run
  79. hideResult activeTab={defaultTab as any}
  80. runID={currentLogItem.workflow_run_id}
  81. onShowIterationDetail={handleShowIterationDetail}
  82. />
  83. </>
  84. )}
  85. </div>
  86. )
  87. }
  88. export default MessageLogModal