From 123c74663a065d3e3241181b3bf7811efa0aaf65 Mon Sep 17 00:00:00 2001 From: Drew Davis Date: Tue, 22 Sep 2026 11:18:47 -0400 Subject: [PATCH 1/2] feat: Filter and select sources by language and display type --- .changeset/chart-editor-source-filtering.md | 5 + .../ChartEditor/PromqlChartEditor.tsx | 5 +- .../ChartEditor/RawSqlChartEditor.tsx | 5 + .../ChartEditor/__tests__/utils.test.ts | 67 +++++++++++ .../app/src/components/ChartEditor/utils.ts | 34 ++++++ .../ChartEditorControls.tsx | 13 +- .../DBEditTimeChartForm/EditTimeChartForm.tsx | 104 +++++++++++++++- .../__tests__/sourceSelectUtils.test.tsx | 40 +++++++ .../app/src/components/sourceSelectUtils.tsx | 15 +++ .../e2e/components/ChartEditorComponent.ts | 48 ++++---- .../chart-editor-source-filtering.spec.ts | 112 ++++++++++++++++++ .../dashboard-filter-variables.spec.ts | 2 +- .../dashboard-required-filters.spec.ts | 2 +- .../features/promql-legend-template.spec.ts | 2 +- .../features/promql-multi-expression.spec.ts | 2 +- packages/common-utils/src/guards.ts | 12 +- 16 files changed, 417 insertions(+), 51 deletions(-) create mode 100644 .changeset/chart-editor-source-filtering.md create mode 100644 packages/app/tests/e2e/features/chart-editor-source-filtering.spec.ts diff --git a/.changeset/chart-editor-source-filtering.md b/.changeset/chart-editor-source-filtering.md new file mode 100644 index 0000000000..8a0aa862d8 --- /dev/null +++ b/.changeset/chart-editor-source-filtering.md @@ -0,0 +1,5 @@ +--- +'@hyperdx/app': patch +--- + +fix: Only offer PromQL sources in the chart editor's PromQL mode diff --git a/packages/app/src/components/ChartEditor/PromqlChartEditor.tsx b/packages/app/src/components/ChartEditor/PromqlChartEditor.tsx index c47c0109f3..4852cb3c4d 100644 --- a/packages/app/src/components/ChartEditor/PromqlChartEditor.tsx +++ b/packages/app/src/components/ChartEditor/PromqlChartEditor.tsx @@ -23,11 +23,13 @@ import { ChartEditorFormState } from './types'; export default function PromqlChartEditor({ control, getValues, + allowedSourceKinds, onSubmit, onOpenDisplaySettings, }: { control: Control; getValues: UseFormGetValues; + allowedSourceKinds: SourceKind[]; onSubmit: (suppressErrorNotification?: boolean) => void; onOpenDisplaySettings: () => void; }) { @@ -82,7 +84,8 @@ export default function PromqlChartEditor({ size="xs" control={control} name="source" - allowedSourceKinds={[SourceKind.Promql]} + data-testid="source-selector" + allowedSourceKinds={allowedSourceKinds} /> {expressions.map((field, index) => ( diff --git a/packages/app/src/components/ChartEditor/RawSqlChartEditor.tsx b/packages/app/src/components/ChartEditor/RawSqlChartEditor.tsx index 3df68b8002..a9d1949642 100644 --- a/packages/app/src/components/ChartEditor/RawSqlChartEditor.tsx +++ b/packages/app/src/components/ChartEditor/RawSqlChartEditor.tsx @@ -12,6 +12,7 @@ import { import { ChartVariable, RawSqlChartConfig, + SourceKind, } from '@hyperdx/common-utils/dist/types'; import { DisplayType, @@ -114,6 +115,7 @@ export function resolveConnectionSourceSync({ export default function RawSqlChartEditor({ control, setValue, + allowedSourceKinds, onOpenDisplaySettings, onSubmit, isDashboardForm, @@ -126,6 +128,7 @@ export default function RawSqlChartEditor({ }: { control: Control; setValue: UseFormSetValue; + allowedSourceKinds: SourceKind[]; onOpenDisplaySettings: () => void; onSubmit: (suppressErrorNotification?: boolean) => void; isDashboardForm: boolean; @@ -281,6 +284,8 @@ export default function RawSqlChartEditor({ { }); }); }); + +describe('getAllowedSourceKinds', () => { + it('offers only PromQL sources in PromQL mode', () => { + expect( + getAllowedSourceKinds({ + configType: 'promql', + displayType: DisplayType.Line, + }), + ).toEqual([SourceKind.Promql]); + }); + + it.each(['builder', 'sql'] as const)( + 'excludes PromQL sources in %s mode', + configType => { + const kinds = getAllowedSourceKinds({ + configType, + displayType: DisplayType.Line, + }); + expect(kinds).not.toContain(SourceKind.Promql); + expect(kinds).toEqual( + expect.arrayContaining([ + SourceKind.Log, + SourceKind.Trace, + SourceKind.Session, + SourceKind.Metric, + ]), + ); + }, + ); + + it.each([DisplayType.Search, DisplayType.EventPatterns])( + 'excludes PromQL sources on %s tiles, which PromQL cannot render', + displayType => { + expect( + getAllowedSourceKinds({ configType: 'promql', displayType }), + ).not.toContain(SourceKind.Promql); + }, + ); + + it.each([DisplayType.Search, DisplayType.EventPatterns])( + 'excludes metric sources on %s tiles, which have no rows to list', + displayType => { + const kinds = getAllowedSourceKinds({ + configType: 'builder', + displayType, + }); + expect(kinds).not.toContain(SourceKind.Metric); + expect(kinds).toEqual( + expect.arrayContaining([ + SourceKind.Log, + SourceKind.Trace, + SourceKind.Session, + ]), + ); + }, + ); + + it('narrows to traces on heatmap tiles', () => { + expect( + getAllowedSourceKinds({ + configType: 'promql', + displayType: DisplayType.Heatmap, + }), + ).toEqual([SourceKind.Trace]); + }); +}); diff --git a/packages/app/src/components/ChartEditor/utils.ts b/packages/app/src/components/ChartEditor/utils.ts index cbec07a09d..cbdcb39b7f 100644 --- a/packages/app/src/components/ChartEditor/utils.ts +++ b/packages/app/src/components/ChartEditor/utils.ts @@ -8,6 +8,7 @@ import { validateRawSqlForAlert, } from '@hyperdx/common-utils/dist/core/utils'; import { + HEATMAP_ALLOWED_SOURCE_KINDS, isBuilderSavedChartConfig, isPromqlSavedChartConfig, isRawSqlSavedChartConfig, @@ -172,6 +173,39 @@ export const isPromqlDisplayType = ( displayType === DisplayType.Bar || displayType === DisplayType.Number; +const NON_PROMQL_SOURCE_KINDS = Object.values(SourceKind).filter( + kind => kind !== SourceKind.Promql, +); + +/** + * Search and event patterns list raw rows out of the source's `from` table. A + * metric source keeps its rows in `metricTables` and leaves `from.tableName` + * empty, so there is nothing for them to read. + */ +const ROW_LISTING_SOURCE_KINDS = NON_PROMQL_SOURCE_KINDS.filter( + kind => kind !== SourceKind.Metric, +); + +/** Source kinds the Data Source picker offers, given the editor mode and the display type. */ +export function getAllowedSourceKinds({ + configType, + displayType, +}: { + configType: ChartEditorFormState['configType']; + displayType: DisplayType | undefined; +}): SourceKind[] { + if (configType === 'promql' && isPromqlDisplayType(displayType)) { + return [SourceKind.Promql]; + } + if (displayType === DisplayType.Heatmap) { + return [...HEATMAP_ALLOWED_SOURCE_KINDS]; + } + if (isStringSelectDisplayType(displayType)) { + return ROW_LISTING_SOURCE_KINDS; + } + return NON_PROMQL_SOURCE_KINDS; +} + const isCustomOrderByDisplayType = ( displayType: DisplayType | undefined, ): displayType is DisplayType.Table | DisplayType.Bar | DisplayType.Pie => diff --git a/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx b/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx index e6ed2ed57c..28c9d1db1e 100644 --- a/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx @@ -9,10 +9,7 @@ import { useWatch, } from 'react-hook-form'; import { TableConnection } from '@hyperdx/common-utils/dist/core/metadata'; -import { - HEATMAP_ALLOWED_SOURCE_KINDS, - isBuilderChartConfig, -} from '@hyperdx/common-utils/dist/guards'; +import { isBuilderChartConfig } from '@hyperdx/common-utils/dist/guards'; import { ChartConfigWithOptTimestamp, DisplayType, @@ -65,6 +62,7 @@ type ChartEditorControlsProps = { duplicateSeries: (index: number) => void; tableSource?: TSource; tableConnection: TableConnection; + allowedSourceKinds: SourceKind[]; databaseName?: string; tableName?: string; dateRange: [Date, Date]; @@ -100,6 +98,7 @@ export function ChartEditorControls({ duplicateSeries, tableSource, tableConnection, + allowedSourceKinds, databaseName, tableName, dateRange, @@ -198,11 +197,7 @@ export function ChartEditorControls({ control={control} name="source" data-testid="source-selector" - allowedSourceKinds={ - displayType === DisplayType.Heatmap - ? [...HEATMAP_ALLOWED_SOURCE_KINDS] - : undefined - } + allowedSourceKinds={allowedSourceKinds} onSchemaPreview={() => setIsSourceSchemaPreviewOpen(true)} isSchemaPreviewEnabled={isSourceSchemaPreviewEnabled(tableSource)} /> diff --git a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx index af43ca8c15..b3e4ac39a6 100644 --- a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx @@ -12,7 +12,10 @@ import { displayTypeSupportsBuilderAlerts, displayTypeSupportsRawSqlAlerts, } from '@hyperdx/common-utils/dist/core/utils'; -import { isRawSqlSavedChartConfig } from '@hyperdx/common-utils/dist/guards'; +import { + displayTypeRequiresSource, + isRawSqlSavedChartConfig, +} from '@hyperdx/common-utils/dist/guards'; import { ChartConfigWithDateRange, ChartVariable, @@ -61,6 +64,7 @@ import { convertFormStateToChartConfig, convertFormStateToSavedChartConfig, convertSavedChartConfigToFormState, + getAllowedSourceKinds, isPromqlDisplayType, isRawSqlDisplayType, isStringSelectDisplayType, @@ -74,12 +78,17 @@ import HeatmapSettingsDrawer, { import { InputControlled } from '@/components/InputControlled'; import SaveToDashboardModal from '@/components/SaveToDashboardModal'; import { getStoredLanguage } from '@/components/SearchInput/SearchWhereInput'; +import { + firstSourceItemValue, + useFilteredSortedSourceItems, +} from '@/components/sourceSelectUtils'; import { IS_PROMQL_ENABLED } from '@/config'; import HDXMarkdownChart from '@/HDXMarkdownChart'; import { getDurationMsExpression, getFirstSeriesNumberFormat, useSource, + useSources, } from '@/source'; import { normalizeNoOpAlertScheduleFields } from '@/utils/alerts'; @@ -267,6 +276,7 @@ export default function EditTimeChartForm({ const markdown = useWatch({ control, name: 'markdown' }); const granularity = useWatch({ control, name: 'granularity' }); const configType = useWatch({ control, name: 'configType' }); + const connection = useWatch({ control, name: 'connection' }); const chartConfigAlert = chartConfig.alert; const isRawSqlInput = @@ -274,7 +284,20 @@ export default function EditTimeChartForm({ const isPromqlInput = configType === 'promql' && isPromqlDisplayType(displayType); - const { data: tableSource } = useSource({ id: sourceId }); + const { data: sources } = useSources(); + + const allowedSourceKinds = useMemo( + () => getAllowedSourceKinds({ configType, displayType }), + [configType, displayType], + ); + + // A source selection that current mode can't query counts as no source, + // so that nothing downstream builds a query from it. + const { data: tableSource } = useSource({ + id: sourceId, + kinds: allowedSourceKinds, + }); + const databaseName = tableSource?.from.databaseName; const tableName = tableSource?.from.tableName; @@ -669,6 +692,67 @@ export default function EditTimeChartForm({ } }, [granularity, onSubmit]); + // Filtered and ordered exactly like the Data Source picker, so the + // replacement picked below is the option the user would see first. + const allowedSourceItems = useFilteredSortedSourceItems({ + sources, + allowedSourceKinds, + connectionId: configType === 'sql' ? connection : undefined, + groupBySection: true, + }); + + // We auto-submit when the display type changes, this ref helps ensure we only + // submit once, and only after the source swap has been processed. + const isDisplayTypeSourceSwapPendingRef = useRef(false); + + // Switching editor mode or display type can invalidate the selected source: + // Swap in the first source the picker still offers rather than + // leaving a selection it no longer lists. + const prevSourceModeRef = useRef({ configType, displayType }); + useEffect(() => { + // Run only on configType and displayType changes + const prev = prevSourceModeRef.current; + if (prev.configType === configType && prev.displayType === displayType) { + return; + } + + isDisplayTypeSourceSwapPendingRef.current = false; + if (sources == null) return; + if (!displayTypeRequiresSource(displayType)) return; + + prevSourceModeRef.current = { configType, displayType }; + + // Builder and PromQL require a source, so an empty selection + // should be filled in. Raw SQL source is optional, so leave it. + if (!sourceId && configType === 'sql') return; + + // If the currently selected source is still allowed, keep it. + const selected = sources.find(s => s.id === sourceId); + if ( + selected && + !selected.disabled && + allowedSourceKinds.includes(selected.kind) + ) { + return; + } + + // Select the first valid source + setValue('source', firstSourceItemValue(allowedSourceItems) ?? ''); + + // Record that a display-type change triggered a source change, so + // that auto-submit runs in the correct effect below. + isDisplayTypeSourceSwapPendingRef.current = + prev.displayType !== displayType; + }, [ + allowedSourceItems, + allowedSourceKinds, + configType, + displayType, + setValue, + sourceId, + sources, + ]); + useEffect(() => { const displayTypeChanged = displayType !== prevDisplayTypeRef.current; const configTypeChanged = configType !== prevConfigTypeRef.current; @@ -714,26 +798,33 @@ export default function EditTimeChartForm({ } // Don't auto-submit when config type changes, to avoid clearing form state (like source) - if (displayTypeChanged) { + // Defer auto-submit to the effect below when the display type change triggered a source swap above. + if (displayTypeChanged && !isDisplayTypeSourceSwapPendingRef.current) { // true = Suppress error notification (because we're auto-submitting) onSubmit(true); } } }, [displayType, select, setValue, onSubmit, configType, tableSource]); - // Auto-populate heatmap defaults when source changes while in heatmap mode + // Handle auto-submitting and form state updates when the source changes. useEffect(() => { const sourceChanged = sourceId !== prevSourceIdRef.current; prevSourceIdRef.current = sourceId; + if (!sourceChanged) return; + + const swappedSourceDueToDisplayTypeChange = + isDisplayTypeSourceSwapPendingRef.current; + isDisplayTypeSourceSwapPendingRef.current = false; if ( - sourceChanged && displayType === DisplayType.Heatmap && tableSource?.kind === SourceKind.Trace && tableSource.durationExpression ) { applyHeatmapDefaults(setValue, getDurationMsExpression(tableSource)); onSubmit(true); + } else if (swappedSourceDueToDisplayTypeChange) { + onSubmit(true); } }, [sourceId, displayType, tableSource, setValue, onSubmit]); @@ -1004,6 +1095,7 @@ export default function EditTimeChartForm({ @@ -1011,6 +1103,7 @@ export default function EditTimeChartForm({ { }); }); +describe('firstSourceItemValue', () => { + it('returns undefined when nothing is selectable', () => { + expect(firstSourceItemValue([])).toBeUndefined(); + }); + + it('returns the first value of a flat list', () => { + expect( + firstSourceItemValue([ + { value: 'a', label: 'Alpha' }, + { value: 'b', label: 'Beta' }, + ]), + ).toBe('a'); + }); + + it('returns the first value of the first group', () => { + expect( + firstSourceItemValue([ + { group: 'Billing', items: [{ value: 'b', label: 'Beta' }] }, + { group: 'Other', items: [{ value: 'a', label: 'Alpha' }] }, + ]), + ).toBe('b'); + }); + + it('skips a group with no items', () => { + expect( + firstSourceItemValue([ + { group: 'Billing', items: [] }, + { group: 'Other', items: [{ value: 'a', label: 'Alpha' }] }, + ]), + ).toBe('a'); + }); + + it('returns undefined when every group is empty', () => { + expect( + firstSourceItemValue([{ group: 'Billing', items: [] }]), + ).toBeUndefined(); + }); +}); + describe('sourceSelectFilter', () => { const grouped: SourceSelectGroup[] = [ { diff --git a/packages/app/src/components/sourceSelectUtils.tsx b/packages/app/src/components/sourceSelectUtils.tsx index a606bde76e..b0d34a6934 100644 --- a/packages/app/src/components/sourceSelectUtils.tsx +++ b/packages/app/src/components/sourceSelectUtils.tsx @@ -113,6 +113,21 @@ export function useFilteredSortedSourceItems({ ]); } +/** + * Value of the first option the selector renders, whether the items came back + * grouped by section or flat. Skips groups with no items, which Mantine + * accepts and renders as a bare header. Undefined when nothing is selectable. + */ +export function firstSourceItemValue( + items: ComboboxItem[] | SourceSelectGroup[], +): string | undefined { + for (const item of items) { + const value = 'group' in item ? item.items[0]?.value : item.value; + if (value != null) return value; + } + return undefined; +} + /** * Implicit-tag search for the source selector. A source's match text is its * own label plus the section header it sits under, so the section behaves as diff --git a/packages/app/tests/e2e/components/ChartEditorComponent.ts b/packages/app/tests/e2e/components/ChartEditorComponent.ts index 362aed378e..1e5094214f 100644 --- a/packages/app/tests/e2e/components/ChartEditorComponent.ts +++ b/packages/app/tests/e2e/components/ChartEditorComponent.ts @@ -252,17 +252,16 @@ export class ChartEditorComponent { * Select a data source */ async selectSource(sourceName: string) { + // The editor pre-selects a source, and clicking the option that is already + // selected deselects it. Leave an existing match alone. + if ((await this.sourceSelector.inputValue()) === sourceName) { + return; + } await this.sourceSelector.click(); // Use getByRole for more reliable selection. exact: true avoids matching // sources whose names are prefixes of others (e.g. "E2E Traces MV" vs // "E2E Traces MV AutoPopulate"). - const sourceOption = this.page.getByRole('option', { - name: sourceName, - exact: true, - }); - if ((await sourceOption.getAttribute('data-combobox-active')) != 'true') { - await sourceOption.click({ timeout: 5000 }); - } + await this.sourceOption(sourceName).click({ timeout: 5000 }); } /** @@ -359,6 +358,27 @@ export class ChartEditorComponent { } } + /** Open the Data Source dropdown. */ + async openSourcePicker() { + await this.sourceSelector.click(); + await expect(this.page.getByRole('option').first()).toBeVisible(); + } + + /** + * Close the Data Source dropdown by moving focus to the chart name input. + * Escape would bubble to the tile-editor modal and close that instead, and + * clicking the select again leaves the searchable dropdown open. + */ + async closeSourcePicker() { + await this.chartNameInput.click(); + await expect(this.page.getByRole('option')).toHaveCount(0); + } + + /** An option in the open Data Source dropdown. */ + sourceOption(sourceName: string): Locator { + return this.page.getByRole('option', { name: sourceName, exact: true }); + } + /** * Switch the chart editor from Builder to SQL mode. */ @@ -385,20 +405,6 @@ export class ChartEditorComponent { await label.click(); } - /** - * Select the PromQL editor's data source. - * - * Located by role rather than by the `source-selector` test id: that id is on - * the builder's source select (ChartEditorControls), and PromQL mode renders - * its own `SourceSelectControlled` which doesn't carry it. - */ - async selectPromqlSource(sourceName: string) { - await this.page.getByRole('combobox', { name: 'Data Source' }).click(); - await this.page - .getByRole('option', { name: sourceName, exact: true }) - .click(); - } - /** * Replace the entire contents of one PromQL expression editor. * diff --git a/packages/app/tests/e2e/features/chart-editor-source-filtering.spec.ts b/packages/app/tests/e2e/features/chart-editor-source-filtering.spec.ts new file mode 100644 index 0000000000..b92e340cf2 --- /dev/null +++ b/packages/app/tests/e2e/features/chart-editor-source-filtering.spec.ts @@ -0,0 +1,112 @@ +/** + * The tile editor's Data Source picker only lists sources the current editor + * mode and display type can query: PromQL sources sit on ClickHouse TimeSeries + * tables that the builder and raw SQL paths cannot read. Switching mode or + * display type swaps a selection that stops being valid for the first source + * the picker still offers. + */ +import { DisplayType } from '@hyperdx/common-utils/dist/types'; + +import { DashboardPage } from '../page-objects/DashboardPage'; +import { expect, test } from '../utils/base-test'; +import { + DEFAULT_LOGS_SOURCE_NAME, + DEFAULT_TRACES_SOURCE_NAME, + PROMQL_SOURCE_NAME, +} from '../utils/constants'; + +test.describe( + 'Chart editor data source filtering', + { tag: ['@dashboard', '@full-stack'] }, + () => { + test('offers PromQL sources in PromQL mode only, and swaps invalid selections', async ({ + page, + }) => { + test.setTimeout(120000); + + const dashboardPage = new DashboardPage(page); + const editor = dashboardPage.chartEditor; + + await dashboardPage.goto(); + await dashboardPage.openNewTileEditor(); + + await test.step('Builder mode leaves PromQL sources out of the picker', async () => { + await editor.selectSource(DEFAULT_LOGS_SOURCE_NAME); + await expect(editor.source).toHaveValue(DEFAULT_LOGS_SOURCE_NAME); + + await editor.openSourcePicker(); + await expect( + editor.sourceOption(DEFAULT_TRACES_SOURCE_NAME), + ).toBeVisible(); + await expect(editor.sourceOption(PROMQL_SOURCE_NAME)).toHaveCount(0); + await editor.closeSourcePicker(); + }); + + await test.step('SQL mode leaves PromQL sources out of the picker', async () => { + await editor.switchToSqlMode(); + await editor.openSourcePicker(); + await expect(editor.sourceOption(PROMQL_SOURCE_NAME)).toHaveCount(0); + await editor.closeSourcePicker(); + }); + + await test.step('PromQL mode swaps in a PromQL source and offers nothing else', async () => { + await editor.switchToPromqlMode(); + await expect(editor.source).toHaveValue(PROMQL_SOURCE_NAME); + + await editor.openSourcePicker(); + await expect(editor.sourceOption(DEFAULT_LOGS_SOURCE_NAME)).toHaveCount( + 0, + ); + await editor.closeSourcePicker(); + }); + + await test.step('Switching back to the builder restores a queryable source', async () => { + await editor.switchToBuilderMode(); + await expect(editor.source).not.toHaveValue(PROMQL_SOURCE_NAME); + await expect(editor.source).not.toHaveValue(''); + }); + + await test.step('A display type PromQL cannot render swaps the source out', async () => { + await editor.switchToPromqlMode(); + await expect(editor.source).toHaveValue(PROMQL_SOURCE_NAME); + + await editor.setChartType(DisplayType.Search); + await expect(editor.source).not.toHaveValue(PROMQL_SOURCE_NAME); + await editor.openSourcePicker(); + await expect(editor.sourceOption(PROMQL_SOURCE_NAME)).toHaveCount(0); + await editor.closeSourcePicker(); + }); + }); + + test('keeps a queryable source across display type changes, and swaps for heatmaps', async ({ + page, + }) => { + test.setTimeout(120000); + + const dashboardPage = new DashboardPage(page); + const editor = dashboardPage.chartEditor; + + await dashboardPage.goto(); + await dashboardPage.openNewTileEditor(); + await editor.selectSource(DEFAULT_LOGS_SOURCE_NAME); + + await test.step('A source the new display type can query is left alone', async () => { + await editor.setChartType(DisplayType.Table); + await expect(editor.source).toHaveValue(DEFAULT_LOGS_SOURCE_NAME); + }); + + await test.step('Heatmap swaps in the first trace source', async () => { + await editor.setChartType(DisplayType.Heatmap); + // Heatmaps read a duration, so only trace sources qualify; the picker + // sorts by name, putting `E2E Traces` ahead of the two MV variants. + await expect(editor.source).toHaveValue(DEFAULT_TRACES_SOURCE_NAME); + + await editor.openSourcePicker(); + await expect(editor.sourceOption(DEFAULT_LOGS_SOURCE_NAME)).toHaveCount( + 0, + ); + await editor.closeSourcePicker(); + }); + }); + }, +); diff --git a/packages/app/tests/e2e/features/dashboard-filter-variables.spec.ts b/packages/app/tests/e2e/features/dashboard-filter-variables.spec.ts index d137edca6f..2e94e6e3f5 100644 --- a/packages/app/tests/e2e/features/dashboard-filter-variables.spec.ts +++ b/packages/app/tests/e2e/features/dashboard-filter-variables.spec.ts @@ -299,7 +299,7 @@ test.describe( await expect(dashboardPage.chartEditor.nameInput).toBeVisible(); await dashboardPage.chartEditor.waitForDataToLoad(); await dashboardPage.chartEditor.switchToPromqlMode(); - await dashboardPage.chartEditor.selectPromqlSource(PROMQL_SOURCE_NAME); + await dashboardPage.chartEditor.selectSource(PROMQL_SOURCE_NAME); }; test('narrows the queried series to the selected values', async ({ diff --git a/packages/app/tests/e2e/features/dashboard-required-filters.spec.ts b/packages/app/tests/e2e/features/dashboard-required-filters.spec.ts index c05b5d6b1e..39eeb51242 100644 --- a/packages/app/tests/e2e/features/dashboard-required-filters.spec.ts +++ b/packages/app/tests/e2e/features/dashboard-required-filters.spec.ts @@ -191,7 +191,7 @@ test.describe( await expect(dashboardPage.chartEditor.nameInput).toBeVisible(); await dashboardPage.chartEditor.waitForDataToLoad(); await dashboardPage.chartEditor.switchToPromqlMode(); - await dashboardPage.chartEditor.selectPromqlSource(PROMQL_SOURCE_NAME); + await dashboardPage.chartEditor.selectSource(PROMQL_SOURCE_NAME); await dashboardPage.chartEditor.setChartName('PromQL tile'); await dashboardPage.chartEditor.replacePromqlExpression( E2E_PROMQL_METRIC_NAME, diff --git a/packages/app/tests/e2e/features/promql-legend-template.spec.ts b/packages/app/tests/e2e/features/promql-legend-template.spec.ts index 9e4857cf5c..3a787c3801 100644 --- a/packages/app/tests/e2e/features/promql-legend-template.spec.ts +++ b/packages/app/tests/e2e/features/promql-legend-template.spec.ts @@ -29,7 +29,7 @@ test.describe( await expect(editor.nameInput).toBeVisible(); await editor.waitForDataToLoad(); await editor.switchToPromqlMode(); - await editor.selectPromqlSource(PROMQL_SOURCE_NAME); + await editor.selectSource(PROMQL_SOURCE_NAME); await editor.setChartName('PromQL legend tile'); // Two known series: the full metric has one per seeded service, and // the legend only shows a subset when there are many. diff --git a/packages/app/tests/e2e/features/promql-multi-expression.spec.ts b/packages/app/tests/e2e/features/promql-multi-expression.spec.ts index 0e1afa6638..cd82fd5f41 100644 --- a/packages/app/tests/e2e/features/promql-multi-expression.spec.ts +++ b/packages/app/tests/e2e/features/promql-multi-expression.spec.ts @@ -33,7 +33,7 @@ test.describe( await expect(editor.nameInput).toBeVisible(); await editor.waitForDataToLoad(); await editor.switchToPromqlMode(); - await editor.selectPromqlSource(PROMQL_SOURCE_NAME); + await editor.selectSource(PROMQL_SOURCE_NAME); await editor.setChartName('PromQL multi-expression tile'); await editor.replacePromqlExpression(ACCOUNTING); await editor.addPromqlExpression(); diff --git a/packages/common-utils/src/guards.ts b/packages/common-utils/src/guards.ts index 059be3473b..4d15ecf67d 100644 --- a/packages/common-utils/src/guards.ts +++ b/packages/common-utils/src/guards.ts @@ -13,17 +13,7 @@ import { TSource, } from './types'; -/** - * Source kinds that can back a heatmap tile. The HeatmapSeriesEditor - * defaults to `Duration` for traces, and the editor's source picker - * filters with `allowedSourceKinds={[SourceKind.Trace]}` when the - * selected display type is heatmap (see - * `packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx`). - * - * The external dashboards API uses the same set so UI and API gates - * move together; expanding heatmap to a new source kind only requires - * adding it here. - */ +/** Source kinds that can back a heatmap tile. */ export const HEATMAP_ALLOWED_SOURCE_KINDS: ReadonlyArray = [ SourceKind.Trace, ]; From be33753a5a62bb43d526756a7e46e231b2a078cf Mon Sep 17 00:00:00 2001 From: Drew Davis Date: Mon, 28 Sep 2026 08:26:21 -0400 Subject: [PATCH 2/2] fix: Fix broken test reference --- packages/app/tests/e2e/features/promql-number.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app/tests/e2e/features/promql-number.spec.ts b/packages/app/tests/e2e/features/promql-number.spec.ts index 50640eb88f..19eddd9447 100644 --- a/packages/app/tests/e2e/features/promql-number.spec.ts +++ b/packages/app/tests/e2e/features/promql-number.spec.ts @@ -38,7 +38,7 @@ test.describe( await expect(editor.nameInput).toBeVisible(); await editor.waitForDataToLoad(); await editor.switchToPromqlMode(); - await editor.selectPromqlSource(PROMQL_SOURCE_NAME); + await editor.selectSource(PROMQL_SOURCE_NAME); await editor.setChartName('PromQL number tile'); await editor.setChartType(DisplayType.Number); }); @@ -98,7 +98,7 @@ test.describe( await expect(editor.nameInput).toBeVisible(); await editor.waitForDataToLoad(); await editor.switchToPromqlMode(); - await editor.selectPromqlSource(PROMQL_SOURCE_NAME); + await editor.selectSource(PROMQL_SOURCE_NAME); await editor.setChartName('PromQL range reducer tile'); await editor.setChartType(DisplayType.Number); // Counts the samples in the window, so the reducer's effect on the