chore: rename folder builder for re-use (#5020)

This commit is contained in:
Richard Shiue 2024-04-10 11:40:02 +08:00 committed by GitHub
parent 17df31a512
commit 12ec90ada0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 26 deletions

View File

@ -1,4 +1,10 @@
use std::collections::HashMap;
use std::convert::TryFrom;
use std::sync::{Arc, Weak};
use bytes::Bytes;
use tokio::sync::RwLock;
use collab_integrate::collab_builder::AppFlowyCollabBuilder;
use collab_integrate::CollabKVDB;
use flowy_database2::entities::DatabaseLayoutPB;
@ -14,19 +20,14 @@ use flowy_folder::manager::{FolderManager, FolderUser};
use flowy_folder::share::ImportType;
use flowy_folder::view_operation::{FolderOperationHandler, FolderOperationHandlers, View};
use flowy_folder::ViewLayout;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::sync::{Arc, Weak};
use tokio::sync::RwLock;
use flowy_folder_pub::folder_builder::WorkspaceViewBuilder;
use flowy_folder_pub::folder_builder::NestedViewBuilder;
use flowy_user::services::authenticate_user::AuthenticateUser;
use crate::integrate::server::ServerProvider;
use lib_dispatch::prelude::ToBytes;
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
use crate::integrate::server::ServerProvider;
pub struct FolderDepsResolver();
impl FolderDepsResolver {
pub async fn resolve(
@ -98,7 +99,7 @@ impl FolderOperationHandler for DocumentFolderOperation {
fn create_workspace_view(
&self,
uid: i64,
workspace_view_builder: Arc<RwLock<WorkspaceViewBuilder>>,
workspace_view_builder: Arc<RwLock<NestedViewBuilder>>,
) -> FutureResult<(), FlowyError> {
let manager = self.0.clone();
FutureResult::new(async move {

View File

@ -1,21 +1,22 @@
use std::future::Future;
use crate::cloud::gen_view_id;
use collab_folder::{RepeatedViewIdentifier, View, ViewIcon, ViewIdentifier, ViewLayout};
use lib_infra::util::timestamp;
use std::future::Future;
/// A builder for creating a view for a workspace.
/// The views created by this builder will be the first level views of the workspace.
pub struct WorkspaceViewBuilder {
/// A builder for creating views, each able to have children views of
/// their own.
pub struct NestedViewBuilder {
pub uid: i64,
pub workspace_id: String,
pub parent_view_id: String,
pub views: Vec<ParentChildViews>,
}
impl WorkspaceViewBuilder {
pub fn new(workspace_id: String, uid: i64) -> Self {
impl NestedViewBuilder {
pub fn new(parent_view_id: String, uid: i64) -> Self {
Self {
uid,
workspace_id,
parent_view_id,
views: vec![],
}
}
@ -25,7 +26,7 @@ impl WorkspaceViewBuilder {
F: Fn(ViewBuilder) -> O,
O: Future<Output = ParentChildViews>,
{
let builder = ViewBuilder::new(self.uid, self.workspace_id.clone());
let builder = ViewBuilder::new(self.uid, self.parent_view_id.clone());
self.views.push(view_builder(builder).await);
}
@ -182,12 +183,12 @@ impl FlattedViews {
#[cfg(test)]
mod tests {
use crate::folder_builder::{FlattedViews, WorkspaceViewBuilder};
use crate::folder_builder::{FlattedViews, NestedViewBuilder};
#[tokio::test]
async fn create_first_level_views_test() {
let workspace_id = "w1".to_string();
let mut builder = WorkspaceViewBuilder::new(workspace_id, 1);
let mut builder = NestedViewBuilder::new(workspace_id, 1);
builder
.with_view_builder(|view_builder| async { view_builder.with_name("1").build() })
.await;
@ -207,7 +208,7 @@ mod tests {
#[tokio::test]
async fn create_view_with_child_views_test() {
let workspace_id = "w1".to_string();
let mut builder = WorkspaceViewBuilder::new(workspace_id, 1);
let mut builder = NestedViewBuilder::new(workspace_id, 1);
builder
.with_view_builder(|view_builder| async {
view_builder
@ -247,10 +248,11 @@ mod tests {
let views = FlattedViews::flatten_views(workspace_views);
assert_eq!(views.len(), 5);
}
#[tokio::test]
async fn create_three_level_view_test() {
let workspace_id = "w1".to_string();
let mut builder = WorkspaceViewBuilder::new(workspace_id, 1);
let mut builder = NestedViewBuilder::new(workspace_id, 1);
builder
.with_view_builder(|view_builder| async {
view_builder

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use collab_folder::{FolderData, RepeatedViewIdentifier, ViewIdentifier, Workspace};
use flowy_folder_pub::folder_builder::{FlattedViews, ParentChildViews, WorkspaceViewBuilder};
use flowy_folder_pub::folder_builder::{FlattedViews, NestedViewBuilder, ParentChildViews};
use tokio::sync::RwLock;
use lib_infra::util::timestamp;
@ -16,7 +16,7 @@ impl DefaultFolderBuilder {
workspace_id: String,
handlers: &FolderOperationHandlers,
) -> FolderData {
let workspace_view_builder = Arc::new(RwLock::new(WorkspaceViewBuilder::new(
let workspace_view_builder = Arc::new(RwLock::new(NestedViewBuilder::new(
workspace_id.clone(),
uid,
)));

View File

@ -8,7 +8,7 @@ use tokio::sync::RwLock;
use flowy_error::FlowyError;
use flowy_folder_pub::folder_builder::WorkspaceViewBuilder;
use flowy_folder_pub::folder_builder::NestedViewBuilder;
use lib_infra::future::FutureResult;
use lib_infra::util::timestamp;
@ -27,7 +27,7 @@ pub trait FolderOperationHandler {
fn create_workspace_view(
&self,
_uid: i64,
_workspace_view_builder: Arc<RwLock<WorkspaceViewBuilder>>,
_workspace_view_builder: Arc<RwLock<NestedViewBuilder>>,
) -> FutureResult<(), FlowyError> {
FutureResult::new(async { Ok(()) })
}