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