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