-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist servers and allow adding/removing them from the UI (#9086)
### What With this PR, the servers are now persisted across viewer relaunch in the Redap browser, and the can be added and removed from the UI. The handling of the collection query management has been improved, so was its UI. Note: this makes a pre-existing `crossbeam-channel` dependency explicit. Add/remove buttons: <img width="307" alt="image" src="https://github.com/user-attachments/assets/1c971763-4f61-405a-b962-4e4843447717" /> <br/><br/> Add server modal: <img width="636" alt="image" src="https://github.com/user-attachments/assets/0f8fbf67-f439-4fb3-81a7-a84e5a51d720" />
- Loading branch information
Showing
18 changed files
with
596 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use re_ui::modal::{ModalHandler, ModalWrapper}; | ||
use re_uri::Scheme; | ||
|
||
use crate::context::Context; | ||
use crate::servers::Command; | ||
|
||
pub struct AddServerModal { | ||
modal: ModalHandler, | ||
|
||
scheme: Scheme, | ||
host: String, | ||
port: u16, | ||
} | ||
|
||
impl Default for AddServerModal { | ||
fn default() -> Self { | ||
Self { | ||
modal: Default::default(), | ||
scheme: Scheme::Rerun, | ||
host: String::new(), | ||
port: 443, | ||
} | ||
} | ||
} | ||
|
||
impl AddServerModal { | ||
pub fn open(&mut self) { | ||
self.scheme = Scheme::Rerun; | ||
self.port = 443; | ||
self.host = String::new(); | ||
|
||
self.modal.open(); | ||
} | ||
|
||
//TODO(ab): handle ESC and return | ||
pub fn ui(&mut self, ctx: &Context<'_>, ui: &egui::Ui) { | ||
self.modal.ui( | ||
ui.ctx(), | ||
|| ModalWrapper::new("Add Server"), | ||
|ui, keep_open| { | ||
ui.label("Scheme:"); | ||
|
||
egui::ComboBox::new("scheme", "") | ||
.selected_text(if self.scheme == Scheme::RerunHttp { | ||
"http" | ||
} else { | ||
"https" | ||
}) | ||
.show_ui(ui, |ui| { | ||
ui.selectable_value(&mut self.scheme, Scheme::RerunHttps, "https"); | ||
ui.selectable_value(&mut self.scheme, Scheme::RerunHttp, "http"); | ||
}); | ||
|
||
ui.add_space(14.0); | ||
|
||
ui.label("Host name:"); | ||
let host = url::Host::parse(&self.host); | ||
ui.scope(|ui| { | ||
// make field red if host is invalid | ||
if host.is_err() { | ||
ui.visuals_mut().widgets.active.bg_stroke = | ||
egui::Stroke::new(1.0, ui.visuals().error_fg_color); | ||
ui.visuals_mut().widgets.hovered.bg_stroke = | ||
egui::Stroke::new(1.0, ui.visuals().error_fg_color); | ||
ui.visuals_mut().widgets.inactive.bg_stroke = | ||
egui::Stroke::new(1.0, ui.visuals().error_fg_color); | ||
} | ||
ui.add(egui::TextEdit::singleline(&mut self.host).lock_focus(false)); | ||
}); | ||
|
||
ui.add_space(14.0); | ||
|
||
ui.label("Port:"); | ||
ui.add(egui::DragValue::new(&mut self.port)); | ||
|
||
let origin = host.map(|host| re_uri::Origin { | ||
scheme: self.scheme, | ||
host, | ||
port: self.port, | ||
}); | ||
|
||
ui.add_space(24.0); | ||
|
||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { | ||
if let Ok(origin) = origin { | ||
if ui.button("Add").clicked() { | ||
*keep_open = false; | ||
|
||
let _ = ctx.command_sender.send(Command::AddServer(origin)); | ||
} | ||
} else { | ||
ui.add_enabled(false, egui::Button::new("Add")); | ||
} | ||
|
||
if ui.button("Cancel").clicked() { | ||
*keep_open = false; | ||
} | ||
}); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.