Skip to content

Commit b312758

Browse files
authored
open dashboard links in new tab (#39)
1 parent bf008ff commit b312758

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

blade/components/dashboard/duration_chart.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use leptos::prelude::*;
2-
use leptos_dom::helpers::window;
32
use state::TestHistory;
43

5-
use crate::{charts::linechart::LineChart, summaryheader::format_time};
4+
use crate::{
5+
charts::linechart::LineChart,
6+
navigation::open_in_new_tab,
7+
summaryheader::format_time,
8+
};
69

710
pub fn format_unix(t: f64) -> String {
811
let d = std::time::Duration::from_secs_f64(t);
@@ -17,7 +20,7 @@ pub fn format_unix(t: f64) -> String {
1720
pub fn DurationChart(history: TestHistory) -> impl IntoView {
1821
let on_point_click = |point: state::TestHistoryPoint| {
1922
let link = format!("/invocation/{}", point.invocation_id);
20-
window().open_with_url_and_target(&link, "_blank").unwrap();
23+
open_in_new_tab(&link);
2124
};
2225

2326
// Sort data so that successful tests are rendered first and failed tests last

blade/components/dashboard/pass_fail_scatterplot.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
use leptos::prelude::*;
2-
use leptos_dom::helpers::window;
32
use state::{Status, TestHistory};
43

5-
use crate::{charts::scatterplot::ScatterPlot, summaryheader::format_time};
4+
use crate::{
5+
charts::scatterplot::ScatterPlot,
6+
navigation::open_in_new_tab,
7+
summaryheader::format_time,
8+
};
69

710
#[allow(non_snake_case)]
811
#[component]
912
pub fn PassFailScatterPlot(history: TestHistory) -> impl IntoView {
1013
let on_point_click = |point: state::TestHistoryPoint| {
1114
let link = format!("/invocation/{}", point.invocation_id);
12-
window().location().set_href(&link).unwrap();
15+
open_in_new_tab(&link);
1316
};
1417

1518
view! {

blade/components/dashboard/test_history_table.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use leptos::prelude::*;
2-
use leptos_router::hooks::use_navigate;
32
use state::{Status, TestHistory};
43

5-
use crate::summaryheader::format_time;
4+
use crate::{navigation::open_in_new_tab, summaryheader::format_time};
65

76
#[derive(Debug, Clone)]
87
struct RuntimeStats {
@@ -140,9 +139,8 @@ pub fn TestHistoryTable(history: TestHistory) -> impl IntoView {
140139
<tr
141140
class="border-b border-gray-200 dark:border-gray-600 hover:bg-gray-100 dark:hover:bg-gray-600 cursor-pointer"
142141
on:click=move |_| {
143-
let navigate = use_navigate();
144142
let url = format!("/invocation/{}", &point.invocation_id);
145-
navigate(&url, Default::default());
143+
open_in_new_tab(&url);
146144
}
147145
>
148146
<td class="py-3 px-6 text-left whitespace-nowrap">

blade/components/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod dashboard;
66
pub mod list;
77
pub mod measuretime;
88
pub mod nav;
9+
pub mod navigation;
910
pub mod searchbar;
1011
pub mod shellout;
1112
pub mod statusicon;

blade/components/navigation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use leptos_dom::helpers::window;
2+
3+
/// Opens a URL in a new browser tab
4+
pub fn open_in_new_tab(url: &str) { let _ = window().open_with_url_and_target(url, "_blank"); }

0 commit comments

Comments
 (0)