diff --git a/blade/components/dashboard/duration_chart.rs b/blade/components/dashboard/duration_chart.rs index 6c18728..1fbe8d7 100644 --- a/blade/components/dashboard/duration_chart.rs +++ b/blade/components/dashboard/duration_chart.rs @@ -1,8 +1,11 @@ use leptos::prelude::*; -use leptos_dom::helpers::window; use state::TestHistory; -use crate::{charts::linechart::LineChart, summaryheader::format_time}; +use crate::{ + charts::linechart::LineChart, + navigation::open_in_new_tab, + summaryheader::format_time, +}; pub fn format_unix(t: f64) -> String { let d = std::time::Duration::from_secs_f64(t); @@ -17,7 +20,7 @@ pub fn format_unix(t: f64) -> String { pub fn DurationChart(history: TestHistory) -> impl IntoView { let on_point_click = |point: state::TestHistoryPoint| { let link = format!("/invocation/{}", point.invocation_id); - window().open_with_url_and_target(&link, "_blank").unwrap(); + open_in_new_tab(&link); }; // Sort data so that successful tests are rendered first and failed tests last diff --git a/blade/components/dashboard/pass_fail_scatterplot.rs b/blade/components/dashboard/pass_fail_scatterplot.rs index ec4779c..7a1c8fb 100644 --- a/blade/components/dashboard/pass_fail_scatterplot.rs +++ b/blade/components/dashboard/pass_fail_scatterplot.rs @@ -1,15 +1,18 @@ use leptos::prelude::*; -use leptos_dom::helpers::window; use state::{Status, TestHistory}; -use crate::{charts::scatterplot::ScatterPlot, summaryheader::format_time}; +use crate::{ + charts::scatterplot::ScatterPlot, + navigation::open_in_new_tab, + summaryheader::format_time, +}; #[allow(non_snake_case)] #[component] pub fn PassFailScatterPlot(history: TestHistory) -> impl IntoView { let on_point_click = |point: state::TestHistoryPoint| { let link = format!("/invocation/{}", point.invocation_id); - window().location().set_href(&link).unwrap(); + open_in_new_tab(&link); }; view! { diff --git a/blade/components/dashboard/test_history_table.rs b/blade/components/dashboard/test_history_table.rs index dfcc1dc..ce05d61 100644 --- a/blade/components/dashboard/test_history_table.rs +++ b/blade/components/dashboard/test_history_table.rs @@ -1,8 +1,7 @@ use leptos::prelude::*; -use leptos_router::hooks::use_navigate; use state::{Status, TestHistory}; -use crate::summaryheader::format_time; +use crate::{navigation::open_in_new_tab, summaryheader::format_time}; #[derive(Debug, Clone)] struct RuntimeStats { @@ -140,9 +139,8 @@ pub fn TestHistoryTable(history: TestHistory) -> impl IntoView { diff --git a/blade/components/lib.rs b/blade/components/lib.rs index 2f95182..eef1d06 100644 --- a/blade/components/lib.rs +++ b/blade/components/lib.rs @@ -6,6 +6,7 @@ pub mod dashboard; pub mod list; pub mod measuretime; pub mod nav; +pub mod navigation; pub mod searchbar; pub mod shellout; pub mod statusicon; diff --git a/blade/components/navigation.rs b/blade/components/navigation.rs new file mode 100644 index 0000000..63deab7 --- /dev/null +++ b/blade/components/navigation.rs @@ -0,0 +1,4 @@ +use leptos_dom::helpers::window; + +/// Opens a URL in a new browser tab +pub fn open_in_new_tab(url: &str) { let _ = window().open_with_url_and_target(url, "_blank"); }