mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: save group configuration
This commit is contained in:
parent
91b2917d60
commit
49601b66ef
@ -287,7 +287,7 @@ impl GroupConfigurationWriter for GroupConfigurationWriterImpl {
|
||||
&self,
|
||||
field_id: &str,
|
||||
field_type: FieldTypeRevision,
|
||||
configuration: Arc<GroupConfigurationRevision>,
|
||||
configuration: GroupConfigurationRevision,
|
||||
) -> AFFuture<FlowyResult<()>> {
|
||||
let user_id = self.user_id.clone();
|
||||
let rev_manager = self.rev_manager.clone();
|
||||
@ -295,7 +295,6 @@ impl GroupConfigurationWriter for GroupConfigurationWriterImpl {
|
||||
let field_id = field_id.to_owned();
|
||||
|
||||
wrap_future(async move {
|
||||
let configuration = (&*configuration).clone();
|
||||
match view_pad
|
||||
.write()
|
||||
.await
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::services::group::Group;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::{
|
||||
FieldRevision, FieldTypeRevision, GroupConfigurationContentSerde, GroupConfigurationRevision, GroupRecordRevision,
|
||||
@ -14,13 +15,13 @@ pub trait GroupConfigurationWriter: Send + Sync + 'static {
|
||||
&self,
|
||||
field_id: &str,
|
||||
field_type: FieldTypeRevision,
|
||||
configuration: Arc<GroupConfigurationRevision>,
|
||||
configuration: GroupConfigurationRevision,
|
||||
) -> AFFuture<FlowyResult<()>>;
|
||||
}
|
||||
|
||||
pub trait GroupConfigurationAction: Send + Sync {
|
||||
fn group_records(&self) -> &[GroupRecordRevision];
|
||||
fn save_groups(&self) -> FlowyResult<()>;
|
||||
fn merge_groups(&self, groups: Vec<Group>) -> FlowyResult<()>;
|
||||
fn hide_group(&self, group_id: &str) -> FlowyResult<()>;
|
||||
fn show_group(&self, group_id: &str) -> FlowyResult<()>;
|
||||
}
|
||||
@ -28,8 +29,9 @@ pub trait GroupConfigurationAction: Send + Sync {
|
||||
pub struct GenericGroupConfiguration<C> {
|
||||
field_rev: Arc<FieldRevision>,
|
||||
reader: Arc<dyn GroupConfigurationReader>,
|
||||
configuration_rev: Arc<GroupConfigurationRevision>,
|
||||
writer: Arc<dyn GroupConfigurationWriter>,
|
||||
configuration: C,
|
||||
pub(crate) configuration: C,
|
||||
}
|
||||
|
||||
impl<C> GenericGroupConfiguration<C>
|
||||
@ -41,15 +43,18 @@ where
|
||||
reader: Arc<dyn GroupConfigurationReader>,
|
||||
writer: Arc<dyn GroupConfigurationWriter>,
|
||||
) -> FlowyResult<Self> {
|
||||
let configuration = reader.get_group_configuration(field_rev.clone()).await;
|
||||
let configuration = C::from_configuration(&configuration.content)?;
|
||||
let configuration_rev = reader.get_group_configuration(field_rev.clone()).await;
|
||||
let configuration = C::from_configuration_content(&configuration.content)?;
|
||||
Ok(Self {
|
||||
field_rev,
|
||||
configuration_rev,
|
||||
reader,
|
||||
writer,
|
||||
configuration,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn save_configuration(&self) {}
|
||||
}
|
||||
|
||||
impl<T> GroupConfigurationReader for Arc<T>
|
||||
@ -69,7 +74,7 @@ where
|
||||
&self,
|
||||
field_id: &str,
|
||||
field_type: FieldTypeRevision,
|
||||
configuration: Arc<GroupConfigurationRevision>,
|
||||
configuration: GroupConfigurationRevision,
|
||||
) -> AFFuture<FlowyResult<()>> {
|
||||
(**self).save_group_configuration(field_id, field_type, configuration)
|
||||
}
|
||||
|
@ -19,19 +19,19 @@ pub type CheckboxGroupController = GenericGroupController<
|
||||
pub type CheckboxGroupConfiguration = GenericGroupConfiguration<CheckboxGroupConfigurationRevision>;
|
||||
impl GroupConfigurationAction for CheckboxGroupConfiguration {
|
||||
fn group_records(&self) -> &[GroupRecordRevision] {
|
||||
todo!()
|
||||
vec![].as_slice()
|
||||
}
|
||||
|
||||
fn save_groups(&self) -> FlowyResult<()> {
|
||||
todo!()
|
||||
fn merge_groups(&self, groups: Vec<Group>) -> FlowyResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn hide_group(&self, group_id: &str) -> FlowyResult<()> {
|
||||
todo!()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn show_group(&self, group_id: &str) -> FlowyResult<()> {
|
||||
todo!()
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,10 +11,11 @@ use flowy_grid_data_model::revision::{
|
||||
pub type SelectOptionGroupConfiguration = GenericGroupConfiguration<SelectOptionGroupConfigurationRevision>;
|
||||
impl GroupConfigurationAction for SelectOptionGroupConfiguration {
|
||||
fn group_records(&self) -> &[GroupRecordRevision] {
|
||||
todo!()
|
||||
self.configuration.as_slice()
|
||||
}
|
||||
|
||||
fn save_groups(&self) -> FlowyResult<()> {
|
||||
fn merge_groups(&self, groups: Vec<Group>) -> FlowyResult<()> {
|
||||
// self.writer.save_group_configuration()
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,11 @@ use crate::services::group::configuration::{GenericGroupConfiguration, GroupConf
|
||||
use crate::services::group::entities::Group;
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::{
|
||||
FieldRevision, GroupConfigurationContentSerde, GroupConfigurationRevision, RowChangeset, RowRevision,
|
||||
TypeOptionDataDeserializer,
|
||||
FieldRevision, GroupConfigurationContentSerde, RowChangeset, RowRevision, TypeOptionDataDeserializer,
|
||||
};
|
||||
use indexmap::IndexMap;
|
||||
use lib_infra::future::AFFuture;
|
||||
|
||||
use crate::services::group::GroupConfigurationWriter;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -84,7 +84,7 @@ where
|
||||
pub async fn new(
|
||||
field_rev: &Arc<FieldRevision>,
|
||||
configuration_reader: Arc<dyn GroupConfigurationReader>,
|
||||
configuration_writer: Arc<dyn GroupConfigurationReader>,
|
||||
configuration_writer: Arc<dyn GroupConfigurationWriter>,
|
||||
) -> FlowyResult<Self> {
|
||||
let configuration =
|
||||
GenericGroupConfiguration::<C>::new(field_rev.clone(), configuration_reader, configuration_writer).await?;
|
||||
|
@ -1,7 +1,3 @@
|
||||
use crate::entities::{
|
||||
CheckboxGroupConfigurationPB, DateGroupConfigurationPB, FieldType, GroupRowsChangesetPB,
|
||||
NumberGroupConfigurationPB, SelectOptionGroupConfigurationPB, TextGroupConfigurationPB, UrlGroupConfigurationPB,
|
||||
};
|
||||
use crate::services::group::configuration::GroupConfigurationReader;
|
||||
use crate::services::group::group_controller::GroupController;
|
||||
use crate::services::group::{
|
||||
@ -14,6 +10,7 @@ use flowy_grid_data_model::revision::{
|
||||
TextGroupConfigurationRevision, UrlGroupConfigurationRevision,
|
||||
};
|
||||
|
||||
use crate::entities::{FieldType, GroupRowsChangesetPB};
|
||||
use std::future::Future;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
@ -4,7 +4,8 @@ use serde_json::Error;
|
||||
use serde_repr::*;
|
||||
|
||||
pub trait GroupConfigurationContentSerde: Sized {
|
||||
fn from_configuration(s: &str) -> Result<Self, serde_json::Error>;
|
||||
fn from_configuration_content(s: &str) -> Result<Self, serde_json::Error>;
|
||||
fn to_configuration_content(&self) -> Result<String, serde_json::Error>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
||||
@ -36,9 +37,12 @@ pub struct TextGroupConfigurationRevision {
|
||||
}
|
||||
|
||||
impl GroupConfigurationContentSerde for TextGroupConfigurationRevision {
|
||||
fn from_configuration(s: &str) -> Result<Self, Error> {
|
||||
fn from_configuration_content(s: &str) -> Result<Self, Error> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
@ -47,9 +51,12 @@ pub struct NumberGroupConfigurationRevision {
|
||||
}
|
||||
|
||||
impl GroupConfigurationContentSerde for NumberGroupConfigurationRevision {
|
||||
fn from_configuration(s: &str) -> Result<Self, Error> {
|
||||
fn from_configuration_content(s: &str) -> Result<Self, Error> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
@ -58,9 +65,12 @@ pub struct UrlGroupConfigurationRevision {
|
||||
}
|
||||
|
||||
impl GroupConfigurationContentSerde for UrlGroupConfigurationRevision {
|
||||
fn from_configuration(s: &str) -> Result<Self, Error> {
|
||||
fn from_configuration_content(s: &str) -> Result<Self, Error> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
@ -69,9 +79,13 @@ pub struct CheckboxGroupConfigurationRevision {
|
||||
}
|
||||
|
||||
impl GroupConfigurationContentSerde for CheckboxGroupConfigurationRevision {
|
||||
fn from_configuration(s: &str) -> Result<Self, Error> {
|
||||
fn from_configuration_content(s: &str) -> Result<Self, Error> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
@ -81,9 +95,13 @@ pub struct SelectOptionGroupConfigurationRevision {
|
||||
}
|
||||
|
||||
impl GroupConfigurationContentSerde for SelectOptionGroupConfigurationRevision {
|
||||
fn from_configuration(s: &str) -> Result<Self, Error> {
|
||||
fn from_configuration_content(s: &str) -> Result<Self, Error> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
@ -102,9 +120,12 @@ pub struct DateGroupConfigurationRevision {
|
||||
}
|
||||
|
||||
impl GroupConfigurationContentSerde for DateGroupConfigurationRevision {
|
||||
fn from_configuration(s: &str) -> Result<Self, Error> {
|
||||
fn from_configuration_content(s: &str) -> Result<Self, Error> {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize_repr, Deserialize_repr)]
|
||||
|
Loading…
Reference in New Issue
Block a user