index.tsx 3.1 KB

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