| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | #![allow(clippy::all)]
 | 
					
						
							|  |  |  | #![allow(dead_code)]
 | 
					
						
							|  |  |  | #![allow(unused_imports)]
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  | use crate::grid::block_test::util::GridRowTestBuilder;
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | use bytes::Bytes;
 | 
					
						
							| 
									
										
										
										
											2022-11-13 22:23:57 +08:00
										 |  |  | use flowy_error::FlowyResult;
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | use flowy_grid::entities::*;
 | 
					
						
							| 
									
										
										
										
											2022-07-17 13:38:53 +08:00
										 |  |  | use flowy_grid::services::field::SelectOptionPB;
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | use flowy_grid::services::field::*;
 | 
					
						
							| 
									
										
										
										
											2022-10-13 23:29:37 +08:00
										 |  |  | use flowy_grid::services::grid_editor::{GridRevisionEditor, GridRevisionSerde};
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  | use flowy_grid::services::row::{CreateRowRevisionPayload, RowRevisionBuilder};
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | use flowy_grid::services::setting::GridSettingChangesetBuilder;
 | 
					
						
							|  |  |  | use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
 | 
					
						
							|  |  |  | use flowy_sync::client_grid::GridBuilder;
 | 
					
						
							|  |  |  | use flowy_test::helper::ViewTest;
 | 
					
						
							|  |  |  | use flowy_test::FlowySDKTest;
 | 
					
						
							| 
									
										
										
										
											2022-11-08 13:51:12 +08:00
										 |  |  | use grid_rev_model::*;
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | use std::collections::HashMap;
 | 
					
						
							|  |  |  | use std::sync::Arc;
 | 
					
						
							|  |  |  | use std::time::Duration;
 | 
					
						
							|  |  |  | use strum::EnumCount;
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  | use strum::IntoEnumIterator;
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | use tokio::time::sleep;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pub struct GridEditorTest {
 | 
					
						
							|  |  |  |     pub sdk: FlowySDKTest,
 | 
					
						
							|  |  |  |     pub grid_id: String,
 | 
					
						
							|  |  |  |     pub editor: Arc<GridRevisionEditor>,
 | 
					
						
							|  |  |  |     pub field_revs: Vec<Arc<FieldRevision>>,
 | 
					
						
							|  |  |  |     pub block_meta_revs: Vec<Arc<GridBlockMetaRevision>>,
 | 
					
						
							|  |  |  |     pub row_revs: Vec<Arc<RowRevision>>,
 | 
					
						
							|  |  |  |     pub field_count: usize,
 | 
					
						
							| 
									
										
										
										
											2022-12-11 11:35:42 +08:00
										 |  |  |     pub row_by_row_id: HashMap<String, RowPB>,
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | impl GridEditorTest {
 | 
					
						
							| 
									
										
										
										
											2022-08-18 21:43:05 +08:00
										 |  |  |     pub async fn new_table() -> Self {
 | 
					
						
							|  |  |  |         Self::new(GridLayout::Table).await
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pub async fn new_board() -> Self {
 | 
					
						
							|  |  |  |         Self::new(GridLayout::Board).await
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pub async fn new(layout: GridLayout) -> Self {
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |         let sdk = FlowySDKTest::default();
 | 
					
						
							|  |  |  |         let _ = sdk.init_user().await;
 | 
					
						
							| 
									
										
										
										
											2022-08-18 21:43:05 +08:00
										 |  |  |         let test = match layout {
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |             GridLayout::Table => {
 | 
					
						
							|  |  |  |                 let build_context = make_test_grid();
 | 
					
						
							|  |  |  |                 let view_data: Bytes = build_context.into();
 | 
					
						
							|  |  |  |                 ViewTest::new_grid_view(&sdk, view_data.to_vec()).await
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             GridLayout::Board => {
 | 
					
						
							|  |  |  |                 let build_context = make_test_board();
 | 
					
						
							|  |  |  |                 let view_data: Bytes = build_context.into();
 | 
					
						
							|  |  |  |                 ViewTest::new_board_view(&sdk, view_data.to_vec()).await
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2022-08-18 21:43:05 +08:00
										 |  |  |         };
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |         let editor = sdk.grid_manager.open_grid(&test.view.id).await.unwrap();
 | 
					
						
							|  |  |  |         let field_revs = editor.get_field_revs(None).await.unwrap();
 | 
					
						
							|  |  |  |         let block_meta_revs = editor.get_block_meta_revs().await.unwrap();
 | 
					
						
							| 
									
										
										
										
											2022-11-13 22:23:57 +08:00
										 |  |  |         let row_revs = editor.get_blocks(None).await.unwrap().pop().unwrap().row_revs;
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |         assert_eq!(block_meta_revs.len(), 1);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // It seems like you should add the field in the make_test_grid() function.
 | 
					
						
							|  |  |  |         // Because we assert the initialize count of the fields is equal to FieldType::COUNT.
 | 
					
						
							|  |  |  |         assert_eq!(field_revs.len(), FieldType::COUNT);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let grid_id = test.view.id;
 | 
					
						
							|  |  |  |         Self {
 | 
					
						
							|  |  |  |             sdk,
 | 
					
						
							|  |  |  |             grid_id,
 | 
					
						
							|  |  |  |             editor,
 | 
					
						
							|  |  |  |             field_revs,
 | 
					
						
							|  |  |  |             block_meta_revs,
 | 
					
						
							|  |  |  |             row_revs,
 | 
					
						
							|  |  |  |             field_count: FieldType::COUNT,
 | 
					
						
							| 
									
										
										
										
											2022-12-11 11:35:42 +08:00
										 |  |  |             row_by_row_id: HashMap::default(),
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-13 17:25:03 +08:00
										 |  |  |     pub async fn get_row_revs(&self) -> Vec<Arc<RowRevision>> {
 | 
					
						
							| 
									
										
										
										
											2022-11-13 22:23:57 +08:00
										 |  |  |         self.editor.get_blocks(None).await.unwrap().pop().unwrap().row_revs
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-13 22:23:57 +08:00
										 |  |  |     pub async fn grid_filters(&self) -> Vec<FilterPB> {
 | 
					
						
							|  |  |  |         self.editor.get_all_filters().await.unwrap()
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  |     pub fn get_field_rev(&self, field_id: &str, field_type: FieldType) -> &Arc<FieldRevision> {
 | 
					
						
							|  |  |  |         self.field_revs
 | 
					
						
							|  |  |  |             .iter()
 | 
					
						
							|  |  |  |             .filter(|field_rev| {
 | 
					
						
							|  |  |  |                 let t_field_type: FieldType = field_rev.ty.into();
 | 
					
						
							|  |  |  |                 field_rev.id == field_id && t_field_type == field_type
 | 
					
						
							|  |  |  |             })
 | 
					
						
							|  |  |  |             .collect::<Vec<_>>()
 | 
					
						
							|  |  |  |             .pop()
 | 
					
						
							|  |  |  |             .unwrap()
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pub fn get_first_field_rev(&self, field_type: FieldType) -> &Arc<FieldRevision> {
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |         self.field_revs
 | 
					
						
							|  |  |  |             .iter()
 | 
					
						
							|  |  |  |             .filter(|field_rev| {
 | 
					
						
							| 
									
										
										
										
											2022-08-19 11:56:47 +08:00
										 |  |  |                 let t_field_type: FieldType = field_rev.ty.into();
 | 
					
						
							| 
									
										
										
										
											2022-07-13 17:25:03 +08:00
										 |  |  |                 t_field_type == field_type
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  |             })
 | 
					
						
							|  |  |  |             .collect::<Vec<_>>()
 | 
					
						
							|  |  |  |             .pop()
 | 
					
						
							|  |  |  |             .unwrap()
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  |     pub fn get_multi_select_type_option(&self, field_id: &str) -> Vec<SelectOptionPB> {
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |         let field_type = FieldType::MultiSelect;
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  |         let field_rev = self.get_field_rev(field_id, field_type.clone());
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |         let type_option = field_rev
 | 
					
						
							|  |  |  |             .get_type_option::<MultiSelectTypeOptionPB>(field_type.into())
 | 
					
						
							|  |  |  |             .unwrap();
 | 
					
						
							|  |  |  |         type_option.options
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  |     pub fn get_single_select_type_option(&self, field_id: &str) -> SingleSelectTypeOptionPB {
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |         let field_type = FieldType::SingleSelect;
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  |         let field_rev = self.get_field_rev(field_id, field_type.clone());
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |         let type_option = field_rev
 | 
					
						
							|  |  |  |             .get_type_option::<SingleSelectTypeOptionPB>(field_type.into())
 | 
					
						
							|  |  |  |             .unwrap();
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  |         type_option
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 22:40:49 +08:00
										 |  |  |     pub fn get_checklist_type_option(&self, field_id: &str) -> ChecklistTypeOptionPB {
 | 
					
						
							|  |  |  |         let field_type = FieldType::Checklist;
 | 
					
						
							|  |  |  |         let field_rev = self.get_field_rev(field_id, field_type.clone());
 | 
					
						
							|  |  |  |         let type_option = field_rev
 | 
					
						
							|  |  |  |             .get_type_option::<ChecklistTypeOptionPB>(field_type.into())
 | 
					
						
							|  |  |  |             .unwrap();
 | 
					
						
							|  |  |  |         type_option
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  |     pub fn get_checkbox_type_option(&self, field_id: &str) -> CheckboxTypeOptionPB {
 | 
					
						
							|  |  |  |         let field_type = FieldType::Checkbox;
 | 
					
						
							|  |  |  |         let field_rev = self.get_field_rev(field_id, field_type.clone());
 | 
					
						
							|  |  |  |         let type_option = field_rev
 | 
					
						
							|  |  |  |             .get_type_option::<CheckboxTypeOptionPB>(field_type.into())
 | 
					
						
							|  |  |  |             .unwrap();
 | 
					
						
							|  |  |  |         type_option
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2022-11-29 13:34:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |     pub fn block_id(&self) -> &str {
 | 
					
						
							|  |  |  |         &self.block_meta_revs.last().unwrap().block_id
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-13 22:56:34 +08:00
										 |  |  | pub const GOOGLE: &str = "Google";
 | 
					
						
							|  |  |  | pub const FACEBOOK: &str = "Facebook";
 | 
					
						
							|  |  |  | pub const TWITTER: &str = "Twitter";
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-13 22:56:34 +08:00
										 |  |  | pub const COMPLETED: &str = "Completed";
 | 
					
						
							|  |  |  | pub const PLANNED: &str = "Planned";
 | 
					
						
							|  |  |  | pub const PAUSED: &str = "Paused";
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 14:17:43 +08:00
										 |  |  | pub const FIRST_THING: &str = "Wake up at 6:00 am";
 | 
					
						
							|  |  |  | pub const SECOND_THING: &str = "Get some coffee";
 | 
					
						
							|  |  |  | pub const THIRD_THING: &str = "Start working";
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  | // This grid is assumed to contain all the Fields.
 | 
					
						
							|  |  |  | fn make_test_grid() -> BuildGridContext {
 | 
					
						
							|  |  |  |     let mut grid_builder = GridBuilder::new();
 | 
					
						
							|  |  |  |     // Iterate through the FieldType to create the corresponding Field.
 | 
					
						
							|  |  |  |     for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |         let field_type: FieldType = field_type;
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |         // The
 | 
					
						
							|  |  |  |         match field_type {
 | 
					
						
							|  |  |  |             FieldType::RichText => {
 | 
					
						
							|  |  |  |                 let text_field = FieldBuilder::new(RichTextTypeOptionBuilder::default())
 | 
					
						
							|  |  |  |                     .name("Name")
 | 
					
						
							|  |  |  |                     .visibility(true)
 | 
					
						
							| 
									
										
										
										
											2022-09-23 15:22:22 +08:00
										 |  |  |                     .primary(true)
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |                     .build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(text_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::Number => {
 | 
					
						
							|  |  |  |                 // Number
 | 
					
						
							|  |  |  |                 let number = NumberTypeOptionBuilder::default().set_format(NumberFormat::USD);
 | 
					
						
							|  |  |  |                 let number_field = FieldBuilder::new(number).name("Price").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(number_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::DateTime => {
 | 
					
						
							|  |  |  |                 // Date
 | 
					
						
							|  |  |  |                 let date = DateTypeOptionBuilder::default()
 | 
					
						
							|  |  |  |                     .date_format(DateFormat::US)
 | 
					
						
							|  |  |  |                     .time_format(TimeFormat::TwentyFourHour);
 | 
					
						
							|  |  |  |                 let date_field = FieldBuilder::new(date).name("Time").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(date_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                 // Single Select
 | 
					
						
							|  |  |  |                 let single_select = SingleSelectTypeOptionBuilder::default()
 | 
					
						
							| 
									
										
										
										
											2022-08-10 17:59:28 +08:00
										 |  |  |                     .add_option(SelectOptionPB::new(COMPLETED))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(PLANNED))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(PAUSED));
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |                 let single_select_field = FieldBuilder::new(single_select).name("Status").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(single_select_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::MultiSelect => {
 | 
					
						
							|  |  |  |                 // MultiSelect
 | 
					
						
							|  |  |  |                 let multi_select = MultiSelectTypeOptionBuilder::default()
 | 
					
						
							| 
									
										
										
										
											2022-08-13 10:01:40 +08:00
										 |  |  |                     .add_option(SelectOptionPB::new(GOOGLE))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(FACEBOOK))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(TWITTER));
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |                 let multi_select_field = FieldBuilder::new(multi_select)
 | 
					
						
							|  |  |  |                     .name("Platform")
 | 
					
						
							|  |  |  |                     .visibility(true)
 | 
					
						
							|  |  |  |                     .build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(multi_select_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::Checkbox => {
 | 
					
						
							|  |  |  |                 // Checkbox
 | 
					
						
							|  |  |  |                 let checkbox = CheckboxTypeOptionBuilder::default();
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                 let checkbox_field = FieldBuilder::new(checkbox).name("is urgent").visibility(true).build();
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |                 grid_builder.add_field(checkbox_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::URL => {
 | 
					
						
							|  |  |  |                 // URL
 | 
					
						
							|  |  |  |                 let url = URLTypeOptionBuilder::default();
 | 
					
						
							|  |  |  |                 let url_field = FieldBuilder::new(url).name("link").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(url_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2022-11-29 22:40:49 +08:00
										 |  |  |             FieldType::Checklist => {
 | 
					
						
							| 
									
										
										
										
											2022-11-29 14:17:43 +08:00
										 |  |  |                 let checklist = ChecklistTypeOptionBuilder::default()
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(FIRST_THING))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(SECOND_THING))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(THIRD_THING));
 | 
					
						
							|  |  |  |                 let checklist_field = FieldBuilder::new(checklist).name("TODO").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(checklist_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |     // We have many assumptions base on the number of the rows, so do not change the number of the loop.
 | 
					
						
							|  |  |  |     for i in 0..5 {
 | 
					
						
							|  |  |  |         let block_id = grid_builder.block_id().to_owned();
 | 
					
						
							|  |  |  |         let field_revs = grid_builder.field_revs();
 | 
					
						
							|  |  |  |         let mut row_builder = GridRowTestBuilder::new(&block_id, field_revs);
 | 
					
						
							|  |  |  |         match i {
 | 
					
						
							|  |  |  |             0 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							|  |  |  |                         FieldType::RichText => row_builder.insert_text_cell("A"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell("1"),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
 | 
					
						
							|  |  |  |                         FieldType::MultiSelect => row_builder
 | 
					
						
							|  |  |  |                             .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
 | 
					
						
							| 
									
										
										
										
											2022-11-29 22:40:49 +08:00
										 |  |  |                         FieldType::Checklist => row_builder.insert_checklist_cell(|options| options),
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             1 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:44:17 +08:00
										 |  |  |                         FieldType::RichText => row_builder.insert_text_cell(""),
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |                         FieldType::Number => row_builder.insert_number_cell("2"),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
 | 
					
						
							|  |  |  |                         FieldType::MultiSelect => row_builder
 | 
					
						
							|  |  |  |                             .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
 | 
					
						
							|  |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             2 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							|  |  |  |                         FieldType::RichText => row_builder.insert_text_cell("C"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell("3"),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
 | 
					
						
							|  |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(0))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         FieldType::MultiSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_multi_select_cell(|mut options| vec![options.remove(1)])
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             3 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							|  |  |  |                         FieldType::RichText => row_builder.insert_text_cell("DA"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell("4"),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1668704685"),
 | 
					
						
							|  |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(0))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             4 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							|  |  |  |                         FieldType::RichText => row_builder.insert_text_cell("AE"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell(""),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1668359085"),
 | 
					
						
							|  |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(1))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             _ => {}
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let row_rev = row_builder.build();
 | 
					
						
							|  |  |  |         grid_builder.add_row(row_rev);
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  |     grid_builder.build()
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fn make_test_board() -> BuildGridContext {
 | 
					
						
							|  |  |  |     let mut grid_builder = GridBuilder::new();
 | 
					
						
							|  |  |  |     // Iterate through the FieldType to create the corresponding Field.
 | 
					
						
							|  |  |  |     for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |         let field_type: FieldType = field_type;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // The
 | 
					
						
							|  |  |  |         match field_type {
 | 
					
						
							|  |  |  |             FieldType::RichText => {
 | 
					
						
							|  |  |  |                 let text_field = FieldBuilder::new(RichTextTypeOptionBuilder::default())
 | 
					
						
							|  |  |  |                     .name("Name")
 | 
					
						
							|  |  |  |                     .visibility(true)
 | 
					
						
							|  |  |  |                     .primary(true)
 | 
					
						
							|  |  |  |                     .build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(text_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::Number => {
 | 
					
						
							|  |  |  |                 // Number
 | 
					
						
							|  |  |  |                 let number = NumberTypeOptionBuilder::default().set_format(NumberFormat::USD);
 | 
					
						
							|  |  |  |                 let number_field = FieldBuilder::new(number).name("Price").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(number_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::DateTime => {
 | 
					
						
							|  |  |  |                 // Date
 | 
					
						
							|  |  |  |                 let date = DateTypeOptionBuilder::default()
 | 
					
						
							|  |  |  |                     .date_format(DateFormat::US)
 | 
					
						
							|  |  |  |                     .time_format(TimeFormat::TwentyFourHour);
 | 
					
						
							|  |  |  |                 let date_field = FieldBuilder::new(date).name("Time").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(date_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                 // Single Select
 | 
					
						
							|  |  |  |                 let single_select = SingleSelectTypeOptionBuilder::default()
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(COMPLETED))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(PLANNED))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(PAUSED));
 | 
					
						
							|  |  |  |                 let single_select_field = FieldBuilder::new(single_select).name("Status").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(single_select_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::MultiSelect => {
 | 
					
						
							|  |  |  |                 // MultiSelect
 | 
					
						
							|  |  |  |                 let multi_select = MultiSelectTypeOptionBuilder::default()
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(GOOGLE))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(FACEBOOK))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(TWITTER));
 | 
					
						
							|  |  |  |                 let multi_select_field = FieldBuilder::new(multi_select)
 | 
					
						
							|  |  |  |                     .name("Platform")
 | 
					
						
							|  |  |  |                     .visibility(true)
 | 
					
						
							|  |  |  |                     .build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(multi_select_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::Checkbox => {
 | 
					
						
							|  |  |  |                 // Checkbox
 | 
					
						
							|  |  |  |                 let checkbox = CheckboxTypeOptionBuilder::default();
 | 
					
						
							|  |  |  |                 let checkbox_field = FieldBuilder::new(checkbox).name("is urgent").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(checkbox_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             FieldType::URL => {
 | 
					
						
							|  |  |  |                 // URL
 | 
					
						
							|  |  |  |                 let url = URLTypeOptionBuilder::default();
 | 
					
						
							|  |  |  |                 let url_field = FieldBuilder::new(url).name("link").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(url_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2022-11-30 14:24:26 +08:00
										 |  |  |             FieldType::Checklist => {
 | 
					
						
							|  |  |  |                 let checklist = ChecklistTypeOptionBuilder::default()
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(FIRST_THING))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(SECOND_THING))
 | 
					
						
							|  |  |  |                     .add_option(SelectOptionPB::new(THIRD_THING));
 | 
					
						
							|  |  |  |                 let checklist_field = FieldBuilder::new(checklist).name("TODO").visibility(true).build();
 | 
					
						
							|  |  |  |                 grid_builder.add_field(checklist_field);
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |     // We have many assumptions base on the number of the rows, so do not change the number of the loop.
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |     for i in 0..5 {
 | 
					
						
							|  |  |  |         let block_id = grid_builder.block_id().to_owned();
 | 
					
						
							|  |  |  |         let field_revs = grid_builder.field_revs();
 | 
					
						
							|  |  |  |         let mut row_builder = GridRowTestBuilder::new(&block_id, field_revs);
 | 
					
						
							|  |  |  |         match i {
 | 
					
						
							|  |  |  |             0 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							|  |  |  |                         FieldType::RichText => row_builder.insert_text_cell("A"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell("1"),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
 | 
					
						
							|  |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(0))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							| 
									
										
										
										
											2022-09-02 21:34:00 +08:00
										 |  |  |                         FieldType::MultiSelect => row_builder
 | 
					
						
							|  |  |  |                             .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |             1 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							|  |  |  |                         FieldType::RichText => row_builder.insert_text_cell("B"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell("2"),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
 | 
					
						
							|  |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(0))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							| 
									
										
										
										
											2022-09-02 21:34:00 +08:00
										 |  |  |                         FieldType::MultiSelect => row_builder
 | 
					
						
							|  |  |  |                             .insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             2 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							|  |  |  |                         FieldType::RichText => row_builder.insert_text_cell("C"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell("3"),
 | 
					
						
							|  |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
 | 
					
						
							|  |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(1))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							| 
									
										
										
										
											2022-09-02 21:34:00 +08:00
										 |  |  |                         FieldType::MultiSelect => {
 | 
					
						
							| 
									
										
										
										
											2022-11-15 09:33:11 +08:00
										 |  |  |                             row_builder.insert_multi_select_cell(|mut options| vec![options.remove(0)])
 | 
					
						
							| 
									
										
										
										
											2022-09-02 21:34:00 +08:00
										 |  |  |                         }
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             3 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							| 
									
										
										
										
											2022-11-13 22:23:57 +08:00
										 |  |  |                         FieldType::RichText => row_builder.insert_text_cell("DA"),
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                         FieldType::Number => row_builder.insert_number_cell("4"),
 | 
					
						
							| 
									
										
										
										
											2022-11-14 16:33:24 +08:00
										 |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1668704685"),
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(1))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             4 => {
 | 
					
						
							|  |  |  |                 for field_type in FieldType::iter() {
 | 
					
						
							|  |  |  |                     match field_type {
 | 
					
						
							| 
									
										
										
										
											2022-11-13 22:23:57 +08:00
										 |  |  |                         FieldType::RichText => row_builder.insert_text_cell("AE"),
 | 
					
						
							|  |  |  |                         FieldType::Number => row_builder.insert_number_cell(""),
 | 
					
						
							| 
									
										
										
										
											2022-11-14 16:33:24 +08:00
										 |  |  |                         FieldType::DateTime => row_builder.insert_date_cell("1668359085"),
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                         FieldType::SingleSelect => {
 | 
					
						
							|  |  |  |                             row_builder.insert_single_select_cell(|mut options| options.remove(2))
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |                         FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
 | 
					
						
							|  |  |  |                         _ => "".to_owned(),
 | 
					
						
							|  |  |  |                     };
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             _ => {}
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-14 09:29:05 +08:00
										 |  |  |         let row_rev = row_builder.build();
 | 
					
						
							|  |  |  |         grid_builder.add_row(row_rev);
 | 
					
						
							| 
									
										
										
										
											2022-07-12 15:49:14 +08:00
										 |  |  |     }
 | 
					
						
							|  |  |  |     grid_builder.build()
 | 
					
						
							| 
									
										
										
										
											2022-07-11 17:15:16 +08:00
										 |  |  | }
 |