use crate::entities::{FieldMeta, FieldType, RowMeta}; use flowy_derive::ProtoBuf; use std::collections::HashMap; use std::sync::Arc; #[derive(Debug, Clone, Default, ProtoBuf)] pub struct Grid { #[pb(index = 1)] pub id: String, #[pb(index = 2)] pub field_orders: Vec, #[pb(index = 3)] pub block_orders: Vec, } #[derive(Debug, Clone, Default, ProtoBuf)] pub struct Field { #[pb(index = 1)] pub id: String, #[pb(index = 2)] pub name: String, #[pb(index = 3)] pub desc: String, #[pb(index = 4)] pub field_type: FieldType, #[pb(index = 5)] pub frozen: bool, #[pb(index = 6)] pub visibility: bool, #[pb(index = 7)] pub width: i32, } #[derive(Debug, Clone, Default, ProtoBuf)] pub struct FieldOrder { #[pb(index = 1)] pub field_id: String, } impl std::convert::From<&FieldMeta> for FieldOrder { fn from(field_meta: &FieldMeta) -> Self { Self { field_id: field_meta.id.clone(), } } } impl std::convert::From for Field { fn from(field_meta: FieldMeta) -> Self { Self { 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, } } } #[derive(Debug, Default, ProtoBuf)] pub struct CreateEditFieldContextParams { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] pub field_type: FieldType, } #[derive(Debug, Default, ProtoBuf)] pub struct EditFieldContext { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] pub grid_field: Field, #[pb(index = 3)] pub type_option_data: Vec, } #[derive(Debug, Default, ProtoBuf)] pub struct RepeatedField { #[pb(index = 1)] pub items: Vec, } impl std::ops::Deref for RepeatedField { type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } impl std::ops::DerefMut for RepeatedField { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } } impl std::convert::From> for RepeatedField { fn from(items: Vec) -> Self { Self { items } } } #[derive(Debug, Clone, Default, ProtoBuf)] pub struct RepeatedFieldOrder { #[pb(index = 1)] pub items: Vec, } impl std::ops::Deref for RepeatedFieldOrder { type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } #[derive(Debug, Default, Clone, ProtoBuf)] pub struct RowOrder { #[pb(index = 1)] pub row_id: String, #[pb(index = 2)] pub block_id: String, #[pb(index = 3)] pub height: i32, } impl std::convert::From<&RowMeta> for RowOrder { fn from(row: &RowMeta) -> Self { Self { row_id: row.id.clone(), block_id: row.block_id.clone(), height: row.height, } } } impl std::convert::From<&Arc> for RowOrder { fn from(row: &Arc) -> Self { Self { row_id: row.id.clone(), block_id: row.block_id.clone(), height: row.height, } } } #[derive(Debug, Default, ProtoBuf)] pub struct Row { #[pb(index = 1)] pub id: String, #[pb(index = 2)] pub cell_by_field_id: HashMap, #[pb(index = 3)] pub height: i32, } #[derive(Debug, Default, ProtoBuf)] pub struct RepeatedRow { #[pb(index = 1)] pub items: Vec, } impl std::convert::From> for RepeatedRow { fn from(items: Vec) -> Self { Self { items } } } #[derive(Debug, Default, ProtoBuf)] pub struct RepeatedGridBlock { #[pb(index = 1)] pub items: Vec, } impl std::convert::From> for RepeatedGridBlock { fn from(items: Vec) -> Self { Self { items } } } #[derive(Debug, Clone, Default, ProtoBuf)] pub struct GridBlockOrder { #[pb(index = 1)] pub block_id: String, } impl std::convert::From<&str> for GridBlockOrder { fn from(s: &str) -> Self { GridBlockOrder { block_id: s.to_owned() } } } #[derive(Debug, Default, ProtoBuf)] pub struct GridBlock { #[pb(index = 1)] pub id: String, #[pb(index = 2)] pub row_orders: Vec, } impl GridBlock { pub fn new(block_id: &str, row_orders: Vec) -> Self { Self { id: block_id.to_owned(), row_orders, } } } #[derive(Debug, Default, ProtoBuf)] pub struct Cell { #[pb(index = 1)] pub field_id: String, #[pb(index = 2)] pub content: String, } impl Cell { pub fn new(field_id: &str, content: String) -> Self { Self { field_id: field_id.to_owned(), content, } } } #[derive(Debug, Default, ProtoBuf)] pub struct RepeatedCell { #[pb(index = 1)] pub items: Vec, } impl std::ops::Deref for RepeatedCell { type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } impl std::ops::DerefMut for RepeatedCell { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } } impl std::convert::From> for RepeatedCell { fn from(items: Vec) -> Self { Self { items } } } #[derive(ProtoBuf, Default)] pub struct CreateGridPayload { #[pb(index = 1)] pub name: String, } #[derive(Clone, ProtoBuf, Default, Debug)] pub struct GridId { #[pb(index = 1)] pub value: String, } impl AsRef for GridId { fn as_ref(&self) -> &str { &self.value } } #[derive(Clone, ProtoBuf, Default, Debug)] pub struct GridBlockId { #[pb(index = 1)] pub value: String, } impl AsRef for GridBlockId { fn as_ref(&self) -> &str { &self.value } } impl std::convert::From<&str> for GridBlockId { fn from(s: &str) -> Self { GridBlockId { value: s.to_owned() } } } #[derive(ProtoBuf, Default)] pub struct CreateRowPayload { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2, one_of)] pub start_row_id: Option, } #[derive(ProtoBuf, Default)] pub struct CreateFieldPayload { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] pub field: Field, #[pb(index = 3)] pub type_option_data: Vec, #[pb(index = 4, one_of)] pub start_field_id: Option, } #[derive(ProtoBuf, Default)] pub struct QueryFieldPayload { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] pub field_orders: RepeatedFieldOrder, } #[derive(ProtoBuf, Default)] pub struct QueryGridBlocksPayload { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] pub block_orders: Vec, } #[derive(ProtoBuf, Default)] pub struct QueryRowPayload { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] pub block_id: String, #[pb(index = 3)] pub row_id: String, }