Skip to content

Commit

Permalink
feat: add support for create database pages via API
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng committed Nov 26, 2024
1 parent 9e067e6 commit 484cd59
Show file tree
Hide file tree
Showing 10 changed files with 624 additions and 47 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,18 @@ debug = true
[profile.ci]
inherits = "release"
opt-level = 2
lto = false # Disable Link-Time Optimization
lto = false # Disable Link-Time Optimization

[patch.crates-io]
# It's diffcult to resovle different version with the same crate used in AppFlowy Frontend and the Client-API crate.
# So using patch to workaround this issue.
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "be6bb90faac22ca8443a950ea3deafc7ec99b3a8" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "be6bb90faac22ca8443a950ea3deafc7ec99b3a8" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "be6bb90faac22ca8443a950ea3deafc7ec99b3a8" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "be6bb90faac22ca8443a950ea3deafc7ec99b3a8" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "be6bb90faac22ca8443a950ea3deafc7ec99b3a8" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "be6bb90faac22ca8443a950ea3deafc7ec99b3a8" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "be6bb90faac22ca8443a950ea3deafc7ec99b3a8" }
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }

[features]
history = []
Expand Down
1 change: 1 addition & 0 deletions libs/database/src/collab/collab_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub trait CollabStorageAccessControl: Send + Sync + 'static {
async fn enforce_delete(&self, workspace_id: &str, uid: &i64, oid: &str) -> Result<(), AppError>;
}

#[derive(Clone)]
pub enum GetCollabOrigin {
User { uid: i64 },
Server,
Expand Down
13 changes: 13 additions & 0 deletions libs/shared-entity/src/dto/workspace_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ pub enum ViewLayout {
Chat = 4,
}

impl std::fmt::Display for ViewLayout {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
ViewLayout::Document => "Document",
ViewLayout::Grid => "Grid",
ViewLayout::Board => "Board",
ViewLayout::Calendar => "Calendar",
ViewLayout::Chat => "Chat",
};
write!(f, "{}", s)
}
}

impl Default for ViewLayout {
fn default() -> Self {
Self::Document
Expand Down
38 changes: 38 additions & 0 deletions src/biz/collab/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use app_error::AppError;
use appflowy_collaborate::collab::storage::CollabAccessControlStorage;
use chrono::DateTime;
use chrono::Utc;
use collab::core::collab::DataSource;
use collab::preclude::Collab;
use collab_database::database::DatabaseBody;
use collab_database::entity::FieldType;
use collab_database::fields::Field;
use collab_database::fields::TypeOptions;
use collab_database::rows::RowDetail;
use collab_database::workspace_database::NoPersistenceDatabaseCollabService;
use collab_database::workspace_database::WorkspaceDatabase;
use collab_database::workspace_database::WorkspaceDatabaseBody;
use collab_entity::CollabType;
use collab_entity::EncodedCollab;
Expand Down Expand Up @@ -295,6 +297,30 @@ pub async fn get_user_workspace_structure(
collab_folder_to_folder_view(root_view_id, &folder, depth, &publish_view_ids)
}

pub async fn get_latest_workspace_database(
collab_storage: &CollabAccessControlStorage,
pg_pool: &PgPool,
collab_origin: GetCollabOrigin,
workspace_id: Uuid,
) -> Result<(String, WorkspaceDatabase), AppError> {
let workspace_database_oid = select_workspace_database_oid(pg_pool, &workspace_id).await?;
let workspace_database_collab = {
let encoded_collab = get_latest_collab_encoded(
collab_storage,
collab_origin,
&workspace_id.to_string(),
&workspace_database_oid,
CollabType::WorkspaceDatabase,
)
.await?;
collab_from_doc_state(encoded_collab.doc_state.to_vec(), &workspace_database_oid)?
};

let workspace_database = WorkspaceDatabase::open(workspace_database_collab)
.map_err(|err| AppError::Unhandled(format!("failed to open workspace database: {}", err)))?;
Ok((workspace_database_oid, workspace_database))
}

pub async fn get_latest_collab_folder(
collab_storage: &CollabAccessControlStorage,
collab_origin: GetCollabOrigin,
Expand Down Expand Up @@ -736,3 +762,15 @@ fn add_to_selection_from_type_options(
}
};
}

pub fn collab_from_doc_state(doc_state: Vec<u8>, object_id: &str) -> Result<Collab, AppError> {
let collab = Collab::new_with_source(
CollabOrigin::Server,
object_id,
DataSource::DocStateV1(doc_state),
vec![],
false,
)
.map_err(|e| AppError::Unhandled(e.to_string()))?;
Ok(collab)
}
14 changes: 0 additions & 14 deletions src/biz/workspace/ops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use authentication::jwt::OptionalUserUuid;
use collab::core::collab::DataSource;
use collab::preclude::Collab;
use collab_folder::CollabOrigin;
use collab_rt_entity::{ClientCollabMessage, UpdateSync};
use collab_rt_protocol::{Message, SyncMessage};
Expand Down Expand Up @@ -750,15 +748,3 @@ pub async fn broadcast_update(

Ok(())
}

pub fn collab_from_doc_state(doc_state: Vec<u8>, object_id: &str) -> Result<Collab, AppError> {
let collab = Collab::new_with_source(
CollabOrigin::Server,
object_id,
DataSource::DocStateV1(doc_state),
vec![],
false,
)
.map_err(|e| AppError::Unhandled(e.to_string()))?;
Ok(collab)
}
Loading

0 comments on commit 484cd59

Please sign in to comment.