mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Fix filter test (#1459)
* chore: move grid_view_editor.rs to view_editor folder * chore: hide invisible rows * fix: lock issue * fix: flutter test potential failed * chore: separate group tests Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
@ -13,7 +13,7 @@ class GridBlockCache {
|
||||
late GridRowCache _rowCache;
|
||||
late GridBlockListener _listener;
|
||||
|
||||
List<RowInfo> get rows => _rowCache.rows;
|
||||
List<RowInfo> get rows => _rowCache.visibleRows;
|
||||
GridRowCache get rowCache => _rowCache;
|
||||
|
||||
GridBlockCache({
|
||||
@ -30,7 +30,7 @@ class GridBlockCache {
|
||||
_listener = GridBlockListener(blockId: block.id);
|
||||
_listener.start((result) {
|
||||
result.fold(
|
||||
(changesets) => _rowCache.applyChangesets(changesets),
|
||||
(changeset) => _rowCache.applyChangesets(changeset),
|
||||
(err) => Log.error(err),
|
||||
);
|
||||
});
|
||||
|
@ -7,11 +7,12 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
|
||||
typedef GridBlockUpdateNotifierValue = Either<List<GridBlockChangesetPB>, FlowyError>;
|
||||
typedef GridBlockUpdateNotifierValue = Either<GridBlockChangesetPB, FlowyError>;
|
||||
|
||||
class GridBlockListener {
|
||||
final String blockId;
|
||||
PublishNotifier<GridBlockUpdateNotifierValue>? _rowsUpdateNotifier = PublishNotifier();
|
||||
PublishNotifier<GridBlockUpdateNotifierValue>? _rowsUpdateNotifier =
|
||||
PublishNotifier();
|
||||
GridNotificationListener? _listener;
|
||||
|
||||
GridBlockListener({required this.blockId});
|
||||
@ -29,11 +30,12 @@ class GridBlockListener {
|
||||
_rowsUpdateNotifier?.addPublishListener(onBlockChanged);
|
||||
}
|
||||
|
||||
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
void _handler(GridDartNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateGridBlock:
|
||||
case GridDartNotification.DidUpdateGridBlock:
|
||||
result.fold(
|
||||
(payload) => _rowsUpdateNotifier?.value = left([GridBlockChangesetPB.fromBuffer(payload)]),
|
||||
(payload) => _rowsUpdateNotifier?.value =
|
||||
left(GridBlockChangesetPB.fromBuffer(payload)),
|
||||
(error) => _rowsUpdateNotifier?.value = right(error),
|
||||
);
|
||||
break;
|
||||
|
@ -22,9 +22,9 @@ class CellListener {
|
||||
objectId: "$rowId:$fieldId", handler: _handler);
|
||||
}
|
||||
|
||||
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
void _handler(GridDartNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateCell:
|
||||
case GridDartNotification.DidUpdateCell:
|
||||
result.fold(
|
||||
(payload) => _updateCellNotifier?.value = left(unit),
|
||||
(error) => _updateCellNotifier?.value = right(error),
|
||||
|
@ -27,11 +27,11 @@ class SingleFieldListener {
|
||||
}
|
||||
|
||||
void _handler(
|
||||
GridNotification ty,
|
||||
GridDartNotification ty,
|
||||
Either<Uint8List, FlowyError> result,
|
||||
) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateField:
|
||||
case GridDartNotification.DidUpdateField:
|
||||
result.fold(
|
||||
(payload) =>
|
||||
_updateFieldNotifier?.value = left(FieldPB.fromBuffer(payload)),
|
||||
|
@ -25,9 +25,9 @@ class GridFieldsListener {
|
||||
);
|
||||
}
|
||||
|
||||
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
void _handler(GridDartNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateGridField:
|
||||
case GridDartNotification.DidUpdateGridField:
|
||||
result.fold(
|
||||
(payload) => updateFieldsNotifier?.value =
|
||||
left(GridFieldChangesetPB.fromBuffer(payload)),
|
||||
|
@ -4,7 +4,7 @@ import 'package:flowy_sdk/protobuf/flowy-grid/checkbox_filter.pbenum.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/date_filter.pbenum.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/number_filter.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/text_filter.pbserver.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/text_filter.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/util.pb.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
@ -114,7 +114,7 @@ class GridFilterBloc extends Bloc<GridFilterEvent, GridFilterState> {
|
||||
(element) => !deleteFilterIds.contains(element.id),
|
||||
);
|
||||
|
||||
// Inserts the new fitler if it's not exist
|
||||
// Inserts the new filter if it's not exist
|
||||
for (final newFilter in changeset.insertFilters) {
|
||||
final index =
|
||||
filters.indexWhere((element) => element.id == newFilter.id);
|
||||
|
@ -29,11 +29,11 @@ class FilterListener {
|
||||
}
|
||||
|
||||
void _handler(
|
||||
GridNotification ty,
|
||||
GridDartNotification ty,
|
||||
Either<Uint8List, FlowyError> result,
|
||||
) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateFilter:
|
||||
case GridDartNotification.DidUpdateFilter:
|
||||
result.fold(
|
||||
(payload) => _filterNotifier?.value =
|
||||
left(FilterChangesetNotificationPB.fromBuffer(payload)),
|
||||
|
@ -33,13 +33,18 @@ class GridRowCache {
|
||||
List<RowInfo> _rowInfos = [];
|
||||
|
||||
/// Use Map for faster access the raw row data.
|
||||
final HashMap<String, RowPB> _rowByRowId;
|
||||
final HashMap<String, RowInfo> _rowInfoByRowId;
|
||||
|
||||
final GridCellCache _cellCache;
|
||||
final IGridRowFieldNotifier _fieldNotifier;
|
||||
final _RowChangesetNotifier _rowChangeReasonNotifier;
|
||||
|
||||
UnmodifiableListView<RowInfo> get rows => UnmodifiableListView(_rowInfos);
|
||||
UnmodifiableListView<RowInfo> get visibleRows {
|
||||
var visibleRows = [..._rowInfos];
|
||||
visibleRows.retainWhere((element) => element.visible);
|
||||
return UnmodifiableListView(visibleRows);
|
||||
}
|
||||
|
||||
GridCellCache get cellCache => _cellCache;
|
||||
|
||||
GridRowCache({
|
||||
@ -47,7 +52,7 @@ class GridRowCache {
|
||||
required this.block,
|
||||
required IGridRowFieldNotifier notifier,
|
||||
}) : _cellCache = GridCellCache(gridId: gridId),
|
||||
_rowByRowId = HashMap(),
|
||||
_rowInfoByRowId = HashMap(),
|
||||
_rowChangeReasonNotifier = _RowChangesetNotifier(),
|
||||
_fieldNotifier = notifier {
|
||||
//
|
||||
@ -55,7 +60,12 @@ class GridRowCache {
|
||||
.receive(const RowsChangedReason.fieldDidChange()));
|
||||
notifier.onRowFieldChanged(
|
||||
(field) => _cellCache.removeCellWithFieldId(field.id));
|
||||
_rowInfos = block.rows.map((rowPB) => buildGridRow(rowPB)).toList();
|
||||
|
||||
for (final row in block.rows) {
|
||||
final rowInfo = buildGridRow(row);
|
||||
_rowInfos.add(rowInfo);
|
||||
_rowInfoByRowId[rowInfo.rowPB.id] = rowInfo;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
@ -64,14 +74,12 @@ class GridRowCache {
|
||||
await _cellCache.dispose();
|
||||
}
|
||||
|
||||
void applyChangesets(List<GridBlockChangesetPB> changesets) {
|
||||
for (final changeset in changesets) {
|
||||
_deleteRows(changeset.deletedRows);
|
||||
_insertRows(changeset.insertedRows);
|
||||
_updateRows(changeset.updatedRows);
|
||||
_hideRows(changeset.hideRows);
|
||||
_showRows(changeset.visibleRows);
|
||||
}
|
||||
void applyChangesets(GridBlockChangesetPB changeset) {
|
||||
_deleteRows(changeset.deletedRows);
|
||||
_insertRows(changeset.insertedRows);
|
||||
_updateRows(changeset.updatedRows);
|
||||
_hideRows(changeset.invisibleRows);
|
||||
_showRows(changeset.visibleRows);
|
||||
}
|
||||
|
||||
void _deleteRows(List<String> deletedRows) {
|
||||
@ -89,7 +97,7 @@ class GridRowCache {
|
||||
if (deletedRowByRowId[rowInfo.rowPB.id] == null) {
|
||||
newRows.add(rowInfo);
|
||||
} else {
|
||||
_rowByRowId.remove(rowInfo.rowPB.id);
|
||||
_rowInfoByRowId.remove(rowInfo.rowPB.id);
|
||||
deletedIndex.add(DeletedIndex(index: index, row: rowInfo));
|
||||
}
|
||||
});
|
||||
@ -109,10 +117,9 @@ class GridRowCache {
|
||||
rowId: insertRow.row.id,
|
||||
);
|
||||
insertIndexs.add(insertIndex);
|
||||
_rowInfos.insert(
|
||||
insertRow.index,
|
||||
(buildGridRow(insertRow.row)),
|
||||
);
|
||||
final rowInfo = buildGridRow(insertRow.row);
|
||||
_rowInfos.insert(insertRow.index, rowInfo);
|
||||
_rowInfoByRowId[rowInfo.rowPB.id] = rowInfo;
|
||||
}
|
||||
|
||||
_rowChangeReasonNotifier.receive(RowsChangedReason.insert(insertIndexs));
|
||||
@ -130,10 +137,11 @@ class GridRowCache {
|
||||
(rowInfo) => rowInfo.rowPB.id == rowId,
|
||||
);
|
||||
if (index != -1) {
|
||||
_rowByRowId[rowId] = updatedRow;
|
||||
final rowInfo = buildGridRow(updatedRow);
|
||||
_rowInfoByRowId[rowId] = rowInfo;
|
||||
|
||||
_rowInfos.removeAt(index);
|
||||
_rowInfos.insert(index, buildGridRow(updatedRow));
|
||||
_rowInfos.insert(index, rowInfo);
|
||||
updatedIndexs[rowId] = UpdatedIndex(index: index, rowId: rowId);
|
||||
}
|
||||
}
|
||||
@ -141,9 +149,26 @@ class GridRowCache {
|
||||
_rowChangeReasonNotifier.receive(RowsChangedReason.update(updatedIndexs));
|
||||
}
|
||||
|
||||
void _hideRows(List<String> hideRows) {}
|
||||
void _hideRows(List<String> invisibleRows) {
|
||||
for (final rowId in invisibleRows) {
|
||||
_rowInfoByRowId[rowId]?.visible = false;
|
||||
}
|
||||
|
||||
void _showRows(List<String> visibleRows) {}
|
||||
if (invisibleRows.isNotEmpty) {
|
||||
_rowChangeReasonNotifier
|
||||
.receive(const RowsChangedReason.filterDidChange());
|
||||
}
|
||||
}
|
||||
|
||||
void _showRows(List<String> visibleRows) {
|
||||
for (final rowId in visibleRows) {
|
||||
_rowInfoByRowId[rowId]?.visible = true;
|
||||
}
|
||||
if (visibleRows.isNotEmpty) {
|
||||
_rowChangeReasonNotifier
|
||||
.receive(const RowsChangedReason.filterDidChange());
|
||||
}
|
||||
}
|
||||
|
||||
void onRowsChanged(void Function(RowsChangedReason) onRowChanged) {
|
||||
_rowChangeReasonNotifier.addListener(() {
|
||||
@ -163,9 +188,10 @@ class GridRowCache {
|
||||
|
||||
notifyUpdate() {
|
||||
if (onCellUpdated != null) {
|
||||
final row = _rowByRowId[rowId];
|
||||
if (row != null) {
|
||||
final GridCellMap cellDataMap = _makeGridCells(rowId, row);
|
||||
final rowInfo = _rowInfoByRowId[rowId];
|
||||
if (rowInfo != null) {
|
||||
final GridCellMap cellDataMap =
|
||||
_makeGridCells(rowId, rowInfo.rowPB);
|
||||
onCellUpdated(cellDataMap, _rowChangeReasonNotifier.reason);
|
||||
}
|
||||
}
|
||||
@ -188,7 +214,7 @@ class GridRowCache {
|
||||
}
|
||||
|
||||
GridCellMap loadGridCells(String rowId) {
|
||||
final RowPB? data = _rowByRowId[rowId];
|
||||
final RowPB? data = _rowInfoByRowId[rowId]?.rowPB;
|
||||
if (data == null) {
|
||||
_loadRow(rowId);
|
||||
}
|
||||
@ -230,7 +256,6 @@ class GridRowCache {
|
||||
final updatedRow = optionRow.row;
|
||||
updatedRow.freeze();
|
||||
|
||||
_rowByRowId[updatedRow.id] = updatedRow;
|
||||
final index =
|
||||
_rowInfos.indexWhere((rowInfo) => rowInfo.rowPB.id == updatedRow.id);
|
||||
if (index != -1) {
|
||||
@ -238,6 +263,7 @@ class GridRowCache {
|
||||
if (_rowInfos[index].rowPB != updatedRow) {
|
||||
final rowInfo = _rowInfos.removeAt(index).copyWith(rowPB: updatedRow);
|
||||
_rowInfos.insert(index, rowInfo);
|
||||
_rowInfoByRowId[rowInfo.rowPB.id] = rowInfo;
|
||||
|
||||
// Calculate the update index
|
||||
final UpdatedIndexs updatedIndexs = UpdatedIndexs();
|
||||
@ -258,6 +284,7 @@ class GridRowCache {
|
||||
gridId: gridId,
|
||||
fields: _fieldNotifier.fields,
|
||||
rowPB: rowPB,
|
||||
visible: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -275,16 +302,18 @@ class _RowChangesetNotifier extends ChangeNotifier {
|
||||
update: (_) => notifyListeners(),
|
||||
fieldDidChange: (_) => notifyListeners(),
|
||||
initial: (_) {},
|
||||
filterDidChange: (_FilterDidChange value) => notifyListeners(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
@unfreezed
|
||||
class RowInfo with _$RowInfo {
|
||||
const factory RowInfo({
|
||||
factory RowInfo({
|
||||
required String gridId,
|
||||
required UnmodifiableListView<GridFieldContext> fields,
|
||||
required RowPB rowPB,
|
||||
required bool visible,
|
||||
}) = _RowInfo;
|
||||
}
|
||||
|
||||
@ -298,6 +327,7 @@ class RowsChangedReason with _$RowsChangedReason {
|
||||
const factory RowsChangedReason.delete(DeletedIndexs items) = _Delete;
|
||||
const factory RowsChangedReason.update(UpdatedIndexs indexs) = _Update;
|
||||
const factory RowsChangedReason.fieldDidChange() = _FieldDidChange;
|
||||
const factory RowsChangedReason.filterDidChange() = _FilterDidChange;
|
||||
const factory RowsChangedReason.initial() = InitialListState;
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,9 @@ class RowListener {
|
||||
_listener = GridNotificationListener(objectId: rowId, handler: _handler);
|
||||
}
|
||||
|
||||
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
void _handler(GridDartNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateRow:
|
||||
case GridDartNotification.DidUpdateRow:
|
||||
result.fold(
|
||||
(payload) =>
|
||||
updateRowNotifier?.value = left(RowPB.fromBuffer(payload)),
|
||||
|
@ -24,9 +24,9 @@ class SettingListener {
|
||||
_listener = GridNotificationListener(objectId: gridId, handler: _handler);
|
||||
}
|
||||
|
||||
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
void _handler(GridDartNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateGridSetting:
|
||||
case GridDartNotification.DidUpdateGridSetting:
|
||||
result.fold(
|
||||
(payload) => _updateSettingNotifier?.value = left(
|
||||
GridSettingPB.fromBuffer(payload),
|
||||
|
Reference in New Issue
Block a user