From 7888e10aae36fe8bb745bb83c64958d5c12ca8a4 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com> Date: Tue, 30 Sep 2025 17:12:42 +0200 Subject: [PATCH] Scopes: Increase rank for recent scopes in command palette (#111805) * Increase prio for recent scopes and bump match score for exact matches * Set scopes prio to 8 --- .../actions/recentScopesActions.ts | 16 ++++++++++++---- public/app/features/commandPalette/useMatches.ts | 16 ++++++++++++---- public/app/features/commandPalette/values.ts | 3 ++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/public/app/features/commandPalette/actions/recentScopesActions.ts b/public/app/features/commandPalette/actions/recentScopesActions.ts index 5afbf3fd115..99687d837d3 100644 --- a/public/app/features/commandPalette/actions/recentScopesActions.ts +++ b/public/app/features/commandPalette/actions/recentScopesActions.ts @@ -16,12 +16,20 @@ export function getRecentScopesActions(): CommandPaletteAction[] { const recentScopes = scopesSelectorService.getRecentScopes(); return recentScopes.map((recentScope) => { + const names = recentScope.map((scope) => scope.spec.title).join(', '); + const keywords = recentScope + .map((scope) => `${scope.spec.title} ${scope.metadata.name}`) + .concat(names) + .join(' '); return { - id: recentScope.map((scope) => scope.spec.title).join(', '), - name: recentScope.map((scope) => scope.spec.title).join(', '), - section: t('command-palette.section.recent-scopes', 'Recent scopes'), - // Only show the parent of the first scope for now + id: names, + name: names, + section: { + name: t('command-palette.section.recent-scopes', 'Recent scopes'), + priority: RECENT_SCOPES_PRIORITY, + }, subtitle: recentScope[0]?.parentNode?.spec.title, + keywords: keywords, priority: RECENT_SCOPES_PRIORITY, perform: () => { scopesSelectorService.changeScopes(recentScope.map((scope) => scope.metadata.name)); diff --git a/public/app/features/commandPalette/useMatches.ts b/public/app/features/commandPalette/useMatches.ts index 42a5716bd8d..3da87c25af4 100644 --- a/public/app/features/commandPalette/useMatches.ts +++ b/public/app/features/commandPalette/useMatches.ts @@ -190,10 +190,18 @@ function useInternalMatches(filtered: ActionImpl[], search: string): Match[] { const matchingIndices = fuzzySearch(haystack, throttledSearch); // Convert indices back to Match objects with proper scoring - const results: Match[] = matchingIndices.map((index, order) => ({ - action: throttledFiltered[index], - score: matchingIndices.length - order, // Higher score for better ranked matches - })); + const results: Match[] = matchingIndices.map((index, order) => { + const name = throttledFiltered[index].name; + const fullNameMatch = name.toLowerCase() === throttledSearch.toLowerCase(); + let score = matchingIndices.length - order; // Higher score for better ranked matches + if (fullNameMatch) { + score += 100; // Bumping for exact matches + } + return { + action: throttledFiltered[index], + score, + }; + }); return results; }, [throttledFiltered, throttledSearch]); diff --git a/public/app/features/commandPalette/values.ts b/public/app/features/commandPalette/values.ts index 2fc599254b0..281bbe38348 100644 --- a/public/app/features/commandPalette/values.ts +++ b/public/app/features/commandPalette/values.ts @@ -1,5 +1,6 @@ +// Bumped to way higher value, to give it more weight when searching +export const RECENT_SCOPES_PRIORITY = 50; export const SCOPES_PRIORITY = 8; -export const RECENT_SCOPES_PRIORITY = 7; export const RECENT_DASHBOARDS_PRIORITY = 6; export const ACTIONS_PRIORITY = 5; export const DEFAULT_PRIORITY = 4;