spruce up workspace navigation

This commit is contained in:
Brent Schroeter 2025-09-25 14:51:09 -07:00
parent 9bb7dcca7c
commit f2d5f9fd01
9 changed files with 179 additions and 103 deletions

View file

@ -43,7 +43,7 @@ pub(crate) fn new_router(app: App) -> Router<()> {
), ),
) )
.nest("/workspaces", workspaces_multi::new_router()) .nest("/workspaces", workspaces_multi::new_router())
.nest("/w/{workspace_id}", workspaces_single::new_router()) .nest("/w", workspaces_single::new_router())
.nest("/auth", auth::new_router()) .nest("/auth", auth::new_router())
.route("/__dev-healthz", any(dev_healthz_handler)) .route("/__dev-healthz", any(dev_healthz_handler))
.layer(SetResponseHeaderLayer::if_not_present( .layer(SetResponseHeaderLayer::if_not_present(

View file

@ -1,21 +1,43 @@
use axum::{ use axum::{
Router, Router,
extract::{Path, State},
response::Redirect, response::Redirect,
routing::{get, post}, routing::{get, post},
}; };
use axum_extra::routing::RouterExt as _; use axum_extra::routing::RouterExt as _;
use serde::Deserialize;
use uuid::Uuid;
use crate::app::App; use crate::{Settings, app::App};
use super::relations_single; use super::relations_single;
mod add_table_handler; mod add_table_handler;
mod nav_handler; mod nav_handler;
#[derive(Clone, Debug, Deserialize)]
struct PathParams {
workspace_id: Uuid,
}
pub(super) fn new_router() -> Router<App> { pub(super) fn new_router() -> Router<App> {
Router::<App>::new() Router::<App>::new()
.route("/", get(|| async move { Redirect::to("nav/") })) .route_with_tsr(
.route("/add-table", post(add_table_handler::post)) "/{workspace_id}",
.route_with_tsr("/nav/", get(nav_handler::get)) get(
.nest("/r/{rel_oid}", relations_single::new_router()) |State(Settings { root_path, .. }): State<Settings>,
Path(PathParams { workspace_id }): Path<PathParams>| async move {
Redirect::to(&format!(
"{root_path}/w/{workspace_id}/nav/",
workspace_id = workspace_id.simple()
))
},
),
)
.route("/{workspace_id}/add-table", post(add_table_handler::post))
.route_with_tsr("/{workspace_id}/nav/", get(nav_handler::get))
.nest(
"/{workspace_id}/r/{rel_oid}",
relations_single::new_router(),
)
} }

View file

@ -7,7 +7,9 @@
<filter-menu identifier-hints="{{ attr_names | json }}" initial-value="{{ filter | json }}"></filter-menu> <filter-menu identifier-hints="{{ attr_names | json }}" initial-value="{{ filter | json }}"></filter-menu>
</div> </div>
<div class="page-grid__sidebar"> <div class="page-grid__sidebar">
{{ navbar | safe }} <div style="padding: 1rem;">
{{ navbar | safe }}
</div>
</div> </div>
<main class="page-grid__main"> <main class="page-grid__main">
<table-viewer columns="{{ attr_names | json }}" root-path="{{ settings.root_path }}"></table-viewer> <table-viewer columns="{{ attr_names | json }}" root-path="{{ settings.root_path }}"></table-viewer>

View file

@ -1,6 +1,6 @@
<nav class="navbar"> <nav class="workspace-nav">
<section> <section>
<div class="navbar__heading"> <div class="workspace-nav__heading">
<h2>Tables</h2> <h2>Tables</h2>
<form <form
action="{{ navigator.get_root_path() -}} action="{{ navigator.get_root_path() -}}
@ -9,18 +9,14 @@
method="post" method="post"
> >
<!-- FIXME: CSRF --> <!-- FIXME: CSRF -->
<button type="submit">+</button> <button class="workspace-nav__aux-button" type="submit">+</button>
</form> </form>
</div> </div>
<menu class="navbar__menu"> <menu class="workspace-nav__menu">
{%- for rel in relations %} {%- for rel in relations %}
<li class="navbar__menu-item <li>
{%- if current == Some(NavLocation::Rel(rel.oid.to_owned(), None)) -%}
{# preserve space #} navbar__menu-item--active
{%- endif -%}
">
<collapsible-menu <collapsible-menu
class="navbar__collapsible-menu" class="workspace-nav__menu-item"
expanded=" expanded="
{%- if let Some(NavLocation::Rel(rel_oid, _)) = current -%} {%- if let Some(NavLocation::Rel(rel_oid, _)) = current -%}
{%- if rel_oid.to_owned() == rel.oid -%} {%- if rel_oid.to_owned() == rel.oid -%}
@ -29,22 +25,24 @@
{%- endif -%} {%- endif -%}
" "
> >
<h4 slot="summary" class="navbar__heading navbar__heading--entity"> <div class="workspace-nav__heading" slot="summary">
{{ rel.name }} <h3>{{ rel.name }}</h3>
</h4> <a
<menu slot="content" class="navbar__menu"> href="{{ navigator.get_root_path() -}}
<li class="navbar__menu-item"> /w/{{ workspace.id.simple() -}}
<a /r/{{ rel.oid.0 -}}
href="{{ navigator.get_root_path() }}/r/{{ rel.oid.0 }}/rbac" /settings/"
class="navbar__menu-link" class="workspace-nav__aux-button"
> role="button"
Sharing >
</a> Settings
</li> </a>
<li class="navbar__menu-item"> </div>
<collapsible-menu class="navbar__collapsible-menu"> <menu class="workspace-nav__menu" slot="content">
<div slot="summary" class="navbar__heading"> <li class="workspace-nav__menu-item">
<h5>Portals</h5> <collapsible-menu class="workspace-nav__collapsible-menu">
<div slot="summary" class="workspace-nav__heading">
<h4>Portals</h4>
<form <form
action="{{ navigator.get_root_path() -}} action="{{ navigator.get_root_path() -}}
/w/{{ workspace.id.simple() -}} /w/{{ workspace.id.simple() -}}
@ -53,28 +51,41 @@
method="post" method="post"
> >
<!-- FIXME: CSRF --> <!-- FIXME: CSRF -->
<button type="submit">+</button> <button class="workspace-nav__aux-button" type="submit">+</button>
</form> </form>
</div> </div>
<menu slot="content" class="navbar__menu"> <menu slot="content" class="workspace-nav__menu">
{% for portal in rel.portals %} {% for portal in rel.portals %}
<li class="navbar__menu-item <li class="workspace-nav__menu-item">
"> <div class="workspace-nav__menu-leaf
<a {%- if current == Some(NavLocation::Rel(rel.oid.to_owned(), Some(RelLocation::Portal(portal.id.to_owned())))) -%}
href=" {# preserve space #} workspace-nav__menu-leaf--current
{{- navigator.get_root_path() -}} {%- endif -%}
/w/{{ workspace.id.simple() -}} ">
/r/{{ rel.oid.0 -}} <a
/p/{{ portal.id.simple() -}} href="
" {{- navigator.get_root_path() -}}
class="navbar__menu-link navbar__menu-link--entity /w/{{ workspace.id.simple() -}}
{%- if current == Some(NavLocation::Rel(rel.oid.to_owned(), Some(RelLocation::Portal(portal.id.to_owned())))) -%} /r/{{ rel.oid.0 -}}
{# preserve space #} navbar__menu-link--current /p/{{ portal.id.simple() -}}
{%- endif -%} "
" class="workspace-nav__menu-link
> "
{{ portal.name }} >
</a> {{ portal.name }}
</a>
<a
href="{{ navigator.get_root_path() -}}
/w/{{ workspace.id.simple() -}}
/r/{{ rel.oid.0 -}}
/p/{{ portal.id.simple() -}}
/form/"
class="workspace-nav__aux-button"
role="button"
>
Form
</a>
</div>
</li> </li>
{% endfor %} {% endfor %}
</menu> </menu>

View file

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block main %} {% block main %}
<main> <main style="position: relative; margin: 0 auto; max-width: 32rem;">
<h1>{{ workspace.name }}</h1> <h1>{{ workspace.name }}</h1>
{{ workspace_nav | safe }} {{ workspace_nav | safe }}
</main> </main>

View file

@ -2,10 +2,11 @@
$button-primary-background: #07f; $button-primary-background: #07f;
$button-primary-color: #fff; $button-primary-color: #fff;
$button-shadow: 0 0.15rem 0.15rem #3331;
$default-border-color: #ccc; $default-border-color: #ccc;
$default-border: solid 1px $default-border-color; $default-border: solid 1px $default-border-color;
$font-family-default: 'Averia Serif Libre', 'Open Sans', 'Helvetica Neue', Arial, sans-serif; $font-family-default: 'Funnel Sans', 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
$font-family-data: 'Funnel Sans', 'Open Sans', 'Helvetica Neue', Arial, sans-serif; $font-family-data: Menlo, 'Courier New', 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
$font-family-mono: Menlo, 'Courier New', Courier, mono; $font-family-mono: Menlo, 'Courier New', Courier, mono;
$popover-border: $default-border; $popover-border: $default-border;
$popover-shadow: 0 0.5rem 0.5rem #3333; $popover-shadow: 0 0.5rem 0.5rem #3333;
@ -30,13 +31,17 @@ $hover-lightness-scale-factor: -10%;
@mixin button-base { @mixin button-base {
@include reset-button; @include reset-button;
@include rounded; @include rounded;
box-shadow: $button-shadow;
font-family: $font-family-default; font-family: $font-family-default;
font-weight: 500;
padding: 0.5rem 1rem; padding: 0.5rem 1rem;
transition: background 0.2s ease; transition: background 0.2s ease;
} }
@mixin button-primary { @mixin button-primary {
@include button-base; @include button-base;
background: $button-primary-background; background: $button-primary-background;
color: $button-primary-color; color: $button-primary-color;
@ -67,6 +72,7 @@ $hover-lightness-scale-factor: -10%;
@mixin button-secondary { @mixin button-secondary {
@include button-base; @include button-base;
background: #fff; background: #fff;
color: #000; color: #000;
border: $default-border; border: $default-border;
@ -83,11 +89,18 @@ $hover-lightness-scale-factor: -10%;
@mixin button-clear { @mixin button-clear {
@include button-base; @include button-base;
box-shadow: none;
&:hover { &:hover {
background: #0000001f; background: #0000001f;
} }
} }
@mixin button-small {
padding: 0.25rem 0.5rem;
font-size: 0.9rem;
}
@mixin reset-input { @mixin reset-input {
appearance: none; appearance: none;
background: none; background: none;

View file

@ -4,10 +4,10 @@
@use 'modern-normalize'; @use 'modern-normalize';
@use 'forms'; @use 'forms';
@use 'collapsible_menu'; @use 'collapsible_menu';
@use 'navbar'; @use 'workspace-nav';
html { html {
font-family: "Averia Serif Libre", "Open Sans", "Helvetica Neue", Arial, sans-serif; font-family: globals.$font-family-default;
} }
button, input[type="submit"] { button, input[type="submit"] {

View file

@ -1,46 +0,0 @@
@use 'globals';
@use 'collapsible_menu';
$background-current-item: #0001;
.navbar {
padding: 2rem;
&__menu {
list-style-type: none;
padding: 0;
margin-bottom: 0;
}
&__heading {
font-size: inherit;
margin: 0;
padding: 0.5rem;
&--entity {
font-family: globals.$font-family-data;
}
}
&__menu-link {
@include globals.rounded-sm;
display: block;
padding: 0.5rem;
color: globals.$link-color;
text-decoration: none;
&--entity {
font-family: globals.$font-family-data;
}
&--current {
background: $background-current-item;
}
}
}
.base-switcher {
@include globals.reset-button;
font-family: globals.$font-family-data;
padding: 1rem;
}

74
sass/workspace-nav.scss Normal file
View file

@ -0,0 +1,74 @@
@use 'globals';
$background-current-item: #0001;
.workspace-nav {
& h1, h2, h3, h4, h5, h6 {
margin: 0;
font-weight: 600;
}
& h2 {
font-size: 1.25rem;
}
& h3 {
font-size: 1.125rem;
}
& h4, h5, h6 {
font-size: 1rem;
}
&__menu {
list-style-type: none;
padding: 0;
margin-bottom: 0;
}
&__heading {
align-items: center;
display: flex;
font-size: inherit;
justify-content: space-between;
margin: 0;
padding: 0.5rem;
}
&__aux-button {
@include globals.button-secondary;
@include globals.button-small;
text-decoration: none;
}
&__menu-item {
padding-top: 0.5rem;
padding-left: 0.5rem;
}
&__menu-leaf {
@include globals.rounded-sm;
align-items: center;
display: flex;
justify-content: space-between;
padding: 0 0.5rem;
&--current, &:hover {
background: $background-current-item;
}
}
&__menu-link {
color: globals.$link-color;
flex: 1;
padding: 0.75rem 0;
text-decoration: none;
}
}
.base-switcher {
@include globals.reset-button;
font-family: globals.$font-family-data;
padding: 1rem;
}