diff --git a/frontend/rust-lib/flowy-grid/src/services/cell/any_cell_data.rs b/frontend/rust-lib/flowy-grid/src/services/cell/any_cell_data.rs
index 8ebffcbedc..690f6f225f 100644
--- a/frontend/rust-lib/flowy-grid/src/services/cell/any_cell_data.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/cell/any_cell_data.rs
@@ -132,11 +132,11 @@ impl CellBytes {
Ok(Self(bytes))
}
- pub fn with_parser
(&self, parser: P) -> FlowyResult
+ pub fn with_parser(&self) -> FlowyResult
where
P: CellBytesParser,
{
- parser.parse(&self.0)
+ P::parse(&self.0)
}
// pub fn parse<'a, T: TryFrom<&'a [u8]>>(&'a self) -> FlowyResult
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/group_generator/generator.rs b/frontend/rust-lib/flowy-grid/src/services/group/group_generator/generator.rs
index 9bb2c2334d..66e195c814 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/group_generator/generator.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/group_generator/generator.rs
@@ -1,14 +1,15 @@
-use crate::services::cell::{decode_any_cell_data, CellBytes};
+use crate::services::cell::{decode_any_cell_data, CellBytes, CellBytesParser};
use bytes::Bytes;
use flowy_error::FlowyResult;
use flowy_grid_data_model::revision::{
CellRevision, FieldRevision, GroupConfigurationRevision, RowRevision, TypeOptionDataDeserializer,
};
+use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::Arc;
-pub trait GroupAction {
- fn should_group(&mut self, content: &str, cell_bytes: CellBytes) -> bool;
+pub trait GroupAction {
+ fn should_group(&self, content: &str, cell_data: CD) -> bool;
}
pub trait GroupCellContentProvider {
@@ -24,15 +25,16 @@ pub trait GroupGenerator {
configuration: &Option,
type_option: &Option,
cell_content_provider: &dyn GroupCellContentProvider,
- ) -> Vec;
+ ) -> HashMap;
}
-pub struct GroupController {
+pub struct GroupController {
field_rev: Arc,
- groups: Vec,
+ groups: HashMap,
type_option: Option,
configuration: Option,
- phantom: PhantomData,
+ group_action_phantom: PhantomData,
+ cell_parser_phantom: PhantomData,
}
pub struct Group {
@@ -40,7 +42,7 @@ pub struct Group {
content: String,
}
-impl GroupController
+impl GroupController
where
C: TryFrom,
T: TypeOptionDataDeserializer,
@@ -62,27 +64,39 @@ where
groups: G::gen_groups(&configuration, &type_option, cell_content_provider),
type_option,
configuration,
- phantom: PhantomData,
+ group_action_phantom: PhantomData,
+ cell_parser_phantom: PhantomData,
})
}
}
-impl GroupController
+impl GroupController
where
- Self: GroupAction,
+ CP: CellBytesParser,
+ Self: GroupAction,
{
pub fn group_row(&mut self, row: &RowRevision) {
if self.configuration.is_none() {
return;
}
if let Some(cell_rev) = row.cells.get(&self.field_rev.id) {
- for group in self.groups.iter_mut() {
+ let mut group_row_id = None;
+ let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), &self.field_rev);
+ // let cell_data = cell_bytes.with_parser(CP);
+ for group in self.groups.values() {
let cell_rev: CellRevision = cell_rev.clone();
- let cell_bytes = decode_any_cell_data(cell_rev.data, &self.field_rev);
+
// if self.should_group(&group.content, cell_bytes) {
- // group.row_ids.push(row.id.clone());
+ // group_row_id = Some(row.id.clone());
+ // break;
// }
}
+
+ if let Some(group_row_id) = group_row_id {
+ self.groups.get_mut(&group_row_id).map(|group| {
+ group.row_ids.push(group_row_id);
+ });
+ }
}
}
}
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/group_generator/select_option_group.rs b/frontend/rust-lib/flowy-grid/src/services/group/group_generator/select_option_group.rs
index bfef713ec5..9de4bf08e3 100644
--- a/frontend/rust-lib/flowy-grid/src/services/group/group_generator/select_option_group.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/group/group_generator/select_option_group.rs
@@ -1,44 +1,52 @@
use crate::entities::SelectOptionGroupConfigurationPB;
use crate::services::cell::CellBytes;
-use crate::services::field::{MultiSelectTypeOptionPB, SelectedSelectOptions, SingleSelectTypeOptionPB};
+use crate::services::field::{
+ MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser, SelectedSelectOptions,
+ SingleSelectTypeOptionPB,
+};
use crate::services::group::{Group, GroupAction, GroupCellContentProvider, GroupController, GroupGenerator};
+use std::collections::HashMap;
-pub type SingleSelectGroupController =
- GroupController;
+pub type SingleSelectGroupController = GroupController<
+ SelectOptionGroupConfigurationPB,
+ SingleSelectTypeOptionPB,
+ SingleSelectGroupGenerator,
+ SelectOptionCellDataParser,
+>;
-pub struct SingleSelectGroupGen();
-impl GroupGenerator for SingleSelectGroupGen {
+pub struct SingleSelectGroupGenerator();
+impl GroupGenerator for SingleSelectGroupGenerator {
fn gen_groups(
configuration: &Option,
type_option: &Option,
cell_content_provider: &dyn GroupCellContentProvider,
- ) -> Vec {
+ ) -> HashMap {
todo!()
}
}
-impl GroupAction for SingleSelectGroupController {
- fn should_group(&mut self, content: &str, cell_bytes: CellBytes) -> bool {
+impl GroupAction for SingleSelectGroupController {
+ fn should_group(&self, content: &str, cell_data: SelectOptionCellDataPB) -> bool {
todo!()
}
}
-pub type MultiSelectGroupController =
- GroupController;
-
-pub struct MultiSelectGroupGen();
-impl GroupGenerator for MultiSelectGroupGen {
- fn gen_groups(
- configuration: &Option,
- type_option: &Option,
- cell_content_provider: &dyn GroupCellContentProvider,
- ) -> Vec {
- todo!()
- }
-}
-
-impl GroupAction for MultiSelectGroupController {
- fn should_group(&mut self, content: &str, cell_bytes: CellBytes) -> bool {
- todo!()
- }
-}
+// pub type MultiSelectGroupController =
+// GroupController;
+//
+// pub struct MultiSelectGroupGenerator();
+// impl GroupGenerator for MultiSelectGroupGenerator {
+// fn gen_groups(
+// configuration: &Option,
+// type_option: &Option,
+// cell_content_provider: &dyn GroupCellContentProvider,
+// ) -> HashMap {
+// todo!()
+// }
+// }
+//
+// impl GroupAction for MultiSelectGroupController {
+// fn should_group(&self, content: &str, cell_bytes: CellBytes) -> bool {
+// todo!()
+// }
+// }