index.tsx 3.0 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. useWorkflow,
  11. } from '../hooks'
  12. import DebugAndPreview from './debug-and-preview'
  13. import Record from './record'
  14. import WorkflowPreview from './workflow-preview'
  15. import ChatRecord from './chat-record'
  16. import ChatVariablePanel from './chat-variable-panel'
  17. import EnvPanel from './env-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 isRestoring = useStore(s => s.isRestoring)
  30. const {
  31. enableShortcuts,
  32. disableShortcuts,
  33. } = useWorkflow()
  34. const { currentLogItem, setCurrentLogItem, showMessageLogModal, setShowMessageLogModal, currentLogModalActiveTab } = useAppStore(useShallow(state => ({
  35. currentLogItem: state.currentLogItem,
  36. setCurrentLogItem: state.setCurrentLogItem,
  37. showMessageLogModal: state.showMessageLogModal,
  38. setShowMessageLogModal: state.setShowMessageLogModal,
  39. currentLogModalActiveTab: state.currentLogModalActiveTab,
  40. })))
  41. return (
  42. <div
  43. tabIndex={-1}
  44. className={cn('absolute top-14 right-0 bottom-2 flex z-10 outline-none')}
  45. onFocus={disableShortcuts}
  46. onBlur={enableShortcuts}
  47. key={`${isRestoring}`}
  48. >
  49. {
  50. showMessageLogModal && (
  51. <MessageLogModal
  52. fixedWidth
  53. width={400}
  54. currentLogItem={currentLogItem}
  55. onCancel={() => {
  56. setCurrentLogItem()
  57. setShowMessageLogModal(false)
  58. }}
  59. defaultTab={currentLogModalActiveTab}
  60. />
  61. )
  62. }
  63. {
  64. !!selectedNode && (
  65. <NodePanel {...selectedNode!} />
  66. )
  67. }
  68. {
  69. historyWorkflowData && !isChatMode && (
  70. <Record />
  71. )
  72. }
  73. {
  74. historyWorkflowData && isChatMode && (
  75. <ChatRecord />
  76. )
  77. }
  78. {
  79. showDebugAndPreviewPanel && isChatMode && (
  80. <DebugAndPreview />
  81. )
  82. }
  83. {
  84. showDebugAndPreviewPanel && !isChatMode && (
  85. <WorkflowPreview />
  86. )
  87. }
  88. {
  89. showEnvPanel && (
  90. <EnvPanel />
  91. )
  92. }
  93. {
  94. showChatVariablePanel && (
  95. <ChatVariablePanel />
  96. )
  97. }
  98. </div>
  99. )
  100. }
  101. export default memo(Panel)