瀏覽代碼

fix: add new created row

appflowy 2 年之前
父節點
當前提交
bfebea7b31

+ 0 - 1
frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart

@@ -4,7 +4,6 @@ import 'package:app_flowy/plugins/grid/presentation/widgets/cell/cell_builder.da
 import 'package:flowy_infra_ui/style_widget/text.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_bloc/flutter_bloc.dart';
-
 import 'board_cell.dart';
 import 'define.dart';
 

+ 1 - 1
frontend/rust-lib/flowy-grid/src/services/block_manager.rs

@@ -107,7 +107,7 @@ impl GridBlockManager {
         let editor = self.get_editor_from_row_id(&changeset.row_id).await?;
         let _ = editor.update_row(changeset.clone()).await?;
         match editor.get_row_rev(&changeset.row_id).await? {
-            None => tracing::error!("Internal error: can't find the row with id: {}", changeset.row_id),
+            None => tracing::error!("Update row failed, can't find the row with id: {}", changeset.row_id),
             Some(row_rev) => {
                 let row_pb = make_row_from_row_rev(row_rev.clone());
                 let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![row_pb]);

+ 2 - 0
frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs

@@ -96,6 +96,8 @@ impl GridViewRevisionEditor {
                     None => Some(0),
                     Some(_) => None,
                 };
+
+                self.group_controller.write().await.did_create_row(row_pb, group_id);
                 let inserted_row = InsertedRowPB {
                     row: row_pb.clone(),
                     index,

+ 1 - 0
frontend/rust-lib/flowy-grid/src/services/group/controller.rs

@@ -15,6 +15,7 @@ use std::sync::Arc;
 // a new row.
 pub trait GroupController: GroupControllerSharedOperation + Send + Sync {
     fn will_create_row(&mut self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
+    fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str);
 }
 
 pub trait GroupGenerator {

+ 11 - 7
frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs

@@ -28,11 +28,11 @@ impl GroupAction for CheckboxGroupController {
     }
 
     fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool {
-        return if cell_data.is_check() {
+        if cell_data.is_check() {
             content == CHECK
         } else {
             content == UNCHECK
-        };
+        }
     }
 
     fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB> {
@@ -46,11 +46,9 @@ impl GroupAction for CheckboxGroupController {
                     changeset.inserted_rows.push(InsertedRowPB::new(row_pb.clone()));
                     group.add_row(row_pb);
                 }
-            } else {
-                if is_contained {
-                    changeset.deleted_rows.push(row_rev.id.clone());
-                    group.remove_row(&row_rev.id);
-                }
+            } else if is_contained {
+                changeset.deleted_rows.push(row_rev.id.clone());
+                group.remove_row(&row_rev.id);
             }
             if !changeset.is_empty() {
                 changesets.push(changeset);
@@ -97,6 +95,12 @@ impl GroupController for CheckboxGroupController {
             }
         }
     }
+
+    fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str) {
+        if let Some(group) = self.group_ctx.get_mut_group(group_id) {
+            group.add_row(row_pb.clone())
+        }
+    }
 }
 
 pub struct CheckboxGroupGenerator();

+ 2 - 0
frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs

@@ -77,4 +77,6 @@ impl GroupControllerSharedOperation for DefaultGroupController {
 
 impl GroupController for DefaultGroupController {
     fn will_create_row(&mut self, _row_rev: &mut RowRevision, _field_rev: &FieldRevision, _group_id: &str) {}
+
+    fn did_create_row(&mut self, _row_rev: &RowPB, _group_id: &str) {}
 }

+ 7 - 1
frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs

@@ -1,4 +1,4 @@
-use crate::entities::GroupChangesetPB;
+use crate::entities::{GroupChangesetPB, RowPB};
 use crate::services::cell::insert_select_option_cell;
 use crate::services::field::{MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser};
 use crate::services::group::action::GroupAction;
@@ -67,6 +67,12 @@ impl GroupController for MultiSelectGroupController {
             }
         }
     }
+
+    fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str) {
+        if let Some(group) = self.group_ctx.get_mut_group(group_id) {
+            group.add_row(row_pb.clone())
+        }
+    }
 }
 
 pub struct MultiSelectGroupGenerator();

+ 5 - 1
frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs

@@ -65,10 +65,14 @@ impl GroupController for SingleSelectGroupController {
             Some(group) => {
                 let cell_rev = insert_select_option_cell(group.id.clone(), field_rev);
                 row_rev.cells.insert(field_rev.id.clone(), cell_rev);
-                group.add_row(RowPB::from(row_rev));
             }
         }
     }
+    fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str) {
+        if let Some(group) = self.group_ctx.get_mut_group(group_id) {
+            group.add_row(row_pb.clone())
+        }
+    }
 }
 
 pub struct SingleSelectGroupGenerator();