You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tabs.tsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import { useAllBuiltInTools, useAllCustomTools, useAllMCPTools, useAllWorkflowTools } from '@/service/use-tools'
  4. import type { BlockEnum } from '../types'
  5. import { useTabs } from './hooks'
  6. import type { ToolDefaultValue } from './types'
  7. import { TabsEnum } from './types'
  8. import Blocks from './blocks'
  9. import AllTools from './all-tools'
  10. import cn from '@/utils/classnames'
  11. export type TabsProps = {
  12. activeTab: TabsEnum
  13. onActiveTabChange: (activeTab: TabsEnum) => void
  14. searchText: string
  15. tags: string[]
  16. onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
  17. availableBlocksTypes?: BlockEnum[]
  18. filterElem: React.ReactNode
  19. noBlocks?: boolean
  20. }
  21. const Tabs: FC<TabsProps> = ({
  22. activeTab,
  23. onActiveTabChange,
  24. tags,
  25. searchText,
  26. onSelect,
  27. availableBlocksTypes,
  28. filterElem,
  29. noBlocks,
  30. }) => {
  31. const tabs = useTabs()
  32. const { data: buildInTools } = useAllBuiltInTools()
  33. const { data: customTools } = useAllCustomTools()
  34. const { data: workflowTools } = useAllWorkflowTools()
  35. const { data: mcpTools } = useAllMCPTools()
  36. return (
  37. <div onClick={e => e.stopPropagation()}>
  38. {
  39. !noBlocks && (
  40. <div className='relative flex bg-background-section-burn pl-1 pt-1'>
  41. {
  42. tabs.map(tab => (
  43. <div
  44. key={tab.key}
  45. className={cn(
  46. 'system-sm-medium relative mr-0.5 flex h-8 cursor-pointer items-center rounded-t-lg px-3 ',
  47. activeTab === tab.key
  48. ? 'sm-no-bottom cursor-default bg-components-panel-bg text-text-accent'
  49. : 'text-text-tertiary',
  50. )}
  51. onClick={() => onActiveTabChange(tab.key)}
  52. >
  53. {tab.name}
  54. </div>
  55. ))
  56. }
  57. </div>
  58. )
  59. }
  60. {filterElem}
  61. {
  62. activeTab === TabsEnum.Blocks && !noBlocks && (
  63. <div className='border-t border-divider-subtle'>
  64. <Blocks
  65. searchText={searchText}
  66. onSelect={onSelect}
  67. availableBlocksTypes={availableBlocksTypes}
  68. />
  69. </div>
  70. )
  71. }
  72. {
  73. activeTab === TabsEnum.Tools && (
  74. <AllTools
  75. searchText={searchText}
  76. onSelect={onSelect}
  77. tags={tags}
  78. canNotSelectMultiple
  79. buildInTools={buildInTools || []}
  80. customTools={customTools || []}
  81. workflowTools={workflowTools || []}
  82. mcpTools={mcpTools || []}
  83. canChooseMCPTool
  84. />
  85. )
  86. }
  87. </div>
  88. )
  89. }
  90. export default memo(Tabs)