feat: use folder view minimal for database list
This commit is contained in:
parent
a6bd54f447
commit
ddecd8457c
|
|
@ -330,7 +330,7 @@ pub struct PublishedView {
|
||||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AFDatabase {
|
pub struct AFDatabase {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub names: Vec<String>,
|
pub views: Vec<FolderViewMinimal>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
|
|
@ -339,12 +339,6 @@ pub struct AFDatabaseField {
|
||||||
pub field_type: String,
|
pub field_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
||||||
pub struct AFDatabaseMeta {
|
|
||||||
pub name: String,
|
|
||||||
pub icon: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AFDatabaseRow {
|
pub struct AFDatabaseRow {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ use shared_entity::dto::workspace_dto::AFDatabase;
|
||||||
use shared_entity::dto::workspace_dto::AFDatabaseRow;
|
use shared_entity::dto::workspace_dto::AFDatabaseRow;
|
||||||
use shared_entity::dto::workspace_dto::AFDatabaseRowDetail;
|
use shared_entity::dto::workspace_dto::AFDatabaseRowDetail;
|
||||||
use shared_entity::dto::workspace_dto::FavoriteFolderView;
|
use shared_entity::dto::workspace_dto::FavoriteFolderView;
|
||||||
|
use shared_entity::dto::workspace_dto::FolderViewMinimal;
|
||||||
use shared_entity::dto::workspace_dto::RecentFolderView;
|
use shared_entity::dto::workspace_dto::RecentFolderView;
|
||||||
use shared_entity::dto::workspace_dto::TrashFolderView;
|
use shared_entity::dto::workspace_dto::TrashFolderView;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
@ -47,6 +48,7 @@ use super::folder_view::collab_folder_to_folder_view;
|
||||||
use super::folder_view::section_items_to_favorite_folder_view;
|
use super::folder_view::section_items_to_favorite_folder_view;
|
||||||
use super::folder_view::section_items_to_recent_folder_view;
|
use super::folder_view::section_items_to_recent_folder_view;
|
||||||
use super::folder_view::section_items_to_trash_folder_view;
|
use super::folder_view::section_items_to_trash_folder_view;
|
||||||
|
use super::folder_view::to_dto_folder_view_miminal;
|
||||||
use super::publish_outline::collab_folder_to_published_outline;
|
use super::publish_outline::collab_folder_to_published_outline;
|
||||||
|
|
||||||
/// Create a new collab member
|
/// Create a new collab member
|
||||||
|
|
@ -416,17 +418,17 @@ pub async fn list_database(
|
||||||
let mut af_databases = Vec::with_capacity(db_metas.len());
|
let mut af_databases = Vec::with_capacity(db_metas.len());
|
||||||
for db_meta in db_metas {
|
for db_meta in db_metas {
|
||||||
let id = db_meta.database_id;
|
let id = db_meta.database_id;
|
||||||
let names: Vec<String> = db_meta
|
let views: Vec<FolderViewMinimal> = db_meta
|
||||||
.linked_views
|
.linked_views
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|view_id| {
|
.map(|view_id| {
|
||||||
folder
|
folder
|
||||||
.get_view(&view_id)
|
.get_view(&view_id)
|
||||||
.map(|v| v.name.clone())
|
.map(|view| to_dto_folder_view_miminal(&view))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
af_databases.push(AFDatabase { id, names });
|
af_databases.push(AFDatabase { id, views });
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(af_databases)
|
Ok(af_databases)
|
||||||
|
|
@ -572,9 +574,12 @@ fn convert_database_cells_human_readable(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
println!("field_type: {:#?}", field.field_type);
|
||||||
|
println!("type_options: {:#?}", field.type_options);
|
||||||
|
|
||||||
let mut human_readable_cell: HashMap<String, String> = HashMap::with_capacity(cell.len());
|
let mut human_readable_cell: HashMap<String, String> = HashMap::with_capacity(cell.len());
|
||||||
for (key, value) in cell {
|
for (key, value) in cell {
|
||||||
let serde_value: String = match key.as_str() {
|
let value_str: String = match key.as_str() {
|
||||||
"created_at" | "last_modified" => match value.cast::<i64>() {
|
"created_at" | "last_modified" => match value.cast::<i64>() {
|
||||||
Ok(timestamp) => chrono::DateTime::from_timestamp(timestamp, 0)
|
Ok(timestamp) => chrono::DateTime::from_timestamp(timestamp, 0)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
|
@ -596,7 +601,7 @@ fn convert_database_cells_human_readable(
|
||||||
},
|
},
|
||||||
_ => value.to_string(),
|
_ => value.to_string(),
|
||||||
};
|
};
|
||||||
human_readable_cell.insert(key, serde_value);
|
human_readable_cell.insert(key, value_str);
|
||||||
}
|
}
|
||||||
human_readable_records.insert(field.name.clone(), human_readable_cell);
|
human_readable_records.insert(field.name.clone(), human_readable_cell);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ async fn workspace_list_database() {
|
||||||
let dbs = c.list_databases(&workspace_id).await.unwrap();
|
let dbs = c.list_databases(&workspace_id).await.unwrap();
|
||||||
assert_eq!(dbs.len(), 1, "{:?}", dbs);
|
assert_eq!(dbs.len(), 1, "{:?}", dbs);
|
||||||
let todos_db = &dbs[0];
|
let todos_db = &dbs[0];
|
||||||
assert_eq!(todos_db.names.len(), 1);
|
assert_eq!(todos_db.views.len(), 1);
|
||||||
assert!(todos_db.names.contains(&String::from("To-dos")));
|
assert_eq!(todos_db.views[0].name, "To-dos");
|
||||||
{
|
{
|
||||||
let db_row_ids = c
|
let db_row_ids = c
|
||||||
.list_database_row_ids(&workspace_id, &todos_db.id)
|
.list_database_row_ids(&workspace_id, &todos_db.id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue