From 3f36c2089b4a9b9efbcacc2a2ef1f0b85fde71e7 Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Sun, 29 Nov 2026 14:38:12 -0600 Subject: [PATCH 1/6] Fix actions while selecting all matching results --- .../e2e/tests/bulk-selection-pending.e2e.ts | 75 +++++++++++++++++++ .../all-matching-selection.svelte.test.ts | 68 +++++++++++++++++ .../shared/all-matching-selection.svelte.ts | 29 ++++--- .../src/routes/(app)/event/+page.svelte | 13 ++-- .../src/routes/(app)/stack/+page.svelte | 13 ++-- 5 files changed, 175 insertions(+), 23 deletions(-) create mode 100644 src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts diff --git a/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts b/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts new file mode 100644 index 0000000000..40ebdb5d9f --- /dev/null +++ b/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts @@ -0,0 +1,75 @@ +import { expect, test } from '../fixtures/e2e-test'; +import { createRepresentativeEvent } from '../support/synthetic-event'; + +for (const kind of ['event', 'stack'] as const) { + test(`selecting all matching ${kind}s takes effect while the count refreshes`, async ({ e2eApi, e2eScenario, page }) => { + // Arrange + for (let index = 0; index < 5; index++) { + const referenceId = `${e2eScenario.referenceId}-pending-${index}`; + await e2eApi.submitEvent( + e2eScenario.projectId, + e2eScenario.projectToken, + createRepresentativeEvent({ + appUrl: e2eApi.environment.appUrl, + message: `${e2eScenario.message} ${referenceId}`, + referenceId, + runId: e2eApi.environment.runId + }) + ); + await e2eApi.pollForEventByReference(e2eScenario.userToken, e2eScenario.projectId, referenceId); + } + await page.goto(`/${kind}?project=${e2eScenario.projectId}&time=all&limit=2`); + const table = page.locator('table:has(thead [role="checkbox"])').first(); + await expect(table.getByRole('checkbox', { name: 'Select row' })).toHaveCount(2, { timeout: 30_000 }); + const isCountRequest = (url: URL) => + url.pathname === `/api/v2/organizations/${e2eScenario.organizationId}/events` && url.searchParams.get('limit') === '1'; + const initialCount = page.waitForResponse((response) => isCountRequest(new URL(response.url())) && response.status() === 200); + await table.getByRole('checkbox', { name: 'Select all rows' }).click(); + await (await initialCount).finished(); + const selectAll = page.getByRole('button', { name: `Select all 5 ${kind}s matching this filter` }); + await expect(selectAll).toBeVisible(); + let countStarted = false; + const countReleased = Promise.withResolvers(); + await page.route( + isCountRequest, + async (route) => { + countStarted = true; + await countReleased.promise; + await route.continue(); + }, + { times: 1 } + ); + const countResponse = page.waitForResponse((response) => isCountRequest(new URL(response.url())) && response.status() === 200); + + // Act + try { + await selectAll.click(); + await expect.poll(() => countStarted).toBe(true); + + // Assert + await expect(page.getByRole('status').filter({ hasText: `All 5 ${kind}s are selected` })).toBeVisible({ timeout: 3_000 }); + + // Act + await page.getByRole('button', { name: 'Actions' }).click(); + await page.getByRole('menuitem', { name: kind === 'event' ? 'Delete' : 'Mark Ignored' }).click(); + + // Assert + const dialog = page.getByRole('alertdialog'); + await expect(dialog).toContainText(`About 5 ${kind}s match this filter`); + + // Act + await dialog.getByRole('button', { name: 'Cancel' }).click(); + await page.getByRole('button', { name: 'Clear selection' }).click(); + + // Assert + await expect(table.getByRole('checkbox', { name: 'Select all rows' })).not.toBeChecked(); + } finally { + countReleased.resolve(); + } + await (await countResponse).finished(); + + // Assert + await expect(page.getByRole('button', { name: 'Clear selection' })).toBeHidden(); + await expect(table.getByRole('checkbox', { name: 'Select all rows' })).not.toBeChecked(); + }); +} diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts index 3e45b88982..34f650450c 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts @@ -64,4 +64,72 @@ describe('createAllMatchingSelection', () => { // Assert expect(selection.active).toBeUndefined(); }); + + it('selects the displayed estimate immediately and updates it when the count finishes', async () => { + // Arrange + const selection = createAllMatchingSelection(() => 'query'); + const count = Promise.withResolvers(); + + // Act + const pending = selection.selectWithRefresh(5, () => count.promise); + + // Assert + expect(selection.active?.count).toBe(5); + + // Act + count.resolve(7); + await pending; + + // Assert + expect(selection.active?.count).toBe(7); + }); + + it('does not restore a selection cleared while the count was loading', async () => { + // Arrange + const selection = createAllMatchingSelection(() => 'query'); + const count = Promise.withResolvers(); + const pending = selection.selectWithRefresh(5, () => count.promise); + + // Act + selection.clear(); + count.resolve(7); + await pending; + + // Assert + expect(selection.active).toBeUndefined(); + }); + + it('does not overwrite a newer selection when an earlier count finishes later', async () => { + // Arrange + const selection = createAllMatchingSelection(() => 'query'); + const firstCount = Promise.withResolvers(); + const secondCount = Promise.withResolvers(); + const first = selection.selectWithRefresh(5, () => firstCount.promise); + const second = selection.selectWithRefresh(6, () => secondCount.promise); + + // Act + secondCount.resolve(8); + await second; + firstCount.resolve(7); + await first; + + // Assert + expect(selection.active?.count).toBe(8); + }); + + it('does not apply a refreshed count to a different query', async () => { + // Arrange + let identity = 'first'; + const selection = createAllMatchingSelection(() => identity); + const count = Promise.withResolvers(); + const pending = selection.selectWithRefresh(5, () => count.promise); + + // Act + identity = 'second'; + count.resolve(7); + await pending; + + // Assert + expect(selection.active).toBeUndefined(); + }); }); diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts index db09696882..3e6f28b1ac 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts @@ -22,6 +22,19 @@ export interface AllMatchingTarget { export function createAllMatchingSelection(getIdentity: () => string) { let selection = $state(); + function select(count: number, expectedIdentity?: string): boolean { + const identity = getIdentity(); + if (expectedIdentity !== undefined && expectedIdentity !== identity) { + return false; + } + + selection = { + count, + identity + }; + return true; + } + return { get active(): AllMatchingSelection | undefined { return selection && selection.identity === getIdentity() ? selection : undefined; @@ -37,17 +50,15 @@ export function createAllMatchingSelection(getIdentity: () => string) { * Selects everything matching the current query. When an expected identity is given and the query changed in * the meantime (the count was fetched for a different filter), nothing is selected and false is returned. */ - select(count: number, expectedIdentity?: string): boolean { + select, + async selectWithRefresh(count: number, refresh: () => Promise): Promise { const identity = getIdentity(); - if (expectedIdentity !== undefined && expectedIdentity !== identity) { - return false; + select(count, identity); + const selected = selection; + const refreshedCount = await refresh(); + if (selection === selected && refreshedCount !== undefined) { + select(refreshedCount, identity); } - - selection = { - count, - identity - }; - return true; } }; } diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte index 3ad4c4d8ed..04d056f444 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte @@ -883,14 +883,13 @@ } async function selectAllMatching() { - // Count again right now, so the number the user confirms is current. If the filter changes while the count is - // loading, the count belongs to the old filter and must not be bound to the new one. - const identity = allMatching.identity; - const result = await matchingTotalQuery.refetch(); - const count = (result.data?.meta.total ?? totalMatching) as number | undefined; - if (count !== undefined) { - allMatching.select(count, identity); + if (totalMatching === undefined) { + return; } + await allMatching.selectWithRefresh(totalMatching, async () => { + const result = await matchingTotalQuery.refetch(); + return result.data?.meta.total as number | undefined; + }); } let reconcileTotalRequested = false; diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte index 7efab475c4..1c736d1083 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte @@ -809,14 +809,13 @@ } async function selectAllMatching() { - // Count again right now, so the number the user confirms is current. If the filter changes while the count is - // loading, the count belongs to the old filter and must not be bound to the new one. - const identity = allMatching.identity; - const result = await matchingTotalQuery.refetch(); - const count = (result.data?.meta.total ?? totalMatching) as number | undefined; - if (count !== undefined) { - allMatching.select(count, identity); + if (totalMatching === undefined) { + return; } + await allMatching.selectWithRefresh(totalMatching, async () => { + const result = await matchingTotalQuery.refetch(); + return result.data?.meta.total as number | undefined; + }); } const debouncedReconciliationRefetch = debounce(1500, () => eventsQuery.refetch()); From c1522d87aadd72a2cea918861a07c36b5faa02da Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Sun, 29 Nov 2026 21:58:13 -0600 Subject: [PATCH 2/6] Clarify bulk selection test phases --- .../e2e/tests/bulk-selection-pending.e2e.ts | 32 ++++++++----------- .../all-matching-selection.svelte.test.ts | 7 ++-- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts b/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts index 40ebdb5d9f..7cdfb69686 100644 --- a/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts +++ b/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts @@ -20,20 +20,20 @@ for (const kind of ['event', 'stack'] as const) { } await page.goto(`/${kind}?project=${e2eScenario.projectId}&time=all&limit=2`); const table = page.locator('table:has(thead [role="checkbox"])').first(); - await expect(table.getByRole('checkbox', { name: 'Select row' })).toHaveCount(2, { timeout: 30_000 }); + await table.getByRole('checkbox', { name: 'Select row' }).nth(1).waitFor({ state: 'visible', timeout: 30_000 }); const isCountRequest = (url: URL) => url.pathname === `/api/v2/organizations/${e2eScenario.organizationId}/events` && url.searchParams.get('limit') === '1'; const initialCount = page.waitForResponse((response) => isCountRequest(new URL(response.url())) && response.status() === 200); await table.getByRole('checkbox', { name: 'Select all rows' }).click(); await (await initialCount).finished(); const selectAll = page.getByRole('button', { name: `Select all 5 ${kind}s matching this filter` }); - await expect(selectAll).toBeVisible(); - let countStarted = false; + await selectAll.waitFor({ state: 'visible' }); + const countStarted = Promise.withResolvers(); const countReleased = Promise.withResolvers(); await page.route( isCountRequest, async (route) => { - countStarted = true; + countStarted.resolve(); await countReleased.promise; await route.continue(); }, @@ -42,33 +42,29 @@ for (const kind of ['event', 'stack'] as const) { const countResponse = page.waitForResponse((response) => isCountRequest(new URL(response.url())) && response.status() === 200); // Act + let selectionText: null | string; + let dialogText: null | string; try { await selectAll.click(); - await expect.poll(() => countStarted).toBe(true); - - // Assert - await expect(page.getByRole('status').filter({ hasText: `All 5 ${kind}s are selected` })).toBeVisible({ timeout: 3_000 }); - - // Act + await countStarted.promise; + const selectionStatus = page.getByRole('status').filter({ hasText: `All 5 ${kind}s are selected` }); + await selectionStatus.waitFor({ state: 'visible', timeout: 3_000 }); + selectionText = await selectionStatus.textContent(); await page.getByRole('button', { name: 'Actions' }).click(); await page.getByRole('menuitem', { name: kind === 'event' ? 'Delete' : 'Mark Ignored' }).click(); - - // Assert const dialog = page.getByRole('alertdialog'); - await expect(dialog).toContainText(`About 5 ${kind}s match this filter`); - - // Act + await dialog.waitFor({ state: 'visible' }); + dialogText = await dialog.textContent(); await dialog.getByRole('button', { name: 'Cancel' }).click(); await page.getByRole('button', { name: 'Clear selection' }).click(); - - // Assert - await expect(table.getByRole('checkbox', { name: 'Select all rows' })).not.toBeChecked(); } finally { countReleased.resolve(); } await (await countResponse).finished(); // Assert + expect(selectionText).toContain(`All 5 ${kind}s are selected`); + expect(dialogText).toContain(`About 5 ${kind}s match this filter`); await expect(page.getByRole('button', { name: 'Clear selection' })).toBeHidden(); await expect(table.getByRole('checkbox', { name: 'Select all rows' })).not.toBeChecked(); }); diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts index 34f650450c..76c6196581 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts @@ -72,15 +72,12 @@ describe('createAllMatchingSelection', () => { // Act const pending = selection.selectWithRefresh(5, () => count.promise); - - // Assert - expect(selection.active?.count).toBe(5); - - // Act + const initialCount = selection.active?.count; count.resolve(7); await pending; // Assert + expect(initialCount).toBe(5); expect(selection.active?.count).toBe(7); }); From 413404b09d861d109fb00cfae769bde507dbfcec Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Sun, 29 Nov 2026 22:07:46 -0600 Subject: [PATCH 3/6] Simplify all-matching selection --- .../all-matching-selection.svelte.test.ts | 42 +++++++------------ .../shared/all-matching-selection.svelte.ts | 34 ++++----------- .../src/routes/(app)/event/+page.svelte | 3 +- .../src/routes/(app)/stack/+page.svelte | 3 +- 4 files changed, 26 insertions(+), 56 deletions(-) diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts index 76c6196581..b19dc78c3f 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts @@ -3,13 +3,13 @@ import { describe, expect, it } from 'vitest'; import { createAllMatchingSelection, getAllMatchingIdentity } from './all-matching-selection.svelte'; describe('createAllMatchingSelection', () => { - it('is active only for the query it was made for', () => { + it('is active only for the query it was made for', async () => { // Arrange const identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id', time: '[now-7d TO now]' }); const selection = createAllMatchingSelection(() => identity); // Act - selection.select(1234); + await selection.select(1234, async () => undefined); // Assert expect(selection.active).toEqual({ count: 1234, identity }); @@ -21,11 +21,11 @@ describe('createAllMatchingSelection', () => { ['project filter', { filter: 'type:error project:project-b', organizationId: 'organization-id', time: '[now-7d TO now]' }], ['saved view', { filter: 'type:error', organizationId: 'organization-id', savedViewId: 'view-2', time: '[now-7d TO now]' }], ['organization', { filter: 'type:error', organizationId: 'another-organization', time: '[now-7d TO now]' }] - ])('is dropped when the %s changes', (_, changed) => { + ])('is dropped when the %s changes', async (_, changed) => { // Arrange let identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id', time: '[now-7d TO now]' }); const selection = createAllMatchingSelection(() => identity); - selection.select(1234); + await selection.select(1234, async () => undefined); // Act identity = getAllMatchingIdentity(changed); @@ -34,27 +34,12 @@ describe('createAllMatchingSelection', () => { expect(selection.active).toBeUndefined(); }); - it('ignores a count that was fetched for a filter that is no longer showing', () => { - // Arrange - let identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id' }); - const selection = createAllMatchingSelection(() => identity); - const identityWhenCountingStarted = selection.identity; - - // Act - identity = getAllMatchingIdentity({ filter: 'type:log', organizationId: 'organization-id' }); - const selected = selection.select(1234, identityWhenCountingStarted); - - // Assert - expect(selected).toBe(false); - expect(selection.active).toBeUndefined(); - }); - - it('does not come back when the original query is restored after being cleared', () => { + it('does not come back when the original query is restored after being cleared', async () => { // Arrange const original = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id' }); let identity = original; const selection = createAllMatchingSelection(() => identity); - selection.select(10); + await selection.select(10, async () => undefined); // Act identity = getAllMatchingIdentity({ filter: 'type:log', organizationId: 'organization-id' }); @@ -71,7 +56,7 @@ describe('createAllMatchingSelection', () => { const count = Promise.withResolvers(); // Act - const pending = selection.selectWithRefresh(5, () => count.promise); + const pending = selection.select(5, () => count.promise); const initialCount = selection.active?.count; count.resolve(7); await pending; @@ -85,7 +70,7 @@ describe('createAllMatchingSelection', () => { // Arrange const selection = createAllMatchingSelection(() => 'query'); const count = Promise.withResolvers(); - const pending = selection.selectWithRefresh(5, () => count.promise); + const pending = selection.select(5, () => count.promise); // Act selection.clear(); @@ -101,8 +86,8 @@ describe('createAllMatchingSelection', () => { const selection = createAllMatchingSelection(() => 'query'); const firstCount = Promise.withResolvers(); const secondCount = Promise.withResolvers(); - const first = selection.selectWithRefresh(5, () => firstCount.promise); - const second = selection.selectWithRefresh(6, () => secondCount.promise); + const first = selection.select(5, () => firstCount.promise); + const second = selection.select(6, () => secondCount.promise); // Act secondCount.resolve(8); @@ -119,14 +104,17 @@ describe('createAllMatchingSelection', () => { let identity = 'first'; const selection = createAllMatchingSelection(() => identity); const count = Promise.withResolvers(); - const pending = selection.selectWithRefresh(5, () => count.promise); + const pending = selection.select(5, () => count.promise); // Act identity = 'second'; count.resolve(7); await pending; + const activeForDifferentQuery = selection.active; + identity = 'first'; // Assert - expect(selection.active).toBeUndefined(); + expect(activeForDifferentQuery).toBeUndefined(); + expect(selection.active?.count).toBe(5); }); }); diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts index 3e6f28b1ac..8fb0114137 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts @@ -22,19 +22,6 @@ export interface AllMatchingTarget { export function createAllMatchingSelection(getIdentity: () => string) { let selection = $state(); - function select(count: number, expectedIdentity?: string): boolean { - const identity = getIdentity(); - if (expectedIdentity !== undefined && expectedIdentity !== identity) { - return false; - } - - selection = { - count, - identity - }; - return true; - } - return { get active(): AllMatchingSelection | undefined { return selection && selection.identity === getIdentity() ? selection : undefined; @@ -42,22 +29,15 @@ export function createAllMatchingSelection(getIdentity: () => string) { clear() { selection = undefined; }, - /** The query the list is showing right now. Capture it before awaiting a count, then pass it to select. */ - get identity(): string { - return getIdentity(); - }, - /** - * Selects everything matching the current query. When an expected identity is given and the query changed in - * the meantime (the count was fetched for a different filter), nothing is selected and false is returned. - */ - select, - async selectWithRefresh(count: number, refresh: () => Promise): Promise { - const identity = getIdentity(); - select(count, identity); + async select(count: number, refresh: () => Promise): Promise { + selection = { + count, + identity: getIdentity() + }; const selected = selection; const refreshedCount = await refresh(); - if (selection === selected && refreshedCount !== undefined) { - select(refreshedCount, identity); + if (selection === selected && getIdentity() === selected.identity && refreshedCount !== undefined) { + selection.count = refreshedCount; } } }; diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte index 04d056f444..b38b0ac54f 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte @@ -886,7 +886,8 @@ if (totalMatching === undefined) { return; } - await allMatching.selectWithRefresh(totalMatching, async () => { + + await allMatching.select(totalMatching, async () => { const result = await matchingTotalQuery.refetch(); return result.data?.meta.total as number | undefined; }); diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte index 1c736d1083..8eb7164bef 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte @@ -812,7 +812,8 @@ if (totalMatching === undefined) { return; } - await allMatching.selectWithRefresh(totalMatching, async () => { + + await allMatching.select(totalMatching, async () => { const result = await matchingTotalQuery.refetch(); return result.data?.meta.total as number | undefined; }); From 9b65935feffc66e7c967719020666858cec597f9 Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Sun, 29 Nov 2026 22:14:25 -0600 Subject: [PATCH 4/6] Preserve the synchronous bulk selection contract while refreshing its count --- .../e2e/tests/bulk-selection-pending.e2e.ts | 8 ++-- .../all-matching-selection.svelte.test.ts | 42 ++++++++++++++----- .../shared/all-matching-selection.svelte.ts | 35 ++++++++++++---- .../src/routes/(app)/event/+page.svelte | 3 +- .../src/routes/(app)/stack/+page.svelte | 3 +- 5 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts b/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts index 7cdfb69686..64888b9b5d 100644 --- a/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts +++ b/src/Exceptionless.Web/ClientApp/e2e/tests/bulk-selection-pending.e2e.ts @@ -1,6 +1,8 @@ import { expect, test } from '../fixtures/e2e-test'; import { createRepresentativeEvent } from '../support/synthetic-event'; +test.use({ e2eUseGeneratedUser: true }); + for (const kind of ['event', 'stack'] as const) { test(`selecting all matching ${kind}s takes effect while the count refreshes`, async ({ e2eApi, e2eScenario, page }) => { // Arrange @@ -47,15 +49,15 @@ for (const kind of ['event', 'stack'] as const) { try { await selectAll.click(); await countStarted.promise; - const selectionStatus = page.getByRole('status').filter({ hasText: `All 5 ${kind}s are selected` }); - await selectionStatus.waitFor({ state: 'visible', timeout: 3_000 }); - selectionText = await selectionStatus.textContent(); await page.getByRole('button', { name: 'Actions' }).click(); await page.getByRole('menuitem', { name: kind === 'event' ? 'Delete' : 'Mark Ignored' }).click(); const dialog = page.getByRole('alertdialog'); await dialog.waitFor({ state: 'visible' }); dialogText = await dialog.textContent(); await dialog.getByRole('button', { name: 'Cancel' }).click(); + const selectionStatus = page.getByRole('status').filter({ hasText: `All 5 ${kind}s are selected` }); + await selectionStatus.waitFor({ state: 'visible', timeout: 3_000 }); + selectionText = await selectionStatus.textContent(); await page.getByRole('button', { name: 'Clear selection' }).click(); } finally { countReleased.resolve(); diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts index b19dc78c3f..9ae0c4d4cd 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts @@ -3,13 +3,13 @@ import { describe, expect, it } from 'vitest'; import { createAllMatchingSelection, getAllMatchingIdentity } from './all-matching-selection.svelte'; describe('createAllMatchingSelection', () => { - it('is active only for the query it was made for', async () => { + it('is active only for the query it was made for', () => { // Arrange const identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id', time: '[now-7d TO now]' }); const selection = createAllMatchingSelection(() => identity); // Act - await selection.select(1234, async () => undefined); + selection.select(1234); // Assert expect(selection.active).toEqual({ count: 1234, identity }); @@ -21,11 +21,11 @@ describe('createAllMatchingSelection', () => { ['project filter', { filter: 'type:error project:project-b', organizationId: 'organization-id', time: '[now-7d TO now]' }], ['saved view', { filter: 'type:error', organizationId: 'organization-id', savedViewId: 'view-2', time: '[now-7d TO now]' }], ['organization', { filter: 'type:error', organizationId: 'another-organization', time: '[now-7d TO now]' }] - ])('is dropped when the %s changes', async (_, changed) => { + ])('is dropped when the %s changes', (_, changed) => { // Arrange let identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id', time: '[now-7d TO now]' }); const selection = createAllMatchingSelection(() => identity); - await selection.select(1234, async () => undefined); + selection.select(1234); // Act identity = getAllMatchingIdentity(changed); @@ -34,12 +34,27 @@ describe('createAllMatchingSelection', () => { expect(selection.active).toBeUndefined(); }); - it('does not come back when the original query is restored after being cleared', async () => { + it('ignores a count that was fetched for a filter that is no longer showing', () => { + // Arrange + let identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id' }); + const selection = createAllMatchingSelection(() => identity); + const identityWhenCountingStarted = selection.identity; + + // Act + identity = getAllMatchingIdentity({ filter: 'type:log', organizationId: 'organization-id' }); + const selected = selection.select(1234, identityWhenCountingStarted); + + // Assert + expect(selected).toBe(false); + expect(selection.active).toBeUndefined(); + }); + + it('does not come back when the original query is restored after being cleared', () => { // Arrange const original = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id' }); let identity = original; const selection = createAllMatchingSelection(() => identity); - await selection.select(10, async () => undefined); + selection.select(10); // Act identity = getAllMatchingIdentity({ filter: 'type:log', organizationId: 'organization-id' }); @@ -56,7 +71,8 @@ describe('createAllMatchingSelection', () => { const count = Promise.withResolvers(); // Act - const pending = selection.select(5, () => count.promise); + selection.select(5); + const pending = selection.refreshCount(() => count.promise); const initialCount = selection.active?.count; count.resolve(7); await pending; @@ -70,7 +86,8 @@ describe('createAllMatchingSelection', () => { // Arrange const selection = createAllMatchingSelection(() => 'query'); const count = Promise.withResolvers(); - const pending = selection.select(5, () => count.promise); + selection.select(5); + const pending = selection.refreshCount(() => count.promise); // Act selection.clear(); @@ -86,8 +103,10 @@ describe('createAllMatchingSelection', () => { const selection = createAllMatchingSelection(() => 'query'); const firstCount = Promise.withResolvers(); const secondCount = Promise.withResolvers(); - const first = selection.select(5, () => firstCount.promise); - const second = selection.select(6, () => secondCount.promise); + selection.select(5); + const first = selection.refreshCount(() => firstCount.promise); + selection.select(6); + const second = selection.refreshCount(() => secondCount.promise); // Act secondCount.resolve(8); @@ -104,7 +123,8 @@ describe('createAllMatchingSelection', () => { let identity = 'first'; const selection = createAllMatchingSelection(() => identity); const count = Promise.withResolvers(); - const pending = selection.select(5, () => count.promise); + selection.select(5); + const pending = selection.refreshCount(() => count.promise); // Act identity = 'second'; diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts index 8fb0114137..26e8091e9a 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts @@ -29,16 +29,37 @@ export function createAllMatchingSelection(getIdentity: () => string) { clear() { selection = undefined; }, - async select(count: number, refresh: () => Promise): Promise { + /** The query the list is showing right now. Capture it before awaiting a count, then pass it to select. */ + get identity(): string { + return getIdentity(); + }, + /** Updates the estimate only while the same selection and query are still active. */ + async refreshCount(refresh: () => Promise): Promise { + const selected = selection; + if (!selected || selected.identity !== getIdentity()) { + return; + } + + const count = await refresh(); + if (count !== undefined && selected === selection && selected.identity === getIdentity()) { + selected.count = count; + } + }, + /** + * Selects everything matching the current query. When an expected identity is given and the query changed in + * the meantime (the count was fetched for a different filter), nothing is selected and false is returned. + */ + select(count: number, expectedIdentity?: string): boolean { + const identity = getIdentity(); + if (expectedIdentity !== undefined && expectedIdentity !== identity) { + return false; + } + selection = { count, - identity: getIdentity() + identity }; - const selected = selection; - const refreshedCount = await refresh(); - if (selection === selected && getIdentity() === selected.identity && refreshedCount !== undefined) { - selection.count = refreshedCount; - } + return true; } }; } diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte index b38b0ac54f..1622e85208 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte @@ -887,7 +887,8 @@ return; } - await allMatching.select(totalMatching, async () => { + allMatching.select(totalMatching); + await allMatching.refreshCount(async () => { const result = await matchingTotalQuery.refetch(); return result.data?.meta.total as number | undefined; }); diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte index 8eb7164bef..7eebaf26bc 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte @@ -813,7 +813,8 @@ return; } - await allMatching.select(totalMatching, async () => { + allMatching.select(totalMatching); + await allMatching.refreshCount(async () => { const result = await matchingTotalQuery.refetch(); return result.data?.meta.total as number | undefined; }); From 5de9bd025cecb2b09e6723fd6f0019bd2cc190af Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Sun, 29 Nov 2026 22:17:25 -0600 Subject: [PATCH 5/6] Refresh the matching count automatically when selection succeeds --- .../all-matching-selection.svelte.test.ts | 55 +++++++++++++------ .../shared/all-matching-selection.svelte.ts | 29 +++++----- .../src/routes/(app)/event/+page.svelte | 25 +++++---- .../src/routes/(app)/stack/+page.svelte | 25 +++++---- 4 files changed, 81 insertions(+), 53 deletions(-) diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts index 9ae0c4d4cd..617329d737 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { createAllMatchingSelection, getAllMatchingIdentity } from './all-matching-selection.svelte'; @@ -67,32 +67,37 @@ describe('createAllMatchingSelection', () => { it('selects the displayed estimate immediately and updates it when the count finishes', async () => { // Arrange - const selection = createAllMatchingSelection(() => 'query'); const count = Promise.withResolvers(); + const selection = createAllMatchingSelection( + () => 'query', + () => count.promise + ); // Act - selection.select(5); - const pending = selection.refreshCount(() => count.promise); + const selected = selection.select(5); const initialCount = selection.active?.count; count.resolve(7); - await pending; + await count.promise; // Assert + expect(selected).toBe(true); expect(initialCount).toBe(5); expect(selection.active?.count).toBe(7); }); it('does not restore a selection cleared while the count was loading', async () => { // Arrange - const selection = createAllMatchingSelection(() => 'query'); const count = Promise.withResolvers(); + const selection = createAllMatchingSelection( + () => 'query', + () => count.promise + ); selection.select(5); - const pending = selection.refreshCount(() => count.promise); // Act selection.clear(); count.resolve(7); - await pending; + await count.promise; // Assert expect(selection.active).toBeUndefined(); @@ -100,19 +105,18 @@ describe('createAllMatchingSelection', () => { it('does not overwrite a newer selection when an earlier count finishes later', async () => { // Arrange - const selection = createAllMatchingSelection(() => 'query'); const firstCount = Promise.withResolvers(); const secondCount = Promise.withResolvers(); + const refreshCount = vi.fn<() => Promise>().mockReturnValueOnce(firstCount.promise).mockReturnValueOnce(secondCount.promise); + const selection = createAllMatchingSelection(() => 'query', refreshCount); selection.select(5); - const first = selection.refreshCount(() => firstCount.promise); selection.select(6); - const second = selection.refreshCount(() => secondCount.promise); // Act secondCount.resolve(8); - await second; + await secondCount.promise; firstCount.resolve(7); - await first; + await firstCount.promise; // Assert expect(selection.active?.count).toBe(8); @@ -121,15 +125,17 @@ describe('createAllMatchingSelection', () => { it('does not apply a refreshed count to a different query', async () => { // Arrange let identity = 'first'; - const selection = createAllMatchingSelection(() => identity); const count = Promise.withResolvers(); + const selection = createAllMatchingSelection( + () => identity, + () => count.promise + ); selection.select(5); - const pending = selection.refreshCount(() => count.promise); // Act identity = 'second'; count.resolve(7); - await pending; + await count.promise; const activeForDifferentQuery = selection.active; identity = 'first'; @@ -137,4 +143,21 @@ describe('createAllMatchingSelection', () => { expect(activeForDifferentQuery).toBeUndefined(); expect(selection.active?.count).toBe(5); }); + + it('keeps the displayed estimate if the refresh fails', async () => { + // Arrange + const count = Promise.withResolvers(); + const selection = createAllMatchingSelection( + () => 'query', + () => count.promise + ); + + // Act + selection.select(5); + count.reject(new Error('Count unavailable')); + await count.promise.catch(() => undefined); + + // Assert + expect(selection.active?.count).toBe(5); + }); }); diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts index 26e8091e9a..b849bdb728 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts @@ -19,9 +19,23 @@ export interface AllMatchingTarget { * for: as soon as the query identity (organization, filter, time range, saved view) changes it is no longer active, so * an action can never run against a different set of events than the user confirmed. */ -export function createAllMatchingSelection(getIdentity: () => string) { +export function createAllMatchingSelection(getIdentity: () => string, refreshCount?: () => Promise) { let selection = $state(); + async function updateCount(selected: AllMatchingSelection) { + let count: number | undefined; + try { + count = await refreshCount?.(); + } catch { + // A failed count refresh leaves the displayed estimate in place. + return; + } + + if (count !== undefined && selection === selected && selected.identity === getIdentity()) { + selected.count = count; + } + } + return { get active(): AllMatchingSelection | undefined { return selection && selection.identity === getIdentity() ? selection : undefined; @@ -33,18 +47,6 @@ export function createAllMatchingSelection(getIdentity: () => string) { get identity(): string { return getIdentity(); }, - /** Updates the estimate only while the same selection and query are still active. */ - async refreshCount(refresh: () => Promise): Promise { - const selected = selection; - if (!selected || selected.identity !== getIdentity()) { - return; - } - - const count = await refresh(); - if (count !== undefined && selected === selection && selected.identity === getIdentity()) { - selected.count = count; - } - }, /** * Selects everything matching the current query. When an expected identity is given and the query changed in * the meantime (the count was fetched for a different filter), nothing is selected and false is returned. @@ -59,6 +61,7 @@ export function createAllMatchingSelection(getIdentity: () => string) { count, identity }; + void updateCount(selection); return true; } }; diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte index 1622e85208..e364be0040 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte @@ -775,13 +775,18 @@ // Gmail-style "select everything matching the filter". It belongs to the query it was made for, so a different // filter, time range, project or saved view drops it. - const allMatching = createAllMatchingSelection(() => - getAllMatchingIdentity({ - filter: eventsQueryParameters.filter, - organizationId: organization.current, - savedViewId: savedViewsState.activeSavedView?.id, - time: eventsQueryParameters.time - }) + const allMatching = createAllMatchingSelection( + () => + getAllMatchingIdentity({ + filter: eventsQueryParameters.filter, + organizationId: organization.current, + savedViewId: savedViewsState.activeSavedView?.id, + time: eventsQueryParameters.time + }), + async () => { + const result = await matchingTotalQuery.refetch(); + return result.data?.meta.total as number | undefined; + } ); const pageRowCount = $derived(table.getRowModel().rows.length); const isPageSelected = $derived(pageRowCount > 0 && table.getIsAllRowsSelected()); @@ -882,16 +887,12 @@ table.setPageIndex(0); } - async function selectAllMatching() { + function selectAllMatching() { if (totalMatching === undefined) { return; } allMatching.select(totalMatching); - await allMatching.refreshCount(async () => { - const result = await matchingTotalQuery.refetch(); - return result.data?.meta.total as number | undefined; - }); } let reconcileTotalRequested = false; diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte index 7eebaf26bc..e97f6e8f39 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte @@ -746,13 +746,18 @@ // Gmail-style "select everything matching the filter". It belongs to the query it was made for, so a different // filter, time range, project or saved view drops it. - const allMatching = createAllMatchingSelection(() => - getAllMatchingIdentity({ - filter: eventsQueryParameters.filter, - organizationId: organization.current, - savedViewId: savedViewsState.activeSavedView?.id, - time: eventsQueryParameters.time - }) + const allMatching = createAllMatchingSelection( + () => + getAllMatchingIdentity({ + filter: eventsQueryParameters.filter, + organizationId: organization.current, + savedViewId: savedViewsState.activeSavedView?.id, + time: eventsQueryParameters.time + }), + async () => { + const result = await matchingTotalQuery.refetch(); + return result.data?.meta.total as number | undefined; + } ); const pageRowCount = $derived(table.getRowModel().rows.length); const isPageSelected = $derived(pageRowCount > 0 && table.getIsAllRowsSelected()); @@ -808,16 +813,12 @@ table.setPageIndex(0); } - async function selectAllMatching() { + function selectAllMatching() { if (totalMatching === undefined) { return; } allMatching.select(totalMatching); - await allMatching.refreshCount(async () => { - const result = await matchingTotalQuery.refetch(); - return result.data?.meta.total as number | undefined; - }); } const debouncedReconciliationRefetch = debounce(1500, () => eventsQuery.refetch()); From 38c90bd6bbe9af2c9367499a3b0231ceea4d6f8a Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Sun, 29 Nov 2026 22:24:03 -0600 Subject: [PATCH 6/6] Require the matching count query when creating a selection --- .../all-matching-selection.svelte.test.ts | 19 +++++++++++++++---- .../shared/all-matching-selection.svelte.ts | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts index 617329d737..dc9b517709 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.test.ts @@ -6,7 +6,10 @@ describe('createAllMatchingSelection', () => { it('is active only for the query it was made for', () => { // Arrange const identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id', time: '[now-7d TO now]' }); - const selection = createAllMatchingSelection(() => identity); + const selection = createAllMatchingSelection( + () => identity, + async () => undefined + ); // Act selection.select(1234); @@ -24,7 +27,10 @@ describe('createAllMatchingSelection', () => { ])('is dropped when the %s changes', (_, changed) => { // Arrange let identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id', time: '[now-7d TO now]' }); - const selection = createAllMatchingSelection(() => identity); + const selection = createAllMatchingSelection( + () => identity, + async () => undefined + ); selection.select(1234); // Act @@ -37,7 +43,8 @@ describe('createAllMatchingSelection', () => { it('ignores a count that was fetched for a filter that is no longer showing', () => { // Arrange let identity = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id' }); - const selection = createAllMatchingSelection(() => identity); + const refreshCount = vi.fn(async () => 1234); + const selection = createAllMatchingSelection(() => identity, refreshCount); const identityWhenCountingStarted = selection.identity; // Act @@ -46,6 +53,7 @@ describe('createAllMatchingSelection', () => { // Assert expect(selected).toBe(false); + expect(refreshCount).not.toHaveBeenCalled(); expect(selection.active).toBeUndefined(); }); @@ -53,7 +61,10 @@ describe('createAllMatchingSelection', () => { // Arrange const original = getAllMatchingIdentity({ filter: 'type:error', organizationId: 'organization-id' }); let identity = original; - const selection = createAllMatchingSelection(() => identity); + const selection = createAllMatchingSelection( + () => identity, + async () => undefined + ); selection.select(10); // Act diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts index b849bdb728..90c869855e 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/all-matching-selection.svelte.ts @@ -19,13 +19,13 @@ export interface AllMatchingTarget { * for: as soon as the query identity (organization, filter, time range, saved view) changes it is no longer active, so * an action can never run against a different set of events than the user confirmed. */ -export function createAllMatchingSelection(getIdentity: () => string, refreshCount?: () => Promise) { +export function createAllMatchingSelection(getIdentity: () => string, refreshCount: () => Promise) { let selection = $state(); async function updateCount(selected: AllMatchingSelection) { let count: number | undefined; try { - count = await refreshCount?.(); + count = await refreshCount(); } catch { // A failed count refresh leaves the displayed estimate in place. return;