chore: read block rows with filters

This commit is contained in:
appflowy 2022-06-26 15:14:24 +08:00
parent b73c68c6f6
commit 7504ea7555
10 changed files with 105 additions and 104 deletions

View File

@ -9,7 +9,7 @@ use flowy_grid_data_model::entities::{
CellChangeset, GridRowsChangeset, IndexRowOrder, Row, RowOrder, UpdatedRowOrder,
};
use flowy_grid_data_model::revision::{
CellRevision, GridBlockRevision, GridBlockRevisionChangeset, RowMetaChangeset, RowRevision,
CellRevision, GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision,
};
use flowy_revision::disk::SQLiteGridBlockMetaRevisionPersistence;
use flowy_revision::{RevisionManager, RevisionPersistence};
@ -30,7 +30,7 @@ impl GridBlockManager {
pub(crate) async fn new(
grid_id: &str,
user: &Arc<dyn GridUser>,
block_revs: Vec<Arc<GridBlockRevision>>,
block_revs: Vec<Arc<GridBlockMetaRevision>>,
persistence: Arc<BlockIndexCache>,
) -> FlowyResult<Self> {
let editor_map = make_block_meta_editor_map(user, block_revs).await?;
@ -86,7 +86,7 @@ impl GridBlockManager {
pub(crate) async fn insert_row(
&self,
rows_by_block_id: HashMap<String, Vec<RowRevision>>,
) -> FlowyResult<Vec<GridBlockRevisionChangeset>> {
) -> FlowyResult<Vec<GridBlockMetaRevisionChangeset>> {
let mut changesets = vec![];
for (block_id, row_revs) in rows_by_block_id {
let mut inserted_row_orders = vec![];
@ -100,7 +100,7 @@ impl GridBlockManager {
row_order.index = index;
inserted_row_orders.push(row_order);
}
changesets.push(GridBlockRevisionChangeset::from_row_count(&block_id, row_count));
changesets.push(GridBlockMetaRevisionChangeset::from_row_count(&block_id, row_count));
let _ = self
.notify_did_update_block(&block_id, GridRowsChangeset::insert(&block_id, inserted_row_orders))
@ -148,7 +148,10 @@ impl GridBlockManager {
Ok(())
}
pub(crate) async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<Vec<GridBlockRevisionChangeset>> {
pub(crate) async fn delete_rows(
&self,
row_orders: Vec<RowOrder>,
) -> FlowyResult<Vec<GridBlockMetaRevisionChangeset>> {
let mut changesets = vec![];
for block_order in block_from_row_orders(row_orders) {
let editor = self.get_editor(&block_order.id).await?;
@ -158,7 +161,7 @@ impl GridBlockManager {
.map(|row_order| Cow::Owned(row_order.row_id))
.collect::<Vec<Cow<String>>>();
let row_count = editor.delete_rows(row_ids).await?;
let changeset = GridBlockRevisionChangeset::from_row_count(&block_order.id, row_count);
let changeset = GridBlockMetaRevisionChangeset::from_row_count(&block_order.id, row_count);
changesets.push(changeset);
}
@ -262,7 +265,7 @@ impl GridBlockManager {
async fn make_block_meta_editor_map(
user: &Arc<dyn GridUser>,
block_revs: Vec<Arc<GridBlockRevision>>,
block_revs: Vec<Arc<GridBlockMetaRevision>>,
) -> FlowyResult<DashMap<String, Arc<GridBlockRevisionEditor>>> {
let editor_map = DashMap::new();
for block_rev in block_revs {

View File

@ -1,7 +1,7 @@
use bytes::Bytes;
use flowy_error::{FlowyError, FlowyResult};
use flowy_grid_data_model::entities::RowOrder;
use flowy_grid_data_model::revision::{CellRevision, GridBlockRevisionData, RowMetaChangeset, RowRevision};
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::entities::revision::Revision;
@ -42,7 +42,7 @@ impl GridBlockRevisionEditor {
})
}
pub async fn duplicate_block(&self, duplicated_block_id: &str) -> GridBlockRevisionData {
pub async fn duplicate_block(&self, duplicated_block_id: &str) -> GridBlockRevision {
self.pad.read().await.duplicate_data(duplicated_block_id).await
}

View File

@ -46,7 +46,7 @@ impl GridRevisionEditor {
let grid_pad = rev_manager.load::<GridPadBuilder>(Some(cloud)).await?;
let rev_manager = Arc::new(rev_manager);
let grid_pad = Arc::new(RwLock::new(grid_pad));
let block_revs = grid_pad.read().await.get_block_revs();
let block_revs = grid_pad.read().await.get_block_meta_revs();
let block_meta_manager = Arc::new(GridBlockManager::new(grid_id, &user, block_revs, persistence).await?);
Ok(Arc::new(Self {
@ -243,14 +243,14 @@ impl GridRevisionEditor {
Ok(field_revs)
}
pub async fn create_block(&self, grid_block: GridBlockRevision) -> FlowyResult<()> {
pub async fn create_block(&self, block_meta_rev: GridBlockMetaRevision) -> FlowyResult<()> {
let _ = self
.modify(|grid_pad| Ok(grid_pad.create_block_rev(grid_block)?))
.modify(|grid_pad| Ok(grid_pad.create_block_meta_rev(block_meta_rev)?))
.await?;
Ok(())
}
pub async fn update_block(&self, changeset: GridBlockRevisionChangeset) -> FlowyResult<()> {
pub async fn update_block(&self, changeset: GridBlockMetaRevisionChangeset) -> FlowyResult<()> {
let _ = self
.modify(|grid_pad| Ok(grid_pad.update_block_rev(changeset)?))
.await?;
@ -270,7 +270,7 @@ impl GridRevisionEditor {
let row_count = self.block_manager.create_row(&block_id, row_rev, start_row_id).await?;
// update block row count
let changeset = GridBlockRevisionChangeset::from_row_count(&block_id, row_count);
let changeset = GridBlockMetaRevisionChangeset::from_row_count(&block_id, row_count);
let _ = self.update_block(changeset).await?;
Ok(row_order)
}
@ -408,9 +408,9 @@ impl GridRevisionEditor {
make_grid_blocks(block_ids, block_snapshots)
}
pub async fn get_block_metas(&self) -> FlowyResult<Vec<Arc<GridBlockRevision>>> {
let grid_blocks = self.grid_pad.read().await.get_block_revs();
Ok(grid_blocks)
pub async fn get_block_meta_revs(&self) -> FlowyResult<Vec<Arc<GridBlockMetaRevision>>> {
let block_meta_revs = self.grid_pad.read().await.get_block_meta_revs();
Ok(block_meta_revs)
}
pub async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<()> {
@ -425,7 +425,7 @@ impl GridRevisionEditor {
let pad_read_guard = self.grid_pad.read().await;
let field_orders = pad_read_guard.get_field_orders();
let mut block_orders = vec![];
for block_rev in pad_read_guard.get_block_revs() {
for block_rev in pad_read_guard.get_block_meta_revs() {
let row_orders = self.block_manager.get_row_orders(&block_rev.block_id).await?;
let block_order = GridBlock {
id: block_rev.block_id.clone(),
@ -469,7 +469,7 @@ impl GridRevisionEditor {
.grid_pad
.read()
.await
.get_block_revs()
.get_block_meta_revs()
.iter()
.map(|block_rev| block_rev.block_id.clone())
.collect::<Vec<String>>(),
@ -519,8 +519,8 @@ impl GridRevisionEditor {
pub async fn duplicate_grid(&self) -> FlowyResult<BuildGridContext> {
let grid_pad = self.grid_pad.read().await;
let original_blocks = grid_pad.get_block_revs();
let (duplicated_fields, duplicated_blocks) = grid_pad.duplicate_grid_meta().await;
let original_blocks = grid_pad.get_block_meta_revs();
let (duplicated_fields, duplicated_blocks) = grid_pad.duplicate_grid_block_meta().await;
let mut blocks_meta_data = vec![];
if original_blocks.len() == duplicated_blocks.len() {
@ -576,7 +576,7 @@ impl GridRevisionEditor {
}
async fn block_id(&self) -> FlowyResult<String> {
match self.grid_pad.read().await.get_block_revs().last() {
match self.grid_pad.read().await.get_block_meta_revs().last() {
None => Err(FlowyError::internal().context("There is no grid block in this grid")),
Some(grid_block) => Ok(grid_block.block_id.clone()),
}

View File

@ -220,6 +220,14 @@ where
}
}
/// The data is encoded by protobuf or utf8. You should choose the corresponding decode struct to parse it.
///
/// For example:
///
/// * Use DateCellData to parse the data when the FieldType is Date.
/// * Use URLCellData to parse the data when the FieldType is URL.
/// * Use String to parse the data when the FieldType is RichText, Number, or Checkbox.
/// * Check out the implementation of CellDataOperation trait for more information.
#[derive(Default)]
pub struct DecodedCellData {
pub data: Vec<u8>,

View File

@ -1,13 +1,13 @@
use crate::grid::script::EditorScript::*;
use crate::grid::script::*;
use flowy_grid_data_model::revision::{GridBlockRevision, GridBlockRevisionChangeset};
use flowy_grid_data_model::revision::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset};
#[tokio::test]
async fn grid_create_block() {
let grid_block = GridBlockRevision::new();
let block_meta_rev = GridBlockMetaRevision::new();
let scripts = vec![
AssertBlockCount(1),
CreateBlock { block: grid_block },
CreateBlock { block: block_meta_rev },
AssertBlockCount(2),
];
GridEditorTest::new().await.run_scripts(scripts).await;
@ -15,10 +15,10 @@ async fn grid_create_block() {
#[tokio::test]
async fn grid_update_block() {
let grid_block = GridBlockRevision::new();
let mut cloned_grid_block = grid_block.clone();
let changeset = GridBlockRevisionChangeset {
block_id: grid_block.block_id.clone(),
let block_meta_rev = GridBlockMetaRevision::new();
let mut cloned_grid_block = block_meta_rev.clone();
let changeset = GridBlockMetaRevisionChangeset {
block_id: block_meta_rev.block_id.clone(),
start_row_index: Some(2),
row_count: Some(10),
};
@ -28,7 +28,7 @@ async fn grid_update_block() {
let scripts = vec![
AssertBlockCount(1),
CreateBlock { block: grid_block },
CreateBlock { block: block_meta_rev },
UpdateBlock { changeset },
AssertBlockCount(2),
AssertBlockEqual {

View File

@ -31,10 +31,10 @@ pub enum EditorScript {
field_rev: FieldRevision,
},
CreateBlock {
block: GridBlockRevision,
block: GridBlockMetaRevision,
},
UpdateBlock {
changeset: GridBlockRevisionChangeset,
changeset: GridBlockMetaRevisionChangeset,
},
AssertBlockCount(usize),
AssertBlock {
@ -44,7 +44,7 @@ pub enum EditorScript {
},
AssertBlockEqual {
block_index: usize,
block: GridBlockRevision,
block: GridBlockMetaRevision,
},
CreateEmptyRow,
CreateRow {
@ -87,7 +87,7 @@ pub struct GridEditorTest {
pub grid_id: String,
pub editor: Arc<GridRevisionEditor>,
pub field_revs: Vec<FieldRevision>,
pub grid_block_revs: Vec<GridBlockRevision>,
pub grid_block_revs: Vec<GridBlockMetaRevision>,
pub row_revs: Vec<Arc<RowRevision>>,
pub field_count: usize,
@ -103,7 +103,7 @@ impl GridEditorTest {
let test = ViewTest::new_grid_view(&sdk, view_data.to_vec()).await;
let editor = sdk.grid_manager.open_grid(&test.view.id).await.unwrap();
let field_revs = editor.get_field_revs::<FieldOrder>(None).await.unwrap();
let grid_blocks = editor.get_block_metas().await.unwrap();
let grid_blocks = editor.get_block_meta_revs().await.unwrap();
let row_revs = editor.grid_block_snapshots(None).await.unwrap().pop().unwrap().row_revs;
assert_eq!(row_revs.len(), 3);
assert_eq!(grid_blocks.len(), 1);
@ -172,13 +172,13 @@ impl GridEditorTest {
}
EditorScript::CreateBlock { block } => {
self.editor.create_block(block).await.unwrap();
self.grid_block_revs = self.editor.get_block_metas().await.unwrap();
self.grid_block_revs = self.editor.get_block_meta_revs().await.unwrap();
}
EditorScript::UpdateBlock { changeset: change } => {
self.editor.update_block(change).await.unwrap();
}
EditorScript::AssertBlockCount(count) => {
assert_eq!(self.editor.get_block_metas().await.unwrap().len(), count);
assert_eq!(self.editor.get_block_meta_revs().await.unwrap().len(), count);
}
EditorScript::AssertBlock {
block_index,
@ -189,7 +189,7 @@ impl GridEditorTest {
assert_eq!(self.grid_block_revs[block_index].start_row_index, start_row_index);
}
EditorScript::AssertBlockEqual { block_index, block } => {
let blocks = self.editor.get_block_metas().await.unwrap();
let blocks = self.editor.get_block_meta_revs().await.unwrap();
let compared_block = blocks[block_index].clone();
assert_eq!(compared_block, block);
}
@ -197,7 +197,7 @@ impl GridEditorTest {
let row_order = self.editor.create_row(None).await.unwrap();
self.row_order_by_row_id.insert(row_order.row_id.clone(), row_order);
self.row_revs = self.get_row_revs().await;
self.grid_block_revs = self.editor.get_block_metas().await.unwrap();
self.grid_block_revs = self.editor.get_block_meta_revs().await.unwrap();
}
EditorScript::CreateRow { payload: context } => {
let row_orders = self.editor.insert_rows(vec![context]).await.unwrap();
@ -205,7 +205,7 @@ impl GridEditorTest {
self.row_order_by_row_id.insert(row_order.row_id.clone(), row_order);
}
self.row_revs = self.get_row_revs().await;
self.grid_block_revs = self.editor.get_block_metas().await.unwrap();
self.grid_block_revs = self.editor.get_block_meta_revs().await.unwrap();
}
EditorScript::UpdateRow { changeset: change } => self.editor.update_row(change).await.unwrap(),
EditorScript::DeleteRows { row_ids } => {
@ -216,7 +216,7 @@ impl GridEditorTest {
self.editor.delete_rows(row_orders).await.unwrap();
self.row_revs = self.get_row_revs().await;
self.grid_block_revs = self.editor.get_block_metas().await.unwrap();
self.grid_block_revs = self.editor.get_block_meta_revs().await.unwrap();
}
EditorScript::AssertRow { expected_row } => {
let row = &*self

View File

@ -30,7 +30,7 @@ pub fn gen_field_id() -> String {
pub struct GridRevision {
pub grid_id: String,
pub fields: Vec<FieldRevision>,
pub blocks: Vec<Arc<GridBlockRevision>>,
pub blocks: Vec<Arc<GridBlockMetaRevision>>,
#[serde(default)]
pub setting: GridSettingRevision,
@ -57,13 +57,13 @@ impl GridRevision {
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct GridBlockRevision {
pub struct GridBlockMetaRevision {
pub block_id: String,
pub start_row_index: i32,
pub row_count: i32,
}
impl GridBlockRevision {
impl GridBlockMetaRevision {
pub fn len(&self) -> i32 {
self.row_count
}
@ -73,22 +73,22 @@ impl GridBlockRevision {
}
}
impl GridBlockRevision {
impl GridBlockMetaRevision {
pub fn new() -> Self {
GridBlockRevision {
GridBlockMetaRevision {
block_id: gen_block_id(),
..Default::default()
}
}
}
pub struct GridBlockRevisionChangeset {
pub struct GridBlockMetaRevisionChangeset {
pub block_id: String,
pub start_row_index: Option<i32>,
pub row_count: Option<i32>,
}
impl GridBlockRevisionChangeset {
impl GridBlockMetaRevisionChangeset {
pub fn from_row_count(block_id: &str, row_count: i32) -> Self {
Self {
block_id: block_id.to_string(),
@ -99,9 +99,9 @@ impl GridBlockRevisionChangeset {
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GridBlockRevisionData {
pub struct GridBlockRevision {
pub block_id: String,
pub rows: Vec<RowRevision>,
pub rows: Vec<Arc<RowRevision>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, Eq, PartialEq)]
@ -292,8 +292,8 @@ impl CellRevision {
#[derive(Clone, Default, Deserialize, Serialize)]
pub struct BuildGridContext {
pub field_revs: Vec<FieldRevision>,
pub blocks: Vec<GridBlockRevision>,
pub blocks_meta_data: Vec<GridBlockRevisionData>,
pub blocks: Vec<GridBlockMetaRevision>,
pub blocks_meta_data: Vec<GridBlockRevision>,
}
impl BuildGridContext {

View File

@ -2,40 +2,37 @@ use crate::entities::revision::{md5, RepeatedRevision, Revision};
use crate::errors::{CollaborateError, CollaborateResult};
use crate::util::{cal_diff, make_delta_from_revisions};
use flowy_grid_data_model::revision::{
gen_block_id, gen_row_id, CellRevision, GridBlockRevisionData, RowMetaChangeset, RowRevision,
gen_block_id, gen_row_id, CellRevision, GridBlockRevision, RowMetaChangeset, RowRevision,
};
use lib_ot::core::{OperationTransformable, PlainTextAttributes, PlainTextDelta, PlainTextDeltaBuilder};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::collections::HashMap;
use std::sync::Arc;
pub type GridBlockRevisionDelta = PlainTextDelta;
pub type GridBlockRevisionDeltaBuilder = PlainTextDeltaBuilder;
#[derive(Debug, Deserialize, Serialize, Clone)]
#[derive(Debug, Clone)]
pub struct GridBlockRevisionPad {
block_id: String,
rows: Vec<Arc<RowRevision>>,
#[serde(skip)]
block_revision: GridBlockRevision,
pub(crate) delta: GridBlockRevisionDelta,
}
impl GridBlockRevisionPad {
pub async fn duplicate_data(&self, duplicated_block_id: &str) -> GridBlockRevisionData {
pub async fn duplicate_data(&self, duplicated_block_id: &str) -> GridBlockRevision {
let duplicated_rows = self
.block_revision
.rows
.iter()
.map(|row| {
let mut duplicated_row = row.as_ref().clone();
duplicated_row.id = gen_row_id();
duplicated_row.block_id = duplicated_block_id.to_string();
duplicated_row
Arc::new(duplicated_row)
})
.collect::<Vec<RowRevision>>();
GridBlockRevisionData {
.collect::<Vec<Arc<RowRevision>>>();
GridBlockRevision {
block_id: duplicated_block_id.to_string(),
rows: duplicated_rows,
}
@ -43,18 +40,12 @@ impl GridBlockRevisionPad {
pub fn from_delta(delta: GridBlockRevisionDelta) -> CollaborateResult<Self> {
let s = delta.to_str()?;
let meta_data: GridBlockRevisionData = serde_json::from_str(&s).map_err(|e| {
let block_revision: GridBlockRevision = serde_json::from_str(&s).map_err(|e| {
let msg = format!("Deserialize delta to block meta failed: {}", e);
tracing::error!("{}", s);
CollaborateError::internal().context(msg)
})?;
let block_id = meta_data.block_id;
let rows = meta_data
.rows
.into_iter()
.map(Arc::new)
.collect::<Vec<Arc<RowRevision>>>();
Ok(Self { block_id, rows, delta })
Ok(Self { block_revision, delta })
}
pub fn from_revisions(_grid_id: &str, revisions: Vec<Revision>) -> CollaborateResult<Self> {
@ -95,9 +86,10 @@ impl GridBlockRevisionPad {
T: AsRef<str> + ToOwned + ?Sized,
{
match row_ids {
None => Ok(self.rows.to_vec()),
None => Ok(self.block_revision.rows.clone()),
Some(row_ids) => {
let row_map = self
.block_revision
.rows
.iter()
.map(|row| (row.id.as_str(), row.clone()))
@ -137,11 +129,12 @@ impl GridBlockRevisionPad {
}
pub fn number_of_rows(&self) -> i32 {
self.rows.len() as i32
self.block_revision.rows.len() as i32
}
pub fn index_of_row(&self, row_id: &str) -> Option<i32> {
self.rows
self.block_revision
.rows
.iter()
.position(|row| row.id == row_id)
.map(|index| index as i32)
@ -190,7 +183,7 @@ impl GridBlockRevisionPad {
F: for<'a> FnOnce(&'a mut Vec<Arc<RowRevision>>) -> CollaborateResult<Option<()>>,
{
let cloned_self = self.clone();
match f(&mut self.rows)? {
match f(&mut self.block_revision.rows)? {
None => Ok(None),
Some(_) => {
let old = cloned_self.to_json()?;
@ -226,7 +219,7 @@ impl GridBlockRevisionPad {
}
pub fn to_json(&self) -> CollaborateResult<String> {
serde_json::to_string(self)
serde_json::to_string(&self.block_revision)
.map_err(|e| CollaborateError::internal().context(format!("serial trash to json failed: {}", e)))
}
@ -245,12 +238,12 @@ pub struct GridBlockMetaChange {
pub md5: String,
}
pub fn make_block_meta_delta(grid_block_meta_data: &GridBlockRevisionData) -> GridBlockRevisionDelta {
let json = serde_json::to_string(&grid_block_meta_data).unwrap();
pub fn make_block_meta_delta(block_rev: &GridBlockRevision) -> GridBlockRevisionDelta {
let json = serde_json::to_string(&block_rev).unwrap();
PlainTextDeltaBuilder::new().insert(&json).build()
}
pub fn make_block_meta_revisions(user_id: &str, grid_block_meta_data: &GridBlockRevisionData) -> RepeatedRevision {
pub fn make_block_meta_revisions(user_id: &str, grid_block_meta_data: &GridBlockRevision) -> RepeatedRevision {
let delta = make_block_meta_delta(grid_block_meta_data);
let bytes = delta.to_delta_bytes();
let revision = Revision::initial_revision(user_id, &grid_block_meta_data.block_id, bytes);
@ -259,17 +252,13 @@ pub fn make_block_meta_revisions(user_id: &str, grid_block_meta_data: &GridBlock
impl std::default::Default for GridBlockRevisionPad {
fn default() -> Self {
let block_meta_data = GridBlockRevisionData {
let block_revision = GridBlockRevision {
block_id: gen_block_id(),
rows: vec![],
};
let delta = make_block_meta_delta(&block_meta_data);
GridBlockRevisionPad {
block_id: block_meta_data.block_id,
rows: block_meta_data.rows.into_iter().map(Arc::new).collect::<Vec<_>>(),
delta,
}
let delta = make_block_meta_delta(&block_revision);
GridBlockRevisionPad { block_revision, delta }
}
}

View File

@ -1,7 +1,8 @@
use crate::errors::{CollaborateError, CollaborateResult};
use flowy_grid_data_model::revision::{
BuildGridContext, FieldRevision, GridBlockRevision, GridBlockRevisionData, RowRevision,
BuildGridContext, FieldRevision, GridBlockMetaRevision, GridBlockRevision, RowRevision,
};
use std::sync::Arc;
pub struct GridBuilder {
build_context: BuildGridContext,
@ -11,8 +12,8 @@ impl std::default::Default for GridBuilder {
fn default() -> Self {
let mut build_context = BuildGridContext::new();
let block_meta = GridBlockRevision::new();
let block_meta_data = GridBlockRevisionData {
let block_meta = GridBlockMetaRevision::new();
let block_meta_data = GridBlockRevision {
block_id: block_meta.block_id.clone(),
rows: vec![],
};
@ -32,10 +33,10 @@ impl GridBuilder {
pub fn add_empty_row(mut self) -> Self {
let row = RowRevision::new(&self.build_context.blocks.first().unwrap().block_id);
let block_meta = self.build_context.blocks.first_mut().unwrap();
let block_meta_data = self.build_context.blocks_meta_data.first_mut().unwrap();
block_meta_data.rows.push(row);
block_meta.row_count += 1;
let block_meta_rev = self.build_context.blocks.first_mut().unwrap();
let block_rev = self.build_context.blocks_meta_data.first_mut().unwrap();
block_rev.rows.push(Arc::new(row));
block_meta_rev.row_count += 1;
self
}
@ -59,10 +60,10 @@ fn check_rows(fields: &[FieldRevision], rows: &[RowRevision]) -> CollaborateResu
#[cfg(test)]
mod tests {
use crate::client_grid::{make_block_meta_delta, make_grid_delta, GridBuilder};
use flowy_grid_data_model::entities::FieldType;
use flowy_grid_data_model::revision::{FieldRevision, GridBlockRevisionData, GridRevision};
use flowy_grid_data_model::revision::{FieldRevision, GridBlockRevision, GridRevision};
use std::sync::Arc;
#[test]
fn create_default_grid_test() {
@ -78,7 +79,7 @@ mod tests {
let grid_rev = GridRevision {
grid_id,
fields: build_context.field_revs,
blocks: build_context.blocks,
blocks: build_context.blocks.into_iter().map(Arc::new).collect(),
setting: Default::default(),
};
@ -86,6 +87,6 @@ mod tests {
let _: GridRevision = serde_json::from_str(&grid_meta_delta.to_str().unwrap()).unwrap();
let grid_block_meta_delta = make_block_meta_delta(build_context.blocks_meta_data.first().unwrap());
let _: GridBlockRevisionData = serde_json::from_str(&grid_block_meta_delta.to_str().unwrap()).unwrap();
let _: GridBlockRevision = serde_json::from_str(&grid_block_meta_delta.to_str().unwrap()).unwrap();
}
}

View File

@ -6,7 +6,7 @@ use flowy_grid_data_model::entities::{FieldChangesetParams, FieldOrder};
use flowy_grid_data_model::entities::{FieldType, GridSettingChangesetParams};
use flowy_grid_data_model::revision::{
gen_block_id, gen_grid_filter_id, gen_grid_group_id, gen_grid_id, gen_grid_sort_id, FieldRevision,
GridBlockRevision, GridBlockRevisionChangeset, GridFilterRevision, GridGroupRevision, GridLayoutRevision,
GridBlockMetaRevision, GridBlockMetaRevisionChangeset, GridFilterRevision, GridGroupRevision, GridLayoutRevision,
GridRevision, GridSettingRevision, GridSortRevision,
};
use lib_infra::util::move_vec_element;
@ -27,7 +27,7 @@ pub trait JsonDeserializer {
}
impl GridRevisionPad {
pub async fn duplicate_grid_meta(&self) -> (Vec<FieldRevision>, Vec<GridBlockRevision>) {
pub async fn duplicate_grid_block_meta(&self) -> (Vec<FieldRevision>, Vec<GridBlockMetaRevision>) {
let fields = self.grid_rev.fields.to_vec();
let blocks = self
@ -39,7 +39,7 @@ impl GridRevisionPad {
duplicated_block.block_id = gen_block_id();
duplicated_block
})
.collect::<Vec<GridBlockRevision>>();
.collect::<Vec<GridBlockMetaRevision>>();
(fields, blocks)
}
@ -281,7 +281,7 @@ impl GridRevisionPad {
}
}
pub fn create_block_rev(&mut self, block: GridBlockRevision) -> CollaborateResult<Option<GridChangeset>> {
pub fn create_block_meta_rev(&mut self, block: GridBlockMetaRevision) -> CollaborateResult<Option<GridChangeset>> {
self.modify_grid(|grid_meta| {
if grid_meta.blocks.iter().any(|b| b.block_id == block.block_id) {
tracing::warn!("Duplicate grid block");
@ -304,13 +304,13 @@ impl GridRevisionPad {
})
}
pub fn get_block_revs(&self) -> Vec<Arc<GridBlockRevision>> {
pub fn get_block_meta_revs(&self) -> Vec<Arc<GridBlockMetaRevision>> {
self.grid_rev.blocks.clone()
}
pub fn update_block_rev(
&mut self,
changeset: GridBlockRevisionChangeset,
changeset: GridBlockMetaRevisionChangeset,
) -> CollaborateResult<Option<GridChangeset>> {
let block_id = changeset.block_id.clone();
self.modify_block(&block_id, |block| {
@ -457,7 +457,7 @@ impl GridRevisionPad {
fn modify_block<F>(&mut self, block_id: &str, f: F) -> CollaborateResult<Option<GridChangeset>>
where
F: FnOnce(&mut GridBlockRevision) -> CollaborateResult<Option<()>>,
F: FnOnce(&mut GridBlockMetaRevision) -> CollaborateResult<Option<()>>,
{
self.modify_grid(
|grid_rev| match grid_rev.blocks.iter().position(|block| block.block_id == block_id) {