mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: fix warnings
This commit is contained in:
parent
915d71991a
commit
82eed0506b
@ -142,7 +142,7 @@ async fn make_field_edit_context(
|
||||
) -> FlowyResult<EditFieldContext> {
|
||||
let field_meta = field_meta.unwrap_or(get_or_create_field_meta(field_id, &field_type, editor).await?);
|
||||
let s = field_meta
|
||||
.get_type_option_str()
|
||||
.get_type_option_str(None)
|
||||
.unwrap_or_else(|| default_type_option_builder_from_type(&field_type).entry().json_str());
|
||||
|
||||
let builder = type_option_builder_from_json_str(&s, &field_meta.field_type);
|
||||
|
@ -30,10 +30,7 @@ macro_rules! impl_type_option {
|
||||
($target: ident, $field_type:expr) => {
|
||||
impl std::convert::From<&FieldMeta> for $target {
|
||||
fn from(field_meta: &FieldMeta) -> $target {
|
||||
match field_meta
|
||||
.type_option_by_field_type_id
|
||||
.get_entry::<$target>(&$field_type)
|
||||
{
|
||||
match field_meta.get_type_option_entry::<$target>(Some($field_type)) {
|
||||
None => $target::default(),
|
||||
Some(target) => target,
|
||||
}
|
||||
@ -66,7 +63,7 @@ macro_rules! impl_type_option {
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeOptionDataFrom for $target {
|
||||
impl TypeOptionDataEntity for $target {
|
||||
fn from_json_str(s: &str) -> $target {
|
||||
match serde_json::from_str(s) {
|
||||
Ok(obj) => obj,
|
||||
|
@ -1,8 +1,6 @@
|
||||
use crate::services::field::type_options::*;
|
||||
use bytes::Bytes;
|
||||
use flowy_grid_data_model::entities::{
|
||||
Field, FieldMeta, FieldType, TypeOptionDataByFieldTypeId, TypeOptionDataEntry, TypeOptionDataFrom,
|
||||
};
|
||||
use flowy_grid_data_model::entities::{Field, FieldMeta, FieldType, TypeOptionDataByFieldTypeId, TypeOptionDataEntry};
|
||||
|
||||
pub struct FieldBuilder {
|
||||
field_meta: FieldMeta,
|
||||
@ -71,9 +69,7 @@ impl FieldBuilder {
|
||||
pub fn build(self) -> FieldMeta {
|
||||
debug_assert_eq!(self.field_meta.field_type, self.type_option_builder.field_type());
|
||||
let mut field_meta = self.field_meta;
|
||||
field_meta
|
||||
.type_option_by_field_type_id
|
||||
.insert_entry(self.type_option_builder.entry());
|
||||
field_meta.insert_type_option_entry(self.type_option_builder.entry());
|
||||
field_meta
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,10 @@
|
||||
use crate::impl_type_option;
|
||||
use crate::services::field::{
|
||||
BoxTypeOptionBuilder, DateTypeOption, MultiSelectTypeOption, NumberTypeOption, RichTextTypeOption,
|
||||
SingleSelectTypeOption, TypeOptionBuilder,
|
||||
};
|
||||
use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder};
|
||||
use crate::services::row::CellDataSerde;
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::ProtoBuf;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntry, TypeOptionDataFrom};
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntity, TypeOptionDataEntry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -5,10 +5,10 @@ use chrono::format::strftime::StrftimeItems;
|
||||
use chrono::NaiveDateTime;
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntry, TypeOptionDataFrom};
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntity, TypeOptionDataEntry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::services::field::{BoxTypeOptionBuilder, RichTextTypeOption, TypeOptionBuilder};
|
||||
use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder};
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
// Date
|
||||
|
@ -2,7 +2,7 @@ use crate::impl_type_option;
|
||||
use crate::services::row::CellDataSerde;
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntry, TypeOptionDataFrom};
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntity, TypeOptionDataEntry};
|
||||
use lazy_static::lazy_static;
|
||||
use rust_decimal::prelude::Zero;
|
||||
use rust_decimal::Decimal;
|
||||
|
@ -5,7 +5,7 @@ use crate::services::util::*;
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntry, TypeOptionDataFrom};
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntity, TypeOptionDataEntry};
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
@ -4,7 +4,7 @@ use crate::services::row::CellDataSerde;
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::ProtoBuf;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntry, TypeOptionDataFrom};
|
||||
use flowy_grid_data_model::entities::{FieldMeta, FieldType, TypeOptionDataEntity, TypeOptionDataEntry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -1,7 +1,3 @@
|
||||
use flowy_grid_data_model::entities::FieldType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
// #[derive(Debug, Clone, Serialize, Deserialize, Default, ProtoBuf)]
|
||||
// pub struct TypeOptionData {
|
||||
// #[pb(index = 1)]
|
||||
|
@ -1,10 +1,7 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridNotification};
|
||||
use crate::manager::GridUser;
|
||||
use crate::services::block_meta_editor::GridBlockMetaEditorManager;
|
||||
use crate::services::field::{
|
||||
default_type_option_builder_from_type, type_option_builder_from_bytes, type_option_builder_from_json_str,
|
||||
FieldBuilder,
|
||||
};
|
||||
use crate::services::field::{default_type_option_builder_from_type, type_option_builder_from_bytes, FieldBuilder};
|
||||
use crate::services::row::*;
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
|
@ -6,7 +6,8 @@ use flowy_grid::services::field::{
|
||||
};
|
||||
use flowy_grid::services::row::{deserialize_cell_data, serialize_cell_data, CellDataSerde, CreateRowMetaBuilder};
|
||||
use flowy_grid_data_model::entities::{
|
||||
CellMetaChangeset, FieldChangeset, FieldType, GridBlockMeta, GridBlockMetaChangeset, RowMetaChangeset,
|
||||
CellMetaChangeset, FieldChangesetParams, FieldType, GridBlockMeta, GridBlockMetaChangeset, RowMetaChangeset,
|
||||
TypeOptionDataEntry,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
@ -55,7 +56,7 @@ async fn grid_create_duplicate_field() {
|
||||
async fn grid_update_field_with_empty_change() {
|
||||
let mut test = GridEditorTest::new().await;
|
||||
let (params, field_meta) = create_single_select_field(&test.grid_id);
|
||||
let changeset = FieldChangeset {
|
||||
let changeset = FieldChangesetParams {
|
||||
field_id: field_meta.id.clone(),
|
||||
grid_id: test.grid_id.clone(),
|
||||
name: None,
|
||||
@ -84,9 +85,9 @@ async fn grid_update_field() {
|
||||
let (single_select_params, single_select_field) = create_single_select_field(&test.grid_id);
|
||||
let mut cloned_field = single_select_field.clone();
|
||||
|
||||
let mut single_select_type_options = SingleSelectTypeOption::from(&single_select_field);
|
||||
single_select_type_options.options.push(SelectOption::new("Unknown"));
|
||||
let changeset = FieldChangeset {
|
||||
let mut single_select_type_option = SingleSelectTypeOption::from(&single_select_field);
|
||||
single_select_type_option.options.push(SelectOption::new("Unknown"));
|
||||
let changeset = FieldChangesetParams {
|
||||
field_id: single_select_field.id.clone(),
|
||||
grid_id: test.grid_id.clone(),
|
||||
name: None,
|
||||
@ -95,12 +96,12 @@ async fn grid_update_field() {
|
||||
frozen: Some(true),
|
||||
visibility: None,
|
||||
width: Some(1000),
|
||||
type_option_data: Some(single_select_type_options.clone().into()),
|
||||
type_option_data: Some(single_select_type_option.protobuf_bytes().to_vec()),
|
||||
};
|
||||
|
||||
cloned_field.frozen = true;
|
||||
cloned_field.width = 1000;
|
||||
cloned_field.type_option_json = single_select_type_options.into();
|
||||
cloned_field.insert_type_option_entry(&single_select_type_option);
|
||||
|
||||
let scripts = vec![
|
||||
CreateField {
|
||||
|
@ -3,10 +3,9 @@ use flowy_grid::services::field::*;
|
||||
use flowy_grid::services::grid_editor::{ClientGridEditor, GridPadBuilder};
|
||||
use flowy_grid::services::row::CreateRowMetaPayload;
|
||||
use flowy_grid_data_model::entities::{
|
||||
BuildGridContext, CellMetaChangeset, CreateFieldParams, Field, FieldChangeset, FieldMeta, FieldType, GridBlockMeta,
|
||||
GridBlockMetaChangeset, RowMeta, RowMetaChangeset, RowOrder,
|
||||
BuildGridContext, CellMetaChangeset, CreateFieldParams, Field, FieldChangesetParams, FieldMeta, FieldType,
|
||||
GridBlockMeta, GridBlockMetaChangeset, RowMeta, RowMetaChangeset, RowOrder, TypeOptionDataEntry,
|
||||
};
|
||||
use flowy_grid_data_model::parser::CreateFieldParams;
|
||||
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
||||
use flowy_sync::client_grid::GridBuilder;
|
||||
use flowy_test::helper::ViewTest;
|
||||
@ -22,7 +21,7 @@ pub enum EditorScript {
|
||||
params: CreateFieldParams,
|
||||
},
|
||||
UpdateField {
|
||||
changeset: FieldChangeset,
|
||||
changeset: FieldChangesetParams,
|
||||
},
|
||||
DeleteField {
|
||||
field_meta: FieldMeta,
|
||||
@ -255,6 +254,12 @@ pub fn create_text_field(grid_id: &str) -> (CreateFieldParams, FieldMeta) {
|
||||
|
||||
let cloned_field_meta = field_meta.clone();
|
||||
|
||||
let type_option_data = field_meta
|
||||
.get_type_option_entry::<RichTextTypeOption>(None)
|
||||
.unwrap()
|
||||
.protobuf_bytes()
|
||||
.to_vec();
|
||||
|
||||
let field = Field {
|
||||
id: field_meta.id,
|
||||
name: field_meta.name,
|
||||
@ -268,7 +273,7 @@ pub fn create_text_field(grid_id: &str) -> (CreateFieldParams, FieldMeta) {
|
||||
let params = CreateFieldParams {
|
||||
grid_id: grid_id.to_owned(),
|
||||
field,
|
||||
type_option_data: field_meta.type_option_json.as_bytes().to_vec(),
|
||||
type_option_data,
|
||||
start_field_id: None,
|
||||
};
|
||||
(params, cloned_field_meta)
|
||||
@ -281,6 +286,11 @@ pub fn create_single_select_field(grid_id: &str) -> (CreateFieldParams, FieldMet
|
||||
|
||||
let field_meta = FieldBuilder::new(single_select).name("Name").visibility(true).build();
|
||||
let cloned_field_meta = field_meta.clone();
|
||||
let type_option_data = field_meta
|
||||
.get_type_option_entry::<SingleSelectTypeOption>(None)
|
||||
.unwrap()
|
||||
.protobuf_bytes()
|
||||
.to_vec();
|
||||
|
||||
let field = Field {
|
||||
id: field_meta.id,
|
||||
@ -295,7 +305,7 @@ pub fn create_single_select_field(grid_id: &str) -> (CreateFieldParams, FieldMet
|
||||
let params = CreateFieldParams {
|
||||
grid_id: grid_id.to_owned(),
|
||||
field,
|
||||
type_option_data: field_meta.type_option_json.as_bytes().to_vec(),
|
||||
type_option_data,
|
||||
start_field_id: None,
|
||||
};
|
||||
(params, cloned_field_meta)
|
||||
|
@ -3,9 +3,7 @@ use bytes::Bytes;
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error_code::ErrorCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
use strum_macros::{Display, EnumCount as EnumCountMacro, EnumIter, EnumString};
|
||||
|
||||
pub const DEFAULT_ROW_HEIGHT: i32 = 36;
|
||||
@ -79,7 +77,7 @@ pub struct GridBlockMetaSerde {
|
||||
pub row_metas: Vec<RowMeta>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, ProtoBuf)]
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, ProtoBuf, Eq, PartialEq)]
|
||||
pub struct FieldMeta {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
@ -120,11 +118,27 @@ impl FieldMeta {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_type_option_str(&self) -> Option<String> {
|
||||
match self.type_option_by_field_type_id.get(&self.field_type) {
|
||||
None => None,
|
||||
Some(s) => Some(s.to_owned()),
|
||||
}
|
||||
pub fn insert_type_option_entry<T: TypeOptionDataEntry + ?Sized>(&mut self, entry: &T) {
|
||||
self.type_option_by_field_type_id
|
||||
.insert(entry.field_type().type_id(), entry.json_str());
|
||||
}
|
||||
|
||||
pub fn get_type_option_entry<T: TypeOptionDataEntity>(&self, field_type: Option<FieldType>) -> Option<T> {
|
||||
let field_type = field_type.as_ref().unwrap_or(&self.field_type);
|
||||
self.type_option_by_field_type_id
|
||||
.get(&field_type.type_id())
|
||||
.map(|s| T::from_json_str(s))
|
||||
}
|
||||
|
||||
pub fn insert_type_option_str(&mut self, field_type: &FieldType, json_str: String) {
|
||||
self.type_option_by_field_type_id.insert(field_type.type_id(), json_str);
|
||||
}
|
||||
|
||||
pub fn get_type_option_str(&self, field_type: Option<FieldType>) -> Option<String> {
|
||||
let field_type = field_type.as_ref().unwrap_or(&self.field_type);
|
||||
self.type_option_by_field_type_id
|
||||
.get(&field_type.type_id())
|
||||
.map(|s| s.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,38 +148,28 @@ pub trait TypeOptionDataEntry {
|
||||
fn protobuf_bytes(&self) -> Bytes;
|
||||
}
|
||||
|
||||
pub trait TypeOptionDataFrom {
|
||||
pub trait TypeOptionDataEntity {
|
||||
fn from_json_str(s: &str) -> Self;
|
||||
fn from_protobuf_bytes(bytes: Bytes) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, ProtoBuf)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, ProtoBuf, PartialEq, Eq)]
|
||||
pub struct TypeOptionDataByFieldTypeId {
|
||||
#[pb(index = 1)]
|
||||
pub map: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl TypeOptionDataByFieldTypeId {
|
||||
pub fn insert_entry<T: TypeOptionDataEntry + ?Sized>(&mut self, entry: &T) {
|
||||
self.map.insert(entry.field_type().type_id(), entry.json_str());
|
||||
}
|
||||
impl std::ops::Deref for TypeOptionDataByFieldTypeId {
|
||||
type Target = HashMap<String, String>;
|
||||
|
||||
pub fn insert(&mut self, field_type: &FieldType, json_str: String) {
|
||||
self.map.insert(field_type.type_id(), json_str);
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.map
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_entry<T: TypeOptionDataFrom>(&self, field_type: &FieldType) -> Option<T> {
|
||||
match self.map.get(&field_type.type_id()) {
|
||||
None => None,
|
||||
Some(s) => Some(T::from_json_str(s)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, field_type: &FieldType) -> Option<String> {
|
||||
match self.map.get(&field_type.type_id()) {
|
||||
None => None,
|
||||
Some(s) => Some(s.to_owned()),
|
||||
}
|
||||
impl std::ops::DerefMut for TypeOptionDataByFieldTypeId {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.map
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,13 @@ use crate::util::{cal_diff, make_delta_from_revisions};
|
||||
use bytes::Bytes;
|
||||
use flowy_grid_data_model::entities::{
|
||||
FieldChangesetParams, FieldMeta, FieldOrder, FieldType, GridBlockMeta, GridBlockMetaChangeset, GridMeta,
|
||||
RepeatedFieldOrder, TypeOptionDataEntry,
|
||||
RepeatedFieldOrder,
|
||||
};
|
||||
|
||||
use lib_infra::uuid;
|
||||
use lib_ot::core::{OperationTransformable, PlainTextAttributes, PlainTextDelta, PlainTextDeltaBuilder};
|
||||
use std::collections::HashMap;
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type GridMetaDelta = PlainTextDelta;
|
||||
@ -107,11 +107,9 @@ impl GridMetaPad {
|
||||
Ok(None)
|
||||
}
|
||||
Some(field_meta) => {
|
||||
if field_meta.get_type_option_str().is_none() {
|
||||
if field_meta.get_type_option_str(Some(field_type.clone())).is_none() {
|
||||
let type_option_json = type_option_json_builder(&field_type);
|
||||
field_meta
|
||||
.type_option_by_field_type_id
|
||||
.insert(&field_type, type_option_json);
|
||||
field_meta.insert_type_option_str(&field_type, type_option_json);
|
||||
}
|
||||
|
||||
field_meta.field_type = field_type;
|
||||
@ -162,7 +160,8 @@ impl GridMetaPad {
|
||||
if let Some(type_option_data) = changeset.type_option_data {
|
||||
match deserializer.deserialize(type_option_data) {
|
||||
Ok(json_str) => {
|
||||
field.type_option_by_field_type_id.insert(&field.field_type, json_str);
|
||||
let field_type = field.field_type.clone();
|
||||
field.insert_type_option_str(&field_type, json_str);
|
||||
is_changed = Some(())
|
||||
}
|
||||
Err(err) => {
|
||||
|
Loading…
Reference in New Issue
Block a user