From c3d9ca43c52fb0f852e5433d7c131d0ccbd83f60 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 1 Dec 2026 14:12:18 +0000 Subject: [PATCH 1/2] Add button to remove stale dashboard URL filter params Co-authored-by: Drew Davis --- .../remove-stale-dashboard-url-filters.md | 8 ++ packages/app/src/DBDashboardPage.tsx | 14 ++++ .../__tests__/useDashboardFilters.test.tsx | 81 +++++++++++++++++++ .../usePresetDashboardFilters.test.tsx | 1 + .../app/src/hooks/useDashboardFilters.tsx | 31 +++++++ .../dashboard-filter-value-format.spec.ts | 68 ++++++++++++++++ .../tests/e2e/page-objects/DashboardPage.ts | 15 ++++ 7 files changed, 218 insertions(+) create mode 100644 .changeset/remove-stale-dashboard-url-filters.md diff --git a/.changeset/remove-stale-dashboard-url-filters.md b/.changeset/remove-stale-dashboard-url-filters.md new file mode 100644 index 0000000000..f4152fedff --- /dev/null +++ b/.changeset/remove-stale-dashboard-url-filters.md @@ -0,0 +1,8 @@ +--- +'@hyperdx/app': patch +--- + +feat: add a "Remove filters from URL" button to the dashboard warning banner +shown when the URL carries filter values that match no dashboard filter. It +clears the stale/mismatched URL state in one click and dismisses the banner, +leaving declared filter selections untouched. diff --git a/packages/app/src/DBDashboardPage.tsx b/packages/app/src/DBDashboardPage.tsx index 5bb4b4ee9c..675cfe0e61 100644 --- a/packages/app/src/DBDashboardPage.tsx +++ b/packages/app/src/DBDashboardPage.tsx @@ -2018,6 +2018,7 @@ function DBDashboardPage({ filterValueEntries, ignoredFilterExpressions, ignoredVariableNames, + removeIgnoredFilterState, getFilterQueriesForSource, variables, referenceVariableValues, @@ -3459,6 +3460,19 @@ function DBDashboardPage({ )} + + + )} {!isKioskMode && ( diff --git a/packages/app/src/hooks/__tests__/useDashboardFilters.test.tsx b/packages/app/src/hooks/__tests__/useDashboardFilters.test.tsx index a2c7f2038d..11a37c787d 100644 --- a/packages/app/src/hooks/__tests__/useDashboardFilters.test.tsx +++ b/packages/app/src/hooks/__tests__/useDashboardFilters.test.tsx @@ -644,6 +644,87 @@ describe('useDashboardFilters', () => { }); }); + describe('removeIgnoredFilterState', () => { + const envVariableFilter: DashboardFilter = { + ...mockFilters[0], + isVariableEnabled: true, + variableName: 'env', + }; + + it('drops ignored expression entries, keeping declared selections', () => { + mockState = [ + { type: 'sql', condition: "environment IN ('production')" }, + { type: 'sql', condition: "team IN ('platform')" }, + ]; + + const { result } = renderHook(() => useDashboardFilters(mockFilters)); + + act(() => { + result.current.removeIgnoredFilterState(); + }); + + expect(mockState).toEqual([ + { type: 'sql', condition: "environment IN ('production')" }, + ]); + }); + + it('drops orphaned variable entries, keeping declared ones', () => { + mockState = [ + { type: 'variable', name: 'nope', values: ['x'] }, + { type: 'variable', name: 'env', values: ['production'] }, + ]; + + const { result } = renderHook(() => + useDashboardFilters([envVariableFilter]), + ); + + act(() => { + result.current.removeIgnoredFilterState(); + }); + + expect(mockState).toEqual([ + { type: 'variable', name: 'env', values: ['production'] }, + ]); + }); + + it('clears both ignored expressions and orphaned variables at once', () => { + mockState = [ + { type: 'sql', condition: "team IN ('platform')" }, + { type: 'variable', name: 'env', values: ['production'] }, + { type: 'variable', name: 'nope', values: ['x'] }, + ]; + + const { result } = renderHook(() => + useDashboardFilters([envVariableFilter]), + ); + + act(() => { + result.current.removeIgnoredFilterState(); + }); + + expect(mockState).toEqual([ + { type: 'variable', name: 'env', values: ['production'] }, + ]); + }); + + it('is a no-op when there is no stale state', () => { + mockState = [{ type: 'variable', name: 'env', values: ['production'] }]; + + const { result } = renderHook(() => + useDashboardFilters([envVariableFilter]), + ); + + act(() => { + result.current.removeIgnoredFilterState(); + }); + + expect(mockSetState).not.toHaveBeenCalled(); + expect(mockState).toEqual([ + { type: 'variable', name: 'env', values: ['production'] }, + ]); + }); + }); + describe('entry format', () => { const envVariableFilter: DashboardFilter = { ...mockFilters[0], diff --git a/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx b/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx index 8424018ef2..66193d6ae1 100644 --- a/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx +++ b/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx @@ -132,6 +132,7 @@ describe('usePresetDashboardFilters', () => { filterValueEntries: null, ignoredFilterExpressions: [], ignoredVariableNames: [], + removeIgnoredFilterState: jest.fn(), getFilterQueriesForSource: jest.fn().mockReturnValue(mockFilterQueries), variables: [], unsatisfiedRequiredFilters: [], diff --git a/packages/app/src/hooks/useDashboardFilters.tsx b/packages/app/src/hooks/useDashboardFilters.tsx index 3c54bf3d85..61d8500256 100644 --- a/packages/app/src/hooks/useDashboardFilters.tsx +++ b/packages/app/src/hooks/useDashboardFilters.tsx @@ -367,6 +367,31 @@ const useDashboardFilters = ( }; }, [filterValueEntries, filters, sources, connections]); + /** + * Drop every URL `filters=` entry that corresponds to no declared filter — + * the expressions in `ignoredFilterExpressions` and the variable names in + * `ignoredVariableNames`. Declared selections and passthrough entries stay. + */ + const removeIgnoredFilterState = useCallback(() => { + if (ignoredExpressions.length === 0 && ignoredVariableNames.length === 0) { + return; + } + setFilterValueEntries(prev => { + const parsed = parseDashboardFilterValues(prev ?? []); + for (const expression of ignoredExpressions) { + delete parsed.byExpression[expression]; + } + for (const name of ignoredVariableNames) { + parsed.byVariable.delete(name); + } + return serializeDashboardFilterValues({ + byExpression: parsed.byExpression, + byVariable: parsed.byVariable, + passthrough: parsed.passthrough, + }); + }); + }, [setFilterValueEntries, ignoredExpressions, ignoredVariableNames]); + // Filters as they query: source and connection variable references replaced // by the selections. Unselected references, and those selecting a source the // field can't use, are left as written. @@ -552,6 +577,12 @@ const useDashboardFilters = ( * whose variable was turned off. */ ignoredVariableNames, + /** + * Remove every URL `filters=` entry that matches no declared filter (those + * in `ignoredFilterExpressions` and `ignoredVariableNames`), clearing the + * stale state that surfaces the warning banner. A no-op when there is none. + */ + removeIgnoredFilterState, /** * Returns the subset of filter queries that should apply to a tile whose * source is `sourceId`. Filters with no `appliesToSourceIds` apply to all diff --git a/packages/app/tests/e2e/features/dashboard-filter-value-format.spec.ts b/packages/app/tests/e2e/features/dashboard-filter-value-format.spec.ts index 5311b95f2b..c784961fb4 100644 --- a/packages/app/tests/e2e/features/dashboard-filter-value-format.spec.ts +++ b/packages/app/tests/e2e/features/dashboard-filter-value-format.spec.ts @@ -237,6 +237,74 @@ test.describe( }); }); + test('removes stale URL filter state via the banner button', async ({ + page, + }) => { + test.setTimeout(120000); + let dashboardId = ''; + + await test.step('Create a dashboard with a variable-enabled Service filter', async () => { + await dashboardPage.addNumberTile( + 'Count tile', + DEFAULT_LOGS_SOURCE_NAME, + ); + dashboardId = dashboardPage.getCurrentDashboardId(); + await dashboardPage.openEditFiltersModal(); + await dashboardPage.addFilterToDashboard( + 'Service', + DEFAULT_LOGS_SOURCE_NAME, + 'ServiceName', + undefined, + undefined, + { variableName: 'svc' }, + ); + await expect( + dashboardPage.getFilterItemByName('Service'), + ).toBeVisible(); + await dashboardPage.closeFiltersModal(); + }); + + await test.step('A link with a stale variable and expression raises the banner', async () => { + await gotoWithFilters(page, dashboardId, [ + { type: 'variable', name: 'groupBy', values: ['ServiceName'] }, + { type: 'sql', condition: "team IN ('platform')" }, + { type: 'variable', name: 'svc', values: ['accounting'] }, + ]); + await dashboardPage.waitForLoaded(); + + await expect(dashboardPage.ignoredUrlFiltersBanner).toBeVisible({ + timeout: 20000, + }); + await expect(dashboardPage.ignoredUrlFiltersBanner).toContainText( + '$groupBy', + ); + await expect(dashboardPage.ignoredUrlFiltersBanner).toContainText( + 'team', + ); + // The declared variable still applied. + await expectSelected(dashboardPage, 'Service', ['accounting']); + }); + + await test.step('The button strips the stale state and clears the banner', async () => { + await dashboardPage.removeIgnoredUrlFilters(); + + await expect(dashboardPage.ignoredUrlFiltersBanner).toBeHidden(); + // Only the declared selection is left in the URL. + await expectFiltersParam(page, [ + { type: 'variable', name: 'svc', values: ['accounting'] }, + ]); + await expectSelected(dashboardPage, 'Service', ['accounting']); + }); + + await test.step('The banner stays gone after a reload', async () => { + await page.reload(); + await dashboardPage.waitForLoaded(); + + await expect(dashboardPage.ignoredUrlFiltersBanner).toBeHidden(); + await expectSelected(dashboardPage, 'Service', ['accounting']); + }); + }); + test('carries values verbatim through the variable-keyed format', async ({ page, }) => { diff --git a/packages/app/tests/e2e/page-objects/DashboardPage.ts b/packages/app/tests/e2e/page-objects/DashboardPage.ts index 54a87a0388..65fb7df6dd 100644 --- a/packages/app/tests/e2e/page-objects/DashboardPage.ts +++ b/packages/app/tests/e2e/page-objects/DashboardPage.ts @@ -2313,6 +2313,21 @@ export class DashboardPage { .click(); } + /** + * The ignored-URL-filters banner's "Remove filters from URL" button, which + * strips the stale `filters=` state and clears the banner in one click. + */ + get removeIgnoredUrlFiltersButton() { + return this.ignoredUrlFiltersBanner.getByTestId( + 'remove-ignored-url-filters-button', + ); + } + + /** Click the banner's "Remove filters from URL" button. */ + async removeIgnoredUrlFilters() { + await this.removeIgnoredUrlFiltersButton.click(); + } + // ---- Chart annotation helpers ---- /** From 1db008ad0b394388aacc1e09857860162f0a1467 Mon Sep 17 00:00:00 2001 From: Drew Davis Date: Tue, 1 Dec 2026 12:53:24 -0500 Subject: [PATCH 2/2] fix: Update Remove ignored values from URL copy --- .changeset/remove-stale-dashboard-url-filters.md | 5 +---- packages/app/src/DBDashboardPage.tsx | 2 +- packages/app/tests/e2e/page-objects/DashboardPage.ts | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.changeset/remove-stale-dashboard-url-filters.md b/.changeset/remove-stale-dashboard-url-filters.md index f4152fedff..2130b7d1aa 100644 --- a/.changeset/remove-stale-dashboard-url-filters.md +++ b/.changeset/remove-stale-dashboard-url-filters.md @@ -2,7 +2,4 @@ '@hyperdx/app': patch --- -feat: add a "Remove filters from URL" button to the dashboard warning banner -shown when the URL carries filter values that match no dashboard filter. It -clears the stale/mismatched URL state in one click and dismisses the banner, -leaving declared filter selections untouched. +feat: add a "Remove ignored values from URL" button to the dashboard warning banner diff --git a/packages/app/src/DBDashboardPage.tsx b/packages/app/src/DBDashboardPage.tsx index 675cfe0e61..5110c65ea4 100644 --- a/packages/app/src/DBDashboardPage.tsx +++ b/packages/app/src/DBDashboardPage.tsx @@ -3470,7 +3470,7 @@ function DBDashboardPage({ setShouldShowIgnoredFiltersBanner(false); }} > - Remove filters from URL + Remove ignored values from URL diff --git a/packages/app/tests/e2e/page-objects/DashboardPage.ts b/packages/app/tests/e2e/page-objects/DashboardPage.ts index 65fb7df6dd..276fe0d001 100644 --- a/packages/app/tests/e2e/page-objects/DashboardPage.ts +++ b/packages/app/tests/e2e/page-objects/DashboardPage.ts @@ -2314,7 +2314,7 @@ export class DashboardPage { } /** - * The ignored-URL-filters banner's "Remove filters from URL" button, which + * The ignored-URL-filters banner's "Remove ignored values from URL" button, which * strips the stale `filters=` state and clears the banner in one click. */ get removeIgnoredUrlFiltersButton() { @@ -2323,7 +2323,7 @@ export class DashboardPage { ); } - /** Click the banner's "Remove filters from URL" button. */ + /** Click the banner's "Remove ignored values from URL" button. */ async removeIgnoredUrlFilters() { await this.removeIgnoredUrlFiltersButton.click(); }