mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
## Context Searching in Cmd K has a tendency to return seemingly irrelevant results - e.g searching "blog" or "colors" would show "Project Integrations" as a search result. Cmd K itself ranks items with a fuzzy scorer that matches characters in order but not contiguously - so _any_ item with a non-zero score stays in the list. <img width="661" height="200" alt="image" src="https://github.com/user-attachments/assets/2e170ccc-ab01-43f3-8d83-7e567e95913e" /> ## Changes involved - Add a custom filter for Cmd K to filter out results which fuzzy score falls below 0.01 - This catches the worst scattered matches and keeps short abbreviations like `db` → Database (about 0.17). - Keywords are matched by substring only, never fuzzily, and requires a score of at least 0.5 - Cmd K normally fuzzy-matches keywords together with the name, so we match keywords by exact substring instead ## To test - Open the command menu in Studio and search `colors` and `blog`. Project Integrations should not appear. - Search `branch`, `vercel`, `github` and `privatelink`. Project Integrations should appear. - Search `addons`, `restart project` and `pause project`. The corresponding Add-ons and Project availability commands should appear. - Search `db`, `auth` and `stor`. The usual results should still appear.
220 lines
7.1 KiB
TypeScript
220 lines
7.1 KiB
TypeScript
import { useFlag, useParams } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import type { CommandOptions, ICommand } from 'ui-patterns/CommandMenu'
|
|
import { useRegisterCommands, useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
|
|
import { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'
|
|
|
|
import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
|
|
import { useIsPlatformWebhooksEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
|
|
export function useProjectSettingsGotoCommands(options?: CommandOptions) {
|
|
const router = useRouter()
|
|
const setIsOpen = useSetCommandMenuOpen()
|
|
let { ref, slug } = useParams()
|
|
const platformWebhooksEnabled = useIsPlatformWebhooksEnabled()
|
|
const showConfigDrift = useFlag('ConfigDrift')
|
|
ref ||= '_'
|
|
const hasOrgSlug = typeof slug === 'string' && slug.length > 0 && slug !== '_'
|
|
|
|
const {
|
|
logsAll,
|
|
projectSettingsLogDrains,
|
|
projectSettingsCustomDomains,
|
|
authenticationSignInProviders,
|
|
} = useIsFeatureEnabled([
|
|
'logs:all',
|
|
'project_settings:log_drains',
|
|
'project_settings:custom_domains',
|
|
'authentication:sign_in_providers',
|
|
])
|
|
|
|
// Log drains depend on the analytics backend, gated by logs:all (see SettingsMenu.utils).
|
|
const showLogDrains = logsAll && projectSettingsLogDrains
|
|
|
|
useRegisterCommands(
|
|
COMMAND_MENU_SECTIONS.NAVIGATE,
|
|
[
|
|
{
|
|
id: 'nav-project-settings-add-ons',
|
|
name: 'Add-ons',
|
|
keywords: ['addons', 'add ons', 'add on', 'add-on'],
|
|
route: `/project/${ref}/settings/addons`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-general',
|
|
name: 'General settings',
|
|
route: `/project/${ref}/settings/general`,
|
|
defaultHidden: true,
|
|
},
|
|
...(IS_PLATFORM && showConfigDrift
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-code-configuration',
|
|
name: 'Code configuration',
|
|
route: `/project/${ref}/settings/code-configuration`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
{
|
|
id: 'nav-project-settings-database',
|
|
name: 'Database settings',
|
|
route: `/project/${ref}/database/settings`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-auth',
|
|
name: 'Auth settings',
|
|
route: authenticationSignInProviders
|
|
? `/project/${ref}/auth/providers`
|
|
: `/project/${ref}/database/policies`,
|
|
defaultHidden: true,
|
|
},
|
|
...(platformWebhooksEnabled
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-webhooks',
|
|
name: 'Project webhooks',
|
|
route: `/project/${ref}/settings/webhooks`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
...(hasOrgSlug
|
|
? [
|
|
{
|
|
id: 'nav-organization-settings-webhooks',
|
|
name: 'Organization Webhooks',
|
|
route: `/org/${slug}/webhooks`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
]
|
|
: []),
|
|
{
|
|
id: 'nav-project-settings-api',
|
|
name: 'API settings',
|
|
route: `/project/${ref}/integrations/data_api/settings`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-integration',
|
|
name: 'Project Integrations',
|
|
keywords: [
|
|
'Branch integration',
|
|
'Vercel integration',
|
|
'GitHub integration',
|
|
'AWS PrivateLink',
|
|
],
|
|
route: `/project/${ref}/settings/integrations`,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-storage',
|
|
name: 'Storage settings',
|
|
route: `/project/${ref}/storage/settings`,
|
|
defaultHidden: true,
|
|
},
|
|
...(projectSettingsCustomDomains
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-custom-domains',
|
|
name: 'Custom domains',
|
|
route: `/project/${ref}/settings/general#custom-domains`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
{
|
|
id: 'nav-project-settings-restart-project',
|
|
name: 'Project availability',
|
|
keywords: ['restart project', 'pause project', 'resume project'],
|
|
route: `/project/${ref}/settings/general#restart-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-pause-project',
|
|
name: 'Pause project',
|
|
route: `/project/${ref}/settings/general#pause-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-transfer-project',
|
|
name: 'Transfer project',
|
|
route: `/project/${ref}/settings/general#transfer-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-delete-project',
|
|
name: 'Delete project',
|
|
route: `/project/${ref}/settings/general#delete-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-database-password',
|
|
name: 'Database password',
|
|
route: `/project/${ref}/database/settings#database-password`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-reset-database-password',
|
|
name: 'Reset database password',
|
|
route: `/project/${ref}/database/settings#database-password`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-connection-string',
|
|
name: 'Connection string',
|
|
action: () => {
|
|
router.push(
|
|
{
|
|
pathname: router.pathname,
|
|
query: { ...router.query, showConnect: 'true' },
|
|
},
|
|
undefined,
|
|
{ shallow: true }
|
|
)
|
|
setIsOpen(false)
|
|
},
|
|
defaultHidden: true,
|
|
} as ICommand,
|
|
{
|
|
id: 'nav-project-settings-connection-pooling',
|
|
name: 'Connection pooling',
|
|
route: `/project/${ref}/database/settings#connection-pooler`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-ssl-configuration',
|
|
name: 'SSL configuration',
|
|
route: `/project/${ref}/database/settings#ssl-configuration`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-network-restrictions',
|
|
name: 'Network restrictions',
|
|
route: `/project/${ref}/database/settings#network-restrictions`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-banned-ips',
|
|
name: 'Banned IPs',
|
|
route: `/project/${ref}/database/settings#banned-ips`,
|
|
defaultHidden: true,
|
|
},
|
|
...(showLogDrains
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-log-drains',
|
|
name: 'Log drains',
|
|
route: `/project/${ref}/settings/log-drains`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
],
|
|
{ ...options, deps: [platformWebhooksEnabled, showLogDrains, showConfigDrift, ref, slug] }
|
|
)
|
|
}
|