chore: type option handler cleanup (#4787)

This commit is contained in:
Richard Shiue 2024-03-01 10:26:38 +08:00 committed by GitHub
parent 682bf19838
commit 37bc5b3fbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 9 additions and 58 deletions

View File

@ -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),
}
}

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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,

View File

@ -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
}
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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
}
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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)
}
}