Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: type option handler cleanup (#4787)

Richard Shiue37bc5b3fbf34
diff --git a/frontend/rust-lib/flowy-database2/src/services/cell/cell_operation.rs b/frontend/rust-lib/flowy-database2/src/services/cell/cell_operation.rs
index 2253f6405d..4caafafef0 100644
--- a/frontend/rust-lib/flowy-database2/src/services/cell/cell_operation.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/cell/cell_operation.rs
@@ -95,13 +95,8 @@ pub fn get_cell_protobuf(
let from_field_type = from_field_type.unwrap();
let to_field_type = FieldType::from(field.field_type);
- match try_decode_cell_str_to_cell_protobuf(
- cell,
- &from_field_type,
- &to_field_type,
- field,
- cell_cache,
- ) {
+ match try_decode_cell_to_cell_protobuf(cell, &from_field_type, &to_field_type, field, cell_cache)
+ {
Ok(cell_bytes) => cell_bytes,
Err(e) => {
tracing::error!("Decode cell data failed, {:?}", e);
@@ -126,7 +121,7 @@ pub fn get_cell_protobuf(
///
/// returns: CellBytes
///
-pub fn try_decode_cell_str_to_cell_protobuf(
+pub fn try_decode_cell_to_cell_protobuf(
cell: &Cell,
from_field_type: &FieldType,
to_field_type: &FieldType,
@@ -137,7 +132,7 @@ pub fn try_decode_cell_str_to_cell_protobuf(
.get_type_option_cell_data_handler(to_field_type)
{
None => Ok(CellProtobufBlob::default()),
- Some(handler) => handler.handle_cell_str(cell, from_field_type, field),
+ Some(handler) => handler.handle_cell_protobuf(cell, from_field_type, field),
}
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs
index 327d426f39..ec693d414d 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs
@@ -124,12 +124,8 @@ impl TypeOptionCellDataFilter for CheckboxTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_checkbox() {
- return true;
- }
filter.is_visible(cell_data)
}
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/checklist_type_option/checklist.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/checklist_type_option/checklist.rs
index 7a6f818f2c..8d080b2d07 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/checklist_type_option/checklist.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/checklist_type_option/checklist.rs
@@ -178,12 +178,8 @@ impl TypeOptionCellDataFilter for ChecklistTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_checklist() {
- return true;
- }
let selected_options = cell_data.selected_options();
filter.is_visible(&cell_data.options, &selected_options)
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs
index 34badaa58f..15acf6ad50 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs
@@ -342,12 +342,8 @@ impl TypeOptionCellDataFilter for DateTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_date() {
- return true;
- }
filter.is_visible(cell_data).unwrap_or(true)
}
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs
index 94da6b0c0b..b79ca661fc 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs
@@ -242,12 +242,8 @@ impl TypeOptionCellDataFilter for NumberTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_number() {
- return true;
- }
match self.format_cell_data(cell_data) {
Ok(cell_data) => filter.is_visible(&cell_data).unwrap_or(true),
Err(_) => true,
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/relation_type_option/relation.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/relation_type_option/relation.rs
index cda3d23b61..357729a0c8 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/relation_type_option/relation.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/relation_type_option/relation.rs
@@ -116,12 +116,7 @@ impl TypeOptionCellDataCompare for RelationTypeOption {
}
impl TypeOptionCellDataFilter for RelationTypeOption {
- fn apply_filter(
- &self,
- _filter: &RelationFilterPB,
- _field_type: &FieldType,
- _cell_data: &RelationCellData,
- ) -> bool {
+ fn apply_filter(&self, _filter: &RelationFilterPB, _cell_data: &RelationCellData) -> bool {
true
}
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/multi_select_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/multi_select_type_option.rs
index 5c739086e6..572bfc5021 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/multi_select_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/multi_select_type_option.rs
@@ -125,12 +125,8 @@ impl TypeOptionCellDataFilter for MultiSelectTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_multi_select() {
- return true;
- }
let selected_options = self.get_selected_options(cell_data.clone()).select_options;
filter.is_visible(&selected_options, FieldType::MultiSelect)
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/single_select_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/single_select_type_option.rs
index c047922b3a..2925dc04ef 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/single_select_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/single_select_type_option.rs
@@ -116,12 +116,8 @@ impl TypeOptionCellDataFilter for SingleSelectTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_single_select() {
- return true;
- }
let selected_options = self.get_selected_options(cell_data.clone()).select_options;
filter.is_visible(&selected_options, FieldType::SingleSelect)
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/text_type_option/text_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/text_type_option/text_type_option.rs
index 0cfa835d8c..b18664e32e 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/text_type_option/text_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/text_type_option/text_type_option.rs
@@ -144,13 +144,8 @@ impl TypeOptionCellDataFilter for RichTextTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_text() {
- return false;
- }
-
filter.is_visible(cell_data)
}
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/timestamp_type_option/timestamp_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/timestamp_type_option/timestamp_type_option.rs
index a5b78a6d89..01eb06835f 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/timestamp_type_option/timestamp_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/timestamp_type_option/timestamp_type_option.rs
@@ -175,12 +175,8 @@ impl TypeOptionCellDataFilter for TimestampTypeOption {
fn apply_filter(
&self,
_filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
_cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_last_edited_time() && !field_type.is_created_time() {
- return true;
- }
false
}
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs
index af3e0d7f7f..172b192728 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs
@@ -117,7 +117,7 @@ pub trait TypeOptionTransform: TypeOption {
///
/// # Arguments
///
- /// * `cell_str`: the cell string of the current field type
+ /// * `cell`: the cell in the current field type
/// * `transformed_field_type`: the cell will be transformed to the is field type's cell data.
/// current `TypeOption` field type.
///
@@ -135,7 +135,6 @@ pub trait TypeOptionCellDataFilter: TypeOption + CellDataDecoder {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool;
}
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option_cell.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option_cell.rs
index 4d144cf0d2..5492d92194 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option_cell.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option_cell.rs
@@ -33,7 +33,7 @@ pub const CELL_DATA: &str = "data";
/// 2. there are no generic types parameters.
///
pub trait TypeOptionCellDataHandler: Send + Sync + 'static {
- fn handle_cell_str(
+ fn handle_cell_protobuf(
&self,
cell: &Cell,
decoded_field_type: &FieldType,
@@ -224,7 +224,7 @@ where
+ Sync
+ 'static,
{
- fn handle_cell_str(
+ fn handle_cell_protobuf(
&self,
cell: &Cell,
decoded_field_type: &FieldType,
@@ -313,7 +313,7 @@ where
let filter_cache = self.cell_filter_cache.as_ref()?.read();
let cell_filter = filter_cache.get::<<Self as TypeOption>::CellFilter>(&field.id)?;
let cell_data = self.get_decoded_cell_data(cell, field_type, field).ok()?;
- Some(self.apply_filter(cell_filter, field_type, &cell_data))
+ Some(self.apply_filter(cell_filter, &cell_data))
};
perform_filter().unwrap_or(true)
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs
index b236b31018..447b5cbf56 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs
@@ -112,13 +112,8 @@ impl TypeOptionCellDataFilter for URLTypeOption {
fn apply_filter(
&self,
filter: &<Self as TypeOption>::CellFilter,
- field_type: &FieldType,
cell_data: &<Self as TypeOption>::CellData,
) -> bool {
- if !field_type.is_url() {
- return true;
- }
-
filter.is_visible(cell_data)
}
}