index.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. useMemo,
  5. } from 'react'
  6. import { useNodes } from 'reactflow'
  7. import type { CommonNodeType } from '../types'
  8. import { Panel as NodePanel } from '../nodes'
  9. import { useStore } from '../store'
  10. import { useIsChatMode } 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 { useStore as useAppStore } from '@/app/components/app/store'
  16. import MessageLogModal from '@/app/components/base/message-log-modal'
  17. const Panel: FC = () => {
  18. const nodes = useNodes<CommonNodeType>()
  19. const isChatMode = useIsChatMode()
  20. const selectedNode = nodes.find(node => node.data.selected)
  21. const showInputsPanel = useStore(s => s.showInputsPanel)
  22. const workflowRunningData = useStore(s => s.workflowRunningData)
  23. const historyWorkflowData = useStore(s => s.historyWorkflowData)
  24. const { currentLogItem, setCurrentLogItem, showMessageLogModal, setShowMessageLogModal } = useAppStore()
  25. const {
  26. showNodePanel,
  27. showDebugAndPreviewPanel,
  28. showWorkflowPreview,
  29. } = useMemo(() => {
  30. return {
  31. showNodePanel: !!selectedNode && !workflowRunningData && !historyWorkflowData && !showInputsPanel,
  32. showDebugAndPreviewPanel: isChatMode && workflowRunningData && !historyWorkflowData,
  33. showWorkflowPreview: !isChatMode && !historyWorkflowData && (workflowRunningData || showInputsPanel),
  34. }
  35. }, [
  36. showInputsPanel,
  37. selectedNode,
  38. isChatMode,
  39. workflowRunningData,
  40. historyWorkflowData,
  41. ])
  42. return (
  43. <div className='absolute top-14 right-0 bottom-2 flex z-10'>
  44. {
  45. showMessageLogModal && (
  46. <MessageLogModal
  47. fixedWidth
  48. width={400}
  49. currentLogItem={currentLogItem}
  50. onCancel={() => {
  51. setCurrentLogItem()
  52. setShowMessageLogModal(false)
  53. }}
  54. />
  55. )
  56. }
  57. {
  58. historyWorkflowData && !isChatMode && (
  59. <Record />
  60. )
  61. }
  62. {
  63. historyWorkflowData && isChatMode && (
  64. <ChatRecord />
  65. )
  66. }
  67. {
  68. showDebugAndPreviewPanel && (
  69. <DebugAndPreview />
  70. )
  71. }
  72. {
  73. showWorkflowPreview && (
  74. <WorkflowPreview />
  75. )
  76. }
  77. {
  78. showNodePanel && (
  79. <NodePanel {...selectedNode!} />
  80. )
  81. }
  82. </div>
  83. )
  84. }
  85. export default memo(Panel)