Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/carry-where-aggcondition-on-chart-type-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

fix: Carry the Search WHERE filter over to the series aggregation condition (and back) when switching chart types, so a filter no longer resets on switching between Search and other chart types
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,23 @@ export default function EditTimeChartForm({
isStringSelectDisplayType(displayType) &&
typeof select !== 'string'
) {
// Carry a single builder series' aggCondition back into `where` so a
// filter set in the builder survives the switch to Search/EventPatterns
// (which only edit `where`). Only with exactly one series and an empty
// `where`, so a filter isn't guessed across series or allowed to
// clobber an existing `where`. See HDX-5602.
const currentSeries = getValues('series');
if (Array.isArray(currentSeries) && currentSeries.length === 1) {
const condition = currentSeries[0]?.aggCondition ?? '';
const currentWhere = getValues('where') ?? '';
if (condition && !currentWhere) {
setValue('where', condition);
const language = currentSeries[0]?.aggConditionLanguage;
if (language) {
setValue('whereLanguage', language);
}
}
}
setValue('select', '');
setValue('series', []);
} else if (displayType === DisplayType.Heatmap) {
Expand All @@ -786,11 +803,17 @@ export default function EditTimeChartForm({
}
applyHeatmapDefaults(setValue, defaultValue);
} else if (!Array.isArray(select)) {
// Carry a Search/EventPatterns `where` filter into the new single
// series' aggCondition so a filter set on those tabs survives the
// switch to a builder chart type, which filters per-series rather than
// via the (hidden) chart-level `where`. See HDX-5602.
const carriedWhere = getValues('where') ?? '';
const defaultSeries: SavedChartConfigWithSelectArray['select'] = [
{
aggFn: 'count',
aggCondition: '',
aggConditionLanguage: getStoredLanguage() ?? 'lucene',
aggCondition: carriedWhere,
aggConditionLanguage:
getValues('whereLanguage') ?? getStoredLanguage() ?? 'lucene',
valueExpression: '',
},
];
Expand All @@ -806,7 +829,15 @@ export default function EditTimeChartForm({
onSubmit(true);
}
}
}, [displayType, select, setValue, onSubmit, configType, tableSource]);
}, [
displayType,
select,
setValue,
getValues,
onSubmit,
configType,
tableSource,
]);

// Handle auto-submitting and form state updates when the source changes.
useEffect(() => {
Expand Down
10 changes: 10 additions & 0 deletions packages/app/tests/e2e/components/ChartEditorComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ export class ChartEditorComponent {
await this.whereInput(scope).typeLucene(text);
}

/**
* Read the current text of a WHERE input in Lucene mode, where it renders as
* a plain textarea. Switches the input to Lucene first (the mode is sticky in
* localStorage, so a prior spec can leave it on SQL).
*/
async getLuceneWhere(scope: 'chart' | 'series' = 'chart'): Promise<string> {
await this.setWhereLanguage('Lucene', scope);
return this.whereInput(scope).luceneInput.inputValue();
Comment on lines +168 to +170

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reader changes filter language

getLuceneWhere switches the input to Lucene before reading it. Both new tests therefore check that the filter text survived, but could pass even if the chart-type switch carried the wrong language. Selecting Lucene also changes the editor’s stored language preference. Check the carried language before changing the input, and cover an SQL filter.

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

}

/**
* Type `prefix` into a SQL WHERE input to open its autocomplete popup, and
* report what it offers plus the help panel of the highlighted suggestion.
Expand Down
69 changes: 69 additions & 0 deletions packages/app/tests/e2e/features/chart-explorer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,73 @@ test.describe('Chart Explorer Functionality', { tag: ['@charts'] }, () => {
});
},
);

// HDX-5602: a filter set on the Search tab lives in the chart-level `where`,
// while the builder chart types filter per-series via `aggCondition`. The
// editor carries the value across so the filter does not silently reset when
// the user switches chart types.
test(
'should carry a Search WHERE filter into the series when switching to Time Series',
{ tag: '@full-stack' },
async () => {
const filter = 'ServiceName:"frontend"';

await test.step('Wait for the chart editor data to load', async () => {
await chartExplorerPage.chartEditor.waitForDataToLoad();
});

await test.step('Select the E2E Logs source', async () => {
await chartExplorerPage.chartEditor.selectSource(
DEFAULT_LOGS_SOURCE_NAME,
);
});

await test.step('Switch to the Search chart type and enter a filter', async () => {
await chartExplorerPage.chartEditor.setChartType(DisplayType.Search);
await chartExplorerPage.chartEditor.setWhereLanguage('Lucene', 'chart');
await chartExplorerPage.chartEditor.typeLuceneWhere(filter, 'chart');
});

await test.step('Switch to Time Series and verify the filter carried into the series WHERE', async () => {
await chartExplorerPage.chartEditor.setChartType(DisplayType.Line);
await expect
.poll(() => chartExplorerPage.chartEditor.getLuceneWhere('series'))
.toBe(filter);
});
},
);

test(
'should carry a single series WHERE filter into the Search WHERE when switching to Search',
{ tag: '@full-stack' },
async () => {
const filter = 'ServiceName:"frontend"';

await test.step('Wait for the chart editor data to load', async () => {
await chartExplorerPage.chartEditor.waitForDataToLoad();
});

await test.step('Select the E2E Logs source', async () => {
await chartExplorerPage.chartEditor.selectSource(
DEFAULT_LOGS_SOURCE_NAME,
);
});

await test.step('On Time Series, enter a filter in the series WHERE', async () => {
await chartExplorerPage.chartEditor.setChartType(DisplayType.Line);
await chartExplorerPage.chartEditor.setWhereLanguage(
'Lucene',
'series',
);
await chartExplorerPage.chartEditor.typeLuceneWhere(filter, 'series');
});

await test.step('Switch to Search and verify the filter carried into the chart WHERE', async () => {
await chartExplorerPage.chartEditor.setChartType(DisplayType.Search);
await expect
.poll(() => chartExplorerPage.chartEditor.getLuceneWhere('chart'))
.toBe(filter);
});
},
);
});
Loading