mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: move some structs
This commit is contained in:
parent
c81b6f10fa
commit
5fac1f044a
@ -1,28 +0,0 @@
|
|||||||
use crate::entities::{CreateRowParams, GridLayout};
|
|
||||||
use flowy_derive::ProtoBuf;
|
|
||||||
use flowy_error::ErrorCode;
|
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
|
||||||
|
|
||||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
|
||||||
pub struct CreateBoardCardPayloadPB {
|
|
||||||
#[pb(index = 1)]
|
|
||||||
pub grid_id: String,
|
|
||||||
|
|
||||||
#[pb(index = 2)]
|
|
||||||
pub group_id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
|
|
||||||
type Error = ErrorCode;
|
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
|
||||||
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
|
||||||
let group_id = NotEmptyStr::parse(self.group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;
|
|
||||||
Ok(CreateRowParams {
|
|
||||||
grid_id: grid_id.0,
|
|
||||||
start_row_id: None,
|
|
||||||
group_id: Some(group_id.0),
|
|
||||||
layout: GridLayout::Board,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{FieldType, RowPB};
|
use crate::entities::{CreateRowParams, FieldType, GridLayout, RowPB};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
@ -6,6 +6,30 @@ use flowy_grid_data_model::revision::{FieldTypeRevision, GroupConfigurationRevis
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||||
|
pub struct CreateBoardCardPayloadPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
pub grid_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 2)]
|
||||||
|
pub group_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
|
||||||
|
type Error = ErrorCode;
|
||||||
|
|
||||||
|
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
||||||
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
||||||
|
let group_id = NotEmptyStr::parse(self.group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;
|
||||||
|
Ok(CreateRowParams {
|
||||||
|
grid_id: grid_id.0,
|
||||||
|
start_row_id: None,
|
||||||
|
group_id: Some(group_id.0),
|
||||||
|
layout: GridLayout::Board,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct GridGroupConfigurationPB {
|
pub struct GridGroupConfigurationPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
mod board_card;
|
|
||||||
mod configuration;
|
mod configuration;
|
||||||
mod group;
|
mod group;
|
||||||
mod group_changeset;
|
mod group_changeset;
|
||||||
|
|
||||||
pub use board_card::*;
|
|
||||||
pub use configuration::*;
|
pub use configuration::*;
|
||||||
pub use group::*;
|
pub use group::*;
|
||||||
pub use group_changeset::*;
|
pub use group_changeset::*;
|
||||||
|
@ -96,23 +96,19 @@ impl GridRevisionEditor {
|
|||||||
} = params;
|
} = params;
|
||||||
let field_id = field.id.clone();
|
let field_id = field.id.clone();
|
||||||
if self.contain_field(&field_id).await {
|
if self.contain_field(&field_id).await {
|
||||||
let _ = self
|
let changeset = FieldChangesetParams {
|
||||||
.modify(|grid| {
|
field_id: field.id,
|
||||||
let deserializer = TypeOptionJsonDeserializer(field.field_type.clone());
|
grid_id,
|
||||||
let changeset = FieldChangesetParams {
|
name: Some(field.name),
|
||||||
field_id: field.id,
|
desc: Some(field.desc),
|
||||||
grid_id,
|
field_type: Some(field.field_type.into()),
|
||||||
name: Some(field.name),
|
frozen: Some(field.frozen),
|
||||||
desc: Some(field.desc),
|
visibility: Some(field.visibility),
|
||||||
field_type: Some(field.field_type.into()),
|
width: Some(field.width),
|
||||||
frozen: Some(field.frozen),
|
type_option_data: Some(type_option_data),
|
||||||
visibility: Some(field.visibility),
|
};
|
||||||
width: Some(field.width),
|
|
||||||
type_option_data: Some(type_option_data),
|
let _ = self.update_field_rev(changeset, field.field_type.clone()).await?;
|
||||||
};
|
|
||||||
Ok(grid.update_field_rev(changeset, deserializer)?)
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
let _ = self.notify_did_update_grid_field(&field_id).await?;
|
let _ = self.notify_did_update_grid_field(&field_id).await?;
|
||||||
} else {
|
} else {
|
||||||
let _ = self
|
let _ = self
|
||||||
@ -140,19 +136,13 @@ impl GridRevisionEditor {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let field_rev = result.unwrap();
|
let field_rev = result.unwrap();
|
||||||
let _ = self
|
let changeset = FieldChangesetParams {
|
||||||
.modify(|grid| {
|
field_id: field_id.to_owned(),
|
||||||
let field_type = field_rev.ty.into();
|
grid_id: grid_id.to_owned(),
|
||||||
let deserializer = TypeOptionJsonDeserializer(field_type);
|
type_option_data: Some(type_option_data),
|
||||||
let changeset = FieldChangesetParams {
|
..Default::default()
|
||||||
field_id: field_id.to_owned(),
|
};
|
||||||
grid_id: grid_id.to_owned(),
|
let _ = self.update_field_rev(changeset, field_rev.ty.into()).await?;
|
||||||
type_option_data: Some(type_option_data),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
Ok(grid.update_field_rev(changeset, deserializer)?)
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
let _ = self.notify_did_update_grid_field(field_id).await?;
|
let _ = self.notify_did_update_grid_field(field_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -179,17 +169,19 @@ impl GridRevisionEditor {
|
|||||||
|
|
||||||
pub async fn update_field(&self, params: FieldChangesetParams) -> FlowyResult<()> {
|
pub async fn update_field(&self, params: FieldChangesetParams) -> FlowyResult<()> {
|
||||||
let field_id = params.field_id.clone();
|
let field_id = params.field_id.clone();
|
||||||
let json_deserializer = match self.grid_pad.read().await.get_field_rev(params.field_id.as_str()) {
|
let field_type: Option<FieldType> = match self.grid_pad.read().await.get_field_rev(params.field_id.as_str()) {
|
||||||
None => return Err(ErrorCode::FieldDoesNotExist.into()),
|
None => None,
|
||||||
Some((_, field_rev)) => TypeOptionJsonDeserializer(field_rev.ty.into()),
|
Some((_, field_rev)) => Some(field_rev.ty.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = self
|
match field_type {
|
||||||
.modify(|grid| Ok(grid.update_field_rev(params, json_deserializer)?))
|
None => Err(ErrorCode::FieldDoesNotExist.into()),
|
||||||
.await?;
|
Some(field_type) => {
|
||||||
|
let _ = self.update_field_rev(params, field_type).await?;
|
||||||
let _ = self.notify_did_update_grid_field(&field_id).await?;
|
let _ = self.notify_did_update_grid_field(&field_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn replace_field(&self, field_rev: Arc<FieldRevision>) -> FlowyResult<()> {
|
pub async fn replace_field(&self, field_rev: Arc<FieldRevision>) -> FlowyResult<()> {
|
||||||
@ -269,6 +261,63 @@ impl GridRevisionEditor {
|
|||||||
Ok(field_revs)
|
Ok(field_revs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update_field_rev(&self, params: FieldChangesetParams, field_type: FieldType) -> FlowyResult<()> {
|
||||||
|
let _ = self
|
||||||
|
.modify(|grid| {
|
||||||
|
let deserializer = TypeOptionJsonDeserializer(field_type);
|
||||||
|
|
||||||
|
let changeset = grid.modify_field(¶ms.field_id, |field| {
|
||||||
|
let mut is_changed = None;
|
||||||
|
if let Some(name) = changeset.name {
|
||||||
|
field.name = name;
|
||||||
|
is_changed = Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(desc) = changeset.desc {
|
||||||
|
field.desc = desc;
|
||||||
|
is_changed = Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(field_type) = changeset.field_type {
|
||||||
|
field.ty = field_type;
|
||||||
|
is_changed = Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(frozen) = changeset.frozen {
|
||||||
|
field.frozen = frozen;
|
||||||
|
is_changed = Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(visibility) = changeset.visibility {
|
||||||
|
field.visibility = visibility;
|
||||||
|
is_changed = Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(width) = changeset.width {
|
||||||
|
field.width = width;
|
||||||
|
is_changed = Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(type_option_data) = changeset.type_option_data {
|
||||||
|
match deserializer.deserialize(type_option_data) {
|
||||||
|
Ok(json_str) => {
|
||||||
|
let field_type = field.ty;
|
||||||
|
field.insert_type_option_str(&field_type, json_str);
|
||||||
|
is_changed = Some(())
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
tracing::error!("Deserialize data to type option json failed: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(is_changed)
|
||||||
|
})?;
|
||||||
|
Ok(changeset)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn create_block(&self, block_meta_rev: GridBlockMetaRevision) -> FlowyResult<()> {
|
pub async fn create_block(&self, block_meta_rev: GridBlockMetaRevision) -> FlowyResult<()> {
|
||||||
let _ = self
|
let _ = self
|
||||||
.modify(|grid_pad| Ok(grid_pad.create_block_meta_rev(block_meta_rev)?))
|
.modify(|grid_pad| Ok(grid_pad.create_block_meta_rev(block_meta_rev)?))
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
mod checkbox_controller;
|
||||||
|
mod group_controller;
|
||||||
|
mod select_option_controller;
|
||||||
|
|
||||||
|
pub use checkbox_controller::*;
|
||||||
|
pub use group_controller::*;
|
||||||
|
pub use select_option_controller::*;
|
@ -1,7 +0,0 @@
|
|||||||
mod checkbox_group;
|
|
||||||
mod group_controller;
|
|
||||||
mod select_option_group;
|
|
||||||
|
|
||||||
pub use checkbox_group::*;
|
|
||||||
pub use group_controller::*;
|
|
||||||
pub use select_option_group::*;
|
|
@ -1,5 +1,5 @@
|
|||||||
mod group_generator;
|
mod controllers;
|
||||||
mod group_service;
|
mod group_service;
|
||||||
|
|
||||||
pub(crate) use group_generator::*;
|
pub(crate) use controllers::*;
|
||||||
pub(crate) use group_service::*;
|
pub(crate) use group_service::*;
|
||||||
|
@ -240,7 +240,9 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GroupConfigurationSerde {}
|
pub trait GroupConfigurationSerde {
|
||||||
|
fn from_configuration(s: &str) -> Result<Self, serde_json::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
||||||
pub struct GroupConfigurationRevision {
|
pub struct GroupConfigurationRevision {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use crate::entities::grid::FieldChangesetParams;
|
|
||||||
use crate::entities::revision::{md5, RepeatedRevision, Revision};
|
use crate::entities::revision::{md5, RepeatedRevision, Revision};
|
||||||
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
||||||
use crate::util::{cal_diff, make_text_delta_from_revisions};
|
use crate::util::{cal_diff, make_text_delta_from_revisions};
|
||||||
@ -162,61 +161,6 @@ impl GridRevisionPad {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_field_rev<T: JsonDeserializer>(
|
|
||||||
&mut self,
|
|
||||||
changeset: FieldChangesetParams,
|
|
||||||
deserializer: T,
|
|
||||||
) -> CollaborateResult<Option<GridRevisionChangeset>> {
|
|
||||||
let field_id = changeset.field_id.clone();
|
|
||||||
self.modify_field(&field_id, |field| {
|
|
||||||
let mut is_changed = None;
|
|
||||||
if let Some(name) = changeset.name {
|
|
||||||
field.name = name;
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(desc) = changeset.desc {
|
|
||||||
field.desc = desc;
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(field_type) = changeset.field_type {
|
|
||||||
field.ty = field_type;
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(frozen) = changeset.frozen {
|
|
||||||
field.frozen = frozen;
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(visibility) = changeset.visibility {
|
|
||||||
field.visibility = visibility;
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(width) = changeset.width {
|
|
||||||
field.width = width;
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(type_option_data) = changeset.type_option_data {
|
|
||||||
match deserializer.deserialize(type_option_data) {
|
|
||||||
Ok(json_str) => {
|
|
||||||
let field_type = field.ty;
|
|
||||||
field.insert_type_option_str(&field_type, json_str);
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
tracing::error!("Deserialize data to type option json failed: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(is_changed)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_field_rev(&self, field_id: &str) -> Option<(usize, &Arc<FieldRevision>)> {
|
pub fn get_field_rev(&self, field_id: &str) -> Option<(usize, &Arc<FieldRevision>)> {
|
||||||
self.grid_rev
|
self.grid_rev
|
||||||
.fields
|
.fields
|
||||||
@ -399,7 +343,7 @@ impl GridRevisionPad {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_field<F>(&mut self, field_id: &str, f: F) -> CollaborateResult<Option<GridRevisionChangeset>>
|
pub fn modify_field<F>(&mut self, field_id: &str, f: F) -> CollaborateResult<Option<GridRevisionChangeset>>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut FieldRevision) -> CollaborateResult<Option<()>>,
|
F: FnOnce(&mut FieldRevision) -> CollaborateResult<Option<()>>,
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
use crate::entities::grid::{CreatGroupParams, CreateFilterParams, GridSettingChangesetParams};
|
|
||||||
use crate::entities::revision::{md5, Revision};
|
use crate::entities::revision::{md5, Revision};
|
||||||
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
||||||
use crate::util::{cal_diff, make_text_delta_from_revisions};
|
use crate::util::{cal_diff, make_text_delta_from_revisions};
|
||||||
use flowy_grid_data_model::revision::{
|
use flowy_grid_data_model::revision::{
|
||||||
gen_grid_filter_id, gen_grid_group_id, FieldRevision, FieldTypeRevision, FilterConfigurationRevision,
|
FieldRevision, FieldTypeRevision, FilterConfigurationRevision, FilterConfigurationsByFieldId, GridViewRevision,
|
||||||
FilterConfigurationsByFieldId, GridViewRevision, GroupConfigurationRevision, GroupConfigurationsByFieldId,
|
GroupConfigurationRevision, GroupConfigurationsByFieldId, SettingRevision, SortConfigurationsByFieldId,
|
||||||
SettingRevision, SortConfigurationsByFieldId,
|
|
||||||
};
|
};
|
||||||
use lib_ot::core::{OperationTransform, PhantomAttributes, TextDelta, TextDeltaBuilder};
|
use lib_ot::core::{OperationTransform, PhantomAttributes, TextDelta, TextDeltaBuilder};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -167,24 +165,6 @@ impl GridViewRevisionPad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_filter_revision(params: &CreateFilterParams) -> FilterConfigurationRevision {
|
|
||||||
FilterConfigurationRevision {
|
|
||||||
id: gen_grid_filter_id(),
|
|
||||||
field_id: params.field_id.clone(),
|
|
||||||
condition: params.condition,
|
|
||||||
content: params.content.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_group_revision(params: &CreatGroupParams) -> GroupConfigurationRevision {
|
|
||||||
GroupConfigurationRevision {
|
|
||||||
id: gen_grid_group_id(),
|
|
||||||
field_id: params.field_id.clone(),
|
|
||||||
field_type_rev: params.field_type_rev,
|
|
||||||
content: params.content.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GridViewRevisionChangeset {
|
pub struct GridViewRevisionChangeset {
|
||||||
pub delta: TextDelta,
|
pub delta: TextDelta,
|
||||||
pub md5: String,
|
pub md5: String,
|
||||||
|
Loading…
Reference in New Issue
Block a user