Skip to content

Commit

Permalink
break nav into smaller pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang2821 committed Aug 14, 2024
1 parent 5cd6c8a commit 24e523c
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 200 deletions.
16 changes: 12 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ rustls-pemfile = "2.1.0"
tokio-rustls = "0.25.0"
tokio-util = "0.7.10"
tokio = { version = "1.36.0", features = ["full"] }
sqlx = { version = "0.7.3", default_features = false, features = ["sqlx-postgres"] }
sqlx = { version = "0.7.3", default-features = false, features = ["sqlx-postgres"] }
sea-orm = { version = "0.12.12", features = [ "sqlx-postgres", "sqlx-sqlite", "runtime-tokio-rustls", "macros" ] }
sea-orm-migration = { version = "0.12.6", features = [ "sqlx-postgres", "runtime-tokio-rustls" ] }
uuid = { version = "1.6.1", features = ["v4", "serde"] }
Expand Down
4 changes: 2 additions & 2 deletions lapdev-api/src/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub async fn create_organization(

pub async fn delete_organization(
TypedHeader(cookie): TypedHeader<Cookie>,
Path((_, org_id)): Path<(String, Uuid)>,
Path(org_id): Path<Uuid>,
State(state): State<CoreState>,
info: RequestInfo,
) -> Result<Response, ApiError> {
Expand Down Expand Up @@ -169,7 +169,7 @@ pub async fn delete_organization(

pub async fn update_org_name(
TypedHeader(cookie): TypedHeader<Cookie>,
Path((_, org_id)): Path<(String, Uuid)>,
Path(org_id): Path<Uuid>,
State(state): State<CoreState>,
info: RequestInfo,
Json(update_org): Json<UpdateOrganizationName>,
Expand Down
25 changes: 17 additions & 8 deletions lapdev-api/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::{
workspace,
};

static STATIC_DIR: include_dir::Dir = include_dir::include_dir!("lapdev-dashboard/dist");
static STATIC_DIR: include_dir::Dir =
include_dir::include_dir!("$CARGO_MANIFEST_DIR/../lapdev-dashboard/dist");

fn private_routes() -> Router<CoreState> {
Router::new()
Expand All @@ -34,8 +35,8 @@ fn private_routes() -> Router<CoreState> {
)
}

fn v1_api_routes() -> Router<CoreState> {
Router::new()
fn v1_api_routes(additional_router: Option<Router<CoreState>>) -> Router<CoreState> {
let router = Router::new()
.route("/cluster_info", get(admin::get_cluster_info))
.route("/auth_providers", get(admin::get_auth_providers))
.route("/hostnames", get(admin::get_hostnames))
Expand Down Expand Up @@ -193,20 +194,28 @@ fn v1_api_routes() -> Router<CoreState> {
delete(machine_type::delete_machine_type),
)
.route("/admin/users", get(admin::get_cluster_users))
.route("/admin/users/:user_id", put(admin::update_cluster_user))
.route("/admin/users/:user_id", put(admin::update_cluster_user));
if let Some(additional) = additional_router {
router.merge(additional)
} else {
router
}
}

fn main_routes() -> Router<CoreState> {
fn main_routes(additional_router: Option<Router<CoreState>>) -> Router<CoreState> {
Router::new()
.nest("/v1", v1_api_routes())
.nest("/v1", v1_api_routes(additional_router))
.nest("/private", private_routes())
}

pub async fn build_router(state: CoreState) -> Router<()> {
pub async fn build_router(
state: CoreState,
additional_router: Option<Router<CoreState>>,
) -> Router<()> {
Router::new()
.route("/", any(handle_catch_all))
.route("/*0", any(handle_catch_all))
.nest("/api", main_routes())
.nest("/api", main_routes(additional_router))
.with_state(state)
.layer(SecureClientIpSource::ConnectInfo.into_extension())
}
Expand Down
6 changes: 3 additions & 3 deletions lapdev-api/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::PathBuf, sync::Arc};

use anyhow::{anyhow, Context, Result};
use axum::extract::Request;
use axum::{extract::Request, Router};
use clap::Parser;
use futures_util::pin_mut;
use hyper::body::Incoming;
Expand Down Expand Up @@ -37,7 +37,7 @@ struct Cli {
config_file: Option<PathBuf>,
}

pub async fn run() -> Result<()> {
pub async fn run(additional_router: Option<Router<CoreState>>) -> Result<()> {
let cli = Cli::parse();
let config_file = cli
.config_file
Expand Down Expand Up @@ -72,7 +72,7 @@ pub async fn run() -> Result<()> {
}

let state = CoreState::new(conductor, ssh_proxy_port).await;
let app = router::build_router(state.clone()).await;
let app = router::build_router(state.clone(), additional_router).await;
let certs = state.certs.clone();

{
Expand Down
3 changes: 1 addition & 2 deletions lapdev-conductor/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use lapdev_common::{BuildTarget, PrebuildUpdateEvent, RunningWorkspace, WorkspaceUpdateEvent};
use lapdev_db::entities;
use lapdev_rpc::{error::ApiError, ConductorService, WorkspaceServiceClient};
use lapdev_rpc::{error::ApiError, ConductorService};
use sea_orm::{ActiveModelTrait, ActiveValue};
use tarpc::context;
use uuid::Uuid;
Expand All @@ -12,7 +12,6 @@ use crate::Conductor;
pub struct ConductorRpc {
pub ws_host_id: Uuid,
pub conductor: Conductor,
pub ws_client: WorkspaceServiceClient,
}

impl ConductorService for ConductorRpc {
Expand Down
1 change: 0 additions & 1 deletion lapdev-conductor/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ impl Conductor {

let rpc = ConductorRpc {
ws_host_id: id,
ws_client: ws_client.clone(),
conductor: self.clone(),
};

Expand Down
13 changes: 5 additions & 8 deletions lapdev-dashboard/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ async fn get_cluster_info() -> Result<ClusterInfo> {
Ok(info)
}

#[component]
pub fn App() -> impl IntoView {
pub fn set_context() {
let login_counter = create_rw_signal(0);
provide_context(login_counter);

Expand All @@ -45,12 +44,6 @@ pub fn App() -> impl IntoView {
);
provide_context(login);

let login = create_local_resource(
move || login_counter.get(),
|_| async move { get_login().await.ok() },
);
provide_context(login);

let cluster_info =
create_local_resource(move || (), |_| async move { get_cluster_info().await.ok() });
let cluster_info = Signal::derive(move || cluster_info.get().flatten());
Expand All @@ -68,7 +61,11 @@ pub fn App() -> impl IntoView {
account: create_rw_signal(pathname.starts_with("/account")),
};
provide_context(nav_expanded);
}

#[component]
pub fn App() -> impl IntoView {
set_context();
view! {
<Router>
<Routes>
Expand Down
29 changes: 14 additions & 15 deletions lapdev-dashboard/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
mod account;
mod app;
mod audit_log;
mod cluster;
mod datepicker;
mod license;
mod modal;
mod nav;
mod organization;
mod project;
mod quota;
mod ssh_key;
mod usage;
mod workspace;
pub use app::App;
pub mod account;
pub mod app;
pub mod audit_log;
pub mod cluster;
pub mod datepicker;
pub mod license;
pub mod modal;
pub mod nav;
pub mod organization;
pub mod project;
pub mod quota;
pub mod ssh_key;
pub mod usage;
pub mod workspace;
2 changes: 1 addition & 1 deletion lapdev-dashboard/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use lapdev_dashboard::App;
use lapdev_dashboard::app::App;
use leptos::{mount_to_body, view};

pub fn main() {
Expand Down
Loading

0 comments on commit 24e523c

Please sign in to comment.