chore: rename structs

This commit is contained in:
appflowy 2022-04-09 22:42:42 +08:00
parent b93feb49c3
commit d08f298fb6
4 changed files with 33 additions and 15 deletions

View File

@ -183,16 +183,22 @@ pub(crate) async fn get_row_handler(
pub(crate) async fn delete_row_handler( pub(crate) async fn delete_row_handler(
data: Data<RowIdentifierPayload>, data: Data<RowIdentifierPayload>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> DataResult<Row, FlowyError> { ) -> Result<(), FlowyError> {
todo!() let params: RowIdentifier = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&params.grid_id)?;
let _ = editor.delete_row(&params.row_id)?;
Ok(())
} }
#[tracing::instrument(level = "debug", skip(data, manager), err)] #[tracing::instrument(level = "debug", skip(data, manager), err)]
pub(crate) async fn duplicate_row_handler( pub(crate) async fn duplicate_row_handler(
data: Data<RowIdentifierPayload>, data: Data<RowIdentifierPayload>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> DataResult<Row, FlowyError> { ) -> Result<(), FlowyError> {
todo!() let params: RowIdentifier = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&params.grid_id)?;
let _ = editor.duplicate_row(&params.row_id)?;
Ok(())
} }
#[tracing::instrument(level = "debug", skip(data, manager), err)] #[tracing::instrument(level = "debug", skip(data, manager), err)]

View File

@ -2,7 +2,7 @@ use crate::dart_notification::{send_dart_notification, GridNotification};
use crate::manager::GridUser; use crate::manager::GridUser;
use crate::services::block_meta_editor::ClientGridBlockMetaEditor; use crate::services::block_meta_editor::ClientGridBlockMetaEditor;
use crate::services::persistence::block_index::BlockIndexPersistence; use crate::services::persistence::block_index::BlockIndexPersistence;
use crate::services::row::{make_block_row_ids, make_rows_from_row_metas, GridBlockSnapshot}; use crate::services::row::{make_block_rows, make_rows_from_row_metas, GridBlockSnapshot};
use dashmap::DashMap; use dashmap::DashMap;
use flowy_error::FlowyResult; use flowy_error::FlowyResult;
@ -94,11 +94,11 @@ impl GridBlockMetaEditorManager {
pub(crate) async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<Vec<GridBlockMetaChangeset>> { pub(crate) async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<Vec<GridBlockMetaChangeset>> {
let mut changesets = vec![]; let mut changesets = vec![];
for block_row_ids in make_block_row_ids(&row_orders) { for block_row in make_block_rows(&row_orders) {
let editor = self.get_editor(&block_row_ids.block_id).await?; let editor = self.get_editor(&block_row.block_id).await?;
let row_count = editor.delete_rows(block_row_ids.row_ids).await?; let row_count = editor.delete_rows(block_row.row_ids).await?;
let changeset = GridBlockMetaChangeset::from_row_count(&block_row_ids.block_id, row_count); let changeset = GridBlockMetaChangeset::from_row_count(&block_row.block_id, row_count);
changesets.push(changeset); changesets.push(changeset);
} }

View File

@ -267,6 +267,13 @@ impl ClientGridEditor {
} }
} }
} }
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
todo!()
}
pub async fn duplicate_row(&self, row_id: &str) -> FlowyResult<()> {
todo!()
}
pub async fn get_cell(&self, params: &CellIdentifier) -> Option<Cell> { pub async fn get_cell(&self, params: &CellIdentifier) -> Option<Cell> {
let field_meta = self.get_field_meta(&params.field_id).await?; let field_meta = self.get_field_meta(&params.field_id).await?;
@ -316,6 +323,11 @@ impl ClientGridEditor {
Ok(grid_blocks) Ok(grid_blocks)
} }
// pub async fn get_field_metas<T>(&self, field_ids: Option<Vec<T>>) -> FlowyResult<Vec<FieldMeta>>
// where
// T: Into<FieldOrder>,
// {
pub async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<()> { pub async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<()> {
let changesets = self.block_meta_manager.delete_rows(row_orders).await?; let changesets = self.block_meta_manager.delete_rows(row_orders).await?;
for changeset in changesets { for changeset in changesets {

View File

@ -8,14 +8,14 @@ use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
pub(crate) struct BlockRowIds { pub(crate) struct BlockRows {
pub(crate) block_id: String, pub(crate) block_id: String,
pub(crate) row_ids: Vec<String>, pub(crate) row_ids: Vec<String>,
} }
impl BlockRowIds { impl BlockRows {
pub fn new(block_id: &str) -> Self { pub fn new(block_id: &str) -> Self {
BlockRowIds { BlockRows {
block_id: block_id.to_owned(), block_id: block_id.to_owned(),
row_ids: vec![], row_ids: vec![],
} }
@ -27,13 +27,13 @@ pub struct GridBlockSnapshot {
pub row_metas: Vec<Arc<RowMeta>>, pub row_metas: Vec<Arc<RowMeta>>,
} }
pub(crate) fn make_block_row_ids(row_orders: &[RowOrder]) -> Vec<BlockRowIds> { pub(crate) fn make_block_rows(row_orders: &[RowOrder]) -> Vec<BlockRows> {
let mut map: HashMap<&String, BlockRowIds> = HashMap::new(); let mut map: HashMap<&String, BlockRows> = HashMap::new();
row_orders.iter().for_each(|row_order| { row_orders.iter().for_each(|row_order| {
let block_id = &row_order.block_id; let block_id = &row_order.block_id;
let row_id = row_order.row_id.clone(); let row_id = row_order.row_id.clone();
map.entry(block_id) map.entry(block_id)
.or_insert_with(|| BlockRowIds::new(block_id)) .or_insert_with(|| BlockRows::new(block_id))
.row_ids .row_ids
.push(row_id); .push(row_id);
}); });