Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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
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 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 selectAll.waitFor({ state: 'visible' });
const countStarted = Promise.withResolvers<void>();
const countReleased = Promise.withResolvers<void>();
await page.route(
isCountRequest,
async (route) => {
countStarted.resolve();
await countReleased.promise;
await route.continue();
},
{ times: 1 }
);
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 countStarted.promise;
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();
}
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();
});
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';

import { createAllMatchingSelection, getAllMatchingIdentity } from './all-matching-selection.svelte';

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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -46,14 +53,18 @@ describe('createAllMatchingSelection', () => {

// Assert
expect(selected).toBe(false);
expect(refreshCount).not.toHaveBeenCalled();
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);
const selection = createAllMatchingSelection(
() => identity,
async () => undefined
);
selection.select(10);

// Act
Expand All @@ -64,4 +75,100 @@ describe('createAllMatchingSelection', () => {
// Assert
expect(selection.active).toBeUndefined();
});

it('selects the displayed estimate immediately and updates it when the count finishes', async () => {
// Arrange
const count = Promise.withResolvers<number | undefined>();
const selection = createAllMatchingSelection(
() => 'query',
() => count.promise
);

// Act
const selected = selection.select(5);
const initialCount = selection.active?.count;
count.resolve(7);
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 count = Promise.withResolvers<number | undefined>();
const selection = createAllMatchingSelection(
() => 'query',
() => count.promise
);
selection.select(5);

// Act
selection.clear();
count.resolve(7);
await count.promise;

// Assert
expect(selection.active).toBeUndefined();
});

it('does not overwrite a newer selection when an earlier count finishes later', async () => {
// Arrange
const firstCount = Promise.withResolvers<number | undefined>();
const secondCount = Promise.withResolvers<number | undefined>();
const refreshCount = vi.fn<() => Promise<number | undefined>>().mockReturnValueOnce(firstCount.promise).mockReturnValueOnce(secondCount.promise);
const selection = createAllMatchingSelection(() => 'query', refreshCount);
selection.select(5);
selection.select(6);

// Act
secondCount.resolve(8);
await secondCount.promise;
firstCount.resolve(7);
await firstCount.promise;

// Assert
expect(selection.active?.count).toBe(8);
});

it('does not apply a refreshed count to a different query', async () => {
// Arrange
let identity = 'first';
const count = Promise.withResolvers<number | undefined>();
const selection = createAllMatchingSelection(
() => identity,
() => count.promise
);
selection.select(5);

// Act
identity = 'second';
count.resolve(7);
await count.promise;
const activeForDifferentQuery = selection.active;
identity = 'first';

// Assert
expect(activeForDifferentQuery).toBeUndefined();
expect(selection.active?.count).toBe(5);
});

it('keeps the displayed estimate if the refresh fails', async () => {
// Arrange
const count = Promise.withResolvers<number>();
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<number | undefined>) {
let selection = $state<AllMatchingSelection>();

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;
Expand All @@ -47,6 +61,7 @@ export function createAllMatchingSelection(getIdentity: () => string) {
count,
identity
};
void updateCount(selection);
return true;
}
};
Expand Down
32 changes: 17 additions & 15 deletions src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -882,15 +887,12 @@
table.setPageIndex(0);
}

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);
function selectAllMatching() {
if (totalMatching === undefined) {
return;
}

allMatching.select(totalMatching);
}

let reconcileTotalRequested = false;
Expand Down
32 changes: 17 additions & 15 deletions src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -808,15 +813,12 @@
table.setPageIndex(0);
}

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);
function selectAllMatching() {
if (totalMatching === undefined) {
return;
}

allMatching.select(totalMatching);
}

const debouncedReconciliationRefetch = debounce(1500, () => eventsQuery.refetch());
Expand Down
Loading