chore: add documentation

This commit is contained in:
appflowy 2022-10-12 16:20:04 +08:00
parent c170b133e6
commit a0d0a13030
9 changed files with 43 additions and 28 deletions

View File

@ -18,14 +18,29 @@ pub trait CellGroupOperation {
/// Return object that describes the cell.
pub trait CellDisplayable<CD> {
fn display_data(
/// Serialize the cell data into `CellBytes` that will be posted to `Dart` side
///
/// Using `utf8` to encode the cell data if the cell data using `String` as its data container.
/// Using `protobuf` to encode the cell data if the cell data using `Protobuf struct` as its data container.
///
fn displayed_cell_bytes(
&self,
cell_data: CellData<CD>,
decoded_field_type: &FieldType,
field_rev: &FieldRevision,
) -> FlowyResult<CellBytes>;
fn display_string(
/// Serialize the cell data into `String` that is readable
///
/// The cell data is not readable which means it can't display the cell data directly to user.
/// For example,
/// 1. the cell data is timestamp if its field type is FieldType::Date that is not readable.
/// it needs to be parsed as the date string.
///
/// 2. the cell data is a commas separated id if its field type if FieldType::MultiSelect that is not readable.
/// it needs to be parsed as a commas separated option name.
///
fn displayed_cell_string(
&self,
cell_data: CellData<CD>,
decoded_field_type: &FieldType,
@ -126,25 +141,25 @@ pub fn decode_cell_data_to_string(
let result = match to_field_type {
FieldType::RichText => field_rev
.get_type_option::<RichTextTypeOptionPB>(field_type)?
.display_string(cell_data.into(), from_field_type, field_rev),
.displayed_cell_string(cell_data.into(), from_field_type, field_rev),
FieldType::Number => field_rev
.get_type_option::<NumberTypeOptionPB>(field_type)?
.display_string(cell_data.into(), from_field_type, field_rev),
.displayed_cell_string(cell_data.into(), from_field_type, field_rev),
FieldType::DateTime => field_rev
.get_type_option::<DateTypeOptionPB>(field_type)?
.display_string(cell_data.into(), from_field_type, field_rev),
.displayed_cell_string(cell_data.into(), from_field_type, field_rev),
FieldType::SingleSelect => field_rev
.get_type_option::<SingleSelectTypeOptionPB>(field_type)?
.display_string(cell_data.into(), from_field_type, field_rev),
.displayed_cell_string(cell_data.into(), from_field_type, field_rev),
FieldType::MultiSelect => field_rev
.get_type_option::<MultiSelectTypeOptionPB>(field_type)?
.display_string(cell_data.into(), from_field_type, field_rev),
.displayed_cell_string(cell_data.into(), from_field_type, field_rev),
FieldType::Checkbox => field_rev
.get_type_option::<CheckboxTypeOptionPB>(field_type)?
.display_string(cell_data.into(), from_field_type, field_rev),
.displayed_cell_string(cell_data.into(), from_field_type, field_rev),
FieldType::URL => field_rev
.get_type_option::<URLTypeOptionPB>(field_type)?
.display_string(cell_data.into(), from_field_type, field_rev),
.displayed_cell_string(cell_data.into(), from_field_type, field_rev),
};
Some(result)
};

View File

@ -45,7 +45,7 @@ pub struct CheckboxTypeOptionPB {
impl_type_option!(CheckboxTypeOptionPB, FieldType::Checkbox);
impl CellDisplayable<CheckboxCellData> for CheckboxTypeOptionPB {
fn display_data(
fn displayed_cell_bytes(
&self,
cell_data: CellData<CheckboxCellData>,
_decoded_field_type: &FieldType,
@ -55,7 +55,7 @@ impl CellDisplayable<CheckboxCellData> for CheckboxTypeOptionPB {
Ok(CellBytes::new(cell_data))
}
fn display_string(
fn displayed_cell_string(
&self,
cell_data: CellData<CheckboxCellData>,
_decoded_field_type: &FieldType,
@ -77,7 +77,7 @@ impl CellDataOperation<CheckboxCellData, String> for CheckboxTypeOptionPB {
return Ok(CellBytes::default());
}
self.display_data(cell_data, decoded_field_type, field_rev)
self.displayed_cell_bytes(cell_data, decoded_field_type, field_rev)
}
fn apply_changeset(

View File

@ -119,7 +119,7 @@ impl DateTypeOptionPB {
}
impl CellDisplayable<DateTimestamp> for DateTypeOptionPB {
fn display_data(
fn displayed_cell_bytes(
&self,
cell_data: CellData<DateTimestamp>,
_decoded_field_type: &FieldType,
@ -130,7 +130,7 @@ impl CellDisplayable<DateTimestamp> for DateTypeOptionPB {
CellBytes::from(date_cell_data)
}
fn display_string(
fn displayed_cell_string(
&self,
cell_data: CellData<DateTimestamp>,
_decoded_field_type: &FieldType,
@ -156,7 +156,7 @@ impl CellDataOperation<DateTimestamp, DateCellChangesetPB> for DateTypeOptionPB
if !decoded_field_type.is_date() {
return Ok(CellBytes::default());
}
self.display_data(cell_data, decoded_field_type, field_rev)
self.displayed_cell_bytes(cell_data, decoded_field_type, field_rev)
}
fn apply_changeset(

View File

@ -108,7 +108,7 @@ pub(crate) fn strip_currency_symbol<T: ToString>(s: T) -> String {
}
impl CellDisplayable<String> for NumberTypeOptionPB {
fn display_data(
fn displayed_cell_bytes(
&self,
cell_data: CellData<String>,
_decoded_field_type: &FieldType,
@ -121,7 +121,7 @@ impl CellDisplayable<String> for NumberTypeOptionPB {
}
}
fn display_string(
fn displayed_cell_string(
&self,
cell_data: CellData<String>,
_decoded_field_type: &FieldType,
@ -143,7 +143,7 @@ impl CellDataOperation<String, String> for NumberTypeOptionPB {
return Ok(CellBytes::default());
}
self.display_data(cell_data, decoded_field_type, field_rev)
self.displayed_cell_bytes(cell_data, decoded_field_type, field_rev)
}
fn apply_changeset(

View File

@ -50,7 +50,7 @@ impl CellDataOperation<SelectOptionIds, SelectOptionCellChangeset> for MultiSele
decoded_field_type: &FieldType,
field_rev: &FieldRevision,
) -> FlowyResult<CellBytes> {
self.display_data(cell_data, decoded_field_type, field_rev)
self.displayed_cell_bytes(cell_data, decoded_field_type, field_rev)
}
fn apply_changeset(

View File

@ -115,7 +115,7 @@ impl<T> CellDisplayable<SelectOptionIds> for T
where
T: SelectOptionOperation,
{
fn display_data(
fn displayed_cell_bytes(
&self,
cell_data: CellData<SelectOptionIds>,
decoded_field_type: &FieldType,
@ -128,7 +128,7 @@ where
CellBytes::from(self.selected_select_option(cell_data))
}
fn display_string(
fn displayed_cell_string(
&self,
cell_data: CellData<SelectOptionIds>,
_decoded_field_type: &FieldType,

View File

@ -52,7 +52,7 @@ impl CellDataOperation<SelectOptionIds, SelectOptionCellChangeset> for SingleSel
decoded_field_type: &FieldType,
field_rev: &FieldRevision,
) -> FlowyResult<CellBytes> {
self.display_data(cell_data, decoded_field_type, field_rev)
self.displayed_cell_bytes(cell_data, decoded_field_type, field_rev)
}
fn apply_changeset(

View File

@ -40,7 +40,7 @@ pub struct RichTextTypeOptionPB {
impl_type_option!(RichTextTypeOptionPB, FieldType::RichText);
impl CellDisplayable<String> for RichTextTypeOptionPB {
fn display_data(
fn displayed_cell_bytes(
&self,
cell_data: CellData<String>,
_decoded_field_type: &FieldType,
@ -50,7 +50,7 @@ impl CellDisplayable<String> for RichTextTypeOptionPB {
Ok(CellBytes::new(cell_str))
}
fn display_string(
fn displayed_cell_string(
&self,
cell_data: CellData<String>,
_decoded_field_type: &FieldType,
@ -77,7 +77,7 @@ impl CellDataOperation<String, String> for RichTextTypeOptionPB {
let s = decode_cell_data_to_string(cell_data, decoded_field_type, decoded_field_type, field_rev);
Ok(CellBytes::new(s.unwrap_or_else(|_| "".to_owned())))
} else {
self.display_data(cell_data, decoded_field_type, field_rev)
self.displayed_cell_bytes(cell_data, decoded_field_type, field_rev)
}
}

View File

@ -39,7 +39,7 @@ pub struct URLTypeOptionPB {
impl_type_option!(URLTypeOptionPB, FieldType::URL);
impl CellDisplayable<URLCellDataPB> for URLTypeOptionPB {
fn display_data(
fn displayed_cell_bytes(
&self,
cell_data: CellData<URLCellDataPB>,
_decoded_field_type: &FieldType,
@ -49,7 +49,7 @@ impl CellDisplayable<URLCellDataPB> for URLTypeOptionPB {
CellBytes::from(cell_data)
}
fn display_string(
fn displayed_cell_string(
&self,
cell_data: CellData<URLCellDataPB>,
_decoded_field_type: &FieldType,
@ -70,7 +70,7 @@ impl CellDataOperation<URLCellDataPB, String> for URLTypeOptionPB {
if !decoded_field_type.is_url() {
return Ok(CellBytes::default());
}
self.display_data(cell_data, decoded_field_type, field_rev)
self.displayed_cell_bytes(cell_data, decoded_field_type, field_rev)
}
fn apply_changeset(