Skip to content

Commit 9f7f86a

Browse files
authored
chore: update test (#1584)
1 parent 2607052 commit 9f7f86a

File tree

23 files changed

+198
-147
lines changed

23 files changed

+198
-147
lines changed

frontend/rust-lib/flowy-error/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl FlowyError {
6868
static_flowy_error!(invalid_data, ErrorCode::InvalidData);
6969
static_flowy_error!(out_of_bounds, ErrorCode::OutOfBounds);
7070
static_flowy_error!(serde, ErrorCode::Serde);
71+
static_flowy_error!(field_record_not_found, ErrorCode::FieldRecordNotFound);
7172
}
7273

7374
impl std::convert::From<ErrorCode> for FlowyError {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct CellPathPB {
5151
}
5252

5353
pub struct CellPathParams {
54-
pub grid_id: String,
54+
pub view_id: String,
5555
pub field_id: String,
5656
pub row_id: String,
5757
}
@@ -64,7 +64,7 @@ impl TryInto<CellPathParams> for CellPathPB {
6464
let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
6565
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
6666
Ok(CellPathParams {
67-
grid_id: grid_id.0,
67+
view_id: grid_id.0,
6868
field_id: field_id.0,
6969
row_id: row_id.0,
7070
})

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub(crate) async fn get_cell_handler(
303303
manager: AFPluginState<Arc<GridManager>>,
304304
) -> DataResult<CellPB, FlowyError> {
305305
let params: CellPathParams = data.into_inner().try_into()?;
306-
let editor = manager.get_grid_editor(&params.grid_id).await?;
306+
let editor = manager.get_grid_editor(&params.view_id).await?;
307307
match editor.get_cell(&params).await {
308308
None => data_result(CellPB::empty(&params.field_id)),
309309
Some(cell) => data_result(cell),
@@ -344,7 +344,7 @@ pub(crate) async fn update_select_option_handler(
344344
manager: AFPluginState<Arc<GridManager>>,
345345
) -> Result<(), FlowyError> {
346346
let changeset: SelectOptionChangeset = data.into_inner().try_into()?;
347-
let editor = manager.get_grid_editor(&changeset.cell_identifier.grid_id).await?;
347+
let editor = manager.get_grid_editor(&changeset.cell_identifier.view_id).await?;
348348

349349
let _ = editor
350350
.modify_field_rev(&changeset.cell_identifier.field_id, |field_rev| {
@@ -375,7 +375,7 @@ pub(crate) async fn update_select_option_handler(
375375

376376
if let Some(cell_content_changeset) = cell_content_changeset {
377377
let changeset = CellChangesetPB {
378-
grid_id: changeset.cell_identifier.grid_id,
378+
grid_id: changeset.cell_identifier.view_id,
379379
row_id: changeset.cell_identifier.row_id,
380380
field_id: changeset.cell_identifier.field_id.clone(),
381381
content: cell_content_changeset,
@@ -401,7 +401,7 @@ pub(crate) async fn get_select_option_handler(
401401
manager: AFPluginState<Arc<GridManager>>,
402402
) -> DataResult<SelectOptionCellDataPB, FlowyError> {
403403
let params: CellPathParams = data.into_inner().try_into()?;
404-
let editor = manager.get_grid_editor(&params.grid_id).await?;
404+
let editor = manager.get_grid_editor(&params.view_id).await?;
405405
match editor.get_field_rev(&params.field_id).await {
406406
None => {
407407
tracing::error!("Can't find the select option field with id: {}", params.field_id);
@@ -431,7 +431,7 @@ pub(crate) async fn update_select_option_cell_handler(
431431
manager: AFPluginState<Arc<GridManager>>,
432432
) -> Result<(), FlowyError> {
433433
let params: SelectOptionCellChangesetParams = data.into_inner().try_into()?;
434-
let editor = manager.get_grid_editor(&params.cell_identifier.grid_id).await?;
434+
let editor = manager.get_grid_editor(&params.cell_identifier.view_id).await?;
435435
let _ = editor.update_cell_with_changeset(params.into()).await?;
436436
Ok(())
437437
}
@@ -449,9 +449,9 @@ pub(crate) async fn update_date_cell_handler(
449449
is_utc: data.is_utc,
450450
};
451451

452-
let editor = manager.get_grid_editor(&cell_path.grid_id).await?;
452+
let editor = manager.get_grid_editor(&cell_path.view_id).await?;
453453
let _ = editor
454-
.update_cell(cell_path.grid_id, cell_path.row_id, cell_path.field_id, content)
454+
.update_cell(cell_path.view_id, cell_path.row_id, cell_path.field_id, content)
455455
.await?;
456456
Ok(())
457457
}

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,17 @@ 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 try_decode_cell_data(
38+
fn decode_cell_data(
3939
&self,
4040
cell_data: String,
4141
decoded_field_type: &FieldType,
4242
field_rev: &FieldRevision,
4343
) -> FlowyResult<<Self as TypeOption>::CellData>;
4444

4545
/// Same as `decode_cell_data` does but Decode the cell data to readable `String`
46-
fn decode_cell_data_to_str(
47-
&self,
48-
cell_data: String,
49-
decoded_field_type: &FieldType,
50-
field_rev: &FieldRevision,
51-
) -> FlowyResult<String>;
46+
/// For example, The string of the Multi-Select cell will be a list of the option's name
47+
/// separated by a comma.
48+
fn decode_cell_data_to_str(&self, cell_data: <Self as TypeOption>::CellData) -> String;
5249
}
5350

5451
pub trait CellDataChangeset: TypeOption {
@@ -119,10 +116,10 @@ pub fn decode_type_cell_data<T: TryInto<TypeCellData, Error = FlowyError> + Debu
119116
}
120117
}
121118

122-
/// Decode the opaque cell data from one field type to another using the corresponding type option builder
119+
/// Decode the opaque cell data from one field type to another using the corresponding `TypeOption`
123120
///
124-
/// The cell data might become an empty string depends on these two fields' `TypeOptionBuilder`
125-
/// support transform or not.
121+
/// The cell data might become an empty string depends on the to_field_type's `TypeOption`
122+
/// support transform the from_field_type's cell data or not.
126123
///
127124
/// # Arguments
128125
///
@@ -147,10 +144,19 @@ pub fn try_decode_cell_data(
147144
}
148145
}
149146

150-
pub fn stringify_cell_data(cell_data: String, field_type: &FieldType, field_rev: &FieldRevision) -> String {
151-
match FieldRevisionExt::new(field_rev).get_type_option_handler(field_type) {
147+
/// Returns a string that represents the current field_type's cell data.
148+
/// If the cell data of the `FieldType` doesn't support displaying in String then will return an
149+
/// empty string. For example, The string of the Multi-Select cell will be a list of the option's name
150+
/// separated by a comma.
151+
pub fn stringify_cell_data(
152+
cell_data: String,
153+
from_field_type: &FieldType,
154+
to_field_type: &FieldType,
155+
field_rev: &FieldRevision,
156+
) -> String {
157+
match FieldRevisionExt::new(field_rev).get_type_option_handler(to_field_type) {
152158
None => "".to_string(),
153-
Some(handler) => handler.stringify_cell_data(cell_data, field_type, field_rev),
159+
Some(handler) => handler.stringify_cell_data(cell_data, from_field_type, field_rev),
154160
}
155161
}
156162

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-
.try_decode_cell_data(input_str.to_owned(), field_type, field_rev)
39+
.decode_cell_data(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: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl TypeOptionCellData for CheckboxTypeOptionPB {
6464
}
6565

6666
impl CellDataDecoder for CheckboxTypeOptionPB {
67-
fn try_decode_cell_data(
67+
fn decode_cell_data(
6868
&self,
6969
cell_data: String,
7070
decoded_field_type: &FieldType,
@@ -77,13 +77,8 @@ impl CellDataDecoder for CheckboxTypeOptionPB {
7777
self.decode_type_option_cell_data(cell_data)
7878
}
7979

80-
fn decode_cell_data_to_str(
81-
&self,
82-
cell_data: String,
83-
_decoded_field_type: &FieldType,
84-
_field_rev: &FieldRevision,
85-
) -> FlowyResult<String> {
86-
Ok(cell_data)
80+
fn decode_cell_data_to_str(&self, cell_data: <Self as TypeOption>::CellData) -> String {
81+
cell_data.to_string()
8782
}
8883
}
8984

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
@@ -163,7 +163,7 @@ mod tests {
163163

164164
fn decode_cell_data(encoded_data: String, type_option: &DateTypeOptionPB, field_rev: &FieldRevision) -> String {
165165
let decoded_data = type_option
166-
.try_decode_cell_data(encoded_data, &FieldType::DateTime, field_rev)
166+
.decode_cell_data(encoded_data, &FieldType::DateTime, field_rev)
167167
.unwrap();
168168
let decoded_data = type_option.convert_to_protobuf(decoded_data);
169169
if type_option.include_time {

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl DateTypeOptionPB {
131131
impl TypeOptionTransform for DateTypeOptionPB {}
132132

133133
impl CellDataDecoder for DateTypeOptionPB {
134-
fn try_decode_cell_data(
134+
fn decode_cell_data(
135135
&self,
136136
cell_data: String,
137137
decoded_field_type: &FieldType,
@@ -148,15 +148,8 @@ impl CellDataDecoder for DateTypeOptionPB {
148148
self.decode_type_option_cell_data(cell_data)
149149
}
150150

151-
fn decode_cell_data_to_str(
152-
&self,
153-
cell_data: String,
154-
_decoded_field_type: &FieldType,
155-
_field_rev: &FieldRevision,
156-
) -> FlowyResult<String> {
157-
let cell_data = self.decode_type_option_cell_data(cell_data)?;
158-
let cell_data_pb = self.today_desc_from_timestamp(cell_data);
159-
Ok(cell_data_pb.date)
151+
fn decode_cell_data_to_str(&self, cell_data: <Self as TypeOption>::CellData) -> String {
152+
self.today_desc_from_timestamp(cell_data).date
160153
}
161154
}
162155

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ mod tests {
439439
) {
440440
assert_eq!(
441441
type_option
442-
.try_decode_cell_data(input_str.to_owned(), field_type, field_rev)
442+
.decode_cell_data(input_str.to_owned(), field_type, field_rev)
443443
.unwrap()
444444
.to_string(),
445445
expected_str.to_owned()

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub(crate) fn strip_currency_symbol<T: ToString>(s: T) -> String {
128128
impl TypeOptionTransform for NumberTypeOptionPB {}
129129

130130
impl CellDataDecoder for NumberTypeOptionPB {
131-
fn try_decode_cell_data(
131+
fn decode_cell_data(
132132
&self,
133133
cell_data: String,
134134
decoded_field_type: &FieldType,
@@ -143,13 +143,11 @@ impl CellDataDecoder for NumberTypeOptionPB {
143143
Ok(s.into())
144144
}
145145

146-
fn decode_cell_data_to_str(
147-
&self,
148-
cell_data: String,
149-
_decoded_field_type: &FieldType,
150-
_field_rev: &FieldRevision,
151-
) -> FlowyResult<String> {
152-
Ok(cell_data)
146+
fn decode_cell_data_to_str(&self, cell_data: <Self as TypeOption>::CellData) -> String {
147+
match self.format_cell_data(&cell_data) {
148+
Ok(cell_data) => cell_data.to_string(),
149+
Err(_) => "".to_string(),
150+
}
153151
}
154152
}
155153

0 commit comments

Comments
 (0)