65 lines
2.2 KiB
Rust
Raw Normal View History

use flowy_grid::entities::*;
2022-07-17 13:38:53 +08:00
use flowy_grid::services::field::selection_type_option::SelectOptionPB;
use flowy_grid::services::field::*;
2023-01-30 11:11:19 +08:00
use grid_model::*;
2022-06-23 23:06:03 +08:00
2022-10-10 21:21:29 +08:00
pub fn create_text_field(grid_id: &str) -> (CreateFieldParams, FieldRevision) {
let mut field_rev = FieldBuilder::new(RichTextTypeOptionBuilder::default())
2022-06-23 23:06:03 +08:00
.name("Name")
.visibility(true)
.build();
let cloned_field_rev = field_rev.clone();
let type_option_data = field_rev
.get_type_option::<RichTextTypeOptionPB>(field_rev.ty)
2022-06-23 23:06:03 +08:00
.unwrap()
.protobuf_bytes()
.to_vec();
2022-10-10 21:21:29 +08:00
let type_option_builder = type_option_builder_from_bytes(type_option_data.clone(), &field_rev.ty.into());
field_rev.insert_type_option(type_option_builder.serializer());
2022-06-23 23:06:03 +08:00
2022-10-10 21:21:29 +08:00
let params = CreateFieldParams {
2022-06-23 23:06:03 +08:00
grid_id: grid_id.to_owned(),
2022-10-10 21:21:29 +08:00
field_type: field_rev.ty.into(),
type_option_data: Some(type_option_data),
2022-06-23 23:06:03 +08:00
};
(params, cloned_field_rev)
}
2022-10-10 21:21:29 +08:00
pub fn create_single_select_field(grid_id: &str) -> (CreateFieldParams, FieldRevision) {
2022-06-23 23:06:03 +08:00
let single_select = SingleSelectTypeOptionBuilder::default()
2022-08-10 17:59:28 +08:00
.add_option(SelectOptionPB::new("Done"))
.add_option(SelectOptionPB::new("Progress"));
2022-06-23 23:06:03 +08:00
2022-10-10 21:21:29 +08:00
let mut field_rev = FieldBuilder::new(single_select).name("Name").visibility(true).build();
2022-06-23 23:06:03 +08:00
let cloned_field_rev = field_rev.clone();
let type_option_data = field_rev
.get_type_option::<SingleSelectTypeOptionPB>(field_rev.ty)
2022-06-23 23:06:03 +08:00
.unwrap()
.protobuf_bytes()
.to_vec();
2022-10-10 21:21:29 +08:00
let type_option_builder = type_option_builder_from_bytes(type_option_data.clone(), &field_rev.ty.into());
field_rev.insert_type_option(type_option_builder.serializer());
2022-06-23 23:06:03 +08:00
2022-10-10 21:21:29 +08:00
let params = CreateFieldParams {
2022-06-23 23:06:03 +08:00
grid_id: grid_id.to_owned(),
2022-10-10 21:21:29 +08:00
field_type: field_rev.ty.into(),
type_option_data: Some(type_option_data),
2022-06-23 23:06:03 +08:00
};
(params, cloned_field_rev)
}
// The grid will contains all existing field types and there are three empty rows in this grid.
pub fn make_date_cell_string(s: &str) -> String {
2022-11-14 12:03:22 +08:00
serde_json::to_string(&DateCellChangeset {
2022-06-23 23:06:03 +08:00
date: Some(s.to_string()),
time: None,
2022-11-14 16:33:24 +08:00
is_utc: true,
2022-06-23 23:06:03 +08:00
})
.unwrap()
}