Browse Source

fix: options don't refresh after moving the card (#1536)

Co-authored-by: nathan <[email protected]>
Nathan.fooo 2 năm trước cách đây
mục cha
commit
a2f9ca2f28

+ 13 - 2
frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart

@@ -97,11 +97,22 @@ class GridRowCache {
     }
     }
   }
   }
 
 
-  void _updateRows(List<RowPB> updatedRows) {
+  void _updateRows(List<UpdatedRowPB> updatedRows) {
     if (updatedRows.isEmpty) return;
     if (updatedRows.isEmpty) return;
+    List<RowPB> rowPBs = [];
+    for (final updatedRow in updatedRows) {
+      for (final fieldId in updatedRow.fieldIds) {
+        final key = GridCellCacheKey(
+          fieldId: fieldId,
+          rowId: updatedRow.row.id,
+        );
+        _cellCache.remove(key);
+      }
+      rowPBs.add(updatedRow.row);
+    }
 
 
     final updatedIndexs =
     final updatedIndexs =
-        _rowList.updateRows(updatedRows, (rowPB) => buildGridRow(rowPB));
+        _rowList.updateRows(rowPBs, (rowPB) => buildGridRow(rowPB));
     if (updatedIndexs.isNotEmpty) {
     if (updatedIndexs.isNotEmpty) {
       _rowChangeReasonNotifier.receive(RowsChangedReason.update(updatedIndexs));
       _rowChangeReasonNotifier.receive(RowsChangedReason.update(updatedIndexs));
     }
     }

+ 2 - 2
frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_detail.dart

@@ -114,7 +114,7 @@ class _PropertyList extends StatelessWidget {
       builder: (context, state) {
       builder: (context, state) {
         return Column(
         return Column(
           children: [
           children: [
-            Expanded(child: _wrapScrollbar(buildList(state))),
+            Expanded(child: _wrapScrollbar(buildRowCells(state))),
             const VSpace(10),
             const VSpace(10),
             _CreateFieldButton(
             _CreateFieldButton(
               viewId: viewId,
               viewId: viewId,
@@ -126,7 +126,7 @@ class _PropertyList extends StatelessWidget {
     );
     );
   }
   }
 
 
-  Widget buildList(RowDetailState state) {
+  Widget buildRowCells(RowDetailState state) {
     return ListView.separated(
     return ListView.separated(
       controller: _scrollController,
       controller: _scrollController,
       itemCount: state.gridCells.length,
       itemCount: state.gridCells.length,

+ 12 - 2
frontend/rust-lib/flowy-grid/src/entities/block_entities.rs

@@ -160,6 +160,16 @@ impl std::convert::From<&RowRevision> for InsertedRowPB {
     }
     }
 }
 }
 
 
+#[derive(Debug, Clone, Default, ProtoBuf)]
+pub struct UpdatedRowPB {
+    #[pb(index = 1)]
+    pub row: RowPB,
+
+    // represents as the cells that were updated in this row.
+    #[pb(index = 2)]
+    pub field_ids: Vec<String>,
+}
+
 #[derive(Debug, Default, Clone, ProtoBuf)]
 #[derive(Debug, Default, Clone, ProtoBuf)]
 pub struct GridBlockChangesetPB {
 pub struct GridBlockChangesetPB {
     #[pb(index = 1)]
     #[pb(index = 1)]
@@ -172,7 +182,7 @@ pub struct GridBlockChangesetPB {
     pub deleted_rows: Vec<String>,
     pub deleted_rows: Vec<String>,
 
 
     #[pb(index = 4)]
     #[pb(index = 4)]
-    pub updated_rows: Vec<RowPB>,
+    pub updated_rows: Vec<UpdatedRowPB>,
 
 
     #[pb(index = 5)]
     #[pb(index = 5)]
     pub visible_rows: Vec<InsertedRowPB>,
     pub visible_rows: Vec<InsertedRowPB>,
@@ -197,7 +207,7 @@ impl GridBlockChangesetPB {
         }
         }
     }
     }
 
 
-    pub fn update(block_id: &str, updated_rows: Vec<RowPB>) -> Self {
+    pub fn update(block_id: &str, updated_rows: Vec<UpdatedRowPB>) -> Self {
         Self {
         Self {
             block_id: block_id.to_owned(),
             block_id: block_id.to_owned(),
             updated_rows,
             updated_rows,

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

@@ -1,5 +1,5 @@
 use crate::dart_notification::{send_dart_notification, GridDartNotification};
 use crate::dart_notification::{send_dart_notification, GridDartNotification};
-use crate::entities::{CellChangesetPB, GridBlockChangesetPB, InsertedRowPB, RowPB};
+use crate::entities::{CellChangesetPB, GridBlockChangesetPB, InsertedRowPB, RowPB, UpdatedRowPB};
 use crate::manager::GridUser;
 use crate::manager::GridUser;
 use crate::services::block_editor::{GridBlockRevisionCompress, GridBlockRevisionEditor};
 use crate::services::block_editor::{GridBlockRevisionCompress, GridBlockRevisionEditor};
 use crate::services::persistence::block_index::BlockIndexCache;
 use crate::services::persistence::block_index::BlockIndexCache;
@@ -111,8 +111,12 @@ impl GridBlockManager {
         match editor.get_row_rev(&changeset.row_id).await? {
         match editor.get_row_rev(&changeset.row_id).await? {
             None => tracing::error!("Update row failed, 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)) => {
             Some((_, row_rev)) => {
-                let row_pb = make_row_from_row_rev(row_rev);
-                let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![row_pb]);
+                let changed_field_ids = changeset.cell_by_field_id.keys().cloned().collect::<Vec<String>>();
+                let updated_row = UpdatedRowPB {
+                    row: make_row_from_row_rev(row_rev),
+                    field_ids: changed_field_ids,
+                };
+                let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![updated_row]);
                 let _ = self
                 let _ = self
                     .notify_did_update_block(&editor.block_id, block_order_changeset)
                     .notify_did_update_block(&editor.block_id, block_order_changeset)
                     .await?;
                     .await?;

+ 2 - 0
shared-lib/grid-rev-model/src/grid_block.rs

@@ -46,6 +46,8 @@ pub struct RowChangeset {
     pub row_id: String,
     pub row_id: String,
     pub height: Option<i32>,
     pub height: Option<i32>,
     pub visibility: Option<bool>,
     pub visibility: Option<bool>,
+    // Contains the key/value changes represents as the update of the cells. For example,
+    // if there is one cell was changed, then the `cell_by_field_id` will only have one key/value.
     pub cell_by_field_id: HashMap<FieldId, CellRevision>,
     pub cell_by_field_id: HashMap<FieldId, CellRevision>,
 }
 }