diff --git a/frontend/app_flowy/test/bloc_test/board_test/group_by_field_test.dart b/frontend/app_flowy/test/bloc_test/board_test/group_by_field_test.dart index e343e95698..df6f2713e7 100644 --- a/frontend/app_flowy/test/bloc_test/board_test/group_by_field_test.dart +++ b/frontend/app_flowy/test/bloc_test/board_test/group_by_field_test.dart @@ -105,6 +105,7 @@ void main() { fieldController: boardTest.context.fieldController, ), act: (bloc) async { + await boardResponseFuture(); bloc.add(GridGroupEvent.setGroupByField( multiSelectField.id, multiSelectField.fieldType, diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs index 11aff9a21f..577dc34beb 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs @@ -12,26 +12,27 @@ impl SelectOptionFilterPB { match self.condition { SelectOptionCondition::OptionIs => { if self.option_ids.len() != selected_option_ids.len() { - return true; + return false; } - // if selected options equal to filter's options, then the required_options will be empty. let required_options = self .option_ids .iter() - .filter(|id| !selected_option_ids.contains(id)) + .filter(|id| selected_option_ids.contains(id)) .collect::>(); - - // https://stackoverflow.com/questions/69413164/how-to-fix-this-clippy-warning-needless-collect - !required_options.is_empty() + required_options.len() == selected_option_ids.len() } SelectOptionCondition::OptionIsNot => { - for option_id in selected_option_ids { - if self.option_ids.contains(option_id) { - return true; - } + if self.option_ids.len() != selected_option_ids.len() { + return true; } - false + let required_options = self + .option_ids + .iter() + .filter(|id| selected_option_ids.contains(id)) + .collect::>(); + + required_options.len() != selected_option_ids.len() } SelectOptionCondition::OptionIsEmpty => selected_option_ids.is_empty(), SelectOptionCondition::OptionIsNotEmpty => !selected_option_ids.is_empty(), @@ -67,43 +68,87 @@ mod tests { use crate::services::field::selection_type_option::{SelectOptionPB, SelectedSelectOptions}; #[test] - fn select_option_filter_is_test() { + fn select_option_filter_is_empty_test() { + let option = SelectOptionPB::new("A"); + let filter = SelectOptionFilterPB { + condition: SelectOptionCondition::OptionIsEmpty, + option_ids: vec![], + }; + + assert_eq!(filter.is_visible(&SelectedSelectOptions { options: vec![] }), true); + + assert_eq!( + filter.is_visible(&SelectedSelectOptions { options: vec![option] }), + false, + ); + } + #[test] + fn select_option_filter_is_not_test() { let option_1 = SelectOptionPB::new("A"); let option_2 = SelectOptionPB::new("B"); let option_3 = SelectOptionPB::new("C"); - let filter_1 = SelectOptionFilterPB { - condition: SelectOptionCondition::OptionIs, + let filter = SelectOptionFilterPB { + condition: SelectOptionCondition::OptionIsNot, option_ids: vec![option_1.id.clone(), option_2.id.clone()], }; assert_eq!( - filter_1.is_visible(&SelectedSelectOptions { + filter.is_visible(&SelectedSelectOptions { options: vec![option_1.clone(), option_2.clone()], }), false ); assert_eq!( - filter_1.is_visible(&SelectedSelectOptions { + filter.is_visible(&SelectedSelectOptions { options: vec![option_1.clone(), option_2.clone(), option_3.clone()], }), true ); assert_eq!( - filter_1.is_visible(&SelectedSelectOptions { + filter.is_visible(&SelectedSelectOptions { options: vec![option_1.clone(), option_3.clone()], }), true ); - assert_eq!(filter_1.is_visible(&SelectedSelectOptions { options: vec![] }), true); + assert_eq!(filter.is_visible(&SelectedSelectOptions { options: vec![] }), true); + } + + #[test] + fn select_option_filter_is_test() { + let option_1 = SelectOptionPB::new("A"); + let option_2 = SelectOptionPB::new("B"); + let option_3 = SelectOptionPB::new("C"); + + let filter = SelectOptionFilterPB { + condition: SelectOptionCondition::OptionIs, + option_ids: vec![option_1.id.clone(), option_2.id.clone()], + }; + assert_eq!( - filter_1.is_visible(&SelectedSelectOptions { - options: vec![option_1.clone()], + filter.is_visible(&SelectedSelectOptions { + options: vec![option_1.clone(), option_2.clone()], }), - true, + true ); + + assert_eq!( + filter.is_visible(&SelectedSelectOptions { + options: vec![option_1.clone(), option_2.clone(), option_3.clone()], + }), + false + ); + + assert_eq!( + filter.is_visible(&SelectedSelectOptions { + options: vec![option_1.clone(), option_3.clone()], + }), + false + ); + + assert_eq!(filter.is_visible(&SelectedSelectOptions { options: vec![] }), false); } } diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs index ca2b589bc8..f1e4b5f52d 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs @@ -237,8 +237,8 @@ impl GridViewRevisionEditor { Ok(()) } - pub(crate) async fn is_grouped(&self) -> bool { - self.group_controller.read().await.groups().len() > 1 + pub(crate) async fn group_id(&self) -> String { + self.group_controller.read().await.field_id().to_string() } pub(crate) async fn get_view_setting(&self) -> GridSettingPB { 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 b626eed8f1..8a254b4229 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 @@ -184,7 +184,7 @@ impl GridViewManager { #[tracing::instrument(level = "trace", skip(self), err)] pub(crate) async fn did_update_view_field_type_option(&self, field_id: &str) -> FlowyResult<()> { let view_editor = self.get_default_view_editor().await?; - if view_editor.is_grouped().await { + if view_editor.group_id().await == field_id { let _ = view_editor.group_by_view_field(field_id).await?; }