Integrations.Commands.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useParams } from 'common'
  2. import type { CommandOptions } from 'ui-patterns/CommandMenu'
  3. import { useRegisterCommands } from 'ui-patterns/CommandMenu'
  4. import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
  5. import { orderCommandSectionsByPriority } from '@/components/interfaces/App/CommandMenu/ordering'
  6. import {
  7. IntegrationDefinition,
  8. INTEGRATIONS,
  9. } from '@/components/interfaces/Integrations/Landing/Integrations.constants'
  10. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  11. export function useIntegrationsGotoCommands(options?: CommandOptions) {
  12. let { ref } = useParams()
  13. ref ||= '_'
  14. const { integrationsWrappers } = useIsFeatureEnabled(['integrations:wrappers'])
  15. const allIntegrations = integrationsWrappers
  16. ? INTEGRATIONS
  17. : INTEGRATIONS.filter((x) => !x.id.endsWith('_wrapper'))
  18. const getName = (integration: IntegrationDefinition) => {
  19. switch (integration.id) {
  20. case 'cron':
  21. return 'View and manage your Cron Jobs'
  22. case 'graphiql':
  23. return 'Query database using GraphQL'
  24. case 'vault':
  25. return 'View and manage your keys and secrets via Vault'
  26. default:
  27. return `View and manage your ${integration.name}${integration.type === 'wrapper' ? 's' : ''}`
  28. }
  29. }
  30. useRegisterCommands(
  31. COMMAND_MENU_SECTIONS.NAVIGATE,
  32. allIntegrations.map((x) => {
  33. return {
  34. id: `nav-integrations-${x.id}`,
  35. name: x.name,
  36. value: `Integrations: ${x.name}`,
  37. route: `/project/${ref}/integrations/${x.id}/overview`,
  38. defaultHidden: true,
  39. }
  40. }),
  41. { ...options, deps: [ref] }
  42. )
  43. useRegisterCommands(
  44. COMMAND_MENU_SECTIONS.INTEGRATIONS,
  45. allIntegrations.map((x) => {
  46. return {
  47. id: `manage-${x.id}`,
  48. name: getName(x),
  49. route: `/project/${ref}/integrations/${x.id}/overview`,
  50. icon: () => (
  51. <div className="w-6 h-6 relative bg-white border rounded-md flex items-center justify-center [&>img]:p-1! [&>svg]:p-1!">
  52. {x.icon()}
  53. </div>
  54. ),
  55. }
  56. }),
  57. {
  58. ...options,
  59. deps: [ref],
  60. orderSection: orderCommandSectionsByPriority,
  61. sectionMeta: { priority: 3 },
  62. }
  63. )
  64. }