1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
use re_chunk::ChunkId;
use re_log_types::TableId;
use re_log_types::{ApplicationId, EntryId, StoreId};
use crate::{Item, RedapEntryKind, TableReference, viewer_url::EXAMPLES_ORIGIN};
/// What a redap entry is, and for a dataset which of its resources we show.
///
/// The server is the authority on this, see `re_protos`' `EntryKind`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum EntryKind {
Table,
Dataset(re_uri::DatasetResource),
}
/// What are we currently showing in the viewer?
///
/// A [`crate::viewer_url::ViewerUrl`] names a route as a URL, for sharing and history.
/// [`crate::viewer_url::ViewerUrl::from_route`] and
/// [`crate::viewer_url::ViewerUrl::to_route`] convert between the two.
///
/// The URL of each route is documented in `docs/content/reference/viewer/urls.md`.
/// Keep that page up to date when adding or changing a route.
#[derive(Clone, PartialEq, Eq)]
pub enum Route {
/// The settings dialog for application-wide configuration.
Settings {
/// What to return to when exiting this mode.
return_route: Box<Self>,
},
// TODO(isse): It would be nice to only switch to newly loaded items if we
// are on the loading screen for that specific item.
/// A loading screen to some source.
Loading(Box<re_log_channel::LogSource>),
/// Regular view of the local recordings, including the current recording's viewport.
///
/// This includes recordings we're streaming from a Redap server.
LocalRecording {
recording_id: StoreId,
},
LocalTable(TableId),
/// A dataset or table entry on a Redap server.
RedapEntry {
origin: re_uri::Origin,
entry_id: EntryId,
/// What the entry is, or `None` while we don't know.
///
/// A route built from an entry url or an [`Item`] has nothing to go by.
kind: Option<EntryKind>,
},
/// A folder in a Redap server's dataset hierarchy, named by a dotted path prefix.
RedapFolder {
origin: re_uri::Origin,
path: String,
},
/// The top-level view of a Redap Server.
///
/// Also used for the example/welcome page, using [`EXAMPLES_ORIGIN`].
RedapServer(re_uri::Origin),
/// A debug-view into the raw chunks of a store (recording or blueprint).
ChunkStoreBrowser {
/// The store to browse. `None` when opened from a route that has
/// no active store — the chunk browser's internal picker will
/// let the user choose one.
store_id: Option<StoreId>,
selected_chunk: Option<ChunkId>,
/// What to return to when exiting this mode.
return_route: Box<Self>,
},
}
impl std::fmt::Debug for Route {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Settings { .. } => write!(f, "Settings"),
Self::Loading(source) => write!(f, "Loading({source})"),
Self::LocalRecording { recording_id } => write!(f, "LocalRecording({recording_id:?})"),
Self::LocalTable(table_id) => write!(f, "LocalTable({table_id})"),
Self::RedapEntry {
origin,
entry_id,
kind,
} => write!(f, "RedapEntry({origin}, {entry_id}, {kind:?})"),
Self::RedapFolder { origin, path } => write!(f, "RedapFolder({origin}, {path})"),
Self::RedapServer(server) => write!(f, "RedapServer({server})"),
Self::ChunkStoreBrowser {
store_id,
selected_chunk,
..
} => {
write!(f, "ChunkStoreBrowser({store_id:?}, {selected_chunk:?})")
}
}
}
}
impl Route {
/// The example page / welcome screen
pub fn welcome_page() -> Self {
Self::RedapServer(EXAMPLES_ORIGIN.clone())
}
/// The settings page, which goes to `return_route` when closed.
///
/// If `return_route` is itself the settings page, it is returned unchanged,
/// so closing the settings never leads back to the settings.
pub fn settings(return_route: &Self) -> Self {
match return_route {
Self::Settings { .. } => return_route.clone(),
_ => Self::Settings {
return_route: Box::new(return_route.clone()),
},
}
}
/// The chunk store browser, which goes to `return_route` when closed.
///
/// If `return_route` is itself the chunk store browser, the new one goes where that one
/// goes, and keeps its store unless `store_id` names one.
pub fn chunk_store_browser(
return_route: &Self,
store_id: Option<StoreId>,
selected_chunk: Option<ChunkId>,
) -> Self {
match return_route {
Self::ChunkStoreBrowser {
store_id: browsed_store_id,
selected_chunk: _,
return_route: browser_return_route,
} => Self::ChunkStoreBrowser {
store_id: store_id.or_else(|| browsed_store_id.clone()),
selected_chunk,
return_route: browser_return_route.clone(),
},
_ => Self::ChunkStoreBrowser {
store_id,
selected_chunk,
return_route: Box::new(return_route.clone()),
},
}
}
/// The active recording [`StoreId`], if any.
pub fn recording_id(&self) -> Option<&StoreId> {
match self {
Self::LocalRecording { recording_id } => Some(recording_id),
Self::ChunkStoreBrowser { .. } // `store_id` of the chunk store browser is just what it shows and may be a blueprint!
| Self::Settings { .. }
| Self::Loading { .. }
| Self::LocalTable { .. }
| Self::RedapEntry { .. }
| Self::RedapFolder { .. }
| Self::RedapServer { .. } => None,
}
}
// TODO(andreas): remove this app-id centric world.
// We use this mostly for blueprint association which is very brittle and not very well defined right now. See also RR-3033.
pub fn app_id(&self) -> Option<&ApplicationId> {
match self {
Self::LocalRecording { recording_id } => Some(recording_id.application_id()),
Self::ChunkStoreBrowser { store_id, .. } => {
store_id.as_ref().map(StoreId::application_id)
}
Self::Settings { return_route } => return_route.app_id(),
Self::RedapServer(server) => {
if server == &*EXAMPLES_ORIGIN {
Some(crate::StoreHub::welcome_screen_app_id())
} else {
None
}
}
Self::Loading { .. }
| Self::LocalTable { .. }
| Self::RedapEntry { .. }
| Self::RedapFolder { .. } => None,
}
}
pub fn has_blueprint_panel(&self) -> bool {
!matches!(self, Self::Settings { .. } | Self::ChunkStoreBrowser { .. })
}
pub fn has_selection_panel(&self) -> bool {
matches!(self, Self::LocalRecording { .. })
}
pub fn has_time_panel(&self) -> bool {
matches!(self, Self::LocalRecording { .. })
}
/// The entry this route shows, if any.
pub fn entry_id(&self) -> Option<EntryId> {
match self {
Self::RedapEntry { entry_id, .. } => Some(*entry_id),
Self::Settings { .. }
| Self::Loading { .. }
| Self::LocalRecording { .. }
| Self::LocalTable { .. }
| Self::RedapFolder { .. }
| Self::RedapServer { .. }
| Self::ChunkStoreBrowser { .. } => None,
}
}
/// The server this route shows, if any.
///
/// A relative Rerun URI shown under this route resolves against it.
pub fn origin(&self) -> Option<&re_uri::Origin> {
match self {
Self::RedapEntry { origin, .. }
| Self::RedapFolder { origin, .. }
| Self::RedapServer(origin) => Some(origin),
Self::Settings { .. }
| Self::Loading { .. }
| Self::LocalRecording { .. }
| Self::LocalTable { .. }
| Self::ChunkStoreBrowser { .. } => None,
}
}
pub fn item(&self) -> Option<Item> {
match self {
Self::LocalRecording { recording_id } => Some(Item::StoreId(recording_id.clone())),
Self::ChunkStoreBrowser { store_id, .. } => {
store_id.as_ref().map(|id| Item::StoreId(id.clone()))
}
Self::LocalTable(table_id) => Some(Item::TableId(table_id.clone())),
Self::RedapEntry {
origin,
entry_id,
kind: _,
} => Some(Item::RedapEntry {
origin: origin.clone(),
kind: RedapEntryKind::Entry(*entry_id),
}),
Self::RedapFolder { origin, path } => Some(Item::RedapEntry {
origin: origin.clone(),
kind: RedapEntryKind::Folder(path.clone()),
}),
Self::RedapServer(origin) => Some(Item::RedapServer(origin.clone())),
Self::Settings { .. } | Self::Loading { .. } => None,
}
}
pub fn from_item(item: &crate::Item) -> Option<Self> {
match item {
Item::StoreId(store_id) => Some(Self::LocalRecording {
recording_id: store_id.clone(),
}),
Item::TableId(table_id) => Some(Self::LocalTable(table_id.clone())),
Item::RedapEntry { origin, kind } => match kind {
RedapEntryKind::Entry(entry_id) => Some(Self::RedapEntry {
origin: origin.clone(),
entry_id: *entry_id,
kind: None,
}),
RedapEntryKind::Folder(path) => Some(Self::RedapFolder {
origin: origin.clone(),
path: path.clone(),
}),
},
Item::RedapServer(origin) => Some(Self::RedapServer(origin.clone())),
Item::AppId { .. }
| Item::DataSource { .. }
| Item::InstancePath { .. }
| Item::ComponentPath { .. }
| Item::Container { .. }
| Item::View { .. }
| Item::DataResult { .. } => None,
}
}
}
impl From<re_uri::EntryUri> for Route {
fn from(uri: re_uri::EntryUri) -> Self {
Self::RedapEntry {
origin: uri.origin,
entry_id: uri.entry_id,
kind: None,
}
}
}
impl Route {
/// Returns the referenced table, if any.
pub fn table_reference(&self) -> Option<TableReference> {
match self {
Self::LocalTable(table_id) => Some(table_id.clone().into()),
// The same table backs every resource of a dataset.
Self::RedapEntry {
origin, entry_id, ..
} => Some(TableReference::RedapEntry {
origin: origin.clone(),
entry_id: *entry_id,
}),
Self::RedapServer(origin) => Some(TableReference::RedapServerEntries {
origin: origin.clone(),
}),
Self::Settings { .. }
| Self::Loading { .. }
| Self::LocalRecording { .. }
| Self::RedapFolder { .. }
| Self::ChunkStoreBrowser { .. } => None,
}
}
/// Returns the redap origin for the current route, if any.
///
/// Proxy origins are excluded because they are local and do not represent a remote server connection.
pub fn redap_origin(&self, store_hub: &crate::StoreHub) -> Option<re_uri::Origin> {
match self {
Self::LocalRecording { recording_id }
| Self::ChunkStoreBrowser {
store_id: Some(recording_id),
..
} => {
let db = store_hub.entity_db(recording_id)?;
Some(db.redap_uri()?.origin.clone())
}
Self::Settings { return_route }
| Self::ChunkStoreBrowser {
store_id: None,
return_route,
..
} => return_route.redap_origin(store_hub),
Self::Loading(log_source) => {
let uri = log_source.redap_uri()?;
// Don't return proxy origins — they are local.
if matches!(uri, re_uri::RedapUri::Proxy(_)) {
return None;
}
Some(uri.origin().clone())
}
Self::RedapEntry { origin, .. } | Self::RedapFolder { origin, .. } => {
Some(origin.clone())
}
Self::RedapServer(server) => Some(server.clone()),
Self::LocalTable { .. } => None,
}
}
}