diff --git a/.changeset/spotlight-settings-entries.md b/.changeset/spotlight-settings-entries.md new file mode 100644 index 000000000..3e0db66e1 --- /dev/null +++ b/.changeset/spotlight-settings-entries.md @@ -0,0 +1,11 @@ +--- +'@hyperdx/app': patch +--- + +feat: Find settings and preferences from the Cmd+K menu + +- Team settings sections (sources, connections, team members, API keys, MCP + server, webhooks, query settings, and more) open the right tab and scroll to + the section. +- "Preferences" opens the preferences modal, and "Use light mode", "Use dark + mode", and "Use system color mode" switch the theme directly. diff --git a/packages/app/src/Spotlights.tsx b/packages/app/src/Spotlights.tsx index d73b5683e..743416ee1 100644 --- a/packages/app/src/Spotlights.tsx +++ b/packages/app/src/Spotlights.tsx @@ -11,13 +11,13 @@ import { IconLayout, IconLogs, IconSearch, - IconSettings, } from '@tabler/icons-react'; import { useBrandDisplayName, useLogomark } from './brand'; import { IS_K8S_DASHBOARD_ENABLED } from './config'; import { useDashboards } from './dashboard'; import { useSavedSearches } from './savedSearch'; +import { useSettingsSpotlightActions } from './spotlightSettingsActions'; import '@mantine/spotlight/styles.css'; @@ -28,6 +28,7 @@ export const useSpotlightActions = () => { const { data: logViewsData } = useSavedSearches(); const { data: dashboardsData } = useDashboards(); + const settingsActions = useSettingsSpotlightActions(); const actions = React.useMemo(() => { const logViews = logViewsData ?? []; @@ -171,16 +172,6 @@ export const useSpotlightActions = () => { router.push('/services'); }, }, - { - id: 'team-settings', - group: 'Menu', - leftSection: , - label: 'Team Settings', - - onClick: () => { - router.push('/team'); - }, - }, { id: 'documentation', group: 'Menu', @@ -206,10 +197,18 @@ export const useSpotlightActions = () => { ); }, }, + ...settingsActions, ); return logViewActions; - }, [brandName, logomark, logViewsData, dashboardsData, router]); + }, [ + brandName, + logomark, + logViewsData, + dashboardsData, + router, + settingsActions, + ]); return { actions }; }; diff --git a/packages/app/src/TeamPage.tsx b/packages/app/src/TeamPage.tsx index 4a465afa2..f4391b5b6 100644 --- a/packages/app/src/TeamPage.tsx +++ b/packages/app/src/TeamPage.tsx @@ -62,6 +62,22 @@ function TeamTabContent({ sections: TeamTab['sections']; active: boolean; }) { + // Deep links like `?tab=api-agents#team-api-agents-mcp-server` (spotlight, + // onboarding) land before the team has loaded, so Next's own hash scroll + // finds no element. + const { asPath } = useRouter(); + const hash = asPath.split('#')[1]; + const scrollTargetId = + active && sections.some(section => section.id === hash) ? hash : null; + useEffect(() => { + if (!scrollTargetId) return; + requestAnimationFrame(() => { + document + .getElementById(scrollTargetId) + ?.scrollIntoView({ behavior: 'smooth', block: 'start' }); + }); + }, [scrollTargetId]); + return ( {sections.map(section => ( diff --git a/packages/app/src/UserPreferencesModal.tsx b/packages/app/src/UserPreferencesModal.tsx index 273693814..8a9b436f1 100644 --- a/packages/app/src/UserPreferencesModal.tsx +++ b/packages/app/src/UserPreferencesModal.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import { atom, useAtom } from 'jotai'; import { Badge } from '@clickhouse/click-ui'; import { Divider, @@ -33,6 +34,16 @@ const OPTIONS_ROW_CLICK_ACTION: { label: string; value: RowClickAction }[] = [ { label: 'Expand inline', value: 'expand' }, ]; +const userPreferencesModalOpenedAtom = atom(false); + +/** Shared so the spotlight can open the modal that AppNav renders. */ +export const useUserPreferencesModal = () => { + const [opened, setOpened] = useAtom(userPreferencesModalOpenedAtom); + const open = React.useCallback(() => setOpened(true), [setOpened]); + const close = React.useCallback(() => setOpened(false), [setOpened]); + return { opened, open, close }; +}; + const SettingContainer = ({ label, description, diff --git a/packages/app/src/__tests__/Spotlights.test.tsx b/packages/app/src/__tests__/Spotlights.test.tsx index 232f676bc..0b8f01205 100644 --- a/packages/app/src/__tests__/Spotlights.test.tsx +++ b/packages/app/src/__tests__/Spotlights.test.tsx @@ -1,8 +1,14 @@ -import { renderHook } from '@testing-library/react'; +import { spotlight } from '@mantine/spotlight'; +import { act, renderHook, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { useDashboards } from '@/dashboard'; import { useSavedSearches } from '@/savedSearch'; -import { useSpotlightActions } from '@/Spotlights'; +import { HDXSpotlightProvider, useSpotlightActions } from '@/Spotlights'; +import { useUserPreferencesModal } from '@/UserPreferencesModal'; +import { useUserPreferences } from '@/useUserPreferences'; + +const mockPush = jest.fn(); jest.mock('next/router', () => ({ useRouter() { @@ -11,7 +17,7 @@ jest.mock('next/router', () => ({ pathname: '', query: '', asPath: '', - push: jest.fn(), + push: mockPush, events: { on: jest.fn(), off: jest.fn(), @@ -90,6 +96,7 @@ describe('useSpotlightActions', () => { // Reset mocks before each test beforeEach(() => { jest.clearAllMocks(); + window.localStorage.clear(); mockUseSavedSearches.mockReturnValue(mockSavedSearches); mockUseDashboards.mockReturnValue(mockSavedDashboard); }); @@ -106,4 +113,41 @@ describe('useSpotlightActions', () => { mockSavedDashboard.data[0].name, ); }); + + const selectSpotlightAction = async (query: string, name: RegExp) => { + renderWithMantine( + +
+ , + ); + act(() => spotlight.open()); + await userEvent.type(await screen.findByPlaceholderText('Search'), query); + await userEvent.click(await screen.findByRole('button', { name })); + }; + + it('opens the anchored team settings section', async () => { + await selectSpotlightAction('mcp', /MCP server/); + + expect(mockPush).toHaveBeenCalledWith( + '/team?tab=api-agents#team-api-agents-mcp-server', + ); + }); + + it('switches color mode without opening preferences', async () => { + await selectSpotlightAction('light mode', /Use light mode/); + + const { result } = renderHook(() => ({ + preferences: useUserPreferences(), + modal: useUserPreferencesModal(), + })); + expect(result.current.preferences.userPreferences.colorMode).toBe('light'); + expect(result.current.modal.opened).toBe(false); + }); + + it('opens the preferences modal', async () => { + await selectSpotlightAction('time zone', /Preferences/); + + const { result } = renderHook(() => useUserPreferencesModal()); + expect(result.current.opened).toBe(true); + }); }); diff --git a/packages/app/src/components/AppNav/AppNav.tsx b/packages/app/src/components/AppNav/AppNav.tsx index 33c41c2fc..ad2746c8e 100644 --- a/packages/app/src/components/AppNav/AppNav.tsx +++ b/packages/app/src/components/AppNav/AppNav.tsx @@ -34,7 +34,10 @@ import OnboardingChecklist from '@/OnboardingChecklist'; import { useSavedSearches } from '@/savedSearch'; import { getTimeZoneShortName } from '@/timeZone'; import { useDisplayTimeZone } from '@/useDisplayTimeZone'; -import { UserPreferencesModal } from '@/UserPreferencesModal'; +import { + UserPreferencesModal, + useUserPreferencesModal, +} from '@/UserPreferencesModal'; import { AppNavCloudBanner, @@ -285,10 +288,11 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { [query.dashboardId], ); - const [ - UserPreferencesOpen, - { close: closeUserPreferences, open: openUserPreferences }, - ] = useDisclosure(false); + const { + opened: UserPreferencesOpen, + close: closeUserPreferences, + open: openUserPreferences, + } = useUserPreferencesModal(); const timeZone = useDisplayTimeZone(); const timeZoneShortName = timeZone && getTimeZoneShortName(timeZone); diff --git a/packages/app/src/spotlightSettingsActions.tsx b/packages/app/src/spotlightSettingsActions.tsx new file mode 100644 index 000000000..e37d4732b --- /dev/null +++ b/packages/app/src/spotlightSettingsActions.tsx @@ -0,0 +1,207 @@ +import * as React from 'react'; +import { useRouter } from 'next/router'; +import { SpotlightActionData } from '@mantine/spotlight'; +import { + IconAdjustmentsHorizontal, + IconApi, + IconBrandTerraform, + IconDatabase, + IconDeviceDesktop, + IconKey, + IconMoon, + IconRobot, + IconSettings, + IconSun, + IconUserCog, + IconUsers, + IconWebhook, +} from '@tabler/icons-react'; + +import { IS_IAC_EXPORT_ENABLED, IS_LOCAL_MODE } from './config'; +import { useUserPreferencesModal } from './UserPreferencesModal'; +import { UserPreferences, useUserPreferences } from './useUserPreferences'; + +const GROUP_SETTINGS = 'Settings'; +const GROUP_PREFERENCES = 'Preferences'; + +type TeamSettingsEntry = { + id: string; + label: string; + description: string; + icon: React.ReactNode; + // `?tab=` and the section anchor match the tab values and section ids in + // TeamPage, which scrolls the anchored section into view. + href: string; + keywords: string[]; +}; + +const TEAM_SETTINGS_ENTRIES: TeamSettingsEntry[] = [ + { + id: 'settings-sources', + label: 'Sources', + description: 'Configure log, trace, metric, and session sources', + icon: , + href: '/team?tab=data#team-data-sources', + keywords: ['settings', 'data', 'source', 'table', 'schema', 'logs'], + }, + { + id: 'settings-connections', + label: 'Connections', + description: 'Manage ClickHouse connections', + icon: , + href: '/team?tab=data#team-data-connections', + keywords: ['settings', 'data', 'clickhouse', 'database', 'host'], + }, + { + id: 'settings-team-members', + label: 'Team members', + description: 'Invite and manage users on your team', + icon: , + href: '/team?tab=team#team-members', + keywords: ['settings', 'users', 'invite', 'people', 'members'], + }, + { + id: 'settings-api-keys', + label: 'API keys', + description: 'View your personal API key', + icon: , + href: '/team?tab=api-agents#team-api-agents-api-keys', + keywords: ['settings', 'api', 'key', 'token', 'ingestion'], + }, + ...(IS_LOCAL_MODE + ? [] + : [ + { + id: 'settings-org-api-keys', + label: 'Organization API keys', + description: 'Create and revoke organization API keys', + icon: , + href: '/team?tab=api-agents#team-api-agents-org-api-keys', + keywords: ['settings', 'api', 'key', 'token', 'org'], + }, + ]), + { + id: 'settings-mcp-server', + label: 'MCP server', + description: 'Connect your AI agents', + icon: , + href: '/team?tab=api-agents#team-api-agents-mcp-server', + keywords: ['settings', 'mcp', 'ai', 'agents', 'llm', 'claude', 'cursor'], + }, + ...(IS_IAC_EXPORT_ENABLED + ? [ + { + id: 'settings-terraform-export', + label: 'Export to Terraform', + description: 'Export your configuration as Terraform', + icon: , + href: '/team?tab=api-agents#team-api-agents-iac', + keywords: ['settings', 'terraform', 'iac', 'export'], + }, + ] + : []), + { + id: 'settings-webhooks', + label: 'Webhooks', + description: 'Manage alert notification integrations', + icon: , + href: '/team?tab=integrations#team-integrations-webhooks', + keywords: ['settings', 'integrations', 'slack', 'pagerduty', 'alerts'], + }, + { + id: 'settings-query-settings', + label: 'Query settings', + description: 'ClickHouse client settings for your team', + icon: , + href: '/team?tab=advanced#team-advanced-query-settings', + keywords: ['settings', 'clickhouse', 'query', 'advanced', 'timeout'], + }, +]; + +const COLOR_MODE_ENTRIES: { + colorMode: UserPreferences['colorMode']; + label: string; + icon: React.ReactNode; +}[] = [ + { colorMode: 'light', label: 'Use light mode', icon: }, + { colorMode: 'dark', label: 'Use dark mode', icon: }, + { + colorMode: 'system', + label: 'Use system color mode', + icon: , + }, +]; + +export const useSettingsSpotlightActions = (): SpotlightActionData[] => { + const router = useRouter(); + const { open: openUserPreferences } = useUserPreferencesModal(); + const { setUserPreference } = useUserPreferences(); + + return React.useMemo(() => { + // The team page renders nothing in local mode, and AppNav hides its link. + const teamActions: SpotlightActionData[] = IS_LOCAL_MODE + ? [] + : [ + { + id: 'team-settings', + group: GROUP_SETTINGS, + leftSection: , + label: 'Team settings', + keywords: ['settings', 'team', 'configuration'], + onClick: () => { + router.push('/team'); + }, + }, + ...TEAM_SETTINGS_ENTRIES.map(entry => ({ + id: entry.id, + group: GROUP_SETTINGS, + leftSection: entry.icon, + label: entry.label, + description: entry.description, + keywords: entry.keywords, + onClick: () => { + router.push(entry.href); + }, + })), + ]; + + const colorModeActions: SpotlightActionData[] = COLOR_MODE_ENTRIES.map( + entry => ({ + id: `preferences-color-mode-${entry.colorMode}`, + group: GROUP_PREFERENCES, + leftSection: entry.icon, + label: entry.label, + keywords: ['theme', 'color', 'appearance', 'light', 'dark', 'mode'], + onClick: () => { + setUserPreference({ colorMode: entry.colorMode }); + }, + }), + ); + + return [ + ...teamActions, + { + id: 'preferences', + group: GROUP_PREFERENCES, + leftSection: , + label: 'Preferences', + description: 'Time zone, time format, row click, font size, and theme', + keywords: [ + 'settings', + 'user', + 'time zone', + 'timezone', + 'utc', + '12h', + '24h', + 'font', + 'row click', + 'side panel', + 'appearance', + ], + onClick: openUserPreferences, + }, + ...colorModeActions, + ]; + }, [openUserPreferences, router, setUserPreference]); +};