Skip to content

Commit f302874

Browse files
committed
Only show share timestamp when it's supported
1 parent a66cc7a commit f302874

File tree

2 files changed

+71
-14
lines changed

2 files changed

+71
-14
lines changed

crates/viewer/re_time_panel/src/time_panel.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,21 +1784,24 @@ fn copy_timeline_properties_context_menu(
17841784
time_ctrl: &TimeControl,
17851785
hovered_time: TimeReal,
17861786
) {
1787-
// TODO: Add shortcuts for these
1788-
if let Some(selected_time_range) = time_ctrl.active_loop_selection()
1789-
&& selected_time_range.contains(hovered_time)
1790-
{
1791-
if ui.button("Copy link to trimmed range").clicked() {
1792-
ctx.command_sender()
1793-
.send_system(UrlContext::from_context(ctx).into_copy_cmd());
1787+
let url_context = UrlContext::from_context(ctx);
1788+
if let Some(url_features) = url_context.features(ctx.storage_context.hub) {
1789+
if let Some(selected_time_range) = time_ctrl.active_loop_selection()
1790+
&& selected_time_range.contains(hovered_time)
1791+
&& url_features.time_range
1792+
{
1793+
if ui.button("Copy link to trimmed range").clicked() {
1794+
ctx.command_sender()
1795+
.send_system(url_context.without_timestamp().into_copy_cmd());
1796+
}
1797+
} else if url_features.fragment && ui.button("Copy link to timestamp").clicked() {
1798+
ctx.command_sender().send_system(
1799+
UrlContext::from_context(ctx)
1800+
.without_time_range()
1801+
.with_timestamp(time_ctrl.timeline(), hovered_time.into())
1802+
.into_copy_cmd(),
1803+
);
17941804
}
1795-
} else if ui.button("Copy link to timestamp").clicked() {
1796-
ctx.command_sender().send_system(
1797-
UrlContext::from_context(ctx)
1798-
.without_time_range()
1799-
.with_timestamp(time_ctrl.timeline(), hovered_time.into())
1800-
.into_copy_cmd(),
1801-
);
18021805
}
18031806

18041807
if ui.button("Copy timestamp").clicked() {

crates/viewer/re_viewer_context/src/url_context.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use re_global_context::{DisplayMode, SystemCommand};
2+
use re_smart_channel::SmartChannelSource;
23

34
use crate::ViewerContext;
45

@@ -12,7 +13,60 @@ pub struct UrlContext {
1213
pub fragment: re_uri::Fragment,
1314
}
1415

16+
#[derive(Default, Clone, Copy)]
17+
pub struct UrlFeatures {
18+
pub time_range: bool,
19+
pub fragment: bool,
20+
}
21+
1522
impl UrlContext {
23+
/// Information about what this url can do, can be used to hide UI for
24+
/// sharing when we know it won't work.
25+
///
26+
/// This should be kept up to date with what `ViewerOpenUrl::new` does
27+
// TODO(isse): I don't really like how this has to be kept up to date manually with
28+
// `ViewerOpenUrl`, would be nice to consolidate.
29+
pub fn features(&self, store_hub: &crate::StoreHub) -> Option<UrlFeatures> {
30+
match &self.display_mode {
31+
DisplayMode::Settings | DisplayMode::LocalTable(_) | DisplayMode::ChunkStoreBrowser => {
32+
None
33+
}
34+
35+
DisplayMode::LocalRecordings => {
36+
let active_recording = store_hub.active_recording()?;
37+
let data_source = active_recording.data_source.as_ref()?;
38+
match data_source {
39+
SmartChannelSource::RrdHttpStream { .. }
40+
| SmartChannelSource::RrdWebEventListener
41+
| SmartChannelSource::MessageProxy(_) => Some(UrlFeatures::default()),
42+
43+
SmartChannelSource::RedapGrpcStream { .. } => Some(UrlFeatures {
44+
time_range: true,
45+
fragment: true,
46+
}),
47+
48+
SmartChannelSource::File(_) => {
49+
#[cfg(not(target_arch = "wasm32"))]
50+
{
51+
Some(UrlFeatures::default())
52+
}
53+
#[cfg(target_arch = "wasm32")]
54+
{
55+
None
56+
}
57+
}
58+
59+
SmartChannelSource::JsChannel { .. }
60+
| SmartChannelSource::Sdk
61+
| SmartChannelSource::Stdin => None,
62+
}
63+
}
64+
DisplayMode::RedapServer(_) | DisplayMode::RedapEntry(_) => {
65+
Some(UrlFeatures::default())
66+
}
67+
}
68+
}
69+
1670
/// Create a url for a certain display mode.
1771
///
1872
/// Not all display modes lead to valid URLs.

0 commit comments

Comments
 (0)