Incident date filter matched nothing #168

Merged
logan merged 1 commits from fix/incident-date-filter into main 2026-09-24 01:15:32 -04:00
+8 -2
View File
@@ -42,11 +42,17 @@ export function useIncidents(limitCount = 100, dateFrom?: Date, dateTo?: Date) {
} }
// A range on the ordered field rides the existing org_id/started_at index. // A range on the ordered field rides the existing org_id/started_at index.
// Incident started_at is stored as a Python isoformat() STRING
// ("2026-09-20T12:00:00.123456+00:00", incident_correlator.py), not a
// Firestore timestamp — unlike calls. A Date bound compares by type and
// matches nothing, so the bounds go in as UTC ISO strings in the same
// shape, which then compare lexicographically in time order.
const isoBound = (ms: number) => new Date(ms).toISOString().replace("Z", "+00:00");
const q = query( const q = query(
collection(db, "incidents"), collection(db, "incidents"),
where("org_id", "==", orgId), where("org_id", "==", orgId),
...(dateFromMs != null ? [where("started_at", ">=", new Date(dateFromMs))] : []), ...(dateFromMs != null ? [where("started_at", ">=", isoBound(dateFromMs))] : []),
...(dateToMs != null ? [where("started_at", "<=", new Date(dateToMs))] : []), ...(dateToMs != null ? [where("started_at", "<=", isoBound(dateToMs))] : []),
orderBy("started_at", "desc"), orderBy("started_at", "desc"),
limit(limitCount) limit(limitCount)
); );