Repository navigation
feat(app): reorder dashboard filters with up/down controls #3876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| --- | ||
|
|
||
| feat: let users reorder dashboard filters and variables. The edit filters modal | ||
| now shows up/down controls on each filter, and that order drives both the modal | ||
| list and the filter bar. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /** | ||
| * Filters are stored as an ordered list, and that order drives both the Edit | ||
| * Filters modal's list and the filter bar on the dashboard. The modal's up/down | ||
| * controls on each row let a user change that order, and the change persists. | ||
| */ | ||
| import { DashboardPage } from '../page-objects/DashboardPage'; | ||
| import { expect, test } from '../utils/base-test'; | ||
|
|
||
| const FILTERS = ['Alpha', 'Bravo', 'Charlie'] as const; | ||
|
|
||
| test.describe( | ||
| 'Dashboard filter reordering', | ||
| { tag: ['@dashboard', '@full-stack'] }, | ||
| () => { | ||
| let dashboardPage: DashboardPage; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| dashboardPage = new DashboardPage(page); | ||
| await dashboardPage.goto(); | ||
| }); | ||
|
|
||
| const createThreeFilters = async () => { | ||
| await dashboardPage.createNewDashboard(); | ||
| await dashboardPage.openEditFiltersModal(); | ||
| for (const [i, name] of FILTERS.entries()) { | ||
| await dashboardPage.addStaticListFilterToDashboard(name, ['x', 'y'], { | ||
| variableName: `v${i}`, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| test('reorders filters with the up/down controls and persists the order', async ({ | ||
| page, | ||
| }) => { | ||
| test.setTimeout(150000); | ||
|
|
||
| await test.step('Create three filters in a known order', async () => { | ||
| await createThreeFilters(); | ||
| await expect | ||
| .poll(() => dashboardPage.getFilterListItemNames(), { | ||
| timeout: 15000, | ||
| }) | ||
| .toEqual([...FILTERS]); | ||
| }); | ||
|
|
||
| await test.step('The ends are pinned: up on the first, down on the last', async () => { | ||
| await expect( | ||
| dashboardPage.getMoveFilterUpButton('Alpha'), | ||
| ).toBeDisabled(); | ||
| await expect( | ||
| dashboardPage.getMoveFilterDownButton('Charlie'), | ||
| ).toBeDisabled(); | ||
| await expect( | ||
| dashboardPage.getMoveFilterDownButton('Alpha'), | ||
| ).toBeEnabled(); | ||
| }); | ||
|
|
||
| // Each move persists through the dashboard update mutation, so poll until | ||
| // the reordered list lands before issuing the next move. | ||
| await test.step('Moving the first filter down swaps it with the second', async () => { | ||
| await dashboardPage.moveFilterDown('Alpha'); | ||
| await expect | ||
| .poll(() => dashboardPage.getFilterListItemNames(), { | ||
| timeout: 15000, | ||
| }) | ||
| .toEqual(['Bravo', 'Alpha', 'Charlie']); | ||
| }); | ||
|
|
||
| await test.step('Moving the last filter up swaps it with the one above', async () => { | ||
| await dashboardPage.moveFilterUp('Charlie'); | ||
| await expect | ||
| .poll(() => dashboardPage.getFilterListItemNames(), { | ||
| timeout: 15000, | ||
| }) | ||
| .toEqual(['Bravo', 'Charlie', 'Alpha']); | ||
| }); | ||
|
|
||
| await test.step('The new order survives a reload', async () => { | ||
| await dashboardPage.closeFiltersModal(); | ||
| await page.reload(); | ||
| await dashboardPage.waitForLoaded(); | ||
| await dashboardPage.openEditFiltersModal(); | ||
| await expect | ||
| .poll(() => dashboardPage.getFilterListItemNames(), { | ||
| timeout: 15000, | ||
| }) | ||
| .toEqual(['Bravo', 'Charlie', 'Alpha']); | ||
| }); | ||
| }); | ||
| }, | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,7 +286,7 @@ | |
| // The document title comes from the saved dashboard, so it only changes | ||
| // once the rename has persisted. | ||
| const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), { | ||
|
Check failure on line 289 in packages/app/tests/e2e/page-objects/DashboardPage.ts
|
||
| timeout: 10000, | ||
| }); | ||
| } | ||
|
|
@@ -1187,6 +1187,43 @@ | |
| return this.page.getByTestId(`dashboard-filter-item-${name}`); | ||
| } | ||
|
|
||
| /** | ||
| * The display names of the filters in the Edit Filters modal's list, in the | ||
| * order they are rendered. Used to assert reordering. | ||
| */ | ||
| async getFilterListItemNames(): Promise<string[]> { | ||
| const items = this.page | ||
| .getByTestId('dashboard-filters-list') | ||
| .locator('[data-testid^="dashboard-filter-item-"]'); | ||
| const count = await items.count(); | ||
| const names: string[] = []; | ||
| for (let i = 0; i < count; i++) { | ||
| const testId = await items.nth(i).getAttribute('data-testid'); | ||
| names.push((testId ?? '').replace('dashboard-filter-item-', '')); | ||
| } | ||
| return names; | ||
| } | ||
|
|
||
| /** Move a filter up one position in the Edit Filters modal's list. */ | ||
| async moveFilterUp(name: string) { | ||
| await this.page.getByTestId(`move-filter-up-button-${name}`).click(); | ||
| } | ||
|
|
||
| /** Move a filter down one position in the Edit Filters modal's list. */ | ||
| async moveFilterDown(name: string) { | ||
| await this.page.getByTestId(`move-filter-down-button-${name}`).click(); | ||
| } | ||
|
|
||
| /** The up control for a filter row, for asserting its disabled state. */ | ||
| getMoveFilterUpButton(name: string): Locator { | ||
| return this.page.getByTestId(`move-filter-up-button-${name}`); | ||
| } | ||
|
|
||
| /** The down control for a filter row, for asserting its disabled state. */ | ||
| getMoveFilterDownButton(name: string): Locator { | ||
| return this.page.getByTestId(`move-filter-down-button-${name}`); | ||
| } | ||
|
|
||
| /** The filters list's summary of which sources a filter broadcasts to. */ | ||
| getFilterBroadcastTarget(name: string) { | ||
| return this.page.getByTestId(`dashboard-filter-applies-to-${name}`); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 P2 — Reorder is computed from stale dashboard data, so quick repeated clicks overwrite each other on saved dashboards
On a saved dashboard,
setDashboardsends a PATCH and only updates the list when the['dashboards']refetch comes back (packages/app/src/dashboard.ts:159-187,279-319). Nothing updates the list in the meantime, so the rows keep their old order and the chevrons stay clickable. Each click builds a fullfiltersarray from the old order and replaces the saved one. Example: starting from [A,B,C], clicking 'down' on A twice quickly sends [B,A,C] both times, so A moves one place instead of two. Clicking A down and then C up quickly sends [A,C,B] last, which throws away A's move. The PATCHes can also arrive out of order. The E2E spec works around this by polling between moves. Fix: disable the reorder buttons whileisLoading(which already reflectsisSavingDashboard || isFetchingDashboard), or update the['dashboards']cache optimistically inonMutate.Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 79a5540. The reorder chevrons are now disabled while a save is in flight (
isLoading=isSavingDashboard || isFetchingDashboard), so a second click can't fire until the list reflects the first move's new order. Added a unit test for the disabled-while-saving state. I went with disabling rather than an optimisticonMutateto keep the change out ofdashboard.ts, which this PR doesn't otherwise touch.