Skip to content

Commit a2f9ca2

Browse files
authored
fix: options don't refresh after moving the card (#1536)
Co-authored-by: nathan <[email protected]>
1 parent 72dc0b8 commit a2f9ca2

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,22 @@ class GridRowCache {
9797
}
9898
}
9999

100-
void _updateRows(List<RowPB> updatedRows) {
100+
void _updateRows(List<UpdatedRowPB> updatedRows) {
101101
if (updatedRows.isEmpty) return;
102+
List<RowPB> rowPBs = [];
103+
for (final updatedRow in updatedRows) {
104+
for (final fieldId in updatedRow.fieldIds) {
105+
final key = GridCellCacheKey(
106+
fieldId: fieldId,
107+
rowId: updatedRow.row.id,
108+
);
109+
_cellCache.remove(key);
110+
}
111+
rowPBs.add(updatedRow.row);
112+
}
102113

103114
final updatedIndexs =
104-
_rowList.updateRows(updatedRows, (rowPB) => buildGridRow(rowPB));
115+
_rowList.updateRows(rowPBs, (rowPB) => buildGridRow(rowPB));
105116
if (updatedIndexs.isNotEmpty) {
106117
_rowChangeReasonNotifier.receive(RowsChangedReason.update(updatedIndexs));
107118
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class _PropertyList extends StatelessWidget {
114114
builder: (context, state) {
115115
return Column(
116116
children: [
117-
Expanded(child: _wrapScrollbar(buildList(state))),
117+
Expanded(child: _wrapScrollbar(buildRowCells(state))),
118118
const VSpace(10),
119119
_CreateFieldButton(
120120
viewId: viewId,
@@ -126,7 +126,7 @@ class _PropertyList extends StatelessWidget {
126126
);
127127
}
128128

129-
Widget buildList(RowDetailState state) {
129+
Widget buildRowCells(RowDetailState state) {
130130
return ListView.separated(
131131
controller: _scrollController,
132132
itemCount: state.gridCells.length,

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ impl std::convert::From<&RowRevision> for InsertedRowPB {
160160
}
161161
}
162162

163+
#[derive(Debug, Clone, Default, ProtoBuf)]
164+
pub struct UpdatedRowPB {
165+
#[pb(index = 1)]
166+
pub row: RowPB,
167+
168+
// represents as the cells that were updated in this row.
169+
#[pb(index = 2)]
170+
pub field_ids: Vec<String>,
171+
}
172+
163173
#[derive(Debug, Default, Clone, ProtoBuf)]
164174
pub struct GridBlockChangesetPB {
165175
#[pb(index = 1)]
@@ -172,7 +182,7 @@ pub struct GridBlockChangesetPB {
172182
pub deleted_rows: Vec<String>,
173183

174184
#[pb(index = 4)]
175-
pub updated_rows: Vec<RowPB>,
185+
pub updated_rows: Vec<UpdatedRowPB>,
176186

177187
#[pb(index = 5)]
178188
pub visible_rows: Vec<InsertedRowPB>,
@@ -197,7 +207,7 @@ impl GridBlockChangesetPB {
197207
}
198208
}
199209

200-
pub fn update(block_id: &str, updated_rows: Vec<RowPB>) -> Self {
210+
pub fn update(block_id: &str, updated_rows: Vec<UpdatedRowPB>) -> Self {
201211
Self {
202212
block_id: block_id.to_owned(),
203213
updated_rows,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::dart_notification::{send_dart_notification, GridDartNotification};
2-
use crate::entities::{CellChangesetPB, GridBlockChangesetPB, InsertedRowPB, RowPB};
2+
use crate::entities::{CellChangesetPB, GridBlockChangesetPB, InsertedRowPB, RowPB, UpdatedRowPB};
33
use crate::manager::GridUser;
44
use crate::services::block_editor::{GridBlockRevisionCompress, GridBlockRevisionEditor};
55
use crate::services::persistence::block_index::BlockIndexCache;
@@ -111,8 +111,12 @@ impl GridBlockManager {
111111
match editor.get_row_rev(&changeset.row_id).await? {
112112
None => tracing::error!("Update row failed, can't find the row with id: {}", changeset.row_id),
113113
Some((_, row_rev)) => {
114-
let row_pb = make_row_from_row_rev(row_rev);
115-
let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![row_pb]);
114+
let changed_field_ids = changeset.cell_by_field_id.keys().cloned().collect::<Vec<String>>();
115+
let updated_row = UpdatedRowPB {
116+
row: make_row_from_row_rev(row_rev),
117+
field_ids: changed_field_ids,
118+
};
119+
let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![updated_row]);
116120
let _ = self
117121
.notify_did_update_block(&editor.block_id, block_order_changeset)
118122
.await?;

shared-lib/grid-rev-model/src/grid_block.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub struct RowChangeset {
4646
pub row_id: String,
4747
pub height: Option<i32>,
4848
pub visibility: Option<bool>,
49+
// Contains the key/value changes represents as the update of the cells. For example,
50+
// if there is one cell was changed, then the `cell_by_field_id` will only have one key/value.
4951
pub cell_by_field_id: HashMap<FieldId, CellRevision>,
5052
}
5153

0 commit comments

Comments
 (0)