index.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {
  2. memo,
  3. useRef,
  4. } from 'react'
  5. import { useKeyPress } from 'ahooks'
  6. import cn from 'classnames'
  7. import { RiCloseLine } from '@remixicon/react'
  8. import { useTranslation } from 'react-i18next'
  9. import {
  10. useEdgesInteractions,
  11. useNodesInteractions,
  12. useWorkflowInteractions,
  13. } from '../../hooks'
  14. import ChatWrapper from './chat-wrapper'
  15. import Button from '@/app/components/base/button'
  16. import { RefreshCcw01 } from '@/app/components/base/icons/src/vender/line/arrows'
  17. export type ChatWrapperRefType = {
  18. handleRestart: () => void
  19. }
  20. const DebugAndPreview = () => {
  21. const { t } = useTranslation()
  22. const chatRef = useRef({ handleRestart: () => { } })
  23. const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions()
  24. const { handleNodeCancelRunningStatus } = useNodesInteractions()
  25. const { handleEdgeCancelRunningStatus } = useEdgesInteractions()
  26. const handleRestartChat = () => {
  27. handleNodeCancelRunningStatus()
  28. handleEdgeCancelRunningStatus()
  29. chatRef.current.handleRestart()
  30. }
  31. useKeyPress('shift.r', () => {
  32. handleRestartChat()
  33. }, {
  34. exactMatch: true,
  35. })
  36. return (
  37. <div
  38. className={cn(
  39. 'flex flex-col w-[400px] rounded-l-2xl h-full border border-black/2',
  40. )}
  41. style={{
  42. background: 'linear-gradient(156deg, rgba(242, 244, 247, 0.80) 0%, rgba(242, 244, 247, 0.00) 99.43%), var(--white, #FFF)',
  43. }}
  44. >
  45. <div className='shrink-0 flex items-center justify-between pl-4 pr-3 pt-3 pb-2 font-semibold text-gray-900'>
  46. {t('workflow.common.debugAndPreview').toLocaleUpperCase()}
  47. <div className='flex items-center'>
  48. <Button
  49. onClick={() => handleRestartChat()}
  50. >
  51. <RefreshCcw01 className='shrink-0 mr-1 w-3 h-3 text-gray-500' />
  52. <div
  53. className='grow truncate uppercase'
  54. title={t('common.operation.refresh') || ''}
  55. >
  56. {t('common.operation.refresh')}
  57. </div>
  58. <div className='shrink-0 ml-1 px-1 leading-[18px] rounded-md border border-gray-200 bg-gray-50 text-[11px] text-gray-500 font-medium'>Shift</div>
  59. <div className='shrink-0 ml-0.5 px-1 leading-[18px] rounded-md border border-gray-200 bg-gray-50 text-[11px] text-gray-500 font-medium'>R</div>
  60. </Button>
  61. <div className='mx-3 w-[1px] h-3.5 bg-gray-200'></div>
  62. <div
  63. className='flex items-center justify-center w-6 h-6 cursor-pointer'
  64. onClick={handleCancelDebugAndPreviewPanel}
  65. >
  66. <RiCloseLine className='w-4 h-4 text-gray-500' />
  67. </div>
  68. </div>
  69. </div>
  70. <div className='grow rounded-b-2xl overflow-y-auto'>
  71. <ChatWrapper ref={chatRef} />
  72. </div>
  73. </div>
  74. )
  75. }
  76. export default memo(DebugAndPreview)