Skip to content

Commit f367f18

Browse files
committed
updates for orgs
1 parent db92b1c commit f367f18

File tree

8 files changed

+134
-35
lines changed

8 files changed

+134
-35
lines changed

pgml-dashboard/src/components/breadcrumbs/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
use crate::components::dropdown::{Dropdown, DropdownItems};
12
use crate::components::NavLink;
3+
use crate::components::StaticNavLink;
24
use pgml_components::component;
35
use sailfish::TemplateOnce;
46

5-
#[derive(TemplateOnce)]
7+
#[derive(TemplateOnce, Clone, Default)]
68
#[template(path = "breadcrumbs/template.html")]
79
pub struct Breadcrumbs<'a> {
8-
pub links: Vec<NavLink<'a>>,
10+
pub organizations: Vec<StaticNavLink>,
11+
pub databases: Vec<StaticNavLink>,
12+
pub path: Vec<NavLink<'a>>,
913
}
1014

1115
impl<'a> Breadcrumbs<'a> {
12-
pub fn render(links: Vec<NavLink<'a>>) -> String {
13-
Breadcrumbs { links }.render_once().unwrap()
16+
pub fn new(path: Vec<NavLink<'a>>, organizations: Vec<StaticNavLink>, databases: Vec<StaticNavLink>) -> Self {
17+
Breadcrumbs {
18+
path,
19+
databases,
20+
organizations,
21+
}
1422
}
1523
}
1624

pgml-dashboard/src/components/breadcrumbs/template.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<%
22
use crate::utils::config;
33
use crate::utils::urls;
4+
use crate::components::dropdown::Dropdown;
45

56
let home_uri = if config::standalone_dashboard() {
67
urls::deployment_notebooks()
@@ -12,18 +13,30 @@
1213
<nav>
1314
<nav aria-label="breadcrumb z-1">
1415
<ol class="breadcrumb">
15-
<li class="breadcrumb-item body-regular-text <% if links.is_empty() {%>active<% } %>">
16+
<!-- <li class="breadcrumb-item body-regular-text <% if path.is_empty() {%>active<% } %>">
1617
<a class="d-flex gap-2 align-items-center" href="<%- home_uri %>">
1718
<span class="icon-owl icomoon"></span>
1819
Home
1920
</a>
21+
</li> -->
22+
23+
<% if !organizations.is_empty() {%>
24+
<li>
25+
<%+ Dropdown::nav(organizations) %>
2026
</li>
27+
<% } %>
28+
29+
<% if !databases.is_empty() {%>
30+
<li>
31+
<%+ Dropdown::nav(databases) %>
32+
</li>
33+
<% } %>
2134

22-
<% if !links.is_empty() {%>
35+
<% if !path.is_empty() {%>
2336
<div class="vr my-1 mx-2"></div>
2437
<% } %>
2538

26-
<% for link in links {
39+
<% for link in path {
2740
let active = if link.active {
2841
"active"
2942
} else {

pgml-dashboard/src/components/navigation/left_nav/web_app/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
use crate::components::StaticNav;
1+
use crate::components::{StaticNav, StaticNavLink};
22
use pgml_components::component;
33
use sailfish::TemplateOnce;
44

5+
#[derive(Default, Debug, Clone)]
6+
pub struct Menu {
7+
pub back: Option<StaticNavLink>,
8+
pub items: StaticNav,
9+
}
10+
511
#[derive(TemplateOnce, Default)]
612
#[template(path = "navigation/left_nav/web_app/template.html")]
713
pub struct WebApp {
8-
pub upper_nav: StaticNav,
914
pub id: Option<String>,
15+
pub menu: Menu,
1016
}
1117

1218
impl WebApp {
13-
pub fn new(upper_nav: StaticNav) -> WebApp {
14-
WebApp { upper_nav, id: None }
19+
pub fn new(menu: Menu) -> WebApp {
20+
WebApp { id: None, menu }
1521
}
1622

1723
pub fn id(mut self, id: &str) -> WebApp {

pgml-dashboard/src/components/navigation/left_nav/web_app/template.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
<div class="d-flex flex-column justify-content-between h-100 menu-container leftnav-collapse-affect collapsed">
1010
<div class="d-flex flex-column">
1111
<span class="leftnav-collapse collapse" data-extend-bs-collapse-target="stateReference" data-navigation-left-nav-web-app-target="stateReference"></span>
12-
<%+ LeftNavMenu { nav: upper_nav } %>
12+
<% if let Some(back_link) = menu.back {%>
13+
<a class="btn btn-tertiary justify-content-start gap-3" style="height: 2rem;" href="<%- back_link.href %>">
14+
<span class="material-symbols-outlined">arrow_back</span>
15+
<span class="collapse collapse-horizontal leftnav-collapse text-nowrap overflow-hidden"><%- back_link.name %></span></a>
16+
<% } %>
17+
<%+ LeftNavMenu { nav: menu.items } %>
1318
</div>
1419
</div>
1520
</nav>

pgml-dashboard/src/guards.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,31 @@ impl Cluster {
4646
context: Context {
4747
user: models::User::default(),
4848
cluster: models::Cluster::default(),
49-
dropdown_nav: StaticNav {
49+
deployment_dropdown: StaticNav {
5050
links: vec![StaticNavLink::new("Local".to_string(), "/dashboard".to_string()).active(true)],
5151
},
52-
product_left_nav: StaticNav {
53-
links: vec![
54-
StaticNavLink::new("Notebooks".to_string(), urls::deployment_notebooks())
55-
.icon("format_list_bulleted_add"),
56-
StaticNavLink::new("Projects".to_string(), urls::deployment_projects()).icon("library_add"),
57-
StaticNavLink::new("Models".to_string(), urls::deployment_models()).icon("grid_view"),
58-
StaticNavLink::new("Snapshots".to_string(), urls::deployment_snapshots())
59-
.icon("filter_center_focus"),
60-
StaticNavLink::new("Upload data".to_string(), urls::deployment_uploader()).icon("upload"),
61-
],
52+
organization_dropdown: StaticNav {
53+
links: vec![StaticNavLink::new(
54+
"Organization".to_string(),
55+
"/organizations".to_string(),
56+
)],
6257
},
6358
marketing_footer: MarketingFooter::new().render_once().unwrap(),
6459
head_items: None,
60+
product_left_nav: crate::components::navigation::left_nav::web_app::Menu {
61+
back: None,
62+
items: StaticNav {
63+
links: vec![
64+
StaticNavLink::new("Notebooks".to_string(), urls::deployment_notebooks())
65+
.icon("format_list_bulleted_add"),
66+
StaticNavLink::new("Projects".to_string(), urls::deployment_projects()).icon("library_add"),
67+
StaticNavLink::new("Models".to_string(), urls::deployment_models()).icon("grid_view"),
68+
StaticNavLink::new("Snapshots".to_string(), urls::deployment_snapshots())
69+
.icon("filter_center_focus"),
70+
StaticNavLink::new("Upload data".to_string(), urls::deployment_uploader()).icon("upload"),
71+
],
72+
},
73+
},
6574
},
6675
notifications: None,
6776
}

pgml-dashboard/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ pub struct ClustersSettings {
4949
pub struct Context {
5050
pub user: models::User,
5151
pub cluster: models::Cluster,
52-
pub dropdown_nav: StaticNav,
53-
pub product_left_nav: StaticNav,
52+
pub organization_dropdown: StaticNav,
53+
pub deployment_dropdown: StaticNav,
5454
pub marketing_footer: String,
5555
pub head_items: Option<String>,
56+
pub product_left_nav: crate::components::navigation::left_nav::web_app::Menu,
5657
}
5758

5859
#[derive(Debug, Clone, Default)]
@@ -646,7 +647,8 @@ mod test {
646647
context: Context {
647648
user: models::User::default(),
648649
cluster: models::Cluster::default(),
649-
dropdown_nav: StaticNav { links: vec![] },
650+
deployment_dropdown: StaticNav { links: vec![] },
651+
organization_dropdown: StaticNav { links: vec![] },
650652
product_left_nav: StaticNav { links: vec![] },
651653
marketing_footer: MarketingFooter::new().render_once().unwrap(),
652654
head_items: None,
@@ -719,7 +721,8 @@ mod test {
719721
context: Context {
720722
user: models::User::default(),
721723
cluster: models::Cluster::default(),
722-
dropdown_nav: StaticNav { links: vec![] },
724+
deployment_dropdown: StaticNav { links: vec![] },
725+
organization_dropdown: StaticNav { links: vec![] },
723726
product_left_nav: StaticNav { links: vec![] },
724727
marketing_footer: MarketingFooter::new().render_once().unwrap(),
725728
head_items: None,

pgml-dashboard/src/templates/mod.rs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use sqlx::postgres::types::PgMoney;
1212
use sqlx::types::time::PrimitiveDateTime;
1313
use sqlx::{Column, Executor, PgPool, Row, Statement, TypeInfo, ValueRef};
1414

15+
use crate::components::breadcrumbs::Breadcrumbs;
1516
use crate::models;
1617
use crate::utils::tabs;
1718

@@ -116,10 +117,10 @@ impl From<Layout> for String {
116117
#[template(path = "layout/web_app_base.html")]
117118
pub struct WebAppBase<'a> {
118119
pub content: Option<String>,
119-
pub breadcrumbs: Vec<NavLink<'a>>,
120+
pub breadcrumbs: Breadcrumbs<'a>,
120121
pub head: Head,
121122
pub dropdown_nav: StaticNav,
122-
pub product_left_nav: StaticNav,
123+
pub product_left_nav: crate::components::navigation::left_nav::web_app::Menu,
123124
pub body_components: Vec<Component>,
124125
pub cluster: Cluster,
125126
pub product_banners_high: Vec<ProductBanner>,
@@ -145,7 +146,7 @@ impl<'a> WebAppBase<'a> {
145146
WebAppBase {
146147
head,
147148
cluster,
148-
dropdown_nav: context.context.dropdown_nav.clone(),
149+
dropdown_nav: context.context.deployment_dropdown.clone(),
149150
product_left_nav: context.context.product_left_nav.clone(),
150151
product_banners_high: all_product_high_level,
151152
product_banner_medium: ProductBanner::from_notification(Notification::next_product_of_level(
@@ -161,18 +162,22 @@ impl<'a> WebAppBase<'a> {
161162
}
162163

163164
pub fn breadcrumbs(&mut self, breadcrumbs: Vec<NavLink<'a>>) -> &mut Self {
164-
self.breadcrumbs = breadcrumbs.to_owned();
165+
self.breadcrumbs.path = breadcrumbs.clone();
165166
self
166167
}
167168

168169
pub fn disable_upper_nav(&mut self) -> &mut Self {
169170
let links: Vec<StaticNavLink> = self
170171
.product_left_nav
172+
.items
171173
.links
172174
.iter()
173175
.map(|item| item.to_owned().disabled(true))
174176
.collect();
175-
self.product_left_nav = StaticNav { links };
177+
self.product_left_nav = crate::components::navigation::left_nav::web_app::Menu {
178+
back: self.product_left_nav.back.clone(),
179+
items: StaticNav { links },
180+
};
176181
self
177182
}
178183

@@ -186,6 +191,56 @@ impl<'a> WebAppBase<'a> {
186191
self
187192
}
188193

194+
pub fn breadcrumbs_from_uri(
195+
&mut self,
196+
org_dropdown: Vec<StaticNavLink>,
197+
database_dropdown: Vec<StaticNavLink>,
198+
uri: &str,
199+
) -> &mut Self {
200+
let uri = if uri.starts_with("/") {
201+
uri.chars().skip(1).collect::<String>()
202+
} else {
203+
uri.to_string()
204+
};
205+
206+
let start_index = match (org_dropdown.is_empty(), database_dropdown.is_empty()) {
207+
(true, true) => 0,
208+
(false, true) => 1,
209+
_ => 2,
210+
};
211+
212+
let mut uris = uri
213+
.split("/")
214+
.skip(start_index)
215+
.enumerate()
216+
.map(|(i, part)| {
217+
let path = uri
218+
.split("/")
219+
.into_iter()
220+
.take(1 + i + start_index)
221+
.collect::<Vec<&str>>()
222+
.join("/");
223+
let mut out = "/".to_owned();
224+
out.push_str(&path);
225+
226+
NavLink::new(part, &out)
227+
})
228+
.collect::<Vec<NavLink>>();
229+
230+
if let Some(last) = uris.clone().into_iter().next_back() {
231+
uris.pop();
232+
uris.push(last.active());
233+
}
234+
235+
self.breadcrumbs = Breadcrumbs {
236+
organizations: org_dropdown,
237+
databases: database_dropdown,
238+
path: uris,
239+
};
240+
241+
self
242+
}
243+
189244
pub fn render<T>(&mut self, template: T) -> String
190245
where
191246
T: sailfish::TemplateOnce,

pgml-dashboard/templates/layout/web_app_base.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
<main>
1515
<div class="container-fluid p-0 min-vh-lg-100">
1616
<div class="row gx-0 min-vh-lg-100 gy-0">
17-
<%+ WebAppNavbar::new(product_left_nav.links.clone(), dropdown_nav).cluster(cluster) %>
17+
<%+ WebAppNavbar::new(product_left_nav.items.links.clone(), dropdown_nav).cluster(cluster) %>
1818
<div class="d-flex">
1919
<%+ WebAppLeftNav::new(product_left_nav.clone())
20-
.id(&product_left_nav.unique_id()) %>
20+
.id(&product_left_nav.items.unique_id()) %>
2121

2222
<div class="clear-from-under-navbar flex-grow-1 min-vw-0 web-app-content-area">
2323
<div class="px-4 px-sm-5 py-3 d-none d-lg-flex" style="position: absolute">
24-
<%- Breadcrumbs::render(breadcrumbs) %>
24+
<%+ breadcrumbs %>
2525
</div>
2626

2727
<div class="px-xs-2 px-md-5 overflow-hidden" style="padding-top: 57px;">

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy