index.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 EnvPanel from './env-panel'
  17. import cn from '@/utils/classnames'
  18. import { useStore as useAppStore } from '@/app/components/app/store'
  19. import MessageLogModal from '@/app/components/base/message-log-modal'
  20. const Panel: FC = () => {
  21. const nodes = useNodes<CommonNodeType>()
  22. const isChatMode = useIsChatMode()
  23. const selectedNode = nodes.find(node => node.data.selected)
  24. const historyWorkflowData = useStore(s => s.historyWorkflowData)
  25. const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel)
  26. const showEnvPanel = useStore(s => s.showEnvPanel)
  27. const isRestoring = useStore(s => s.isRestoring)
  28. const {
  29. enableShortcuts,
  30. disableShortcuts,
  31. } = useWorkflow()
  32. const { currentLogItem, setCurrentLogItem, showMessageLogModal, setShowMessageLogModal, currentLogModalActiveTab } = useAppStore(useShallow(state => ({
  33. currentLogItem: state.currentLogItem,
  34. setCurrentLogItem: state.setCurrentLogItem,
  35. showMessageLogModal: state.showMessageLogModal,
  36. setShowMessageLogModal: state.setShowMessageLogModal,
  37. currentLogModalActiveTab: state.currentLogModalActiveTab,
  38. })))
  39. return (
  40. <div
  41. tabIndex={-1}
  42. className={cn('absolute top-14 right-0 bottom-2 flex z-10 outline-none')}
  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. {
  87. showEnvPanel && (
  88. <EnvPanel />
  89. )
  90. }
  91. </div>
  92. )
  93. }
  94. export default memo(Panel)