mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: type option handler cleanup (#4787)
This commit is contained in:
parent
682bf19838
commit
37bc5b3fbf
@ -95,13 +95,8 @@ pub fn get_cell_protobuf(
|
|||||||
|
|
||||||
let from_field_type = from_field_type.unwrap();
|
let from_field_type = from_field_type.unwrap();
|
||||||
let to_field_type = FieldType::from(field.field_type);
|
let to_field_type = FieldType::from(field.field_type);
|
||||||
match try_decode_cell_str_to_cell_protobuf(
|
match try_decode_cell_to_cell_protobuf(cell, &from_field_type, &to_field_type, field, cell_cache)
|
||||||
cell,
|
{
|
||||||
&from_field_type,
|
|
||||||
&to_field_type,
|
|
||||||
field,
|
|
||||||
cell_cache,
|
|
||||||
) {
|
|
||||||
Ok(cell_bytes) => cell_bytes,
|
Ok(cell_bytes) => cell_bytes,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Decode cell data failed, {:?}", e);
|
tracing::error!("Decode cell data failed, {:?}", e);
|
||||||
@ -126,7 +121,7 @@ pub fn get_cell_protobuf(
|
|||||||
///
|
///
|
||||||
/// returns: CellBytes
|
/// returns: CellBytes
|
||||||
///
|
///
|
||||||
pub fn try_decode_cell_str_to_cell_protobuf(
|
pub fn try_decode_cell_to_cell_protobuf(
|
||||||
cell: &Cell,
|
cell: &Cell,
|
||||||
from_field_type: &FieldType,
|
from_field_type: &FieldType,
|
||||||
to_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)
|
.get_type_option_cell_data_handler(to_field_type)
|
||||||
{
|
{
|
||||||
None => Ok(CellProtobufBlob::default()),
|
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,12 +124,8 @@ impl TypeOptionCellDataFilter for CheckboxTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_checkbox() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
filter.is_visible(cell_data)
|
filter.is_visible(cell_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,12 +178,8 @@ impl TypeOptionCellDataFilter for ChecklistTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_checklist() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
let selected_options = cell_data.selected_options();
|
let selected_options = cell_data.selected_options();
|
||||||
filter.is_visible(&cell_data.options, &selected_options)
|
filter.is_visible(&cell_data.options, &selected_options)
|
||||||
}
|
}
|
||||||
|
@ -342,12 +342,8 @@ impl TypeOptionCellDataFilter for DateTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_date() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
filter.is_visible(cell_data).unwrap_or(true)
|
filter.is_visible(cell_data).unwrap_or(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,12 +242,8 @@ impl TypeOptionCellDataFilter for NumberTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_number() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
match self.format_cell_data(cell_data) {
|
match self.format_cell_data(cell_data) {
|
||||||
Ok(cell_data) => filter.is_visible(&cell_data).unwrap_or(true),
|
Ok(cell_data) => filter.is_visible(&cell_data).unwrap_or(true),
|
||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
|
@ -116,12 +116,7 @@ impl TypeOptionCellDataCompare for RelationTypeOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TypeOptionCellDataFilter for RelationTypeOption {
|
impl TypeOptionCellDataFilter for RelationTypeOption {
|
||||||
fn apply_filter(
|
fn apply_filter(&self, _filter: &RelationFilterPB, _cell_data: &RelationCellData) -> bool {
|
||||||
&self,
|
|
||||||
_filter: &RelationFilterPB,
|
|
||||||
_field_type: &FieldType,
|
|
||||||
_cell_data: &RelationCellData,
|
|
||||||
) -> bool {
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,12 +125,8 @@ impl TypeOptionCellDataFilter for MultiSelectTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_multi_select() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
let selected_options = self.get_selected_options(cell_data.clone()).select_options;
|
let selected_options = self.get_selected_options(cell_data.clone()).select_options;
|
||||||
filter.is_visible(&selected_options, FieldType::MultiSelect)
|
filter.is_visible(&selected_options, FieldType::MultiSelect)
|
||||||
}
|
}
|
||||||
|
@ -116,12 +116,8 @@ impl TypeOptionCellDataFilter for SingleSelectTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_single_select() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
let selected_options = self.get_selected_options(cell_data.clone()).select_options;
|
let selected_options = self.get_selected_options(cell_data.clone()).select_options;
|
||||||
filter.is_visible(&selected_options, FieldType::SingleSelect)
|
filter.is_visible(&selected_options, FieldType::SingleSelect)
|
||||||
}
|
}
|
||||||
|
@ -144,13 +144,8 @@ impl TypeOptionCellDataFilter for RichTextTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_text() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
filter.is_visible(cell_data)
|
filter.is_visible(cell_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,12 +175,8 @@ impl TypeOptionCellDataFilter for TimestampTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
_filter: &<Self as TypeOption>::CellFilter,
|
_filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
_cell_data: &<Self as TypeOption>::CellData,
|
_cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_last_edited_time() && !field_type.is_created_time() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ pub trait TypeOptionTransform: TypeOption {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # 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.
|
/// * `transformed_field_type`: the cell will be transformed to the is field type's cell data.
|
||||||
/// current `TypeOption` field type.
|
/// current `TypeOption` field type.
|
||||||
///
|
///
|
||||||
@ -135,7 +135,6 @@ pub trait TypeOptionCellDataFilter: TypeOption + CellDataDecoder {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ pub const CELL_DATA: &str = "data";
|
|||||||
/// 2. there are no generic types parameters.
|
/// 2. there are no generic types parameters.
|
||||||
///
|
///
|
||||||
pub trait TypeOptionCellDataHandler: Send + Sync + 'static {
|
pub trait TypeOptionCellDataHandler: Send + Sync + 'static {
|
||||||
fn handle_cell_str(
|
fn handle_cell_protobuf(
|
||||||
&self,
|
&self,
|
||||||
cell: &Cell,
|
cell: &Cell,
|
||||||
decoded_field_type: &FieldType,
|
decoded_field_type: &FieldType,
|
||||||
@ -224,7 +224,7 @@ where
|
|||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
fn handle_cell_str(
|
fn handle_cell_protobuf(
|
||||||
&self,
|
&self,
|
||||||
cell: &Cell,
|
cell: &Cell,
|
||||||
decoded_field_type: &FieldType,
|
decoded_field_type: &FieldType,
|
||||||
@ -313,7 +313,7 @@ where
|
|||||||
let filter_cache = self.cell_filter_cache.as_ref()?.read();
|
let filter_cache = self.cell_filter_cache.as_ref()?.read();
|
||||||
let cell_filter = filter_cache.get::<<Self as TypeOption>::CellFilter>(&field.id)?;
|
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()?;
|
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)
|
perform_filter().unwrap_or(true)
|
||||||
|
@ -112,13 +112,8 @@ impl TypeOptionCellDataFilter for URLTypeOption {
|
|||||||
fn apply_filter(
|
fn apply_filter(
|
||||||
&self,
|
&self,
|
||||||
filter: &<Self as TypeOption>::CellFilter,
|
filter: &<Self as TypeOption>::CellFilter,
|
||||||
field_type: &FieldType,
|
|
||||||
cell_data: &<Self as TypeOption>::CellData,
|
cell_data: &<Self as TypeOption>::CellData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !field_type.is_url() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
filter.is_visible(cell_data)
|
filter.is_visible(cell_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user