mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add sub data type
This commit is contained in:
@ -22,7 +22,7 @@ pub struct ViewPB {
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub data_type: ViewDataType,
|
||||
pub data_type: ViewDataTypePB,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub modified_time: i64,
|
||||
@ -49,31 +49,37 @@ impl std::convert::From<ViewRevision> for ViewPB {
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
||||
pub enum ViewDataType {
|
||||
pub enum ViewDataTypePB {
|
||||
TextBlock = 0,
|
||||
Grid = 1,
|
||||
Database = 1,
|
||||
}
|
||||
|
||||
impl std::default::Default for ViewDataType {
|
||||
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
||||
pub enum SubViewDataTypePB {
|
||||
Grid = 0,
|
||||
Board = 1,
|
||||
}
|
||||
|
||||
impl std::default::Default for ViewDataTypePB {
|
||||
fn default() -> Self {
|
||||
ViewDataTypeRevision::default().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewDataTypeRevision> for ViewDataType {
|
||||
impl std::convert::From<ViewDataTypeRevision> for ViewDataTypePB {
|
||||
fn from(rev: ViewDataTypeRevision) -> Self {
|
||||
match rev {
|
||||
ViewDataTypeRevision::TextBlock => ViewDataType::TextBlock,
|
||||
ViewDataTypeRevision::Grid => ViewDataType::Grid,
|
||||
ViewDataTypeRevision::TextBlock => ViewDataTypePB::TextBlock,
|
||||
ViewDataTypeRevision::Database => ViewDataTypePB::Database,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewDataType> for ViewDataTypeRevision {
|
||||
fn from(ty: ViewDataType) -> Self {
|
||||
impl std::convert::From<ViewDataTypePB> for ViewDataTypeRevision {
|
||||
fn from(ty: ViewDataTypePB) -> Self {
|
||||
match ty {
|
||||
ViewDataType::TextBlock => ViewDataTypeRevision::TextBlock,
|
||||
ViewDataType::Grid => ViewDataTypeRevision::Grid,
|
||||
ViewDataTypePB::TextBlock => ViewDataTypeRevision::TextBlock,
|
||||
ViewDataTypePB::Database => ViewDataTypeRevision::Database,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -113,12 +119,15 @@ pub struct CreateViewPayloadPB {
|
||||
pub thumbnail: Option<String>,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub data_type: ViewDataType,
|
||||
pub data_type: ViewDataTypePB,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub plugin_type: i32,
|
||||
#[pb(index = 6, one_of)]
|
||||
pub sub_data_type: Option<SubViewDataTypePB>,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub plugin_type: i32,
|
||||
|
||||
#[pb(index = 8)]
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
@ -128,7 +137,8 @@ pub struct CreateViewParams {
|
||||
pub name: String,
|
||||
pub desc: String,
|
||||
pub thumbnail: String,
|
||||
pub data_type: ViewDataType,
|
||||
pub data_type: ViewDataTypePB,
|
||||
pub sub_data_type: Option<SubViewDataTypePB>,
|
||||
pub view_id: String,
|
||||
pub data: Vec<u8>,
|
||||
pub plugin_type: i32,
|
||||
@ -151,6 +161,7 @@ impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
||||
name,
|
||||
desc: self.desc,
|
||||
data_type: self.data_type,
|
||||
sub_data_type: self.sub_data_type,
|
||||
thumbnail,
|
||||
view_id,
|
||||
data: self.data,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{RepeatedViewPB, ViewDataType};
|
||||
use crate::entities::{RepeatedViewPB, ViewDataTypePB};
|
||||
use flowy_derive::ProtoBuf;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
@ -16,7 +16,7 @@ pub struct ViewInfoPB {
|
||||
pub desc: String,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub data_type: ViewDataType,
|
||||
pub data_type: ViewDataTypePB,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub belongings: RepeatedViewPB,
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::entities::view::ViewDataType;
|
||||
use crate::entities::view::ViewDataTypePB;
|
||||
use crate::entities::SubViewDataTypePB;
|
||||
use crate::services::folder_editor::FolderRevisionCompactor;
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
@ -221,7 +222,7 @@ impl DefaultFolderBuilder {
|
||||
};
|
||||
let _ = view_controller.set_latest_view(&view.id);
|
||||
let _ = view_controller
|
||||
.create_view(&view.id, ViewDataType::TextBlock, Bytes::from(view_data))
|
||||
.create_view(&view.id, ViewDataTypePB::TextBlock, Bytes::from(view_data))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@ -256,7 +257,12 @@ pub trait ViewDataProcessor {
|
||||
|
||||
fn get_delta_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError>;
|
||||
|
||||
fn create_default_view(&self, user_id: &str, view_id: &str) -> FutureResult<Bytes, FlowyError>;
|
||||
fn create_default_view(
|
||||
&self,
|
||||
user_id: &str,
|
||||
view_id: &str,
|
||||
sub_data_type: Option<SubViewDataTypePB>,
|
||||
) -> FutureResult<Bytes, FlowyError>;
|
||||
|
||||
fn create_view_from_delta_data(
|
||||
&self,
|
||||
@ -265,7 +271,7 @@ pub trait ViewDataProcessor {
|
||||
data: Vec<u8>,
|
||||
) -> FutureResult<Bytes, FlowyError>;
|
||||
|
||||
fn data_type(&self) -> ViewDataType;
|
||||
fn data_type(&self) -> ViewDataTypePB;
|
||||
}
|
||||
|
||||
pub type ViewDataProcessorMap = Arc<HashMap<ViewDataType, Arc<dyn ViewDataProcessor + Send + Sync>>>;
|
||||
pub type ViewDataProcessorMap = Arc<HashMap<ViewDataTypePB, Arc<dyn ViewDataProcessor + Send + Sync>>>;
|
||||
|
@ -88,7 +88,7 @@ impl ViewTable {
|
||||
pub fn new(view_rev: ViewRevision) -> Self {
|
||||
let data_type = match view_rev.data_type {
|
||||
ViewDataTypeRevision::TextBlock => SqlViewDataType::Block,
|
||||
ViewDataTypeRevision::Grid => SqlViewDataType::Grid,
|
||||
ViewDataTypeRevision::Database => SqlViewDataType::Grid,
|
||||
};
|
||||
|
||||
ViewTable {
|
||||
@ -111,7 +111,7 @@ impl std::convert::From<ViewTable> for ViewRevision {
|
||||
fn from(table: ViewTable) -> Self {
|
||||
let data_type = match table.view_type {
|
||||
SqlViewDataType::Block => ViewDataTypeRevision::TextBlock,
|
||||
SqlViewDataType::Grid => ViewDataTypeRevision::Grid,
|
||||
SqlViewDataType::Grid => ViewDataTypeRevision::Database,
|
||||
};
|
||||
|
||||
ViewRevision {
|
||||
|
@ -1,5 +1,5 @@
|
||||
pub use crate::entities::view::ViewDataType;
|
||||
use crate::entities::ViewInfoPB;
|
||||
pub use crate::entities::view::ViewDataTypePB;
|
||||
use crate::entities::{SubViewDataTypePB, ViewInfoPB};
|
||||
use crate::manager::{ViewDataProcessor, ViewDataProcessorMap};
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
@ -61,7 +61,9 @@ impl ViewController {
|
||||
let processor = self.get_data_processor(params.data_type.clone())?;
|
||||
let user_id = self.user.user_id()?;
|
||||
if params.data.is_empty() {
|
||||
let view_data = processor.create_default_view(&user_id, ¶ms.view_id).await?;
|
||||
let view_data = processor
|
||||
.create_default_view(&user_id, ¶ms.view_id, params.sub_data_type.clone())
|
||||
.await?;
|
||||
params.data = view_data.to_vec();
|
||||
} else {
|
||||
let delta_data = processor
|
||||
@ -81,7 +83,7 @@ impl ViewController {
|
||||
pub(crate) async fn create_view(
|
||||
&self,
|
||||
view_id: &str,
|
||||
data_type: ViewDataType,
|
||||
data_type: ViewDataTypePB,
|
||||
delta_data: Bytes,
|
||||
) -> Result<(), FlowyError> {
|
||||
if delta_data.is_empty() {
|
||||
@ -217,6 +219,7 @@ impl ViewController {
|
||||
desc: view_rev.desc,
|
||||
thumbnail: view_rev.thumbnail,
|
||||
data_type: view_rev.data_type.into(),
|
||||
sub_data_type: None,
|
||||
data: delta_bytes.to_vec(),
|
||||
view_id: gen_view_id(),
|
||||
plugin_type: view_rev.plugin_type,
|
||||
@ -364,7 +367,7 @@ impl ViewController {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_data_processor<T: Into<ViewDataType>>(
|
||||
fn get_data_processor<T: Into<ViewDataTypePB>>(
|
||||
&self,
|
||||
data_type: T,
|
||||
) -> FlowyResult<Arc<dyn ViewDataProcessor + Send + Sync>> {
|
||||
@ -452,7 +455,7 @@ async fn handle_trash_event(
|
||||
|
||||
fn get_data_processor(
|
||||
data_processors: ViewDataProcessorMap,
|
||||
data_type: &ViewDataType,
|
||||
data_type: &ViewDataTypePB,
|
||||
) -> FlowyResult<Arc<dyn ViewDataProcessor + Send + Sync>> {
|
||||
match data_processors.get(data_type) {
|
||||
None => Err(FlowyError::internal().context(format!(
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::script::{invalid_workspace_name_test_case, FolderScript::*, FolderTest};
|
||||
use flowy_folder::entities::view::ViewDataType;
|
||||
use flowy_folder::entities::view::ViewDataTypePB;
|
||||
use flowy_folder::entities::workspace::CreateWorkspacePayloadPB;
|
||||
|
||||
use flowy_revision::disk::RevisionState;
|
||||
@ -134,12 +134,12 @@ async fn app_create_with_view() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataType::TextBlock,
|
||||
data_type: ViewDataTypePB::TextBlock,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
desc: "Grid description".to_owned(),
|
||||
data_type: ViewDataType::Grid,
|
||||
data_type: ViewDataTypePB::Database,
|
||||
},
|
||||
ReadApp(app.id),
|
||||
])
|
||||
@ -198,12 +198,12 @@ async fn view_delete_all() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataType::TextBlock,
|
||||
data_type: ViewDataTypePB::TextBlock,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
desc: "Grid description".to_owned(),
|
||||
data_type: ViewDataType::Grid,
|
||||
data_type: ViewDataTypePB::Database,
|
||||
},
|
||||
ReadApp(app.id.clone()),
|
||||
])
|
||||
@ -231,7 +231,7 @@ async fn view_delete_all_permanent() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataType::TextBlock,
|
||||
data_type: ViewDataTypePB::TextBlock,
|
||||
},
|
||||
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: ViewDataType::TextBlock,
|
||||
data_type: ViewDataTypePB::TextBlock,
|
||||
},
|
||||
AssertCurrentRevId(3),
|
||||
AssertNextSyncRevId(Some(3)),
|
||||
|
@ -9,7 +9,7 @@ use flowy_folder::entities::{
|
||||
use flowy_folder::entities::{
|
||||
app::{AppPB, RepeatedAppPB},
|
||||
trash::TrashPB,
|
||||
view::{RepeatedViewPB, ViewDataType, ViewPB},
|
||||
view::{RepeatedViewPB, ViewDataTypePB, ViewPB},
|
||||
workspace::WorkspacePB,
|
||||
};
|
||||
use flowy_folder::event_map::FolderEvent::*;
|
||||
@ -51,7 +51,7 @@ pub enum FolderScript {
|
||||
CreateView {
|
||||
name: String,
|
||||
desc: String,
|
||||
data_type: ViewDataType,
|
||||
data_type: ViewDataTypePB,
|
||||
},
|
||||
AssertView(ViewPB),
|
||||
ReadView(String),
|
||||
@ -98,7 +98,7 @@ impl FolderTest {
|
||||
&app.id,
|
||||
"Folder View",
|
||||
"Folder test view",
|
||||
ViewDataType::TextBlock,
|
||||
ViewDataTypePB::TextBlock,
|
||||
)
|
||||
.await;
|
||||
app.belongings = RepeatedViewPB {
|
||||
@ -346,7 +346,13 @@ pub async fn delete_app(sdk: &FlowySDKTest, app_id: &str) {
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, data_type: ViewDataType) -> ViewPB {
|
||||
pub async fn create_view(
|
||||
sdk: &FlowySDKTest,
|
||||
app_id: &str,
|
||||
name: &str,
|
||||
desc: &str,
|
||||
data_type: ViewDataTypePB,
|
||||
) -> ViewPB {
|
||||
let request = CreateViewPayloadPB {
|
||||
belong_to_id: app_id.to_string(),
|
||||
name: name.to_string(),
|
||||
|
Reference in New Issue
Block a user