fix(ui): send explicit export range and whole-hour retention

This commit is contained in:
sam committed 2026-10-25 22:09:25 +11:00
1 parent 16ebc89c55
commit b1e99ecb9b
3 files changed
+108 -86

No files matched your search

+9 -7
View File
@@ -48,10 +48,10 @@ import AuditDetail from "./AuditDetail.vue";
import AuditExportMenu from "./AuditExportMenu.vue";
import AuditFilters from "./AuditFilters.vue";
import {
apiParams,
badgeFor,
dedupeRecords,
emptyMessage,
exportFilterParams,
hasFilters,
queryFromRoute,
readSavedViews,
@@ -75,7 +75,7 @@ const { records, facets, loading, loadingMore, error, moreError, hasMore } = sto
const query = computed(() => queryFromRoute(route.query));
const queryKey = computed(() => JSON.stringify(query.value));
const exportParams = computed(() => apiParams(query.value));
const exportParams = computed(() => exportFilterParams(query.value));
const columns: DataTableColumn<AuditRecord>[] = [
{ id: "event", label: "Event", fixed: true, class: "whitespace-normal" },
@@ -289,9 +289,10 @@ const retentionSaving = ref(false);
const retentionState = settings.stateFor(RETENTION_KIND);
function hoursFrom(value: unknown): number {
if (typeof value === "number") return value;
if (typeof value === "number")
return Number.isInteger(value) && value >= 0 ? value : 0;
if (typeof value !== "string") return 0;
const match = value.match(/^(\d+(?:\.\d+)?)h$/);
const match = value.trim().match(/^(\d+)h$/);
return match ? Number(match[1]) : 0;
}
@@ -308,9 +309,10 @@ async function openRetention(): Promise<void> {
async function saveRetention(): Promise<void> {
if (retentionSaving.value) return;
const hours = Number(retentionHours.value);
if (!Number.isFinite(hours) || hours < 0) {
retentionError.value = "Enter a number of hours.";
const raw = retentionHours.value.trim();
const hours = Number(raw);
if (!raw || !Number.isInteger(hours) || hours < 0) {
retentionError.value = "Enter a whole number of hours.";
return;
}
const state = retentionState;
+22 -2
View File
@@ -114,6 +114,9 @@ const PRESET_MS: Record<string, number> = {
/** The default window: what the time select shows when the URL is bare. */
export const DEFAULT_SINCE = "30d";
/** Export names its own start when the operator chose Any time. */
const EPOCH = "1970-01-01T00:00:00Z";
function text(value: LocationQuery[string] | undefined): string | undefined {
const first = Array.isArray(value) ? value[0] : value;
const trimmed = first == null ? "" : String(first).trim();
@@ -177,6 +180,10 @@ function instant(value: string | undefined): string | undefined {
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
}
function presetMs(since?: string): number {
return PRESET_MS[since ?? DEFAULT_SINCE] ?? PRESET_MS[DEFAULT_SINCE];
}
/** Resolves the explicit window once per load. The cursor is bound to these
* exact bounds, so pagination must not recompute them. */
export function timeBounds(
@@ -187,8 +194,7 @@ export function timeBounds(
const to = instant(query.to);
if (from || to) return { from, to };
if (query.since === "any") return {};
const ms = PRESET_MS[query.since ?? DEFAULT_SINCE] ?? PRESET_MS[DEFAULT_SINCE];
return { from: new Date(now - ms).toISOString() };
return { from: new Date(now - presetMs(query.since)).toISOString() };
}
/** The server filter for one page. Arrays become repeated parameters. */
@@ -209,6 +215,20 @@ export function apiParams(query: AuditQuery, now = Date.now()): QueryParams {
};
}
/** Export takes both ends explicitly: the server refuses to guess a window.
* An open start is the epoch sentinel, and both preset and default windows
* resolve to concrete timestamps. */
export function exportFilterParams(query: AuditQuery, now = Date.now()): QueryParams {
const params = apiParams(query, now);
const to = instant(query.to) ?? new Date(now).toISOString();
const from =
instant(query.from) ??
(query.since === "any"
? EPOCH
: new Date(now - presetMs(query.since)).toISOString());
return { ...params, from, to };
}
export function hasFilters(query: AuditQuery): boolean {
return !!(
query.q ||