mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: move checkbox card fail
This commit is contained in:
@ -34,7 +34,3 @@ pub fn send_dart_notification(id: &str, ty: GridNotification) -> DartNotifyBuild
|
|||||||
DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY)
|
DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace")]
|
|
||||||
pub fn send_anonymous_dart_notification(ty: GridNotification) -> DartNotifyBuilder {
|
|
||||||
DartNotifyBuilder::new("", ty, OBSERVABLE_CATEGORY)
|
|
||||||
}
|
|
||||||
|
@ -19,7 +19,10 @@ impl std::str::FromStr for AnyCellData {
|
|||||||
type Err = FlowyError;
|
type Err = FlowyError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let type_option_cell_data: AnyCellData = serde_json::from_str(s)?;
|
let type_option_cell_data: AnyCellData = serde_json::from_str(s).map_err(|err| {
|
||||||
|
let msg = format!("Deserialize {} to any cell data failed. Serde error: {}", s, err);
|
||||||
|
FlowyError::internal().context(msg)
|
||||||
|
})?;
|
||||||
Ok(type_option_cell_data)
|
Ok(type_option_cell_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::entities::FieldType;
|
use crate::entities::FieldType;
|
||||||
use crate::services::cell::{AnyCellData, CellBytes};
|
use crate::services::cell::{AnyCellData, CellBytes};
|
||||||
use crate::services::field::*;
|
use crate::services::field::*;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||||
use flowy_grid_data_model::revision::{CellRevision, FieldRevision, FieldTypeRevision};
|
use flowy_grid_data_model::revision::{CellRevision, FieldRevision, FieldTypeRevision};
|
||||||
@ -73,8 +74,12 @@ pub fn apply_cell_data_changeset<C: ToString, T: AsRef<FieldRevision>>(
|
|||||||
Ok(AnyCellData::new(s, field_type).json())
|
Ok(AnyCellData::new(s, field_type).json())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_any_cell_data<T: TryInto<AnyCellData>>(data: T, field_rev: &FieldRevision) -> CellBytes {
|
pub fn decode_any_cell_data<T: TryInto<AnyCellData, Error = FlowyError> + Debug>(
|
||||||
if let Ok(any_cell_data) = data.try_into() {
|
data: T,
|
||||||
|
field_rev: &FieldRevision,
|
||||||
|
) -> CellBytes {
|
||||||
|
match data.try_into() {
|
||||||
|
Ok(any_cell_data) => {
|
||||||
let AnyCellData { data, field_type } = any_cell_data;
|
let AnyCellData { data, field_type } = any_cell_data;
|
||||||
let to_field_type = field_rev.ty.into();
|
let to_field_type = field_rev.ty.into();
|
||||||
match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) {
|
match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) {
|
||||||
@ -84,10 +89,16 @@ pub fn decode_any_cell_data<T: TryInto<AnyCellData>>(data: T, field_rev: &FieldR
|
|||||||
CellBytes::default()
|
CellBytes::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
tracing::error!("Decode type option data failed");
|
Err(err) => {
|
||||||
|
tracing::error!(
|
||||||
|
"Decode type option data to type: {} failed: {:?}",
|
||||||
|
std::any::type_name::<T>(),
|
||||||
|
err,
|
||||||
|
);
|
||||||
CellBytes::default()
|
CellBytes::default()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_decode_cell_data(
|
pub fn try_decode_cell_data(
|
||||||
|
@ -14,5 +14,6 @@ pub trait GroupAction: Send + Sync {
|
|||||||
fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool;
|
fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool;
|
||||||
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
||||||
fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
|
||||||
|
// Move row from one group to another
|
||||||
fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec<GroupChangesetPB>;
|
fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec<GroupChangesetPB>;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
use crate::entities::{GroupChangesetPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
|
use crate::entities::{ GroupChangesetPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
|
||||||
use crate::services::cell::{decode_any_cell_data, CellBytesParser};
|
use crate::services::cell::{decode_any_cell_data, CellBytesParser,};
|
||||||
use crate::services::group::action::GroupAction;
|
use crate::services::group::action::GroupAction;
|
||||||
use crate::services::group::configuration::GroupContext;
|
use crate::services::group::configuration::GroupContext;
|
||||||
use crate::services::group::entities::Group;
|
use crate::services::group::entities::Group;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_grid_data_model::revision::{
|
use flowy_grid_data_model::revision::{ FieldRevision, GroupConfigurationContentSerde, GroupRevision, RowChangeset, RowRevision, TypeOptionDataDeserializer};
|
||||||
FieldRevision, GroupConfigurationContentSerde, GroupRevision, RowChangeset, RowRevision, TypeOptionDataDeserializer,
|
|
||||||
};
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -86,8 +84,7 @@ where
|
|||||||
G: GroupGenerator<Context = GroupContext<C>, TypeOptionType = T>,
|
G: GroupGenerator<Context = GroupContext<C>, TypeOptionType = T>,
|
||||||
{
|
{
|
||||||
pub async fn new(field_rev: &Arc<FieldRevision>, mut configuration: GroupContext<C>) -> FlowyResult<Self> {
|
pub async fn new(field_rev: &Arc<FieldRevision>, mut configuration: GroupContext<C>) -> FlowyResult<Self> {
|
||||||
let field_type_rev = field_rev.ty;
|
let type_option = field_rev.get_type_option::<T>(field_rev.ty);
|
||||||
let type_option = field_rev.get_type_option::<T>(field_type_rev);
|
|
||||||
let groups = G::generate_groups(&field_rev.id, &configuration, &type_option);
|
let groups = G::generate_groups(&field_rev.id, &configuration, &type_option);
|
||||||
let _ = configuration.init_groups(groups, true)?;
|
let _ = configuration.init_groups(groups, true)?;
|
||||||
|
|
||||||
@ -278,12 +275,19 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<Vec<GroupChangesetPB>> {
|
fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<Vec<GroupChangesetPB>> {
|
||||||
if let Some(cell_rev) = context.row_rev.cells.get(&self.field_id) {
|
let cell_rev = match context.row_rev.cells.get(&self.field_id) {
|
||||||
let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), context.field_rev);
|
Some(cell_rev) => Some(cell_rev.clone()),
|
||||||
|
None => self.default_cell_rev(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(cell_rev) = cell_rev {
|
||||||
|
let cell_bytes = decode_any_cell_data(cell_rev.data, context.field_rev);
|
||||||
let cell_data = cell_bytes.parser::<P>()?;
|
let cell_data = cell_bytes.parser::<P>()?;
|
||||||
Ok(self.move_row(&cell_data, context))
|
Ok(self.move_row(&cell_data, context))
|
||||||
} else {
|
} else {
|
||||||
|
tracing::warn!("Unexpected moving group row, changes should not be empty");
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use crate::entities::{GroupChangesetPB, InsertedRowPB, RowPB};
|
use crate::entities::{FieldType, GroupChangesetPB, InsertedRowPB, RowPB};
|
||||||
use crate::services::cell::insert_select_option_cell;
|
use crate::services::cell::{insert_checkbox_cell, insert_select_option_cell};
|
||||||
use crate::services::field::{SelectOptionCellDataPB, SelectOptionPB};
|
use crate::services::field::{SelectOptionCellDataPB, SelectOptionPB, CHECK};
|
||||||
use crate::services::group::configuration::GroupContext;
|
use crate::services::group::configuration::GroupContext;
|
||||||
use crate::services::group::{GeneratedGroup, Group};
|
|
||||||
|
|
||||||
use crate::services::group::controller::MoveGroupRowContext;
|
use crate::services::group::controller::MoveGroupRowContext;
|
||||||
use flowy_grid_data_model::revision::{GroupRevision, RowRevision, SelectOptionGroupConfigurationRevision};
|
use crate::services::group::{GeneratedGroup, Group};
|
||||||
|
use flowy_grid_data_model::revision::{
|
||||||
|
CellRevision, FieldRevision, GroupRevision, RowRevision, SelectOptionGroupConfigurationRevision,
|
||||||
|
};
|
||||||
|
|
||||||
pub type SelectOptionGroupContext = GroupContext<SelectOptionGroupConfigurationRevision>;
|
pub type SelectOptionGroupContext = GroupContext<SelectOptionGroupConfigurationRevision>;
|
||||||
|
|
||||||
@ -109,12 +110,18 @@ pub fn move_group_row(group: &mut Group, context: &mut MoveGroupRowContext) -> O
|
|||||||
|
|
||||||
// Update the corresponding row's cell content.
|
// Update the corresponding row's cell content.
|
||||||
if from_index.is_none() {
|
if from_index.is_none() {
|
||||||
tracing::debug!("Mark row:{} belong to group:{}", row_rev.id, group.id);
|
let cell_rev = make_inserted_cell_rev(&group.id, field_rev);
|
||||||
let cell_rev = insert_select_option_cell(group.id.clone(), field_rev);
|
if let Some(cell_rev) = cell_rev {
|
||||||
|
tracing::debug!(
|
||||||
|
"Update content of the cell in the row:{} to group:{}",
|
||||||
|
row_rev.id,
|
||||||
|
group.id
|
||||||
|
);
|
||||||
row_changeset.cell_by_field_id.insert(field_rev.id.clone(), cell_rev);
|
row_changeset.cell_by_field_id.insert(field_rev.id.clone(), cell_rev);
|
||||||
changeset.updated_rows.push(RowPB::from(*row_rev));
|
changeset.updated_rows.push(RowPB::from(*row_rev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if changeset.is_empty() {
|
if changeset.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -122,6 +129,27 @@ pub fn move_group_row(group: &mut Group, context: &mut MoveGroupRowContext) -> O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn make_inserted_cell_rev(group_id: &str, field_rev: &FieldRevision) -> Option<CellRevision> {
|
||||||
|
let field_type: FieldType = field_rev.ty.into();
|
||||||
|
match field_type {
|
||||||
|
FieldType::SingleSelect => {
|
||||||
|
let cell_rev = insert_select_option_cell(group_id.to_owned(), field_rev);
|
||||||
|
Some(cell_rev)
|
||||||
|
}
|
||||||
|
FieldType::MultiSelect => {
|
||||||
|
let cell_rev = insert_select_option_cell(group_id.to_owned(), field_rev);
|
||||||
|
Some(cell_rev)
|
||||||
|
}
|
||||||
|
FieldType::Checkbox => {
|
||||||
|
let cell_rev = insert_checkbox_cell(group_id == CHECK, field_rev);
|
||||||
|
Some(cell_rev)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
tracing::warn!("Unknown field type: {:?}", field_type);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn generate_select_option_groups(
|
pub fn generate_select_option_groups(
|
||||||
_field_id: &str,
|
_field_id: &str,
|
||||||
_group_ctx: &SelectOptionGroupContext,
|
_group_ctx: &SelectOptionGroupContext,
|
||||||
|
Reference in New Issue
Block a user