Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/spotlight-settings-entries.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 11 additions & 12 deletions packages/app/src/Spotlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -28,6 +28,7 @@ export const useSpotlightActions = () => {

const { data: logViewsData } = useSavedSearches();
const { data: dashboardsData } = useDashboards();
const settingsActions = useSettingsSpotlightActions();

const actions = React.useMemo<SpotlightActionData[]>(() => {
const logViews = logViewsData ?? [];
Expand Down Expand Up @@ -171,16 +172,6 @@ export const useSpotlightActions = () => {
router.push('/services');
},
},
{
id: 'team-settings',
group: 'Menu',
leftSection: <IconSettings size={16} />,
label: 'Team Settings',

onClick: () => {
router.push('/team');
},
},
{
id: 'documentation',
group: 'Menu',
Expand All @@ -206,10 +197,18 @@ export const useSpotlightActions = () => {
);
},
},
...settingsActions,
);

return logViewActions;
}, [brandName, logomark, logViewsData, dashboardsData, router]);
}, [
brandName,
logomark,
logViewsData,
dashboardsData,
router,
settingsActions,
]);

return { actions };
};
Expand Down
16 changes: 16 additions & 0 deletions packages/app/src/TeamPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Stack gap="lg" pt="lg">
{sections.map(section => (
Expand Down
11 changes: 11 additions & 0 deletions packages/app/src/UserPreferencesModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { atom, useAtom } from 'jotai';
import { Badge } from '@clickhouse/click-ui';
import {
Divider,
Expand Down Expand Up @@ -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,
Expand Down
50 changes: 47 additions & 3 deletions packages/app/src/__tests__/Spotlights.test.tsx
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -11,7 +17,7 @@ jest.mock('next/router', () => ({
pathname: '',
query: '',
asPath: '',
push: jest.fn(),
push: mockPush,
events: {
on: jest.fn(),
off: jest.fn(),
Expand Down Expand Up @@ -90,6 +96,7 @@ describe('useSpotlightActions', () => {
// Reset mocks before each test
beforeEach(() => {
jest.clearAllMocks();
window.localStorage.clear();
mockUseSavedSearches.mockReturnValue(mockSavedSearches);
mockUseDashboards.mockReturnValue(mockSavedDashboard);
});
Expand All @@ -106,4 +113,41 @@ describe('useSpotlightActions', () => {
mockSavedDashboard.data[0].name,
);
});

const selectSpotlightAction = async (query: string, name: RegExp) => {
renderWithMantine(
<HDXSpotlightProvider>
<div />
</HDXSpotlightProvider>,
);
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);
});
});
14 changes: 9 additions & 5 deletions packages/app/src/components/AppNav/AppNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading