Skip to content

Commit edd520a

Browse files
authored
Merge pull request #877 from AppFlowy-IO/feat/board_test
chore: fix some bugs and add more tests
2 parents a0753ce + 659ae5d commit edd520a

File tree

29 files changed

+243
-75
lines changed

29 files changed

+243
-75
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,16 @@ pub struct CellChangesetPB {
131131
#[pb(index = 3)]
132132
pub field_id: String,
133133

134-
#[pb(index = 4, one_of)]
135-
pub content: Option<String>,
134+
#[pb(index = 4)]
135+
pub content: String,
136136
}
137137

138138
impl std::convert::From<CellChangesetPB> for RowChangeset {
139139
fn from(changeset: CellChangesetPB) -> Self {
140140
let mut cell_by_field_id = HashMap::with_capacity(1);
141141
let field_id = changeset.field_id;
142142
let cell_rev = CellRevision {
143-
data: changeset.content.unwrap_or_else(|| "".to_owned()),
143+
data: changeset.content,
144144
};
145145
cell_by_field_id.insert(field_id, cell_rev);
146146

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl std::convert::From<FieldRevision> for FieldPB {
4242
id: field_rev.id,
4343
name: field_rev.name,
4444
desc: field_rev.desc,
45-
field_type: field_rev.field_type_rev.into(),
45+
field_type: field_rev.ty.into(),
4646
frozen: field_rev.frozen,
4747
visibility: field_rev.visibility,
4848
width: field_rev.width,

frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl CreateGridFilterPayloadPB {
9292
pub fn new<T: Into<i32>>(field_rev: &FieldRevision, condition: T, content: Option<String>) -> Self {
9393
Self {
9494
field_id: field_rev.id.clone(),
95-
field_type: field_rev.field_type_rev.into(),
95+
field_type: field_rev.ty.into(),
9696
condition: condition.into(),
9797
content,
9898
}

frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ impl std::ops::DerefMut for RepeatedGridGroupPB {
4747
#[derive(ProtoBuf, Debug, Default, Clone)]
4848
pub struct GroupPB {
4949
#[pb(index = 1)]
50-
pub group_id: String,
50+
pub field_id: String,
5151

5252
#[pb(index = 2)]
53-
pub desc: String,
53+
pub group_id: String,
5454

5555
#[pb(index = 3)]
56+
pub desc: String,
57+
58+
#[pb(index = 4)]
5659
pub rows: Vec<RowPB>,
5760
}
5861

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub(crate) async fn get_field_type_option_data_handler(
171171
match editor.get_field_rev(&params.field_id).await {
172172
None => Err(FlowyError::record_not_found()),
173173
Some(field_rev) => {
174-
let field_type = field_rev.field_type_rev.into();
174+
let field_type = field_rev.ty.into();
175175
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
176176
let data = FieldTypeOptionDataPB {
177177
grid_id: params.grid_id,
@@ -192,7 +192,7 @@ pub(crate) async fn create_field_type_option_data_handler(
192192
let params: CreateFieldParams = data.into_inner().try_into()?;
193193
let editor = manager.get_grid_editor(&params.grid_id)?;
194194
let field_rev = editor.create_next_field_rev(&params.field_type).await?;
195-
let field_type: FieldType = field_rev.field_type_rev.into();
195+
let field_type: FieldType = field_rev.ty.into();
196196
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
197197

198198
data_result(FieldTypeOptionDataPB {
@@ -218,7 +218,7 @@ async fn get_type_option_data(field_rev: &FieldRevision, field_type: &FieldType)
218218
let s = field_rev
219219
.get_type_option_str(field_type)
220220
.unwrap_or_else(|| default_type_option_builder_from_type(field_type).entry().json_str());
221-
let field_type: FieldType = field_rev.field_type_rev.into();
221+
let field_type: FieldType = field_rev.ty.into();
222222
let builder = type_option_builder_from_json_str(&s, &field_type);
223223
let type_option_data = builder.entry().protobuf_bytes().to_vec();
224224

@@ -352,13 +352,15 @@ pub(crate) async fn update_select_option_handler(
352352
mut_field_rev.insert_type_option_entry(&*type_option);
353353
let _ = editor.replace_field(field_rev).await?;
354354

355-
let changeset = CellChangesetPB {
356-
grid_id: changeset.cell_identifier.grid_id,
357-
row_id: changeset.cell_identifier.row_id,
358-
field_id: changeset.cell_identifier.field_id,
359-
content: cell_content_changeset,
360-
};
361-
let _ = editor.update_cell(changeset).await?;
355+
if let Some(cell_content_changeset) = cell_content_changeset {
356+
let changeset = CellChangesetPB {
357+
grid_id: changeset.cell_identifier.grid_id,
358+
row_id: changeset.cell_identifier.row_id,
359+
field_id: changeset.cell_identifier.field_id,
360+
content: cell_content_changeset,
361+
};
362+
let _ = editor.update_cell(changeset).await?;
363+
}
362364
}
363365
Ok(())
364366
}
@@ -382,7 +384,7 @@ pub(crate) async fn get_select_option_handler(
382384
let any_cell_data: AnyCellData = match cell_rev {
383385
None => AnyCellData {
384386
data: "".to_string(),
385-
field_type: field_rev.field_type_rev.into(),
387+
field_type: field_rev.ty.into(),
386388
},
387389
Some(cell_rev) => cell_rev.try_into()?,
388390
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn apply_cell_data_changeset<C: ToString, T: AsRef<FieldRevision>>(
5757
) -> Result<String, FlowyError> {
5858
let field_rev = field_rev.as_ref();
5959
let changeset = changeset.to_string();
60-
let field_type = field_rev.field_type_rev.into();
60+
let field_type = field_rev.ty.into();
6161
let s = match field_type {
6262
FieldType::RichText => RichTextTypeOptionPB::from(field_rev).apply_changeset(changeset.into(), cell_rev),
6363
FieldType::Number => NumberTypeOptionPB::from(field_rev).apply_changeset(changeset.into(), cell_rev),
@@ -76,7 +76,7 @@ pub fn apply_cell_data_changeset<C: ToString, T: AsRef<FieldRevision>>(
7676
pub fn decode_any_cell_data<T: TryInto<AnyCellData>>(data: T, field_rev: &FieldRevision) -> CellBytes {
7777
if let Ok(any_cell_data) = data.try_into() {
7878
let AnyCellData { data, field_type } = any_cell_data;
79-
let to_field_type = field_rev.field_type_rev.into();
79+
let to_field_type = field_rev.ty.into();
8080
match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) {
8181
Ok(cell_bytes) => cell_bytes,
8282
Err(e) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl FieldBuilder {
3333
id: field.id,
3434
name: field.name,
3535
desc: field.desc,
36-
field_type_rev: field.field_type.into(),
36+
ty: field.field_type.into(),
3737
frozen: field.frozen,
3838
visibility: field.visibility,
3939
width: field.width,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ impl std::convert::From<DateChangesetParams> for CellChangesetPB {
5858
date: params.date,
5959
time: params.time,
6060
};
61-
let s = serde_json::to_string(&changeset).unwrap();
61+
let content = serde_json::to_string(&changeset).unwrap();
6262
CellChangesetPB {
6363
grid_id: params.cell_identifier.grid_id,
6464
row_id: params.cell_identifier.row_id,
6565
field_id: params.cell_identifier.field_id,
66-
content: Some(s),
66+
content,
6767
}
6868
}
6969
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ mod tests {
174174
field_rev: &FieldRevision,
175175
expected: Vec<SelectOptionPB>,
176176
) {
177-
let field_type: FieldType = field_rev.field_type_rev.into();
177+
let field_type: FieldType = field_rev.ty.into();
178178
assert_eq!(
179179
expected,
180180
type_option

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ where
123123
}
124124

125125
pub fn select_option_operation(field_rev: &FieldRevision) -> FlowyResult<Box<dyn SelectOptionOperation>> {
126-
let field_type: FieldType = field_rev.field_type_rev.into();
126+
let field_type: FieldType = field_rev.ty.into();
127127
match &field_type {
128128
FieldType::SingleSelect => {
129129
let type_option = SingleSelectTypeOptionPB::from(field_rev);
@@ -247,12 +247,12 @@ impl std::convert::From<SelectOptionCellChangesetParams> for CellChangesetPB {
247247
insert_option_id: params.insert_option_id,
248248
delete_option_id: params.delete_option_id,
249249
};
250-
let s = serde_json::to_string(&changeset).unwrap();
250+
let content = serde_json::to_string(&changeset).unwrap();
251251
CellChangesetPB {
252252
grid_id: params.cell_identifier.grid_id,
253253
row_id: params.cell_identifier.row_id,
254254
field_id: params.cell_identifier.field_id,
255-
content: Some(s),
255+
content,
256256
}
257257
}
258258
}

0 commit comments

Comments
 (0)