Skip to content

Commit af3312a

Browse files
authored
Add refresh button to the collection UI (rerun-io#9145)
title <img width="585" alt="image" src="https://github.com/user-attachments/assets/cee7913a-b5d8-4be6-80a6-3cb557524d59" />
1 parent 12c4616 commit af3312a

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

crates/viewer/re_redap_browser/src/collection_ui.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,17 @@ pub fn collection_ui(
8181
};
8282

8383
egui::Frame::new().inner_margin(5.0).show(ui, |ui| {
84-
if ui.button("Close").clicked() {
85-
let _ = ctx.command_sender.send(Command::DeselectCollection);
86-
}
84+
ui.horizontal(|ui| {
85+
if ui.button("Close").clicked() {
86+
let _ = ctx.command_sender.send(Command::DeselectCollection);
87+
}
88+
89+
if ui.button("Refresh").clicked() {
90+
let _ = ctx
91+
.command_sender
92+
.send(Command::RefreshCollection(origin.clone()));
93+
}
94+
});
8795

8896
egui_table::Table::new()
8997
.id_salt(table_id_salt)

crates/viewer/re_redap_browser/src/collections.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,20 @@ pub struct Collections {
3434
}
3535

3636
impl Collections {
37-
pub fn add(
37+
pub fn fetch(
3838
&mut self,
3939
runtime: &AsyncRuntimeHandle,
4040
egui_ctx: &egui::Context,
4141
origin: re_uri::Origin,
4242
) {
43-
//TODO(ab): should we return error if the requested collection already exists? Or maybe just
44-
// query it again.
45-
self.collections.entry(origin.clone()).or_insert_with(|| {
43+
self.collections.insert(
44+
origin.clone(),
4645
RequestedObject::new_with_repaint(
4746
runtime,
4847
egui_ctx.clone(),
4948
stream_catalog_async(origin),
50-
)
51-
});
49+
),
50+
);
5251
}
5352

5453
/// Convert all completed queries into proper collections.

crates/viewer/re_redap_browser/src/servers.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ impl Server {
2121
let mut collections = Collections::default();
2222

2323
//TODO(ab): For now, we just auto-download the default collection
24-
collections.add(runtime, egui_ctx, origin.clone());
24+
collections.fetch(runtime, egui_ctx, origin.clone());
2525

2626
Self {
2727
origin,
2828
collections,
2929
}
3030
}
3131

32+
//TODO(ab): this should take a collection id in the future
33+
fn refresh_default_collection(
34+
&mut self,
35+
runtime: &AsyncRuntimeHandle,
36+
egui_ctx: &egui::Context,
37+
) {
38+
self.collections
39+
.fetch(runtime, egui_ctx, self.origin.clone());
40+
}
41+
3242
fn on_frame_start(&mut self) {
3343
self.collections.on_frame_start();
3444
}
@@ -131,6 +141,7 @@ pub enum Command {
131141
DeselectCollection,
132142
AddServer(re_uri::Origin),
133143
RemoveServer(re_uri::Origin),
144+
RefreshCollection(re_uri::Origin),
134145
}
135146

136147
impl RedapServers {
@@ -183,6 +194,12 @@ impl RedapServers {
183194
Command::RemoveServer(origin) => {
184195
self.servers.remove(&origin);
185196
}
197+
198+
Command::RefreshCollection(origin) => {
199+
self.servers.entry(origin).and_modify(|server| {
200+
server.refresh_default_collection(runtime, egui_ctx);
201+
});
202+
}
186203
}
187204
}
188205

0 commit comments

Comments
 (0)