mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 22:59:11 +03:00
Add new command menu to studio. Ports over commands from old menu (with some minor reorganization), then adds: - Branch switcher - Project switcher
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { AiIconAnimation } from 'ui'
|
|
|
|
import { useRegisterCommands } from '../../api/hooks/commandsHooks'
|
|
import { useRegisterPage, useSetPage } from '../../api/hooks/pagesHooks'
|
|
import type { ICommand, CommandOptions } from '../../api/types'
|
|
import { PageType } from '../../api/utils'
|
|
import { DocsAiPage } from './DocsAiPage'
|
|
|
|
const DOCS_AI_COMMANDS = {
|
|
PAGE_NAME: 'Ask Supabase AI',
|
|
SECTION_NAME: 'Docs',
|
|
}
|
|
|
|
const identity = <T,>(x: T) => x
|
|
|
|
const useDocsAiCommands = ({
|
|
modify = identity,
|
|
options,
|
|
}: { modify?: (command: ICommand) => ICommand; options?: CommandOptions } = {}) => {
|
|
const setCommandPage = useSetPage()
|
|
|
|
useRegisterPage(DOCS_AI_COMMANDS.PAGE_NAME, { type: PageType.Component, component: DocsAiPage })
|
|
|
|
useRegisterCommands(
|
|
DOCS_AI_COMMANDS.SECTION_NAME,
|
|
[
|
|
{
|
|
id: 'ai-docs',
|
|
name: 'Ask Supabase AI',
|
|
action: () => {
|
|
setCommandPage(DOCS_AI_COMMANDS.PAGE_NAME, true)
|
|
},
|
|
icon: () => <AiIconAnimation />,
|
|
},
|
|
].map(modify),
|
|
options
|
|
)
|
|
}
|
|
|
|
export { useDocsAiCommands }
|