From 08b9930510f98832abe276aa8d5fb7a7dc51e214 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 11 Aug 2022 13:25:55 +0800 Subject: [PATCH] refactor: prefer namespace isolation, remove Grid keyword in some structs --- .../plugins/board/application/board_bloc.dart | 22 +-- .../application/board_data_controller.dart | 126 ++++++++++++++++++ .../lib/plugins/board/application/group.dart | 4 +- .../board/presentation/board_page.dart | 2 +- .../lib/plugins/board/presentation/card.dart | 2 +- .../grid/application/block/block_cache.dart | 6 +- .../cell_service/cell_field_notifier.dart | 2 +- .../cell/cell_service/cell_service.dart | 2 +- .../cell/cell_service/context_builder.dart | 6 +- .../grid/application/cell/date_cell_bloc.dart | 17 ++- .../field/field_action_sheet_bloc.dart | 14 +- .../grid/application/field/field_cache.dart | 34 ++--- .../application/field/field_cell_bloc.dart | 4 +- .../application/field/field_editor_bloc.dart | 6 +- .../application/field/field_listener.dart | 11 +- .../grid/application/field/field_service.dart | 6 +- .../field/field_type_option_edit_bloc.dart | 6 +- .../grid/application/field/grid_listener.dart | 11 +- .../type_option/type_option_context.dart | 4 +- .../type_option_data_controller.dart | 12 +- .../plugins/grid/application/grid_bloc.dart | 16 +-- .../application/grid_data_controller.dart | 12 +- .../grid/application/grid_header_bloc.dart | 14 +- .../grid/application/grid_service.dart | 9 +- .../lib/plugins/grid/application/prelude.dart | 4 +- .../row/row_action_sheet_bloc.dart | 7 +- .../grid/application/row/row_bloc.dart | 14 +- .../grid/application/row/row_cache.dart | 75 +++++------ .../application/row/row_data_controller.dart | 4 +- .../grid/application/row/row_listener.dart | 10 +- .../grid/application/row/row_service.dart | 8 +- .../application/setting/property_bloc.dart | 10 +- .../plugins/grid/presentation/grid_page.dart | 6 +- .../grid/presentation/layout/layout.dart | 10 +- .../widgets/header/field_cell.dart | 2 +- .../header/field_type_option_editor.dart | 4 +- .../widgets/header/grid_header.dart | 2 +- .../widgets/header/type_option/builder.dart | 2 +- .../presentation/widgets/row/grid_row.dart | 2 +- .../widgets/row/row_action_sheet.dart | 2 +- .../widgets/toolbar/grid_property.dart | 2 +- .../widgets/emoji_picker/src/emoji_lists.dart | 2 +- .../flowy-grid/src/entities/block_entities.rs | 56 ++++---- .../flowy-grid/src/entities/field_entities.rs | 110 +++++++-------- .../flowy-grid/src/entities/grid_entities.rs | 6 +- .../src/entities/group_entities/group.rs | 4 +- .../flowy-grid/src/entities/row_entities.rs | 10 +- .../rust-lib/flowy-grid/src/event_handler.rs | 28 ++-- frontend/rust-lib/flowy-grid/src/event_map.rs | 22 +-- .../flowy-grid/src/services/block_manager.rs | 13 +- .../src/services/block_revision_editor.rs | 10 +- .../src/services/field/field_builder.rs | 4 +- .../flowy-grid/src/services/grid_editor.rs | 32 ++--- .../flowy-grid/src/services/row/row_loader.rs | 26 ++-- .../tests/grid/block_test/script.rs | 4 +- .../flowy-grid/tests/grid/field_test/util.rs | 4 +- .../flowy-grid/tests/grid/grid_editor.rs | 2 +- 57 files changed, 493 insertions(+), 352 deletions(-) create mode 100644 frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart diff --git a/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart b/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart index 5bf941ef99..5c2072d2f1 100644 --- a/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart +++ b/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart @@ -56,7 +56,7 @@ class BoardBloc extends Bloc { didReceiveGridUpdate: (GridPB grid) { emit(state.copyWith(grid: Some(grid))); }, - groupByField: (GridFieldPB field) { + groupByField: (FieldPB field) { emit(state.copyWith(groupField: Some(field))); }, ); @@ -95,12 +95,12 @@ class BoardBloc extends Bloc { ); } - void _buildColumnItems(List rowInfos) { + void _buildColumnItems(List rowInfos) { for (final rowInfo in rowInfos) {} } - void _buildColumns(UnmodifiableListView fields) { - GridFieldPB? groupField; + void _buildColumns(UnmodifiableListView fields) { + FieldPB? groupField; for (final field in fields) { if (field.fieldType == FieldType.SingleSelect) { groupField = field; @@ -112,7 +112,7 @@ class BoardBloc extends Bloc { add(BoardEvent.groupByField(groupField!)); } - void _buildColumnsFromSingleSelect(GridFieldPB field) { + void _buildColumnsFromSingleSelect(FieldPB field) { final typeOptionContext = makeTypeOptionContext( gridId: _gridDataController.gridId, field: field, @@ -151,7 +151,7 @@ class BoardBloc extends Bloc { class BoardEvent with _$BoardEvent { const factory BoardEvent.initial() = InitialGrid; const factory BoardEvent.createRow() = _CreateRow; - const factory BoardEvent.groupByField(GridFieldPB field) = _GroupByField; + const factory BoardEvent.groupByField(FieldPB field) = _GroupByField; const factory BoardEvent.didReceiveGridUpdate( GridPB grid, ) = _DidReceiveGridUpdate; @@ -162,8 +162,8 @@ class BoardState with _$BoardState { const factory BoardState({ required String gridId, required Option grid, - required Option groupField, - required List rowInfos, + required Option groupField, + required List rowInfos, required GridLoadingState loadingState, }) = _BoardState; @@ -184,9 +184,9 @@ class GridLoadingState with _$GridLoadingState { } class GridFieldEquatable extends Equatable { - final UnmodifiableListView _fields; + final UnmodifiableListView _fields; const GridFieldEquatable( - UnmodifiableListView fields, + UnmodifiableListView fields, ) : _fields = fields; @override @@ -203,7 +203,7 @@ class GridFieldEquatable extends Equatable { ]; } - UnmodifiableListView get value => UnmodifiableListView(_fields); + UnmodifiableListView get value => UnmodifiableListView(_fields); } class TextItem extends ColumnItem { diff --git a/frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart b/frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart new file mode 100644 index 0000000000..d52b516663 --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart @@ -0,0 +1,126 @@ +// import 'dart:collection'; + +// import 'package:flowy_sdk/log.dart'; +// import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +// import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; +// import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart'; +// import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; +// import 'package:flowy_sdk/protobuf/flowy-grid/grid_entities.pb.dart'; +// import 'dart:async'; +// import 'package:dartz/dartz.dart'; + +// typedef OnFieldsChanged = void Function(UnmodifiableListView); +// typedef OnGridChanged = void Function(GridPB); + +// typedef OnRowsChanged = void Function( +// List rowInfos, +// GridRowChangeReason, +// ); +// typedef ListenONRowChangedCondition = bool Function(); + +// class GridDataController { +// final String gridId; +// final GridService _gridFFIService; +// final GridFieldCache fieldCache; + +// // key: the block id +// final LinkedHashMap _blocks; +// UnmodifiableMapView get blocks => +// UnmodifiableMapView(_blocks); + +// OnRowsChanged? _onRowChanged; +// OnFieldsChanged? _onFieldsChanged; +// OnGridChanged? _onGridChanged; + +// List get rowInfos { +// final List rows = []; +// for (var block in _blocks.values) { +// rows.addAll(block.rows); +// } +// return rows; +// } + +// GridDataController({required ViewPB view}) +// : gridId = view.id, +// _blocks = LinkedHashMap.identity(), +// _gridFFIService = GridService(gridId: view.id), +// fieldCache = GridFieldCache(gridId: view.id); + +// void addListener({ +// required OnGridChanged onGridChanged, +// required OnRowsChanged onRowsChanged, +// required OnFieldsChanged onFieldsChanged, +// }) { +// _onGridChanged = onGridChanged; +// _onRowChanged = onRowsChanged; +// _onFieldsChanged = onFieldsChanged; + +// fieldCache.addListener(onFields: (fields) { +// _onFieldsChanged?.call(UnmodifiableListView(fields)); +// }); +// } + +// Future> loadData() async { +// final result = await _gridFFIService.loadGrid(); +// return Future( +// () => result.fold( +// (grid) async { +// _initialBlocks(grid.blocks); +// _onGridChanged?.call(grid); +// return await _loadFields(grid); +// }, +// (err) => right(err), +// ), +// ); +// } + +// void createRow() { +// _gridFFIService.createRow(); +// } + +// Future dispose() async { +// await _gridFFIService.closeGrid(); +// await fieldCache.dispose(); + +// for (final blockCache in _blocks.values) { +// blockCache.dispose(); +// } +// } + +// void _initialBlocks(List blocks) { +// for (final block in blocks) { +// if (_blocks[block.id] != null) { +// Log.warn("Initial duplicate block's cache: ${block.id}"); +// return; +// } + +// final cache = GridBlockCache( +// gridId: gridId, +// block: block, +// fieldCache: fieldCache, +// ); + +// cache.addListener( +// onChangeReason: (reason) { +// _onRowChanged?.call(rowInfos, reason); +// }, +// ); + +// _blocks[block.id] = cache; +// } +// } + +// Future> _loadFields(GridPB grid) async { +// final result = await _gridFFIService.getFields(fieldIds: grid.fields); +// return Future( +// () => result.fold( +// (fields) { +// fieldCache.fields = fields.items; +// _onFieldsChanged?.call(UnmodifiableListView(fieldCache.fields)); +// return left(unit); +// }, +// (err) => right(err), +// ), +// ); +// } +// } diff --git a/frontend/app_flowy/lib/plugins/board/application/group.dart b/frontend/app_flowy/lib/plugins/board/application/group.dart index 98f11b6b35..1e59350826 100644 --- a/frontend/app_flowy/lib/plugins/board/application/group.dart +++ b/frontend/app_flowy/lib/plugins/board/application/group.dart @@ -2,11 +2,11 @@ import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; class BoardGroupService { final String gridId; - GridFieldPB? groupField; + FieldPB? groupField; BoardGroupService(this.gridId); - void setGroupField(GridFieldPB field) { + void setGroupField(FieldPB field) { groupField = field; } } diff --git a/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart b/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart index 1155168e70..60b788ae6d 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart @@ -88,7 +88,7 @@ class BoardContent extends StatelessWidget { } Widget _buildCard(BuildContext context, ColumnItem item) { - final rowInfo = item as GridRowInfo; + final rowInfo = item as RowInfo; return AppFlowyColumnItemCard( key: ObjectKey(item), child: BoardCard(rowInfo: rowInfo), diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card.dart b/frontend/app_flowy/lib/plugins/board/presentation/card.dart index b98739eea8..0511b96b03 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/card.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/card.dart @@ -2,7 +2,7 @@ import 'package:app_flowy/plugins/grid/application/row/row_cache.dart'; import 'package:flutter/material.dart'; class BoardCard extends StatelessWidget { - final GridRowInfo rowInfo; + final RowInfo rowInfo; const BoardCard({required this.rowInfo, Key? key}) : super(key: key); diff --git a/frontend/app_flowy/lib/plugins/grid/application/block/block_cache.dart b/frontend/app_flowy/lib/plugins/grid/application/block/block_cache.dart index 5569311228..ecfea7e119 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/block/block_cache.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/block/block_cache.dart @@ -9,11 +9,11 @@ import 'block_listener.dart'; /// Read https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid for more information class GridBlockCache { final String gridId; - final GridBlockPB block; + final BlockPB block; late GridRowCache _rowCache; late GridBlockListener _listener; - List get rows => _rowCache.rows; + List get rows => _rowCache.rows; GridRowCache get rowCache => _rowCache; GridBlockCache({ @@ -42,7 +42,7 @@ class GridBlockCache { } void addListener({ - required void Function(GridRowChangeReason) onChangeReason, + required void Function(RowChangeReason) onChangeReason, bool Function()? listenWhen, }) { _rowCache.onRowsChanged((reason) { diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_field_notifier.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_field_notifier.dart index 1b2393671c..d4cca373bc 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_field_notifier.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_field_notifier.dart @@ -4,7 +4,7 @@ import 'package:flutter/foundation.dart'; import 'cell_service.dart'; abstract class IGridCellFieldNotifier { - void onCellFieldChanged(void Function(GridFieldPB) callback); + void onCellFieldChanged(void Function(FieldPB) callback); void onCellDispose(); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_service.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_service.dart index 7dc15a01ee..bb750b4b89 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_service.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_service.dart @@ -60,7 +60,7 @@ class GridCellIdentifier with _$GridCellIdentifier { const factory GridCellIdentifier({ required String gridId, required String rowId, - required GridFieldPB field, + required FieldPB field, }) = _GridCellIdentifier; // ignore: unused_element diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart index 09564b46b0..b7c68a7937 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart @@ -166,7 +166,7 @@ class IGridCellController extends Equatable { String get fieldId => cellId.field.id; - GridFieldPB get field => cellId.field; + FieldPB get field => cellId.field; FieldType get fieldType => cellId.field.fieldType; @@ -321,8 +321,8 @@ class GridCellFieldNotifierImpl extends IGridCellFieldNotifier { } @override - void onCellFieldChanged(void Function(GridFieldPB p1) callback) { - _onChangesetFn = (GridFieldChangesetPB changeset) { + void onCellFieldChanged(void Function(FieldPB p1) callback) { + _onChangesetFn = (FieldChangesetPB changeset) { for (final updatedField in changeset.updatedFields) { callback(updatedField); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/date_cell_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/date_cell_bloc.dart index c4f79f1f90..fdc0ad1082 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/cell/date_cell_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/cell/date_cell_bloc.dart @@ -10,15 +10,18 @@ class DateCellBloc extends Bloc { final GridDateCellController cellContext; void Function()? _onCellChangedFn; - DateCellBloc({required this.cellContext}) : super(DateCellState.initial(cellContext)) { + DateCellBloc({required this.cellContext}) + : super(DateCellState.initial(cellContext)) { on( (event, emit) async { event.when( initial: () => _startListening(), didReceiveCellUpdate: (DateCellDataPB? cellData) { - emit(state.copyWith(data: cellData, dateStr: _dateStrFromCellData(cellData))); + emit(state.copyWith( + data: cellData, dateStr: _dateStrFromCellData(cellData))); }, - didReceiveFieldUpdate: (GridFieldPB value) => emit(state.copyWith(field: value)), + didReceiveFieldUpdate: (FieldPB value) => + emit(state.copyWith(field: value)), ); }, ); @@ -48,8 +51,10 @@ class DateCellBloc extends Bloc { @freezed class DateCellEvent with _$DateCellEvent { const factory DateCellEvent.initial() = _InitialCell; - const factory DateCellEvent.didReceiveCellUpdate(DateCellDataPB? data) = _DidReceiveCellUpdate; - const factory DateCellEvent.didReceiveFieldUpdate(GridFieldPB field) = _DidReceiveFieldUpdate; + const factory DateCellEvent.didReceiveCellUpdate(DateCellDataPB? data) = + _DidReceiveCellUpdate; + const factory DateCellEvent.didReceiveFieldUpdate(FieldPB field) = + _DidReceiveFieldUpdate; } @freezed @@ -57,7 +62,7 @@ class DateCellState with _$DateCellState { const factory DateCellState({ required DateCellDataPB? data, required String dateStr, - required GridFieldPB field, + required FieldPB field, }) = _DateCellState; factory DateCellState.initial(GridDateCellController context) { diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/field_action_sheet_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/field/field_action_sheet_bloc.dart index 3caef12f73..52b3d3368e 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/field_action_sheet_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/field_action_sheet_bloc.dart @@ -7,11 +7,13 @@ import 'field_service.dart'; part 'field_action_sheet_bloc.freezed.dart'; -class FieldActionSheetBloc extends Bloc { +class FieldActionSheetBloc + extends Bloc { final FieldService fieldService; - FieldActionSheetBloc({required GridFieldPB field, required this.fieldService}) - : super(FieldActionSheetState.initial(FieldTypeOptionDataPB.create()..field_2 = field)) { + FieldActionSheetBloc({required FieldPB field, required this.fieldService}) + : super(FieldActionSheetState.initial( + FieldTypeOptionDataPB.create()..field_2 = field)) { on( (event, emit) async { await event.map( @@ -57,7 +59,8 @@ class FieldActionSheetBloc extends Bloc FieldActionSheetState( + factory FieldActionSheetState.initial(FieldTypeOptionDataPB data) => + FieldActionSheetState( fieldTypeOptionData: data, errorText: '', fieldName: data.field_2.name, diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/field_cache.dart b/frontend/app_flowy/lib/plugins/grid/application/field/field_cache.dart index 9597c871c1..e521f097ee 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/field_cache.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/field_cache.dart @@ -8,18 +8,18 @@ import 'package:flutter/foundation.dart'; import '../row/row_cache.dart'; class FieldsNotifier extends ChangeNotifier { - List _fields = []; + List _fields = []; - set fields(List fields) { + set fields(List fields) { _fields = fields; notifyListeners(); } - List get fields => _fields; + List get fields => _fields; } -typedef FieldChangesetCallback = void Function(GridFieldChangesetPB); -typedef FieldsCallback = void Function(List); +typedef FieldChangesetCallback = void Function(FieldChangesetPB); +typedef FieldsCallback = void Function(List); class GridFieldCache { final String gridId; @@ -52,12 +52,12 @@ class GridFieldCache { _fieldNotifier = null; } - UnmodifiableListView get unmodifiableFields => + UnmodifiableListView get unmodifiableFields => UnmodifiableListView(_fieldNotifier?.fields ?? []); - List get fields => [..._fieldNotifier?.fields ?? []]; + List get fields => [..._fieldNotifier?.fields ?? []]; - set fields(List fields) { + set fields(List fields) { _fieldNotifier?.fields = [...fields]; } @@ -106,12 +106,12 @@ class GridFieldCache { } } - void _deleteFields(List deletedFields) { + void _deleteFields(List deletedFields) { if (deletedFields.isEmpty) { return; } - final List newFields = fields; - final Map deletedFieldMap = { + final List newFields = fields; + final Map deletedFieldMap = { for (var fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder }; @@ -123,7 +123,7 @@ class GridFieldCache { if (insertedFields.isEmpty) { return; } - final List newFields = fields; + final List newFields = fields; for (final indexField in insertedFields) { if (newFields.length > indexField.index) { newFields.insert(indexField.index, indexField.field_1); @@ -134,11 +134,11 @@ class GridFieldCache { _fieldNotifier?.fields = newFields; } - void _updateFields(List updatedFields) { + void _updateFields(List updatedFields) { if (updatedFields.isEmpty) { return; } - final List newFields = fields; + final List newFields = fields; for (final updatedField in updatedFields) { final index = newFields.indexWhere((field) => field.id == updatedField.id); @@ -158,7 +158,7 @@ class GridRowFieldNotifierImpl extends IGridRowFieldNotifier { GridRowFieldNotifierImpl(GridFieldCache cache) : _cache = cache; @override - UnmodifiableListView get fields => _cache.unmodifiableFields; + UnmodifiableListView get fields => _cache.unmodifiableFields; @override void onRowFieldsChanged(VoidCallback callback) { @@ -167,8 +167,8 @@ class GridRowFieldNotifierImpl extends IGridRowFieldNotifier { } @override - void onRowFieldChanged(void Function(GridFieldPB) callback) { - _onChangesetFn = (GridFieldChangesetPB changeset) { + void onRowFieldChanged(void Function(FieldPB) callback) { + _onChangesetFn = (FieldChangesetPB changeset) { for (final updatedField in changeset.updatedFields) { callback(updatedField); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/field_cell_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/field/field_cell_bloc.dart index ce09ba20bf..43114036c1 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/field_cell_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/field_cell_bloc.dart @@ -63,7 +63,7 @@ class FieldCellBloc extends Bloc { @freezed class FieldCellEvent with _$FieldCellEvent { const factory FieldCellEvent.initial() = _InitialCell; - const factory FieldCellEvent.didReceiveFieldUpdate(GridFieldPB field) = + const factory FieldCellEvent.didReceiveFieldUpdate(FieldPB field) = _DidReceiveFieldUpdate; const factory FieldCellEvent.startUpdateWidth(double offset) = _StartUpdateWidth; @@ -74,7 +74,7 @@ class FieldCellEvent with _$FieldCellEvent { class FieldCellState with _$FieldCellState { const factory FieldCellState({ required String gridId, - required GridFieldPB field, + required FieldPB field, required double width, }) = _FieldCellState; diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/field_editor_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/field/field_editor_bloc.dart index fc80964a87..aa40e98e92 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/field_editor_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/field_editor_bloc.dart @@ -34,7 +34,7 @@ class FieldEditorBloc extends Bloc { dataController.fieldName = name; emit(state.copyWith(name: name)); }, - didReceiveFieldChanged: (GridFieldPB field) { + didReceiveFieldChanged: (FieldPB field) { emit(state.copyWith(field: Some(field))); }, ); @@ -52,7 +52,7 @@ class FieldEditorBloc extends Bloc { class FieldEditorEvent with _$FieldEditorEvent { const factory FieldEditorEvent.initial() = _InitialField; const factory FieldEditorEvent.updateName(String name) = _UpdateName; - const factory FieldEditorEvent.didReceiveFieldChanged(GridFieldPB field) = + const factory FieldEditorEvent.didReceiveFieldChanged(FieldPB field) = _DidReceiveFieldChanged; } @@ -62,7 +62,7 @@ class FieldEditorState with _$FieldEditorState { required String gridId, required String errorText, required String name, - required Option field, + required Option field, }) = _FieldEditorState; factory FieldEditorState.initial( diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/field_listener.dart b/frontend/app_flowy/lib/plugins/grid/application/field/field_listener.dart index d3b35e2bfc..b1bb885ae2 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/field_listener.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/field_listener.dart @@ -7,16 +7,18 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; -typedef UpdateFieldNotifiedValue = Either; +typedef UpdateFieldNotifiedValue = Either; class SingleFieldListener { final String fieldId; - PublishNotifier? _updateFieldNotifier = PublishNotifier(); + PublishNotifier? _updateFieldNotifier = + PublishNotifier(); GridNotificationListener? _listener; SingleFieldListener({required this.fieldId}); - void start({required void Function(UpdateFieldNotifiedValue) onFieldChanged}) { + void start( + {required void Function(UpdateFieldNotifiedValue) onFieldChanged}) { _updateFieldNotifier?.addPublishListener(onFieldChanged); _listener = GridNotificationListener( objectId: fieldId, @@ -31,7 +33,8 @@ class SingleFieldListener { switch (ty) { case GridNotification.DidUpdateField: result.fold( - (payload) => _updateFieldNotifier?.value = left(GridFieldPB.fromBuffer(payload)), + (payload) => + _updateFieldNotifier?.value = left(FieldPB.fromBuffer(payload)), (error) => _updateFieldNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/field_service.dart b/frontend/app_flowy/lib/plugins/grid/application/field/field_service.dart index 39cdccb9ab..aca65dbc80 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/field_service.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/field_service.dart @@ -73,7 +73,7 @@ class FieldService { // Create the field if it does not exist. Otherwise, update the field. static Future> insertField({ required String gridId, - required GridFieldPB field, + required FieldPB field, List? typeOptionData, String? startFieldId, }) { @@ -121,7 +121,7 @@ class FieldService { Future> getFieldTypeOptionData({ required FieldType fieldType, }) { - final payload = GridFieldTypeOptionIdPB.create() + final payload = FieldTypeOptionIdPB.create() ..gridId = gridId ..fieldId = fieldId ..fieldType = fieldType; @@ -138,6 +138,6 @@ class FieldService { class GridFieldCellContext with _$GridFieldCellContext { const factory GridFieldCellContext({ required String gridId, - required GridFieldPB field, + required FieldPB field, }) = _GridFieldCellContext; } diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/field_type_option_edit_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/field/field_type_option_edit_bloc.dart index 5aa380cd72..254a371654 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/field_type_option_edit_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/field_type_option_edit_bloc.dart @@ -42,14 +42,14 @@ class FieldTypeOptionEditBloc @freezed class FieldTypeOptionEditEvent with _$FieldTypeOptionEditEvent { const factory FieldTypeOptionEditEvent.initial() = _Initial; - const factory FieldTypeOptionEditEvent.didReceiveFieldUpdated( - GridFieldPB field) = _DidReceiveFieldUpdated; + const factory FieldTypeOptionEditEvent.didReceiveFieldUpdated(FieldPB field) = + _DidReceiveFieldUpdated; } @freezed class FieldTypeOptionEditState with _$FieldTypeOptionEditState { const factory FieldTypeOptionEditState({ - required GridFieldPB field, + required FieldPB field, }) = _FieldTypeOptionEditState; factory FieldTypeOptionEditState.initial( diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/grid_listener.dart b/frontend/app_flowy/lib/plugins/grid/application/field/grid_listener.dart index 67bec17be7..61d931e43e 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/grid_listener.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/grid_listener.dart @@ -7,15 +7,17 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; -typedef UpdateFieldNotifiedValue = Either; +typedef UpdateFieldNotifiedValue = Either; class GridFieldsListener { final String gridId; - PublishNotifier? updateFieldsNotifier = PublishNotifier(); + PublishNotifier? updateFieldsNotifier = + PublishNotifier(); GridNotificationListener? _listener; GridFieldsListener({required this.gridId}); - void start({required void Function(UpdateFieldNotifiedValue) onFieldsChanged}) { + void start( + {required void Function(UpdateFieldNotifiedValue) onFieldsChanged}) { updateFieldsNotifier?.addPublishListener(onFieldsChanged); _listener = GridNotificationListener( objectId: gridId, @@ -27,7 +29,8 @@ class GridFieldsListener { switch (ty) { case GridNotification.DidUpdateGridField: result.fold( - (payload) => updateFieldsNotifier?.value = left(GridFieldChangesetPB.fromBuffer(payload)), + (payload) => updateFieldsNotifier?.value = + left(FieldChangesetPB.fromBuffer(payload)), (error) => updateFieldsNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart index e3cd38f396..9b04fcbed9 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart @@ -176,7 +176,7 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader { class FieldTypeOptionLoader extends IFieldTypeOptionLoader { @override final String gridId; - final GridFieldPB field; + final FieldPB field; FieldTypeOptionLoader({ required this.gridId, @@ -185,7 +185,7 @@ class FieldTypeOptionLoader extends IFieldTypeOptionLoader { @override Future> load() { - final payload = GridFieldTypeOptionIdPB.create() + final payload = FieldTypeOptionIdPB.create() ..gridId = gridId ..fieldId = field.id ..fieldType = field.fieldType; diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart index b28cdcdb7d..66f4c35c20 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart @@ -12,12 +12,12 @@ class TypeOptionDataController { final String gridId; final IFieldTypeOptionLoader loader; late FieldTypeOptionDataPB _data; - final PublishNotifier _fieldNotifier = PublishNotifier(); + final PublishNotifier _fieldNotifier = PublishNotifier(); TypeOptionDataController({ required this.gridId, required this.loader, - GridFieldPB? field, + FieldPB? field, }) { if (field != null) { _data = FieldTypeOptionDataPB.create() @@ -42,11 +42,11 @@ class TypeOptionDataController { ); } - GridFieldPB get field { + FieldPB get field { return _data.field_2; } - set field(GridFieldPB field) { + set field(FieldPB field) { _updateData(newField: field); } @@ -64,7 +64,7 @@ class TypeOptionDataController { void _updateData({ String? newName, - GridFieldPB? newField, + FieldPB? newField, List? newTypeOptionData, }) { _data = _data.rebuild((rebuildData) { @@ -108,7 +108,7 @@ class TypeOptionDataController { }); } - void Function() addFieldListener(void Function(GridFieldPB) callback) { + void Function() addFieldListener(void Function(FieldPB) callback) { listener() { callback(field); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/grid_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/grid_bloc.dart index 44881b9f54..73d2079a6b 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/grid_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/grid_bloc.dart @@ -97,11 +97,11 @@ class GridEvent with _$GridEvent { const factory GridEvent.initial() = InitialGrid; const factory GridEvent.createRow() = _CreateRow; const factory GridEvent.didReceiveRowUpdate( - List rows, - GridRowChangeReason listState, + List rows, + RowChangeReason listState, ) = _DidReceiveRowUpdate; const factory GridEvent.didReceiveFieldUpdate( - UnmodifiableListView fields, + UnmodifiableListView fields, ) = _DidReceiveFieldUpdate; const factory GridEvent.didReceiveGridUpdate( @@ -115,9 +115,9 @@ class GridState with _$GridState { required String gridId, required Option grid, required GridFieldEquatable fields, - required List rowInfos, + required List rowInfos, required GridLoadingState loadingState, - required GridRowChangeReason reason, + required RowChangeReason reason, }) = _GridState; factory GridState.initial(String gridId) => GridState( @@ -138,9 +138,9 @@ class GridLoadingState with _$GridLoadingState { } class GridFieldEquatable extends Equatable { - final UnmodifiableListView _fields; + final UnmodifiableListView _fields; const GridFieldEquatable( - UnmodifiableListView fields, + UnmodifiableListView fields, ) : _fields = fields; @override @@ -157,5 +157,5 @@ class GridFieldEquatable extends Equatable { ]; } - UnmodifiableListView get value => UnmodifiableListView(_fields); + UnmodifiableListView get value => UnmodifiableListView(_fields); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart index 4833bc3ae0..dcbc67e530 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart @@ -13,12 +13,12 @@ import 'field/field_cache.dart'; import 'prelude.dart'; import 'row/row_cache.dart'; -typedef OnFieldsChanged = void Function(UnmodifiableListView); +typedef OnFieldsChanged = void Function(UnmodifiableListView); typedef OnGridChanged = void Function(GridPB); typedef OnRowsChanged = void Function( - List rowInfos, - GridRowChangeReason, + List rowInfos, + RowChangeReason, ); typedef ListenONRowChangedCondition = bool Function(); @@ -36,8 +36,8 @@ class GridDataController { OnFieldsChanged? _onFieldsChanged; OnGridChanged? _onGridChanged; - List get rowInfos { - final List rows = []; + List get rowInfos { + final List rows = []; for (var block in _blocks.values) { rows.addAll(block.rows); } @@ -91,7 +91,7 @@ class GridDataController { } } - void _initialBlocks(List blocks) { + void _initialBlocks(List blocks) { for (final block in blocks) { if (_blocks[block.id] != null) { Log.warn("Initial duplicate block's cache: ${block.id}"); diff --git a/frontend/app_flowy/lib/plugins/grid/application/grid_header_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/grid_header_bloc.dart index a0ab1aa343..125bd8d652 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/grid_header_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/grid_header_bloc.dart @@ -36,7 +36,7 @@ class GridHeaderBloc extends Bloc { Future _moveField( _MoveField value, Emitter emit) async { - final fields = List.from(state.fields); + final fields = List.from(state.fields); fields.insert(value.toIndex, fields.removeAt(value.fromIndex)); emit(state.copyWith(fields: fields)); @@ -64,19 +64,19 @@ class GridHeaderBloc extends Bloc { @freezed class GridHeaderEvent with _$GridHeaderEvent { const factory GridHeaderEvent.initial() = _InitialHeader; - const factory GridHeaderEvent.didReceiveFieldUpdate( - List fields) = _DidReceiveFieldUpdate; + const factory GridHeaderEvent.didReceiveFieldUpdate(List fields) = + _DidReceiveFieldUpdate; const factory GridHeaderEvent.moveField( - GridFieldPB field, int fromIndex, int toIndex) = _MoveField; + FieldPB field, int fromIndex, int toIndex) = _MoveField; } @freezed class GridHeaderState with _$GridHeaderState { - const factory GridHeaderState({required List fields}) = + const factory GridHeaderState({required List fields}) = _GridHeaderState; - factory GridHeaderState.initial(List fields) { - // final List newFields = List.from(fields); + factory GridHeaderState.initial(List fields) { + // final List newFields = List.from(fields); // newFields.retainWhere((field) => field.visibility); return GridHeaderState(fields: fields); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/grid_service.dart b/frontend/app_flowy/lib/plugins/grid/application/grid_service.dart index 6eaaab7be8..5f95827d7e 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/grid_service.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/grid_service.dart @@ -20,18 +20,17 @@ class GridService { return GridEventGetGrid(payload).send(); } - Future> createRow( - {Option? startRowId}) { + Future> createRow({Option? startRowId}) { CreateRowPayloadPB payload = CreateRowPayloadPB.create()..gridId = gridId; startRowId?.fold(() => null, (id) => payload.startRowId = id); return GridEventCreateRow(payload).send(); } - Future> getFields( - {required List fieldIds}) { + Future> getFields( + {required List fieldIds}) { final payload = QueryFieldPayloadPB.create() ..gridId = gridId - ..fieldIds = RepeatedGridFieldIdPB(items: fieldIds); + ..fieldIds = RepeatedFieldIdPB(items: fieldIds); return GridEventGetFields(payload).send(); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/prelude.dart b/frontend/app_flowy/lib/plugins/grid/application/prelude.dart index 2a19ca1134..7585c55e49 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/prelude.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/prelude.dart @@ -4,13 +4,13 @@ export 'row/row_service.dart'; export 'grid_service.dart'; export 'grid_header_bloc.dart'; -// GridFieldPB +// FieldPB export 'field/field_service.dart'; export 'field/field_action_sheet_bloc.dart'; export 'field/field_editor_bloc.dart'; export 'field/field_type_option_edit_bloc.dart'; -// GridFieldPB Type Option +// FieldPB Type Option export 'field/type_option/date_bloc.dart'; export 'field/type_option/number_bloc.dart'; export 'field/type_option/single_select_type_option.dart'; diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart index cedd426348..0b4499682f 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart @@ -14,7 +14,7 @@ class RowActionSheetBloc extends Bloc { final RowService _rowService; - RowActionSheetBloc({required GridRowInfo rowData}) + RowActionSheetBloc({required RowInfo rowData}) : _rowService = RowService( gridId: rowData.gridId, blockId: rowData.blockId, @@ -56,11 +56,10 @@ class RowActionSheetEvent with _$RowActionSheetEvent { @freezed class RowActionSheetState with _$RowActionSheetState { const factory RowActionSheetState({ - required GridRowInfo rowData, + required RowInfo rowData, }) = _RowActionSheetState; - factory RowActionSheetState.initial(GridRowInfo rowData) => - RowActionSheetState( + factory RowActionSheetState.initial(RowInfo rowData) => RowActionSheetState( rowData: rowData, ); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart index b2579930ad..e6a68cd080 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart @@ -16,7 +16,7 @@ class RowBloc extends Bloc { final GridRowDataController _dataController; RowBloc({ - required GridRowInfo rowInfo, + required RowInfo rowInfo, required GridRowDataController dataController, }) : _rowService = RowService( gridId: rowInfo.gridId, @@ -72,19 +72,19 @@ class RowEvent with _$RowEvent { const factory RowEvent.initial() = _InitialRow; const factory RowEvent.createRow() = _CreateRow; const factory RowEvent.didReceiveCells( - GridCellMap gridCellMap, GridRowChangeReason reason) = _DidReceiveCells; + GridCellMap gridCellMap, RowChangeReason reason) = _DidReceiveCells; } @freezed class RowState with _$RowState { const factory RowState({ - required GridRowInfo rowInfo, + required RowInfo rowInfo, required GridCellMap gridCellMap, required UnmodifiableListView snapshots, - GridRowChangeReason? changeReason, + RowChangeReason? changeReason, }) = _RowState; - factory RowState.initial(GridRowInfo rowInfo, GridCellMap cellDataMap) => + factory RowState.initial(RowInfo rowInfo, GridCellMap cellDataMap) => RowState( rowInfo: rowInfo, gridCellMap: cellDataMap, @@ -94,9 +94,9 @@ class RowState with _$RowState { } class GridCellEquatable extends Equatable { - final GridFieldPB _field; + final FieldPB _field; - const GridCellEquatable(GridFieldPB field) : _field = field; + const GridCellEquatable(FieldPB field) : _field = field; @override List get props => [ 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 4f63794afc..ec212148d1 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 @@ -12,9 +12,9 @@ part 'row_cache.freezed.dart'; typedef RowUpdateCallback = void Function(); abstract class IGridRowFieldNotifier { - UnmodifiableListView get fields; + UnmodifiableListView get fields; void onRowFieldsChanged(VoidCallback callback); - void onRowFieldChanged(void Function(GridFieldPB) callback); + void onRowFieldChanged(void Function(FieldPB) callback); void onRowDispose(); } @@ -25,20 +25,20 @@ abstract class IGridRowFieldNotifier { class GridRowCache { final String gridId; - final GridBlockPB block; + final BlockPB block; /// _rows containers the current block's rows /// Use List to reverse the order of the GridRow. - List _rowInfos = []; + List _rowInfos = []; /// Use Map for faster access the raw row data. - final HashMap _rowByRowId; + final HashMap _rowByRowId; final GridCellCache _cellCache; final IGridRowFieldNotifier _fieldNotifier; - final _GridRowChangesetNotifier _rowChangeReasonNotifier; + final _RowChangesetNotifier _rowChangeReasonNotifier; - UnmodifiableListView get rows => UnmodifiableListView(_rowInfos); + UnmodifiableListView get rows => UnmodifiableListView(_rowInfos); GridCellCache get cellCache => _cellCache; GridRowCache({ @@ -47,11 +47,11 @@ class GridRowCache { required IGridRowFieldNotifier notifier, }) : _cellCache = GridCellCache(gridId: gridId), _rowByRowId = HashMap(), - _rowChangeReasonNotifier = _GridRowChangesetNotifier(), + _rowChangeReasonNotifier = _RowChangesetNotifier(), _fieldNotifier = notifier { // notifier.onRowFieldsChanged(() => _rowChangeReasonNotifier - .receive(const GridRowChangeReason.fieldDidChange())); + .receive(const RowChangeReason.fieldDidChange())); notifier.onRowFieldChanged((field) => _cellCache.remove(field.id)); _rowInfos = block.rows .map((rowInfo) => buildGridRow(rowInfo.id, rowInfo.height.toDouble())) @@ -79,7 +79,7 @@ class GridRowCache { return; } - final List newRows = []; + final List newRows = []; final DeletedIndexs deletedIndex = []; final Map deletedRowByRowId = { for (var rowId in deletedRows) rowId: rowId @@ -94,7 +94,7 @@ class GridRowCache { } }); _rowInfos = newRows; - _rowChangeReasonNotifier.receive(GridRowChangeReason.delete(deletedIndex)); + _rowChangeReasonNotifier.receive(RowChangeReason.delete(deletedIndex)); } void _insertRows(List insertRows) { @@ -113,7 +113,7 @@ class GridRowCache { (buildGridRow(insertRow.rowId, insertRow.height.toDouble()))); } - _rowChangeReasonNotifier.receive(GridRowChangeReason.insert(insertIndexs)); + _rowChangeReasonNotifier.receive(RowChangeReason.insert(insertIndexs)); } void _updateRows(List updatedRows) { @@ -135,7 +135,7 @@ class GridRowCache { } } - _rowChangeReasonNotifier.receive(GridRowChangeReason.update(updatedIndexs)); + _rowChangeReasonNotifier.receive(RowChangeReason.update(updatedIndexs)); } void _hideRows(List hideRows) {} @@ -143,7 +143,7 @@ class GridRowCache { void _showRows(List visibleRows) {} void onRowsChanged( - void Function(GridRowChangeReason) onRowChanged, + void Function(RowChangeReason) onRowChanged, ) { _rowChangeReasonNotifier.addListener(() { onRowChanged(_rowChangeReasonNotifier.reason); @@ -152,7 +152,7 @@ class GridRowCache { RowUpdateCallback addListener({ required String rowId, - void Function(GridCellMap, GridRowChangeReason)? onCellUpdated, + void Function(GridCellMap, RowChangeReason)? onCellUpdated, bool Function()? listenWhen, }) { listenerHandler() async { @@ -187,7 +187,7 @@ class GridRowCache { } GridCellMap loadGridCells(String rowId) { - final GridRowPB? data = _rowByRowId[rowId]; + final RowPB? data = _rowByRowId[rowId]; if (data == null) { _loadRow(rowId); } @@ -195,7 +195,7 @@ class GridRowCache { } Future _loadRow(String rowId) async { - final payload = GridRowIdPB.create() + final payload = RowIdPB.create() ..gridId = gridId ..blockId = block.id ..rowId = rowId; @@ -207,7 +207,7 @@ class GridRowCache { ); } - GridCellMap _makeGridCells(String rowId, GridRowPB? row) { + GridCellMap _makeGridCells(String rowId, RowPB? row) { var cellDataMap = GridCellMap.new(); for (final field in _fieldNotifier.fields) { if (field.visibility) { @@ -242,14 +242,13 @@ class GridRowCache { updatedIndexs[row.id] = UpdatedIndex(index: index, rowId: row.id); // - _rowChangeReasonNotifier - .receive(GridRowChangeReason.update(updatedIndexs)); + _rowChangeReasonNotifier.receive(RowChangeReason.update(updatedIndexs)); } } } - GridRowInfo buildGridRow(String rowId, double rowHeight) { - return GridRowInfo( + RowInfo buildGridRow(String rowId, double rowHeight) { + return RowInfo( gridId: gridId, blockId: block.id, fields: _fieldNotifier.fields, @@ -259,12 +258,12 @@ class GridRowCache { } } -class _GridRowChangesetNotifier extends ChangeNotifier { - GridRowChangeReason reason = const InitialListState(); +class _RowChangesetNotifier extends ChangeNotifier { + RowChangeReason reason = const InitialListState(); - _GridRowChangesetNotifier(); + _RowChangesetNotifier(); - void receive(GridRowChangeReason newReason) { + void receive(RowChangeReason newReason) { reason = newReason; reason.map( insert: (_) => notifyListeners(), @@ -277,15 +276,15 @@ class _GridRowChangesetNotifier extends ChangeNotifier { } @freezed -class GridRowInfo with _$GridRowInfo { - const factory GridRowInfo({ +class RowInfo with _$RowInfo { + const factory RowInfo({ required String gridId, required String blockId, required String id, - required UnmodifiableListView fields, + required UnmodifiableListView fields, required double height, - GridRowPB? rawRow, - }) = _GridRowInfo; + RowPB? rawRow, + }) = _RowInfo; } typedef InsertedIndexs = List; @@ -293,12 +292,12 @@ typedef DeletedIndexs = List; typedef UpdatedIndexs = LinkedHashMap; @freezed -class GridRowChangeReason with _$GridRowChangeReason { - const factory GridRowChangeReason.insert(InsertedIndexs items) = _Insert; - const factory GridRowChangeReason.delete(DeletedIndexs items) = _Delete; - const factory GridRowChangeReason.update(UpdatedIndexs indexs) = _Update; - const factory GridRowChangeReason.fieldDidChange() = _FieldDidChange; - const factory GridRowChangeReason.initial() = InitialListState; +class RowChangeReason with _$RowChangeReason { + const factory RowChangeReason.insert(InsertedIndexs items) = _Insert; + const factory RowChangeReason.delete(DeletedIndexs items) = _Delete; + const factory RowChangeReason.update(UpdatedIndexs indexs) = _Update; + const factory RowChangeReason.fieldDidChange() = _FieldDidChange; + const factory RowChangeReason.initial() = InitialListState; } class InsertedIndex { @@ -312,7 +311,7 @@ class InsertedIndex { class DeletedIndex { final int index; - final GridRowInfo row; + final RowInfo row; DeletedIndex({ required this.index, required this.row, diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart index 3f25e414f1..31a54aa29b 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart @@ -5,10 +5,10 @@ import '../cell/cell_service/cell_service.dart'; import '../field/field_cache.dart'; import 'row_cache.dart'; -typedef OnRowChanged = void Function(GridCellMap, GridRowChangeReason); +typedef OnRowChanged = void Function(GridCellMap, RowChangeReason); class GridRowDataController extends GridCellBuilderDelegate { - final GridRowInfo rowInfo; + final RowInfo rowInfo; final List _onRowChangedListeners = []; final GridFieldCache _fieldCache; final GridRowCache _rowCache; diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_listener.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_listener.dart index 9aa829d617..1df24c50c2 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_listener.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_listener.dart @@ -8,12 +8,13 @@ import 'dart:typed_data'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; -typedef UpdateRowNotifiedValue = Either; -typedef UpdateFieldNotifiedValue = Either, FlowyError>; +typedef UpdateRowNotifiedValue = Either; +typedef UpdateFieldNotifiedValue = Either, FlowyError>; class RowListener { final String rowId; - PublishNotifier? updateRowNotifier = PublishNotifier(); + PublishNotifier? updateRowNotifier = + PublishNotifier(); GridNotificationListener? _listener; RowListener({required this.rowId}); @@ -26,7 +27,8 @@ class RowListener { switch (ty) { case GridNotification.DidUpdateRow: result.fold( - (payload) => updateRowNotifier?.value = left(GridRowPB.fromBuffer(payload)), + (payload) => + updateRowNotifier?.value = left(RowPB.fromBuffer(payload)), (error) => updateRowNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart index 2dce917da4..94e047c1f7 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart @@ -13,7 +13,7 @@ class RowService { RowService( {required this.gridId, required this.blockId, required this.rowId}); - Future> createRow() { + Future> createRow() { CreateRowPayloadPB payload = CreateRowPayloadPB.create() ..gridId = gridId ..startRowId = rowId; @@ -34,7 +34,7 @@ class RowService { } Future> getRow() { - final payload = GridRowIdPB.create() + final payload = RowIdPB.create() ..gridId = gridId ..blockId = blockId ..rowId = rowId; @@ -43,7 +43,7 @@ class RowService { } Future> deleteRow() { - final payload = GridRowIdPB.create() + final payload = RowIdPB.create() ..gridId = gridId ..blockId = blockId ..rowId = rowId; @@ -52,7 +52,7 @@ class RowService { } Future> duplicateRow() { - final payload = GridRowIdPB.create() + final payload = RowIdPB.create() ..gridId = gridId ..blockId = blockId ..rowId = rowId; diff --git a/frontend/app_flowy/lib/plugins/grid/application/setting/property_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/setting/property_bloc.dart index 972b64f69a..fc0c2b4b12 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/setting/property_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/setting/property_bloc.dart @@ -11,7 +11,7 @@ part 'property_bloc.freezed.dart'; class GridPropertyBloc extends Bloc { final GridFieldCache _fieldCache; - Function(List)? _onFieldsFn; + Function(List)? _onFieldsFn; GridPropertyBloc({required String gridId, required GridFieldCache fieldCache}) : _fieldCache = fieldCache, @@ -67,8 +67,8 @@ class GridPropertyEvent with _$GridPropertyEvent { const factory GridPropertyEvent.initial() = _Initial; const factory GridPropertyEvent.setFieldVisibility( String fieldId, bool visibility) = _SetFieldVisibility; - const factory GridPropertyEvent.didReceiveFieldUpdate( - List fields) = _DidReceiveFieldUpdate; + const factory GridPropertyEvent.didReceiveFieldUpdate(List fields) = + _DidReceiveFieldUpdate; const factory GridPropertyEvent.moveField(int fromIndex, int toIndex) = _MoveField; } @@ -77,10 +77,10 @@ class GridPropertyEvent with _$GridPropertyEvent { class GridPropertyState with _$GridPropertyState { const factory GridPropertyState({ required String gridId, - required List fields, + required List fields, }) = _GridPropertyState; - factory GridPropertyState.initial(String gridId, List fields) => + factory GridPropertyState.initial(String gridId, List fields) => GridPropertyState( gridId: gridId, fields: fields, diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/grid_page.dart b/frontend/app_flowy/lib/plugins/grid/presentation/grid_page.dart index 3d3be83c79..8709b395b2 100755 --- a/frontend/app_flowy/lib/plugins/grid/presentation/grid_page.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/grid_page.dart @@ -225,7 +225,7 @@ class _GridRowsState extends State<_GridRows> { initialItemCount: context.read().state.rowInfos.length, itemBuilder: (BuildContext context, int index, Animation animation) { - final GridRowInfo rowInfo = + final RowInfo rowInfo = context.read().state.rowInfos[index]; return _renderRow(context, rowInfo, animation); }, @@ -236,7 +236,7 @@ class _GridRowsState extends State<_GridRows> { Widget _renderRow( BuildContext context, - GridRowInfo rowInfo, + RowInfo rowInfo, Animation animation, ) { final rowCache = @@ -274,7 +274,7 @@ class _GridRowsState extends State<_GridRows> { void _openRowDetailPage( BuildContext context, - GridRowInfo rowInfo, + RowInfo rowInfo, GridFieldCache fieldCache, GridRowCache rowCache, GridCellBuilder cellBuilder, diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/layout/layout.dart b/frontend/app_flowy/lib/plugins/grid/presentation/layout/layout.dart index 0b289ecd4b..e47b47a267 100755 --- a/frontend/app_flowy/lib/plugins/grid/presentation/layout/layout.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/layout/layout.dart @@ -2,11 +2,15 @@ import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; import 'sizes.dart'; class GridLayout { - static double headerWidth(List fields) { + static double headerWidth(List fields) { if (fields.isEmpty) return 0; - final fieldsWidth = fields.map((field) => field.width.toDouble()).reduce((value, element) => value + element); + final fieldsWidth = fields + .map((field) => field.width.toDouble()) + .reduce((value, element) => value + element); - return fieldsWidth + GridSize.leadingHeaderPadding + GridSize.trailHeaderPadding; + return fieldsWidth + + GridSize.leadingHeaderPadding + + GridSize.trailHeaderPadding; } } diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell.dart index cb8df60591..c1de0eca31 100755 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell.dart @@ -144,7 +144,7 @@ class _DragToExpandLine extends StatelessWidget { class FieldCellButton extends StatelessWidget { final VoidCallback onTap; - final GridFieldPB field; + final FieldPB field; const FieldCellButton({ required this.field, required this.onTap, diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_type_option_editor.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_type_option_editor.dart index 50a218fd0d..20440235cb 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_type_option_editor.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_type_option_editor.dart @@ -16,7 +16,7 @@ import 'field_type_extension.dart'; import 'field_type_list.dart'; import 'type_option/builder.dart'; -typedef UpdateFieldCallback = void Function(GridFieldPB, Uint8List); +typedef UpdateFieldCallback = void Function(FieldPB, Uint8List); typedef SwitchToFieldCallback = Future> Function( String fieldId, @@ -64,7 +64,7 @@ class _FieldTypeOptionEditorState extends State { ); } - Widget _switchFieldTypeButton(BuildContext context, GridFieldPB field) { + Widget _switchFieldTypeButton(BuildContext context, FieldPB field) { final theme = context.watch(); return SizedBox( height: GridSize.typeOptionItemHeight, diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart index 4b5f364c0d..1a8ed0be20 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart @@ -170,7 +170,7 @@ class CreateFieldButton extends StatelessWidget { class SliverHeaderDelegateImplementation extends SliverPersistentHeaderDelegate { final String gridId; - final List fields; + final List fields; SliverHeaderDelegateImplementation( {required this.gridId, required this.fields}); diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/type_option/builder.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/type_option/builder.dart index 40ce6fb82e..464c2f847c 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/type_option/builder.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/type_option/builder.dart @@ -131,7 +131,7 @@ TypeOptionWidgetBuilder makeTypeOptionWidgetBuilder({ TypeOptionContext makeTypeOptionContext({ required String gridId, - required GridFieldPB field, + required FieldPB field, }) { final loader = FieldTypeOptionLoader(gridId: gridId, field: field); final dataController = TypeOptionDataController( diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart index 044ddbb5ee..6c995d57eb 100755 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart @@ -16,7 +16,7 @@ import '../cell/prelude.dart'; import 'row_action_sheet.dart'; class GridRowWidget extends StatefulWidget { - final GridRowInfo rowInfo; + final RowInfo rowInfo; final GridRowDataController dataController; final GridCellBuilder cellBuilder; final void Function(BuildContext, GridCellBuilder) openDetailPage; diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_action_sheet.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_action_sheet.dart index 9c31bab5f3..720aac0dc0 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_action_sheet.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_action_sheet.dart @@ -15,7 +15,7 @@ import '../../../application/row/row_cache.dart'; import '../../layout/sizes.dart'; class GridRowActionSheet extends StatelessWidget { - final GridRowInfo rowData; + final RowInfo rowData; const GridRowActionSheet({required this.rowData, Key? key}) : super(key: key); @override diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/toolbar/grid_property.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/toolbar/grid_property.dart index b49cce1f11..02230e5139 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/toolbar/grid_property.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/toolbar/grid_property.dart @@ -78,7 +78,7 @@ class GridPropertyList extends StatelessWidget with FlowyOverlayDelegate { } class _GridPropertyCell extends StatelessWidget { - final GridFieldPB field; + final FieldPB field; final String gridId; const _GridPropertyCell({required this.gridId, required this.field, Key? key}) : super(key: key); diff --git a/frontend/app_flowy/lib/workspace/presentation/widgets/emoji_picker/src/emoji_lists.dart b/frontend/app_flowy/lib/workspace/presentation/widgets/emoji_picker/src/emoji_lists.dart index b5d364f67e..d012b0e7ca 100644 --- a/frontend/app_flowy/lib/workspace/presentation/widgets/emoji_picker/src/emoji_lists.dart +++ b/frontend/app_flowy/lib/workspace/presentation/widgets/emoji_picker/src/emoji_lists.dart @@ -1632,7 +1632,7 @@ final Map activities = Map.fromIterables([ 'Flying Disc', 'Bowling', 'Cricket Game', - 'GridFieldPB Hockey', + 'FieldPB Hockey', 'Ice Hockey', 'Lacrosse', 'Ping Pong', 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 f778186903..ad89532b02 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs @@ -4,24 +4,24 @@ use flowy_grid_data_model::parser::NotEmptyStr; use flowy_grid_data_model::revision::RowRevision; use std::sync::Arc; -/// [GridBlockPB] contains list of row ids. The rows here does not contain any data, just the id -/// of the row. Check out [GridRowPB] for more details. +/// [BlockPB] contains list of row ids. The rows here does not contain any data, just the id +/// of the row. Check out [RowPB] for more details. /// /// /// A grid can have many rows. Rows are therefore grouped into Blocks in order to make /// things more efficient. /// | #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridBlockPB { +pub struct BlockPB { #[pb(index = 1)] pub id: String, #[pb(index = 2)] - pub rows: Vec, + pub rows: Vec, } -impl GridBlockPB { - pub fn new(block_id: &str, rows: Vec) -> Self { +impl BlockPB { + pub fn new(block_id: &str, rows: Vec) -> Self { Self { id: block_id.to_owned(), rows, @@ -29,9 +29,9 @@ impl GridBlockPB { } } -/// [GridRowPB] Describes a row. Has the id of the parent Block. Has the metadata of the row. +/// [RowPB] Describes a row. Has the id of the parent Block. Has the metadata of the row. #[derive(Debug, Default, Clone, ProtoBuf)] -pub struct GridRowPB { +pub struct RowPB { #[pb(index = 1)] pub block_id: String, @@ -42,7 +42,7 @@ pub struct GridRowPB { pub height: i32, } -impl GridRowPB { +impl RowPB { pub fn row_id(&self) -> &str { &self.id } @@ -52,7 +52,7 @@ impl GridRowPB { } } -impl std::convert::From<&RowRevision> for GridRowPB { +impl std::convert::From<&RowRevision> for RowPB { fn from(rev: &RowRevision) -> Self { Self { block_id: rev.block_id.clone(), @@ -62,7 +62,7 @@ impl std::convert::From<&RowRevision> for GridRowPB { } } -impl std::convert::From<&Arc> for GridRowPB { +impl std::convert::From<&Arc> for RowPB { fn from(rev: &Arc) -> Self { Self { block_id: rev.block_id.clone(), @@ -75,30 +75,30 @@ impl std::convert::From<&Arc> for GridRowPB { #[derive(Debug, Default, ProtoBuf)] pub struct OptionalRowPB { #[pb(index = 1, one_of)] - pub row: Option, + pub row: Option, } #[derive(Debug, Default, ProtoBuf)] pub struct RepeatedRowPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::convert::From> for RepeatedRowPB { - fn from(items: Vec) -> Self { +impl std::convert::From> for RepeatedRowPB { + fn from(items: Vec) -> Self { Self { items } } } -/// [RepeatedGridBlockPB] contains list of [GridBlockPB] +/// [RepeatedBlockPB] contains list of [BlockPB] #[derive(Debug, Default, ProtoBuf)] -pub struct RepeatedGridBlockPB { +pub struct RepeatedBlockPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::convert::From> for RepeatedGridBlockPB { - fn from(items: Vec) -> Self { +impl std::convert::From> for RepeatedBlockPB { + fn from(items: Vec) -> Self { Self { items } } } @@ -127,11 +127,11 @@ pub struct UpdatedRowPB { pub row_id: String, #[pb(index = 3)] - pub row: GridRowPB, + pub row: RowPB, } impl UpdatedRowPB { - pub fn new(row_rev: &RowRevision, row: GridRowPB) -> Self { + pub fn new(row_rev: &RowRevision, row: RowPB) -> Self { Self { row_id: row_rev.id.clone(), block_id: row_rev.block_id.clone(), @@ -140,8 +140,8 @@ impl UpdatedRowPB { } } -impl std::convert::From for InsertedRowPB { - fn from(row_info: GridRowPB) -> Self { +impl std::convert::From for InsertedRowPB { + fn from(row_info: RowPB) -> Self { Self { row_id: row_info.id, block_id: row_info.block_id, @@ -153,7 +153,7 @@ impl std::convert::From for InsertedRowPB { impl std::convert::From<&RowRevision> for InsertedRowPB { fn from(row: &RowRevision) -> Self { - let row_order = GridRowPB::from(row); + let row_order = RowPB::from(row); Self::from(row_order) } } @@ -204,10 +204,10 @@ impl GridBlockChangesetPB { } } -/// [QueryGridBlocksPayloadPB] is used to query the data of the block that belongs to the grid whose +/// [QueryBlocksPayloadPB] is used to query the data of the block that belongs to the grid whose /// id is grid_id. #[derive(ProtoBuf, Default)] -pub struct QueryGridBlocksPayloadPB { +pub struct QueryBlocksPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -220,7 +220,7 @@ pub struct QueryGridBlocksParams { pub block_ids: Vec, } -impl TryInto for QueryGridBlocksPayloadPB { +impl TryInto for QueryBlocksPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs index dd31e22a54..468b216b5b 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs @@ -8,9 +8,9 @@ use std::sync::Arc; use strum_macros::{Display, EnumCount as EnumCountMacro, EnumIter, EnumString}; -/// [GridFieldPB] defines a Field's attributes. Such as the name, field_type, and width. etc. +/// [FieldPB] defines a Field's attributes. Such as the name, field_type, and width. etc. #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridFieldPB { +pub struct FieldPB { #[pb(index = 1)] pub id: String, @@ -36,7 +36,7 @@ pub struct GridFieldPB { pub is_primary: bool, } -impl std::convert::From for GridFieldPB { +impl std::convert::From for FieldPB { fn from(field_rev: FieldRevision) -> Self { Self { id: field_rev.id, @@ -51,33 +51,33 @@ impl std::convert::From for GridFieldPB { } } -impl std::convert::From> for GridFieldPB { +impl std::convert::From> for FieldPB { fn from(field_rev: Arc) -> Self { let field_rev = field_rev.as_ref().clone(); - GridFieldPB::from(field_rev) + FieldPB::from(field_rev) } } -/// [GridFieldIdPB] id of the [Field] +/// [FieldIdPB] id of the [Field] #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridFieldIdPB { +pub struct FieldIdPB { #[pb(index = 1)] pub field_id: String, } -impl std::convert::From<&str> for GridFieldIdPB { +impl std::convert::From<&str> for FieldIdPB { fn from(s: &str) -> Self { - GridFieldIdPB { field_id: s.to_owned() } + FieldIdPB { field_id: s.to_owned() } } } -impl std::convert::From for GridFieldIdPB { +impl std::convert::From for FieldIdPB { fn from(s: String) -> Self { - GridFieldIdPB { field_id: s } + FieldIdPB { field_id: s } } } -impl std::convert::From<&Arc> for GridFieldIdPB { +impl std::convert::From<&Arc> for FieldIdPB { fn from(field_rev: &Arc) -> Self { Self { field_id: field_rev.id.clone(), @@ -85,7 +85,7 @@ impl std::convert::From<&Arc> for GridFieldIdPB { } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridFieldChangesetPB { +pub struct FieldChangesetPB { #[pb(index = 1)] pub grid_id: String, @@ -93,13 +93,13 @@ pub struct GridFieldChangesetPB { pub inserted_fields: Vec, #[pb(index = 3)] - pub deleted_fields: Vec, + pub deleted_fields: Vec, #[pb(index = 4)] - pub updated_fields: Vec, + pub updated_fields: Vec, } -impl GridFieldChangesetPB { +impl FieldChangesetPB { pub fn insert(grid_id: &str, inserted_fields: Vec) -> Self { Self { grid_id: grid_id.to_owned(), @@ -109,7 +109,7 @@ impl GridFieldChangesetPB { } } - pub fn delete(grid_id: &str, deleted_fields: Vec) -> Self { + pub fn delete(grid_id: &str, deleted_fields: Vec) -> Self { Self { grid_id: grid_id.to_string(), inserted_fields: vec![], @@ -118,7 +118,7 @@ impl GridFieldChangesetPB { } } - pub fn update(grid_id: &str, updated_fields: Vec) -> Self { + pub fn update(grid_id: &str, updated_fields: Vec) -> Self { Self { grid_id: grid_id.to_string(), inserted_fields: vec![], @@ -131,7 +131,7 @@ impl GridFieldChangesetPB { #[derive(Debug, Clone, Default, ProtoBuf)] pub struct IndexFieldPB { #[pb(index = 1)] - pub field: GridFieldPB, + pub field: FieldPB, #[pb(index = 2)] pub index: i32, @@ -140,7 +140,7 @@ pub struct IndexFieldPB { impl IndexFieldPB { pub fn from_field_rev(field_rev: &Arc, index: usize) -> Self { Self { - field: GridFieldPB::from(field_rev.as_ref().clone()), + field: FieldPB::from(field_rev.as_ref().clone()), index: index as i32, } } @@ -220,7 +220,7 @@ impl TryInto for EditFieldPayloadPB { } #[derive(Debug, Default, ProtoBuf)] -pub struct GridFieldTypeOptionIdPB { +pub struct FieldTypeOptionIdPB { #[pb(index = 1)] pub grid_id: String, @@ -231,19 +231,19 @@ pub struct GridFieldTypeOptionIdPB { pub field_type: FieldType, } -pub struct GridFieldTypeOptionIdParams { +pub struct FieldTypeOptionIdParams { pub grid_id: String, pub field_id: String, pub field_type: FieldType, } -impl TryInto for GridFieldTypeOptionIdPB { +impl TryInto for FieldTypeOptionIdPB { type Error = ErrorCode; - fn try_into(self) -> Result { + fn try_into(self) -> Result { let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?; - Ok(GridFieldTypeOptionIdParams { + Ok(FieldTypeOptionIdParams { grid_id: grid_id.0, field_id: field_id.0, field_type: self.field_type, @@ -264,60 +264,60 @@ pub struct FieldTypeOptionDataPB { pub grid_id: String, #[pb(index = 2)] - pub field: GridFieldPB, + pub field: FieldPB, #[pb(index = 3)] pub type_option_data: Vec, } -/// Collection of the [GridFieldPB] +/// Collection of the [FieldPB] #[derive(Debug, Default, ProtoBuf)] -pub struct RepeatedGridFieldPB { +pub struct RepeatedFieldPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::ops::Deref for RepeatedGridFieldPB { - type Target = Vec; +impl std::ops::Deref for RepeatedFieldPB { + type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } -impl std::ops::DerefMut for RepeatedGridFieldPB { +impl std::ops::DerefMut for RepeatedFieldPB { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } } -impl std::convert::From> for RepeatedGridFieldPB { - fn from(items: Vec) -> Self { +impl std::convert::From> for RepeatedFieldPB { + fn from(items: Vec) -> Self { Self { items } } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct RepeatedGridFieldIdPB { +pub struct RepeatedFieldIdPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::ops::Deref for RepeatedGridFieldIdPB { - type Target = Vec; +impl std::ops::Deref for RepeatedFieldIdPB { + type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } -impl std::convert::From> for RepeatedGridFieldIdPB { - fn from(items: Vec) -> Self { - RepeatedGridFieldIdPB { items } +impl std::convert::From> for RepeatedFieldIdPB { + fn from(items: Vec) -> Self { + RepeatedFieldIdPB { items } } } -impl std::convert::From for RepeatedGridFieldIdPB { +impl std::convert::From for RepeatedFieldIdPB { fn from(s: String) -> Self { - RepeatedGridFieldIdPB { - items: vec![GridFieldIdPB::from(s)], + RepeatedFieldIdPB { + items: vec![FieldIdPB::from(s)], } } } @@ -328,7 +328,7 @@ pub struct InsertFieldPayloadPB { pub grid_id: String, #[pb(index = 2)] - pub field: GridFieldPB, + pub field: FieldPB, #[pb(index = 3)] pub type_option_data: Vec, @@ -340,7 +340,7 @@ pub struct InsertFieldPayloadPB { #[derive(Clone)] pub struct InsertFieldParams { pub grid_id: String, - pub field: GridFieldPB, + pub field: FieldPB, pub type_option_data: Vec, pub start_field_id: Option, } @@ -408,12 +408,12 @@ pub struct QueryFieldPayloadPB { pub grid_id: String, #[pb(index = 2)] - pub field_ids: RepeatedGridFieldIdPB, + pub field_ids: RepeatedFieldIdPB, } pub struct QueryFieldParams { pub grid_id: String, - pub field_ids: RepeatedGridFieldIdPB, + pub field_ids: RepeatedFieldIdPB, } impl TryInto for QueryFieldPayloadPB { @@ -633,13 +633,13 @@ pub struct GridFieldIdentifierPayloadPB { pub grid_id: String, } -impl TryInto for DuplicateFieldPayloadPB { +impl TryInto for DuplicateFieldPayloadPB { type Error = ErrorCode; - fn try_into(self) -> Result { + fn try_into(self) -> Result { let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?; - Ok(GridFieldIdParams { + Ok(FieldIdParams { grid_id: grid_id.0, field_id: field_id.0, }) @@ -655,20 +655,20 @@ pub struct DeleteFieldPayloadPB { pub grid_id: String, } -impl TryInto for DeleteFieldPayloadPB { +impl TryInto for DeleteFieldPayloadPB { type Error = ErrorCode; - fn try_into(self) -> Result { + fn try_into(self) -> Result { let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?; - Ok(GridFieldIdParams { + Ok(FieldIdParams { grid_id: grid_id.0, field_id: field_id.0, }) } } -pub struct GridFieldIdParams { +pub struct FieldIdParams { pub field_id: String, pub grid_id: String, } diff --git a/frontend/rust-lib/flowy-grid/src/entities/grid_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/grid_entities.rs index 49278afc54..6657e0e05a 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/grid_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/grid_entities.rs @@ -1,4 +1,4 @@ -use crate::entities::{GridBlockPB, GridFieldIdPB}; +use crate::entities::{BlockPB, FieldIdPB}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; @@ -10,10 +10,10 @@ pub struct GridPB { pub id: String, #[pb(index = 2)] - pub fields: Vec, + pub fields: Vec, #[pb(index = 3)] - pub blocks: Vec, + pub blocks: Vec, } #[derive(ProtoBuf, Default)] diff --git a/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs b/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs index cc89a11e59..11f338de63 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/group_entities/group.rs @@ -1,4 +1,4 @@ -use crate::entities::{FieldType, GridRowPB}; +use crate::entities::{FieldType, RowPB}; use flowy_derive::ProtoBuf; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; @@ -44,7 +44,7 @@ pub struct GroupPB { pub desc: String, #[pb(index = 3)] - pub rows: Vec, + pub rows: Vec, } #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] diff --git a/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs index 745a5dc368..47af2e00d3 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/row_entities.rs @@ -3,7 +3,7 @@ use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; #[derive(Debug, Default, Clone, ProtoBuf)] -pub struct GridRowIdPB { +pub struct RowIdPB { #[pb(index = 1)] pub grid_id: String, @@ -14,21 +14,21 @@ pub struct GridRowIdPB { pub row_id: String, } -pub struct GridRowIdParams { +pub struct RowIdParams { pub grid_id: String, pub block_id: String, pub row_id: String, } -impl TryInto for GridRowIdPB { +impl TryInto for RowIdPB { type Error = ErrorCode; - fn try_into(self) -> Result { + fn try_into(self) -> Result { let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; let block_id = NotEmptyStr::parse(self.block_id).map_err(|_| ErrorCode::BlockIdIsEmpty)?; let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?; - Ok(GridRowIdParams { + Ok(RowIdParams { grid_id: grid_id.0, block_id: block_id.0, row_id: row_id.0, diff --git a/frontend/rust-lib/flowy-grid/src/event_handler.rs b/frontend/rust-lib/flowy-grid/src/event_handler.rs index 496ee5ed18..4721e70bca 100644 --- a/frontend/rust-lib/flowy-grid/src/event_handler.rs +++ b/frontend/rust-lib/flowy-grid/src/event_handler.rs @@ -49,9 +49,9 @@ pub(crate) async fn update_grid_setting_handler( #[tracing::instrument(level = "debug", skip(data, manager), err)] pub(crate) async fn get_grid_blocks_handler( - data: Data, + data: Data, manager: AppData>, -) -> DataResult { +) -> DataResult { let params: QueryGridBlocksParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let repeated_grid_block = editor.get_blocks(Some(params.block_ids)).await?; @@ -62,7 +62,7 @@ pub(crate) async fn get_grid_blocks_handler( pub(crate) async fn get_fields_handler( data: Data, manager: AppData>, -) -> DataResult { +) -> DataResult { let params: QueryFieldParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let field_orders = params @@ -72,7 +72,7 @@ pub(crate) async fn get_fields_handler( .map(|field_order| field_order.field_id) .collect(); let field_revs = editor.get_field_revs(Some(field_orders)).await?; - let repeated_field: RepeatedGridFieldPB = field_revs.into_iter().map(GridFieldPB::from).collect::>().into(); + let repeated_field: RepeatedFieldPB = field_revs.into_iter().map(FieldPB::from).collect::>().into(); data_result(repeated_field) } @@ -116,7 +116,7 @@ pub(crate) async fn delete_field_handler( data: Data, manager: AppData>, ) -> Result<(), FlowyError> { - let params: GridFieldIdParams = data.into_inner().try_into()?; + let params: FieldIdParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let _ = editor.delete_field(¶ms.field_id).await?; Ok(()) @@ -154,7 +154,7 @@ pub(crate) async fn duplicate_field_handler( data: Data, manager: AppData>, ) -> Result<(), FlowyError> { - let params: GridFieldIdParams = data.into_inner().try_into()?; + let params: FieldIdParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let _ = editor.duplicate_field(¶ms.field_id).await?; Ok(()) @@ -163,10 +163,10 @@ pub(crate) async fn duplicate_field_handler( /// Return the FieldTypeOptionData if the Field exists otherwise return record not found error. #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn get_field_type_option_data_handler( - data: Data, + data: Data, manager: AppData>, ) -> DataResult { - let params: GridFieldTypeOptionIdParams = data.into_inner().try_into()?; + let params: FieldTypeOptionIdParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; match editor.get_field_rev(¶ms.field_id).await { None => Err(FlowyError::record_not_found()), @@ -227,10 +227,10 @@ async fn get_type_option_data(field_rev: &FieldRevision, field_type: &FieldType) #[tracing::instrument(level = "debug", skip(data, manager), err)] pub(crate) async fn get_row_handler( - data: Data, + data: Data, manager: AppData>, ) -> DataResult { - let params: GridRowIdParams = data.into_inner().try_into()?; + let params: RowIdParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let row = editor .get_row_rev(¶ms.row_id) @@ -242,10 +242,10 @@ pub(crate) async fn get_row_handler( #[tracing::instrument(level = "debug", skip(data, manager), err)] pub(crate) async fn delete_row_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { - let params: GridRowIdParams = data.into_inner().try_into()?; + let params: RowIdParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let _ = editor.delete_row(¶ms.row_id).await?; Ok(()) @@ -253,10 +253,10 @@ pub(crate) async fn delete_row_handler( #[tracing::instrument(level = "debug", skip(data, manager), err)] pub(crate) async fn duplicate_row_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { - let params: GridRowIdParams = data.into_inner().try_into()?; + let params: RowIdParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let _ = editor.duplicate_row(¶ms.row_id).await?; Ok(()) diff --git a/frontend/rust-lib/flowy-grid/src/event_map.rs b/frontend/rust-lib/flowy-grid/src/event_map.rs index f9b0770174..0852deade2 100644 --- a/frontend/rust-lib/flowy-grid/src/event_map.rs +++ b/frontend/rust-lib/flowy-grid/src/event_map.rs @@ -57,9 +57,9 @@ pub enum GridEvent { /// [GetGridBlocks] event is used to get the grid's block. /// - /// The event handler accepts a [QueryGridBlocksPayloadPB] and returns a [RepeatedGridBlockPB] + /// The event handler accepts a [QueryBlocksPayloadPB] and returns a [RepeatedBlockPB] /// if there are no errors. - #[event(input = "QueryGridBlocksPayloadPB", output = "RepeatedGridBlockPB")] + #[event(input = "QueryBlocksPayloadPB", output = "RepeatedBlockPB")] GetGridBlocks = 1, /// [GetGridSetting] event is used to get the grid's settings. @@ -77,9 +77,9 @@ pub enum GridEvent { /// [GetFields] event is used to get the grid's settings. /// - /// The event handler accepts a [QueryFieldPayloadPB] and returns a [RepeatedGridFieldPB] + /// The event handler accepts a [QueryFieldPayloadPB] and returns a [RepeatedFieldPB] /// if there are no errors. - #[event(input = "QueryFieldPayloadPB", output = "RepeatedGridFieldPB")] + #[event(input = "QueryFieldPayloadPB", output = "RepeatedFieldPB")] GetFields = 10, /// [UpdateField] event is used to update a field's attributes. @@ -132,13 +132,13 @@ pub enum GridEvent { #[event(input = "MoveItemPayloadPB")] MoveItem = 22, - /// [GetFieldTypeOption] event is used to get the FieldTypeOption data for a specific field type. + /// [FieldTypeOptionIdPB] event is used to get the FieldTypeOption data for a specific field type. /// /// Check out the [FieldTypeOptionDataPB] for more details. If the [FieldTypeOptionData] does exist /// for the target type, the [TypeOptionBuilder] will create the default data for that type. /// /// Return the [FieldTypeOptionDataPB] if there are no errors. - #[event(input = "GridFieldTypeOptionIdPB", output = "FieldTypeOptionDataPB")] + #[event(input = "FieldTypeOptionIdPB", output = "FieldTypeOptionDataPB")] GetFieldTypeOption = 23, /// [CreateFieldTypeOption] event is used to create a new FieldTypeOptionData. @@ -165,18 +165,18 @@ pub enum GridEvent { #[event(input = "SelectOptionChangesetPayloadPB")] UpdateSelectOption = 32, - #[event(input = "CreateRowPayloadPB", output = "GridRowPB")] + #[event(input = "CreateRowPayloadPB", output = "RowPB")] CreateRow = 50, - /// [GetRow] event is used to get the row data,[GridRowPB]. [OptionalRowPB] is a wrapper that enables + /// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables /// to return a nullable row data. - #[event(input = "GridRowIdPB", output = "OptionalRowPB")] + #[event(input = "RowIdPB", output = "OptionalRowPB")] GetRow = 51, - #[event(input = "GridRowIdPB")] + #[event(input = "RowIdPB")] DeleteRow = 52, - #[event(input = "GridRowIdPB")] + #[event(input = "RowIdPB")] DuplicateRow = 53, #[event(input = "GridCellIdPB", output = "GridCellPB")] 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 c83bfcc2cd..d7c01a6a09 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, GridNotification}; -use crate::entities::{CellChangesetPB, GridBlockChangesetPB, GridRowPB, InsertedRowPB, UpdatedRowPB}; +use crate::entities::{CellChangesetPB, GridBlockChangesetPB, InsertedRowPB, RowPB, UpdatedRowPB}; use crate::manager::GridUser; use crate::services::block_revision_editor::{GridBlockRevisionCompactor, GridBlockRevisionEditor}; use crate::services::persistence::block_index::BlockIndexCache; @@ -110,7 +110,7 @@ impl GridBlockManager { pub async fn update_row(&self, changeset: RowMetaChangeset, row_builder: F) -> FlowyResult<()> where - F: FnOnce(Arc) -> Option, + F: FnOnce(Arc) -> Option, { let editor = self.get_editor_from_row_id(&changeset.row_id).await?; let _ = editor.update_row(changeset.clone()).await?; @@ -146,10 +146,7 @@ impl GridBlockManager { Ok(()) } - pub(crate) async fn delete_rows( - &self, - row_orders: Vec, - ) -> FlowyResult> { + pub(crate) async fn delete_rows(&self, row_orders: Vec) -> FlowyResult> { let mut changesets = vec![]; for grid_block in block_from_row_orders(row_orders) { let editor = self.get_editor(&grid_block.id).await?; @@ -198,7 +195,7 @@ impl GridBlockManager { pub async fn update_cell(&self, changeset: CellChangesetPB, row_builder: F) -> FlowyResult<()> where - F: FnOnce(Arc) -> Option, + F: FnOnce(Arc) -> Option, { let row_changeset: RowMetaChangeset = changeset.clone().into(); let _ = self.update_row(row_changeset, row_builder).await?; @@ -217,7 +214,7 @@ impl GridBlockManager { } } - pub async fn get_row_orders(&self, block_id: &str) -> FlowyResult> { + pub async fn get_row_orders(&self, block_id: &str) -> FlowyResult> { let editor = self.get_editor(block_id).await?; editor.get_row_infos::<&str>(None).await } diff --git a/frontend/rust-lib/flowy-grid/src/services/block_revision_editor.rs b/frontend/rust-lib/flowy-grid/src/services/block_revision_editor.rs index a9f68c5776..0d5f5d206e 100644 --- a/frontend/rust-lib/flowy-grid/src/services/block_revision_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/block_revision_editor.rs @@ -1,4 +1,4 @@ -use crate::entities::GridRowPB; +use crate::entities::RowPB; use bytes::Bytes; use flowy_error::{FlowyError, FlowyResult}; use flowy_grid_data_model::revision::{CellRevision, GridBlockRevision, RowMetaChangeset, RowRevision}; @@ -123,12 +123,12 @@ impl GridBlockRevisionEditor { Ok(cell_revs) } - pub async fn get_row_info(&self, row_id: &str) -> FlowyResult> { + pub async fn get_row_info(&self, row_id: &str) -> FlowyResult> { let row_ids = Some(vec![Cow::Borrowed(row_id)]); Ok(self.get_row_infos(row_ids).await?.pop()) } - pub async fn get_row_infos(&self, row_ids: Option>>) -> FlowyResult> + pub async fn get_row_infos(&self, row_ids: Option>>) -> FlowyResult> where T: AsRef + ToOwned + ?Sized, { @@ -138,8 +138,8 @@ impl GridBlockRevisionEditor { .await .get_row_revs(row_ids)? .iter() - .map(GridRowPB::from) - .collect::>(); + .map(RowPB::from) + .collect::>(); Ok(row_infos) } diff --git a/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs b/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs index 6578ceb933..ccd16a019e 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/field_builder.rs @@ -1,4 +1,4 @@ -use crate::entities::{FieldType, GridFieldPB}; +use crate::entities::{FieldPB, FieldType}; use crate::services::field::type_options::*; use bytes::Bytes; use flowy_grid_data_model::revision::{FieldRevision, TypeOptionDataEntry}; @@ -28,7 +28,7 @@ impl FieldBuilder { Self::new(type_option_builder) } - pub fn from_field(field: GridFieldPB, type_option_builder: Box) -> Self { + pub fn from_field(field: FieldPB, type_option_builder: Box) -> Self { let field_rev = FieldRevision { id: field.id, name: field.name, diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs index c50042edad..74a2894680 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs @@ -192,8 +192,8 @@ impl GridRevisionEditor { pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> { let _ = self.modify(|grid_pad| Ok(grid_pad.delete_field_rev(field_id)?)).await?; - let field_order = GridFieldIdPB::from(field_id); - let notified_changeset = GridFieldChangesetPB::delete(&self.grid_id, vec![field_order]); + let field_order = FieldIdPB::from(field_id); + let notified_changeset = FieldChangesetPB::delete(&self.grid_id, vec![field_order]); let _ = self.notify_did_update_grid(notified_changeset).await?; Ok(()) } @@ -272,13 +272,13 @@ impl GridRevisionEditor { Ok(()) } - pub async fn create_row(&self, start_row_id: Option) -> FlowyResult { + pub async fn create_row(&self, start_row_id: Option) -> FlowyResult { let field_revs = self.grid_pad.read().await.get_field_revs(None)?; let block_id = self.block_id().await?; // insert empty row below the row whose id is upper_row_id let row_rev = RowRevisionBuilder::new(&block_id, &field_revs).build(); - let row_order = GridRowPB::from(&row_rev); + let row_order = RowPB::from(&row_rev); // insert the row let row_count = self.block_manager.create_row(&block_id, row_rev, start_row_id).await?; @@ -289,12 +289,12 @@ impl GridRevisionEditor { Ok(row_order) } - pub async fn insert_rows(&self, row_revs: Vec) -> FlowyResult> { + pub async fn insert_rows(&self, row_revs: Vec) -> FlowyResult> { let block_id = self.block_id().await?; let mut rows_by_block_id: HashMap> = HashMap::new(); let mut row_orders = vec![]; for row_rev in row_revs { - row_orders.push(GridRowPB::from(&row_rev)); + row_orders.push(RowPB::from(&row_rev)); rows_by_block_id .entry(block_id.clone()) .or_insert_with(Vec::new) @@ -406,7 +406,7 @@ impl GridRevisionEditor { } } - pub async fn get_blocks(&self, block_ids: Option>) -> FlowyResult { + pub async fn get_blocks(&self, block_ids: Option>) -> FlowyResult { let block_snapshots = self.grid_block_snapshots(block_ids.clone()).await?; make_grid_blocks(block_ids, block_snapshots) } @@ -416,7 +416,7 @@ impl GridRevisionEditor { Ok(block_meta_revs) } - pub async fn delete_rows(&self, row_orders: Vec) -> FlowyResult<()> { + pub async fn delete_rows(&self, row_orders: Vec) -> FlowyResult<()> { let changesets = self.block_manager.delete_rows(row_orders).await?; for changeset in changesets { let _ = self.update_block(changeset).await?; @@ -429,12 +429,12 @@ impl GridRevisionEditor { let field_orders = pad_read_guard .get_field_revs(None)? .iter() - .map(GridFieldIdPB::from) + .map(FieldIdPB::from) .collect(); let mut block_orders = vec![]; for block_rev in pad_read_guard.get_block_meta_revs() { let row_orders = self.block_manager.get_row_orders(&block_rev.block_id).await?; - let block_order = GridBlockPB { + let block_order = BlockPB { id: block_rev.block_id.clone(), rows: row_orders, }; @@ -512,9 +512,9 @@ impl GridRevisionEditor { .modify(|grid_pad| Ok(grid_pad.move_field(field_id, from as usize, to as usize)?)) .await?; if let Some((index, field_rev)) = self.grid_pad.read().await.get_field_rev(field_id) { - let delete_field_order = GridFieldIdPB::from(field_id); + let delete_field_order = FieldIdPB::from(field_id); let insert_field = IndexFieldPB::from_field_rev(field_rev, index); - let notified_changeset = GridFieldChangesetPB { + let notified_changeset = FieldChangesetPB { grid_id: self.grid_id.clone(), inserted_fields: vec![insert_field], deleted_fields: vec![delete_field_order], @@ -605,7 +605,7 @@ impl GridRevisionEditor { async fn notify_did_insert_grid_field(&self, field_id: &str) -> FlowyResult<()> { if let Some((index, field_rev)) = self.grid_pad.read().await.get_field_rev(field_id) { let index_field = IndexFieldPB::from_field_rev(field_rev, index); - let notified_changeset = GridFieldChangesetPB::insert(&self.grid_id, vec![index_field]); + let notified_changeset = FieldChangesetPB::insert(&self.grid_id, vec![index_field]); let _ = self.notify_did_update_grid(notified_changeset).await?; } Ok(()) @@ -620,8 +620,8 @@ impl GridRevisionEditor { .get_field_rev(field_id) .map(|(index, field)| (index, field.clone())) { - let updated_field = GridFieldPB::from(field_rev); - let notified_changeset = GridFieldChangesetPB::update(&self.grid_id, vec![updated_field.clone()]); + let updated_field = FieldPB::from(field_rev); + let notified_changeset = FieldChangesetPB::update(&self.grid_id, vec![updated_field.clone()]); let _ = self.notify_did_update_grid(notified_changeset).await?; send_dart_notification(field_id, GridNotification::DidUpdateField) @@ -632,7 +632,7 @@ impl GridRevisionEditor { Ok(()) } - async fn notify_did_update_grid(&self, changeset: GridFieldChangesetPB) -> FlowyResult<()> { + async fn notify_did_update_grid(&self, changeset: FieldChangesetPB) -> FlowyResult<()> { send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridField) .payload(changeset) .send(); diff --git a/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs b/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs index 3a5aa58c6d..24c2cda68a 100644 --- a/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs +++ b/frontend/rust-lib/flowy-grid/src/services/row/row_loader.rs @@ -1,4 +1,4 @@ -use crate::entities::{GridBlockPB, GridRowPB, RepeatedGridBlockPB}; +use crate::entities::{BlockPB, RepeatedBlockPB, RowPB}; use flowy_error::FlowyResult; use flowy_grid_data_model::revision::RowRevision; use std::collections::HashMap; @@ -9,14 +9,14 @@ pub struct GridBlockSnapshot { pub row_revs: Vec>, } -pub(crate) fn block_from_row_orders(row_orders: Vec) -> Vec { - let mut map: HashMap = HashMap::new(); +pub(crate) fn block_from_row_orders(row_orders: Vec) -> Vec { + let mut map: HashMap = HashMap::new(); row_orders.into_iter().for_each(|row_info| { // Memory Optimization: escape clone block_id let block_id = row_info.block_id().to_owned(); let cloned_block_id = block_id.clone(); map.entry(block_id) - .or_insert_with(|| GridBlockPB::new(&cloned_block_id, vec![])) + .or_insert_with(|| BlockPB::new(&cloned_block_id, vec![])) .rows .push(row_info); }); @@ -35,16 +35,16 @@ pub(crate) fn block_from_row_orders(row_orders: Vec) -> Vec]) -> Vec { - row_revs.iter().map(GridRowPB::from).collect::>() +pub(crate) fn make_row_orders_from_row_revs(row_revs: &[Arc]) -> Vec { + row_revs.iter().map(RowPB::from).collect::>() } -pub(crate) fn make_row_from_row_rev(row_rev: Arc) -> Option { +pub(crate) fn make_row_from_row_rev(row_rev: Arc) -> Option { make_rows_from_row_revs(&[row_rev]).pop() } -pub(crate) fn make_rows_from_row_revs(row_revs: &[Arc]) -> Vec { - let make_row = |row_rev: &Arc| GridRowPB { +pub(crate) fn make_rows_from_row_revs(row_revs: &[Arc]) -> Vec { + let make_row = |row_rev: &Arc| RowPB { block_id: row_rev.block_id.clone(), id: row_rev.id.clone(), height: row_rev.height, @@ -56,15 +56,15 @@ pub(crate) fn make_rows_from_row_revs(row_revs: &[Arc]) -> Vec>, block_snapshots: Vec, -) -> FlowyResult { +) -> FlowyResult { match block_ids { None => Ok(block_snapshots .into_iter() .map(|snapshot| { let row_orders = make_row_orders_from_row_revs(&snapshot.row_revs); - GridBlockPB::new(&snapshot.block_id, row_orders) + BlockPB::new(&snapshot.block_id, row_orders) }) - .collect::>() + .collect::>() .into()), Some(block_ids) => { let block_meta_data_map: HashMap<&String, &Vec>> = block_snapshots @@ -78,7 +78,7 @@ pub(crate) fn make_grid_blocks( None => {} Some(row_revs) => { let row_orders = make_row_orders_from_row_revs(row_revs); - grid_blocks.push(GridBlockPB::new(&block_id, row_orders)); + grid_blocks.push(BlockPB::new(&block_id, row_orders)); } } } diff --git a/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs index 14671c2eb2..900a41c6ed 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/block_test/script.rs @@ -2,7 +2,7 @@ use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow}; use crate::grid::block_test::util::GridRowTestBuilder; use crate::grid::grid_editor::GridEditorTest; -use flowy_grid::entities::{FieldType, GridCellIdParams, GridRowPB}; +use flowy_grid::entities::{FieldType, GridCellIdParams, RowPB}; use flowy_grid::services::field::*; use flowy_grid_data_model::revision::{ GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision, @@ -97,7 +97,7 @@ impl GridRowTest { let row_orders = row_ids .into_iter() .map(|row_id| self.row_order_by_row_id.get(&row_id).unwrap().clone()) - .collect::>(); + .collect::>(); self.editor.delete_rows(row_orders).await.unwrap(); self.row_revs = self.get_row_revs().await; diff --git a/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs b/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs index 9987b60671..bfd8c92f0a 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/field_test/util.rs @@ -17,7 +17,7 @@ pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) { .protobuf_bytes() .to_vec(); - let field = GridFieldPB { + let field = FieldPB { id: field_rev.id, name: field_rev.name, desc: field_rev.desc, @@ -50,7 +50,7 @@ pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldRev .protobuf_bytes() .to_vec(); - let field = GridFieldPB { + let field = FieldPB { id: field_rev.id, name: field_rev.name, desc: field_rev.desc, diff --git a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs index f4a1528f8f..a0f1b6d9cf 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs @@ -32,7 +32,7 @@ pub struct GridEditorTest { pub block_meta_revs: Vec>, pub row_revs: Vec>, pub field_count: usize, - pub row_order_by_row_id: HashMap, + pub row_order_by_row_id: HashMap, } impl GridEditorTest {