index.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {
  2. memo,
  3. useRef,
  4. } from 'react'
  5. import { useKeyPress } from 'ahooks'
  6. import cn from 'classnames'
  7. import { useTranslation } from 'react-i18next'
  8. import {
  9. useEdgesInteractions,
  10. useNodesInteractions,
  11. useWorkflowInteractions,
  12. } from '../../hooks'
  13. import ChatWrapper from './chat-wrapper'
  14. import Button from '@/app/components/base/button'
  15. import { RefreshCcw01 } from '@/app/components/base/icons/src/vender/line/arrows'
  16. import { XClose } from '@/app/components/base/icons/src/vender/line/general'
  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. className='px-2 h-8 bg-white border-[0.5px] border-gray-200 shadow-xs rounded-lg text-xs text-gray-700 font-medium'
  50. onClick={() => handleRestartChat()}
  51. >
  52. <RefreshCcw01 className='shrink-0 mr-1 w-3 h-3 text-gray-500' />
  53. <div
  54. className='grow truncate uppercase'
  55. title={t('common.operation.refresh') || ''}
  56. >
  57. {t('common.operation.refresh')}
  58. </div>
  59. <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>
  60. <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>
  61. </Button>
  62. <div className='mx-3 w-[1px] h-3.5 bg-gray-200'></div>
  63. <div
  64. className='flex items-center justify-center w-6 h-6 cursor-pointer'
  65. onClick={handleCancelDebugAndPreviewPanel}
  66. >
  67. <XClose className='w-4 h-4 text-gray-500' />
  68. </div>
  69. </div>
  70. </div>
  71. <div className='grow rounded-b-2xl overflow-y-auto'>
  72. <ChatWrapper ref={chatRef} />
  73. </div>
  74. </div>
  75. )
  76. }
  77. export default memo(DebugAndPreview)