index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 VersionHistoryPanel from './version-history-panel'
  19. import cn from '@/utils/classnames'
  20. import { useStore as useAppStore } from '@/app/components/app/store'
  21. import MessageLogModal from '@/app/components/base/message-log-modal'
  22. const Panel: FC = () => {
  23. const nodes = useNodes<CommonNodeType>()
  24. const isChatMode = useIsChatMode()
  25. const selectedNode = nodes.find(node => node.data.selected)
  26. const historyWorkflowData = useStore(s => s.historyWorkflowData)
  27. const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel)
  28. const showEnvPanel = useStore(s => s.showEnvPanel)
  29. const showChatVariablePanel = useStore(s => s.showChatVariablePanel)
  30. const showGlobalVariablePanel = useStore(s => s.showGlobalVariablePanel)
  31. const showWorkflowVersionHistoryPanel = useStore(s => s.showWorkflowVersionHistoryPanel)
  32. const isRestoring = useStore(s => s.isRestoring)
  33. const { currentLogItem, setCurrentLogItem, showMessageLogModal, setShowMessageLogModal, currentLogModalActiveTab } = useAppStore(useShallow(state => ({
  34. currentLogItem: state.currentLogItem,
  35. setCurrentLogItem: state.setCurrentLogItem,
  36. showMessageLogModal: state.showMessageLogModal,
  37. setShowMessageLogModal: state.setShowMessageLogModal,
  38. currentLogModalActiveTab: state.currentLogModalActiveTab,
  39. })))
  40. return (
  41. <div
  42. tabIndex={-1}
  43. className={cn('absolute bottom-2 right-0 top-14 z-10 flex outline-none')}
  44. key={`${isRestoring}`}
  45. >
  46. {
  47. showMessageLogModal && (
  48. <MessageLogModal
  49. fixedWidth
  50. width={400}
  51. currentLogItem={currentLogItem}
  52. onCancel={() => {
  53. setCurrentLogItem()
  54. setShowMessageLogModal(false)
  55. }}
  56. defaultTab={currentLogModalActiveTab}
  57. />
  58. )
  59. }
  60. {
  61. !!selectedNode && (
  62. <NodePanel {...selectedNode!} />
  63. )
  64. }
  65. {
  66. historyWorkflowData && !isChatMode && (
  67. <Record />
  68. )
  69. }
  70. {
  71. historyWorkflowData && isChatMode && (
  72. <ChatRecord />
  73. )
  74. }
  75. {
  76. showDebugAndPreviewPanel && isChatMode && (
  77. <DebugAndPreview />
  78. )
  79. }
  80. {
  81. showDebugAndPreviewPanel && !isChatMode && (
  82. <WorkflowPreview />
  83. )
  84. }
  85. {
  86. showEnvPanel && (
  87. <EnvPanel />
  88. )
  89. }
  90. {
  91. showChatVariablePanel && (
  92. <ChatVariablePanel />
  93. )
  94. }
  95. {
  96. showGlobalVariablePanel && (
  97. <GlobalVariablePanel />
  98. )
  99. }
  100. {
  101. showWorkflowVersionHistoryPanel && (
  102. <VersionHistoryPanel/>
  103. )
  104. }
  105. </div>
  106. )
  107. }
  108. export default memo(Panel)