Skip to content

Commit eee3dcf

Browse files
authored
Create test template (#1594)
* refactor: rename functions * chore: create test templagte Co-authored-by: nathan <[email protected]>
1 parent af716be commit eee3dcf

File tree

36 files changed

+169
-123
lines changed

36 files changed

+169
-123
lines changed

frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CellService {
3838
..gridId = cellId.gridId
3939
..fieldId = cellId.fieldId
4040
..rowId = cellId.rowId
41-
..content = data;
41+
..typeCellData = data;
4242
return GridEventUpdateCell(payload).send();
4343
}
4444

frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ pub struct CellChangesetPB {
139139
pub field_id: String,
140140

141141
#[pb(index = 4)]
142-
pub content: String,
142+
pub type_cell_data: String,
143143
}
144144

145145
impl std::convert::From<CellChangesetPB> for RowChangeset {
146146
fn from(changeset: CellChangesetPB) -> Self {
147147
let mut cell_by_field_id = HashMap::with_capacity(1);
148148
let field_id = changeset.field_id;
149149
let cell_rev = CellRevision {
150-
data: changeset.content,
150+
type_cell_data: changeset.type_cell_data,
151151
};
152152
cell_by_field_id.insert(field_id, cell_rev);
153153

frontend/rust-lib/flowy-grid/src/event_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub(crate) async fn update_select_option_handler(
378378
grid_id: changeset.cell_identifier.view_id,
379379
row_id: changeset.cell_identifier.row_id,
380380
field_id: changeset.cell_identifier.field_id.clone(),
381-
content: cell_content_changeset,
381+
type_cell_data: cell_content_changeset,
382382
};
383383
let cloned_editor = editor.clone();
384384
tokio::spawn(async move {
@@ -413,12 +413,12 @@ pub(crate) async fn get_select_option_handler(
413413
let type_option = select_type_option_from_field_rev(&field_rev)?;
414414
let type_cell_data: TypeCellData = match cell_rev {
415415
None => TypeCellData {
416-
data: "".to_string(),
416+
cell_str: "".to_string(),
417417
field_type: field_rev.ty.into(),
418418
},
419419
Some(cell_rev) => cell_rev.try_into()?,
420420
};
421-
let ids = SelectOptionIds::from_cell_str(&type_cell_data.data)?;
421+
let ids = SelectOptionIds::from_cell_str(&type_cell_data.cell_str)?;
422422
let selected_options = type_option.get_selected_options(ids);
423423
data_result(selected_options)
424424
}

frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub trait CellComparable {
2424
/// Decode the opaque cell data into readable format content
2525
pub trait CellDataDecoder: TypeOption {
2626
///
27-
/// Tries to decode the opaque cell data to `decoded_field_type`. Sometimes, the `field_type`
27+
/// Tries to decode the opaque cell string to `decoded_field_type`'s cell data. Sometimes, the `field_type`
2828
/// of the `FieldRevision` is not equal to the `decoded_field_type`(This happened When switching
2929
/// the field type of the `FieldRevision` to another field type). So the cell data is need to do
3030
/// some transformation.
@@ -35,9 +35,9 @@ pub trait CellDataDecoder: TypeOption {
3535
/// data that can be parsed by the current field type. One approach is to transform the cell data
3636
/// when it get read. For the moment, the cell data is a string, `Yes` or `No`. It needs to compare
3737
/// with the option's name, if match return the id of the option.
38-
fn decode_cell_data(
38+
fn decode_cell_str(
3939
&self,
40-
cell_data: String,
40+
cell_str: String,
4141
decoded_field_type: &FieldType,
4242
field_rev: &FieldRevision,
4343
) -> FlowyResult<<Self as TypeOption>::CellData>;
@@ -94,8 +94,8 @@ pub fn decode_type_cell_data<T: TryInto<TypeCellData, Error = FlowyError> + Debu
9494
let to_field_type = field_rev.ty.into();
9595
match data.try_into() {
9696
Ok(type_cell_data) => {
97-
let TypeCellData { data, field_type } = type_cell_data;
98-
match try_decode_cell_data(data, &field_type, &to_field_type, field_rev) {
97+
let TypeCellData { cell_str, field_type } = type_cell_data;
98+
match try_decode_cell_str(cell_str, &field_type, &to_field_type, field_rev) {
9999
Ok(cell_bytes) => (field_type, cell_bytes),
100100
Err(e) => {
101101
tracing::error!("Decode cell data failed, {:?}", e);
@@ -120,7 +120,7 @@ pub fn decode_type_cell_data<T: TryInto<TypeCellData, Error = FlowyError> + Debu
120120
///
121121
/// # Arguments
122122
///
123-
/// * `cell_data`: the opaque cell data
123+
/// * `cell_str`: the opaque cell string
124124
/// * `from_field_type`: the original field type of the passed-in cell data. Check the `TypeCellData`
125125
/// that is used to save the origin field type of the cell data.
126126
/// * `to_field_type`: decode the passed-in cell data to this field type. It will use the to_field_type's
@@ -129,15 +129,15 @@ pub fn decode_type_cell_data<T: TryInto<TypeCellData, Error = FlowyError> + Debu
129129
///
130130
/// returns: CellBytes
131131
///
132-
pub fn try_decode_cell_data(
133-
cell_data: String,
132+
pub fn try_decode_cell_str(
133+
cell_str: String,
134134
from_field_type: &FieldType,
135135
to_field_type: &FieldType,
136136
field_rev: &FieldRevision,
137137
) -> FlowyResult<CellProtobufBlob> {
138138
match FieldRevisionExt::new(field_rev).get_type_option_cell_data_handler(to_field_type) {
139139
None => Ok(CellProtobufBlob::default()),
140-
Some(handler) => handler.handle_cell_data(cell_data, from_field_type, field_rev),
140+
Some(handler) => handler.handle_cell_str(cell_str, from_field_type, field_rev),
141141
}
142142
}
143143

@@ -153,7 +153,7 @@ pub fn stringify_cell_data(
153153
) -> String {
154154
match FieldRevisionExt::new(field_rev).get_type_option_cell_data_handler(to_field_type) {
155155
None => "".to_string(),
156-
Some(handler) => handler.stringify_cell_data(cell_data, from_field_type, field_rev),
156+
Some(handler) => handler.stringify_cell_str(cell_data, from_field_type, field_rev),
157157
}
158158
}
159159

frontend/rust-lib/flowy-grid/src/services/cell/type_cell_data.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,29 @@ use serde::{Deserialize, Serialize};
1616
///
1717
#[derive(Debug, Serialize, Deserialize)]
1818
pub struct TypeCellData {
19-
pub data: String,
19+
#[serde(rename = "data")]
20+
pub cell_str: String,
2021
pub field_type: FieldType,
2122
}
2223

2324
impl TypeCellData {
2425
pub fn from_field_type(field_type: &FieldType) -> TypeCellData {
2526
Self {
26-
data: "".to_string(),
27+
cell_str: "".to_string(),
2728
field_type: field_type.clone(),
2829
}
2930
}
3031

3132
pub fn from_json_str(s: &str) -> FlowyResult<Self> {
3233
let type_cell_data: TypeCellData = serde_json::from_str(s).map_err(|err| {
33-
let msg = format!("Deserialize {} to any cell data failed.{}", s, err);
34+
let msg = format!("Deserialize {} to type cell data failed.{}", s, err);
3435
FlowyError::internal().context(msg)
3536
})?;
3637
Ok(type_cell_data)
3738
}
3839

3940
pub fn into_inner(self) -> String {
40-
self.data
41+
self.cell_str
4142
}
4243
}
4344

@@ -54,21 +55,21 @@ where
5455
T: FromCellString,
5556
{
5657
fn from(any_call_data: TypeCellData) -> Self {
57-
IntoCellData::from(any_call_data.data)
58+
IntoCellData::from(any_call_data.cell_str)
5859
}
5960
}
6061

6162
impl ToString for TypeCellData {
6263
fn to_string(&self) -> String {
63-
self.data.clone()
64+
self.cell_str.clone()
6465
}
6566
}
6667

6768
impl std::convert::TryFrom<&CellRevision> for TypeCellData {
6869
type Error = FlowyError;
6970

7071
fn try_from(value: &CellRevision) -> Result<Self, Self::Error> {
71-
Self::from_json_str(&value.data)
72+
Self::from_json_str(&value.type_cell_data)
7273
}
7374
}
7475

@@ -83,7 +84,7 @@ impl std::convert::TryFrom<CellRevision> for TypeCellData {
8384
impl TypeCellData {
8485
pub fn new(content: String, field_type: FieldType) -> Self {
8586
TypeCellData {
86-
data: content,
87+
cell_str: content,
8788
field_type,
8889
}
8990
}

frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl CellFilterable for CheckboxTypeOptionPB {
2222
if !type_cell_data.is_checkbox() {
2323
return Ok(true);
2424
}
25-
let checkbox_cell_data = self.decode_type_option_cell_data(type_cell_data.data)?;
25+
let checkbox_cell_data = self.decode_type_option_cell_str(type_cell_data.cell_str)?;
2626
Ok(filter.is_visible(&checkbox_cell_data))
2727
}
2828
}

frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod tests {
3636
) {
3737
assert_eq!(
3838
type_option
39-
.decode_cell_data(input_str.to_owned(), field_type, field_rev)
39+
.decode_cell_str(input_str.to_owned(), field_type, field_rev)
4040
.unwrap()
4141
.to_string(),
4242
expected_str.to_owned()

frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ impl TypeOptionCellData for CheckboxTypeOptionPB {
5858
cell_data
5959
}
6060

61-
fn decode_type_option_cell_data(&self, cell_data: String) -> FlowyResult<<Self as TypeOption>::CellData> {
62-
CheckboxCellData::from_cell_str(&cell_data)
61+
fn decode_type_option_cell_str(&self, cell_str: String) -> FlowyResult<<Self as TypeOption>::CellData> {
62+
CheckboxCellData::from_cell_str(&cell_str)
6363
}
6464
}
6565

6666
impl CellDataDecoder for CheckboxTypeOptionPB {
67-
fn decode_cell_data(
67+
fn decode_cell_str(
6868
&self,
69-
cell_data: String,
69+
cell_str: String,
7070
decoded_field_type: &FieldType,
7171
_field_rev: &FieldRevision,
7272
) -> FlowyResult<<Self as TypeOption>::CellData> {
7373
if !decoded_field_type.is_checkbox() {
7474
return Ok(Default::default());
7575
}
7676

77-
self.decode_type_option_cell_data(cell_data)
77+
self.decode_type_option_cell_str(cell_str)
7878
}
7979

8080
fn decode_cell_data_to_str(&self, cell_data: <Self as TypeOption>::CellData) -> String {

frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl CellFilterable for DateTypeOptionPB {
7070
return Ok(true);
7171
}
7272

73-
let date_cell_data = self.decode_type_option_cell_data(type_cell_data.data)?;
73+
let date_cell_data = self.decode_type_option_cell_str(type_cell_data.cell_str)?;
7474
Ok(filter.is_visible(date_cell_data))
7575
}
7676
}

frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mod tests {
162162

163163
fn decode_cell_data(encoded_data: String, type_option: &DateTypeOptionPB, field_rev: &FieldRevision) -> String {
164164
let decoded_data = type_option
165-
.decode_cell_data(encoded_data, &FieldType::DateTime, field_rev)
165+
.decode_cell_str(encoded_data, &FieldType::DateTime, field_rev)
166166
.unwrap();
167167
let decoded_data = type_option.convert_to_protobuf(decoded_data);
168168
if type_option.include_time {

0 commit comments

Comments
 (0)