diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart index 07e426b385..0a920639a9 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart @@ -97,11 +97,22 @@ class GridRowCache { } } - void _updateRows(List updatedRows) { + void _updateRows(List updatedRows) { if (updatedRows.isEmpty) return; + List 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 = - _rowList.updateRows(updatedRows, (rowPB) => buildGridRow(rowPB)); + _rowList.updateRows(rowPBs, (rowPB) => buildGridRow(rowPB)); if (updatedIndexs.isNotEmpty) { _rowChangeReasonNotifier.receive(RowsChangedReason.update(updatedIndexs)); } diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_detail.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_detail.dart index fc090eb914..c13ddf28ba 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_detail.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_detail.dart @@ -114,7 +114,7 @@ class _PropertyList extends StatelessWidget { builder: (context, state) { return Column( children: [ - Expanded(child: _wrapScrollbar(buildList(state))), + Expanded(child: _wrapScrollbar(buildRowCells(state))), const VSpace(10), _CreateFieldButton( viewId: viewId, @@ -126,7 +126,7 @@ class _PropertyList extends StatelessWidget { ); } - Widget buildList(RowDetailState state) { + Widget buildRowCells(RowDetailState state) { return ListView.separated( controller: _scrollController, itemCount: state.gridCells.length, diff --git a/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs index 252e5527de..25d2fb79ad 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs +++ b/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, +} + #[derive(Debug, Default, Clone, ProtoBuf)] pub struct GridBlockChangesetPB { #[pb(index = 1)] @@ -172,7 +182,7 @@ pub struct GridBlockChangesetPB { pub deleted_rows: Vec, #[pb(index = 4)] - pub updated_rows: Vec, + pub updated_rows: Vec, #[pb(index = 5)] pub visible_rows: Vec, @@ -197,7 +207,7 @@ impl GridBlockChangesetPB { } } - pub fn update(block_id: &str, updated_rows: Vec) -> Self { + pub fn update(block_id: &str, updated_rows: Vec) -> Self { Self { block_id: block_id.to_owned(), updated_rows, diff --git a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs index f84cd8af52..5c99b38418 100644 --- a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs +++ b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs @@ -1,5 +1,5 @@ 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::services::block_editor::{GridBlockRevisionCompress, GridBlockRevisionEditor}; use crate::services::persistence::block_index::BlockIndexCache; @@ -111,8 +111,12 @@ impl GridBlockManager { 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), 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::>(); + 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 .notify_did_update_block(&editor.block_id, block_order_changeset) .await?; diff --git a/shared-lib/grid-rev-model/src/grid_block.rs b/shared-lib/grid-rev-model/src/grid_block.rs index e75b2b0f37..476d493330 100644 --- a/shared-lib/grid-rev-model/src/grid_block.rs +++ b/shared-lib/grid-rev-model/src/grid_block.rs @@ -46,6 +46,8 @@ pub struct RowChangeset { pub row_id: String, pub height: Option, pub visibility: Option, + // 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, }