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.

hooks.ts 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {
  2. useMemo,
  3. useState,
  4. } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import {
  7. TabsEnum,
  8. ToolTypeEnum,
  9. } from './types'
  10. export const useTabs = (noBlocks?: boolean, noSources?: boolean, noTools?: boolean) => {
  11. const { t } = useTranslation()
  12. const tabs = useMemo(() => {
  13. return [
  14. ...(
  15. noBlocks
  16. ? []
  17. : [
  18. {
  19. key: TabsEnum.Blocks,
  20. name: t('workflow.tabs.blocks'),
  21. },
  22. ]
  23. ),
  24. ...(
  25. noSources
  26. ? []
  27. : [
  28. {
  29. key: TabsEnum.Sources,
  30. name: t('workflow.tabs.sources'),
  31. },
  32. ]
  33. ),
  34. ...(
  35. noTools
  36. ? []
  37. : [
  38. {
  39. key: TabsEnum.Tools,
  40. name: t('workflow.tabs.tools'),
  41. },
  42. ]
  43. ),
  44. ]
  45. }, [t, noBlocks, noSources, noTools])
  46. const initialTab = useMemo(() => {
  47. if (noBlocks)
  48. return noTools ? TabsEnum.Sources : TabsEnum.Tools
  49. if (noTools)
  50. return noBlocks ? TabsEnum.Sources : TabsEnum.Blocks
  51. return TabsEnum.Blocks
  52. }, [noBlocks, noSources, noTools])
  53. const [activeTab, setActiveTab] = useState(initialTab)
  54. return {
  55. tabs,
  56. activeTab,
  57. setActiveTab,
  58. }
  59. }
  60. export const useToolTabs = (isHideMCPTools?: boolean) => {
  61. const { t } = useTranslation()
  62. const tabs = [
  63. {
  64. key: ToolTypeEnum.All,
  65. name: t('workflow.tabs.allTool'),
  66. },
  67. {
  68. key: ToolTypeEnum.BuiltIn,
  69. name: t('workflow.tabs.plugin'),
  70. },
  71. {
  72. key: ToolTypeEnum.Custom,
  73. name: t('workflow.tabs.customTool'),
  74. },
  75. {
  76. key: ToolTypeEnum.Workflow,
  77. name: t('workflow.tabs.workflowTool'),
  78. },
  79. ]
  80. if (!isHideMCPTools) {
  81. tabs.push({
  82. key: ToolTypeEnum.MCP,
  83. name: 'MCP',
  84. })
  85. }
  86. return tabs
  87. }