Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist servers and allow adding/removing them from the UI #9086

Merged
merged 17 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6436,10 +6436,10 @@ version = "0.23.0-alpha.1+dev"
dependencies = [
"ahash",
"arrow",
"crossbeam-channel",
"egui",
"egui_table",
"once_cell",
"parking_lot",
"re_arrow_util",
"re_grpc_client",
"re_log",
Expand All @@ -6452,10 +6452,12 @@ dependencies = [
"re_uri",
"re_view_dataframe",
"re_viewer_context",
"serde",
"thiserror 1.0.65",
"tokio-stream",
"tonic",
"tonic-web-wasm-client",
"url",
]

[[package]]
Expand Down Expand Up @@ -6834,6 +6836,7 @@ dependencies = [
name = "re_uri"
version = "0.23.0-alpha.1+dev"
dependencies = [
"serde",
"thiserror 1.0.65",
"url",
]
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const_format = "0.2"
convert_case = "0.6"
criterion = "0.5"
crossbeam = "0.8"
crossbeam-channel = "0.5"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was already in the dependency tree

directories = "5"
document-features = "0.2.8"
econtext = "0.2" # Prints error contexts on crashes
Expand Down
3 changes: 2 additions & 1 deletion crates/store/re_data_source/src/data_source.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::FileContents;
use re_log::debug;
use re_log_types::LogMsg;
use re_smart_channel::{Receiver, SmartChannelSource, SmartMessageSource};

use crate::FileContents;

#[cfg(not(target_arch = "wasm32"))]
use anyhow::Context as _;

Expand Down
2 changes: 1 addition & 1 deletion crates/top/rerun/src/commands/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ fn run_impl(
app.set_examples_manifest_url(url);
}
for endpoint in catalog_endpoints {
app.fetch_catalog(endpoint);
app.add_redap_server(endpoint);
}
Box::new(app)
}),
Expand Down
3 changes: 2 additions & 1 deletion crates/utils/re_uri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ version.workspace = true
workspace = true

[dependencies]
serde.workspace = true
thiserror.workspace = true
url.workspace = true
url = { workspace = true, features = ["serde"] }
8 changes: 6 additions & 2 deletions crates/utils/re_uri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub use self::{
/// The different schemes supported by Rerun.
///
/// We support `rerun`, `rerun+http`, and `rerun+https`.
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
#[derive(
Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
)]
pub enum Scheme {
Rerun,
RerunHttp,
Expand Down Expand Up @@ -76,7 +78,9 @@ impl TryFrom<&str> for Scheme {
}
}

#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[derive(
Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
)]
pub struct Origin {
pub scheme: Scheme,
pub host: url::Host<String>,
Expand Down
4 changes: 3 additions & 1 deletion crates/viewer/re_redap_browser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ re_uri.workspace = true

ahash.workspace = true
arrow.workspace = true
crossbeam-channel.workspace = true
egui.workspace = true
egui_table.workspace = true
once_cell.workspace = true
parking_lot.workspace = true
serde.workspace = true
thiserror.workspace = true
tokio-stream.workspace = true
url.workspace = true

# Native dependencies:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
102 changes: 102 additions & 0 deletions crates/viewer/re_redap_browser/src/add_server_modal.rs
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;
}
});
},
);
}
}
25 changes: 12 additions & 13 deletions crates/viewer/re_redap_browser/src/collection_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use re_ui::UiExt as _;
use re_view_dataframe::display_record_batch::{DisplayRecordBatch, DisplayRecordBatchError};
use re_viewer_context::ViewerContext;

use super::servers::{Command, RecordingCollection};
use super::servers::Command;
use crate::collections::Collection;
use crate::context::Context;

#[derive(thiserror::Error, Debug)]
enum CollectionUiError {
Expand All @@ -25,24 +27,23 @@ enum CollectionUiError {
}

pub fn collection_ui(
ctx: &ViewerContext<'_>,
viewer_ctx: &ViewerContext<'_>,
ctx: &Context<'_>,
ui: &mut egui::Ui,
origin: &re_uri::Origin,
collection: &RecordingCollection,
) -> Vec<Command> {
let mut commands = vec![];

collection: &Collection,
) {
let sorbet_schema = {
let Some(sorbet_batch) = collection.collection.first() else {
ui.label(egui::RichText::new("This collection is empty").italics());
return commands;
return;
};

sorbet_batch.sorbet_schema()
};

// The table id mainly drives column widths, along with the id of each column.
let table_id_salt = collection.collection_id.with("__collection_table__");
let table_id_salt = egui::Id::new(collection.collection_id).with("__collection_table__");

let num_rows = collection
.collection
Expand All @@ -69,19 +70,19 @@ pub fn collection_ui(
Err(err) => {
//TODO(ab): better error handling?
ui.error_label(err.to_string());
return commands;
return;
}
};

let mut table_delegate = CollectionTableDelegate {
ctx,
ctx: viewer_ctx,
display_record_batches: &display_record_batches,
selected_columns: &columns,
};

egui::Frame::new().inner_margin(5.0).show(ui, |ui| {
if ui.button("Close").clicked() {
commands.push(Command::DeselectCollection);
let _ = ctx.command_sender.send(Command::DeselectCollection);
}

egui_table::Table::new()
Expand All @@ -102,8 +103,6 @@ pub fn collection_ui(
.num_rows(num_rows)
.show(ui, &mut table_delegate);
});

commands
}

/// Descriptor for the generated `RecordingUri` component.
Expand Down
Loading