diff --git a/frontend/app_flowy/packages/appflowy_board/lib/src/utils/log.dart b/frontend/app_flowy/packages/appflowy_board/lib/src/utils/log.dart index 6f35ae4195..9c23060b26 100644 --- a/frontend/app_flowy/packages/appflowy_board/lib/src/utils/log.dart +++ b/frontend/app_flowy/packages/appflowy_board/lib/src/utils/log.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; const DART_LOG = "Dart_LOG"; class Log { - static const enableLog = true; + static const enableLog = false; static void info(String? message) { if (enableLog) { diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs index 12f94c943c..dcec7772a7 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs @@ -155,11 +155,12 @@ pub fn select_option_color_from_index(index: usize) -> SelectOptionColorPB { } } +#[derive(Default)] pub struct SelectOptionIds(Vec); impl SelectOptionIds { pub fn new() -> Self { - Self(vec![]) + Self::default() } pub fn into_inner(self) -> Vec { self.0 diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs b/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs index 70e4cc29b1..0444c52763 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs @@ -134,7 +134,7 @@ impl GridViewManager { row_rev: Arc, to_group_id: String, to_row_id: Option, - with_row_changeset: impl FnOnce(RowChangeset) -> AFFuture<()>, + recv_row_changeset: impl FnOnce(RowChangeset) -> AFFuture<()>, ) -> FlowyResult<()> { let mut row_changeset = RowChangeset::new(row_rev.id.clone()); let view_editor = self.get_default_view_editor().await?; @@ -143,7 +143,7 @@ impl GridViewManager { .await; if !row_changeset.is_empty() { - with_row_changeset(row_changeset).await; + recv_row_changeset(row_changeset).await; } for group_changeset in group_changesets { diff --git a/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs b/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs index fea71ebbbc..ab25cd4307 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs @@ -93,16 +93,47 @@ where }) } - pub(crate) fn groups(&self) -> Vec<&Group> { + /// Returns the groups without the default group + pub(crate) fn concrete_groups(&self) -> Vec<&Group> { self.groups_map.values().collect() } + /// Returns the all the groups that contain the default group. pub(crate) fn clone_groups(&self) -> Vec { let mut groups: Vec = self.groups_map.values().cloned().collect(); groups.push(self.default_group.clone()); groups } + /// Iterate mut the groups. The default group will be the last one that get mutated. + pub(crate) fn iter_mut_groups(&mut self, mut each: impl FnMut(&mut Group)) { + self.groups_map.iter_mut().for_each(|(_, group)| { + each(group); + }); + + each(&mut self.default_group); + } + + pub(crate) fn move_group(&mut self, from_id: &str, to_id: &str) -> FlowyResult<()> { + let from_index = self.groups_map.get_index_of(from_id); + let to_index = self.groups_map.get_index_of(to_id); + match (from_index, to_index) { + (Some(from_index), Some(to_index)) => { + self.groups_map.swap_indices(from_index, to_index); + self.mut_configuration(|configuration| { + let from_index = configuration.groups.iter().position(|group| group.id == from_id); + let to_index = configuration.groups.iter().position(|group| group.id == to_id); + if let (Some(from), Some(to)) = (from_index, to_index) { + configuration.groups.swap(from, to); + } + true + })?; + Ok(()) + } + _ => Err(FlowyError::out_of_bounds()), + } + } + pub(crate) fn merge_groups(&mut self, groups: Vec) -> FlowyResult> { let MergeGroupResult { groups, @@ -154,7 +185,7 @@ where #[allow(dead_code)] pub(crate) async fn hide_group(&mut self, group_id: &str) -> FlowyResult<()> { - self.mut_configuration_group(group_id, |group_rev| { + self.mut_group_rev(group_id, |group_rev| { group_rev.visible = false; })?; Ok(()) @@ -162,45 +193,18 @@ where #[allow(dead_code)] pub(crate) async fn show_group(&mut self, group_id: &str) -> FlowyResult<()> { - self.mut_configuration_group(group_id, |group_rev| { + self.mut_group_rev(group_id, |group_rev| { group_rev.visible = true; })?; Ok(()) } - pub(crate) fn iter_mut_groups(&mut self, mut each: impl FnMut(&mut Group)) { - self.groups_map.iter_mut().for_each(|(_, group)| { - each(group); - }) - } - - pub(crate) fn get_mut_group(&mut self, group_id: &str) -> Option<&mut Group> { - self.groups_map.get_mut(group_id) - } - pub(crate) fn get_mut_default_group(&mut self) -> &mut Group { &mut self.default_group } - pub(crate) fn move_group(&mut self, from_id: &str, to_id: &str) -> FlowyResult<()> { - let from_index = self.groups_map.get_index_of(from_id); - let to_index = self.groups_map.get_index_of(to_id); - match (from_index, to_index) { - (Some(from_index), Some(to_index)) => { - self.groups_map.swap_indices(from_index, to_index); - - self.mut_configuration(|configuration| { - let from_index = configuration.groups.iter().position(|group| group.id == from_id); - let to_index = configuration.groups.iter().position(|group| group.id == to_id); - if let (Some(from), Some(to)) = (from_index, to_index) { - configuration.groups.swap(from, to); - } - true - })?; - Ok(()) - } - _ => Err(FlowyError::out_of_bounds()), - } + pub(crate) fn get_mut_group(&mut self, group_id: &str) -> Option<&mut Group> { + self.groups_map.get_mut(group_id) } // Returns the index and group specified by the group_id @@ -231,22 +235,6 @@ where Ok(()) } - fn mut_configuration_group( - &mut self, - group_id: &str, - mut_groups_fn: impl Fn(&mut GroupRevision), - ) -> FlowyResult<()> { - self.mut_configuration(|configuration| { - match configuration.groups.iter_mut().find(|group| group.id == group_id) { - None => false, - Some(group_rev) => { - mut_groups_fn(group_rev); - true - } - } - }) - } - fn mut_configuration( &mut self, mut_configuration_fn: impl FnOnce(&mut GroupConfigurationRevision) -> bool, @@ -258,6 +246,18 @@ where } Ok(()) } + + fn mut_group_rev(&mut self, group_id: &str, mut_groups_fn: impl Fn(&mut GroupRevision)) -> FlowyResult<()> { + self.mut_configuration(|configuration| { + match configuration.groups.iter_mut().find(|group| group.id == group_id) { + None => false, + Some(group_rev) => { + mut_groups_fn(group_rev); + true + } + } + }) + } } fn merge_groups(old_groups: &[GroupRevision], groups: Vec) -> MergeGroupResult { diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs index 562f21eb17..62647d44b8 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs @@ -195,7 +195,7 @@ where let mut grouped_rows: Vec = vec![]; let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev); let cell_data = cell_bytes.parser::

()?; - for group in self.configuration.groups() { + for group in self.configuration.concrete_groups() { if self.can_group(&group.content, &cell_data) { grouped_rows.push(GroupedRow { row: row_rev.into(),