Skip to content

Make parent nav links clickable #1064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pgml-dashboard/src/api/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ async fn doc_handler(path: PathBuf, cluster: &Cluster) -> Result<ResponseOk, Sta
let guides = markdown::parse_summary_into_nav_links(&mdast)
.expect("could not extract nav links from table of contents");

render(cluster, &path, guides, "Guides", &Path::new("docs"), &config::docs_dir()).await
render(
cluster,
&path,
guides,
"Guides",
&Path::new("docs"),
&config::docs_dir(),
)
.await
}

#[get("/blog/<path..>", rank = 10)]
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/inputs/select/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::components::stimulus::stimulus_action::{StimulusAction, StimulusEvents};
use crate::components::stimulus::stimulus_target::StimulusTarget;
use crate::types::CustomOption;
use pgml_components::component;
use pgml_components::Component;
use sailfish::TemplateOnce;
use crate::types::CustomOption;

#[derive(TemplateOnce, Default)]
#[template(path = "inputs/select/template.html")]
Expand Down
8 changes: 4 additions & 4 deletions pgml-dashboard/src/components/nav/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

<% if link.nav.is_some() { %>
<ul class="nav flex-column justify-content-end flex-grow-1 ps-5">

<% for link in link.nav.unwrap().links.iter() {
let active = if link.active {
"active"
} else {
""
};

let aria = if link.active {
r#"area-current="page""#
} else {
Expand All @@ -48,10 +48,10 @@
<span class="nav-link-name"><%= link.name %></span>
</a>
</li>

<% } %>
</ul>

<% } %>
</li>
<% } %>
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use sailfish::TemplateOnce;
use sqlx::PgPool;
use std::collections::HashMap;

pub mod types;
pub mod api;
pub mod components;
pub mod fairings;
Expand All @@ -22,6 +21,7 @@ pub mod guards;
pub mod models;
pub mod responses;
pub mod templates;
pub mod types;
pub mod utils;

use guards::{Cluster, ConnectedCluster};
Expand Down
5 changes: 1 addition & 4 deletions pgml-dashboard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ mod test {
#[rocket::async_test]
async fn test_docs() {
let client = Client::tracked(rocket().await).await.unwrap();
let response = client
.get("/docs/guides/README")
.dispatch()
.await;
let response = client.get("/docs/guides/README").dispatch().await;
assert_eq!(response.status().code, 200);
}

Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/templates/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl NavLink {
/// Automatically expand the link and it's parents
/// when one of the children is visible.
pub fn should_open(&mut self, path: &str) -> bool {
self.open = self.href.contains(&path);
let open = if self.children.is_empty() {
self.open = self.href.contains(&path);
self.open
} else {
for child in self.children.iter_mut() {
Expand Down
17 changes: 7 additions & 10 deletions pgml-dashboard/src/utils/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ use url::Url;
use crate::templates::docs::NavLink;
use std::fmt;

pub struct MarkdownHeadings {
}
pub struct MarkdownHeadings {}

impl MarkdownHeadings {
pub fn new() -> Self {
Self {
}
Self {}
}
}

Expand Down Expand Up @@ -583,7 +581,7 @@ pub fn get_sub_links(list: &markdown::mdast::List) -> Result<Vec<NavLink>> {
.unwrap();
let parent = NavLink::new(text.value.as_str())
.href(&url);
links.push(parent)
links.push(parent);
}
_ => error!("unhandled link child: {:?}", node),
}
Expand Down Expand Up @@ -1074,8 +1072,8 @@ pub fn mkdocs<'a>(root: &'a AstNode<'a>, arena: &'a Arena<AstNode<'a>>) -> anyho
r#"
<ul class="nav nav-tabs">
"#
.to_string()
.into(),
.to_string()
.into(),
)))));

parent.insert_after(n);
Expand Down Expand Up @@ -1136,7 +1134,7 @@ pub fn mkdocs<'a>(root: &'a AstNode<'a>, arena: &'a Arena<AstNode<'a>>) -> anyho
active = if tab.active { "show active" } else { "" },
id = tab.id
)
.into(),
.into(),
),
))));

Expand Down Expand Up @@ -1337,8 +1335,7 @@ impl SearchIndex {
}

pub fn documents() -> Vec<PathBuf> {
let guides =
glob::glob(&(config::docs_dir() + "/guides/**/*.md")).expect("glob failed");
let guides = glob::glob(&(config::docs_dir() + "/guides/**/*.md")).expect("glob failed");
let blogs = glob::glob(&(config::blogs_dir() + "/blog/**/*.md")).expect("glob failed");
guides
.chain(blogs)
Expand Down
5 changes: 1 addition & 4 deletions pgml-dashboard/static/css/scss/components/_navs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,9 @@
&:focus:not(:hover) {
color: #{$gray-100}
}

}
[aria-expanded=false] {
span.material-symbols-outlined {
transform: rotate(-90deg);
}
transform: rotate(-90deg);
}
@include media-breakpoint-down(xxl) {
border-radius: 0px;
Expand Down
28 changes: 16 additions & 12 deletions pgml-dashboard/templates/components/link.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<div class="nav flex-column" role="tablist" aria-orientation="vertical">
<% if !children.is_empty() {
<%
let color = if open {
"purple"
} else {
""
};

if children.is_empty() {
%>
<a class="nav-link px-0 text-break <%- color %>" href="<%- href %>"><%- title %></a>
<% } else {
let aria = if open {
"true"
} else {
Expand All @@ -12,23 +22,17 @@
"false"
};
%>
<a class="nav-link px-0 d-flex justify-content-between align-items-center text-break" data-bs-toggle="collapse" href="#doc-<%= id %>" role="button" aria-expanded="<%- aria %>" aria-controls="doc-<%= id %>">
<span><%= title %></span><span class="material-symbols-outlined">expand_more</span>
</a>

<span class="px-0 d-flex justify-content-between align-items-center text-break" >
<a class="nav-link px-0 text-break <%- color %>" href="<%- href %>"><%- title %></a>
<span class="material-symbols-outlined" data-bs-toggle="collapse" href="#doc-<%= id %>" role="button" aria-expanded="<%- aria %>" aria-controls="doc-<%= id %>">expand_more</span>
</span>
<div class="collapse <%- show %> ps-3" id="doc-<%= id %>">
<div class="nav flex-column" role="tablist" aria-orentation="vertical">
<% for child in children.into_iter() { %>
<%- child.render_once().unwrap() %>
<% } %>
</div>
</div>
<% } else {
let color = if open {
"purple"
} else {
""
};
%>
<a class="nav-link px-0 text-break <%- color %>" href="<%- href %>"><%- title %></a>
<% } %>
</div>