From 2e1fc4767583f2d777cae6f2fc4eef5ac99a7086 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 26 Aug 2026 09:26:09 +0300 Subject: [PATCH] feat: hide empty event queue table, show count --- src/pages.rs | 220 +++++++++++++++++++++++++++------------------------ 1 file changed, 117 insertions(+), 103 deletions(-) diff --git a/src/pages.rs b/src/pages.rs index e52f42ed..4b9c19f9 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -200,113 +200,127 @@ impl PageData { fn event_queue(&self, doc: &mut ReportPage) { doc.h2("Event queue"); - let mut table = Element::new(Tag::Table) - .with_class("event-queue") - .with_child( - Element::new(Tag::Tr) - .with_child(Element::new(Tag::Th).with_text("Queue id")) - .with_child(Element::new(Tag::Th).with_text("Timestamp")) - .with_child(Element::new(Tag::Th).with_text("Event")), - ); - for event in self.events.iter() { - fn render_event( - repo: &RepoId, - alias: Option, - refname: &str, - commit: &Oid, - ) -> Element { - let alias = if let Some(alias) = alias { - Element::new(Tag::Span).with_child( - Element::new(Tag::Span) - .with_class("alias") - .with_text(&alias), - ) - } else { - Element::new(Tag::Span) + let queue_len = self.events.len(); + doc.push(Element::p().with_text(format!("{queue_len} events in queue."))); + if queue_len > 0 { + let mut table = Element::new(Tag::Table) + .with_class("event-queue") + .with_child( + Element::new(Tag::Tr) + .with_child(Element::new(Tag::Th).with_text("Queue id")) + .with_child(Element::new(Tag::Th).with_text("Timestamp")) + .with_child(Element::new(Tag::Th).with_text("Event")), + ); + for event in self.events.iter() { + let event_element = match event.event() { + CiEvent::V1(CiEventV1::Shutdown) => { + Element::new(Tag::Span).with_text("shutdown") + } + CiEvent::V1(CiEventV1::Terminate(_)) => { + Element::new(Tag::Span).with_text("terminate") + } + CiEvent::V1(CiEventV1::BranchCreated { + from_node: _, + repo, + branch, + tip, + }) => Self::render_event(repo, self.repo_alias(*repo), branch, tip), + CiEvent::V1(CiEventV1::BranchUpdated { + from_node: _, + repo, + branch, + tip, + old_tip: _, + }) => Self::render_event(repo, self.repo_alias(*repo), branch, tip), + CiEvent::V1(CiEventV1::BranchDeleted { + repo, branch, tip, .. + }) => Self::render_event(repo, self.repo_alias(*repo), branch, tip), + CiEvent::V1(CiEventV1::TagCreated { + from_node: _, + repo, + tag, + tip, + }) => Self::render_event(repo, self.repo_alias(*repo), tag.as_str(), tip), + CiEvent::V1(CiEventV1::TagUpdated { + from_node: _, + repo, + tag, + tip, + old_tip: _, + }) => Self::render_event(repo, self.repo_alias(*repo), tag.as_str(), tip), + CiEvent::V1(CiEventV1::TagDeleted { repo, tag, tip, .. }) => { + Self::render_event(repo, self.repo_alias(*repo), tag.as_str(), tip) + } + CiEvent::V1(CiEventV1::PatchCreated { + from_node: _, + repo, + patch, + new_tip, + }) => Self::render_event( + repo, + self.repo_alias(*repo), + &patch.to_string(), + new_tip, + ), + CiEvent::V1(CiEventV1::PatchUpdated { + from_node: _, + repo, + patch, + new_tip, + }) => Self::render_event( + repo, + self.repo_alias(*repo), + &patch.to_string(), + new_tip, + ), + CiEvent::V1(CiEventV1::CanonicalRefUpdated { + from_node: _, + repo, + refname, + target, + }) => { + Self::render_event(repo, self.repo_alias(*repo), refname.as_str(), target) + } }; - Element::new(Tag::Span) - .with_child(alias) - .with_child(Element::new(Tag::Br)) - .with_child( - Element::new(Tag::Span) - .with_class("repoid") - .with_text(repo.to_string()), - ) - .with_child(Element::new(Tag::Br)) - .with_child(Element::new(Tag::Span).with_class("ref").with_text(refname)) - .with_child(Element::new(Tag::Br)) - .with_child( - Element::new(Tag::Span) - .with_class("commit") - .with_text(commit.to_string()), - ) + + table.push_child( + Element::new(Tag::Tr) + .with_child(Element::new(Tag::Td).with_text(event.id().to_string())) + .with_child(Element::new(Tag::Td).with_text(event.timestamp())) + .with_child(Element::new(Tag::Td).with_child(event_element)), + ); } - let event_element = match event.event() { - CiEvent::V1(CiEventV1::Shutdown) => Element::new(Tag::Span).with_text("shutdown"), - CiEvent::V1(CiEventV1::Terminate(_)) => { - Element::new(Tag::Span).with_text("terminate") - } - CiEvent::V1(CiEventV1::BranchCreated { - from_node: _, - repo, - branch, - tip, - }) => render_event(repo, self.repo_alias(*repo), branch, tip), - CiEvent::V1(CiEventV1::BranchUpdated { - from_node: _, - repo, - branch, - tip, - old_tip: _, - }) => render_event(repo, self.repo_alias(*repo), branch, tip), - CiEvent::V1(CiEventV1::BranchDeleted { - repo, branch, tip, .. - }) => render_event(repo, self.repo_alias(*repo), branch, tip), - CiEvent::V1(CiEventV1::TagCreated { - from_node: _, - repo, - tag, - tip, - }) => render_event(repo, self.repo_alias(*repo), tag.as_str(), tip), - CiEvent::V1(CiEventV1::TagUpdated { - from_node: _, - repo, - tag, - tip, - old_tip: _, - }) => render_event(repo, self.repo_alias(*repo), tag.as_str(), tip), - CiEvent::V1(CiEventV1::TagDeleted { repo, tag, tip, .. }) => { - render_event(repo, self.repo_alias(*repo), tag.as_str(), tip) - } - CiEvent::V1(CiEventV1::PatchCreated { - from_node: _, - repo, - patch, - new_tip, - }) => render_event(repo, self.repo_alias(*repo), &patch.to_string(), new_tip), - CiEvent::V1(CiEventV1::PatchUpdated { - from_node: _, - repo, - patch, - new_tip, - }) => render_event(repo, self.repo_alias(*repo), &patch.to_string(), new_tip), - CiEvent::V1(CiEventV1::CanonicalRefUpdated { - from_node: _, - repo, - refname, - target, - }) => render_event(repo, self.repo_alias(*repo), refname.as_str(), target), - }; - - table.push_child( - Element::new(Tag::Tr) - .with_child(Element::new(Tag::Td).with_text(event.id().to_string())) - .with_child(Element::new(Tag::Td).with_text(event.timestamp())) - .with_child(Element::new(Tag::Td).with_child(event_element)), - ); + doc.push(table); } - doc.push(table); + } + + fn render_event(repo: &RepoId, alias: Option, refname: &str, commit: &Oid) -> Element { + let alias = if let Some(alias) = alias { + Element::new(Tag::Span).with_child( + Element::new(Tag::Span) + .with_class("alias") + .with_text(&alias), + ) + } else { + Element::new(Tag::Span) + }; + Element::new(Tag::Span) + .with_child(alias) + .with_child(Element::new(Tag::Br)) + .with_child( + Element::new(Tag::Span) + .with_class("repoid") + .with_text(repo.to_string()), + ) + .with_child(Element::new(Tag::Br)) + .with_child(Element::new(Tag::Span).with_class("ref").with_text(refname)) + .with_child(Element::new(Tag::Br)) + .with_child( + Element::new(Tag::Span) + .with_class("commit") + .with_text(commit.to_string()), + ) } fn recent_status(&self, doc: &mut ReportPage) -> Result<(), PageError> {