2025-06-12 17:03:52 +08:00
|
|
|
import { t } from '@grafana/i18n';
|
2025-04-17 23:00:10 +08:00
|
|
|
import { config } from '@grafana/runtime';
|
2025-05-05 20:00:20 +08:00
|
|
|
import { useScopesServices } from 'app/features/scopes/ScopesContextProvider';
|
2025-04-17 23:00:10 +08:00
|
|
|
|
|
|
|
import { CommandPaletteAction } from '../types';
|
|
|
|
import { RECENT_SCOPES_PRIORITY } from '../values';
|
|
|
|
|
|
|
|
export function getRecentScopesActions(): CommandPaletteAction[] {
|
2025-05-05 20:00:20 +08:00
|
|
|
const services = useScopesServices();
|
2025-06-12 17:03:52 +08:00
|
|
|
|
2025-05-05 20:00:20 +08:00
|
|
|
if (!(config.featureToggles.scopeFilters && services)) {
|
2025-04-17 23:00:10 +08:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2025-05-05 20:00:20 +08:00
|
|
|
const { scopesSelectorService } = services;
|
2025-04-17 23:00:10 +08:00
|
|
|
const recentScopes = scopesSelectorService.getRecentScopes();
|
|
|
|
|
|
|
|
return recentScopes.map((recentScope) => {
|
|
|
|
return {
|
2025-06-10 16:21:43 +08:00
|
|
|
id: recentScope.map((scope) => scope.spec.title).join(', '),
|
|
|
|
name: recentScope.map((scope) => scope.spec.title).join(', '),
|
2025-04-17 23:00:10 +08:00
|
|
|
section: t('command-palette.section.recent-scopes', 'Recent scopes'),
|
|
|
|
priority: RECENT_SCOPES_PRIORITY,
|
|
|
|
perform: () => {
|
2025-06-10 16:21:43 +08:00
|
|
|
scopesSelectorService.changeScopes(recentScope.map((scope) => scope.metadata.name));
|
2025-04-17 23:00:10 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|