output-panel.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use client'
  2. import type { FC } from 'react'
  3. import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
  4. import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
  5. import { Markdown } from '@/app/components/base/markdown'
  6. import LoadingAnim from '@/app/components/base/chat/chat/loading-anim'
  7. import StatusContainer from '@/app/components/workflow/run/status-container'
  8. type OutputPanelProps = {
  9. isRunning?: boolean
  10. outputs?: any
  11. error?: string
  12. height?: number
  13. }
  14. const OutputPanel: FC<OutputPanelProps> = ({
  15. isRunning,
  16. outputs,
  17. error,
  18. height,
  19. }) => {
  20. return (
  21. <div className='py-2'>
  22. {isRunning && (
  23. <div className='pt-4 pl-[26px]'>
  24. <LoadingAnim type='text' />
  25. </div>
  26. )}
  27. {!isRunning && error && (
  28. <div className='px-4'>
  29. <StatusContainer status='failed'>{error}</StatusContainer>
  30. </div>
  31. )}
  32. {!isRunning && !outputs && (
  33. <div className='px-4 py-2'>
  34. <Markdown content='No Output' />
  35. </div>
  36. )}
  37. {outputs && Object.keys(outputs).length === 1 && (
  38. <div className='px-4 py-2'>
  39. <Markdown content={outputs[Object.keys(outputs)[0]] || ''} />
  40. </div>
  41. )}
  42. {outputs && Object.keys(outputs).length > 1 && height! > 0 && (
  43. <div className='px-4 py-2 flex flex-col gap-2'>
  44. <CodeEditor
  45. readOnly
  46. title={<div></div>}
  47. language={CodeLanguage.json}
  48. value={outputs}
  49. isJSONStringifyBeauty
  50. height={height}
  51. />
  52. </div>
  53. )}
  54. </div>
  55. )
  56. }
  57. export default OutputPanel