Skip to content

Commit 583b550

Browse files
cursoragentpulpdrew
andcommitted
fix(app): carry WHERE filter across chart type switches
A filter set on the Search tab lives in the chart-level `where`, while builder chart types filter per-series via `aggCondition`. Switching chart types reset the filter instead of carrying it over. Carry a single series' aggCondition into `where` when switching to Search/EventPatterns, and the Search `where` into the new series' aggCondition when switching to a builder chart type. Add E2E coverage for both directions. HDX-5602 Co-authored-by: Drew Davis <pulpdrew@gmail.com>
1 parent b52adf7 commit 583b550

4 files changed

Lines changed: 118 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hyperdx/app': patch
3+
---
4+
5+
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

‎packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,23 @@ export default function EditTimeChartForm({
767767
isStringSelectDisplayType(displayType) &&
768768
typeof select !== 'string'
769769
) {
770+
// Carry a single builder series' aggCondition back into `where` so a
771+
// filter set in the builder survives the switch to Search/EventPatterns
772+
// (which only edit `where`). Only with exactly one series and an empty
773+
// `where`, so a filter isn't guessed across series or allowed to
774+
// clobber an existing `where`. See HDX-5602.
775+
const currentSeries = getValues('series');
776+
if (Array.isArray(currentSeries) && currentSeries.length === 1) {
777+
const condition = currentSeries[0]?.aggCondition ?? '';
778+
const currentWhere = getValues('where') ?? '';
779+
if (condition && !currentWhere) {
780+
setValue('where', condition);
781+
const language = currentSeries[0]?.aggConditionLanguage;
782+
if (language) {
783+
setValue('whereLanguage', language);
784+
}
785+
}
786+
}
770787
setValue('select', '');
771788
setValue('series', []);
772789
} else if (displayType === DisplayType.Heatmap) {
@@ -786,11 +803,17 @@ export default function EditTimeChartForm({
786803
}
787804
applyHeatmapDefaults(setValue, defaultValue);
788805
} else if (!Array.isArray(select)) {
806+
// Carry a Search/EventPatterns `where` filter into the new single
807+
// series' aggCondition so a filter set on those tabs survives the
808+
// switch to a builder chart type, which filters per-series rather than
809+
// via the (hidden) chart-level `where`. See HDX-5602.
810+
const carriedWhere = getValues('where') ?? '';
789811
const defaultSeries: SavedChartConfigWithSelectArray['select'] = [
790812
{
791813
aggFn: 'count',
792-
aggCondition: '',
793-
aggConditionLanguage: getStoredLanguage() ?? 'lucene',
814+
aggCondition: carriedWhere,
815+
aggConditionLanguage:
816+
getValues('whereLanguage') ?? getStoredLanguage() ?? 'lucene',
794817
valueExpression: '',
795818
},
796819
];
@@ -806,7 +829,15 @@ export default function EditTimeChartForm({
806829
onSubmit(true);
807830
}
808831
}
809-
}, [displayType, select, setValue, onSubmit, configType, tableSource]);
832+
}, [
833+
displayType,
834+
select,
835+
setValue,
836+
getValues,
837+
onSubmit,
838+
configType,
839+
tableSource,
840+
]);
810841

811842
// Handle auto-submitting and form state updates when the source changes.
812843
useEffect(() => {

‎packages/app/tests/e2e/components/ChartEditorComponent.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ export class ChartEditorComponent {
160160
await this.whereInput(scope).typeLucene(text);
161161
}
162162

163+
/**
164+
* Read the current text of a WHERE input in Lucene mode, where it renders as
165+
* a plain textarea. Switches the input to Lucene first (the mode is sticky in
166+
* localStorage, so a prior spec can leave it on SQL).
167+
*/
168+
async getLuceneWhere(scope: 'chart' | 'series' = 'chart'): Promise<string> {
169+
await this.setWhereLanguage('Lucene', scope);
170+
return this.whereInput(scope).luceneInput.inputValue();
171+
}
172+
163173
/**
164174
* Type `prefix` into a SQL WHERE input to open its autocomplete popup, and
165175
* report what it offers plus the help panel of the highlighted suggestion.

‎packages/app/tests/e2e/features/chart-explorer.spec.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,73 @@ test.describe('Chart Explorer Functionality', { tag: ['@charts'] }, () => {
359359
});
360360
},
361361
);
362+
363+
// HDX-5602: a filter set on the Search tab lives in the chart-level `where`,
364+
// while the builder chart types filter per-series via `aggCondition`. The
365+
// editor carries the value across so the filter does not silently reset when
366+
// the user switches chart types.
367+
test(
368+
'should carry a Search WHERE filter into the series when switching to Time Series',
369+
{ tag: '@full-stack' },
370+
async () => {
371+
const filter = 'ServiceName:"frontend"';
372+
373+
await test.step('Wait for the chart editor data to load', async () => {
374+
await chartExplorerPage.chartEditor.waitForDataToLoad();
375+
});
376+
377+
await test.step('Select the E2E Logs source', async () => {
378+
await chartExplorerPage.chartEditor.selectSource(
379+
DEFAULT_LOGS_SOURCE_NAME,
380+
);
381+
});
382+
383+
await test.step('Switch to the Search chart type and enter a filter', async () => {
384+
await chartExplorerPage.chartEditor.setChartType(DisplayType.Search);
385+
await chartExplorerPage.chartEditor.setWhereLanguage('Lucene', 'chart');
386+
await chartExplorerPage.chartEditor.typeLuceneWhere(filter, 'chart');
387+
});
388+
389+
await test.step('Switch to Time Series and verify the filter carried into the series WHERE', async () => {
390+
await chartExplorerPage.chartEditor.setChartType(DisplayType.Line);
391+
await expect
392+
.poll(() => chartExplorerPage.chartEditor.getLuceneWhere('series'))
393+
.toBe(filter);
394+
});
395+
},
396+
);
397+
398+
test(
399+
'should carry a single series WHERE filter into the Search WHERE when switching to Search',
400+
{ tag: '@full-stack' },
401+
async () => {
402+
const filter = 'ServiceName:"frontend"';
403+
404+
await test.step('Wait for the chart editor data to load', async () => {
405+
await chartExplorerPage.chartEditor.waitForDataToLoad();
406+
});
407+
408+
await test.step('Select the E2E Logs source', async () => {
409+
await chartExplorerPage.chartEditor.selectSource(
410+
DEFAULT_LOGS_SOURCE_NAME,
411+
);
412+
});
413+
414+
await test.step('On Time Series, enter a filter in the series WHERE', async () => {
415+
await chartExplorerPage.chartEditor.setChartType(DisplayType.Line);
416+
await chartExplorerPage.chartEditor.setWhereLanguage(
417+
'Lucene',
418+
'series',
419+
);
420+
await chartExplorerPage.chartEditor.typeLuceneWhere(filter, 'series');
421+
});
422+
423+
await test.step('Switch to Search and verify the filter carried into the chart WHERE', async () => {
424+
await chartExplorerPage.chartEditor.setChartType(DisplayType.Search);
425+
await expect
426+
.poll(() => chartExplorerPage.chartEditor.getLuceneWhere('chart'))
427+
.toBe(filter);
428+
});
429+
},
430+
);
362431
});

0 commit comments

Comments
 (0)