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: add comments

appflowy41989cf1866c
diff --git a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs
index 137693e13a..d43e77e9ae 100644
--- a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs
+++ b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs
@@ -458,6 +458,8 @@ impl TryInto<FieldChangesetParams> for FieldChangesetPayload {
Serialize_repr,
Deserialize_repr,
)]
+/// The order of the enum can't be changed. If you want to add a new type,
+/// it would be better to append it to the end of the list.
#[repr(u8)]
pub enum FieldType {
RichText = 0,
diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option.rs
index 09af0cda8d..b87e20e666 100644
--- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option.rs
@@ -2,7 +2,7 @@ use crate::entities::{FieldType, GridTextFilter};
use crate::impl_type_option;
use crate::services::field::{BoxTypeOptionBuilder, TextCellData, TypeOptionBuilder};
use crate::services::row::{
- AnyCellData, CellContentChangeset, CellDataOperation, CellFilterOperation, DecodedCellData, EncodedCellData,
+ AnyCellData, CellContentChangeset, CellDataOperation, CellFilterOperation, DecodedCellData, Parser,
};
use bytes::Bytes;
use fancy_regex::Regex;
@@ -46,7 +46,7 @@ impl CellFilterOperation<GridTextFilter> for URLTypeOption {
}
}
-impl CellDataOperation<EncodedCellData<URLCellData>> for URLTypeOption {
+impl CellDataOperation<Parser<URLCellData>> for URLTypeOption {
fn decode_cell_data<T>(
&self,
cell_data: T,
@@ -54,7 +54,7 @@ impl CellDataOperation<EncodedCellData<URLCellData>> for URLTypeOption {
_field_rev: &FieldRevision,
) -> FlowyResult<DecodedCellData>
where
- T: Into<EncodedCellData<URLCellData>>,
+ T: Into<Parser<URLCellData>>,
{
if !decoded_field_type.is_url() {
return Ok(DecodedCellData::default());
@@ -152,7 +152,7 @@ mod tests {
use crate::entities::FieldType;
use crate::services::field::FieldBuilder;
use crate::services::field::{URLCellData, URLTypeOption};
- use crate::services::row::{CellDataOperation, EncodedCellData};
+ use crate::services::row::{CellDataOperation, Parser};
use flowy_grid_data_model::revision::FieldRevision;
#[test]
@@ -201,7 +201,7 @@ mod tests {
assert_eq!(expected_url.to_owned(), decode_cell_data.url);
}
- fn decode_cell_data<T: Into<EncodedCellData<URLCellData>>>(
+ fn decode_cell_data<T: Into<Parser<URLCellData>>>(
encoded_data: T,
type_option: &URLTypeOption,
field_rev: &FieldRevision,
diff --git a/frontend/rust-lib/flowy-grid/src/services/row/cell_data_operation.rs b/frontend/rust-lib/flowy-grid/src/services/row/cell_data_operation.rs
index 15368d42c3..5ec0efb906 100644
--- a/frontend/rust-lib/flowy-grid/src/services/row/cell_data_operation.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/row/cell_data_operation.rs
@@ -12,6 +12,8 @@ pub trait CellFilterOperation<T> {
}
pub trait CellDataOperation<D> {
+ /// The cell_data is able to parse into the specific data that was impl the From<String> trait.
+ /// D will be URLCellData, DateCellData. etc.
fn decode_cell_data<T>(
&self,
cell_data: T,
@@ -52,6 +54,9 @@ impl std::ops::Deref for CellContentChangeset {
}
}
+/// AnyCellData is a generic CellData, you can parse the cell_data according to the field_type.
+/// When the type of field is changed, it's different from the field_type of AnyCellData.
+/// So it will return an empty data. You could check the CellDataOperation trait for more information.
#[derive(Debug, Serialize, Deserialize)]
pub struct AnyCellData {
pub cell_data: String,
@@ -230,9 +235,9 @@ pub fn try_decode_cell_data(
}
}
-pub(crate) struct EncodedCellData<T>(pub Option<T>);
+pub(crate) struct Parser<T>(pub Option<T>);
-impl<T> EncodedCellData<T> {
+impl<T> Parser<T> {
pub fn try_into_inner(self) -> FlowyResult<T> {
match self.0 {
None => Err(ErrorCode::InvalidData.into()),
@@ -241,16 +246,16 @@ impl<T> EncodedCellData<T> {
}
}
-impl<T> std::convert::From<String> for EncodedCellData<T>
+impl<T> std::convert::From<String> for Parser<T>
where
T: FromStr<Err = FlowyError>,
{
fn from(s: String) -> Self {
match T::from_str(&s) {
- Ok(inner) => EncodedCellData(Some(inner)),
+ Ok(inner) => Parser(Some(inner)),
Err(e) => {
tracing::error!("Deserialize Cell Data failed: {}", e);
- EncodedCellData(None)
+ Parser(None)
}
}
}