mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: create default grid
This commit is contained in:
@ -12,7 +12,7 @@ use bytes::Bytes;
|
||||
use chrono::Utc;
|
||||
|
||||
use flowy_collaboration::client_document::default::{initial_quill_delta_string, initial_read_me};
|
||||
use flowy_collaboration::entities::revision::RepeatedRevision;
|
||||
|
||||
use flowy_collaboration::{client_folder::FolderPad, entities::ws_data::ServerRevisionWSData};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_folder_data_model::entities::view::ViewDataType;
|
||||
@ -164,7 +164,7 @@ impl FolderManager {
|
||||
let _ = self.persistence.initialize(user_id, &folder_id).await?;
|
||||
|
||||
let pool = self.persistence.db_pool()?;
|
||||
let disk_cache = Arc::new(SQLiteTextBlockRevisionPersistence::new(&user_id, pool));
|
||||
let disk_cache = Arc::new(SQLiteTextBlockRevisionPersistence::new(user_id, pool));
|
||||
let rev_persistence = Arc::new(RevisionPersistence::new(user_id, folder_id.as_ref(), disk_cache));
|
||||
let rev_manager = RevisionManager::new(user_id, folder_id.as_ref(), rev_persistence);
|
||||
|
||||
@ -214,7 +214,7 @@ impl DefaultFolderBuilder {
|
||||
};
|
||||
let _ = view_controller.set_latest_view(&view.id);
|
||||
let _ = view_controller
|
||||
.create_view(&view.id, ViewDataType::Block, Bytes::from(view_data))
|
||||
.create_view(&view.id, ViewDataType::TextBlock, Bytes::from(view_data))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@ -239,7 +239,7 @@ impl FolderManager {
|
||||
pub trait ViewDataProcessor {
|
||||
fn initialize(&self) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn create_container(&self, view_id: &str, repeated_revision: RepeatedRevision) -> FutureResult<(), FlowyError>;
|
||||
fn create_container(&self, user_id: &str, view_id: &str, delta_data: Bytes) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn delete_container(&self, view_id: &str) -> FutureResult<(), FlowyError>;
|
||||
|
||||
@ -247,7 +247,7 @@ pub trait ViewDataProcessor {
|
||||
|
||||
fn delta_str(&self, view_id: &str) -> FutureResult<String, FlowyError>;
|
||||
|
||||
fn default_view_data(&self, view_id: &str) -> String;
|
||||
fn create_default_view(&self, user_id: &str, view_id: &str) -> FutureResult<String, FlowyError>;
|
||||
|
||||
fn data_type(&self) -> ViewDataType;
|
||||
}
|
||||
|
@ -8,14 +8,14 @@ use crate::manager::FolderId;
|
||||
use bytes::Bytes;
|
||||
use flowy_collaboration::util::make_delta_from_revisions;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sync::disk::RevisionDiskCache;
|
||||
|
||||
use flowy_sync::{
|
||||
RevisionCloudService, RevisionCompactor, RevisionManager, RevisionObjectBuilder, RevisionPersistence,
|
||||
RevisionWebSocket, RevisionWebSocketManager,
|
||||
RevisionCloudService, RevisionCompactor, RevisionManager, RevisionObjectBuilder, RevisionWebSocket,
|
||||
RevisionWebSocketManager,
|
||||
};
|
||||
use lib_infra::future::FutureResult;
|
||||
use lib_ot::core::{Delta, PlainTextAttributes};
|
||||
use lib_sqlite::ConnectionPool;
|
||||
use lib_ot::core::PlainTextAttributes;
|
||||
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -88,7 +88,7 @@ impl FolderMigration {
|
||||
return Ok(None);
|
||||
}
|
||||
let pool = self.database.db_pool()?;
|
||||
let disk_cache = Arc::new(SQLiteTextBlockRevisionPersistence::new(&user_id, pool));
|
||||
let disk_cache = Arc::new(SQLiteTextBlockRevisionPersistence::new(user_id, pool));
|
||||
let rev_persistence = Arc::new(RevisionPersistence::new(user_id, folder_id.as_ref(), disk_cache));
|
||||
let (revisions, _) = RevisionLoader {
|
||||
object_id: folder_id.as_ref().to_owned(),
|
||||
|
@ -84,7 +84,7 @@ pub(crate) struct ViewTable {
|
||||
impl ViewTable {
|
||||
pub fn new(view: View) -> Self {
|
||||
let data_type = match view.data_type {
|
||||
ViewDataType::Block => SqlViewDataType::Block,
|
||||
ViewDataType::TextBlock => SqlViewDataType::Block,
|
||||
ViewDataType::Grid => SqlViewDataType::Grid,
|
||||
};
|
||||
|
||||
@ -106,7 +106,7 @@ impl ViewTable {
|
||||
impl std::convert::From<ViewTable> for View {
|
||||
fn from(table: ViewTable) -> Self {
|
||||
let data_type = match table.view_type {
|
||||
SqlViewDataType::Block => ViewDataType::Block,
|
||||
SqlViewDataType::Block => ViewDataType::TextBlock,
|
||||
SqlViewDataType::Grid => ViewDataType::Grid,
|
||||
};
|
||||
|
||||
|
@ -13,10 +13,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use flowy_collaboration::entities::{
|
||||
revision::{RepeatedRevision, Revision},
|
||||
text_block_info::TextBlockId,
|
||||
};
|
||||
use flowy_collaboration::entities::text_block_info::TextBlockId;
|
||||
use flowy_database::kv::KV;
|
||||
use flowy_folder_data_model::entities::view::ViewDataType;
|
||||
use futures::{FutureExt, StreamExt};
|
||||
@ -58,18 +55,18 @@ impl ViewController {
|
||||
#[tracing::instrument(level = "trace", skip(self, params), fields(name = %params.name), err)]
|
||||
pub(crate) async fn create_view_from_params(&self, mut params: CreateViewParams) -> Result<View, FlowyError> {
|
||||
let processor = self.get_data_processor(¶ms.data_type)?;
|
||||
let content = if params.data.is_empty() {
|
||||
let default_view_data = processor.default_view_data(¶ms.view_id);
|
||||
params.data = default_view_data.clone();
|
||||
default_view_data
|
||||
|
||||
if params.data.is_empty() {
|
||||
let user_id = self.user.user_id()?;
|
||||
let view_data = processor.create_default_view(&user_id, ¶ms.view_id).await?;
|
||||
params.data = view_data;
|
||||
} else {
|
||||
params.data.clone()
|
||||
let delta_data = Bytes::from(params.data.clone());
|
||||
let _ = self
|
||||
.create_view(¶ms.view_id, params.data_type.clone(), delta_data)
|
||||
.await?;
|
||||
};
|
||||
|
||||
let delta_data = Bytes::from(content);
|
||||
let _ = self
|
||||
.create_view(¶ms.view_id, params.data_type.clone(), delta_data)
|
||||
.await?;
|
||||
let view = self.create_view_on_server(params).await?;
|
||||
let _ = self.create_view_on_local(view.clone()).await?;
|
||||
Ok(view)
|
||||
@ -86,9 +83,8 @@ impl ViewController {
|
||||
return Err(FlowyError::internal().context("The content of the view should not be empty"));
|
||||
}
|
||||
let user_id = self.user.user_id()?;
|
||||
let repeated_revision: RepeatedRevision = Revision::initial_revision(&user_id, view_id, delta_data).into();
|
||||
let processor = self.get_data_processor(&data_type)?;
|
||||
let _ = processor.create_container(view_id, repeated_revision).await?;
|
||||
let _ = processor.create_container(&user_id, view_id, delta_data).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::script::{invalid_workspace_name_test_case, FolderScript::*, FolderTest};
|
||||
use flowy_collaboration::{client_document::default::initial_quill_delta_string, entities::revision::RevisionState};
|
||||
|
||||
use flowy_folder::entities::workspace::CreateWorkspacePayload;
|
||||
use flowy_sync::disk::RevisionState;
|
||||
use flowy_test::{event_builder::*, FlowySDKTest};
|
||||
|
||||
#[tokio::test]
|
||||
@ -168,16 +169,6 @@ async fn view_update() {
|
||||
assert_eq!(test.view.name, new_name);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn open_document_view() {
|
||||
let mut test = FolderTest::new().await;
|
||||
assert_eq!(test.document_info, None);
|
||||
|
||||
test.run_scripts(vec![OpenDocument]).await;
|
||||
let document_info = test.document_info.unwrap();
|
||||
assert_eq!(document_info.text, initial_quill_delta_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[should_panic]
|
||||
async fn view_delete() {
|
||||
|
@ -161,7 +161,8 @@ pub async fn delete_view(sdk: &FlowySDKTest, view_ids: Vec<String>) {
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn open_document(sdk: &FlowySDKTest, view_id: &str) -> TextBlockInfo {
|
||||
#[allow(dead_code)]
|
||||
pub async fn set_latest_view(sdk: &FlowySDKTest, view_id: &str) -> TextBlockInfo {
|
||||
let view_id: ViewId = view_id.into();
|
||||
FolderEventBuilder::new(sdk.clone())
|
||||
.event(SetLatestView)
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::helper::*;
|
||||
use flowy_collaboration::entities::{revision::RevisionState, text_block_info::TextBlockInfo};
|
||||
|
||||
use flowy_folder::{errors::ErrorCode, services::folder_editor::ClientFolderEditor};
|
||||
use flowy_folder_data_model::entities::{
|
||||
app::{App, RepeatedApp},
|
||||
@ -7,6 +7,7 @@ use flowy_folder_data_model::entities::{
|
||||
view::{RepeatedView, View, ViewDataType},
|
||||
workspace::Workspace,
|
||||
};
|
||||
use flowy_sync::disk::RevisionState;
|
||||
use flowy_sync::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
||||
use flowy_test::FlowySDKTest;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
@ -42,9 +43,6 @@ pub enum FolderScript {
|
||||
ReadTrash,
|
||||
DeleteAllTrash,
|
||||
|
||||
// Document
|
||||
OpenDocument,
|
||||
|
||||
// Sync
|
||||
AssertCurrentRevId(i64),
|
||||
AssertNextSyncRevId(Option<i64>),
|
||||
@ -58,7 +56,6 @@ pub struct FolderTest {
|
||||
pub app: App,
|
||||
pub view: View,
|
||||
pub trash: Vec<Trash>,
|
||||
pub document_info: Option<TextBlockInfo>,
|
||||
// pub folder_editor:
|
||||
}
|
||||
|
||||
@ -68,7 +65,14 @@ impl FolderTest {
|
||||
let _ = sdk.init_user().await;
|
||||
let mut workspace = create_workspace(&sdk, "FolderWorkspace", "Folder test workspace").await;
|
||||
let mut app = create_app(&sdk, &workspace.id, "Folder App", "Folder test app").await;
|
||||
let view = create_view(&sdk, &app.id, "Folder View", "Folder test view", ViewDataType::Block).await;
|
||||
let view = create_view(
|
||||
&sdk,
|
||||
&app.id,
|
||||
"Folder View",
|
||||
"Folder test view",
|
||||
ViewDataType::TextBlock,
|
||||
)
|
||||
.await;
|
||||
app.belongings = RepeatedView {
|
||||
items: vec![view.clone()],
|
||||
};
|
||||
@ -83,7 +87,6 @@ impl FolderTest {
|
||||
app,
|
||||
view,
|
||||
trash: vec![],
|
||||
document_info: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +149,7 @@ impl FolderTest {
|
||||
}
|
||||
|
||||
FolderScript::CreateView { name, desc } => {
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, ViewDataType::Block).await;
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, ViewDataType::TextBlock).await;
|
||||
self.view = view;
|
||||
}
|
||||
FolderScript::AssertView(view) => {
|
||||
@ -179,10 +182,6 @@ impl FolderTest {
|
||||
delete_all_trash(sdk).await;
|
||||
self.trash = vec![];
|
||||
}
|
||||
FolderScript::OpenDocument => {
|
||||
let document_info = open_document(sdk, &self.view.id).await;
|
||||
self.document_info = Some(document_info);
|
||||
}
|
||||
FolderScript::AssertRevisionState { rev_id, state } => {
|
||||
let record = cache.get(rev_id).await.unwrap();
|
||||
assert_eq!(record.state, state);
|
||||
|
Reference in New Issue
Block a user