Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

8.1 KB
Raw Blame
import React from 'react';
import ROUTES from 'constants/routes';
import { GlobalShortcutsName } from 'constants/shortcuts/globalShortcuts';
import { THEME_MODE } from 'hooks/useDarkMode/constant';
import {
	BarChart,
	BellDot,
	Bug,
	Compass,
	DraftingCompass,
	Expand,
	HardDrive,
	Home,
	LayoutGrid,
	ListMinus,
	ScrollText,
	Settings,
	Workflow,
} from '@signozhq/icons';
import Noz from 'components/Noz/Noz';
import { ROLES } from 'types/roles';

export type CmdAction = {
	id: string;
	name: string;
	shortcut?: string[];
	keywords?: string;
	section?: string;
	icon?: React.ReactNode;
	roles?: ROLES[];
	perform: () => void;
};

type ActionDeps = {
	navigate: (path: string) => void;
	handleThemeChange: (mode: string) => void;
	/**
	 * Provided only when the AI Assistant feature is available for the current
	 * tenant. When present, the palette surfaces an "Open AI Assistant" entry
	 * at the top; when absent, the action is omitted entirely.
	 */
	aiAssistant?: {
		open: () => void;
	};
	/**
	 * Provided only in development mode. Opens the AuthZ DevTools modal
	 * for testing permission overrides.
	 */
	authzDevTools?: {
		open: () => void;
	};
};

