mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add GridViewRevisionPad
This commit is contained in:
@ -3,7 +3,7 @@ use bytes::Bytes;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::revision::{CellRevision, GridBlockRevision, RowMetaChangeset, RowRevision};
|
||||
use flowy_revision::{RevisionCloudService, RevisionCompactor, RevisionManager, RevisionObjectBuilder};
|
||||
use flowy_sync::client_grid::{GridBlockMetaChange, GridBlockRevisionPad};
|
||||
use flowy_sync::client_grid::{GridBlockRevisionChangeset, GridBlockRevisionPad};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::util::make_delta_from_revisions;
|
||||
use lib_infra::future::FutureResult;
|
||||
@ -29,8 +29,8 @@ impl GridBlockRevisionEditor {
|
||||
let cloud = Arc::new(GridBlockRevisionCloudService {
|
||||
token: token.to_owned(),
|
||||
});
|
||||
let block_meta_pad = rev_manager.load::<GridBlockMetaPadBuilder>(Some(cloud)).await?;
|
||||
let pad = Arc::new(RwLock::new(block_meta_pad));
|
||||
let block_revision_pad = rev_manager.load::<GridBlockRevisionPadBuilder>(Some(cloud)).await?;
|
||||
let pad = Arc::new(RwLock::new(block_revision_pad));
|
||||
let rev_manager = Arc::new(rev_manager);
|
||||
let user_id = user_id.to_owned();
|
||||
let block_id = block_id.to_owned();
|
||||
@ -145,7 +145,7 @@ impl GridBlockRevisionEditor {
|
||||
|
||||
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
||||
where
|
||||
F: for<'a> FnOnce(&'a mut GridBlockRevisionPad) -> FlowyResult<Option<GridBlockMetaChange>>,
|
||||
F: for<'a> FnOnce(&'a mut GridBlockRevisionPad) -> FlowyResult<Option<GridBlockRevisionChangeset>>,
|
||||
{
|
||||
let mut write_guard = self.pad.write().await;
|
||||
match f(&mut *write_guard)? {
|
||||
@ -157,8 +157,8 @@ impl GridBlockRevisionEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn apply_change(&self, change: GridBlockMetaChange) -> FlowyResult<()> {
|
||||
let GridBlockMetaChange { delta, md5 } = change;
|
||||
async fn apply_change(&self, change: GridBlockRevisionChangeset) -> FlowyResult<()> {
|
||||
let GridBlockRevisionChangeset { delta, md5 } = change;
|
||||
let user_id = self.user_id.clone();
|
||||
let (base_rev_id, rev_id) = self.rev_manager.next_rev_id_pair();
|
||||
let delta_data = delta.json_bytes();
|
||||
@ -187,8 +187,8 @@ impl RevisionCloudService for GridBlockRevisionCloudService {
|
||||
}
|
||||
}
|
||||
|
||||
struct GridBlockMetaPadBuilder();
|
||||
impl RevisionObjectBuilder for GridBlockMetaPadBuilder {
|
||||
struct GridBlockRevisionPadBuilder();
|
||||
impl RevisionObjectBuilder for GridBlockRevisionPadBuilder {
|
||||
type Output = GridBlockRevisionPad;
|
||||
|
||||
fn build_object(object_id: &str, revisions: Vec<Revision>) -> FlowyResult<Self::Output> {
|
||||
|
@ -16,7 +16,7 @@ use bytes::Bytes;
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::revision::*;
|
||||
use flowy_revision::{RevisionCloudService, RevisionCompactor, RevisionManager, RevisionObjectBuilder};
|
||||
use flowy_sync::client_grid::{GridChangeset, GridRevisionPad, JsonDeserializer};
|
||||
use flowy_sync::client_grid::{GridRevisionChangeset, GridRevisionPad, JsonDeserializer};
|
||||
use flowy_sync::entities::grid::{FieldChangesetParams, GridSettingChangesetParams};
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::errors::CollaborateResult;
|
||||
@ -608,7 +608,7 @@ impl GridRevisionEditor {
|
||||
|
||||
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
||||
where
|
||||
F: for<'a> FnOnce(&'a mut GridRevisionPad) -> FlowyResult<Option<GridChangeset>>,
|
||||
F: for<'a> FnOnce(&'a mut GridRevisionPad) -> FlowyResult<Option<GridRevisionChangeset>>,
|
||||
{
|
||||
let mut write_guard = self.grid_pad.write().await;
|
||||
if let Some(changeset) = f(&mut *write_guard)? {
|
||||
@ -617,8 +617,8 @@ impl GridRevisionEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn apply_change(&self, change: GridChangeset) -> FlowyResult<()> {
|
||||
let GridChangeset { delta, md5 } = change;
|
||||
async fn apply_change(&self, change: GridRevisionChangeset) -> FlowyResult<()> {
|
||||
let GridRevisionChangeset { delta, md5 } = change;
|
||||
let user_id = self.user.user_id()?;
|
||||
let (base_rev_id, rev_id) = self.rev_manager.next_rev_id_pair();
|
||||
let delta_data = delta.json_bytes();
|
||||
|
@ -0,0 +1,48 @@
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::revision::GridViewRevision;
|
||||
use flowy_revision::{RevisionCloudService, RevisionManager, RevisionObjectBuilder};
|
||||
use flowy_sync::client_grid::GridViewRevisionPad;
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use lib_infra::future::FutureResult;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct GridViewRevisionEditor {
|
||||
pad: Arc<RwLock<GridViewRevisionPad>>,
|
||||
rev_manager: Arc<RevisionManager>,
|
||||
}
|
||||
|
||||
impl GridViewRevisionEditor {
|
||||
pub async fn new(token: &str, mut rev_manager: RevisionManager) -> FlowyResult<Self> {
|
||||
let cloud = Arc::new(GridViewRevisionCloudService {
|
||||
token: token.to_owned(),
|
||||
});
|
||||
let view_revision_pad = rev_manager.load::<GridViewRevisionPadBuilder>(Some(cloud)).await?;
|
||||
let pad = Arc::new(RwLock::new(view_revision_pad));
|
||||
let rev_manager = Arc::new(rev_manager);
|
||||
|
||||
Ok(Self { pad, rev_manager })
|
||||
}
|
||||
}
|
||||
|
||||
struct GridViewRevisionCloudService {
|
||||
#[allow(dead_code)]
|
||||
token: String,
|
||||
}
|
||||
|
||||
impl RevisionCloudService for GridViewRevisionCloudService {
|
||||
#[tracing::instrument(level = "trace", skip(self))]
|
||||
fn fetch_object(&self, _user_id: &str, _object_id: &str) -> FutureResult<Vec<Revision>, FlowyError> {
|
||||
FutureResult::new(async move { Ok(vec![]) })
|
||||
}
|
||||
}
|
||||
|
||||
struct GridViewRevisionPadBuilder();
|
||||
impl RevisionObjectBuilder for GridViewRevisionPadBuilder {
|
||||
type Output = GridViewRevisionPad;
|
||||
|
||||
fn build_object(object_id: &str, revisions: Vec<Revision>) -> FlowyResult<Self::Output> {
|
||||
let pad = GridViewRevisionPad::from_revisions(object_id, revisions)?;
|
||||
Ok(pad)
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ pub mod field;
|
||||
mod filter;
|
||||
pub mod grid_editor;
|
||||
mod grid_editor_task;
|
||||
pub mod grid_view_editor;
|
||||
pub mod group;
|
||||
pub mod persistence;
|
||||
pub mod row;
|
||||
|
Reference in New Issue
Block a user