2022-05-22 05:08:38 +00:00
|
|
|
use crate::entities::{FieldIdentifier, FieldIdentifierPayload};
|
2022-04-07 00:33:10 +00:00
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
use flowy_error::ErrorCode;
|
2022-04-11 07:27:03 +00:00
|
|
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
2022-07-01 12:32:11 +00:00
|
|
|
use flowy_grid_data_model::revision::{CellRevision, RowMetaChangeset};
|
|
|
|
use std::collections::HashMap;
|
2022-04-07 00:33:10 +00:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default)]
|
|
|
|
pub struct CreateSelectOptionPayload {
|
|
|
|
#[pb(index = 1)]
|
2022-04-18 09:17:42 +00:00
|
|
|
pub field_identifier: FieldIdentifierPayload,
|
2022-04-07 00:33:10 +00:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub option_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CreateSelectOptionParams {
|
2022-04-18 09:17:42 +00:00
|
|
|
pub field_identifier: FieldIdentifier,
|
2022-04-07 00:33:10 +00:00
|
|
|
pub option_name: String,
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:17:42 +00:00
|
|
|
impl std::ops::Deref for CreateSelectOptionParams {
|
|
|
|
type Target = FieldIdentifier;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.field_identifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 00:33:10 +00:00
|
|
|
impl TryInto<CreateSelectOptionParams> for CreateSelectOptionPayload {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<CreateSelectOptionParams, Self::Error> {
|
|
|
|
let option_name = NotEmptyStr::parse(self.option_name).map_err(|_| ErrorCode::SelectOptionNameIsEmpty)?;
|
2022-04-18 09:17:42 +00:00
|
|
|
let field_identifier = self.field_identifier.try_into()?;
|
2022-04-07 00:33:10 +00:00
|
|
|
Ok(CreateSelectOptionParams {
|
2022-04-18 09:17:42 +00:00
|
|
|
field_identifier,
|
2022-04-07 00:33:10 +00:00
|
|
|
option_name: option_name.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
|
|
|
pub struct CellIdentifierPayload {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub grid_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub row_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CellIdentifier {
|
|
|
|
pub grid_id: String,
|
|
|
|
pub field_id: String,
|
|
|
|
pub row_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<CellIdentifier> for CellIdentifierPayload {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<CellIdentifier, Self::Error> {
|
2022-04-11 07:27:03 +00:00
|
|
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
|
|
|
let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
|
|
|
|
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
|
2022-04-07 00:33:10 +00:00
|
|
|
Ok(CellIdentifier {
|
|
|
|
grid_id: grid_id.0,
|
|
|
|
field_id: field_id.0,
|
|
|
|
row_id: row_id.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 12:32:11 +00:00
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
|
|
|
pub struct Cell {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub data: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Cell {
|
|
|
|
pub fn new(field_id: &str, data: Vec<u8>) -> Self {
|
|
|
|
Self {
|
|
|
|
field_id: field_id.to_owned(),
|
|
|
|
data,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn empty(field_id: &str) -> Self {
|
|
|
|
Self {
|
|
|
|
field_id: field_id.to_owned(),
|
|
|
|
data: vec![],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
|
|
|
pub struct RepeatedCell {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<Cell>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::Deref for RepeatedCell {
|
|
|
|
type Target = Vec<Cell>;
|
|
|
|
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<Vec<Cell>> for RepeatedCell {
|
|
|
|
fn from(items: Vec<Cell>) -> Self {
|
|
|
|
Self { items }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
|
|
|
pub struct CellChangeset {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub grid_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub row_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
2022-07-08 06:54:11 +00:00
|
|
|
pub content: Option<String>,
|
2022-07-01 12:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<CellChangeset> for RowMetaChangeset {
|
|
|
|
fn from(changeset: CellChangeset) -> Self {
|
|
|
|
let mut cell_by_field_id = HashMap::with_capacity(1);
|
|
|
|
let field_id = changeset.field_id;
|
|
|
|
let cell_rev = CellRevision {
|
2022-07-08 06:54:11 +00:00
|
|
|
data: changeset.content.unwrap_or_else(|| "".to_owned()),
|
2022-07-01 12:32:11 +00:00
|
|
|
};
|
|
|
|
cell_by_field_id.insert(field_id, cell_rev);
|
|
|
|
|
|
|
|
RowMetaChangeset {
|
|
|
|
row_id: changeset.row_id,
|
|
|
|
height: None,
|
|
|
|
visibility: None,
|
|
|
|
cell_by_field_id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|