2022-03-15 11:07:18 +08:00
|
|
|
use flowy_grid_data_model::entities::{CellMeta, FieldMeta, RowMeta, DEFAULT_ROW_HEIGHT};
|
2022-03-14 17:24:25 +08:00
|
|
|
use std::collections::HashMap;
|
2022-03-13 11:06:28 +08:00
|
|
|
|
2022-03-14 17:24:25 +08:00
|
|
|
pub struct CreateRowContextBuilder<'a> {
|
|
|
|
#[allow(dead_code)]
|
2022-03-15 11:07:18 +08:00
|
|
|
fields: &'a [FieldMeta],
|
2022-03-14 17:24:25 +08:00
|
|
|
ctx: CreateRowContext,
|
2022-03-13 11:06:28 +08:00
|
|
|
}
|
|
|
|
|
2022-03-14 17:24:25 +08:00
|
|
|
impl<'a> CreateRowContextBuilder<'a> {
|
2022-03-15 11:07:18 +08:00
|
|
|
pub fn new(fields: &'a [FieldMeta]) -> Self {
|
2022-03-14 17:24:25 +08:00
|
|
|
let ctx = CreateRowContext {
|
|
|
|
row_id: uuid::Uuid::new_v4().to_string(),
|
|
|
|
cell_by_field_id: Default::default(),
|
|
|
|
height: DEFAULT_ROW_HEIGHT,
|
|
|
|
visibility: true,
|
|
|
|
};
|
|
|
|
Self { fields, ctx }
|
2022-03-13 11:06:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn add_cell(mut self, field_id: &str, data: String) -> Self {
|
|
|
|
let cell = CellMeta::new(field_id, data);
|
2022-03-14 17:24:25 +08:00
|
|
|
self.ctx.cell_by_field_id.insert(field_id.to_owned(), cell);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn height(mut self, height: i32) -> Self {
|
|
|
|
self.ctx.height = height;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn visibility(mut self, visibility: bool) -> Self {
|
|
|
|
self.ctx.visibility = visibility;
|
2022-03-13 11:06:28 +08:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-03-14 17:24:25 +08:00
|
|
|
pub fn build(self) -> CreateRowContext {
|
|
|
|
self.ctx
|
2022-03-13 11:06:28 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-14 17:24:25 +08:00
|
|
|
|
|
|
|
pub fn row_meta_from_context(block_id: &str, ctx: CreateRowContext) -> RowMeta {
|
|
|
|
RowMeta {
|
|
|
|
id: ctx.row_id,
|
|
|
|
block_id: block_id.to_owned(),
|
|
|
|
cell_by_field_id: ctx.cell_by_field_id,
|
|
|
|
height: ctx.height,
|
|
|
|
visibility: ctx.visibility,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CreateRowContext {
|
|
|
|
pub row_id: String,
|
|
|
|
pub cell_by_field_id: HashMap<String, CellMeta>,
|
|
|
|
pub height: i32,
|
|
|
|
pub visibility: bool,
|
|
|
|
}
|