From 461d6cfa48ee2bebcc6e71653be77f9e4fc572e9 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Fri, 27 Dec 2024 10:46:57 -0600 Subject: [PATCH] elastic: fix events pagination The previous commit only fixed event pagination for SQLite. The search parameters were not being set for Elastic. Also, cleanup the URLs in event pagination by removing characters that would get escaped in the URL. --- src/datetime.rs | 5 ++++- src/elastic/eventrepo/events.rs | 4 ++-- webapp/src/Events.tsx | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/datetime.rs b/src/datetime.rs index 38e97fb2..f0b99641 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -225,7 +225,10 @@ mod test { #[test] fn test_parse() { - let _ts = parse("2024-05-16T16:08:17.876423-0600", None).unwrap(); + let ts0 = parse("2024-05-16T16:08:17.876423-0600", None).unwrap(); + let ts1 = parse("20240516T160817.876423-0600", None).unwrap(); + assert_eq!(ts0, ts1); + let _ts = parse("2023-01-01T01:02:00.0+0000", None).unwrap(); let _ts = parse("2024-05-16T16:08:17.876423+0600", None).unwrap(); let _ts = parse("2024-05-16T16:08:17.876423Z", None).unwrap(); diff --git a/src/elastic/eventrepo/events.rs b/src/elastic/eventrepo/events.rs index 67173433..d7f6f2cd 100644 --- a/src/elastic/eventrepo/events.rs +++ b/src/elastic/eventrepo/events.rs @@ -32,11 +32,11 @@ impl ElasticEventRepo { ); if let Some(ts) = params.from { - warn!("Unexpected min_timestamp of {}", &ts); + filters.push(request::timestamp_gte_filter(&ts)); } if let Some(ts) = params.to { - warn!("Unexpected max_timestamp of {}", &ts); + filters.push(request::timestamp_lte_filter(&ts)); } let sort_by = params.sort_by.unwrap_or_else(|| "@timestamp".to_string()); diff --git a/webapp/src/Events.tsx b/webapp/src/Events.tsx index f9bb0e81..2c09c48d 100644 --- a/webapp/src/Events.tsx +++ b/webapp/src/Events.tsx @@ -205,7 +205,10 @@ export function Events() { } function gotoNewer() { - const timestamp = events()[0]._source["@timestamp"]; + // Removing "-" and ":" are for URL tidyness, but don't matter. + const timestamp = events()[0] + ._source["@timestamp"].replace(/(\d{4})-(\d{2})-(\d{2})/, "$1$2$3") + .replaceAll(":", ""); setSearchParams({ order: "asc", from: timestamp, @@ -214,7 +217,13 @@ export function Events() { } function gotoOlder() { - const timestamp = events()[events().length - 1]._source["@timestamp"]; + // Removing "-" and ":" are for URL tidyness, but don't matter. + const timestamp = events() + [events().length - 1]._source["@timestamp"].replace( + /(\d{4})-(\d{2})-(\d{2})/, + "$1$2$3" + ) + .replaceAll(":", ""); setSearchParams({ order: undefined, from: undefined, @@ -225,7 +234,7 @@ export function Events() { function gotoNewest() { setSearchParams({ order: undefined, - to: undefined, + max_timestamp: undefined, from: undefined, }); }