Files
Charis 84732ff44c feat: add new command menu to studio (#28432)
Add new command menu to studio. Ports over commands from old menu (with some minor reorganization), then adds:
- Branch switcher
- Project switcher
2024-08-08 16:42:07 -04:00

46 lines
1.3 KiB
TypeScript

import { Link } from 'lucide-react'
import { useProjectApiQuery } from 'data/config/project-api-query'
import { copyToClipboard } from 'lib/helpers'
import { Badge } from 'ui'
import { useRegisterCommands, useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { COMMAND_MENU_SECTIONS } from './CommandMenu.utils'
import { orderCommandSectionsByPriority } from './ordering'
export function useApiUrlCommand() {
const setIsOpen = useSetCommandMenuOpen()
const project = useSelectedProject()
const { data: settings } = useProjectApiQuery(
{ projectRef: project?.ref },
{ enabled: !!project }
)
const apiUrl = settings?.autoApiService.endpoint
? `${settings.autoApiService.protocol ?? 'https'}://${settings.autoApiService.endpoint}`
: undefined
useRegisterCommands(
COMMAND_MENU_SECTIONS.ACTIONS,
[
{
id: 'api-url',
name: 'Copy API URL',
action: () => {
copyToClipboard(apiUrl ?? '')
setIsOpen(false)
},
icon: () => <Link />,
badge: () => <Badge>Project: {project?.name}</Badge>,
},
],
{
enabled: !!project,
deps: [apiUrl, project],
orderSection: orderCommandSectionsByPriority,
sectionMeta: { priority: 3 },
}
)
}