mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: replace plugin type with layout type
This commit is contained in:
@ -7,7 +7,7 @@ use crate::{
|
||||
impl_def_and_def_mut,
|
||||
};
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewRevision};
|
||||
use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
@ -31,7 +31,7 @@ pub struct ViewPB {
|
||||
pub create_time: i64,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub plugin_type: i32,
|
||||
pub layout: ViewLayoutTypePB,
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewRevision> for ViewPB {
|
||||
@ -43,14 +43,14 @@ impl std::convert::From<ViewRevision> for ViewPB {
|
||||
data_type: rev.data_type.into(),
|
||||
modified_time: rev.modified_time,
|
||||
create_time: rev.create_time,
|
||||
plugin_type: rev.plugin_type,
|
||||
layout: rev.layout.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
||||
pub enum ViewDataTypePB {
|
||||
Document = 0,
|
||||
Text = 0,
|
||||
Database = 1,
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ impl std::default::Default for ViewDataTypePB {
|
||||
impl std::convert::From<ViewDataTypeRevision> for ViewDataTypePB {
|
||||
fn from(rev: ViewDataTypeRevision) -> Self {
|
||||
match rev {
|
||||
ViewDataTypeRevision::Document => ViewDataTypePB::Document,
|
||||
ViewDataTypeRevision::Text => ViewDataTypePB::Text,
|
||||
ViewDataTypeRevision::Database => ViewDataTypePB::Database,
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ impl std::convert::From<ViewDataTypeRevision> for ViewDataTypePB {
|
||||
impl std::convert::From<ViewDataTypePB> for ViewDataTypeRevision {
|
||||
fn from(ty: ViewDataTypePB) -> Self {
|
||||
match ty {
|
||||
ViewDataTypePB::Document => ViewDataTypeRevision::Document,
|
||||
ViewDataTypePB::Text => ViewDataTypeRevision::Text,
|
||||
ViewDataTypePB::Database => ViewDataTypeRevision::Database,
|
||||
}
|
||||
}
|
||||
@ -80,8 +80,9 @@ impl std::convert::From<ViewDataTypePB> for ViewDataTypeRevision {
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
||||
pub enum ViewLayoutTypePB {
|
||||
Grid = 0,
|
||||
Board = 1,
|
||||
Document = 0,
|
||||
Grid = 3,
|
||||
Board = 4,
|
||||
}
|
||||
|
||||
impl std::default::Default for ViewLayoutTypePB {
|
||||
@ -90,6 +91,26 @@ impl std::default::Default for ViewLayoutTypePB {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewLayoutTypeRevision> for ViewLayoutTypePB {
|
||||
fn from(rev: ViewLayoutTypeRevision) -> Self {
|
||||
match rev {
|
||||
ViewLayoutTypeRevision::Grid => ViewLayoutTypePB::Grid,
|
||||
ViewLayoutTypeRevision::Board => ViewLayoutTypePB::Board,
|
||||
ViewLayoutTypeRevision::Document => ViewLayoutTypePB::Document,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewLayoutTypePB> for ViewLayoutTypeRevision {
|
||||
fn from(rev: ViewLayoutTypePB) -> Self {
|
||||
match rev {
|
||||
ViewLayoutTypePB::Grid => ViewLayoutTypeRevision::Grid,
|
||||
ViewLayoutTypePB::Board => ViewLayoutTypeRevision::Board,
|
||||
ViewLayoutTypePB::Document => ViewLayoutTypeRevision::Document,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
||||
pub struct RepeatedViewPB {
|
||||
#[pb(index = 1)]
|
||||
@ -131,9 +152,6 @@ pub struct CreateViewPayloadPB {
|
||||
pub layout: ViewLayoutTypePB,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub plugin_type: i32,
|
||||
|
||||
#[pb(index = 8)]
|
||||
pub view_content_data: Vec<u8>,
|
||||
}
|
||||
|
||||
@ -147,7 +165,6 @@ pub struct CreateViewParams {
|
||||
pub layout: ViewLayoutTypePB,
|
||||
pub view_id: String,
|
||||
pub view_content_data: Vec<u8>,
|
||||
pub plugin_type: i32,
|
||||
}
|
||||
|
||||
impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
||||
@ -171,7 +188,6 @@ impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
||||
thumbnail,
|
||||
view_id,
|
||||
view_content_data: self.view_content_data,
|
||||
plugin_type: self.plugin_type,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ impl DefaultFolderBuilder {
|
||||
};
|
||||
let _ = view_controller.set_latest_view(&view.id);
|
||||
let _ = view_controller
|
||||
.create_view(&view.id, ViewDataTypePB::Document, Bytes::from(view_data))
|
||||
.create_view(&view.id, ViewDataTypePB::Text, Bytes::from(view_data))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use flowy_database::{
|
||||
SqliteConnection,
|
||||
};
|
||||
|
||||
use flowy_folder_data_model::revision::{ViewDataTypeRevision, ViewRevision};
|
||||
use flowy_folder_data_model::revision::{ViewDataTypeRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use lib_infra::util::timestamp;
|
||||
|
||||
pub struct ViewTableSql();
|
||||
@ -87,7 +87,7 @@ pub(crate) struct ViewTable {
|
||||
impl ViewTable {
|
||||
pub fn new(view_rev: ViewRevision) -> Self {
|
||||
let data_type = match view_rev.data_type {
|
||||
ViewDataTypeRevision::Document => SqlViewDataType::Block,
|
||||
ViewDataTypeRevision::Text => SqlViewDataType::Block,
|
||||
ViewDataTypeRevision::Database => SqlViewDataType::Grid,
|
||||
};
|
||||
|
||||
@ -110,7 +110,7 @@ impl ViewTable {
|
||||
impl std::convert::From<ViewTable> for ViewRevision {
|
||||
fn from(table: ViewTable) -> Self {
|
||||
let data_type = match table.view_type {
|
||||
SqlViewDataType::Block => ViewDataTypeRevision::Document,
|
||||
SqlViewDataType::Block => ViewDataTypeRevision::Text,
|
||||
SqlViewDataType::Grid => ViewDataTypeRevision::Database,
|
||||
};
|
||||
|
||||
@ -127,8 +127,8 @@ impl std::convert::From<ViewTable> for ViewRevision {
|
||||
ext_data: "".to_string(),
|
||||
thumbnail: table.thumbnail,
|
||||
// Store the view in ViewTable was deprecated since v0.0.2.
|
||||
// No need to worry about plugin_type.
|
||||
plugin_type: 0,
|
||||
// No need to worry about layout.
|
||||
layout: ViewLayoutTypeRevision::Document,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,10 +220,9 @@ impl ViewController {
|
||||
desc: view_rev.desc,
|
||||
thumbnail: view_rev.thumbnail,
|
||||
data_type: view_rev.data_type.into(),
|
||||
layout: ViewLayoutTypePB::Board,
|
||||
layout: view_rev.layout.into(),
|
||||
view_content_data: delta_bytes.to_vec(),
|
||||
view_id: gen_view_id(),
|
||||
plugin_type: view_rev.plugin_type,
|
||||
};
|
||||
|
||||
let _ = self.create_view_from_params(duplicate_params).await?;
|
||||
@ -468,7 +467,7 @@ fn make_view_rev_from(params: CreateViewParams) -> ViewRevision {
|
||||
create_time: time,
|
||||
ext_data: "".to_string(),
|
||||
thumbnail: params.thumbnail,
|
||||
plugin_type: params.plugin_type,
|
||||
layout: params.layout.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ async fn app_create_with_view() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
@ -198,7 +198,7 @@ async fn view_delete_all() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
@ -231,7 +231,7 @@ async fn view_delete_all_permanent() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
ReadApp(app.id.clone()),
|
||||
])
|
||||
@ -330,7 +330,7 @@ async fn folder_sync_revision_with_new_view() {
|
||||
CreateView {
|
||||
name: view_name.clone(),
|
||||
desc: view_desc.clone(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
AssertCurrentRevId(3),
|
||||
AssertNextSyncRevId(Some(3)),
|
||||
|
@ -53,6 +53,7 @@ pub enum FolderScript {
|
||||
name: String,
|
||||
desc: String,
|
||||
data_type: ViewDataTypePB,
|
||||
layout: ViewLayoutTypePB,
|
||||
},
|
||||
AssertView(ViewPB),
|
||||
ReadView(String),
|
||||
@ -99,7 +100,8 @@ impl FolderTest {
|
||||
&app.id,
|
||||
"Folder View",
|
||||
"Folder test view",
|
||||
ViewDataTypePB::Document,
|
||||
ViewDataTypePB::Text,
|
||||
ViewLayoutTypePB::Document,
|
||||
)
|
||||
.await;
|
||||
app.belongings = RepeatedViewPB {
|
||||
@ -179,8 +181,13 @@ impl FolderTest {
|
||||
delete_app(sdk, &self.app.id).await;
|
||||
}
|
||||
|
||||
FolderScript::CreateView { name, desc, data_type } => {
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, data_type).await;
|
||||
FolderScript::CreateView {
|
||||
name,
|
||||
desc,
|
||||
data_type,
|
||||
layout,
|
||||
} => {
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, data_type, layout).await;
|
||||
self.view = view;
|
||||
}
|
||||
FolderScript::AssertView(view) => {
|
||||
@ -353,20 +360,15 @@ pub async fn create_view(
|
||||
name: &str,
|
||||
desc: &str,
|
||||
data_type: ViewDataTypePB,
|
||||
layout: ViewLayoutTypePB,
|
||||
) -> ViewPB {
|
||||
let sub_data_type = match data_type {
|
||||
ViewDataTypePB::Document => None,
|
||||
ViewDataTypePB::Database => Some(ViewLayoutTypePB::Grid),
|
||||
};
|
||||
|
||||
let request = CreateViewPayloadPB {
|
||||
belong_to_id: app_id.to_string(),
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
thumbnail: None,
|
||||
data_type,
|
||||
layout: sub_data_type,
|
||||
plugin_type: 0,
|
||||
layout,
|
||||
view_content_data: vec![],
|
||||
};
|
||||
let view = FolderEventBuilder::new(sdk.clone())
|
||||
|
Reference in New Issue
Block a user