|
@@ -1,31 +1,45 @@
|
|
-use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
|
|
|
-use flowy_grid_data_model::revision::{CellRevision, FieldRevision, FieldTypeRevision};
|
|
|
|
-
|
|
|
|
use crate::entities::FieldType;
|
|
use crate::entities::FieldType;
|
|
-use crate::services::cell::{AnyCellData, DecodedCellData};
|
|
|
|
|
|
+use crate::services::cell::{AnyCellData, CellBytes};
|
|
use crate::services::field::*;
|
|
use crate::services::field::*;
|
|
|
|
|
|
|
|
+use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
|
|
|
+use flowy_grid_data_model::revision::{CellRevision, FieldRevision, FieldTypeRevision};
|
|
|
|
+
|
|
|
|
+/// This trait is used when doing filter/search on the grid.
|
|
pub trait CellFilterOperation<T> {
|
|
pub trait CellFilterOperation<T> {
|
|
/// Return true if any_cell_data match the filter condition.
|
|
/// Return true if any_cell_data match the filter condition.
|
|
fn apply_filter(&self, any_cell_data: AnyCellData, filter: &T) -> FlowyResult<bool>;
|
|
fn apply_filter(&self, any_cell_data: AnyCellData, filter: &T) -> FlowyResult<bool>;
|
|
}
|
|
}
|
|
|
|
|
|
-pub trait CellDataOperation<D, C> {
|
|
|
|
- /// The cell_data is able to parse into the specific data that was impl the FromCellData trait.
|
|
|
|
|
|
+/// Return object that describes the cell.
|
|
|
|
+pub trait CellDisplayable<CD, DC> {
|
|
|
|
+ fn display_data(
|
|
|
|
+ &self,
|
|
|
|
+ cell_data: CellData<CD>,
|
|
|
|
+ decoded_field_type: &FieldType,
|
|
|
|
+ field_rev: &FieldRevision,
|
|
|
|
+ ) -> FlowyResult<DC>;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// CD: Short for CellData. This type is the type return by apply_changeset function.
|
|
|
|
+// CS: Short for Changeset. Parse the string into specific Changeset type.
|
|
|
|
+pub trait CellDataOperation<CD, CS> {
|
|
|
|
+ /// The cell_data is able to parse into the specific data if CD impl the FromCellData trait.
|
|
/// For example:
|
|
/// For example:
|
|
/// URLCellData, DateCellData. etc.
|
|
/// URLCellData, DateCellData. etc.
|
|
fn decode_cell_data(
|
|
fn decode_cell_data(
|
|
&self,
|
|
&self,
|
|
- cell_data: CellData<D>,
|
|
|
|
|
|
+ cell_data: CellData<CD>,
|
|
decoded_field_type: &FieldType,
|
|
decoded_field_type: &FieldType,
|
|
field_rev: &FieldRevision,
|
|
field_rev: &FieldRevision,
|
|
- ) -> FlowyResult<DecodedCellData>;
|
|
|
|
|
|
+ ) -> FlowyResult<CellBytes>;
|
|
|
|
|
|
- /// The changeset is able to parse into the specific data that was impl the FromCellChangeset trait.
|
|
|
|
|
|
+ /// The changeset is able to parse into the specific data if CS impl the FromCellChangeset trait.
|
|
/// For example:
|
|
/// For example:
|
|
/// SelectOptionCellChangeset,DateCellChangeset. etc.
|
|
/// SelectOptionCellChangeset,DateCellChangeset. etc.
|
|
- fn apply_changeset(&self, changeset: CellDataChangeset<C>, cell_rev: Option<CellRevision>) -> FlowyResult<String>;
|
|
|
|
|
|
+ fn apply_changeset(&self, changeset: CellDataChangeset<CS>, cell_rev: Option<CellRevision>) -> FlowyResult<String>;
|
|
}
|
|
}
|
|
|
|
+
|
|
/// changeset: It will be deserialized into specific data base on the FieldType.
|
|
/// changeset: It will be deserialized into specific data base on the FieldType.
|
|
/// For example,
|
|
/// For example,
|
|
/// FieldType::RichText => String
|
|
/// FieldType::RichText => String
|
|
@@ -53,23 +67,20 @@ pub fn apply_cell_data_changeset<C: ToString, T: AsRef<FieldRevision>>(
|
|
Ok(AnyCellData::new(s, field_type).json())
|
|
Ok(AnyCellData::new(s, field_type).json())
|
|
}
|
|
}
|
|
|
|
|
|
-pub fn decode_any_cell_data<T: TryInto<AnyCellData>>(data: T, field_rev: &FieldRevision) -> DecodedCellData {
|
|
|
|
|
|
+pub fn decode_any_cell_data<T: TryInto<AnyCellData>>(data: T, field_rev: &FieldRevision) -> CellBytes {
|
|
if let Ok(any_cell_data) = data.try_into() {
|
|
if let Ok(any_cell_data) = data.try_into() {
|
|
- let AnyCellData {
|
|
|
|
- data: cell_data,
|
|
|
|
- field_type,
|
|
|
|
- } = any_cell_data;
|
|
|
|
|
|
+ let AnyCellData { data, field_type } = any_cell_data;
|
|
let to_field_type = field_rev.field_type_rev.into();
|
|
let to_field_type = field_rev.field_type_rev.into();
|
|
- match try_decode_cell_data(CellData(Some(cell_data)), field_rev, &field_type, &to_field_type) {
|
|
|
|
- Ok(cell_data) => cell_data,
|
|
|
|
|
|
+ match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) {
|
|
|
|
+ Ok(cell_bytes) => cell_bytes,
|
|
Err(e) => {
|
|
Err(e) => {
|
|
tracing::error!("Decode cell data failed, {:?}", e);
|
|
tracing::error!("Decode cell data failed, {:?}", e);
|
|
- DecodedCellData::default()
|
|
|
|
|
|
+ CellBytes::default()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
tracing::error!("Decode type option data failed");
|
|
tracing::error!("Decode type option data failed");
|
|
- DecodedCellData::default()
|
|
|
|
|
|
+ CellBytes::default()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -78,7 +89,7 @@ pub fn try_decode_cell_data(
|
|
field_rev: &FieldRevision,
|
|
field_rev: &FieldRevision,
|
|
s_field_type: &FieldType,
|
|
s_field_type: &FieldType,
|
|
t_field_type: &FieldType,
|
|
t_field_type: &FieldType,
|
|
-) -> FlowyResult<DecodedCellData> {
|
|
|
|
|
|
+) -> FlowyResult<CellBytes> {
|
|
let cell_data = cell_data.try_into_inner()?;
|
|
let cell_data = cell_data.try_into_inner()?;
|
|
let get_cell_data = || {
|
|
let get_cell_data = || {
|
|
let field_type: FieldTypeRevision = t_field_type.into();
|
|
let field_type: FieldTypeRevision = t_field_type.into();
|
|
@@ -112,9 +123,9 @@ pub fn try_decode_cell_data(
|
|
Some(Ok(data)) => Ok(data),
|
|
Some(Ok(data)) => Ok(data),
|
|
Some(Err(err)) => {
|
|
Some(Err(err)) => {
|
|
tracing::error!("{:?}", err);
|
|
tracing::error!("{:?}", err);
|
|
- Ok(DecodedCellData::default())
|
|
|
|
|
|
+ Ok(CellBytes::default())
|
|
}
|
|
}
|
|
- None => Ok(DecodedCellData::default()),
|
|
|
|
|
|
+ None => Ok(CellBytes::default()),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|