From f5f9af52ec64d2f42e77660a63af580dd7e32171 Mon Sep 17 00:00:00 2001 From: dal Date: Thu, 20 Mar 2025 12:32:04 -0600 Subject: [PATCH] ok update dashboard but will need to mess with it more --- .../src/dashboards/get_dashboard_handler.rs | 20 ++++- api/libs/handlers/src/dashboards/types.rs | 5 ++ .../handlers/src/favorites/favorites_utils.rs | 85 +++++++++++++++---- 3 files changed, 92 insertions(+), 18 deletions(-) diff --git a/api/libs/handlers/src/dashboards/get_dashboard_handler.rs b/api/libs/handlers/src/dashboards/get_dashboard_handler.rs index 8af7f5ef8..d61750f07 100644 --- a/api/libs/handlers/src/dashboards/get_dashboard_handler.rs +++ b/api/libs/handlers/src/dashboards/get_dashboard_handler.rs @@ -263,11 +263,27 @@ fn parse_dashboard_config(content: &Value) -> Result { }) .collect::>>()?; + // Extract column_sizes from the row if available + let column_sizes = row + .get("columnSizes") + .and_then(|sizes| { + sizes.as_array().map(|arr| { + arr.iter() + .filter_map(|size| size.as_u64().map(|s| s as u32)) + .collect::>() + }) + }); + + // Extract row_height from the row if available + let row_height = row + .get("rowHeight") + .and_then(|height| height.as_u64().map(|h| h as u32)); + Ok(DashboardRow { id: (index + 1).to_string(), items, - row_height: None, - column_sizes: None, + row_height, + column_sizes, }) }) .collect::>>()?; diff --git a/api/libs/handlers/src/dashboards/types.rs b/api/libs/handlers/src/dashboards/types.rs index 19ca3f452..2cc6be98c 100644 --- a/api/libs/handlers/src/dashboards/types.rs +++ b/api/libs/handlers/src/dashboards/types.rs @@ -76,19 +76,24 @@ pub struct DashboardCollection { // Note: This is a placeholder for DashboardConfig which needs to be defined based on your specific needs #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct DashboardConfig { pub rows: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct DashboardRow { pub id: String, pub items: Vec, + #[serde(alias = "rowHeight", skip_serializing_if = "Option::is_none")] pub row_height: Option, + #[serde(alias = "columnSizes", skip_serializing_if = "Option::is_none")] pub column_sizes: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct DashboardRowItem { pub id: String, } diff --git a/api/libs/handlers/src/favorites/favorites_utils.rs b/api/libs/handlers/src/favorites/favorites_utils.rs index d29c04c65..ba70a08b3 100644 --- a/api/libs/handlers/src/favorites/favorites_utils.rs +++ b/api/libs/handlers/src/favorites/favorites_utils.rs @@ -10,7 +10,7 @@ use database::{ enums::AssetType, pool::get_pg_pool, models::UserFavorite, - schema::{collections, collections_to_assets, dashboards, messages_deprecated, threads_deprecated, user_favorites, metric_files}, + schema::{collections, collections_to_assets, dashboard_files, chats, messages_deprecated, threads_deprecated, user_favorites, metric_files}, }; use middleware::AuthenticatedUser; @@ -113,10 +113,21 @@ pub async fn list_user_favorites(user: &AuthenticatedUser) -> Result { - (dashboard_fav_res, collection_fav_res, threads_fav_res, metrics_fav_res) + let chats_favorites = { + let chat_ids = Arc::new( + user_favorites + .iter() + .filter(|(_, f)| f == &AssetType::Chat) + .map(|f| f.0) + .collect::>(), + ); + tokio::spawn(async move { get_favorite_chats(chat_ids).await }) + }; + + let (dashboard_fav_res, collection_fav_res, threads_fav_res, metrics_fav_res, chats_fav_res) = + match tokio::try_join!(dashboard_favorites, collection_favorites, threads_favorites, metrics_favorites, chats_favorites) { + Ok((dashboard_fav_res, collection_fav_res, threads_fav_res, metrics_fav_res, chats_fav_res)) => { + (dashboard_fav_res, collection_fav_res, threads_fav_res, metrics_fav_res, chats_fav_res) } Err(e) => { tracing::error!("Error getting favorite assets: {}", e); @@ -156,6 +167,14 @@ pub async fn list_user_favorites(user: &AuthenticatedUser) -> Result chats, + Err(e) => { + tracing::error!("Error getting favorite chats: {}", e); + return Err(anyhow!("Error getting favorite chats: {}", e)); + } + }; + let mut favorites: Vec = Vec::with_capacity(user_favorites.len()); for favorite in &user_favorites { @@ -183,6 +202,11 @@ pub async fn list_user_favorites(user: &AuthenticatedUser) -> Result { + if let Some(chat) = favorite_chats.iter().find(|c| c.id == favorite.0) { + favorites.push(FavoriteEnum::Object(chat.clone())); + } + } _ => {} } } @@ -231,16 +255,16 @@ async fn get_favorite_dashboards(dashboard_ids: Arc>) -> Result return Err(anyhow!("Error getting connection from pool: {:?}", e)), }; - let dashboard_records: Vec<(Uuid, String)> = match dashboards::table - .select((dashboards::id, dashboards::name)) - .filter(dashboards::id.eq_any(dashboard_ids.as_ref())) - .filter(dashboards::deleted_at.is_null()) + let dashboard_records: Vec<(Uuid, String)> = match dashboard_files::table + .select((dashboard_files::id, dashboard_files::name)) + .filter(dashboard_files::id.eq_any(dashboard_ids.as_ref())) + .filter(dashboard_files::deleted_at.is_null()) .load::<(Uuid, String)>(&mut conn) .await { Ok(dashboard_records) => dashboard_records, - Err(diesel::NotFound) => return Err(anyhow!("Dashboards not found")), - Err(e) => return Err(anyhow!("Error loading dashboard records: {:?}", e)), + Err(diesel::NotFound) => return Err(anyhow!("Dashboard files not found")), + Err(e) => return Err(anyhow!("Error loading dashboard file records: {:?}", e)), }; let favorite_dashboards = dashboard_records @@ -254,6 +278,35 @@ async fn get_favorite_dashboards(dashboard_ids: Arc>) -> Result>) -> Result> { + let mut conn = match get_pg_pool().get().await { + Ok(conn) => conn, + Err(e) => return Err(anyhow!("Error getting connection from pool: {:?}", e)), + }; + + let chat_records: Vec<(Uuid, String)> = match chats::table + .select((chats::id, chats::title)) + .filter(chats::id.eq_any(chat_ids.as_ref())) + .filter(chats::deleted_at.is_null()) + .load::<(Uuid, String)>(&mut conn) + .await + { + Ok(chat_records) => chat_records, + Err(diesel::NotFound) => return Err(anyhow!("Chats not found")), + Err(e) => return Err(anyhow!("Error loading chat records: {:?}", e)), + }; + + let favorite_chats = chat_records + .iter() + .map(|(id, title)| FavoriteObject { + id: *id, + name: title.clone(), + type_: AssetType::Chat, + }) + .collect(); + Ok(favorite_chats) +} + async fn get_assets_from_collections( collection_ids: Arc>, ) -> Result> { @@ -366,18 +419,18 @@ async fn get_dashboards_from_collections( Err(e) => return Err(anyhow!("Error getting connection from pool: {:?}", e)), }; - let dashboard_records: Vec<(Uuid, Uuid, String)> = match dashboards::table + let dashboard_records: Vec<(Uuid, Uuid, String)> = match dashboard_files::table .inner_join( - collections_to_assets::table.on(dashboards::id.eq(collections_to_assets::asset_id)), + collections_to_assets::table.on(dashboard_files::id.eq(collections_to_assets::asset_id)), ) .select(( collections_to_assets::collection_id, - dashboards::id, - dashboards::name, + dashboard_files::id, + dashboard_files::name, )) .filter(collections_to_assets::collection_id.eq_any(collection_ids)) .filter(collections_to_assets::asset_type.eq(AssetType::Dashboard)) - .filter(dashboards::deleted_at.is_null()) + .filter(dashboard_files::deleted_at.is_null()) .filter(collections_to_assets::deleted_at.is_null()) .load::<(Uuid, Uuid, String)>(&mut conn) .await