index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import { useNodes } from 'reactflow'
  4. import cn from 'classnames'
  5. import { useShallow } from 'zustand/react/shallow'
  6. import type { CommonNodeType } from '../types'
  7. import { Panel as NodePanel } from '../nodes'
  8. import { useStore } from '../store'
  9. import {
  10. useIsChatMode,
  11. useWorkflow,
  12. } from '../hooks'
  13. import DebugAndPreview from './debug-and-preview'
  14. import Record from './record'
  15. import WorkflowPreview from './workflow-preview'
  16. import ChatRecord from './chat-record'
  17. import { useStore as useAppStore } from '@/app/components/app/store'
  18. import MessageLogModal from '@/app/components/base/message-log-modal'
  19. const Panel: FC = () => {
  20. const nodes = useNodes<CommonNodeType>()
  21. const isChatMode = useIsChatMode()
  22. const selectedNode = nodes.find(node => node.data.selected)
  23. const historyWorkflowData = useStore(s => s.historyWorkflowData)
  24. const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel)
  25. const isRestoring = useStore(s => s.isRestoring)
  26. const {
  27. enableShortcuts,
  28. disableShortcuts,
  29. } = useWorkflow()
  30. const { currentLogItem, setCurrentLogItem, showMessageLogModal, setShowMessageLogModal, currentLogModalActiveTab } = useAppStore(useShallow(state => ({
  31. currentLogItem: state.currentLogItem,
  32. setCurrentLogItem: state.setCurrentLogItem,
  33. showMessageLogModal: state.showMessageLogModal,
  34. setShowMessageLogModal: state.setShowMessageLogModal,
  35. currentLogModalActiveTab: state.currentLogModalActiveTab,
  36. })))
  37. return (
  38. <div
  39. tabIndex={-1}
  40. className={cn(
  41. 'absolute top-14 right-0 bottom-2 flex z-10 outline-none',
  42. )}
  43. onFocus={disableShortcuts}
  44. onBlur={enableShortcuts}
  45. key={`${isRestoring}`}
  46. >
  47. {
  48. showMessageLogModal && (
  49. <MessageLogModal
  50. fixedWidth
  51. width={400}
  52. currentLogItem={currentLogItem}
  53. onCancel={() => {
  54. setCurrentLogItem()
  55. setShowMessageLogModal(false)
  56. }}
  57. defaultTab={currentLogModalActiveTab}
  58. />
  59. )
  60. }
  61. {
  62. !!selectedNode && (
  63. <NodePanel {...selectedNode!} />
  64. )
  65. }
  66. {
  67. historyWorkflowData && !isChatMode && (
  68. <Record />
  69. )
  70. }
  71. {
  72. historyWorkflowData && isChatMode && (
  73. <ChatRecord />
  74. )
  75. }
  76. {
  77. showDebugAndPreviewPanel && isChatMode && (
  78. <DebugAndPreview />
  79. )
  80. }
  81. {
  82. showDebugAndPreviewPanel && !isChatMode && (
  83. <WorkflowPreview />
  84. )
  85. }
  86. </div>
  87. )
  88. }
  89. export default memo(Panel)