diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/events/api.svelte.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/events/api.svelte.ts index cbdeeb4feb..1b6c1d4554 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/events/api.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/events/api.svelte.ts @@ -493,7 +493,7 @@ export function getOrganizationEventsQuery(request: GetOrganizationEventsRequest /** * Get session count with aggregations for stats and chart data. - * Uses aggregation: avg:value cardinality:user date:(date^offset cardinality:user) + * Uses aggregation: avg:value cardinality:user date:(date^timezone cardinality:user) */ export function getOrganizationSessionsCountQuery(request: GetOrganizationSessionsCountRequest) { const queryClient = useQueryClient(); diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/summary/summary.svelte b/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/summary/summary.svelte index 51ab2de906..4c82a4bb98 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/summary/summary.svelte +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/summary/summary.svelte @@ -28,34 +28,45 @@ let { linkToDetails = true, showStatus = true, showType = true, summary }: Props = $props(); let showBadge: boolean = $derived(showStatus && 'status' in summary && summary.status !== 'open'); let badgeStatus = $derived(('status' in summary && (summary.status as StackStatus)) || StackStatus.Open); + // Stack summaries always link to the stack; event summaries only when asked to. + let isLinked = $derived(linkToDetails || summary.template_key.startsWith('stack-')); -{#if summary.template_key === 'event-summary'} - -{:else if summary.template_key === 'stack-summary'} - -{:else if summary.template_key === 'event-simple-summary'} - -{:else if summary.template_key === 'stack-simple-summary'} - -{:else if summary.template_key === 'event-error-summary'} - -{:else if summary.template_key === 'stack-error-summary'} - -{:else if summary.template_key === 'event-session-summary'} - -{:else if summary.template_key === 'stack-session-summary'} - -{:else if summary.template_key === 'event-notfound-summary'} - -{:else if summary.template_key === 'stack-notfound-summary'} - -{:else if summary.template_key === 'event-feature-summary'} - -{:else if summary.template_key === 'stack-feature-summary'} - -{:else if summary.template_key === 'event-log-summary'} - -{:else} - -{/if} + +
+ {#if summary.template_key === 'event-summary'} + + {:else if summary.template_key === 'stack-summary'} + + {:else if summary.template_key === 'event-simple-summary'} + + {:else if summary.template_key === 'stack-simple-summary'} + + {:else if summary.template_key === 'event-error-summary'} + + {:else if summary.template_key === 'stack-error-summary'} + + {:else if summary.template_key === 'event-session-summary'} + + {:else if summary.template_key === 'stack-session-summary'} + + {:else if summary.template_key === 'event-notfound-summary'} + + {:else if summary.template_key === 'stack-notfound-summary'} + + {:else if summary.template_key === 'event-feature-summary'} + + {:else if summary.template_key === 'stack-feature-summary'} + + {:else if summary.template_key === 'event-log-summary'} + + {:else} + + {/if} +
+ + diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/table/events-bulk-actions-dropdown-menu.svelte b/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/table/events-bulk-actions-dropdown-menu.svelte index 20ae96d5d5..b23c0ceef0 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/table/events-bulk-actions-dropdown-menu.svelte +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/events/components/table/events-bulk-actions-dropdown-menu.svelte @@ -3,8 +3,6 @@ - - {percentage.toFixed(1)}% - + +{#if users > 0} + {compactCountFormat.format(users)} +{:else} + — +{/if} diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/api/api.svelte.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/api/api.svelte.ts index 20ad16e13c..ea7ef5f8ea 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/api/api.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/api/api.svelte.ts @@ -14,6 +14,12 @@ export { DEFAULT_LIMIT } from './constants'; */ export const DEFAULT_OFFSET = new SvelteDate().getTimezoneOffset() !== 0 ? new SvelteDate().getTimezoneOffset() * -1 + 'm' : undefined; +/** + * The time zone date histograms bucket in. An IANA zone keeps day buckets on local midnight across daylight saving changes, + * which a fixed offset can't: buckets from the other half of the year would start at 1 AM or 11 PM local time. + */ +export const DEFAULT_HISTOGRAM_TIME_ZONE = getHistogramTimeZone(); + export class FetchClientStatus { public isLoading = $state(false); @@ -46,10 +52,29 @@ export async function fetchApiJson(path: string, init: RequestInit): Promise< return (await response.json()) as T; } +/** The `date` aggregation term, bucketed in the user's time zone, e.g. `date^Europe/Amsterdam`. */ +export function getDateHistogramTerm(field = 'date'): string { + return DEFAULT_HISTOGRAM_TIME_ZONE ? `${field}^${DEFAULT_HISTOGRAM_TIME_ZONE}` : field; +} + export function useFetchClientStatus(target?: FetchClient | FetchClientProvider) { return new FetchClientStatus(target); } +function getHistogramTimeZone(): string | undefined { + try { + const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; + // Unquoted aggregation terms can't contain whitespace or query syntax characters. + if (timeZone && timeZone !== 'UTC' && /^[\w+\-/]+$/.test(timeZone)) { + return timeZone; + } + } catch { + // Fall back to the fixed offset below. + } + + return DEFAULT_OFFSET; +} + async function toProblemDetails(response: Response): Promise { const contentType = response.headers.get('Content-Type') ?? ''; if (contentType.startsWith('application/problem+json') || contentType.startsWith('application/json')) { diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/data-table/data-table-footer.svelte b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/data-table/data-table-footer.svelte index 2e5938aa01..95e6378991 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/data-table/data-table-footer.svelte +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/data-table/data-table-footer.svelte @@ -93,7 +93,7 @@ diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/formatters/date-time.svelte b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/formatters/date-time.svelte index 9a64fca082..5dc2bddc20 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/formatters/date-time.svelte +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/components/formatters/date-time.svelte @@ -15,7 +15,6 @@ return date.toLocaleString(undefined, { day: 'numeric', hour: 'numeric', - hour12: true, minute: '2-digit', month: 'short', second: '2-digit', diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.test.ts index 55a588ab89..f931914d90 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { formatDateLabel, formatDateRangeLabel, getDifferenceInSeconds, getRelativeTimeFormatUnit, getSetIntervalTime } from './dates'; +import { formatDateLabel, formatDateRangeLabel, getDifferenceInSeconds, getRelativeTimeFormatUnit, getSetIntervalTime, usesTwelveHourClock } from './dates'; describe('formatDateLabel', () => { it('preserves local date and relative-label behavior without a timezone override', () => { @@ -49,7 +49,20 @@ describe('formatDateLabel', () => { // Assert expect(label).toContain(' at '); - expect(label).toContain(new Intl.DateTimeFormat(undefined, { hour: 'numeric', hour12: true, minute: '2-digit', timeZone }).format(date)); + expect(label).toContain(new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit', timeZone }).format(date)); + }); +}); + +describe('usesTwelveHourClock', () => { + it('follows the locale instead of always using AM/PM', () => { + // Arrange + const locales = ['en-US', 'nl-NL', 'de-DE']; + + // Act + const results = locales.map((locale) => usesTwelveHourClock(locale)); + + // Assert + expect(results).toEqual([true, false, false]); }); }); diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.ts index 9c302423ed..455afd6dc0 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/shared/dates.ts @@ -4,7 +4,7 @@ import { fromDate, getLocalTimeZone, isSameDay, isSameYear } from '@internationa * Configuration options for date and time formatting */ interface DateLabelFormatOptions { - /** Use 12-hour format with AM/PM (default: true) */ + /** Use 12-hour format with AM/PM (default: the user's locale) */ hour12?: boolean; /** Show relative labels like "Today" and "Yesterday" (default: true) */ includeRelative?: boolean; @@ -54,7 +54,7 @@ export function formatDate(value: Date): string { * }) */ export function formatDateLabel(date: Date, currentDate: Date = new Date(), options: DateLabelFormatOptions = {}): string { - const { hour12 = true, includeRelative = true, joiner = ' at ', month = 'long', timeZone } = options; + const { hour12, includeRelative = true, joiner = ' at ', month = 'long', timeZone } = options; const displayDate = fromDate(date, timeZone ?? getLocalTimeZone()); const displayCurrentDate = fromDate(currentDate, timeZone ?? getLocalTimeZone()); @@ -87,8 +87,8 @@ export function formatDateLabel(date: Date, currentDate: Date = new Date(), opti const timeOpts: Intl.DateTimeFormatOptions = { hour: 'numeric', - hour12, - ...(min > 0 || sec > 0 ? { minute: '2-digit' } : {}), + ...(hour12 === undefined ? {} : { hour12 }), + ...(min > 0 || sec > 0 || !(hour12 ?? usesTwelveHourClock()) ? { minute: '2-digit' } : {}), ...(sec > 0 ? { second: '2-digit' } : {}), ...(timeZone ? { timeZone } : {}) }; @@ -196,6 +196,15 @@ export function isSameUtcMonth(date: Date, other: Date = new Date()): boolean { return date.getUTCFullYear() === other.getUTCFullYear() && date.getUTCMonth() === other.getUTCMonth(); } +/** + * Whether the user's locale writes times on a 12-hour clock ("2 PM") rather than a 24-hour one ("14:00"). + * A bare hour reads well on a 12-hour clock, but a 24-hour time always needs its minutes. + */ +export function usesTwelveHourClock(locale?: string): boolean { + const hourCycle = new Intl.DateTimeFormat(locale, { hour: 'numeric' }).resolvedOptions().hourCycle; + return hourCycle === 'h11' || hourCycle === 'h12'; +} + function formatCompactDateTimeLabel(date: Date, currentDate: Date): string { const datePart = formatDatePart(date, currentDate); const timePart = formatTimePart(date, true); @@ -230,8 +239,7 @@ function formatTimePart(date: Date, omitSeconds: boolean): string { const opts: Intl.DateTimeFormatOptions = { hour: 'numeric', - hour12: true, - ...(min > 0 || (!omitSeconds && sec > 0) ? { minute: '2-digit' } : {}), + ...(min > 0 || (!omitSeconds && sec > 0) || !usesTwelveHourClock() ? { minute: '2-digit' } : {}), ...(!omitSeconds && sec > 0 ? { second: '2-digit' } : {}) }; diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stack-card.svelte b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stack-card.svelte index ff5fdb8ab8..34cb24a99a 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stack-card.svelte +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stack-card.svelte @@ -34,7 +34,7 @@ import TagList from '#features/shared/components/tag-list.svelte'; import { fillDateSeries } from '#features/shared/utils/charts.ts'; import { getStackQuery } from '#features/stacks/api.svelte.ts'; - import { DEFAULT_OFFSET } from '#shared/api/api.svelte.ts'; + import { getDateHistogramTerm } from '#shared/api/api.svelte.ts'; import StackLogLevel from './stack-log-level.svelte'; import StackOptionsDropdownMenu from './stack-options-dropdown-menu.svelte'; @@ -91,7 +91,7 @@ // TODO: Add stack charts for Occurrences, Average Value, Value Sum const stackCountQuery = getStackCountQuery({ params: { - aggregations: `date:(date${DEFAULT_OFFSET ? '^' + DEFAULT_OFFSET : ''} cardinality:user sum:count~1) min:date max:date cardinality:user sum:count~1`, + aggregations: `date:(${getDateHistogramTerm()} cardinality:user sum:count~1) min:date max:date cardinality:user sum:count~1`, time: METRICS_TIME_RANGE }, route: { diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte index 22fedb4153..c1452781a8 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte @@ -12,6 +12,7 @@ import { Button } from '#comp/ui/button/index.ts'; import * as DropdownMenu from '#comp/ui/dropdown-menu/index.ts'; + import { organization } from '#features/organizations/context.svelte.ts'; import { postBulkOperation } from '#features/tasks/api.svelte.ts'; import { BulkOperationSelectionKind, @@ -22,8 +23,6 @@ } from '#features/tasks/models.ts'; import { getProblemMessage } from '#shared/validation.ts'; - import { deleteStack, postChangeStatus, postMarkFixed, postMarkSnoozed } from '../api.svelte'; - import { StackStatus } from '../models'; import ConfirmMatchingStacksDialog from './dialogs/confirm-matching-stacks-dialog.svelte'; import MarkStackDiscardedDialog from './dialogs/mark-stack-discarded-dialog.svelte'; import MarkStackFixedInVersionDialog from './dialogs/mark-stack-fixed-in-version-dialog.svelte'; @@ -34,7 +33,8 @@ detail?: string; label: string; parameters: Record; - success: string; + /** The toast shown once started, given the count, e.g. "Marking 12 stacks as ignored". */ + success: (count: string) => string; type: string; } @@ -91,144 +91,54 @@ openRemoveStackDialog = dialog === 'remove'; } - const updateMarkFixed = postMarkFixed({ - route: { - get ids() { - return ids; - } - } - }); - - const updateMarkSnoozed = postMarkSnoozed({ - route: { - get ids() { - return ids; - } - } - }); - - const changeStatus = postChangeStatus({ - route: { - get ids() { - return ids; - } - } - }); - - const removeStack = deleteStack({ - route: { - get ids() { - return ids; - } - } - }); - const startBulk = postBulkOperation(); - async function markDiscarded() { - if (allMatching) { - await runAllMatching( - STACKS_CHANGE_STATUS_OPERATION, - { - status: 'discarded' - }, - 'Marking as discarded' - ); - return; - } - - await changeStatus.mutateAsync(StackStatus.Discarded); - - if (ids.length === 1) { - toast.success('Successfully marked stack as discarded.'); - } else { - toast.success(`Successfully marked ${Intl.NumberFormat().format(ids.length)} stacks as discarded.`); - } + function formatStackCount(count: number): string { + return count === 1 ? '1 stack' : `${Intl.NumberFormat().format(count)} stacks`; + } - table.resetRowSelection(); + async function markDiscarded() { + await startBulkOperation( + STACKS_CHANGE_STATUS_OPERATION, + { + status: 'discarded' + }, + (count) => `Marking ${count} as discarded` + ); } async function markFixed(version?: string) { - if (allMatching) { - await runAllMatching( - STACKS_MARK_FIXED_OPERATION, - version - ? { - version - } - : {}, - 'Marking as fixed' - ); - return; - } - - await updateMarkFixed.mutateAsync(version); - - if (ids.length === 1) { - toast.success('Successfully marked stack as fixed.'); - } else { - toast.success(`Successfully marked ${Intl.NumberFormat().format(ids.length)} stacks as fixed.`); - } - - table.resetRowSelection(); + await startBulkOperation( + STACKS_MARK_FIXED_OPERATION, + version + ? { + version + } + : {}, + (count) => `Marking ${count} as fixed` + ); } async function markIgnored() { - if (allMatching) { - requestConfirm({ - label: 'Mark Matching Stacks Ignored', - parameters: { - status: 'ignored' - }, - success: 'Marking as ignored', - type: STACKS_CHANGE_STATUS_OPERATION - }); - return; - } - - try { - await changeStatus.mutateAsync(StackStatus.Ignored); - } catch (error) { - toast.error(getProblemMessage(error, 'Unable to change stack status.')); - return; - } - - if (ids.length === 1) { - toast.success('Successfully marked stack as ignored.'); - } else { - toast.success(`Successfully marked ${Intl.NumberFormat().format(ids.length)} stacks as ignored.`); - } - - table.resetRowSelection(); + await runOrConfirm({ + label: 'Mark Matching Stacks Ignored', + parameters: { + status: 'ignored' + }, + success: (count) => `Marking ${count} as ignored`, + type: STACKS_CHANGE_STATUS_OPERATION + }); } async function markOpen() { - if (allMatching) { - requestConfirm({ - label: 'Mark Matching Stacks Open', - parameters: { - status: 'open' - }, - success: 'Marking as open', - type: STACKS_CHANGE_STATUS_OPERATION - }); - return; - } - - try { - await changeStatus.mutateAsync(StackStatus.Open); - } catch (error) { - toast.error(getProblemMessage(error, 'Unable to change stack status.')); - return; - } - - if (ids.length === 1) { - toast.success('Successfully marked stack as open.'); - } else { - toast.success(`Successfully marked ${Intl.NumberFormat().format(ids.length)} stacks as open.`); - } - - table.resetRowSelection(); + await runOrConfirm({ + label: 'Mark Matching Stacks Open', + parameters: { + status: 'open' + }, + success: (count) => `Marking ${count} as open`, + type: STACKS_CHANGE_STATUS_OPERATION + }); } async function markSnoozed(timePeriod: '6hours' | 'day' | 'month' | 'week') { @@ -254,62 +164,53 @@ break; } - if (allMatching) { - requestConfirm({ - detail: `Snooze for ${duration}, until ${snoozeUntilUtc.toLocaleString()}.`, - label: 'Snooze Matching Stacks', - parameters: { - snooze_until_utc: snoozeUntilUtc.toISOString() - }, - success: 'Snoozing', - type: STACKS_SNOOZE_OPERATION - }); - return; - } - - try { - await updateMarkSnoozed.mutateAsync(snoozeUntilUtc); - } catch (error) { - toast.error(getProblemMessage(error, 'Unable to snooze selected stacks.')); - return; - } - - if (ids.length === 1) { - toast.success('Successfully marked stack as snoozed.'); - } else { - toast.success(`Successfully marked ${Intl.NumberFormat().format(ids.length)} stacks as snoozed.`); - } - - table.resetRowSelection(); + await runOrConfirm({ + detail: `Snooze for ${duration}, until ${snoozeUntilUtc.toLocaleString()}.`, + label: 'Snooze Matching Stacks', + parameters: { + snooze_until_utc: snoozeUntilUtc.toISOString() + }, + success: (count) => `Snoozing ${count}`, + type: STACKS_SNOOZE_OPERATION + }); } async function remove() { + await startBulkOperation(STACKS_DELETE_OPERATION, {}, (count) => `Deleting ${count}`); + } + + /** Selected rows run right away; everything matching a filter asks first, since the user can't see every stack it covers. */ + async function runOrConfirm(request: PendingConfirm): Promise { + confirmed(); if (allMatching) { - await runAllMatching(STACKS_DELETE_OPERATION, {}, 'Deleting'); + pendingConfirm = request; + openConfirmDialog = true; return; } - await removeStack.mutateAsync(); + await startBulkOperation(request.type, request.parameters, request.success); + } - if (ids.length === 1) { - toast.success('Successfully deleted stack.'); - } else { - toast.success(`Successfully deleted ${Intl.NumberFormat().format(ids.length)} stacks.`); + async function runPending(): Promise { + const request = pendingConfirm; + if (request) { + await startBulkOperation(request.type, request.parameters, request.success); } - - table.resetRowSelection(); } - function requestConfirm(request: PendingConfirm): void { - confirmed(); - pendingConfirm = request; - openConfirmDialog = true; + function setOpen(isOpen: boolean): void { + open = selectedCount > 0 && isOpen; } - /** Starts the action on everything matching the filter. When it can't be started the problem is shown and the selection is kept. */ - async function runAllMatching(type: string, parameters: Record, success: string): Promise { + /** + * Runs the action as a background task, on the selected stacks or on everything matching the filter. Ids go in the request + * body, so any number of selected stacks works. When it can't be started the problem is shown and the selection is kept. + */ + async function startBulkOperation(type: string, parameters: Record, success: (count: string) => string): Promise { const target = allMatching; - if (!target || isStarting || confirmedSelectionIdentity !== selectionIdentity) { + const selectedIds = ids; + const organizationId = target?.organizationId ?? organization.current; + if (!organizationId || selectedCount === 0 || isStarting || confirmedSelectionIdentity !== selectionIdentity) { return; } @@ -317,40 +218,37 @@ try { try { await startBulk.mutateAsync({ - organization_id: target.organizationId, + organization_id: organizationId, parameters: Object.keys(parameters).length > 0 ? parameters : undefined, - selection: { - filter: target.filter ?? '', - kind: BulkOperationSelectionKind.Filter, - offset: target.offset, - time: target.time - }, + selection: target + ? { + filter: target.filter ?? '', + kind: BulkOperationSelectionKind.Filter, + offset: target.offset, + time: target.time + } + : { + ids: selectedIds, + kind: BulkOperationSelectionKind.Ids + }, type }); } catch (error) { // Keep the selection so the user can try again, for example after another delete finishes. - toast.error(getProblemMessage(error, 'Unable to start the operation on the matching stacks.')); + toast.error(getProblemMessage(error, 'Unable to start the operation on the selected stacks.')); return; } - toast.success(`${success} about ${Intl.NumberFormat().format(target.count)} stacks. Progress is shown at the bottom of the page.`); + const count = target ? `about ${Intl.NumberFormat().format(target.count)} stacks` : formatStackCount(selectedIds.length); + toast.success(`${success(count)}. Progress is shown at the bottom of the page.`); table.resetRowSelection(); - onAllMatchingStarted?.(); + if (target) { + onAllMatchingStarted?.(); + } } finally { isStarting = false; } } - - async function runPending(): Promise { - const request = pendingConfirm; - if (request) { - await runAllMatching(request.type, request.parameters, request.success); - } - } - - function setOpen(isOpen: boolean): void { - open = selectedCount > 0 && isOpen; - } open, setOpen}> diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte.test.ts index ca1d5687ac..d5d559a200 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte.test.ts @@ -3,17 +3,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; const startBulk = vi.hoisted(() => vi.fn()); const toast = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn() })); -const mutations = vi.hoisted(() => ({ changeStatus: vi.fn(), delete: vi.fn(), markFixed: vi.fn(), snooze: vi.fn() })); vi.mock('svelte-sonner', () => ({ toast })); vi.mock('#features/tasks/api.svelte.ts', () => ({ postBulkOperation: () => ({ mutateAsync: startBulk }) })); - -vi.mock('../api.svelte', () => ({ - deleteStack: vi.fn(() => ({ mutateAsync: mutations.delete })), - postChangeStatus: vi.fn(() => ({ mutateAsync: mutations.changeStatus })), - postMarkFixed: vi.fn(() => ({ mutateAsync: mutations.markFixed })), - postMarkSnoozed: vi.fn(() => ({ mutateAsync: mutations.snooze })) -})); +vi.mock('#features/organizations/context.svelte.ts', () => ({ organization: { current: 'current-organization-id' } })); import { BulkOperationSelectionKind } from '#features/tasks/models.ts'; @@ -40,7 +33,6 @@ describe('StacksBulkActionsDropdownMenu', () => { startBulk.mockResolvedValue(undefined); toast.error.mockClear(); toast.success.mockClear(); - Object.values(mutations).forEach((m) => m.mockReset()); }); afterEach(async () => { @@ -81,17 +73,30 @@ describe('StacksBulkActionsDropdownMenu', () => { expect(trigger.title).toBe('Actions'); }); - it('changes the selected stacks through the per-id endpoint when all matching is not active', async () => { + it('starts a background task for the selected stack ids without confirming', async () => { // Arrange - const table = { getSelectedRowModel: () => ({ flatRows: [{ id: 'a' }] }), resetRowSelection: vi.fn() } as never; - render(StacksBulkActionsDropdownMenu, { props: { table } }); + const ids = Array.from({ length: 12 }, (_, index) => `stack-${index}`); + const resetRowSelection = vi.fn(); + const onAllMatchingStarted = vi.fn(); + const table = { getSelectedRowModel: () => ({ flatRows: ids.map((id) => ({ id })) }), resetRowSelection } as never; + render(StacksBulkActionsDropdownMenu, { props: { onAllMatchingStarted, table } }); // Act - await choose('Mark Open'); + await choose('Mark Ignored'); // Assert - await waitFor(() => expect(mutations.changeStatus).toHaveBeenCalledWith('open')); - expect(startBulk).not.toHaveBeenCalled(); + await waitFor(() => + expect(startBulk).toHaveBeenCalledWith({ + organization_id: 'current-organization-id', + parameters: { status: 'ignored' }, + selection: { ids, kind: BulkOperationSelectionKind.Ids }, + type: 'stacks.change-status' + }) + ); + expect(screen.queryByRole('alertdialog')).toBeNull(); + expect(resetRowSelection).toHaveBeenCalledOnce(); + expect(onAllMatchingStarted).not.toHaveBeenCalled(); + expect(toast.success).toHaveBeenCalledWith('Marking 12 stacks as ignored. Progress is shown at the bottom of the page.'); }); it.each([ @@ -111,7 +116,6 @@ describe('StacksBulkActionsDropdownMenu', () => { await waitFor(() => expect(startBulk).toHaveBeenCalledWith({ organization_id: 'organization-id', parameters, selection, type })); expect(onAllMatchingStarted).toHaveBeenCalledOnce(); expect(resetRowSelection).toHaveBeenCalledOnce(); - expect(mutations.changeStatus).not.toHaveBeenCalled(); }); it('only opens the snooze durations when the submenu is opened with the keyboard', async () => { 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..af5b92321f 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/+page.svelte @@ -73,7 +73,7 @@ import { parseDateMathRange } from '#features/shared/utils/datemath.ts'; import { StackStatus } from '#features/stacks/models.ts'; import { ChangeType, type WebSocketMessageValue } from '#features/websockets/models.ts'; - import { DEFAULT_OFFSET } from '#shared/api/api.svelte.ts'; + import { DEFAULT_OFFSET, getDateHistogramTerm } from '#shared/api/api.svelte.ts'; import { createQueryParameters } from '#shared/query-params/index.ts'; import { @@ -983,7 +983,7 @@ enabled: () => !isSavedViewRoutePending, params: { get aggregations() { - return `date:(date${DEFAULT_OFFSET ? `^${DEFAULT_OFFSET}` : ''} cardinality:stack sum:count~1) cardinality:stack terms:(first @include:true) sum:count~1`; + return `date:(${getDateHistogramTerm()} cardinality:stack sum:count~1) cardinality:stack terms:(first @include:true) sum:count~1`; }, get filter() { return eventsQueryParameters.filter; diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/[eventId=objectid]/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/[eventId=objectid]/+page.svelte index 71fce3adc9..853a06bfce 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/[eventId=objectid]/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/event/[eventId=objectid]/+page.svelte @@ -15,10 +15,10 @@ import { buildEventDetailsHref } from '#features/events/components/summary/index.ts'; import { organization } from '#features/organizations/context.svelte.ts'; - import { getEventsNavigationOptionsForFilter, redirectToEventsWithFilter } from '../../redirect-to-events.svelte.ts'; + import { getDetailsNavigationOptions, redirectToEventsWithFilter } from '../../redirect-to-events.svelte.ts'; async function filterChanged(addedOrUpdated: FacetedFilter.IFilter) { - await redirectToEventsWithFilter(organization.current, addedOrUpdated, getEventsNavigationOptionsForFilter(addedOrUpdated)); + await redirectToEventsWithFilter(organization.current, addedOrUpdated, getDetailsNavigationOptions()); } async function handleError(problem: ProblemDetails) { diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/project/[projectId]/stacks/[stackId]/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/project/[projectId]/stacks/[stackId]/+page.svelte index bddebf6492..bb318d873c 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/project/[projectId]/stacks/[stackId]/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/project/[projectId]/stacks/[stackId]/+page.svelte @@ -14,7 +14,7 @@ import { getStackQuery } from '#features/stacks/api.svelte.ts'; import StackDetails from '#features/stacks/components/stack-details.svelte'; - import { getEventsNavigationOptionsForFilter, redirectToEventsWithFilter } from '../../../../redirect-to-events.svelte.ts'; + import { getDetailsNavigationOptions, redirectToEventsWithFilter } from '../../../../redirect-to-events.svelte.ts'; const projectId = $derived(page.params.projectId || ''); const stackId = $derived(page.params.stackId || ''); @@ -40,7 +40,7 @@ }); async function filterChanged(addedOrUpdated: IFilter) { - await redirectToEventsWithFilter(organization.current, addedOrUpdated, getEventsNavigationOptionsForFilter(addedOrUpdated)); + await redirectToEventsWithFilter(organization.current, addedOrUpdated, getDetailsNavigationOptions()); } async function handleDeleted() { diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.test.ts b/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.test.ts index a4516aa383..16f9cb1250 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.test.ts +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.test.ts @@ -99,6 +99,18 @@ describe('redirect-to-events', () => { expect(url.searchParams.has('filters')).toBe(false); }); + it('searches all time for drilldowns from a details page', async () => { + // Arrange + const { ALL_TIME_QUERY_VALUE, buildListPageHref, getDetailsNavigationOptions } = await import('./redirect-to-events.svelte'); + + // Act + const href = buildListPageHref('events', 'org-1', [new StringFilter('error.code', '500')], getDetailsNavigationOptions()); + const url = new URL(href, 'https://example.test'); + + // Assert + expect(url.searchParams.get('time')).toBe(ALL_TIME_QUERY_VALUE); + }); + it('uses relative duration shortcuts for time query parameters', async () => { // Arrange const { buildListPageHref, deserializeTimeQueryParam } = await import('./redirect-to-events.svelte'); diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.ts b/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.ts index 62b7ca77a1..ff851d0ea9 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.ts +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/redirect-to-events.svelte.ts @@ -103,6 +103,16 @@ export function deserializeTimeQueryParam(time: string): string { return trimmed; } +/** + * Drilldowns from a stack or event details page have no time range of their own, and the event they come from can be older + * than the list's default range. Search all time so the destination always includes the event the value came from. + */ +export function getDetailsNavigationOptions(): ListNavigationOptions { + return { + time: null + }; +} + /** * Stack filter drilldowns mean "show every event for this stack". * Clear any active date range so the destination cannot hide older stack events. diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/sessions/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/sessions/+page.svelte index d7bc404527..3289218985 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/sessions/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/sessions/+page.svelte @@ -60,7 +60,7 @@ import { fillDateSeries } from '#features/shared/utils/charts.ts'; import { parseDateMathRange, toDateMathRange } from '#features/shared/utils/datemath.ts'; import { ChangeType, type WebSocketMessageValue } from '#features/websockets/models.ts'; - import { DEFAULT_OFFSET } from '#shared/api/api.svelte.ts'; + import { DEFAULT_OFFSET, getDateHistogramTerm } from '#shared/api/api.svelte.ts'; import { createQueryParameters } from '#shared/query-params/index.ts'; import { @@ -859,7 +859,7 @@ enabled: () => hasPremiumFeatures && !isSavedViewRoutePending, params: { get aggregations() { - return `avg:value cardinality:user date:(date${DEFAULT_OFFSET ? `^${DEFAULT_OFFSET}` : ''} cardinality:user)`; + return `avg:value cardinality:user date:(${getDateHistogramTerm()} cardinality:user)`; }, get filter() { return eventsQueryParameters.filter; 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..93b4eb805e 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/+page.svelte @@ -72,7 +72,7 @@ import TableStacksBulkActionsDropdownMenu from '#features/stacks/components/stacks-bulk-actions-dropdown-menu.svelte'; import { StackStatus } from '#features/stacks/models.ts'; import { ChangeType, type WebSocketMessageValue } from '#features/websockets/models.ts'; - import { DEFAULT_OFFSET } from '#shared/api/api.svelte.ts'; + import { DEFAULT_OFFSET, getDateHistogramTerm } from '#shared/api/api.svelte.ts'; import { createQueryParameters } from '#shared/query-params/index.ts'; import { @@ -879,7 +879,7 @@ enabled: () => !isSavedViewRoutePending, params: { get aggregations() { - return `date:(date${DEFAULT_OFFSET ? `^${DEFAULT_OFFSET}` : ''} cardinality:stack sum:count~1) cardinality:stack terms:(first @include:true) sum:count~1`; + return `date:(${getDateHistogramTerm()} cardinality:stack sum:count~1) cardinality:stack terms:(first @include:true) sum:count~1`; }, get filter() { return eventsQueryParameters.filter; diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/+page.svelte index c7287d9cb0..111f252c08 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/+page.svelte @@ -16,12 +16,12 @@ import { organization } from '#features/organizations/context.svelte.ts'; import StackDetails from '#features/stacks/components/stack-details.svelte'; - import { getEventsNavigationOptionsForFilter, redirectToEventsWithFilter } from '../../redirect-to-events.svelte.ts'; + import { getDetailsNavigationOptions, redirectToEventsWithFilter } from '../../redirect-to-events.svelte.ts'; const stackId = $derived(page.params.stackId || ''); async function filterChanged(addedOrUpdated: IFilter) { - await redirectToEventsWithFilter(organization.current, addedOrUpdated, getEventsNavigationOptionsForFilter(addedOrUpdated)); + await redirectToEventsWithFilter(organization.current, addedOrUpdated, getDetailsNavigationOptions()); } async function handleDeleted() { diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/[action=stackaction]/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/[action=stackaction]/+page.svelte index fd083a2c84..c5587aef07 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/[action=stackaction]/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/[action=stackaction]/+page.svelte @@ -6,12 +6,12 @@ import type { PageProps } from './$types'; - import { getEventsNavigationOptionsForFilter, redirectToEventsWithFilter } from '../../../redirect-to-events.svelte.ts'; + import { getDetailsNavigationOptions, redirectToEventsWithFilter } from '../../../redirect-to-events.svelte.ts'; let { params }: PageProps = $props(); async function filterChanged(filter: IFilter) { - await redirectToEventsWithFilter(organization.current, filter, getEventsNavigationOptionsForFilter(filter)); + await redirectToEventsWithFilter(organization.current, filter, getDetailsNavigationOptions()); } diff --git a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/event/[eventId=objectid]/+page.svelte b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/event/[eventId=objectid]/+page.svelte index be0bb96c3c..a8943fc091 100644 --- a/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/event/[eventId=objectid]/+page.svelte +++ b/src/Exceptionless.Web/ClientApp/src/routes/(app)/stack/[stackId=objectid]/event/[eventId=objectid]/+page.svelte @@ -15,13 +15,13 @@ import { organization } from '#features/organizations/context.svelte.ts'; import StackDetails from '#features/stacks/components/stack-details.svelte'; - import { getEventsNavigationOptionsForFilter, redirectToEventsWithFilter } from '../../../../redirect-to-events.svelte.ts'; + import { getDetailsNavigationOptions, redirectToEventsWithFilter } from '../../../../redirect-to-events.svelte.ts'; const stackId = $derived(page.params.stackId || ''); const eventId = $derived(page.params.eventId || ''); async function filterChanged(addedOrUpdated: IFilter) { - await redirectToEventsWithFilter(organization.current, addedOrUpdated, getEventsNavigationOptionsForFilter(addedOrUpdated)); + await redirectToEventsWithFilter(organization.current, addedOrUpdated, getDetailsNavigationOptions()); } async function handleDeleted() { diff --git a/tests/Exceptionless.Tests/Search/PersistentEventQueryValidatorTests.cs b/tests/Exceptionless.Tests/Search/PersistentEventQueryValidatorTests.cs index 5323532380..64c9c815c5 100644 --- a/tests/Exceptionless.Tests/Search/PersistentEventQueryValidatorTests.cs +++ b/tests/Exceptionless.Tests/Search/PersistentEventQueryValidatorTests.cs @@ -130,6 +130,8 @@ public async Task CanProcessQueryAsync(string query, string expected, bool isVal [InlineData("date:(date cardinality:stack sum:count~1) cardinality:stack terms:(first @include:true) sum:count~1", true, false)] // dashboards [InlineData("date:(date cardinality:user sum:value avg:value sum:count~1) min:date max:date cardinality:user sum:count~1", true, false)] // stack dashboard [InlineData("avg:value cardinality:user date:(date cardinality:user)", true, false)] // session dashboard + [InlineData("date:(date^Europe/Amsterdam cardinality:stack sum:count~1) cardinality:stack terms:(first @include:true) sum:count~1", true, false)] // dashboards bucketed in a time zone + [InlineData("date:(date^America/Argentina/Buenos_Aires cardinality:user)", true, false)] [InlineData("date:(date~month terms:(project cardinality:stack terms:(first @include:true)) cardinality:stack terms:(first @include:true))", true, true)] // Breakdown of total events, new events and unique events per month by project public async Task CanProcessAggregationsAsync(string? query, bool isValid, bool usesPremiumFeatures) { diff --git a/tests/Exceptionless.Tests/Stats/AggregationTests.cs b/tests/Exceptionless.Tests/Stats/AggregationTests.cs index 1cba629e64..182c3119d9 100644 --- a/tests/Exceptionless.Tests/Stats/AggregationTests.cs +++ b/tests/Exceptionless.Tests/Stats/AggregationTests.cs @@ -82,6 +82,30 @@ public async Task CanGetDateHistogramWithCardinalityAggregationsAsync() } } + [Fact] + public async Task CanGetDateHistogramInTimeZoneAsync() + { + // Arrange + const int eventCount = 100; + await CreateDataAsync(eventCount, false); + var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Amsterdam"); + + // Act + // A time zone name keeps every day bucket on local midnight, including across daylight saving changes. + var result = await _eventRepository.CountAsync(q => q.Project(TestConstants.ProjectId).AggregationsExpression("date:(date~1d^Europe/Amsterdam cardinality:id)")); + + // Assert + var dateHistogram = result.Aggregations.DateHistogram("date_date"); + Assert.NotNull(dateHistogram); + Assert.NotEmpty(dateHistogram.Buckets); + Assert.Equal(eventCount, dateHistogram.Buckets.Sum(t => t.Total)); + Assert.All(dateHistogram.Buckets, bucket => + { + var local = TimeZoneInfo.ConvertTime(new DateTimeOffset(bucket.Date, TimeSpan.Zero), timeZone); + Assert.Equal(TimeSpan.Zero, local.TimeOfDay); + }); + } + [Fact] public async Task CanGetExcludedTermsAggregationsAsync() {