瀏覽代碼

chore: rename structs

appflowy 3 年之前
父節點
當前提交
d08f298fb6

+ 10 - 4
frontend/rust-lib/flowy-grid/src/event_handler.rs

@@ -183,16 +183,22 @@ pub(crate) async fn get_row_handler(
 pub(crate) async fn delete_row_handler(
     data: Data<RowIdentifierPayload>,
     manager: AppData<Arc<GridManager>>,
-) -> DataResult<Row, FlowyError> {
-    todo!()
+) -> Result<(), FlowyError> {
+    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)]
 pub(crate) async fn duplicate_row_handler(
     data: Data<RowIdentifierPayload>,
     manager: AppData<Arc<GridManager>>,
-) -> DataResult<Row, FlowyError> {
-    todo!()
+) -> Result<(), FlowyError> {
+    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)]

+ 5 - 5
frontend/rust-lib/flowy-grid/src/services/block_meta_manager.rs

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

+ 12 - 0
frontend/rust-lib/flowy-grid/src/services/grid_editor.rs

@@ -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> {
         let field_meta = self.get_field_meta(&params.field_id).await?;
@@ -316,6 +323,11 @@ impl ClientGridEditor {
         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<()> {
         let changesets = self.block_meta_manager.delete_rows(row_orders).await?;
         for changeset in changesets {

+ 6 - 6
frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs

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