2022-03-15 11:00:28 +00:00
|
|
|
use bytes::Bytes;
|
2023-01-30 03:11:19 +00:00
|
|
|
use flowy_client_sync::client_grid::GridBuilder;
|
2022-03-12 13:06:15 +00:00
|
|
|
use flowy_grid::services::field::*;
|
2022-06-07 06:22:20 +00:00
|
|
|
use flowy_grid::services::grid_meta_editor::{GridMetaEditor, GridPadBuilder};
|
2022-03-18 13:04:01 +00:00
|
|
|
use flowy_grid::services::row::CreateRowMetaPayload;
|
2022-03-19 08:52:28 +00:00
|
|
|
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
2022-03-12 13:06:15 +00:00
|
|
|
use flowy_test::helper::ViewTest;
|
|
|
|
use flowy_test::FlowySDKTest;
|
2023-01-30 03:11:19 +00:00
|
|
|
use grid_model::entities::{
|
2022-11-08 05:51:12 +00:00
|
|
|
BuildGridContext, CellChangeset, Field, FieldChangesetParams, FieldMeta, FieldOrder, FieldType,
|
|
|
|
GridBlockInfoChangeset, GridBlockMetaSnapshot, InsertFieldParams, RowMeta, RowMetaChangeset, RowOrder,
|
|
|
|
TypeOptionDataFormat,
|
|
|
|
};
|
2022-03-23 14:10:31 +00:00
|
|
|
use std::collections::HashMap;
|
2022-03-12 13:06:15 +00:00
|
|
|
use std::sync::Arc;
|
2022-03-12 14:52:24 +00:00
|
|
|
use std::time::Duration;
|
2022-03-16 02:02:37 +00:00
|
|
|
use strum::EnumCount;
|
2022-03-12 14:52:24 +00:00
|
|
|
use tokio::time::sleep;
|
2022-03-12 13:06:15 +00:00
|
|
|
|
|
|
|
pub enum EditorScript {
|
2022-03-14 09:24:25 +00:00
|
|
|
CreateField {
|
2022-04-12 02:06:47 +00:00
|
|
|
params: InsertFieldParams,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
|
|
|
UpdateField {
|
2022-04-01 14:49:26 +00:00
|
|
|
changeset: FieldChangesetParams,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
|
|
|
DeleteField {
|
2022-03-15 03:07:18 +00:00
|
|
|
field_meta: FieldMeta,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
2022-03-12 14:52:24 +00:00
|
|
|
AssertFieldCount(usize),
|
2022-03-14 09:24:25 +00:00
|
|
|
AssertFieldEqual {
|
|
|
|
field_index: usize,
|
2022-03-15 03:07:18 +00:00
|
|
|
field_meta: FieldMeta,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
|
|
|
CreateBlock {
|
2022-06-07 06:22:20 +00:00
|
|
|
block: GridBlockMetaSnapshot,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
|
|
|
UpdateBlock {
|
2022-06-07 06:22:20 +00:00
|
|
|
changeset: GridBlockInfoChangeset,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
2022-03-13 03:06:28 +00:00
|
|
|
AssertBlockCount(usize),
|
2022-03-14 09:24:25 +00:00
|
|
|
AssertBlock {
|
|
|
|
block_index: usize,
|
|
|
|
row_count: i32,
|
|
|
|
start_row_index: i32,
|
|
|
|
},
|
|
|
|
AssertBlockEqual {
|
|
|
|
block_index: usize,
|
2022-06-07 06:22:20 +00:00
|
|
|
block: GridBlockMetaSnapshot,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
|
|
|
CreateEmptyRow,
|
|
|
|
CreateRow {
|
2022-03-18 13:04:01 +00:00
|
|
|
context: CreateRowMetaPayload,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
|
|
|
UpdateRow {
|
|
|
|
changeset: RowMetaChangeset,
|
|
|
|
},
|
|
|
|
AssertRow {
|
|
|
|
changeset: RowMetaChangeset,
|
|
|
|
},
|
|
|
|
DeleteRow {
|
|
|
|
row_ids: Vec<String>,
|
|
|
|
},
|
|
|
|
UpdateCell {
|
2022-04-11 06:09:50 +00:00
|
|
|
changeset: CellChangeset,
|
2022-03-16 02:02:37 +00:00
|
|
|
is_err: bool,
|
2022-03-14 09:24:25 +00:00
|
|
|
},
|
2022-03-13 03:06:28 +00:00
|
|
|
AssertRowCount(usize),
|
|
|
|
// AssertRowEqual{ row_index: usize, row: RowMeta},
|
|
|
|
AssertGridMetaPad,
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct GridEditorTest {
|
|
|
|
pub sdk: FlowySDKTest,
|
|
|
|
pub grid_id: String,
|
2022-05-26 09:28:44 +00:00
|
|
|
pub editor: Arc<GridMetaEditor>,
|
2022-03-15 03:07:18 +00:00
|
|
|
pub field_metas: Vec<FieldMeta>,
|
2022-06-07 06:22:20 +00:00
|
|
|
pub grid_blocks: Vec<GridBlockMetaSnapshot>,
|
2022-03-15 03:07:18 +00:00
|
|
|
pub row_metas: Vec<Arc<RowMeta>>,
|
2022-03-15 11:00:28 +00:00
|
|
|
pub field_count: usize,
|
2022-03-18 13:04:01 +00:00
|
|
|
|
|
|
|
pub row_order_by_row_id: HashMap<String, RowOrder>,
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl GridEditorTest {
|
|
|
|
pub async fn new() -> Self {
|
|
|
|
let sdk = FlowySDKTest::default();
|
|
|
|
let _ = sdk.init_user().await;
|
2022-03-15 11:00:28 +00:00
|
|
|
let build_context = make_template_1_grid();
|
2022-04-11 06:09:50 +00:00
|
|
|
let view_data: Bytes = build_context.into();
|
2022-03-15 11:00:28 +00:00
|
|
|
let test = ViewTest::new_grid_view(&sdk, view_data.to_vec()).await;
|
2022-03-12 13:06:15 +00:00
|
|
|
let editor = sdk.grid_manager.open_grid(&test.view.id).await.unwrap();
|
2022-04-07 07:34:00 +00:00
|
|
|
let field_metas = editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
2022-03-18 09:14:46 +00:00
|
|
|
let grid_blocks = editor.get_block_metas().await.unwrap();
|
|
|
|
let row_metas = get_row_metas(&editor).await;
|
2022-03-14 09:24:25 +00:00
|
|
|
|
2022-03-12 13:06:15 +00:00
|
|
|
let grid_id = test.view.id;
|
2022-03-14 09:24:25 +00:00
|
|
|
Self {
|
|
|
|
sdk,
|
|
|
|
grid_id,
|
|
|
|
editor,
|
2022-03-15 11:00:28 +00:00
|
|
|
field_metas,
|
2022-03-14 09:24:25 +00:00
|
|
|
grid_blocks,
|
|
|
|
row_metas,
|
2022-03-15 11:00:28 +00:00
|
|
|
field_count: FieldType::COUNT,
|
2022-03-18 13:04:01 +00:00
|
|
|
row_order_by_row_id: HashMap::default(),
|
2022-03-14 09:24:25 +00:00
|
|
|
}
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run_scripts(&mut self, scripts: Vec<EditorScript>) {
|
|
|
|
for script in scripts {
|
|
|
|
self.run_script(script).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run_script(&mut self, script: EditorScript) {
|
|
|
|
let grid_manager = self.sdk.grid_manager.clone();
|
|
|
|
let pool = self.sdk.user_session.db_pool().unwrap();
|
|
|
|
let rev_manager = self.editor.rev_manager();
|
2022-03-14 15:16:25 +00:00
|
|
|
let _cache = rev_manager.revision_cache().await;
|
2022-03-12 13:06:15 +00:00
|
|
|
|
|
|
|
match script {
|
2022-03-23 14:10:31 +00:00
|
|
|
EditorScript::CreateField { params } => {
|
|
|
|
if !self.editor.contain_field(¶ms.field.id).await {
|
2022-03-15 11:00:28 +00:00
|
|
|
self.field_count += 1;
|
|
|
|
}
|
2022-03-23 14:10:31 +00:00
|
|
|
|
2022-04-12 02:06:47 +00:00
|
|
|
self.editor.insert_field(params).await.unwrap();
|
2022-04-07 07:34:00 +00:00
|
|
|
self.field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
2022-03-15 11:00:28 +00:00
|
|
|
assert_eq!(self.field_count, self.field_metas.len());
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
2022-03-14 09:24:25 +00:00
|
|
|
EditorScript::UpdateField { changeset: change } => {
|
2022-03-12 14:52:24 +00:00
|
|
|
self.editor.update_field(change).await.unwrap();
|
2022-04-07 07:34:00 +00:00
|
|
|
self.field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
2022-03-12 14:52:24 +00:00
|
|
|
}
|
2022-03-15 11:00:28 +00:00
|
|
|
EditorScript::DeleteField { field_meta } => {
|
2022-03-23 14:10:31 +00:00
|
|
|
if self.editor.contain_field(&field_meta.id).await {
|
2022-03-15 11:00:28 +00:00
|
|
|
self.field_count -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.editor.delete_field(&field_meta.id).await.unwrap();
|
2022-04-07 07:34:00 +00:00
|
|
|
self.field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
2022-03-15 11:00:28 +00:00
|
|
|
assert_eq!(self.field_count, self.field_metas.len());
|
2022-03-13 03:06:28 +00:00
|
|
|
}
|
2022-03-12 14:52:24 +00:00
|
|
|
EditorScript::AssertFieldCount(count) => {
|
2022-04-07 07:34:00 +00:00
|
|
|
assert_eq!(
|
|
|
|
self.editor.get_field_metas::<FieldOrder>(None).await.unwrap().len(),
|
|
|
|
count
|
|
|
|
);
|
2022-03-12 14:52:24 +00:00
|
|
|
}
|
2022-03-15 03:07:18 +00:00
|
|
|
EditorScript::AssertFieldEqual {
|
|
|
|
field_index,
|
|
|
|
field_meta,
|
|
|
|
} => {
|
2022-04-07 07:34:00 +00:00
|
|
|
let field_metas = self.editor.get_field_metas::<FieldOrder>(None).await.unwrap();
|
2022-03-15 03:07:18 +00:00
|
|
|
assert_eq!(field_metas[field_index].clone(), field_meta);
|
2022-03-12 14:52:24 +00:00
|
|
|
}
|
2022-03-13 03:06:28 +00:00
|
|
|
EditorScript::CreateBlock { block } => {
|
|
|
|
self.editor.create_block(block).await.unwrap();
|
2022-03-18 09:14:46 +00:00
|
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
2022-03-13 03:06:28 +00:00
|
|
|
}
|
2022-03-14 09:24:25 +00:00
|
|
|
EditorScript::UpdateBlock { changeset: change } => {
|
2022-03-13 03:06:28 +00:00
|
|
|
self.editor.update_block(change).await.unwrap();
|
|
|
|
}
|
|
|
|
EditorScript::AssertBlockCount(count) => {
|
2022-03-18 09:14:46 +00:00
|
|
|
assert_eq!(self.editor.get_block_metas().await.unwrap().len(), count);
|
2022-03-13 03:06:28 +00:00
|
|
|
}
|
2022-03-14 09:24:25 +00:00
|
|
|
EditorScript::AssertBlock {
|
|
|
|
block_index,
|
|
|
|
row_count,
|
|
|
|
start_row_index,
|
|
|
|
} => {
|
|
|
|
assert_eq!(self.grid_blocks[block_index].row_count, row_count);
|
|
|
|
assert_eq!(self.grid_blocks[block_index].start_row_index, start_row_index);
|
|
|
|
}
|
2022-03-13 03:06:28 +00:00
|
|
|
EditorScript::AssertBlockEqual { block_index, block } => {
|
2022-03-18 09:14:46 +00:00
|
|
|
let blocks = self.editor.get_block_metas().await.unwrap();
|
2022-03-13 03:06:28 +00:00
|
|
|
let compared_block = blocks[block_index].clone();
|
|
|
|
assert_eq!(compared_block, block);
|
|
|
|
}
|
2022-03-14 09:24:25 +00:00
|
|
|
EditorScript::CreateEmptyRow => {
|
2022-03-18 13:04:01 +00:00
|
|
|
let row_order = self.editor.create_row(None).await.unwrap();
|
|
|
|
self.row_order_by_row_id.insert(row_order.row_id.clone(), row_order);
|
2022-03-18 09:14:46 +00:00
|
|
|
self.row_metas = self.get_row_metas().await;
|
|
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
2022-03-14 09:24:25 +00:00
|
|
|
}
|
|
|
|
EditorScript::CreateRow { context } => {
|
2022-03-18 13:04:01 +00:00
|
|
|
let row_orders = self.editor.insert_rows(vec![context]).await.unwrap();
|
|
|
|
for row_order in row_orders {
|
|
|
|
self.row_order_by_row_id.insert(row_order.row_id.clone(), row_order);
|
|
|
|
}
|
2022-03-18 09:14:46 +00:00
|
|
|
self.row_metas = self.get_row_metas().await;
|
|
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
2022-03-14 09:24:25 +00:00
|
|
|
}
|
|
|
|
EditorScript::UpdateRow { changeset: change } => self.editor.update_row(change).await.unwrap(),
|
|
|
|
EditorScript::DeleteRow { row_ids } => {
|
2022-03-18 13:04:01 +00:00
|
|
|
let row_orders = row_ids
|
|
|
|
.into_iter()
|
|
|
|
.map(|row_id| self.row_order_by_row_id.get(&row_id).unwrap().clone())
|
|
|
|
.collect::<Vec<RowOrder>>();
|
|
|
|
|
|
|
|
self.editor.delete_rows(row_orders).await.unwrap();
|
2022-03-18 09:14:46 +00:00
|
|
|
self.row_metas = self.get_row_metas().await;
|
|
|
|
self.grid_blocks = self.editor.get_block_metas().await.unwrap();
|
2022-03-14 09:24:25 +00:00
|
|
|
}
|
|
|
|
EditorScript::AssertRow { changeset } => {
|
|
|
|
let row = self.row_metas.iter().find(|row| row.id == changeset.row_id).unwrap();
|
|
|
|
|
|
|
|
if let Some(visibility) = changeset.visibility {
|
|
|
|
assert_eq!(row.visibility, visibility);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(height) = changeset.height {
|
|
|
|
assert_eq!(row.height, height);
|
|
|
|
}
|
|
|
|
}
|
2022-03-16 02:02:37 +00:00
|
|
|
EditorScript::UpdateCell { changeset, is_err } => {
|
|
|
|
let result = self.editor.update_cell(changeset).await;
|
|
|
|
if is_err {
|
|
|
|
assert!(result.is_err())
|
|
|
|
} else {
|
|
|
|
let _ = result.unwrap();
|
2022-03-18 09:14:46 +00:00
|
|
|
self.row_metas = self.get_row_metas().await;
|
2022-03-16 02:02:37 +00:00
|
|
|
}
|
2022-03-13 03:06:28 +00:00
|
|
|
}
|
|
|
|
EditorScript::AssertRowCount(count) => {
|
2022-03-18 09:14:46 +00:00
|
|
|
assert_eq!(self.row_metas.len(), count);
|
2022-03-13 03:06:28 +00:00
|
|
|
}
|
2022-03-12 13:06:15 +00:00
|
|
|
EditorScript::AssertGridMetaPad => {
|
2022-03-12 14:52:24 +00:00
|
|
|
sleep(Duration::from_millis(2 * REVISION_WRITE_INTERVAL_IN_MILLIS)).await;
|
2022-03-12 13:06:15 +00:00
|
|
|
let mut grid_rev_manager = grid_manager.make_grid_rev_manager(&self.grid_id, pool.clone()).unwrap();
|
|
|
|
let grid_pad = grid_rev_manager.load::<GridPadBuilder>(None).await.unwrap();
|
|
|
|
println!("{}", grid_pad.delta_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-18 09:14:46 +00:00
|
|
|
|
|
|
|
async fn get_row_metas(&self) -> Vec<Arc<RowMeta>> {
|
|
|
|
get_row_metas(&self.editor).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
async fn get_row_metas(editor: &Arc<GridMetaEditor>) -> Vec<Arc<RowMeta>> {
|
2022-03-18 09:14:46 +00:00
|
|
|
editor
|
2022-04-02 02:54:01 +00:00
|
|
|
.grid_block_snapshots(None)
|
2022-03-18 09:14:46 +00:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.pop()
|
|
|
|
.unwrap()
|
|
|
|
.row_metas
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 02:06:47 +00:00
|
|
|
pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldMeta) {
|
2022-03-24 09:09:05 +00:00
|
|
|
let field_meta = FieldBuilder::new(RichTextTypeOptionBuilder::default())
|
2022-03-12 13:06:15 +00:00
|
|
|
.name("Name")
|
|
|
|
.visibility(true)
|
2022-03-23 14:10:31 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
let cloned_field_meta = field_meta.clone();
|
|
|
|
|
2022-04-01 14:49:26 +00:00
|
|
|
let type_option_data = field_meta
|
2022-08-12 08:05:56 +00:00
|
|
|
.get_type_option_entry::<RichTextTypeOptionPB>(&field_meta.field_type)
|
2022-04-01 14:49:26 +00:00
|
|
|
.unwrap()
|
|
|
|
.protobuf_bytes()
|
|
|
|
.to_vec();
|
|
|
|
|
2022-03-23 14:10:31 +00:00
|
|
|
let field = Field {
|
|
|
|
id: field_meta.id,
|
|
|
|
name: field_meta.name,
|
|
|
|
desc: field_meta.desc,
|
|
|
|
field_type: field_meta.field_type,
|
|
|
|
frozen: field_meta.frozen,
|
|
|
|
visibility: field_meta.visibility,
|
|
|
|
width: field_meta.width,
|
2022-04-20 08:32:12 +00:00
|
|
|
is_primary: false,
|
2022-03-23 14:10:31 +00:00
|
|
|
};
|
|
|
|
|
2022-04-12 02:06:47 +00:00
|
|
|
let params = InsertFieldParams {
|
2022-03-23 14:10:31 +00:00
|
|
|
grid_id: grid_id.to_owned(),
|
|
|
|
field,
|
2022-04-01 14:49:26 +00:00
|
|
|
type_option_data,
|
2022-03-23 14:10:31 +00:00
|
|
|
start_field_id: None,
|
|
|
|
};
|
|
|
|
(params, cloned_field_meta)
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 02:06:47 +00:00
|
|
|
pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldMeta) {
|
2022-03-24 09:09:05 +00:00
|
|
|
let single_select = SingleSelectTypeOptionBuilder::default()
|
2022-03-12 13:06:15 +00:00
|
|
|
.option(SelectOption::new("Done"))
|
|
|
|
.option(SelectOption::new("Progress"));
|
|
|
|
|
2022-03-24 09:09:05 +00:00
|
|
|
let field_meta = FieldBuilder::new(single_select).name("Name").visibility(true).build();
|
2022-03-23 14:10:31 +00:00
|
|
|
let cloned_field_meta = field_meta.clone();
|
2022-04-01 14:49:26 +00:00
|
|
|
let type_option_data = field_meta
|
2022-04-10 12:21:28 +00:00
|
|
|
.get_type_option_entry::<SingleSelectTypeOption>(&field_meta.field_type)
|
2022-04-01 14:49:26 +00:00
|
|
|
.unwrap()
|
|
|
|
.protobuf_bytes()
|
|
|
|
.to_vec();
|
2022-03-23 14:10:31 +00:00
|
|
|
|
|
|
|
let field = Field {
|
|
|
|
id: field_meta.id,
|
|
|
|
name: field_meta.name,
|
|
|
|
desc: field_meta.desc,
|
|
|
|
field_type: field_meta.field_type,
|
|
|
|
frozen: field_meta.frozen,
|
|
|
|
visibility: field_meta.visibility,
|
|
|
|
width: field_meta.width,
|
2022-04-20 08:32:12 +00:00
|
|
|
is_primary: false,
|
2022-03-23 14:10:31 +00:00
|
|
|
};
|
|
|
|
|
2022-04-12 02:06:47 +00:00
|
|
|
let params = InsertFieldParams {
|
2022-03-23 14:10:31 +00:00
|
|
|
grid_id: grid_id.to_owned(),
|
|
|
|
field,
|
2022-04-01 14:49:26 +00:00
|
|
|
type_option_data,
|
2022-03-23 14:10:31 +00:00
|
|
|
start_field_id: None,
|
|
|
|
};
|
|
|
|
(params, cloned_field_meta)
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
2022-03-15 11:00:28 +00:00
|
|
|
|
|
|
|
fn make_template_1_grid() -> BuildGridContext {
|
2022-03-24 09:09:05 +00:00
|
|
|
let text_field = FieldBuilder::new(RichTextTypeOptionBuilder::default())
|
2022-03-15 11:00:28 +00:00
|
|
|
.name("Name")
|
|
|
|
.visibility(true)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// Single Select
|
2022-03-24 09:09:05 +00:00
|
|
|
let single_select = SingleSelectTypeOptionBuilder::default()
|
2022-03-15 11:00:28 +00:00
|
|
|
.option(SelectOption::new("Live"))
|
|
|
|
.option(SelectOption::new("Completed"))
|
|
|
|
.option(SelectOption::new("Planned"))
|
|
|
|
.option(SelectOption::new("Paused"));
|
2022-03-24 09:09:05 +00:00
|
|
|
let single_select_field = FieldBuilder::new(single_select).name("Status").visibility(true).build();
|
2022-03-15 11:00:28 +00:00
|
|
|
|
|
|
|
// MultiSelect
|
2022-03-24 09:09:05 +00:00
|
|
|
let multi_select = MultiSelectTypeOptionBuilder::default()
|
2022-03-15 11:00:28 +00:00
|
|
|
.option(SelectOption::new("Google"))
|
|
|
|
.option(SelectOption::new("Facebook"))
|
|
|
|
.option(SelectOption::new("Twitter"));
|
|
|
|
let multi_select_field = FieldBuilder::new(multi_select)
|
|
|
|
.name("Platform")
|
|
|
|
.visibility(true)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// Number
|
2022-03-24 09:09:05 +00:00
|
|
|
let number = NumberTypeOptionBuilder::default().set_format(NumberFormat::USD);
|
|
|
|
let number_field = FieldBuilder::new(number).name("Price").visibility(true).build();
|
2022-03-15 11:00:28 +00:00
|
|
|
|
|
|
|
// Date
|
2022-03-24 09:09:05 +00:00
|
|
|
let date = DateTypeOptionBuilder::default()
|
2022-03-15 11:00:28 +00:00
|
|
|
.date_format(DateFormat::US)
|
|
|
|
.time_format(TimeFormat::TwentyFourHour);
|
2022-03-24 09:09:05 +00:00
|
|
|
let date_field = FieldBuilder::new(date).name("Time").visibility(true).build();
|
2022-03-15 11:00:28 +00:00
|
|
|
|
|
|
|
// Checkbox
|
2022-03-24 09:09:05 +00:00
|
|
|
let checkbox = CheckboxTypeOptionBuilder::default();
|
|
|
|
let checkbox_field = FieldBuilder::new(checkbox).name("is done").visibility(true).build();
|
2022-03-15 11:00:28 +00:00
|
|
|
|
2022-05-27 12:19:22 +00:00
|
|
|
// URL
|
|
|
|
let url = URLTypeOptionBuilder::default();
|
|
|
|
let url_field = FieldBuilder::new(url).name("link").visibility(true).build();
|
|
|
|
|
2022-03-15 11:00:28 +00:00
|
|
|
GridBuilder::default()
|
|
|
|
.add_field(text_field)
|
|
|
|
.add_field(single_select_field)
|
|
|
|
.add_field(multi_select_field)
|
|
|
|
.add_field(number_field)
|
|
|
|
.add_field(date_field)
|
|
|
|
.add_field(checkbox_field)
|
2022-05-27 12:19:22 +00:00
|
|
|
.add_field(url_field)
|
2022-03-15 11:00:28 +00:00
|
|
|
.add_empty_row()
|
|
|
|
.add_empty_row()
|
|
|
|
.add_empty_row()
|
|
|
|
.build()
|
|
|
|
}
|