You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

result-tab.tsx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. memo,
  3. useEffect,
  4. } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import cn from '@/utils/classnames'
  7. // import Loading from '@/app/components/base/loading'
  8. import { Markdown } from '@/app/components/base/markdown'
  9. import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
  10. import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
  11. import type { WorkflowProcess } from '@/app/components/base/chat/types'
  12. // import { WorkflowRunningStatus } from '@/app/components/workflow/types'
  13. const ResultTab = ({
  14. data,
  15. content,
  16. currentTab,
  17. onCurrentTabChange,
  18. }: {
  19. data?: WorkflowProcess
  20. content: any
  21. currentTab: string
  22. onCurrentTabChange: (tab: string) => void
  23. }) => {
  24. const { t } = useTranslation()
  25. const switchTab = async (tab: string) => {
  26. onCurrentTabChange(tab)
  27. }
  28. useEffect(() => {
  29. if (data?.resultText)
  30. switchTab('RESULT')
  31. else
  32. switchTab('DETAIL')
  33. }, [data?.resultText])
  34. return (
  35. <div className='grow relative flex flex-col'>
  36. {data?.resultText && (
  37. <div className='shrink-0 flex items-center mb-2 border-b-[0.5px] border-[rgba(0,0,0,0.05)]'>
  38. <div
  39. className={cn(
  40. 'mr-6 py-3 border-b-2 border-transparent text-[13px] font-semibold leading-[18px] text-gray-400 cursor-pointer',
  41. currentTab === 'RESULT' && '!border-[rgb(21,94,239)] text-gray-700',
  42. )}
  43. onClick={() => switchTab('RESULT')}
  44. >{t('runLog.result')}</div>
  45. <div
  46. className={cn(
  47. 'mr-6 py-3 border-b-2 border-transparent text-[13px] font-semibold leading-[18px] text-gray-400 cursor-pointer',
  48. currentTab === 'DETAIL' && '!border-[rgb(21,94,239)] text-gray-700',
  49. )}
  50. onClick={() => switchTab('DETAIL')}
  51. >{t('runLog.detail')}</div>
  52. </div>
  53. )}
  54. <div className={cn('grow bg-white')}>
  55. {currentTab === 'RESULT' && (
  56. <Markdown content={data?.resultText || ''} />
  57. )}
  58. {currentTab === 'DETAIL' && content && (
  59. <CodeEditor
  60. readOnly
  61. title={<div>JSON OUTPUT</div>}
  62. language={CodeLanguage.json}
  63. value={content}
  64. isJSONStringifyBeauty
  65. />
  66. )}
  67. </div>
  68. </div>
  69. )
  70. }
  71. export default memo(ResultTab)