mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add documentation
This commit is contained in:
parent
00f7256e70
commit
d2933bdb04
@ -410,7 +410,7 @@ impl GridRevisionEditor {
|
|||||||
pub async fn update_row(&self, changeset: RowChangeset) -> FlowyResult<()> {
|
pub async fn update_row(&self, changeset: RowChangeset) -> FlowyResult<()> {
|
||||||
let row_id = changeset.row_id.clone();
|
let row_id = changeset.row_id.clone();
|
||||||
let _ = self.block_manager.update_row(changeset).await?;
|
let _ = self.block_manager.update_row(changeset).await?;
|
||||||
self.view_manager.did_update_row(&row_id).await;
|
self.view_manager.did_update_cell(&row_id).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +504,7 @@ impl GridRevisionEditor {
|
|||||||
content,
|
content,
|
||||||
};
|
};
|
||||||
let _ = self.block_manager.update_cell(cell_changeset).await?;
|
let _ = self.block_manager.update_cell(cell_changeset).await?;
|
||||||
self.view_manager.did_update_cell(&row_id, &field_id).await;
|
self.view_manager.did_update_cell(&row_id).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ impl GridViewRevisionEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn did_update_view_row(&self, row_rev: &RowRevision) {
|
pub(crate) async fn did_update_view_cell(&self, row_rev: &RowRevision) {
|
||||||
let changesets = self
|
let changesets = self
|
||||||
.mut_group_controller(|group_controller, field_rev| {
|
.mut_group_controller(|group_controller, field_rev| {
|
||||||
group_controller.did_update_group_row(row_rev, &field_rev)
|
group_controller.did_update_group_row(row_rev, &field_rev)
|
||||||
|
@ -77,15 +77,15 @@ impl GridViewManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert/Delete the group's row if the corresponding data was changed.
|
/// Insert/Delete the group's row if the corresponding cell data was changed.
|
||||||
pub(crate) async fn did_update_row(&self, row_id: &str) {
|
pub(crate) async fn did_update_cell(&self, row_id: &str) {
|
||||||
match self.row_delegate.gv_get_row_rev(row_id).await {
|
match self.row_delegate.gv_get_row_rev(row_id).await {
|
||||||
None => {
|
None => {
|
||||||
tracing::warn!("Can not find the row in grid view");
|
tracing::warn!("Can not find the row in grid view");
|
||||||
}
|
}
|
||||||
Some(row_rev) => {
|
Some(row_rev) => {
|
||||||
for view_editor in self.view_editors.iter() {
|
for view_editor in self.view_editors.iter() {
|
||||||
view_editor.did_update_view_row(&row_rev).await;
|
view_editor.did_update_view_cell(&row_rev).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,10 +97,6 @@ impl GridViewManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn did_update_cell(&self, row_id: &str, _field_id: &str) {
|
|
||||||
self.did_update_row(row_id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn did_delete_row(&self, row_rev: Arc<RowRevision>) {
|
pub(crate) async fn did_delete_row(&self, row_rev: Arc<RowRevision>) {
|
||||||
for view_editor in self.view_editors.iter() {
|
for view_editor in self.view_editors.iter() {
|
||||||
view_editor.did_delete_view_row(&row_rev).await;
|
view_editor.did_delete_view_row(&row_rev).await;
|
||||||
|
@ -1,19 +1,80 @@
|
|||||||
use crate::entities::GroupChangesetPB;
|
use crate::entities::{GroupChangesetPB, GroupViewChangesetPB};
|
||||||
|
|
||||||
use crate::services::group::controller::MoveGroupRowContext;
|
use crate::services::group::controller::MoveGroupRowContext;
|
||||||
use flowy_grid_data_model::revision::{CellRevision, RowRevision};
|
use crate::services::group::Group;
|
||||||
|
use flowy_error::FlowyResult;
|
||||||
|
use flowy_grid_data_model::revision::{CellRevision, FieldRevision, RowRevision};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub trait GroupAction: Send + Sync {
|
/// Using polymorphism to provides the customs action for different group controller.
|
||||||
|
///
|
||||||
|
/// For example, the `CheckboxGroupController` implements this trait to provide custom behavior.
|
||||||
|
///
|
||||||
|
pub trait GroupControllerCustomActions: Send + Sync {
|
||||||
type CellDataType;
|
type CellDataType;
|
||||||
|
/// Returns the a value of the cell, default value is None
|
||||||
|
///
|
||||||
|
/// Determine which group the row is placed in based on the data of the cell. If the cell data
|
||||||
|
/// is None. The row will be put in to the `No status` group
|
||||||
|
///
|
||||||
fn default_cell_rev(&self) -> Option<CellRevision> {
|
fn default_cell_rev(&self) -> Option<CellRevision> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn use_default_group(&self) -> bool {
|
|
||||||
|
/// Returns a bool value to determine the `No status` group should show or hide.
|
||||||
|
///
|
||||||
|
fn use_no_status_group(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a bool value to determine whether the group should contain this cell or not.
|
||||||
fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool;
|
fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool;
|
||||||
|
|
||||||
|
/// Adding a new row to the group if the cell data match the group filter.
|
||||||
|
/// It gets called after editing the cell or row
|
||||||
|
///
|
||||||
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
||||||
|
|
||||||
|
///
|
||||||
fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
||||||
// Move row from one group to another
|
|
||||||
|
/// Move row from one group to another
|
||||||
fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec<GroupChangesetPB>;
|
fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec<GroupChangesetPB>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Defines the shared actions any group controller can perform.
|
||||||
|
pub trait GroupControllerSharedActions: Send + Sync {
|
||||||
|
/// The field that is used for grouping the rows
|
||||||
|
fn field_id(&self) -> &str;
|
||||||
|
|
||||||
|
/// Returns number of groups the current field has
|
||||||
|
fn groups(&self) -> Vec<Group>;
|
||||||
|
|
||||||
|
/// Returns the index and the group data with group_id
|
||||||
|
fn get_group(&self, group_id: &str) -> Option<(usize, Group)>;
|
||||||
|
|
||||||
|
/// Separates the rows into different groups
|
||||||
|
fn fill_groups(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<()>;
|
||||||
|
|
||||||
|
/// Remove the group with from_group_id and insert it to the index with to_group_id
|
||||||
|
fn move_group(&mut self, from_group_id: &str, to_group_id: &str) -> FlowyResult<()>;
|
||||||
|
|
||||||
|
/// Insert/Remove the row to the group if the corresponding cell data is changed
|
||||||
|
fn did_update_group_row(
|
||||||
|
&mut self,
|
||||||
|
row_rev: &RowRevision,
|
||||||
|
field_rev: &FieldRevision,
|
||||||
|
) -> FlowyResult<Vec<GroupChangesetPB>>;
|
||||||
|
|
||||||
|
/// Remove the row from the group if the row gets deleted
|
||||||
|
fn did_delete_delete_row(
|
||||||
|
&mut self,
|
||||||
|
row_rev: &RowRevision,
|
||||||
|
field_rev: &FieldRevision,
|
||||||
|
) -> FlowyResult<Vec<GroupChangesetPB>>;
|
||||||
|
|
||||||
|
/// Move the row from one group to another group
|
||||||
|
fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<Vec<GroupChangesetPB>>;
|
||||||
|
|
||||||
|
/// Update the group if the corresponding field is changed
|
||||||
|
fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>>;
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::entities::{GroupChangesetPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
|
use crate::entities::{GroupChangesetPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
|
||||||
use crate::services::cell::{decode_any_cell_data, CellBytesParser};
|
use crate::services::cell::{decode_any_cell_data, CellBytesParser};
|
||||||
use crate::services::group::action::GroupAction;
|
use crate::services::group::action::{GroupControllerCustomActions, GroupControllerSharedActions};
|
||||||
use crate::services::group::configuration::GroupContext;
|
use crate::services::group::configuration::GroupContext;
|
||||||
use crate::services::group::entities::Group;
|
use crate::services::group::entities::Group;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
@ -18,7 +18,7 @@ use std::sync::Arc;
|
|||||||
/// If the [FieldType] doesn't implement its group controller, then the [DefaultGroupController] will
|
/// If the [FieldType] doesn't implement its group controller, then the [DefaultGroupController] will
|
||||||
/// be used.
|
/// be used.
|
||||||
///
|
///
|
||||||
pub trait GroupController: GroupControllerActions + Send + Sync {
|
pub trait GroupController: GroupControllerSharedActions + Send + Sync {
|
||||||
fn will_create_row(&mut self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
|
fn will_create_row(&mut self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
|
||||||
fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str);
|
fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str);
|
||||||
}
|
}
|
||||||
@ -47,45 +47,6 @@ pub struct MoveGroupRowContext<'a> {
|
|||||||
pub to_group_id: &'a str,
|
pub to_group_id: &'a str,
|
||||||
pub to_row_id: Option<String>,
|
pub to_row_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defines the shared actions each group controller can perform.
|
|
||||||
pub trait GroupControllerActions: Send + Sync {
|
|
||||||
/// The field that is used for grouping the rows
|
|
||||||
fn field_id(&self) -> &str;
|
|
||||||
|
|
||||||
/// Returns number of groups the current field has
|
|
||||||
fn groups(&self) -> Vec<Group>;
|
|
||||||
|
|
||||||
/// Returns the index and the group data with group_id
|
|
||||||
fn get_group(&self, group_id: &str) -> Option<(usize, Group)>;
|
|
||||||
|
|
||||||
/// Separates the rows into different groups
|
|
||||||
fn fill_groups(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<()>;
|
|
||||||
|
|
||||||
/// Remove the group with from_group_id and insert it to the index with to_group_id
|
|
||||||
fn move_group(&mut self, from_group_id: &str, to_group_id: &str) -> FlowyResult<()>;
|
|
||||||
|
|
||||||
/// Insert the row to the group if the corresponding cell data is changed
|
|
||||||
fn did_update_group_row(
|
|
||||||
&mut self,
|
|
||||||
row_rev: &RowRevision,
|
|
||||||
field_rev: &FieldRevision,
|
|
||||||
) -> FlowyResult<Vec<GroupChangesetPB>>;
|
|
||||||
|
|
||||||
/// Remove the row from the group if the corresponding cell data is changed
|
|
||||||
fn did_delete_delete_row(
|
|
||||||
&mut self,
|
|
||||||
row_rev: &RowRevision,
|
|
||||||
field_rev: &FieldRevision,
|
|
||||||
) -> FlowyResult<Vec<GroupChangesetPB>>;
|
|
||||||
|
|
||||||
/// Move the row from one group to another group
|
|
||||||
fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<Vec<GroupChangesetPB>>;
|
|
||||||
|
|
||||||
/// Update the group if the corresponding field is changed
|
|
||||||
fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// C: represents the group configuration that impl [GroupConfigurationSerde]
|
/// C: represents the group configuration that impl [GroupConfigurationSerde]
|
||||||
/// T: the type-option data deserializer that impl [TypeOptionDataDeserializer]
|
/// T: the type-option data deserializer that impl [TypeOptionDataDeserializer]
|
||||||
/// G: the group generator, [GroupGenerator]
|
/// G: the group generator, [GroupGenerator]
|
||||||
@ -186,21 +147,21 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, T, G, P> GroupControllerActions for GenericGroupController<C, T, G, P>
|
impl<C, T, G, P> GroupControllerSharedActions for GenericGroupController<C, T, G, P>
|
||||||
where
|
where
|
||||||
P: CellBytesParser,
|
P: CellBytesParser,
|
||||||
C: GroupConfigurationContentSerde,
|
C: GroupConfigurationContentSerde,
|
||||||
T: TypeOptionDataDeserializer,
|
T: TypeOptionDataDeserializer,
|
||||||
G: GroupGenerator<Context = GroupContext<C>, TypeOptionType = T>,
|
G: GroupGenerator<Context = GroupContext<C>, TypeOptionType = T>,
|
||||||
|
|
||||||
Self: GroupAction<CellDataType = P::Object>,
|
Self: GroupControllerCustomActions<CellDataType = P::Object>,
|
||||||
{
|
{
|
||||||
fn field_id(&self) -> &str {
|
fn field_id(&self) -> &str {
|
||||||
&self.field_id
|
&self.field_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn groups(&self) -> Vec<Group> {
|
fn groups(&self) -> Vec<Group> {
|
||||||
if self.use_default_group() {
|
if self.use_no_status_group() {
|
||||||
self.group_ctx.groups().into_iter().cloned().collect()
|
self.group_ctx.groups().into_iter().cloned().collect()
|
||||||
} else {
|
} else {
|
||||||
self.group_ctx
|
self.group_ctx
|
||||||
@ -270,16 +231,12 @@ where
|
|||||||
let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev).1;
|
let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev).1;
|
||||||
let cell_data = cell_bytes.parser::<P>()?;
|
let cell_data = cell_bytes.parser::<P>()?;
|
||||||
let mut changesets = self.add_row_if_match(row_rev, &cell_data);
|
let mut changesets = self.add_row_if_match(row_rev, &cell_data);
|
||||||
|
// if let Some(default_group_changeset) = self.update_default_group(row_rev, &changesets) {
|
||||||
if self.use_default_group() {
|
// tracing::trace!("default_group_changeset: {}", default_group_changeset);
|
||||||
if let Some(default_group_changeset) = self.update_default_group(row_rev, &changesets) {
|
// if !default_group_changeset.is_empty() {
|
||||||
tracing::trace!("default_group_changeset: {}", default_group_changeset);
|
// changesets.push(default_group_changeset);
|
||||||
if !default_group_changeset.is_empty() {
|
// }
|
||||||
changesets.push(default_group_changeset);
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(changesets)
|
Ok(changesets)
|
||||||
} else {
|
} else {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::entities::{GroupChangesetPB, InsertedRowPB, RowPB};
|
use crate::entities::{GroupChangesetPB, InsertedRowPB, RowPB};
|
||||||
use crate::services::field::{CheckboxCellData, CheckboxCellDataParser, CheckboxTypeOptionPB, CHECK, UNCHECK};
|
use crate::services::field::{CheckboxCellData, CheckboxCellDataParser, CheckboxTypeOptionPB, CHECK, UNCHECK};
|
||||||
use crate::services::group::action::GroupAction;
|
use crate::services::group::action::GroupControllerCustomActions;
|
||||||
use crate::services::group::configuration::GroupContext;
|
use crate::services::group::configuration::GroupContext;
|
||||||
use crate::services::group::controller::{
|
use crate::services::group::controller::{
|
||||||
GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
|
GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
|
||||||
@ -21,13 +21,13 @@ pub type CheckboxGroupController = GenericGroupController<
|
|||||||
|
|
||||||
pub type CheckboxGroupContext = GroupContext<CheckboxGroupConfigurationRevision>;
|
pub type CheckboxGroupContext = GroupContext<CheckboxGroupConfigurationRevision>;
|
||||||
|
|
||||||
impl GroupAction for CheckboxGroupController {
|
impl GroupControllerCustomActions for CheckboxGroupController {
|
||||||
type CellDataType = CheckboxCellData;
|
type CellDataType = CheckboxCellData;
|
||||||
fn default_cell_rev(&self) -> Option<CellRevision> {
|
fn default_cell_rev(&self) -> Option<CellRevision> {
|
||||||
Some(CellRevision::new(UNCHECK.to_string()))
|
Some(CellRevision::new(UNCHECK.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn use_default_group(&self) -> bool {
|
fn use_no_status_group(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::entities::{GroupChangesetPB, GroupViewChangesetPB, RowPB};
|
use crate::entities::{GroupChangesetPB, GroupViewChangesetPB, RowPB};
|
||||||
use crate::services::group::{Group, GroupController, GroupControllerActions, MoveGroupRowContext};
|
use crate::services::group::{Group, GroupController, GroupControllerSharedActions, MoveGroupRowContext};
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, RowRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, RowRevision};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -30,7 +30,7 @@ impl DefaultGroupController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GroupControllerActions for DefaultGroupController {
|
impl GroupControllerSharedActions for DefaultGroupController {
|
||||||
fn field_id(&self) -> &str {
|
fn field_id(&self) -> &str {
|
||||||
&self.field_id
|
&self.field_id
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::entities::{GroupChangesetPB, RowPB};
|
use crate::entities::{GroupChangesetPB, RowPB};
|
||||||
use crate::services::cell::insert_select_option_cell;
|
use crate::services::cell::insert_select_option_cell;
|
||||||
use crate::services::field::{MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser};
|
use crate::services::field::{MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser};
|
||||||
use crate::services::group::action::GroupAction;
|
use crate::services::group::action::GroupControllerCustomActions;
|
||||||
|
|
||||||
use crate::services::group::controller::{
|
use crate::services::group::controller::{
|
||||||
GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
|
GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
|
||||||
@ -19,7 +19,7 @@ pub type MultiSelectGroupController = GenericGroupController<
|
|||||||
SelectOptionCellDataParser,
|
SelectOptionCellDataParser,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
impl GroupAction for MultiSelectGroupController {
|
impl GroupControllerCustomActions for MultiSelectGroupController {
|
||||||
type CellDataType = SelectOptionCellDataPB;
|
type CellDataType = SelectOptionCellDataPB;
|
||||||
|
|
||||||
fn can_group(&self, content: &str, cell_data: &SelectOptionCellDataPB) -> bool {
|
fn can_group(&self, content: &str, cell_data: &SelectOptionCellDataPB) -> bool {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::entities::{GroupChangesetPB, RowPB};
|
use crate::entities::{GroupChangesetPB, RowPB};
|
||||||
use crate::services::cell::insert_select_option_cell;
|
use crate::services::cell::insert_select_option_cell;
|
||||||
use crate::services::field::{SelectOptionCellDataPB, SelectOptionCellDataParser, SingleSelectTypeOptionPB};
|
use crate::services::field::{SelectOptionCellDataPB, SelectOptionCellDataParser, SingleSelectTypeOptionPB};
|
||||||
use crate::services::group::action::GroupAction;
|
use crate::services::group::action::GroupControllerCustomActions;
|
||||||
|
|
||||||
use crate::services::group::controller::{
|
use crate::services::group::controller::{
|
||||||
GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
|
GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
|
||||||
@ -20,7 +20,7 @@ pub type SingleSelectGroupController = GenericGroupController<
|
|||||||
SelectOptionCellDataParser,
|
SelectOptionCellDataParser,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
impl GroupAction for SingleSelectGroupController {
|
impl GroupControllerCustomActions for SingleSelectGroupController {
|
||||||
type CellDataType = SelectOptionCellDataPB;
|
type CellDataType = SelectOptionCellDataPB;
|
||||||
fn can_group(&self, content: &str, cell_data: &SelectOptionCellDataPB) -> bool {
|
fn can_group(&self, content: &str, cell_data: &SelectOptionCellDataPB) -> bool {
|
||||||
cell_data.select_options.iter().any(|option| option.id == content)
|
cell_data.select_options.iter().any(|option| option.id == content)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user