action.rs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. use crate::entities::{GroupChangesetPB, GroupViewChangesetPB};
  2. use crate::services::cell::CellDataIsEmpty;
  3. use crate::services::group::controller::MoveGroupRowContext;
  4. use crate::services::group::Group;
  5. use flowy_error::FlowyResult;
  6. use grid_rev_model::{CellRevision, FieldRevision, RowRevision};
  7. use std::sync::Arc;
  8. /// Using polymorphism to provides the customs action for different group controller.
  9. ///
  10. /// For example, the `CheckboxGroupController` implements this trait to provide custom behavior.
  11. ///
  12. pub trait GroupControllerCustomActions: Send + Sync {
  13. type CellDataType: CellDataIsEmpty;
  14. /// Returns the a value of the cell, default value is None
  15. ///
  16. /// Determine which group the row is placed in based on the data of the cell. If the cell data
  17. /// is None. The row will be put in to the `No status` group
  18. ///
  19. fn default_cell_rev(&self) -> Option<CellRevision> {
  20. None
  21. }
  22. /// Returns a bool value to determine whether the group should contain this cell or not.
  23. fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool;
  24. /// Adds or removes a row if the cell data match the group filter.
  25. /// It gets called after editing the cell or row
  26. ///
  27. fn add_or_remove_row_in_groups_if_match(
  28. &mut self,
  29. row_rev: &RowRevision,
  30. cell_data: &Self::CellDataType,
  31. ) -> Vec<GroupChangesetPB>;
  32. /// Deletes the row from the group
  33. fn delete_row(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
  34. /// Move row from one group to another
  35. fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec<GroupChangesetPB>;
  36. }
  37. /// Defines the shared actions any group controller can perform.
  38. pub trait GroupControllerSharedActions: Send + Sync {
  39. /// The field that is used for grouping the rows
  40. fn field_id(&self) -> &str;
  41. /// Returns number of groups the current field has
  42. fn groups(&self) -> Vec<Group>;
  43. /// Returns the index and the group data with group_id
  44. fn get_group(&self, group_id: &str) -> Option<(usize, Group)>;
  45. /// Separates the rows into different groups
  46. fn fill_groups(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<()>;
  47. /// Remove the group with from_group_id and insert it to the index with to_group_id
  48. fn move_group(&mut self, from_group_id: &str, to_group_id: &str) -> FlowyResult<()>;
  49. /// Insert/Remove the row to the group if the corresponding cell data is changed
  50. fn did_update_group_row(
  51. &mut self,
  52. row_rev: &RowRevision,
  53. field_rev: &FieldRevision,
  54. ) -> FlowyResult<Vec<GroupChangesetPB>>;
  55. /// Remove the row from the group if the row gets deleted
  56. fn did_delete_delete_row(
  57. &mut self,
  58. row_rev: &RowRevision,
  59. field_rev: &FieldRevision,
  60. ) -> FlowyResult<Vec<GroupChangesetPB>>;
  61. /// Move the row from one group to another group
  62. fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<Vec<GroupChangesetPB>>;
  63. /// Update the group if the corresponding field is changed
  64. fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>>;
  65. }