docs: update code documentation (#1804)

* docs: update code documentation

* chore: fix bloc test

* chore: reduce lock granularity

* chore: fix bloc test
This commit is contained in:
Nathan.fooo
2023-02-06 15:59:30 +08:00
committed by GitHub
parent 4d5063de6a
commit 1df2619c9f
29 changed files with 199 additions and 213 deletions

View File

@ -2,11 +2,9 @@ pub mod app;
mod parser;
pub mod trash;
pub mod view;
mod view_info;
pub mod workspace;
pub use app::*;
pub use trash::*;
pub use view::*;
pub use view_info::*;
pub use workspace::*;

View File

@ -50,9 +50,13 @@ impl std::convert::From<ViewRevision> for ViewPB {
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
pub enum ViewDataFormatPB {
/// Indicate this view is using `Delta` for the persistence data format, it's deprecated.
DeltaFormat = 0,
/// Indicate this view is using `Database` for the persistence data format. It is used in AppFlowy database
/// views including Grid,Board, and Calendar.
DatabaseFormat = 1,
TreeFormat = 2,
/// Indicate this view is using `Node` for the persistence data format. It is used in AppFlowy document
NodeFormat = 2,
}
impl std::default::Default for ViewDataFormatPB {
@ -66,7 +70,7 @@ impl std::convert::From<ViewDataFormatRevision> for ViewDataFormatPB {
match rev {
ViewDataFormatRevision::DeltaFormat => ViewDataFormatPB::DeltaFormat,
ViewDataFormatRevision::DatabaseFormat => ViewDataFormatPB::DatabaseFormat,
ViewDataFormatRevision::TreeFormat => ViewDataFormatPB::TreeFormat,
ViewDataFormatRevision::NodeFormat => ViewDataFormatPB::NodeFormat,
}
}
}
@ -76,7 +80,7 @@ impl std::convert::From<ViewDataFormatPB> for ViewDataFormatRevision {
match ty {
ViewDataFormatPB::DeltaFormat => ViewDataFormatRevision::DeltaFormat,
ViewDataFormatPB::DatabaseFormat => ViewDataFormatRevision::DatabaseFormat,
ViewDataFormatPB::TreeFormat => ViewDataFormatRevision::TreeFormat,
ViewDataFormatPB::NodeFormat => ViewDataFormatRevision::NodeFormat,
}
}
}

View File

@ -1,26 +0,0 @@
use crate::entities::{RepeatedViewPB, ViewDataFormatPB};
use flowy_derive::ProtoBuf;
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
pub struct ViewInfoPB {
#[pb(index = 1)]
pub id: String,
#[pb(index = 2)]
pub belong_to_id: String,
#[pb(index = 3)]
pub name: String,
#[pb(index = 4)]
pub desc: String,
#[pb(index = 5)]
pub data_type: ViewDataFormatPB,
#[pb(index = 6)]
pub belongings: RepeatedViewPB,
#[pb(index = 7)]
pub ext_data: String,
}

View File

@ -63,12 +63,11 @@ pub fn init(folder: Arc<FolderManager>) -> AFPlugin {
.event(FolderEvent::CreateView, create_view_handler)
.event(FolderEvent::ReadView, read_view_handler)
.event(FolderEvent::UpdateView, update_view_handler)
.event(FolderEvent::ReadViewInfo, read_view_info_handler)
.event(FolderEvent::DeleteView, delete_view_handler)
.event(FolderEvent::DuplicateView, duplicate_view_handler)
.event(FolderEvent::SetLatestView, set_latest_view_handler)
.event(FolderEvent::CloseView, close_view_handler)
.event(FolderEvent::MoveFolderItem, move_item_handler);
.event(FolderEvent::MoveItem, move_item_handler);
// Trash
plugin = plugin
@ -84,78 +83,99 @@ pub fn init(folder: Arc<FolderManager>) -> AFPlugin {
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
#[event_err = "FlowyError"]
pub enum FolderEvent {
/// Create a new workspace
#[event(input = "CreateWorkspacePayloadPB", output = "WorkspacePB")]
CreateWorkspace = 0,
/// Read the current opening workspace
#[event(output = "WorkspaceSettingPB")]
ReadCurrentWorkspace = 1,
/// Open the workspace and mark it as the current workspace
#[event(input = "WorkspaceIdPB", output = "RepeatedWorkspacePB")]
ReadWorkspaces = 2,
/// Delete the workspace
#[event(input = "WorkspaceIdPB")]
DeleteWorkspace = 3,
/// Open the workspace and mark it as the current workspace
#[event(input = "WorkspaceIdPB", output = "WorkspacePB")]
OpenWorkspace = 4,
/// Return a list of apps that belong to this workspace
#[event(input = "WorkspaceIdPB", output = "RepeatedAppPB")]
ReadWorkspaceApps = 5,
/// Create a new app
#[event(input = "CreateAppPayloadPB", output = "AppPB")]
CreateApp = 101,
/// Delete the app
#[event(input = "AppIdPB")]
DeleteApp = 102,
/// Read the app
#[event(input = "AppIdPB", output = "AppPB")]
ReadApp = 103,
/// Update the app's properties including the name,description, etc.
#[event(input = "UpdateAppPayloadPB")]
UpdateApp = 104,
/// Create a new view in the corresponding app
#[event(input = "CreateViewPayloadPB", output = "ViewPB")]
CreateView = 201,
/// Return the view info
#[event(input = "ViewIdPB", output = "ViewPB")]
ReadView = 202,
/// Update the view's properties including the name,description, etc.
#[event(input = "UpdateViewPayloadPB", output = "ViewPB")]
UpdateView = 203,
/// Move the view to the trash folder
#[event(input = "RepeatedViewIdPB")]
DeleteView = 204,
/// Duplicate the view
#[event(input = "ViewPB")]
DuplicateView = 205,
/// Close and release the resources that are used by this view.
/// It should get called when the 'View' page get destroy
#[event(input = "ViewIdPB")]
CloseView = 206,
#[event(input = "ViewIdPB", output = "ViewInfoPB")]
ReadViewInfo = 207,
#[event()]
CopyLink = 220,
/// Set the current visiting view
#[event(input = "ViewIdPB")]
SetLatestView = 221,
/// Move the view or app to another place
#[event(input = "MoveFolderItemPayloadPB")]
MoveFolderItem = 230,
MoveItem = 230,
/// Read the trash that was deleted by the user
#[event(output = "RepeatedTrashPB")]
ReadTrash = 300,
/// Put back the trash to the origin folder
#[event(input = "TrashIdPB")]
PutbackTrash = 301,
/// Delete the trash from the disk
#[event(input = "RepeatedTrashIdPB")]
DeleteTrash = 302,
/// Put back all the trash to its original folder
#[event()]
RestoreAllTrash = 303,
/// Delete all the trash from the disk
#[event()]
DeleteAllTrash = 304,
}

View File

@ -89,7 +89,7 @@ impl ViewTable {
let data_type = match view_rev.data_format {
ViewDataFormatRevision::DeltaFormat => SqlViewDataFormat::Delta,
ViewDataFormatRevision::DatabaseFormat => SqlViewDataFormat::Database,
ViewDataFormatRevision::TreeFormat => SqlViewDataFormat::Tree,
ViewDataFormatRevision::NodeFormat => SqlViewDataFormat::Tree,
};
ViewTable {
@ -113,7 +113,7 @@ impl std::convert::From<ViewTable> for ViewRevision {
let data_type = match table.view_type {
SqlViewDataFormat::Delta => ViewDataFormatRevision::DeltaFormat,
SqlViewDataFormat::Database => ViewDataFormatRevision::DatabaseFormat,
SqlViewDataFormat::Tree => ViewDataFormatRevision::TreeFormat,
SqlViewDataFormat::Tree => ViewDataFormatRevision::NodeFormat,
};
ViewRevision {

View File

@ -1,10 +1,10 @@
pub use crate::entities::view::ViewDataFormatPB;
use crate::entities::{AppPB, DeletedViewPB, ViewInfoPB, ViewLayoutTypePB};
use crate::entities::{AppPB, DeletedViewPB, ViewLayoutTypePB};
use crate::manager::{ViewDataProcessor, ViewDataProcessorMap};
use crate::{
entities::{
trash::{RepeatedTrashIdPB, TrashType},
view::{CreateViewParams, RepeatedViewPB, UpdateViewParams, ViewIdPB, ViewPB},
view::{CreateViewParams, UpdateViewParams, ViewIdPB, ViewPB},
},
errors::{FlowyError, FlowyResult},
event_map::{FolderCouldServiceV1, WorkspaceUser},
@ -139,35 +139,6 @@ impl ViewController {
Ok(view_rev)
}
#[tracing::instrument(level = "debug", skip(self, view_id), fields(view_id = %view_id.value), err)]
pub(crate) async fn read_view_pb(&self, view_id: ViewIdPB) -> Result<ViewInfoPB, FlowyError> {
let view_info = self
.persistence
.begin_transaction(|transaction| {
let view_rev = transaction.read_view(&view_id.value)?;
let items: Vec<ViewPB> = view_rev
.belongings
.into_iter()
.map(|view_rev| view_rev.into())
.collect();
let view_info = ViewInfoPB {
id: view_rev.id,
belong_to_id: view_rev.app_id,
name: view_rev.name,
desc: view_rev.desc,
data_type: view_rev.data_format.into(),
belongings: RepeatedViewPB { items },
ext_data: view_rev.ext_data,
};
Ok(view_info)
})
.await?;
Ok(view_info)
}
pub(crate) async fn read_local_views(&self, ids: Vec<String>) -> Result<Vec<ViewRevision>, FlowyError> {
self.persistence
.begin_transaction(|transaction| {

View File

@ -1,5 +1,4 @@
use crate::entities::view::{MoveFolderItemParams, MoveFolderItemPayloadPB, MoveFolderItemType};
use crate::entities::ViewInfoPB;
use crate::manager::FolderManager;
use crate::services::{notify_workspace_setting_did_change, AppController};
use crate::{
@ -35,15 +34,6 @@ pub(crate) async fn read_view_handler(
data_result(view_rev.into())
}
pub(crate) async fn read_view_info_handler(
data: AFPluginData<ViewIdPB>,
controller: AFPluginState<Arc<ViewController>>,
) -> DataResult<ViewInfoPB, FlowyError> {
let view_id: ViewIdPB = data.into_inner();
let view_info = controller.read_view_pb(view_id.clone()).await?;
data_result(view_info)
}
#[tracing::instrument(level = "debug", skip(data, controller), err)]
pub(crate) async fn update_view_handler(
data: AFPluginData<UpdateViewPayloadPB>,

View File

@ -182,7 +182,7 @@ impl FolderTest {
FolderScript::CreateView { name, desc, data_type } => {
let layout = match data_type {
ViewDataFormatPB::DeltaFormat => ViewLayoutTypePB::Document,
ViewDataFormatPB::TreeFormat => ViewLayoutTypePB::Document,
ViewDataFormatPB::NodeFormat => ViewLayoutTypePB::Document,
ViewDataFormatPB::DatabaseFormat => ViewLayoutTypePB::Grid,
};
let view = create_view(sdk, &self.app.id, &name, &desc, data_type, layout).await;