export function createShortcutActions(deps: ActionDeps): CmdAction[] {
	const { navigate, handleThemeChange, aiAssistant, authzDevTools } = deps;

	const actions: CmdAction[] = [
		{
			id: 'home',
			name: 'Go to Home',
			shortcut: [GlobalShortcutsName.NavigateToHome],
			keywords: 'home',
			section: 'Navigation',
			icon: <Home size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.HOME),
		},
		{
			id: 'dashboards',
			name: 'Go to Dashboards',
			shortcut: [GlobalShortcutsName.NavigateToDashboards],
			keywords: 'dashboards',
			section: 'Navigation',
			icon: <LayoutGrid size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.ALL_DASHBOARD),
		},
		{
			id: 'services',
			name: 'Go to Services',
			shortcut: [GlobalShortcutsName.NavigateToServices],
			keywords: 'services monitoring',
			section: 'Navigation',
			icon: <HardDrive size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.APPLICATION),
		},
		{
			id: 'alerts',
			name: 'Go to Alerts',
			shortcut: [GlobalShortcutsName.NavigateToAlerts],
			keywords: 'alerts',
			section: 'Navigation',
			icon: <BellDot size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.LIST_ALL_ALERT),
		},
		{
			id: 'exceptions',
			name: 'Go to Exceptions',
			shortcut: [GlobalShortcutsName.NavigateToExceptions],
			keywords: 'exceptions errors',
			section: 'Navigation',
			icon: <Bug size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.ALL_ERROR),
		},
		{
			id: 'messaging-queues',
			name: 'Go to Messaging Queues',
			shortcut: [GlobalShortcutsName.NavigateToMessagingQueues],
			keywords: 'messaging queues mq',
			section: 'Navigation',
			icon: <ListMinus size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.MESSAGING_QUEUES_OVERVIEW),
		},

		// logs
		{
			id: 'logs',
			name: 'Go to Logs',
			shortcut: [GlobalShortcutsName.NavigateToLogs],
			keywords: 'logs',
			section: 'Logs',
			icon: <ScrollText size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.LOGS),
		},
		{
			id: 'logs',
			name: 'Go to Logs Pipelines',
			shortcut: [GlobalShortcutsName.NavigateToLogsPipelines],
			keywords: 'logs pipelines',
			section: 'Logs',
			icon: <Workflow size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.LOGS_PIPELINES),
		},

		// metrics
		{
			id: 'metrics-summary',
			name: 'Go to Metrics Summary',
			shortcut: [GlobalShortcutsName.NavigateToMetricsSummary],
			keywords: 'metrics summary',
			section: 'Metrics',
			icon: <BarChart size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.METRICS_EXPLORER),
		},
		{
			id: 'metrics-explorer',
			name: 'Go to Metrics Explorer',
			shortcut: [GlobalShortcutsName.NavigateToMetricsExplorer],
			keywords: 'metrics explorer',
			section: 'Metrics',
			icon: <Compass size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.METRICS_EXPLORER_EXPLORER),
		},

		// Traces
		{
			id: 'traces',
			name: 'Go to Traces',
			shortcut: [GlobalShortcutsName.NavigateToTraces],
			keywords: 'traces',
			section: 'Traces',
			icon: <DraftingCompass size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.TRACES_EXPLORER),
		},
		{
			id: 'traces-funnel',
			name: 'Go to Traces Funnels',
			shortcut: [GlobalShortcutsName.NavigateToTracesFunnel],
			keywords: 'traces funnel',
			section: 'Traces',
			icon: <DraftingCompass size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.TRACES_FUNNELS),
		},

		// Common actions
		{
			id: 'dark-mode',
			name: 'Switch to Dark Mode',
			keywords: 'theme dark mode appearance',
			section: 'Common',
			icon: <Expand size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => handleThemeChange(THEME_MODE.DARK),
		},
		{
			id: 'light-mode',
			name: 'Switch to Light Mode [Beta]',
			keywords: 'theme light mode appearance',
			section: 'Common',
			icon: <Expand size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => handleThemeChange(THEME_MODE.LIGHT),
		},
		{
			id: 'system-theme',
			name: 'Switch to System Theme',
			keywords: 'system theme appearance',
			section: 'Common',
			icon: <Expand size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => handleThemeChange(THEME_MODE.SYSTEM),
		},

		// settings sub-pages
		{
			id: 'my-settings',
			name: 'Go to Account Settings',
			shortcut: [GlobalShortcutsName.NavigateToSettings],
			keywords: 'account settings',
			section: 'Settings',
			icon: <Settings size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: (): void => navigate(ROUTES.MY_SETTINGS),
		},
		{
			id: 'my-settings-ingestion',
			name: 'Go to Account Settings Ingestion',
			shortcut: [GlobalShortcutsName.NavigateToSettingsIngestion],
			keywords: 'account settings',
			section: 'Settings',
			icon: <Settings size={14} />,
			roles: ['ADMIN', 'EDITOR'],
			perform: (): void => navigate(ROUTES.INGESTION_SETTINGS),
		},

		{
			id: 'my-settings-billing',
			name: 'Go to Account Settings Billing',
			shortcut: [GlobalShortcutsName.NavigateToSettingsBilling],
			keywords: 'account settings billing',
			section: 'Settings',
			icon: <Settings size={14} />,
			roles: ['ADMIN', 'EDITOR'],
			perform: (): void => navigate(ROUTES.BILLING),
		},
		{
			id: 'my-settings-service-accounts',
			name: 'Go to Service Accounts',
			shortcut: [GlobalShortcutsName.NavigateToSettingsServiceAccounts],
			keywords: 'settings service accounts',
			section: 'Settings',
			icon: <Settings size={14} />,
			roles: ['ADMIN'],
			perform: (): void => navigate(ROUTES.SERVICE_ACCOUNTS_SETTINGS),
		},
		{
			id: 'my-settings-roles',
			name: 'Go to Roles',
			shortcut: [GlobalShortcutsName.NavigateToSettingsRoles],
			keywords: 'settings roles',
			section: 'Settings',
			icon: <Settings size={14} />,
			roles: ['ADMIN'],
			perform: (): void => navigate(ROUTES.ROLES_SETTINGS),
		},
		{
			id: 'my-settings-members',
			name: 'Go to Members',
			shortcut: [GlobalShortcutsName.NavigateToSettingsMembers],
			keywords: 'settings members',
			section: 'Settings',
			icon: <Settings size={14} />,
			roles: ['ADMIN'],
			perform: (): void => navigate(ROUTES.MEMBERS_SETTINGS),
		},
	];

	if (aiAssistant) {
		actions.unshift({
			id: 'ai-assistant',
			name: 'Open Noz',
			shortcut: ['cmd+j'],
			keywords: 'noz ai assistant chat ask sparkles copilot',
			section: 'Noz',
			icon: <Noz size={16} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: aiAssistant.open,
		});
	}

	if (authzDevTools) {
		actions.push({
			id: 'authz-devtools',
			name: 'AuthZ DevTools',
			keywords: 'authz permissions rbac debug devtools override testing',
			section: 'Dev',
			icon: <Settings size={14} />,
			roles: ['ADMIN', 'EDITOR', 'VIEWER'],
			perform: authzDevTools.open,
		});
	}

	return actions;
}