TableEditor.Commands.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { useParams } from 'common'
  2. import { Table2 } from 'lucide-react'
  3. import type { CommandOptions } from 'ui-patterns/CommandMenu'
  4. import { useRegisterCommands } from 'ui-patterns/CommandMenu'
  5. import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
  6. import { orderCommandSectionsByPriority } from '@/components/interfaces/App/CommandMenu/ordering'
  7. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  8. export function useProjectLevelTableEditorCommands(options?: CommandOptions) {
  9. const { data: project } = useSelectedProjectQuery()
  10. const ref = project?.ref || '_'
  11. useRegisterCommands(
  12. COMMAND_MENU_SECTIONS.TABLE,
  13. [
  14. {
  15. id: 'create-table',
  16. name: 'Create new table',
  17. route: `/project/${ref}/editor?create=table`,
  18. icon: () => <Table2 />,
  19. },
  20. ],
  21. {
  22. ...options,
  23. deps: [ref],
  24. enabled: (options?.enabled ?? true) && !!project,
  25. orderSection: orderCommandSectionsByPriority,
  26. sectionMeta: { priority: 3 },
  27. }
  28. )
  29. }
  30. export function useTableEditorGotoCommands(options?: CommandOptions) {
  31. let { ref } = useParams()
  32. ref ||= '_'
  33. useRegisterCommands(
  34. COMMAND_MENU_SECTIONS.TABLE,
  35. [
  36. {
  37. id: 'view-tables',
  38. name: 'View your tables',
  39. route: `/project/${ref}/editor`,
  40. icon: () => <Table2 />,
  41. },
  42. ],
  43. {
  44. ...options,
  45. deps: [ref],
  46. orderSection: orderCommandSectionsByPriority,
  47. sectionMeta: { priority: 3 },
  48. }
  49. )
  50. useRegisterCommands(
  51. COMMAND_MENU_SECTIONS.NAVIGATE,
  52. [
  53. {
  54. id: 'nav-table-editor',
  55. name: 'Table Editor',
  56. route: `/project/${ref}/editor`,
  57. defaultHidden: true,
  58. },
  59. ],
  60. { ...options, deps: [ref] }
  61. )
  62. }