From 1a5e357bc349e011d1b80b1794875a9ed68238f1 Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Sat, 28 Nov 2026 12:21:13 +0000 Subject: [PATCH 01/17] fix(app): clarify chart explorer AI assistant and chart name controls - Focus the question input instead of the source select, so opening the AI assistant no longer pops the source dropdown. - Show the A shortcut as a Kbd instead of an '[A]' suffix. - Drop the Experimental badge. The assistant is already gated by the server's ANTHROPIC_API_KEY, so the badge implied an opt-in that does not exist. - Replace the chart name field with InlineNameInputControlled so the name is a label until clicked. Refs HDX-6227 Co-authored-by: Cursor --- packages/app/src/DBChartPage.tsx | 9 +++++---- .../DBEditTimeChartForm/EditTimeChartForm.tsx | 15 +++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/app/src/DBChartPage.tsx b/packages/app/src/DBChartPage.tsx index 186499a751..f73eb5b077 100644 --- a/packages/app/src/DBChartPage.tsx +++ b/packages/app/src/DBChartPage.tsx @@ -5,7 +5,7 @@ import Link from 'next/link'; import { parseAsJson, parseAsString, useQueryState } from 'nuqs'; import { useForm } from 'react-hook-form'; import { useHotkeys } from 'react-hotkeys-hook'; -import { Badge, Separator } from '@clickhouse/click-ui'; +import { Separator } from '@clickhouse/click-ui'; import { SavedChartConfig, SourceKind } from '@hyperdx/common-utils/dist/types'; import { Alert, @@ -15,6 +15,7 @@ import { Collapse, Divider, Group, + Kbd, Loader, Skeleton, Stack, @@ -163,10 +164,10 @@ function AIAssistant({ ) : ( )} - AI Assistant [A] + AI assistant + A - {opened && ( @@ -174,7 +175,6 @@ function AIAssistant({
- - Chart Name - - From dd0d9f74ac270282243336549bd6f2a944ed17aa Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Sat, 28 Nov 2026 12:28:59 +0000 Subject: [PATCH 02/17] feat(app): open the chart explorer AI assistant as a right-side panel The assistant expanded inline above the chart, pushing it down and away from where its result appears. It now opens in a resizable panel beside the chart, using the same docking as the alert panel. Generating a chart replaces the current chart and time range, so the success notification now offers an Undo that restores both. Moves the assistant out of DBChartPage into components/ChartAssistant. Co-authored-by: Cursor --- packages/app/src/DBChartPage.tsx | 284 +++++------------- .../ChartAssistant/ChartAssistant.tsx | 250 +++++++++++++++ .../__tests__/ChartAssistant.test.tsx | 106 +++++++ 3 files changed, 433 insertions(+), 207 deletions(-) create mode 100644 packages/app/src/components/ChartAssistant/ChartAssistant.tsx create mode 100644 packages/app/src/components/ChartAssistant/__tests__/ChartAssistant.test.tsx diff --git a/packages/app/src/DBChartPage.tsx b/packages/app/src/DBChartPage.tsx index f73eb5b077..17d4dfb03d 100644 --- a/packages/app/src/DBChartPage.tsx +++ b/packages/app/src/DBChartPage.tsx @@ -3,46 +3,37 @@ import dynamic from 'next/dynamic'; import Head from 'next/head'; import Link from 'next/link'; import { parseAsJson, parseAsString, useQueryState } from 'nuqs'; -import { useForm } from 'react-hook-form'; import { useHotkeys } from 'react-hotkeys-hook'; -import { Separator } from '@clickhouse/click-ui'; -import { SavedChartConfig, SourceKind } from '@hyperdx/common-utils/dist/types'; +import { SavedChartConfig } from '@hyperdx/common-utils/dist/types'; import { - Alert, Anchor, Box, Button, - Collapse, - Divider, + Flex, Group, Kbd, - Loader, Skeleton, Stack, Text, } from '@mantine/core'; import { notifications } from '@mantine/notifications'; -import { - IconChevronDown, - IconChevronUp, - IconInfoCircle, -} from '@tabler/icons-react'; +import { IconLayoutSidebarRight } from '@tabler/icons-react'; import { useQueryClient } from '@tanstack/react-query'; import api from '@/api'; -import { useBrandDisplayName, usePageTitle } from '@/brand'; +import { usePageTitle } from '@/brand'; import { DEFAULT_CHART_CONFIG } from '@/ChartUtils'; +import { + ChartAssistantPanel, + ChartAssistantUnavailableAlert, +} from '@/components/ChartAssistant/ChartAssistant'; import EditTimeChartForm from '@/components/DBEditTimeChartForm'; -import { InputControlled } from '@/components/InputControlled'; -import { SourceSelectControlled } from '@/components/SourceSelect'; import { IS_ALERT_DETAILS_ENABLED } from '@/config'; -import { useChartAssistant } from '@/hooks/ai'; import { useAlertSeededChartConfig } from '@/hooks/useAlertSeededChartConfig'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { withAppNavForSurface } from '@/layout'; import { useSources } from '@/source'; import { useDefaultTimeRange, useNewTimeQuery } from '@/timeQuery'; -import { useLocalStorage } from '@/utils'; import { buildInlineAlertPayload } from '@/utils/alerts'; import { getApiErrorMessage } from '@/utils/apiErrors'; @@ -52,162 +43,6 @@ import OnboardingModal from './components/OnboardingModal'; // Sampled field discovery and full field discovery -function AIAssistant({ - setConfig, - onTimeRangeSelect, - submitRef, - aiAssistantEnabled, -}: { - setConfig: (config: SavedChartConfig) => void; - onTimeRangeSelect: (start: Date, end: Date) => void; - submitRef: React.RefObject<(() => void) | undefined>; - aiAssistantEnabled: boolean; -}) { - const brandName = useBrandDisplayName(); - const [opened, setOpened] = useState(false); - const [alertDismissed, setAlertDismissed] = useLocalStorage( - 'ai-assistant-alert-dismissed', - false, - ); - const { control, handleSubmit } = useForm<{ - text: string; - source: string; - }>({ - defaultValues: { - text: '', - source: '', - }, - }); - - const chartAssistant = useChartAssistant(); - - const onSubmit = (data: { text: string; source: string }) => { - chartAssistant.mutate( - { - sourceId: data.source, - text: data.text, - }, - { - onSuccess(data) { - setConfig({ ...data, where: '' }); - onTimeRangeSelect( - new Date(data.dateRange[0]), - new Date(data.dateRange[1]), - ); - - // FIXME: This is a hack to submit after the form has been updated - setTimeout(() => { - if (submitRef.current) { - submitRef.current(); - } - }, 100); - - notifications.show({ - color: 'green', - message: 'Chart generated successfully', - autoClose: 2000, - }); - }, - onError(err) { - notifications.show({ - color: 'red', - title: 'Error Generating Chart', - message: err.message, - autoClose: 2000, - }); - }, - }, - ); - }; - - useHotkeys( - 'a', - () => { - setOpened(v => !v); - }, - { - preventDefault: true, - }, - ); - - if (!aiAssistantEnabled && !alertDismissed) { - return ( - - } - variant="outline" - withCloseButton - onClose={() => setAlertDismissed(true)} - p="xxs" - > - - New AI Assistant available, enable with configuring the{' '} - ANTHROPIC_API_KEY environment variable on the{' '} - {brandName} server. - - - - - ); - } else if (!aiAssistantEnabled) { - return null; - } - - return ( - - - - - - {opened && ( - // eslint-disable-next-line react-hooks/refs - - - - - - - {chartAssistant.isPending ? ( - - ) : ( - - )} - - - )} - - - - ); -} - const DEFAULT_INTERVAL = 'Past 1h'; function DBChartExplorerPage() { @@ -230,6 +65,16 @@ function DBChartExplorerPage() { const { data: me } = api.useMe(); const queryClient = useQueryClient(); const createAlert = api.useCreateAlert(); + const aiAssistantEnabled = me?.aiAssistantEnabled ?? false; + const [assistantOpened, setAssistantOpened] = useState(false); + + useHotkeys( + 'a', + () => { + if (aiAssistantEnabled) setAssistantOpened(v => !v); + }, + { preventDefault: true }, + ); const [rawChartConfig, setChartConfig] = useQueryState( 'config', @@ -320,40 +165,65 @@ function DBChartExplorerPage() { {title} - - {/* Held back until an `alertId` seed resolves: the form auto-runs once - on mount, and mounting it early would run the default config and - then swap the query out from under the result. */} - {isSeedingFromAlert ? ( - - - - - ) : ( - { - setChartConfig(config); - }} - dateRange={searchedTimeRange} - setDisplayedTimeInputValue={setDisplayedTimeInputValue} - displayedTimeInputValue={displayedTimeInputValue} - onTimeRangeSearch={onSearch} - onTimeRangeSelect={onTimeRangeSelect} - submitRef={submitRef} - autoRun - enableAlerts - onSaveAlert={onSaveAlert} - saveAlertLabel="Create alert" - isSavingAlert={createAlert.isPending} - /> - )} + + + + {aiAssistantEnabled && ( + + + + )} + {/* Held back until an `alertId` seed resolves: the form auto-runs once + on mount, and mounting it early would run the default config and + then swap the query out from under the result. */} + {isSeedingFromAlert ? ( + + + + + ) : ( + { + setChartConfig(config); + }} + dateRange={searchedTimeRange} + setDisplayedTimeInputValue={setDisplayedTimeInputValue} + displayedTimeInputValue={displayedTimeInputValue} + onTimeRangeSearch={onSearch} + onTimeRangeSelect={onTimeRangeSelect} + submitRef={submitRef} + autoRun + enableAlerts + onSaveAlert={onSaveAlert} + saveAlertLabel="Create alert" + isSavingAlert={createAlert.isPending} + /> + )} + + {assistantOpened && aiAssistantEnabled && ( + setAssistantOpened(false)} + /> + )} + ); } diff --git a/packages/app/src/components/ChartAssistant/ChartAssistant.tsx b/packages/app/src/components/ChartAssistant/ChartAssistant.tsx new file mode 100644 index 0000000000..1b58fe5fb5 --- /dev/null +++ b/packages/app/src/components/ChartAssistant/ChartAssistant.tsx @@ -0,0 +1,250 @@ +import type { RefObject } from 'react'; +import { useForm } from 'react-hook-form'; +import { SavedChartConfig, SourceKind } from '@hyperdx/common-utils/dist/types'; +import { + ActionIcon, + Alert, + Box, + Button, + Divider, + Group, + Loader, + Stack, + Text, +} from '@mantine/core'; +import { notifications } from '@mantine/notifications'; +import { IconInfoCircle, IconX } from '@tabler/icons-react'; + +import { useBrandDisplayName } from '@/brand'; +import { InputControlled } from '@/components/InputControlled'; +import { SourceSelectControlled } from '@/components/SourceSelect'; +import { useChartAssistant } from '@/hooks/ai'; +import useResizable from '@/hooks/useResizable'; +import { useLocalStorage } from '@/utils'; + +import resizeStyles from '@styles/ResizablePanel.module.scss'; + +// Widths as percentages of the window, the unit useResizable drags in. +const DEFAULT_PANEL_WIDTH_PERCENT = 30; +const MAX_PANEL_WIDTH_PERCENT = 50; +const MIN_PANEL_WIDTH = 320; + +const UNDO_NOTIFICATION_MS = 8000; + +interface ChartAssistantFormValues { + text: string; + source: string; +} + +export function ChartAssistantUnavailableAlert({ + aiAssistantEnabled, +}: { + aiAssistantEnabled: boolean; +}) { + const brandName = useBrandDisplayName(); + const [alertDismissed, setAlertDismissed] = useLocalStorage( + 'ai-assistant-alert-dismissed', + false, + ); + + if (aiAssistantEnabled || alertDismissed) return null; + + return ( + + } + variant="outline" + withCloseButton + onClose={() => setAlertDismissed(true)} + p="xxs" + > + + New AI Assistant available, enable with configuring the{' '} + ANTHROPIC_API_KEY environment variable on the {brandName}{' '} + server. + + + + + ); +} + +export interface ChartAssistantPanelProps { + currentConfig: SavedChartConfig; + searchedTimeRange: [Date, Date]; + setConfig: (config: SavedChartConfig) => void; + onTimeRangeSelect: (start: Date, end: Date) => void; + submitRef: RefObject<(() => void) | undefined>; + onClose: () => void; +} + +/** + * Generates a chart from a prompt, docked beside the chart explorer. The + * generated chart replaces the current one, so the notification after a + * successful generation offers to restore the previous chart and time range. + */ +export function ChartAssistantPanel({ + currentConfig, + searchedTimeRange, + setConfig, + onTimeRangeSelect, + submitRef, + onClose, +}: ChartAssistantPanelProps) { + const { control, handleSubmit } = useForm({ + defaultValues: { + text: '', + source: '', + }, + }); + const chartAssistant = useChartAssistant(); + const { size: widthPercent, startResize } = useResizable( + DEFAULT_PANEL_WIDTH_PERCENT, + 'right', + { + minPercent: + typeof window === 'undefined' + ? undefined + : (MIN_PANEL_WIDTH / window.innerWidth) * 100, + maxPercent: MAX_PANEL_WIDTH_PERCENT, + }, + ); + + const onSubmit = (data: ChartAssistantFormValues) => { + const previousConfig = currentConfig; + const [previousStart, previousEnd] = searchedTimeRange; + + chartAssistant.mutate( + { + sourceId: data.source, + text: data.text, + }, + { + onSuccess(generated) { + setConfig({ ...generated, where: '' }); + onTimeRangeSelect( + new Date(generated.dateRange[0]), + new Date(generated.dateRange[1]), + ); + + // FIXME: This is a hack to submit after the form has been updated + setTimeout(() => { + if (submitRef.current) { + submitRef.current(); + } + }, 100); + + const notificationId = notifications.show({ + color: 'green', + autoClose: UNDO_NOTIFICATION_MS, + message: ( + + Chart generated. + + + ), + }); + }, + onError(err) { + notifications.show({ + color: 'red', + title: 'Error generating chart', + message: err.message, + autoClose: 2000, + }); + }, + }, + ); + }; + + return ( + +
+ + + + AI assistant + + + + + + + Describe the chart you want. It replaces the current chart, and you + can undo it. + + {/* eslint-disable-next-line react-hooks/refs */} +
+ + + + + {chartAssistant.isPending ? ( + + ) : ( + + )} + + +
+
+ + ); +} diff --git a/packages/app/src/components/ChartAssistant/__tests__/ChartAssistant.test.tsx b/packages/app/src/components/ChartAssistant/__tests__/ChartAssistant.test.tsx new file mode 100644 index 0000000000..0d74840351 --- /dev/null +++ b/packages/app/src/components/ChartAssistant/__tests__/ChartAssistant.test.tsx @@ -0,0 +1,106 @@ +import { SavedChartConfig } from '@hyperdx/common-utils/dist/types'; +import { screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; + +import { DEFAULT_CHART_CONFIG } from '@/ChartUtils'; +import { ChartAssistantPanel } from '@/components/ChartAssistant/ChartAssistant'; + +const mockMutate = jest.fn(); +jest.mock('@/hooks/ai', () => ({ + useChartAssistant: () => ({ mutate: mockMutate, isPending: false }), +})); + +jest.mock('@/components/SourceSelect', () => ({ + SourceSelectControlled: () =>
, +})); + +jest.mock('@/hooks/useResizable', () => ({ + __esModule: true, + default: () => ({ size: 30, startResize: jest.fn() }), +})); + +const mockNotificationShow = jest.fn(); +jest.mock('@mantine/notifications', () => ({ + notifications: { + show: (...args: unknown[]) => mockNotificationShow(...args), + update: jest.fn(), + }, +})); + +const previousConfig: SavedChartConfig = { + ...DEFAULT_CHART_CONFIG, + source: 'previous-source', + where: 'service:api', +}; +const previousRange: [Date, Date] = [ + new Date('2026-11-27T00:00:00Z'), + new Date('2026-11-27T01:00:00Z'), +]; +const generatedResponse = { + ...DEFAULT_CHART_CONFIG, + source: 'generated-source', + where: 'generated', + dateRange: ['2026-11-26T00:00:00Z', '2026-11-26T06:00:00Z'], +}; + +function renderPanel() { + const setConfig = jest.fn(); + const onTimeRangeSelect = jest.fn(); + renderWithMantine( + , + ); + return { setConfig, onTimeRangeSelect }; +} + +describe('ChartAssistantPanel', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('replaces the chart on success and offers an undo that restores it', async () => { + const user = userEvent.setup(); + const { setConfig, onTimeRangeSelect } = renderPanel(); + + await user.type( + screen.getByTestId('save-search-name-input'), + 'errors by service', + ); + await user.click(screen.getByRole('button', { name: 'Generate' })); + + const [input, options] = mockMutate.mock.calls[0]; + expect(input).toEqual({ sourceId: '', text: 'errors by service' }); + + options.onSuccess(generatedResponse); + expect(setConfig).toHaveBeenCalledWith({ ...generatedResponse, where: '' }); + expect(onTimeRangeSelect).toHaveBeenCalledWith( + new Date('2026-11-26T00:00:00Z'), + new Date('2026-11-26T06:00:00Z'), + ); + + const [{ message }] = mockNotificationShow.mock.calls[0]; + renderWithMantine(<>{message}); + setConfig.mockClear(); + onTimeRangeSelect.mockClear(); + + await user.click(screen.getByRole('button', { name: 'Undo' })); + + expect(setConfig).toHaveBeenCalledWith(previousConfig); + expect(onTimeRangeSelect).toHaveBeenCalledWith(...previousRange); + }); + + it('does not submit an empty prompt', async () => { + const user = userEvent.setup(); + renderPanel(); + + await user.click(screen.getByRole('button', { name: 'Generate' })); + + await waitFor(() => expect(mockMutate).not.toHaveBeenCalled()); + }); +}); From 96537716810638d9388a56c5ff73ddc89c52e532 Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Sat, 28 Nov 2026 18:42:28 +0000 Subject: [PATCH 03/17] feat(app): label the chart explorer's save to dashboard action Saving a chart from the explorer was only reachable through an unlabeled kebab menu next to Run, so users did not find it. Make it a labeled secondary button that opens the existing save modal. The modal title and button use sentence case. Adds unit and e2e coverage for the explorer-to-dashboard save. Co-authored-by: Cursor --- .../DBEditTimeChartForm/ChartActionBar.tsx | 40 +++++-------------- .../__tests__/ChartActionBar.test.tsx | 25 ++++++++++++ .../src/components/SaveToDashboardModal.tsx | 4 +- .../tests/e2e/features/chart-explorer.spec.ts | 36 +++++++++++++++++ .../e2e/page-objects/ChartExplorerPage.ts | 23 +++++++++++ 5 files changed, 97 insertions(+), 31 deletions(-) diff --git a/packages/app/src/components/DBEditTimeChartForm/ChartActionBar.tsx b/packages/app/src/components/DBEditTimeChartForm/ChartActionBar.tsx index aa25ac16cb..df9d326276 100644 --- a/packages/app/src/components/DBEditTimeChartForm/ChartActionBar.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/ChartActionBar.tsx @@ -1,20 +1,8 @@ import { Control, useWatch } from 'react-hook-form'; import { TableConnection } from '@hyperdx/common-utils/dist/core/metadata'; import { isRangeQuery } from '@hyperdx/common-utils/dist/core/promql'; -import { - ActionIcon, - Box, - Button, - Flex, - Menu, - Switch, - Tooltip, -} from '@mantine/core'; -import { - IconDotsVertical, - IconLayoutGrid, - IconPlayerPlay, -} from '@tabler/icons-react'; +import { Box, Button, Flex, Switch, Tooltip } from '@mantine/core'; +import { IconLayoutGrid, IconPlayerPlay } from '@tabler/icons-react'; import { ChartEditorFormState } from '@/components/ChartEditor/types'; import { isPromqlDisplayType } from '@/components/ChartEditor/utils'; @@ -180,21 +168,15 @@ export function ChartActionBar({ )} {!IS_LOCAL_MODE && (showSaveToDashboard ?? !dashboardId) && ( - - - - - - - - } - onClick={() => setSaveToDashboardModalOpen(true)} - > - Save to Dashboard - - - + )} diff --git a/packages/app/src/components/DBEditTimeChartForm/__tests__/ChartActionBar.test.tsx b/packages/app/src/components/DBEditTimeChartForm/__tests__/ChartActionBar.test.tsx index eb9707ff10..d076baed92 100644 --- a/packages/app/src/components/DBEditTimeChartForm/__tests__/ChartActionBar.test.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/__tests__/ChartActionBar.test.tsx @@ -307,4 +307,29 @@ describe('ChartActionBar', () => { expect(screen.getByTestId('chart-run-query-button')).toBeInTheDocument(); expect(screen.getByTestId('granularity-picker')).toBeInTheDocument(); }); + + describe('save to dashboard', () => { + const saveButton = () => + screen.queryByRole('button', { name: 'Save to dashboard' }); + + it('is offered outside a dashboard and opens the save modal', async () => { + const { setSaveToDashboardModalOpen } = renderActionBar(); + + expect(saveButton()).toBeInTheDocument(); + await userEvent.click(saveButton()!); + + expect(setSaveToDashboardModalOpen).toHaveBeenCalledWith(true); + }); + + it('is absent on a dashboard tile', () => { + renderActionBar({ dashboardId: 'dashboard-1' }); + + expect(saveButton()).not.toBeInTheDocument(); + }); + + it('follows showSaveToDashboard when it is set', () => { + renderActionBar({ showSaveToDashboard: false }); + expect(saveButton()).not.toBeInTheDocument(); + }); + }); }); diff --git a/packages/app/src/components/SaveToDashboardModal.tsx b/packages/app/src/components/SaveToDashboardModal.tsx index 229643a12b..740d32c603 100644 --- a/packages/app/src/components/SaveToDashboardModal.tsx +++ b/packages/app/src/components/SaveToDashboardModal.tsx @@ -204,7 +204,7 @@ export default function SaveToDashboardModal({
@@ -281,7 +281,7 @@ export default function SaveToDashboardModal({ Cancel diff --git a/packages/app/tests/e2e/features/chart-explorer.spec.ts b/packages/app/tests/e2e/features/chart-explorer.spec.ts index 5c87132827..1b983b338d 100644 --- a/packages/app/tests/e2e/features/chart-explorer.spec.ts +++ b/packages/app/tests/e2e/features/chart-explorer.spec.ts @@ -1,6 +1,7 @@ import { DisplayType } from '@hyperdx/common-utils/dist/types'; import { ChartExplorerPage } from '../page-objects/ChartExplorerPage'; +import { DashboardPage } from '../page-objects/DashboardPage'; import { expect, test } from '../utils/base-test'; import { DEFAULT_LOGS_SOURCE_NAME, @@ -579,3 +580,38 @@ test.describe( }); }, ); + +test.describe('Chart Explorer save to dashboard', { tag: ['@charts'] }, () => { + test( + 'saves the chart to a new dashboard', + { tag: '@full-stack' }, + async ({ page }) => { + const chartExplorerPage = new ChartExplorerPage(page); + const dashboardPage = new DashboardPage(page); + const ts = Date.now(); + const chartName = `E2E Explorer Chart ${ts}`; + const dashboardName = `E2E Explorer Dashboard ${ts}`; + + await test.step('Open the explorer and run a named chart', async () => { + await chartExplorerPage.goto(); + await expect(chartExplorerPage.form).toBeVisible(); + await chartExplorerPage.chartEditor.setChartName(chartName); + await chartExplorerPage.chartEditor.runQuery(); + }); + + await test.step('Save the chart to a new dashboard', async () => { + await expect(chartExplorerPage.saveToDashboardButton).toBeVisible(); + await chartExplorerPage.saveToNewDashboard(dashboardName); + }); + + await test.step('Open the dashboard and find the chart on it', async () => { + await chartExplorerPage.openSavedDashboard(dashboardName); + await dashboardPage.waitForLoaded(); + await expect( + dashboardPage.getDashboardHeading(dashboardName), + ).toBeVisible(); + await expect(dashboardPage.getTile(0)).toContainText(chartName); + }); + }, + ); +}); diff --git a/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts b/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts index d54b986555..5f7b17d662 100644 --- a/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts +++ b/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts @@ -134,6 +134,29 @@ export class ChartExplorerPage { return (await cells.allTextContents()).map(c => c.trim()); } + /** The "Save to dashboard" button in the chart action bar. */ + get saveToDashboardButton() { + return this.page.getByTestId('chart-save-to-dashboard-button'); + } + + /** Save the current chart as the first tile of a new dashboard. */ + async saveToNewDashboard(dashboardName: string) { + await this.saveToDashboardButton.click(); + const dialog = this.page.getByRole('dialog'); + await dialog.getByPlaceholder('Select a dashboard').click(); + await this.page + .getByRole('option', { name: 'Create New Dashboard' }) + .click(); + await dialog.getByPlaceholder('Enter dashboard name').fill(dashboardName); + await dialog.getByRole('button', { name: 'Save to dashboard' }).click(); + } + + /** Open the dashboard linked from the "Chart saved to dashboard" notification. */ + async openSavedDashboard(dashboardName: string) { + await this.page.getByRole('link', { name: dashboardName }).click(); + await this.page.waitForURL('**/dashboards/**'); + } + // Getters for assertions get form() { From 9098cf158d3895ec5fdc7012f39b28fd76d529a9 Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Sat, 28 Nov 2026 18:58:49 +0000 Subject: [PATCH 04/17] feat(app): drop the explorer chart name and name charts on save The explorer's name field was discarded unless the chart was saved, and it changed nothing visible while exploring. Hide it in the explorer. An unnamed chart now gets a default name from its first series and group by when it is saved to a dashboard, and that name seeds an inline alert's display name. Tile names are still editable in the tile editor. Co-authored-by: Cursor --- packages/app/src/DBChartPage.tsx | 1 + .../ChartEditor/__tests__/utils.test.ts | 28 ++++++++++++++++ .../app/src/components/ChartEditor/utils.ts | 18 +++++++++++ .../ChartEditorControls.tsx | 8 ++++- .../DBEditTimeChartForm/EditTimeChartForm.tsx | 32 ++++++++++++------- .../src/components/SaveToDashboardModal.tsx | 17 ++++++++-- .../tests/e2e/features/chart-explorer.spec.ts | 12 +++---- 7 files changed, 95 insertions(+), 21 deletions(-) diff --git a/packages/app/src/DBChartPage.tsx b/packages/app/src/DBChartPage.tsx index 17d4dfb03d..03efd14fef 100644 --- a/packages/app/src/DBChartPage.tsx +++ b/packages/app/src/DBChartPage.tsx @@ -205,6 +205,7 @@ function DBChartExplorerPage() { onTimeRangeSearch={onSearch} onTimeRangeSelect={onTimeRangeSelect} submitRef={submitRef} + showChartName={false} autoRun enableAlerts onSaveAlert={onSaveAlert} diff --git a/packages/app/src/components/ChartEditor/__tests__/utils.test.ts b/packages/app/src/components/ChartEditor/__tests__/utils.test.ts index a8da9b70a4..75398a9f48 100644 --- a/packages/app/src/components/ChartEditor/__tests__/utils.test.ts +++ b/packages/app/src/components/ChartEditor/__tests__/utils.test.ts @@ -24,6 +24,7 @@ import { convertFormStateToSavedChartConfig, convertSavedChartConfigToFormState, getAllowedSourceKinds, + getDefaultChartName, getInterchangeableSourceKind, promqlExpressionPlaceholder, validateChartForm, @@ -2805,3 +2806,30 @@ describe('getInterchangeableSourceKind', () => { }, ); }); + +describe('getDefaultChartName', () => { + it('names a count without a group by', () => { + expect(getDefaultChartName({ aggFn: 'count' }, undefined)).toBe( + 'Count of events', + ); + }); + + it('adds the group by', () => { + expect(getDefaultChartName({ aggFn: 'count' }, 'ServiceName')).toBe( + 'Count of events by ServiceName', + ); + }); + + it('names a measure after its column', () => { + expect( + getDefaultChartName( + { aggFn: 'avg', valueExpression: 'Duration' }, + 'ServiceName', + ), + ).toBe('avg of Duration by ServiceName'); + }); + + it('falls back when there is no series', () => { + expect(getDefaultChartName(undefined, undefined)).toBe('Untitled chart'); + }); +}); diff --git a/packages/app/src/components/ChartEditor/utils.ts b/packages/app/src/components/ChartEditor/utils.ts index e6f2dba3e3..5a4d139d5d 100644 --- a/packages/app/src/components/ChartEditor/utils.ts +++ b/packages/app/src/components/ChartEditor/utils.ts @@ -830,3 +830,21 @@ export const validateChartForm = ( return errors; }; + +/** + * Name for a chart the user has not named, from its first series and group by. + * It becomes the tile name on save and the default alert name, so an unnamed + * chart still has a name where it is stored. + */ +export function getDefaultChartName( + firstSeries: { aggFn?: string; valueExpression?: string } | undefined, + groupBy: string | undefined, +): string { + if (firstSeries?.aggFn == null) return 'Untitled chart'; + const measure = + firstSeries.aggFn === 'count' + ? 'Count of events' + : `${firstSeries.aggFn} of ${firstSeries.valueExpression?.trim() || 'events'}`; + const by = groupBy?.trim(); + return by ? `${measure} by ${by}` : measure; +} diff --git a/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx b/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx index 7c5d577cd3..9e25fae52e 100644 --- a/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx @@ -26,6 +26,7 @@ import { SavedChartConfigWithSelectArray, } from '@/components/ChartEditor/types'; import { + getDefaultChartName, isFormulaDisplayType, isFormulaSourceKind, } from '@/components/ChartEditor/utils'; @@ -516,7 +517,12 @@ export function ChartEditorControls({ onAddAlert={() => setValue('alert', { ...DEFAULT_TILE_ALERT, - ...(chartName && { displayName: chartName }), + displayName: + chartName || + getDefaultChartName( + series?.[0], + typeof groupBy === 'string' ? groupBy : undefined, + ), }) } /> diff --git a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx index 4c9539d446..e00340a80d 100644 --- a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx @@ -155,6 +155,11 @@ type EditTimeChartFormProps = { 'data-testid'?: string; submitRef?: React.MutableRefObject<(() => void) | undefined>; isDashboardForm?: boolean; + /** + * Whether to show the chart name field. The explorer hides it: a name typed + * there has no saved object to live on until the chart is saved as a tile. + */ + showChartName?: boolean; autoRun?: boolean; /** * Whether the editor offers an alert. Defaults to "inside a dashboard", @@ -269,6 +274,7 @@ export default function EditTimeChartForm({ 'data-testid': dataTestId, submitRef, isDashboardForm = false, + showChartName = true, autoRun = false, enableAlerts, onSaveAlert, @@ -1308,18 +1314,20 @@ export default function EditTimeChartForm({ direction={{ base: 'column', lg: 'row' }} align={{ base: 'stretch', lg: 'center' }} > - - - + {showChartName && ( + + + + )} {isDashboardForm && ( diff --git a/packages/app/src/components/SaveToDashboardModal.tsx b/packages/app/src/components/SaveToDashboardModal.tsx index 740d32c603..0e197f384e 100644 --- a/packages/app/src/components/SaveToDashboardModal.tsx +++ b/packages/app/src/components/SaveToDashboardModal.tsx @@ -1,5 +1,6 @@ import { useEffect } from 'react'; import { Controller, useForm, useWatch } from 'react-hook-form'; +import { isBuilderSavedChartConfig } from '@hyperdx/common-utils/dist/guards'; import { SavedChartConfig } from '@hyperdx/common-utils/dist/types'; import { Box, @@ -15,6 +16,7 @@ import { import { notifications } from '@mantine/notifications'; import { useQueryClient } from '@tanstack/react-query'; +import { getDefaultChartName } from '@/components/ChartEditor/utils'; import { Dashboard, Tile, @@ -36,6 +38,17 @@ interface SaveToDashboardModalProps { const CREATE_NEW_DASHBOARD_VALUE = '_new'; +// The explorer no longer names charts, so an unnamed chart gets a name from +// its query when it is saved as a tile. +function getTileName(chartConfig: SavedChartConfig): string { + if (chartConfig.name) return chartConfig.name; + if (!isBuilderSavedChartConfig(chartConfig)) return 'Untitled chart'; + return getDefaultChartName( + Array.isArray(chartConfig.select) ? chartConfig.select[0] : undefined, + typeof chartConfig.groupBy === 'string' ? chartConfig.groupBy : undefined, + ); +} + export default function SaveToDashboardModal({ chartConfig, opened, @@ -84,7 +97,7 @@ export default function SaveToDashboardModal({ y: position.y, w: size.w, h: size.h, - config: chartConfig, + config: { ...chartConfig, name: getTileName(chartConfig) }, }; }; @@ -219,7 +232,7 @@ export default function SaveToDashboardModal({ Name: - {chartConfig.name || 'Untitled Chart'} + {getTileName(chartConfig)} {chartConfig.displayType && ( diff --git a/packages/app/tests/e2e/features/chart-explorer.spec.ts b/packages/app/tests/e2e/features/chart-explorer.spec.ts index 1b983b338d..a77d79d008 100644 --- a/packages/app/tests/e2e/features/chart-explorer.spec.ts +++ b/packages/app/tests/e2e/features/chart-explorer.spec.ts @@ -588,14 +588,14 @@ test.describe('Chart Explorer save to dashboard', { tag: ['@charts'] }, () => { async ({ page }) => { const chartExplorerPage = new ChartExplorerPage(page); const dashboardPage = new DashboardPage(page); - const ts = Date.now(); - const chartName = `E2E Explorer Chart ${ts}`; - const dashboardName = `E2E Explorer Dashboard ${ts}`; + const dashboardName = `E2E Explorer Dashboard ${Date.now()}`; + // The explorer has no name field, so the tile takes the default name + // for the default query: a count of events. + const defaultChartName = 'Count of events'; - await test.step('Open the explorer and run a named chart', async () => { + await test.step('Open the explorer and run the default chart', async () => { await chartExplorerPage.goto(); await expect(chartExplorerPage.form).toBeVisible(); - await chartExplorerPage.chartEditor.setChartName(chartName); await chartExplorerPage.chartEditor.runQuery(); }); @@ -610,7 +610,7 @@ test.describe('Chart Explorer save to dashboard', { tag: ['@charts'] }, () => { await expect( dashboardPage.getDashboardHeading(dashboardName), ).toBeVisible(); - await expect(dashboardPage.getTile(0)).toContainText(chartName); + await expect(dashboardPage.getTile(0)).toContainText(defaultChartName); }); }, ); From f30f448aaaf2a31690e0a102e24acb956469496e Mon Sep 17 00:00:00 2001 From: Elizabet Oliveira Date: Sat, 28 Nov 2026 19:26:54 +0000 Subject: [PATCH 05/17] Use a select for chart type and fold header controls into one row The chart type tabs took a full row and the AI assistant toggle sat on its own line above the builder toggle. Move the chart type into the header next to the builder toggle and pass the AI assistant toggle in as a header action, which removes two rows above the chart. Markdown is only offered on dashboard forms. The explorer has nowhere to save a markdown tile, so the option was dead weight there. Existing markdown tiles keep their type. Co-authored-by: Cursor --- packages/app/src/DBChartPage.tsx | 32 ++-- .../DBEditTimeChartForm/EditTimeChartForm.tsx | 168 +++++++++--------- .../__tests__/DBEditTimeChartForm.test.tsx | 37 ++++ .../e2e/components/ChartEditorComponent.ts | 18 +- .../tests/e2e/page-objects/DashboardPage.ts | 15 +- 5 files changed, 159 insertions(+), 111 deletions(-) diff --git a/packages/app/src/DBChartPage.tsx b/packages/app/src/DBChartPage.tsx index 03efd14fef..62645dae4b 100644 --- a/packages/app/src/DBChartPage.tsx +++ b/packages/app/src/DBChartPage.tsx @@ -168,22 +168,6 @@ function DBChartExplorerPage() { - {aiAssistantEnabled && ( - - - - )} {/* Held back until an `alertId` seed resolves: the form auto-runs once on mount, and mounting it early would run the default config and then swap the query out from under the result. */} @@ -211,6 +195,22 @@ function DBChartExplorerPage() { onSaveAlert={onSaveAlert} saveAlertLabel="Create alert" isSavingAlert={createAlert.isPending} + headerActions={ + aiAssistantEnabled ? ( + + ) : undefined + } /> )} diff --git a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx index e00340a80d..67cedab9a0 100644 --- a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx @@ -1,4 +1,11 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { + type ReactNode, + useCallback, + useEffect, + useMemo, + useRef, + useState, +} from 'react'; import { isEqual } from 'lodash'; import { Controller, @@ -45,7 +52,7 @@ import { Box, Flex, SegmentedControl, - Tabs, + Select, Text, Textarea, } from '@mantine/core'; @@ -181,8 +188,30 @@ type EditTimeChartFormProps = { isAlertRequired?: boolean; /** Whether to offer "Save to dashboard". Defaults to "outside a dashboard". */ showSaveToDashboard?: boolean; + /** Extra controls rendered in the header row, next to the config type toggle. */ + headerActions?: ReactNode; }; +const CHART_TYPE_OPTIONS: { + value: DisplayType; + label: string; + Icon: typeof IconChartLine; +}[] = [ + { value: DisplayType.Line, label: 'Time Series', Icon: IconChartLine }, + { value: DisplayType.Table, label: 'Table', Icon: IconTable }, + { value: DisplayType.Number, label: 'Number', Icon: IconNumbers }, + { value: DisplayType.Bar, label: 'Bar', Icon: IconChartBar }, + { value: DisplayType.Pie, label: 'Pie', Icon: IconChartPie }, + { value: DisplayType.Search, label: 'Search', Icon: IconList }, + { value: DisplayType.Heatmap, label: 'Heatmap', Icon: IconGrid3x3 }, + { + value: DisplayType.EventPatterns, + label: 'Patterns', + Icon: IconBracketsContain, + }, + { value: DisplayType.Markdown, label: 'Markdown', Icon: IconMarkdown }, +]; + const zodChartFormResolver = zodResolver(zSavedChartConfig); // A tile on a variable can't keep an alert. The form holds on to it, so that @@ -282,6 +311,7 @@ export default function EditTimeChartForm({ isSavingAlert, isAlertRequired = false, showSaveToDashboard, + headerActions, }: EditTimeChartFormProps) { const formValue: ChartEditorFormState = useMemo( () => convertSavedChartConfigToFormState(chartConfig), @@ -1357,6 +1387,61 @@ export default function EditTimeChartForm({ )} + { + const selectedType = isTimeSeriesDisplayType(value) + ? DisplayType.Line + : value; + // Markdown tiles are a dashboard feature; the explorer has no + // place to save one, so only offer it on dashboard forms (or + // keep it when the current value already is markdown). + const options = CHART_TYPE_OPTIONS.filter( + option => + option.value !== DisplayType.Markdown || + isDashboardForm || + value === DisplayType.Markdown, + ); + const selectedOption = CHART_TYPE_OPTIONS.find( + option => option.value === selectedType, + ); + const SelectedIcon = selectedOption?.Icon; + return ( +