From c3474bcf2c0945e83f6bb6b242e6afacf5dc38ec Mon Sep 17 00:00:00 2001 From: dmackdev Date: Sat, 21 Oct 2023 13:23:30 +0100 Subject: [PATCH 1/5] Add combo box for message search mode. --- pubsubman/src/ui/messages_view.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pubsubman/src/ui/messages_view.rs b/pubsubman/src/ui/messages_view.rs index f83d323..42e2cad 100644 --- a/pubsubman/src/ui/messages_view.rs +++ b/pubsubman/src/ui/messages_view.rs @@ -19,6 +19,7 @@ pub struct MessagesView { pub stream_messages_enabled: bool, pub stream_messages_cancel_token: Option, pub search_query: String, + search_mode: SearchMode, } impl MessagesView { @@ -117,6 +118,22 @@ impl MessagesView { search_query_changed = true; } + egui::ComboBox::from_id_source("search_mode_combo_box") + .selected_text(format!("{:?}", self.search_mode)) + .width(50.0) + .show_ui(ui, |ui| { + ui.selectable_value( + &mut self.search_mode, + SearchMode::Data, + "Data", + ); + ui.selectable_value( + &mut self.search_mode, + SearchMode::Id, + "Id", + ); + }); + ui.visuals_mut().widgets.inactive.weak_bg_fill = egui::Color32::from_gray(32); @@ -232,3 +249,10 @@ fn render_messages_table<'a, I>( } }); } + +#[derive(Default, Debug, PartialEq, Eq)] +enum SearchMode { + #[default] + Data, + Id, +} From 01d4570545115cce3131f225f6c8c3ee75e40aa5 Mon Sep 17 00:00:00 2001 From: dmackdev Date: Sat, 21 Oct 2023 13:45:02 +0100 Subject: [PATCH 2/5] Added filtering of messages based on search mode. Resetting json tree expanded nodes when it changes. --- pubsubman/src/ui/messages_view.rs | 75 ++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/pubsubman/src/ui/messages_view.rs b/pubsubman/src/ui/messages_view.rs index 42e2cad..e4e5f54 100644 --- a/pubsubman/src/ui/messages_view.rs +++ b/pubsubman/src/ui/messages_view.rs @@ -35,9 +35,14 @@ impl MessagesView { on_message_id_click: impl FnMut(usize), ) { let search_query = self.search_query.to_ascii_lowercase(); - let filtered_messages = messages - .iter() - .filter(|msg| msg.data.to_ascii_lowercase().contains(&search_query)); + let search_mode = self.search_mode; + let filtered_messages = messages.iter().filter(|msg| { + let source = match search_mode { + SearchMode::Data => &msg.data, + SearchMode::Id => &msg.id, + }; + source.to_ascii_lowercase().contains(&search_query) + }); egui::TopBottomPanel::top("messages_top_panel") .frame(egui::Frame::side_top_panel(ui.style()).inner_margin(8.0)) @@ -103,7 +108,7 @@ impl MessagesView { ui.label("Pull or Stream new messages to retrieve the latest."); }); } else { - let mut search_query_changed = false; + let mut should_reset_expanded = false; ui.horizontal(|ui| { ui.visuals_mut().extreme_bg_color = egui::Color32::from_gray(32); @@ -115,31 +120,41 @@ impl MessagesView { ); if search_query_edit_response.changed() { - search_query_changed = true; + should_reset_expanded = true; } - egui::ComboBox::from_id_source("search_mode_combo_box") - .selected_text(format!("{:?}", self.search_mode)) - .width(50.0) - .show_ui(ui, |ui| { - ui.selectable_value( - &mut self.search_mode, - SearchMode::Data, - "Data", - ); - ui.selectable_value( - &mut self.search_mode, - SearchMode::Id, - "Id", - ); - }); + let search_mode_changed = + egui::ComboBox::from_id_source("search_mode_combo_box") + .selected_text(format!("{:?}", self.search_mode)) + .width(50.0) + .show_ui(ui, |ui| { + ui.selectable_value( + &mut self.search_mode, + SearchMode::Data, + "Data", + ) + .changed() + || ui + .selectable_value( + &mut self.search_mode, + SearchMode::Id, + "Id", + ) + .changed() + }) + .inner + .unwrap_or_default(); + + if search_mode_changed { + should_reset_expanded = true; + } ui.visuals_mut().widgets.inactive.weak_bg_fill = egui::Color32::from_gray(32); if ui.button("✖").clicked() && !self.search_query.is_empty() { self.search_query.clear(); - search_query_changed = true; + should_reset_expanded = true; } ui.with_layout( @@ -171,7 +186,8 @@ impl MessagesView { column_settings, filtered_messages, &search_query, - search_query_changed, + should_reset_expanded, + self.search_mode, on_message_id_click, ); }); @@ -181,13 +197,15 @@ impl MessagesView { } } +#[allow(clippy::too_many_arguments)] fn render_messages_table<'a, I>( ui: &mut egui::Ui, selected_topic: &TopicName, column_settings: &ColumnSettings, messages: I, search_term: &str, - search_query_changed: bool, + should_reset_expanded: bool, + search_mode: SearchMode, mut on_message_id_click: impl FnMut(usize), ) where I: Iterator, @@ -236,12 +254,17 @@ fn render_messages_table<'a, I>( } } + let default_expand = match search_mode { + SearchMode::Data => DefaultExpand::SearchResults(search_term), + SearchMode::Id => DefaultExpand::None, + }; + let response = JsonTree::new(&message.id, &message.data_json) - .default_expand(DefaultExpand::SearchResults(search_term)) + .default_expand(default_expand) .response_callback(show_json_context_menu(&message.data_json)) .show(ui); - if search_query_changed { + if should_reset_expanded { response.reset_expanded(ui); } @@ -250,7 +273,7 @@ fn render_messages_table<'a, I>( }); } -#[derive(Default, Debug, PartialEq, Eq)] +#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)] enum SearchMode { #[default] Data, From cb166a9b441876ebd8029b03aaf615e7d5f069dd Mon Sep 17 00:00:00 2001 From: dmackdev Date: Tue, 24 Oct 2023 18:55:32 +0100 Subject: [PATCH 3/5] Format ID option for combo box as uppercase. --- pubsubman/src/ui/messages_view.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pubsubman/src/ui/messages_view.rs b/pubsubman/src/ui/messages_view.rs index e4e5f54..2a636bc 100644 --- a/pubsubman/src/ui/messages_view.rs +++ b/pubsubman/src/ui/messages_view.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use chrono::{DateTime, Local}; use egui_json_tree::{DefaultExpand, JsonTree}; use pubsubman_backend::{ @@ -125,7 +127,7 @@ impl MessagesView { let search_mode_changed = egui::ComboBox::from_id_source("search_mode_combo_box") - .selected_text(format!("{:?}", self.search_mode)) + .selected_text(format!("{}", self.search_mode)) .width(50.0) .show_ui(ui, |ui| { ui.selectable_value( @@ -138,7 +140,7 @@ impl MessagesView { .selectable_value( &mut self.search_mode, SearchMode::Id, - "Id", + "ID", ) .changed() }) @@ -279,3 +281,12 @@ enum SearchMode { Data, Id, } + +impl Display for SearchMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SearchMode::Data => write!(f, "Data"), + SearchMode::Id => write!(f, "ID"), + } + } +} From 093c4dc90abc68356d4a8eed7706f2aa5d90ccc4 Mon Sep 17 00:00:00 2001 From: dmackdev Date: Tue, 24 Oct 2023 19:07:29 +0100 Subject: [PATCH 4/5] Prevent duplicate GH Workflows runs on pull requests. --- .github/workflows/rust.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 90dba6c..86bef6f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,7 +1,11 @@ -on: [push, pull_request] - name: CI +on: + push: + branches: + - master + pull_request: + env: # This is required to enable the web_sys clipboard API which egui_web uses # https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html From 7c0f46806300ca32dfd61655c686b0004d8ae878 Mon Sep 17 00:00:00 2001 From: dmackdev Date: Tue, 24 Oct 2023 19:12:23 +0100 Subject: [PATCH 5/5] Made search_query private. --- pubsubman/src/ui/messages_view.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubsubman/src/ui/messages_view.rs b/pubsubman/src/ui/messages_view.rs index 2a636bc..318353e 100644 --- a/pubsubman/src/ui/messages_view.rs +++ b/pubsubman/src/ui/messages_view.rs @@ -20,7 +20,7 @@ use super::show_json_context_menu; pub struct MessagesView { pub stream_messages_enabled: bool, pub stream_messages_cancel_token: Option, - pub search_query: String, + search_query: String, search_mode: SearchMode, }