From 807341448549d674af385151c3bd08a84b2284be Mon Sep 17 00:00:00 2001 From: appflowy Date: Sun, 17 Jul 2022 11:29:02 +0800 Subject: [PATCH 1/3] refactor: rename struct & add documentation --- .../application/grid/block/block_cache.dart | 2 +- .../workspace/application/grid/grid_bloc.dart | 23 ++++++----- .../application/grid/grid_service.dart | 6 +-- .../grid/row/row_action_sheet_bloc.dart | 6 +-- .../application/grid/row/row_bloc.dart | 18 ++++----- .../application/grid/row/row_detail_bloc.dart | 8 ++-- .../application/grid/row/row_service.dart | 40 +++++++++---------- .../plugins/grid/src/grid_page.dart | 14 +++---- .../grid/src/widgets/row/grid_row.dart | 10 ++--- .../src/widgets/row/row_action_sheet.dart | 2 +- .../grid/src/widgets/row/row_detail.dart | 6 +-- .../flowy-grid/src/entities/block_entities.rs | 39 +++++++----------- .../flowy-grid/src/entities/field_entities.rs | 26 ++++++------ .../flowy-grid/src/entities/grid_entities.rs | 4 +- .../flowy-grid/src/services/block_manager.rs | 13 +++--- .../src/services/block_revision_editor.rs | 10 ++--- .../flowy-grid/src/services/grid_editor.rs | 20 +++++----- .../flowy-grid/src/services/row/row_loader.rs | 11 ++--- .../tests/grid/block_test/script.rs | 4 +- .../flowy-grid/tests/grid/grid_editor.rs | 2 +- 20 files changed, 127 insertions(+), 137 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart b/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart index caf61e64b3..9afdf17be6 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart @@ -13,7 +13,7 @@ class GridBlockCache { late GridRowCache _rowCache; late GridBlockListener _listener; - List get rows => _rowCache.rows; + List get rows => _rowCache.rows; GridRowCache get rowCache => _rowCache; GridBlockCache({ diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart index 7f120cf3d8..aaf47d8fc9 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart @@ -22,8 +22,8 @@ class GridBloc extends Bloc { // key: the block id final LinkedHashMap _blocks; - List get rows { - final List rows = []; + List get rowInfos { + final List rows = []; for (var block in _blocks.values) { rows.addAll(block.rows); } @@ -46,11 +46,11 @@ class GridBloc extends Bloc { createRow: () { _gridService.createRow(); }, - didReceiveRowUpdate: (rows, reason) { - emit(state.copyWith(rows: rows, reason: reason)); + didReceiveRowUpdate: (newRowInfos, reason) { + emit(state.copyWith(rowInfos: newRowInfos, reason: reason)); }, didReceiveFieldUpdate: (fields) { - emit(state.copyWith(rows: rows, fields: GridFieldEquatable(fields))); + emit(state.copyWith(rowInfos: rowInfos, fields: GridFieldEquatable(fields))); }, ); }, @@ -94,7 +94,7 @@ class GridBloc extends Bloc { } Future _loadFields(Grid grid, Emitter emit) async { - final result = await _gridService.getFields(fieldOrders: grid.fieldOrders); + final result = await _gridService.getFields(fieldOrders: grid.fields); return Future( () => result.fold( (fields) { @@ -103,7 +103,7 @@ class GridBloc extends Bloc { emit(state.copyWith( grid: Some(grid), fields: GridFieldEquatable(fieldCache.fields), - rows: rows, + rowInfos: rowInfos, loadingState: GridLoadingState.finish(left(unit)), )); }, @@ -127,7 +127,7 @@ class GridBloc extends Bloc { cache.addListener( listenWhen: () => !isClosed, - onChangeReason: (reason) => add(GridEvent.didReceiveRowUpdate(rows, reason)), + onChangeReason: (reason) => add(GridEvent.didReceiveRowUpdate(rowInfos, reason)), ); _blocks[block.id] = cache; @@ -139,7 +139,8 @@ class GridBloc extends Bloc { class GridEvent with _$GridEvent { const factory GridEvent.initial() = InitialGrid; const factory GridEvent.createRow() = _CreateRow; - const factory GridEvent.didReceiveRowUpdate(List rows, GridRowChangeReason listState) = _DidReceiveRowUpdate; + const factory GridEvent.didReceiveRowUpdate(List rows, GridRowChangeReason listState) = + _DidReceiveRowUpdate; const factory GridEvent.didReceiveFieldUpdate(List fields) = _DidReceiveFieldUpdate; } @@ -149,14 +150,14 @@ class GridState with _$GridState { required String gridId, required Option grid, required GridFieldEquatable fields, - required List rows, + required List rowInfos, required GridLoadingState loadingState, required GridRowChangeReason reason, }) = _GridState; factory GridState.initial(String gridId) => GridState( fields: const GridFieldEquatable([]), - rows: [], + rowInfos: [], grid: none(), gridId: gridId, loadingState: const _Loading(), diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart index 4e742f9f42..67511a4c61 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart @@ -32,7 +32,7 @@ class GridService { return GridEventCreateRow(payload).send(); } - Future> getFields({required List fieldOrders}) { + Future> getFields({required List fieldOrders}) { final payload = QueryFieldPayload.create() ..gridId = gridId ..fieldOrders = RepeatedFieldOrder(items: fieldOrders); @@ -141,12 +141,12 @@ class GridFieldCache { } } - void _deleteFields(List deletedFields) { + void _deleteFields(List deletedFields) { if (deletedFields.isEmpty) { return; } final List newFields = fields; - final Map deletedFieldMap = { + final Map deletedFieldMap = { for (var fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder }; diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_action_sheet_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_action_sheet_bloc.dart index 7d570c9412..9fe12f3ff5 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_action_sheet_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_action_sheet_bloc.dart @@ -11,7 +11,7 @@ part 'row_action_sheet_bloc.freezed.dart'; class RowActionSheetBloc extends Bloc { final RowService _rowService; - RowActionSheetBloc({required GridRow rowData}) + RowActionSheetBloc({required GridRowInfo rowData}) : _rowService = RowService( gridId: rowData.gridId, blockId: rowData.blockId, @@ -53,10 +53,10 @@ class RowActionSheetEvent with _$RowActionSheetEvent { @freezed class RowActionSheetState with _$RowActionSheetState { const factory RowActionSheetState({ - required GridRow rowData, + required GridRowInfo rowData, }) = _RowActionSheetState; - factory RowActionSheetState.initial(GridRow rowData) => RowActionSheetState( + factory RowActionSheetState.initial(GridRowInfo rowData) => RowActionSheetState( rowData: rowData, ); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart index 69d2a95059..6fec53b441 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart @@ -15,15 +15,15 @@ class RowBloc extends Bloc { void Function()? _rowListenFn; RowBloc({ - required GridRow rowData, + required GridRowInfo rowInfo, required GridRowCache rowCache, }) : _rowService = RowService( - gridId: rowData.gridId, - blockId: rowData.blockId, - rowId: rowData.id, + gridId: rowInfo.gridId, + blockId: rowInfo.blockId, + rowId: rowInfo.id, ), _rowCache = rowCache, - super(RowState.initial(rowData, rowCache.loadGridCells(rowData.id))) { + super(RowState.initial(rowInfo, rowCache.loadGridCells(rowInfo.id))) { on( (event, emit) async { await event.map( @@ -58,7 +58,7 @@ class RowBloc extends Bloc { Future _startListening() async { _rowListenFn = _rowCache.addListener( - rowId: state.rowData.id, + rowId: state.rowInfo.id, onCellUpdated: (cellDatas, reason) => add(RowEvent.didReceiveCellDatas(cellDatas, reason)), listenWhen: () => !isClosed, ); @@ -76,14 +76,14 @@ class RowEvent with _$RowEvent { @freezed class RowState with _$RowState { const factory RowState({ - required GridRow rowData, + required GridRowInfo rowInfo, required GridCellMap gridCellMap, required UnmodifiableListView snapshots, GridRowChangeReason? changeReason, }) = _RowState; - factory RowState.initial(GridRow rowData, GridCellMap cellDataMap) => RowState( - rowData: rowData, + factory RowState.initial(GridRowInfo rowInfo, GridCellMap cellDataMap) => RowState( + rowInfo: rowInfo, gridCellMap: cellDataMap, snapshots: UnmodifiableListView(cellDataMap.values.map((e) => GridCellEquatable(e.field)).toList()), ); diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_detail_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_detail_bloc.dart index b75caf32cf..966310fe8c 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_detail_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_detail_bloc.dart @@ -7,12 +7,12 @@ import 'row_service.dart'; part 'row_detail_bloc.freezed.dart'; class RowDetailBloc extends Bloc { - final GridRow rowData; + final GridRowInfo rowInfo; final GridRowCache _rowCache; void Function()? _rowListenFn; RowDetailBloc({ - required this.rowData, + required this.rowInfo, required GridRowCache rowCache, }) : _rowCache = rowCache, super(RowDetailState.initial()) { @@ -41,14 +41,14 @@ class RowDetailBloc extends Bloc { Future _startListening() async { _rowListenFn = _rowCache.addListener( - rowId: rowData.id, + rowId: rowInfo.id, onCellUpdated: (cellDatas, reason) => add(RowDetailEvent.didReceiveCellDatas(cellDatas.values.toList())), listenWhen: () => !isClosed, ); } Future _loadCellData() async { - final cellDataMap = _rowCache.loadGridCells(rowData.id); + final cellDataMap = _rowCache.loadGridCells(rowInfo.id); if (!isClosed) { add(RowDetailEvent.didReceiveCellDatas(cellDataMap.values.toList())); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart index 7296fd51a8..e733c6c20a 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart @@ -32,7 +32,7 @@ class GridRowCache { /// _rows containers the current block's rows /// Use List to reverse the order of the GridRow. - List _rows = []; + List _rowInfos = []; /// Use Map for faster access the raw row data. final HashMap _rowByRowId; @@ -41,7 +41,7 @@ class GridRowCache { final GridRowCacheFieldNotifier _fieldNotifier; final _GridRowChangesetNotifier _rowChangeReasonNotifier; - UnmodifiableListView get rows => UnmodifiableListView(_rows); + UnmodifiableListView get rows => UnmodifiableListView(_rowInfos); GridCellCache get cellCache => _cellCache; GridRowCache({ @@ -55,7 +55,7 @@ class GridRowCache { // notifier.onFieldsChanged(() => _rowChangeReasonNotifier.receive(const GridRowChangeReason.fieldDidChange())); notifier.onFieldChanged((field) => _cellCache.remove(field.id)); - _rows = block.rowInfos.map((rowInfo) => buildGridRow(rowInfo.rowId, rowInfo.height.toDouble())).toList(); + _rowInfos = block.rows.map((rowInfo) => buildGridRow(rowInfo.id, rowInfo.height.toDouble())).toList(); } Future dispose() async { @@ -79,11 +79,11 @@ class GridRowCache { return; } - final List newRows = []; + final List newRows = []; final DeletedIndexs deletedIndex = []; final Map deletedRowByRowId = {for (var rowId in deletedRows) rowId: rowId}; - _rows.asMap().forEach((index, row) { + _rowInfos.asMap().forEach((index, row) { if (deletedRowByRowId[row.id] == null) { newRows.add(row); } else { @@ -91,7 +91,7 @@ class GridRowCache { deletedIndex.add(DeletedIndex(index: index, row: row)); } }); - _rows = newRows; + _rowInfos = newRows; _rowChangeReasonNotifier.receive(GridRowChangeReason.delete(deletedIndex)); } @@ -107,7 +107,7 @@ class GridRowCache { rowId: insertRow.rowId, ); insertIndexs.add(insertIndex); - _rows.insert(insertRow.index, (buildGridRow(insertRow.rowId, insertRow.height.toDouble()))); + _rowInfos.insert(insertRow.index, (buildGridRow(insertRow.rowId, insertRow.height.toDouble()))); } _rowChangeReasonNotifier.receive(GridRowChangeReason.insert(insertIndexs)); @@ -121,12 +121,12 @@ class GridRowCache { final UpdatedIndexs updatedIndexs = UpdatedIndexs(); for (final updatedRow in updatedRows) { final rowId = updatedRow.rowId; - final index = _rows.indexWhere((row) => row.id == rowId); + final index = _rowInfos.indexWhere((row) => row.id == rowId); if (index != -1) { _rowByRowId[rowId] = updatedRow.row; - _rows.removeAt(index); - _rows.insert(index, buildGridRow(rowId, updatedRow.row.height.toDouble())); + _rowInfos.removeAt(index); + _rowInfos.insert(index, buildGridRow(rowId, updatedRow.row.height.toDouble())); updatedIndexs[rowId] = UpdatedIndex(index: index, rowId: rowId); } } @@ -225,12 +225,12 @@ class GridRowCache { updatedRow.freeze(); _rowByRowId[updatedRow.id] = updatedRow; - final index = _rows.indexWhere((gridRow) => gridRow.id == updatedRow.id); + final index = _rowInfos.indexWhere((gridRow) => gridRow.id == updatedRow.id); if (index != -1) { // update the corresponding row in _rows if they are not the same - if (_rows[index].rawRow != updatedRow) { - final row = _rows.removeAt(index).copyWith(rawRow: updatedRow); - _rows.insert(index, row); + if (_rowInfos[index].rawRow != updatedRow) { + final row = _rowInfos.removeAt(index).copyWith(rawRow: updatedRow); + _rowInfos.insert(index, row); // Calculate the update index final UpdatedIndexs updatedIndexs = UpdatedIndexs(); @@ -242,8 +242,8 @@ class GridRowCache { } } - GridRow buildGridRow(String rowId, double rowHeight) { - return GridRow( + GridRowInfo buildGridRow(String rowId, double rowHeight) { + return GridRowInfo( gridId: gridId, blockId: block.id, fields: _fieldNotifier.fields, @@ -325,15 +325,15 @@ class RowService { } @freezed -class GridRow with _$GridRow { - const factory GridRow({ +class GridRowInfo with _$GridRowInfo { + const factory GridRowInfo({ required String gridId, required String blockId, required String id, required UnmodifiableListView fields, required double height, Row? rawRow, - }) = _GridRow; + }) = _GridRowInfo; } typedef InsertedIndexs = List; @@ -360,7 +360,7 @@ class InsertedIndex { class DeletedIndex { final int index; - final GridRow row; + final GridRowInfo row; DeletedIndex({ required this.index, required this.row, diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart index d7d2999dd1..2ec27f3f3c 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart @@ -212,10 +212,10 @@ class _GridRowsState extends State<_GridRows> { builder: (context, state) { return SliverAnimatedList( key: _key, - initialItemCount: context.read().state.rows.length, + initialItemCount: context.read().state.rowInfos.length, itemBuilder: (BuildContext context, int index, Animation animation) { - final GridRow rowData = context.read().state.rows[index]; - return _renderRow(context, rowData, animation); + final GridRowInfo rowInfo = context.read().state.rowInfos[index]; + return _renderRow(context, rowInfo, animation); }, ); }, @@ -224,19 +224,19 @@ class _GridRowsState extends State<_GridRows> { Widget _renderRow( BuildContext context, - GridRow rowData, + GridRowInfo rowInfo, Animation animation, ) { - final rowCache = context.read().getRowCache(rowData.blockId, rowData.id); + final rowCache = context.read().getRowCache(rowInfo.blockId, rowInfo.id); final fieldCache = context.read().fieldCache; if (rowCache != null) { return SizeTransition( sizeFactor: animation, child: GridRowWidget( - rowData: rowData, + rowData: rowInfo, rowCache: rowCache, fieldCache: fieldCache, - key: ValueKey(rowData.id), + key: ValueKey(rowInfo.id), ), ); } else { diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart index b0c1cd2ea0..c3e2e17b7e 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart @@ -15,7 +15,7 @@ import 'row_action_sheet.dart'; import 'row_detail.dart'; class GridRowWidget extends StatefulWidget { - final GridRow rowData; + final GridRowInfo rowData; final GridRowCache rowCache; final GridCellBuilder cellBuilder; @@ -40,7 +40,7 @@ class _GridRowWidgetState extends State { @override void initState() { _rowBloc = RowBloc( - rowData: widget.rowData, + rowInfo: widget.rowData, rowCache: widget.rowCache, ); _rowBloc.add(const RowEvent.initial()); @@ -53,7 +53,7 @@ class _GridRowWidgetState extends State { value: _rowBloc, child: _RowEnterRegion( child: BlocBuilder( - buildWhen: (p, c) => p.rowData.height != c.rowData.height, + buildWhen: (p, c) => p.rowInfo.height != c.rowInfo.height, builder: (context, state) { return Row( children: [ @@ -80,7 +80,7 @@ class _GridRowWidgetState extends State { void _expandRow(BuildContext context) { final page = RowDetailPage( - rowData: widget.rowData, + rowInfo: widget.rowData, rowCache: widget.rowCache, cellBuilder: widget.cellBuilder, ); @@ -148,7 +148,7 @@ class _DeleteRowButton extends StatelessWidget { width: 20, height: 30, onPressed: () => GridRowActionSheet( - rowData: context.read().state.rowData, + rowData: context.read().state.rowInfo, ).show(context), iconPadding: const EdgeInsets.all(3), icon: svgWidget("editor/details"), diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_action_sheet.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_action_sheet.dart index 1d7886c86c..06e9c68d19 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_action_sheet.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_action_sheet.dart @@ -14,7 +14,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class GridRowActionSheet extends StatelessWidget { - final GridRow rowData; + final GridRowInfo rowData; const GridRowActionSheet({required this.rowData, Key? key}) : super(key: key); @override diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart index 4449ea6770..a01f97b847 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart @@ -21,12 +21,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class RowDetailPage extends StatefulWidget with FlowyOverlayDelegate { - final GridRow rowData; + final GridRowInfo rowInfo; final GridRowCache rowCache; final GridCellBuilder cellBuilder; const RowDetailPage({ - required this.rowData, + required this.rowInfo, required this.rowCache, required this.cellBuilder, Key? key, @@ -62,7 +62,7 @@ class _RowDetailPageState extends State { Widget build(BuildContext context) { return BlocProvider( create: (context) { - final bloc = RowDetailBloc(rowData: widget.rowData, rowCache: widget.rowCache); + final bloc = RowDetailBloc(rowInfo: widget.rowInfo, rowCache: widget.rowCache); bloc.add(const RowDetailEvent.initial()); return bloc; }, 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 9cfdbc088c..eb486f4cd2 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs @@ -10,33 +10,33 @@ pub struct GridBlock { pub id: String, #[pb(index = 2)] - pub row_infos: Vec, + pub rows: Vec, } impl GridBlock { - pub fn new(block_id: &str, row_orders: Vec) -> Self { + pub fn new(block_id: &str, rows: Vec) -> Self { Self { id: block_id.to_owned(), - row_infos: row_orders, + rows, } } } #[derive(Debug, Default, Clone, ProtoBuf)] -pub struct RowInfo { +pub struct Row { #[pb(index = 1)] pub block_id: String, #[pb(index = 2)] - pub row_id: String, + pub id: String, #[pb(index = 3)] pub height: i32, } -impl RowInfo { +impl Row { pub fn row_id(&self) -> &str { - &self.row_id + &self.id } pub fn block_id(&self) -> &str { @@ -44,35 +44,26 @@ impl RowInfo { } } -impl std::convert::From<&RowRevision> for RowInfo { +impl std::convert::From<&RowRevision> for Row { fn from(rev: &RowRevision) -> Self { Self { block_id: rev.block_id.clone(), - row_id: rev.id.clone(), + id: rev.id.clone(), height: rev.height, } } } -impl std::convert::From<&Arc> for RowInfo { +impl std::convert::From<&Arc> for Row { fn from(rev: &Arc) -> Self { Self { block_id: rev.block_id.clone(), - row_id: rev.id.clone(), + id: rev.id.clone(), height: rev.height, } } } -#[derive(Debug, Default, ProtoBuf)] -pub struct Row { - #[pb(index = 1)] - pub id: String, - - #[pb(index = 2)] - pub height: i32, -} - #[derive(Debug, Default, ProtoBuf)] pub struct OptionalRow { #[pb(index = 1, one_of)] @@ -139,10 +130,10 @@ impl UpdatedRow { } } -impl std::convert::From for InsertedRow { - fn from(row_info: RowInfo) -> Self { +impl std::convert::From for InsertedRow { + fn from(row_info: Row) -> Self { Self { - row_id: row_info.row_id, + row_id: row_info.id, block_id: row_info.block_id, height: row_info.height, index: None, @@ -152,7 +143,7 @@ impl std::convert::From for InsertedRow { impl std::convert::From<&RowRevision> for InsertedRow { fn from(row: &RowRevision) -> Self { - let row_order = RowInfo::from(row); + let row_order = Row::from(row); Self::from(row_order) } } 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 d43e77e9ae..f7fa70455c 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs @@ -57,24 +57,24 @@ impl std::convert::From> for Field { } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct FieldOrder { +pub struct GridField { #[pb(index = 1)] pub field_id: String, } -impl std::convert::From<&str> for FieldOrder { +impl std::convert::From<&str> for GridField { fn from(s: &str) -> Self { - FieldOrder { field_id: s.to_owned() } + GridField { field_id: s.to_owned() } } } -impl std::convert::From for FieldOrder { +impl std::convert::From for GridField { fn from(s: String) -> Self { - FieldOrder { field_id: s } + GridField { field_id: s } } } -impl std::convert::From<&Arc> for FieldOrder { +impl std::convert::From<&Arc> for GridField { fn from(field_rev: &Arc) -> Self { Self { field_id: field_rev.id.clone(), @@ -90,7 +90,7 @@ pub struct GridFieldChangeset { pub inserted_fields: Vec, #[pb(index = 3)] - pub deleted_fields: Vec, + pub deleted_fields: Vec, #[pb(index = 4)] pub updated_fields: Vec, @@ -106,7 +106,7 @@ impl GridFieldChangeset { } } - 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![], @@ -259,18 +259,18 @@ impl std::convert::From> for RepeatedField { #[derive(Debug, Clone, Default, ProtoBuf)] pub struct RepeatedFieldOrder { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } impl std::ops::Deref for RepeatedFieldOrder { - type Target = Vec; + type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } -impl std::convert::From> for RepeatedFieldOrder { - fn from(field_orders: Vec) -> Self { +impl std::convert::From> for RepeatedFieldOrder { + fn from(field_orders: Vec) -> Self { RepeatedFieldOrder { items: field_orders } } } @@ -278,7 +278,7 @@ impl std::convert::From> for RepeatedFieldOrder { impl std::convert::From for RepeatedFieldOrder { fn from(s: String) -> Self { RepeatedFieldOrder { - items: vec![FieldOrder::from(s)], + items: vec![GridField::from(s)], } } } 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 c05df11414..1cc6f2ba45 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::{FieldOrder, GridBlock}; +use crate::entities::{GridBlock, GridField}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; @@ -8,7 +8,7 @@ pub struct Grid { pub id: String, #[pb(index = 2)] - pub field_orders: Vec, + pub fields: Vec, #[pb(index = 3)] pub blocks: Vec, 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 a905a9640b..c52f0662ec 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::{CellChangeset, GridBlockChangeset, InsertedRow, Row, RowInfo, UpdatedRow}; +use crate::entities::{CellChangeset, GridBlockChangeset, InsertedRow, Row, UpdatedRow}; use crate::manager::GridUser; use crate::services::block_revision_editor::GridBlockRevisionEditor; use crate::services::persistence::block_index::BlockIndexCache; @@ -138,7 +138,7 @@ impl GridBlockManager { Some(row_info) => { let _ = editor.delete_rows(vec![Cow::Borrowed(&row_id)]).await?; let _ = self - .notify_did_update_block(&block_id, GridBlockChangeset::delete(&block_id, vec![row_info.row_id])) + .notify_did_update_block(&block_id, GridBlockChangeset::delete(&block_id, vec![row_info.id])) .await?; } } @@ -146,15 +146,12 @@ 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?; let row_ids = grid_block - .row_infos + .rows .into_iter() .map(|row_info| Cow::Owned(row_info.row_id().to_owned())) .collect::>>(); @@ -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 e73a66c0fa..99d851a7d5 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::RowInfo; +use crate::entities::Row; 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(RowInfo::from) - .collect::>(); + .map(Row::from) + .collect::>(); Ok(row_infos) } 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 1d63b6dd69..e6a37ef203 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs @@ -189,7 +189,7 @@ 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 = FieldOrder::from(field_id); + let field_order = GridField::from(field_id); let notified_changeset = GridFieldChangeset::delete(&self.grid_id, vec![field_order]); let _ = self.notify_did_update_grid(notified_changeset).await?; Ok(()) @@ -269,14 +269,14 @@ 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_ctx = CreateRowRevisionBuilder::new(&field_revs).build(); let row_rev = make_row_rev_from_context(&block_id, row_rev_ctx); - let row_order = RowInfo::from(&row_rev); + let row_order = Row::from(&row_rev); // insert the row let row_count = self.block_manager.create_row(&block_id, row_rev, start_row_id).await?; @@ -287,13 +287,13 @@ impl GridRevisionEditor { Ok(row_order) } - pub async fn insert_rows(&self, contexts: Vec) -> FlowyResult> { + pub async fn insert_rows(&self, contexts: Vec) -> FlowyResult> { let block_id = self.block_id().await?; let mut rows_by_block_id: HashMap> = HashMap::new(); let mut row_orders = vec![]; for ctx in contexts { let row_rev = make_row_rev_from_context(&block_id, ctx); - row_orders.push(RowInfo::from(&row_rev)); + row_orders.push(Row::from(&row_rev)); rows_by_block_id .entry(block_id.clone()) .or_insert_with(Vec::new) @@ -421,7 +421,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?; @@ -434,21 +434,21 @@ impl GridRevisionEditor { let field_orders = pad_read_guard .get_field_revs(None)? .iter() - .map(FieldOrder::from) + .map(GridField::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 = GridBlock { id: block_rev.block_id.clone(), - row_infos: row_orders, + rows: row_orders, }; block_orders.push(block_order); } Ok(Grid { id: self.grid_id.clone(), - field_orders, + fields: field_orders, blocks: block_orders, }) } @@ -517,7 +517,7 @@ 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 = FieldOrder::from(field_id); + let delete_field_order = GridField::from(field_id); let insert_field = IndexField::from_field_rev(field_rev, index); let notified_changeset = GridFieldChangeset { grid_id: self.grid_id.clone(), 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 1b9ce80101..9d6543b650 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::{GridBlock, RepeatedGridBlock, Row, RowInfo}; +use crate::entities::{GridBlock, RepeatedGridBlock, Row}; use flowy_error::FlowyResult; use flowy_grid_data_model::revision::{FieldRevision, RowRevision}; use std::collections::HashMap; @@ -9,7 +9,7 @@ pub struct GridBlockSnapshot { pub row_revs: Vec>, } -pub(crate) fn block_from_row_orders(row_orders: Vec) -> Vec { +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 @@ -17,7 +17,7 @@ pub(crate) fn block_from_row_orders(row_orders: Vec) -> Vec let cloned_block_id = block_id.clone(); map.entry(block_id) .or_insert_with(|| GridBlock::new(&cloned_block_id, vec![])) - .row_infos + .rows .push(row_info); }); map.into_values().collect::>() @@ -35,8 +35,8 @@ pub(crate) fn block_from_row_orders(row_orders: Vec) -> Vec // Some((field_id, cell)) // } -pub(crate) fn make_row_orders_from_row_revs(row_revs: &[Arc]) -> Vec { - row_revs.iter().map(RowInfo::from).collect::>() +pub(crate) fn make_row_orders_from_row_revs(row_revs: &[Arc]) -> Vec { + row_revs.iter().map(Row::from).collect::>() } pub(crate) fn make_row_from_row_rev(fields: &[Arc], row_rev: Arc) -> Option { @@ -58,6 +58,7 @@ pub(crate) fn make_rows_from_row_revs(_fields: &[Arc], row_revs: // .collect::>(); Row { + block_id: row_rev.block_id.clone(), id: row_rev.id.clone(), height: row_rev.height, } 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 288133958b..5a9b29b76d 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 @@ -1,5 +1,5 @@ use crate::grid::grid_editor::GridEditorTest; -use flowy_grid::entities::RowInfo; +use flowy_grid::entities::Row; use flowy_grid::services::row::{CreateRowRevisionBuilder, CreateRowRevisionPayload}; use flowy_grid_data_model::revision::{ FieldRevision, GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision, @@ -90,7 +90,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/grid_editor.rs b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs index d944aac6c5..bfa9e6e0ba 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs @@ -30,7 +30,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 { From 1bf0f0f875ab306c33942cdc42cfc037b2d1a1b1 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sun, 17 Jul 2022 13:38:53 +0800 Subject: [PATCH 2/3] chore: add suffix PB to rust struct --- .../application/grid/block/block_cache.dart | 2 +- .../application/grid/field/field_service.dart | 4 +- .../application/grid/grid_service.dart | 10 +- .../flowy-grid/src/entities/block_entities.rs | 70 +++++----- .../flowy-grid/src/entities/cell_entities.rs | 4 +- .../flowy-grid/src/entities/field_entities.rs | 130 ++++++++---------- .../src/entities/filter_entities/util.rs | 18 +-- .../flowy-grid/src/entities/grid_entities.rs | 36 ++--- .../flowy-grid/src/entities/group_entities.rs | 22 +-- .../flowy-grid/src/entities/row_entities.rs | 16 +-- .../src/entities/setting_entities.rs | 34 ++--- .../flowy-grid/src/entities/sort_entities.rs | 12 +- .../rust-lib/flowy-grid/src/event_handler.rs | 90 ++++++------ .../flowy-grid/src/services/block_manager.rs | 33 +++-- .../src/services/block_revision_editor.rs | 10 +- .../src/services/cell/cell_operation.rs | 6 +- .../src/services/field/field_builder.rs | 6 +- .../date_type_option/date_tests.rs | 30 ++-- .../date_type_option/date_type_option.rs | 14 +- .../date_type_option_entities.rs | 20 +-- .../multi_select_type_option.rs | 24 ++-- .../selection_type_option/select_option.rs | 100 +++++++------- .../single_select_type_option.rs | 40 +++--- .../text_type_option/text_type_option.rs | 6 +- .../type_options/url_type_option/url_tests.rs | 6 +- .../url_type_option/url_type_option.rs | 14 +- .../url_type_option_entities.rs | 12 +- .../src/services/filter/filter_service.rs | 10 +- .../filter/impls/select_option_filter.rs | 12 +- .../flowy-grid/src/services/grid_editor.rs | 48 +++---- .../flowy-grid/src/services/row/row_loader.rs | 26 ++-- .../src/services/setting/setting_builder.rs | 14 +- .../tests/grid/block_test/script.rs | 8 +- .../flowy-grid/tests/grid/block_test/util.rs | 10 +- .../flowy-grid/tests/grid/cell_test/test.rs | 4 +- .../flowy-grid/tests/grid/field_test/test.rs | 8 +- .../flowy-grid/tests/grid/field_test/util.rs | 14 +- .../tests/grid/filter_test/script.rs | 6 +- .../grid/filter_test/text_filter_test.rs | 10 +- .../flowy-grid/tests/grid/grid_editor.rs | 16 +-- 40 files changed, 474 insertions(+), 481 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart b/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart index 9afdf17be6..3c99c0e0e1 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/block/block_cache.dart @@ -9,7 +9,7 @@ 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 GridBlock block; + final GridBlockPB block; late GridRowCache _rowCache; late GridBlockListener _listener; diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart index de5b6adcb0..828ea4cc74 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart @@ -21,10 +21,10 @@ class FieldService { FieldService({required this.gridId, required this.fieldId}); Future> moveField(int fromIndex, int toIndex) { - final payload = MoveItemPayload.create() + final payload = MoveItemPayloadPB.create() ..gridId = gridId ..itemId = fieldId - ..ty = MoveItemType.MoveField + ..ty = MoveItemTypePB.MoveField ..fromIndex = fromIndex ..toIndex = toIndex; diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart index 67511a4c61..1d0c309d51 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart @@ -19,10 +19,10 @@ class GridService { required this.gridId, }); - Future> loadGrid() async { + Future> loadGrid() async { await FolderEventSetLatestView(ViewId(value: gridId)).send(); - final payload = GridId(value: gridId); + final payload = GridIdPB(value: gridId); return GridEventGetGrid(payload).send(); } @@ -32,7 +32,7 @@ class GridService { return GridEventCreateRow(payload).send(); } - Future> getFields({required List fieldOrders}) { + Future> getFields({required List fieldOrders}) { final payload = QueryFieldPayload.create() ..gridId = gridId ..fieldOrders = RepeatedFieldOrder(items: fieldOrders); @@ -141,12 +141,12 @@ class GridFieldCache { } } - void _deleteFields(List deletedFields) { + void _deleteFields(List deletedFields) { if (deletedFields.isEmpty) { return; } final List newFields = fields; - final Map deletedFieldMap = { + final Map deletedFieldMap = { for (var fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder }; 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 eb486f4cd2..df2192c77d 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs @@ -5,16 +5,16 @@ use flowy_grid_data_model::revision::RowRevision; use std::sync::Arc; #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridBlock { +pub struct GridBlockPB { #[pb(index = 1)] pub id: String, #[pb(index = 2)] - pub rows: Vec, + pub rows: Vec, } -impl GridBlock { - pub fn new(block_id: &str, rows: Vec) -> Self { +impl GridBlockPB { + pub fn new(block_id: &str, rows: Vec) -> Self { Self { id: block_id.to_owned(), rows, @@ -23,7 +23,7 @@ impl GridBlock { } #[derive(Debug, Default, Clone, ProtoBuf)] -pub struct Row { +pub struct GridRowPB { #[pb(index = 1)] pub block_id: String, @@ -34,7 +34,7 @@ pub struct Row { pub height: i32, } -impl Row { +impl GridRowPB { pub fn row_id(&self) -> &str { &self.id } @@ -44,7 +44,7 @@ impl Row { } } -impl std::convert::From<&RowRevision> for Row { +impl std::convert::From<&RowRevision> for GridRowPB { fn from(rev: &RowRevision) -> Self { Self { block_id: rev.block_id.clone(), @@ -54,7 +54,7 @@ impl std::convert::From<&RowRevision> for Row { } } -impl std::convert::From<&Arc> for Row { +impl std::convert::From<&Arc> for GridRowPB { fn from(rev: &Arc) -> Self { Self { block_id: rev.block_id.clone(), @@ -65,36 +65,36 @@ impl std::convert::From<&Arc> for Row { } #[derive(Debug, Default, ProtoBuf)] -pub struct OptionalRow { +pub struct OptionalRowPB { #[pb(index = 1, one_of)] - pub row: Option, + pub row: Option, } #[derive(Debug, Default, ProtoBuf)] -pub struct RepeatedRow { +pub struct RepeatedRowPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::convert::From> for RepeatedRow { - fn from(items: Vec) -> Self { +impl std::convert::From> for RepeatedRowPB { + fn from(items: Vec) -> Self { Self { items } } } #[derive(Debug, Default, ProtoBuf)] -pub struct RepeatedGridBlock { +pub struct RepeatedGridBlockPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::convert::From> for RepeatedGridBlock { - fn from(items: Vec) -> Self { +impl std::convert::From> for RepeatedGridBlockPB { + fn from(items: Vec) -> Self { Self { items } } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct InsertedRow { +pub struct InsertedRowPB { #[pb(index = 1)] pub block_id: String, @@ -109,7 +109,7 @@ pub struct InsertedRow { } #[derive(Debug, Default, ProtoBuf)] -pub struct UpdatedRow { +pub struct UpdatedRowPB { #[pb(index = 1)] pub block_id: String, @@ -117,11 +117,11 @@ pub struct UpdatedRow { pub row_id: String, #[pb(index = 3)] - pub row: Row, + pub row: GridRowPB, } -impl UpdatedRow { - pub fn new(row_rev: &RowRevision, row: Row) -> Self { +impl UpdatedRowPB { + pub fn new(row_rev: &RowRevision, row: GridRowPB) -> Self { Self { row_id: row_rev.id.clone(), block_id: row_rev.block_id.clone(), @@ -130,8 +130,8 @@ impl UpdatedRow { } } -impl std::convert::From for InsertedRow { - fn from(row_info: Row) -> Self { +impl std::convert::From for InsertedRowPB { + fn from(row_info: GridRowPB) -> Self { Self { row_id: row_info.id, block_id: row_info.block_id, @@ -141,26 +141,26 @@ impl std::convert::From for InsertedRow { } } -impl std::convert::From<&RowRevision> for InsertedRow { +impl std::convert::From<&RowRevision> for InsertedRowPB { fn from(row: &RowRevision) -> Self { - let row_order = Row::from(row); + let row_order = GridRowPB::from(row); Self::from(row_order) } } #[derive(Debug, Default, ProtoBuf)] -pub struct GridBlockChangeset { +pub struct GridBlockChangesetPB { #[pb(index = 1)] pub block_id: String, #[pb(index = 2)] - pub inserted_rows: Vec, + pub inserted_rows: Vec, #[pb(index = 3)] pub deleted_rows: Vec, #[pb(index = 4)] - pub updated_rows: Vec, + pub updated_rows: Vec, #[pb(index = 5)] pub visible_rows: Vec, @@ -168,8 +168,8 @@ pub struct GridBlockChangeset { #[pb(index = 6)] pub hide_rows: Vec, } -impl GridBlockChangeset { - pub fn insert(block_id: &str, inserted_rows: Vec) -> Self { +impl GridBlockChangesetPB { + pub fn insert(block_id: &str, inserted_rows: Vec) -> Self { Self { block_id: block_id.to_owned(), inserted_rows, @@ -185,7 +185,7 @@ impl GridBlockChangeset { } } - pub fn update(block_id: &str, updated_rows: Vec) -> Self { + pub fn update(block_id: &str, updated_rows: Vec) -> Self { Self { block_id: block_id.to_owned(), updated_rows, @@ -195,7 +195,7 @@ impl GridBlockChangeset { } #[derive(ProtoBuf, Default)] -pub struct QueryGridBlocksPayload { +pub struct QueryGridBlocksPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -208,7 +208,7 @@ pub struct QueryGridBlocksParams { pub block_ids: Vec, } -impl TryInto for QueryGridBlocksPayload { +impl TryInto for QueryGridBlocksPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs index f7daa84147..57993a27db 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs @@ -1,4 +1,4 @@ -use crate::entities::{FieldIdentifier, FieldIdentifierPayload}; +use crate::entities::{FieldIdentifier, FieldIdentifierPayloadPB}; use flowy_derive::ProtoBuf; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; @@ -8,7 +8,7 @@ use std::collections::HashMap; #[derive(ProtoBuf, Default)] pub struct CreateSelectOptionPayload { #[pb(index = 1)] - pub field_identifier: FieldIdentifierPayload, + pub field_identifier: FieldIdentifierPayloadPB, #[pb(index = 2)] pub option_name: String, 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 f7fa70455c..1a4fac2e8c 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use strum_macros::{Display, EnumCount as EnumCountMacro, EnumIter, EnumString}; #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct Field { +pub struct FieldPB { #[pb(index = 1)] pub id: String, @@ -35,7 +35,7 @@ pub struct Field { pub is_primary: bool, } -impl std::convert::From for Field { +impl std::convert::From for FieldPB { fn from(field_rev: FieldRevision) -> Self { Self { id: field_rev.id, @@ -50,31 +50,31 @@ impl std::convert::From for Field { } } -impl std::convert::From> for Field { +impl std::convert::From> for FieldPB { fn from(field_rev: Arc) -> Self { let field_rev = field_rev.as_ref().clone(); - Field::from(field_rev) + FieldPB::from(field_rev) } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridField { +pub struct GridFieldPB { #[pb(index = 1)] pub field_id: String, } -impl std::convert::From<&str> for GridField { +impl std::convert::From<&str> for GridFieldPB { fn from(s: &str) -> Self { - GridField { field_id: s.to_owned() } + GridFieldPB { field_id: s.to_owned() } } } -impl std::convert::From for GridField { +impl std::convert::From for GridFieldPB { fn from(s: String) -> Self { - GridField { field_id: s } + GridFieldPB { field_id: s } } } -impl std::convert::From<&Arc> for GridField { +impl std::convert::From<&Arc> for GridFieldPB { fn from(field_rev: &Arc) -> Self { Self { field_id: field_rev.id.clone(), @@ -82,22 +82,22 @@ impl std::convert::From<&Arc> for GridField { } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridFieldChangeset { +pub struct GridFieldChangesetPB { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] - pub inserted_fields: Vec, + 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 GridFieldChangeset { - pub fn insert(grid_id: &str, inserted_fields: Vec) -> Self { +impl GridFieldChangesetPB { + pub fn insert(grid_id: &str, inserted_fields: Vec) -> Self { Self { grid_id: grid_id.to_owned(), inserted_fields, @@ -106,7 +106,7 @@ impl GridFieldChangeset { } } - 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![], @@ -115,7 +115,7 @@ impl GridFieldChangeset { } } - 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![], @@ -126,25 +126,25 @@ impl GridFieldChangeset { } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct IndexField { +pub struct IndexFieldPB { #[pb(index = 1)] - pub field: Field, + pub field: FieldPB, #[pb(index = 2)] pub index: i32, } -impl IndexField { +impl IndexFieldPB { pub fn from_field_rev(field_rev: &Arc, index: usize) -> Self { Self { - field: Field::from(field_rev.as_ref().clone()), + field: FieldPB::from(field_rev.as_ref().clone()), index: index as i32, } } } #[derive(Debug, Default, ProtoBuf)] -pub struct GetEditFieldContextPayload { +pub struct GetEditFieldContextPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -156,7 +156,7 @@ pub struct GetEditFieldContextPayload { } #[derive(Debug, Default, ProtoBuf)] -pub struct EditFieldPayload { +pub struct EditFieldPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -176,7 +176,7 @@ pub struct EditFieldParams { pub field_type: FieldType, } -impl TryInto for EditFieldPayload { +impl TryInto for EditFieldPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -195,7 +195,7 @@ pub struct CreateFieldParams { pub field_type: FieldType, } -impl TryInto for EditFieldPayload { +impl TryInto for EditFieldPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -209,87 +209,75 @@ impl TryInto for EditFieldPayload { } #[derive(Debug, Default, ProtoBuf)] -pub struct FieldTypeOptionContext { +pub struct FieldTypeOptionDataPB { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] - pub grid_field: Field, + pub field: FieldPB, #[pb(index = 3)] pub type_option_data: Vec, } #[derive(Debug, Default, ProtoBuf)] -pub struct FieldTypeOptionData { +pub struct RepeatedFieldPB { #[pb(index = 1)] - pub grid_id: String, - - #[pb(index = 2)] - pub field: Field, - - #[pb(index = 3)] - pub type_option_data: Vec, + pub items: Vec, } - -#[derive(Debug, Default, ProtoBuf)] -pub struct RepeatedField { - #[pb(index = 1)] - pub items: Vec, -} -impl std::ops::Deref for RepeatedField { - type Target = Vec; +impl std::ops::Deref for RepeatedFieldPB { + type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } -impl std::ops::DerefMut for RepeatedField { +impl std::ops::DerefMut for RepeatedFieldPB { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } } -impl std::convert::From> for RepeatedField { - 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 RepeatedFieldOrder { +pub struct RepeatedGridFieldPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::ops::Deref for RepeatedFieldOrder { - type Target = Vec; +impl std::ops::Deref for RepeatedGridFieldPB { + type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } -impl std::convert::From> for RepeatedFieldOrder { - fn from(field_orders: Vec) -> Self { - RepeatedFieldOrder { items: field_orders } +impl std::convert::From> for RepeatedGridFieldPB { + fn from(field_orders: Vec) -> Self { + RepeatedGridFieldPB { items: field_orders } } } -impl std::convert::From for RepeatedFieldOrder { +impl std::convert::From for RepeatedGridFieldPB { fn from(s: String) -> Self { - RepeatedFieldOrder { - items: vec![GridField::from(s)], + RepeatedGridFieldPB { + items: vec![GridFieldPB::from(s)], } } } #[derive(ProtoBuf, Default)] -pub struct InsertFieldPayload { +pub struct InsertFieldPayloadPB { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] - pub field: Field, + pub field: FieldPB, #[pb(index = 3)] pub type_option_data: Vec, @@ -301,12 +289,12 @@ pub struct InsertFieldPayload { #[derive(Clone)] pub struct InsertFieldParams { pub grid_id: String, - pub field: Field, + pub field: FieldPB, pub type_option_data: Vec, pub start_field_id: Option, } -impl TryInto for InsertFieldPayload { +impl TryInto for InsertFieldPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -328,7 +316,7 @@ impl TryInto for InsertFieldPayload { } #[derive(ProtoBuf, Default)] -pub struct UpdateFieldTypeOptionPayload { +pub struct UpdateFieldTypeOptionPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -346,7 +334,7 @@ pub struct UpdateFieldTypeOptionParams { pub type_option_data: Vec, } -impl TryInto for UpdateFieldTypeOptionPayload { +impl TryInto for UpdateFieldTypeOptionPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -362,20 +350,20 @@ impl TryInto for UpdateFieldTypeOptionPayload { } #[derive(ProtoBuf, Default)] -pub struct QueryFieldPayload { +pub struct QueryFieldPayloadPB { #[pb(index = 1)] pub grid_id: String, #[pb(index = 2)] - pub field_orders: RepeatedFieldOrder, + pub field_orders: RepeatedGridFieldPB, } pub struct QueryFieldParams { pub grid_id: String, - pub field_orders: RepeatedFieldOrder, + pub field_orders: RepeatedGridFieldPB, } -impl TryInto for QueryFieldPayload { +impl TryInto for QueryFieldPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -388,7 +376,7 @@ impl TryInto for QueryFieldPayload { } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct FieldChangesetPayload { +pub struct FieldChangesetPayloadPB { #[pb(index = 1)] pub field_id: String, @@ -417,7 +405,7 @@ pub struct FieldChangesetPayload { pub type_option_data: Option>, } -impl TryInto for FieldChangesetPayload { +impl TryInto for FieldChangesetPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -569,7 +557,7 @@ impl std::convert::From for FieldType { } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct FieldIdentifierPayload { +pub struct FieldIdentifierPayloadPB { #[pb(index = 1)] pub field_id: String, @@ -582,7 +570,7 @@ pub struct FieldIdentifier { pub grid_id: String, } -impl TryInto for FieldIdentifierPayload { +impl TryInto for FieldIdentifierPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs index bc520dea54..03cc3d6111 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/util.rs @@ -17,7 +17,7 @@ pub struct GridFilter { } #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct RepeatedGridFilter { +pub struct RepeatedGridFilterPB { #[pb(index = 1)] pub items: Vec, } @@ -28,22 +28,22 @@ impl std::convert::From<&GridFilterRevision> for GridFilter { } } -impl std::convert::From>> for RepeatedGridFilter { +impl std::convert::From>> for RepeatedGridFilterPB { fn from(revs: Vec>) -> Self { - RepeatedGridFilter { + RepeatedGridFilterPB { items: revs.into_iter().map(|rev| rev.as_ref().into()).collect(), } } } -impl std::convert::From> for RepeatedGridFilter { +impl std::convert::From> for RepeatedGridFilterPB { fn from(items: Vec) -> Self { Self { items } } } #[derive(ProtoBuf, Debug, Default, Clone)] -pub struct DeleteFilterPayload { +pub struct DeleteFilterPayloadPB { #[pb(index = 1)] pub field_id: String, @@ -54,7 +54,7 @@ pub struct DeleteFilterPayload { pub field_type: FieldType, } -impl TryInto for DeleteFilterPayload { +impl TryInto for DeleteFilterPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -73,7 +73,7 @@ impl TryInto for DeleteFilterPayload { } #[derive(ProtoBuf, Debug, Default, Clone)] -pub struct CreateGridFilterPayload { +pub struct CreateGridFilterPayloadPB { #[pb(index = 1)] pub field_id: String, @@ -87,7 +87,7 @@ pub struct CreateGridFilterPayload { pub content: Option, } -impl CreateGridFilterPayload { +impl CreateGridFilterPayloadPB { #[allow(dead_code)] pub fn new>(field_rev: &FieldRevision, condition: T, content: Option) -> Self { Self { @@ -99,7 +99,7 @@ impl CreateGridFilterPayload { } } -impl TryInto for CreateGridFilterPayload { +impl TryInto for CreateGridFilterPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { 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 1cc6f2ba45..d333f201a4 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/grid_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/grid_entities.rs @@ -1,69 +1,69 @@ -use crate::entities::{GridBlock, GridField}; +use crate::entities::{GridBlockPB, GridFieldPB}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct Grid { +pub struct GridPB { #[pb(index = 1)] pub id: String, #[pb(index = 2)] - pub fields: Vec, + pub fields: Vec, #[pb(index = 3)] - pub blocks: Vec, + pub blocks: Vec, } #[derive(ProtoBuf, Default)] -pub struct CreateGridPayload { +pub struct CreateGridPayloadPB { #[pb(index = 1)] pub name: String, } #[derive(Clone, ProtoBuf, Default, Debug)] -pub struct GridId { +pub struct GridIdPB { #[pb(index = 1)] pub value: String, } -impl AsRef for GridId { +impl AsRef for GridIdPB { fn as_ref(&self) -> &str { &self.value } } #[derive(Clone, ProtoBuf, Default, Debug)] -pub struct GridBlockId { +pub struct GridBlockIdPB { #[pb(index = 1)] pub value: String, } -impl AsRef for GridBlockId { +impl AsRef for GridBlockIdPB { fn as_ref(&self) -> &str { &self.value } } -impl std::convert::From<&str> for GridBlockId { +impl std::convert::From<&str> for GridBlockIdPB { fn from(s: &str) -> Self { - GridBlockId { value: s.to_owned() } + GridBlockIdPB { value: s.to_owned() } } } #[derive(Debug, Clone, ProtoBuf_Enum)] -pub enum MoveItemType { +pub enum MoveItemTypePB { MoveField = 0, MoveRow = 1, } -impl std::default::Default for MoveItemType { +impl std::default::Default for MoveItemTypePB { fn default() -> Self { - MoveItemType::MoveField + MoveItemTypePB::MoveField } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct MoveItemPayload { +pub struct MoveItemPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -77,7 +77,7 @@ pub struct MoveItemPayload { pub to_index: i32, #[pb(index = 5)] - pub ty: MoveItemType, + pub ty: MoveItemTypePB, } #[derive(Clone)] @@ -86,10 +86,10 @@ pub struct MoveItemParams { pub item_id: String, pub from_index: i32, pub to_index: i32, - pub ty: MoveItemType, + pub ty: MoveItemTypePB, } -impl TryInto for MoveItemPayload { +impl TryInto for MoveItemPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-grid/src/entities/group_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/group_entities.rs index 53d20bbc57..dda624fc67 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/group_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/group_entities.rs @@ -7,7 +7,7 @@ use std::convert::TryInto; use std::sync::Arc; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct GridGroup { +pub struct GridGroupPB { #[pb(index = 1)] pub id: String, @@ -18,9 +18,9 @@ pub struct GridGroup { pub sub_group_field_id: Option, } -impl std::convert::From<&GridGroupRevision> for GridGroup { +impl std::convert::From<&GridGroupRevision> for GridGroupPB { fn from(rev: &GridGroupRevision) -> Self { - GridGroup { + GridGroupPB { id: rev.id.clone(), group_field_id: rev.field_id.clone(), sub_group_field_id: rev.sub_field_id.clone(), @@ -29,27 +29,27 @@ impl std::convert::From<&GridGroupRevision> for GridGroup { } #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct RepeatedGridGroup { +pub struct RepeatedGridGroupPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::convert::From> for RepeatedGridGroup { - fn from(items: Vec) -> Self { +impl std::convert::From> for RepeatedGridGroupPB { + fn from(items: Vec) -> Self { Self { items } } } -impl std::convert::From>> for RepeatedGridGroup { +impl std::convert::From>> for RepeatedGridGroupPB { fn from(revs: Vec>) -> Self { - RepeatedGridGroup { + RepeatedGridGroupPB { items: revs.iter().map(|rev| rev.as_ref().into()).collect(), } } } #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct CreateGridGroupPayload { +pub struct CreateGridGroupPayloadPB { #[pb(index = 1, one_of)] pub field_id: Option, @@ -57,7 +57,7 @@ pub struct CreateGridGroupPayload { pub sub_field_id: Option, } -impl TryInto for CreateGridGroupPayload { +impl TryInto for CreateGridGroupPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { 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 4b3c8a7a78..f66e1c1d06 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(ProtoBuf, Default)] -pub struct GridRowIdPayload { +pub struct GridRowIdPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -15,7 +15,7 @@ pub struct GridRowIdPayload { } #[derive(Debug, Default, Clone, ProtoBuf)] -pub struct GridRowId { +pub struct GridRowIdPB { #[pb(index = 1)] pub grid_id: String, @@ -26,15 +26,15 @@ pub struct GridRowId { pub row_id: String, } -impl TryInto for GridRowIdPayload { +impl TryInto for GridRowIdPayloadPB { 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(GridRowId { + Ok(GridRowIdPB { grid_id: grid_id.0, block_id: block_id.0, row_id: row_id.0, @@ -43,7 +43,7 @@ impl TryInto for GridRowIdPayload { } #[derive(Debug, Default, Clone, ProtoBuf)] -pub struct BlockRowId { +pub struct BlockRowIdPB { #[pb(index = 1)] pub block_id: String, @@ -52,7 +52,7 @@ pub struct BlockRowId { } #[derive(ProtoBuf, Default)] -pub struct CreateRowPayload { +pub struct CreateRowPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -66,7 +66,7 @@ pub struct CreateRowParams { pub start_row_id: Option, } -impl TryInto for CreateRowPayload { +impl TryInto for CreateRowPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs index 740ab38def..9272cfe46d 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/setting_entities.rs @@ -1,6 +1,6 @@ use crate::entities::{ - CreateGridFilterPayload, CreateGridGroupPayload, CreateGridSortPayload, DeleteFilterPayload, RepeatedGridFilter, - RepeatedGridGroup, RepeatedGridSort, + CreateGridFilterPayloadPB, CreateGridGroupPayloadPB, CreateGridSortPayloadPB, DeleteFilterPayloadPB, + RepeatedGridFilterPB, RepeatedGridGroupPB, RepeatedGridSortPB, }; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_error::ErrorCode; @@ -13,34 +13,34 @@ use strum::IntoEnumIterator; use strum_macros::EnumIter; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct GridSetting { +pub struct GridSettingPB { #[pb(index = 1)] - pub layouts: Vec, + pub layouts: Vec, #[pb(index = 2)] pub current_layout_type: GridLayoutType, #[pb(index = 3)] - pub filters_by_field_id: HashMap, + pub filters_by_field_id: HashMap, #[pb(index = 4)] - pub groups_by_field_id: HashMap, + pub groups_by_field_id: HashMap, #[pb(index = 5)] - pub sorts_by_field_id: HashMap, + pub sorts_by_field_id: HashMap, } #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct GridLayout { +pub struct GridLayoutPB { #[pb(index = 1)] ty: GridLayoutType, } -impl GridLayout { - pub fn all() -> Vec { +impl GridLayoutPB { + pub fn all() -> Vec { let mut layouts = vec![]; for layout_ty in GridLayoutType::iter() { - layouts.push(GridLayout { ty: layout_ty }) + layouts.push(GridLayoutPB { ty: layout_ty }) } layouts @@ -79,7 +79,7 @@ impl std::convert::From for GridLayoutRevision { } #[derive(Default, ProtoBuf)] -pub struct GridSettingChangesetPayload { +pub struct GridSettingChangesetPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -87,25 +87,25 @@ pub struct GridSettingChangesetPayload { pub layout_type: GridLayoutType, #[pb(index = 3, one_of)] - pub insert_filter: Option, + pub insert_filter: Option, #[pb(index = 4, one_of)] - pub delete_filter: Option, + pub delete_filter: Option, #[pb(index = 5, one_of)] - pub insert_group: Option, + pub insert_group: Option, #[pb(index = 6, one_of)] pub delete_group: Option, #[pb(index = 7, one_of)] - pub insert_sort: Option, + pub insert_sort: Option, #[pb(index = 8, one_of)] pub delete_sort: Option, } -impl TryInto for GridSettingChangesetPayload { +impl TryInto for GridSettingChangesetPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs index 3a560460fe..b630b000c5 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/sort_entities.rs @@ -26,32 +26,32 @@ impl std::convert::From<&GridSortRevision> for GridSort { } #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct RepeatedGridSort { +pub struct RepeatedGridSortPB { #[pb(index = 1)] pub items: Vec, } -impl std::convert::From>> for RepeatedGridSort { +impl std::convert::From>> for RepeatedGridSortPB { fn from(revs: Vec>) -> Self { - RepeatedGridSort { + RepeatedGridSortPB { items: revs.into_iter().map(|rev| rev.as_ref().into()).collect(), } } } -impl std::convert::From> for RepeatedGridSort { +impl std::convert::From> for RepeatedGridSortPB { fn from(items: Vec) -> Self { Self { items } } } #[derive(ProtoBuf, Debug, Default, Clone)] -pub struct CreateGridSortPayload { +pub struct CreateGridSortPayloadPB { #[pb(index = 1, one_of)] pub field_id: Option, } -impl TryInto for CreateGridSortPayload { +impl TryInto for CreateGridSortPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-grid/src/event_handler.rs b/frontend/rust-lib/flowy-grid/src/event_handler.rs index 52c3c3424c..81f74c8e32 100644 --- a/frontend/rust-lib/flowy-grid/src/event_handler.rs +++ b/frontend/rust-lib/flowy-grid/src/event_handler.rs @@ -3,9 +3,9 @@ use crate::manager::GridManager; use crate::services::cell::AnyCellData; use crate::services::field::{ default_type_option_builder_from_type, select_option_operation, type_option_builder_from_json_str, - DateChangesetParams, DateChangesetPayload, SelectOption, SelectOptionCellChangeset, - SelectOptionCellChangesetParams, SelectOptionCellChangesetPayload, SelectOptionCellData, SelectOptionChangeset, - SelectOptionChangesetPayload, + DateChangesetParams, DateChangesetPayloadPB, SelectOptionPB, SelectOptionCellChangeset, + SelectOptionCellChangesetParams, SelectOptionCellChangesetPayloadPB, SelectOptionCellDataPB, SelectOptionChangeset, + SelectOptionChangesetPayloadPB, }; use crate::services::row::make_row_from_row_rev; use flowy_error::{ErrorCode, FlowyError, FlowyResult}; @@ -16,10 +16,10 @@ use std::sync::Arc; #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn get_grid_handler( - data: Data, + data: Data, manager: AppData>, -) -> DataResult { - let grid_id: GridId = data.into_inner(); +) -> DataResult { + let grid_id: GridIdPB = data.into_inner(); let editor = manager.open_grid(grid_id).await?; let grid = editor.get_grid_data().await?; data_result(grid) @@ -27,10 +27,10 @@ pub(crate) async fn get_grid_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn get_grid_setting_handler( - data: Data, + data: Data, manager: AppData>, -) -> DataResult { - let grid_id: GridId = data.into_inner(); +) -> DataResult { + let grid_id: GridIdPB = data.into_inner(); let editor = manager.open_grid(grid_id).await?; let grid_setting = editor.get_grid_setting().await?; data_result(grid_setting) @@ -38,7 +38,7 @@ pub(crate) async fn get_grid_setting_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn update_grid_setting_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: GridSettingChangesetParams = data.into_inner().try_into()?; @@ -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?; @@ -60,9 +60,9 @@ pub(crate) async fn get_grid_blocks_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn get_fields_handler( - data: Data, + 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,13 +72,13 @@ 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: RepeatedField = field_revs.into_iter().map(Field::from).collect::>().into(); + let repeated_field: RepeatedFieldPB = field_revs.into_iter().map(FieldPB::from).collect::>().into(); data_result(repeated_field) } #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn update_field_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let changeset: FieldChangesetParams = data.into_inner().try_into()?; @@ -89,7 +89,7 @@ pub(crate) async fn update_field_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn insert_field_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: InsertFieldParams = data.into_inner().try_into()?; @@ -100,7 +100,7 @@ pub(crate) async fn insert_field_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn update_field_type_option_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: UpdateFieldTypeOptionParams = data.into_inner().try_into()?; @@ -113,7 +113,7 @@ pub(crate) async fn update_field_type_option_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn delete_field_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: FieldIdentifier = data.into_inner().try_into()?; @@ -124,9 +124,9 @@ pub(crate) async fn delete_field_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn switch_to_field_handler( - data: Data, + data: Data, manager: AppData>, -) -> DataResult { +) -> DataResult { let params: EditFieldParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; editor @@ -140,7 +140,7 @@ pub(crate) async fn switch_to_field_handler( .unwrap_or(Arc::new(editor.next_field_rev(¶ms.field_type).await?)); let type_option_data = get_type_option_data(&field_rev, ¶ms.field_type).await?; - let data = FieldTypeOptionData { + let data = FieldTypeOptionDataPB { grid_id: params.grid_id, field: field_rev.into(), type_option_data, @@ -151,7 +151,7 @@ pub(crate) async fn switch_to_field_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn duplicate_field_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: FieldIdentifier = data.into_inner().try_into()?; @@ -163,9 +163,9 @@ 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 { +) -> DataResult { let params: EditFieldParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; match editor.get_field_rev(¶ms.field_id).await { @@ -173,7 +173,7 @@ pub(crate) async fn get_field_type_option_data_handler( Some(field_rev) => { let field_type = field_rev.field_type_rev.into(); let type_option_data = get_type_option_data(&field_rev, &field_type).await?; - let data = FieldTypeOptionData { + let data = FieldTypeOptionDataPB { grid_id: params.grid_id, field: field_rev.into(), type_option_data, @@ -186,16 +186,16 @@ pub(crate) async fn get_field_type_option_data_handler( /// Create FieldMeta and save it. Return the FieldTypeOptionData. #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn create_field_type_option_data_handler( - data: Data, + data: Data, manager: AppData>, -) -> DataResult { +) -> DataResult { let params: CreateFieldParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let field_rev = editor.create_next_field_rev(¶ms.field_type).await?; let field_type: FieldType = field_rev.field_type_rev.into(); let type_option_data = get_type_option_data(&field_rev, &field_type).await?; - data_result(FieldTypeOptionData { + data_result(FieldTypeOptionDataPB { grid_id: params.grid_id, field: field_rev.into(), type_option_data, @@ -204,7 +204,7 @@ pub(crate) async fn create_field_type_option_data_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn move_item_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: MoveItemParams = data.into_inner().try_into()?; @@ -227,25 +227,25 @@ 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: GridRowId = data.into_inner().try_into()?; +) -> DataResult { + let params: GridRowIdPB = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let row = editor .get_row_rev(¶ms.row_id) .await? .and_then(make_row_from_row_rev); - data_result(OptionalRow { row }) + data_result(OptionalRowPB { row }) } #[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: GridRowId = data.into_inner().try_into()?; + let params: GridRowIdPB = 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: GridRowId = data.into_inner().try_into()?; + let params: GridRowIdPB = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let _ = editor.duplicate_row(¶ms.row_id).await?; Ok(()) @@ -264,7 +264,7 @@ pub(crate) async fn duplicate_row_handler( #[tracing::instrument(level = "debug", skip(data, manager), err)] pub(crate) async fn create_row_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: CreateRowParams = data.into_inner().try_into()?; @@ -301,7 +301,7 @@ pub(crate) async fn update_cell_handler( pub(crate) async fn new_select_option_handler( data: Data, manager: AppData>, -) -> DataResult { +) -> DataResult { let params: CreateSelectOptionParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; match editor.get_field_rev(¶ms.field_id).await { @@ -316,7 +316,7 @@ pub(crate) async fn new_select_option_handler( #[tracing::instrument(level = "trace", skip_all, err)] pub(crate) async fn update_select_option_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let changeset: SelectOptionChangeset = data.into_inner().try_into()?; @@ -359,13 +359,13 @@ pub(crate) async fn update_select_option_handler( pub(crate) async fn get_select_option_handler( data: Data, manager: AppData>, -) -> DataResult { +) -> DataResult { let params: CellIdentifier = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; match editor.get_field_rev(¶ms.field_id).await { None => { tracing::error!("Can't find the select option field with id: {}", params.field_id); - data_result(SelectOptionCellData::default()) + data_result(SelectOptionCellDataPB::default()) } Some(field_rev) => { // @@ -386,7 +386,7 @@ pub(crate) async fn get_select_option_handler( #[tracing::instrument(level = "trace", skip_all, err)] pub(crate) async fn update_select_option_cell_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: SelectOptionCellChangesetParams = data.into_inner().try_into()?; @@ -397,7 +397,7 @@ pub(crate) async fn update_select_option_cell_handler( #[tracing::instrument(level = "trace", skip_all, err)] pub(crate) async fn update_date_cell_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { let params: DateChangesetParams = data.into_inner().try_into()?; 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 c52f0662ec..0bbd3b09f0 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::{CellChangeset, GridBlockChangeset, InsertedRow, Row, UpdatedRow}; +use crate::entities::{CellChangeset, GridBlockChangesetPB, GridRowPB, InsertedRowPB, UpdatedRowPB}; use crate::manager::GridUser; use crate::services::block_revision_editor::GridBlockRevisionEditor; use crate::services::persistence::block_index::BlockIndexCache; @@ -71,12 +71,12 @@ impl GridBlockManager { let _ = self.persistence.insert(&row_rev.block_id, &row_rev.id)?; let editor = self.get_editor(&row_rev.block_id).await?; - let mut index_row_order = InsertedRow::from(&row_rev); + let mut index_row_order = InsertedRowPB::from(&row_rev); let (row_count, row_index) = editor.create_row(row_rev, start_row_id).await?; index_row_order.index = row_index; let _ = self - .notify_did_update_block(block_id, GridBlockChangeset::insert(block_id, vec![index_row_order])) + .notify_did_update_block(block_id, GridBlockChangesetPB::insert(block_id, vec![index_row_order])) .await?; Ok(row_count) } @@ -92,7 +92,7 @@ impl GridBlockManager { let mut row_count = 0; for row in row_revs { let _ = self.persistence.insert(&row.block_id, &row.id)?; - let mut row_order = InsertedRow::from(&row); + let mut row_order = InsertedRowPB::from(&row); let (count, index) = editor.create_row(row, None).await?; row_count = count; row_order.index = index; @@ -101,7 +101,7 @@ impl GridBlockManager { changesets.push(GridBlockMetaRevisionChangeset::from_row_count(&block_id, row_count)); let _ = self - .notify_did_update_block(&block_id, GridBlockChangeset::insert(&block_id, inserted_row_orders)) + .notify_did_update_block(&block_id, GridBlockChangesetPB::insert(&block_id, inserted_row_orders)) .await?; } @@ -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?; @@ -118,8 +118,8 @@ impl GridBlockManager { None => tracing::error!("Internal error: can't find the row with id: {}", changeset.row_id), Some(row_rev) => { if let Some(row) = row_builder(row_rev.clone()) { - let row_order = UpdatedRow::new(&row_rev, row); - let block_order_changeset = GridBlockChangeset::update(&editor.block_id, vec![row_order]); + let row_order = UpdatedRowPB::new(&row_rev, row); + let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![row_order]); let _ = self .notify_did_update_block(&editor.block_id, block_order_changeset) .await?; @@ -138,7 +138,7 @@ impl GridBlockManager { Some(row_info) => { let _ = editor.delete_rows(vec![Cow::Borrowed(&row_id)]).await?; let _ = self - .notify_did_update_block(&block_id, GridBlockChangeset::delete(&block_id, vec![row_info.id])) + .notify_did_update_block(&block_id, GridBlockChangesetPB::delete(&block_id, vec![row_info.id])) .await?; } } @@ -146,7 +146,10 @@ 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?; @@ -170,14 +173,14 @@ impl GridBlockManager { match editor.get_row_revs(Some(vec![Cow::Borrowed(row_id)])).await?.pop() { None => {} Some(row_rev) => { - let insert_row = InsertedRow { + let insert_row = InsertedRowPB { block_id: row_rev.block_id.clone(), row_id: row_rev.id.clone(), index: Some(to as i32), height: row_rev.height, }; - let notified_changeset = GridBlockChangeset { + let notified_changeset = GridBlockChangesetPB { block_id: editor.block_id.clone(), inserted_rows: vec![insert_row], deleted_rows: vec![row_rev.id.clone()], @@ -195,7 +198,7 @@ impl GridBlockManager { pub async fn update_cell(&self, changeset: CellChangeset, 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?; @@ -214,7 +217,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 } @@ -244,7 +247,7 @@ impl GridBlockManager { Ok(snapshots) } - async fn notify_did_update_block(&self, block_id: &str, changeset: GridBlockChangeset) -> FlowyResult<()> { + async fn notify_did_update_block(&self, block_id: &str, changeset: GridBlockChangesetPB) -> FlowyResult<()> { send_dart_notification(block_id, GridNotification::DidUpdateGridBlock) .payload(changeset) .send(); 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 99d851a7d5..3b94665283 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::Row; +use crate::entities::GridRowPB; 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(Row::from) - .collect::>(); + .map(GridRowPB::from) + .collect::>(); Ok(row_infos) } diff --git a/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs b/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs index b4729c6925..e34f3a8430 100644 --- a/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs +++ b/frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs @@ -58,7 +58,9 @@ pub fn apply_cell_data_changeset>( FieldType::RichText => RichTextTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev), FieldType::Number => NumberTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev), FieldType::DateTime => DateTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev), - FieldType::SingleSelect => SingleSelectTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev), + FieldType::SingleSelect => { + SingleSelectTypeOptionPB::from(field_rev).apply_changeset(changeset.into(), cell_rev) + } FieldType::MultiSelect => MultiSelectTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev), FieldType::Checkbox => CheckboxTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev), FieldType::URL => URLTypeOption::from(field_rev).apply_changeset(changeset.into(), cell_rev), @@ -104,7 +106,7 @@ pub fn try_decode_cell_data( .get_type_option_entry::(field_type)? .decode_cell_data(cell_data.into(), s_field_type, field_rev), FieldType::SingleSelect => field_rev - .get_type_option_entry::(field_type)? + .get_type_option_entry::(field_type)? .decode_cell_data(cell_data.into(), s_field_type, field_rev), FieldType::MultiSelect => field_rev .get_type_option_entry::(field_type)? 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 352d3e7f5c..dea6686915 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::{Field, FieldType}; +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: Field, 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, @@ -93,7 +93,7 @@ pub fn default_type_option_builder_from_type(field_type: &FieldType) -> Box RichTextTypeOption::default().into(), FieldType::Number => NumberTypeOption::default().into(), FieldType::DateTime => DateTypeOption::default().into(), - FieldType::SingleSelect => SingleSelectTypeOption::default().into(), + FieldType::SingleSelect => SingleSelectTypeOptionPB::default().into(), FieldType::MultiSelect => MultiSelectTypeOption::default().into(), FieldType::Checkbox => CheckboxTypeOption::default().into(), FieldType::URL => URLTypeOption::default().into(), diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs index 0c81268f77..5bb2b1c415 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_tests.rs @@ -14,7 +14,7 @@ mod tests { let field_rev = FieldBuilder::from_field_type(&field_type).build(); assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some("1e".to_string()), time: Some("23:00".to_owned()), }, @@ -60,7 +60,7 @@ mod tests { TimeFormat::TwentyFourHour => { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(1653609600.to_string()), time: None, }, @@ -70,7 +70,7 @@ mod tests { ); assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(1653609600.to_string()), time: Some("23:00".to_owned()), }, @@ -82,7 +82,7 @@ mod tests { TimeFormat::TwelveHour => { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(1653609600.to_string()), time: None, }, @@ -93,7 +93,7 @@ mod tests { // assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(1653609600.to_string()), time: Some("".to_owned()), }, @@ -104,7 +104,7 @@ mod tests { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(1653609600.to_string()), time: Some("11:23 pm".to_owned()), }, @@ -126,7 +126,7 @@ mod tests { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(date_timestamp.clone()), time: None, }, @@ -138,7 +138,7 @@ mod tests { type_option.include_time = true; assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(date_timestamp.clone()), time: None, }, @@ -149,7 +149,7 @@ mod tests { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(date_timestamp.clone()), time: Some("1:00".to_owned()), }, @@ -161,7 +161,7 @@ mod tests { type_option.time_format = TimeFormat::TwelveHour; assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(date_timestamp), time: Some("1:00 am".to_owned()), }, @@ -181,7 +181,7 @@ mod tests { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(date_timestamp.clone()), time: Some("1:".to_owned()), }, @@ -192,7 +192,7 @@ mod tests { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(date_timestamp), time: Some("1:00".to_owned()), }, @@ -212,7 +212,7 @@ mod tests { assert_changeset_result( &type_option, - DateCellChangeset { + DateCellChangesetPB { date: Some(date_timestamp), time: Some("1:00 am".to_owned()), }, @@ -224,7 +224,7 @@ mod tests { fn assert_changeset_result( type_option: &DateTypeOption, - changeset: DateCellChangeset, + changeset: DateCellChangesetPB, _field_type: &FieldType, field_rev: &FieldRevision, expected: &str, @@ -243,7 +243,7 @@ mod tests { field_rev: &FieldRevision, expected: &str, ) { - let s = serde_json::to_string(&DateCellChangeset { + let s = serde_json::to_string(&DateCellChangesetPB { date: Some(timestamp.to_string()), time: None, }) diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs index 783b9faa7c..17b897b1f0 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option.rs @@ -2,7 +2,7 @@ use crate::entities::FieldType; use crate::impl_type_option; use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable}; use crate::services::field::{ - BoxTypeOptionBuilder, DateCellChangeset, DateCellData, DateFormat, DateTimestamp, TimeFormat, TypeOptionBuilder, + BoxTypeOptionBuilder, DateCellChangesetPB, DateCellDataPB, DateFormat, DateTimestamp, TimeFormat, TypeOptionBuilder, }; use bytes::Bytes; use chrono::format::strftime::StrftimeItems; @@ -32,15 +32,15 @@ impl DateTypeOption { Self::default() } - fn today_desc_from_timestamp>(&self, timestamp: T) -> DateCellData { + fn today_desc_from_timestamp>(&self, timestamp: T) -> DateCellDataPB { let timestamp = *timestamp.as_ref(); let native = chrono::NaiveDateTime::from_timestamp(timestamp, 0); self.date_from_native(native) } - fn date_from_native(&self, native: chrono::NaiveDateTime) -> DateCellData { + fn date_from_native(&self, native: chrono::NaiveDateTime) -> DateCellDataPB { if native.timestamp() == 0 { - return DateCellData::default(); + return DateCellDataPB::default(); } let time = native.time(); @@ -57,7 +57,7 @@ impl DateTypeOption { } let timestamp = native.timestamp(); - DateCellData { date, time, timestamp } + DateCellDataPB { date, time, timestamp } } fn date_fmt(&self, time: &Option) -> String { @@ -129,7 +129,7 @@ impl CellDisplayable for DateTypeOption { } } -impl CellDataOperation for DateTypeOption { +impl CellDataOperation for DateTypeOption { fn decode_cell_data( &self, cell_data: CellData, @@ -148,7 +148,7 @@ impl CellDataOperation for DateTypeOption { fn apply_changeset( &self, - changeset: CellDataChangeset, + changeset: CellDataChangeset, _cell_rev: Option, ) -> Result { let changeset = changeset.try_into_inner()?; diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option_entities.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option_entities.rs index b73c89a9b2..28dfd90dcf 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option_entities.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use strum_macros::EnumIter; #[derive(Clone, Debug, Default, ProtoBuf)] -pub struct DateCellData { +pub struct DateCellDataPB { #[pb(index = 1)] pub date: String, @@ -22,7 +22,7 @@ pub struct DateCellData { } #[derive(Clone, Debug, Default, ProtoBuf)] -pub struct DateChangesetPayload { +pub struct DateChangesetPayloadPB { #[pb(index = 1)] pub cell_identifier: CellIdentifierPayload, @@ -39,7 +39,7 @@ pub struct DateChangesetParams { pub time: Option, } -impl TryInto for DateChangesetPayload { +impl TryInto for DateChangesetPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -54,7 +54,7 @@ impl TryInto for DateChangesetPayload { impl std::convert::From for CellChangeset { fn from(params: DateChangesetParams) -> Self { - let changeset = DateCellChangeset { + let changeset = DateCellChangesetPB { date: params.date, time: params.time, }; @@ -69,12 +69,12 @@ impl std::convert::From for CellChangeset { } #[derive(Clone, Serialize, Deserialize)] -pub struct DateCellChangeset { +pub struct DateCellChangesetPB { pub date: Option, pub time: Option, } -impl DateCellChangeset { +impl DateCellChangesetPB { pub fn date_timestamp(&self) -> Option { if let Some(date) = &self.date { match date.parse::() { @@ -87,12 +87,12 @@ impl DateCellChangeset { } } -impl FromCellChangeset for DateCellChangeset { +impl FromCellChangeset for DateCellChangesetPB { fn from_changeset(changeset: String) -> FlowyResult where Self: Sized, { - serde_json::from_str::(&changeset).map_err(internal_error) + serde_json::from_str::(&changeset).map_err(internal_error) } } pub struct DateTimestamp(i64); @@ -202,9 +202,9 @@ impl std::default::Default for TimeFormat { pub struct DateCellDataParser(); impl CellBytesParser for DateCellDataParser { - type Object = DateCellData; + type Object = DateCellDataPB; fn parse(&self, bytes: &Bytes) -> FlowyResult { - DateCellData::try_from(bytes.as_ref()).map_err(internal_error) + DateCellDataPB::try_from(bytes.as_ref()).map_err(internal_error) } } diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs index 759114ca5a..187b81d060 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/multi_select_type_option.rs @@ -3,8 +3,8 @@ use crate::impl_type_option; use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable}; use crate::services::field::type_options::util::get_cell_data; use crate::services::field::{ - make_selected_select_options, BoxTypeOptionBuilder, SelectOption, SelectOptionCellChangeset, SelectOptionCellData, - SelectOptionIds, SelectOptionOperation, TypeOptionBuilder, SELECTION_IDS_SEPARATOR, + make_selected_select_options, BoxTypeOptionBuilder, SelectOptionCellChangeset, SelectOptionCellDataPB, + SelectOptionIds, SelectOptionOperation, SelectOptionPB, TypeOptionBuilder, SELECTION_IDS_SEPARATOR, }; use bytes::Bytes; use flowy_derive::ProtoBuf; @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)] pub struct MultiSelectTypeOption { #[pb(index = 1)] - pub options: Vec, + pub options: Vec, #[pb(index = 2)] pub disable_color: bool, @@ -24,19 +24,19 @@ pub struct MultiSelectTypeOption { impl_type_option!(MultiSelectTypeOption, FieldType::MultiSelect); impl SelectOptionOperation for MultiSelectTypeOption { - fn selected_select_option(&self, cell_data: CellData) -> SelectOptionCellData { + fn selected_select_option(&self, cell_data: CellData) -> SelectOptionCellDataPB { let select_options = make_selected_select_options(cell_data, &self.options); - SelectOptionCellData { + SelectOptionCellDataPB { options: self.options.clone(), select_options, } } - fn options(&self) -> &Vec { + fn options(&self) -> &Vec { &self.options } - fn mut_options(&mut self) -> &mut Vec { + fn mut_options(&mut self) -> &mut Vec { &mut self.options } } @@ -97,7 +97,7 @@ pub struct MultiSelectTypeOptionBuilder(MultiSelectTypeOption); impl_into_box_type_option_builder!(MultiSelectTypeOptionBuilder); impl_builder_from_json_str_and_from_bytes!(MultiSelectTypeOptionBuilder, MultiSelectTypeOption); impl MultiSelectTypeOptionBuilder { - pub fn option(mut self, opt: SelectOption) -> Self { + pub fn option(mut self, opt: SelectOptionPB) -> Self { self.0.options.push(opt); self } @@ -123,9 +123,9 @@ mod tests { #[test] fn multi_select_test() { - let google_option = SelectOption::new("Google"); - let facebook_option = SelectOption::new("Facebook"); - let twitter_option = SelectOption::new("Twitter"); + let google_option = SelectOptionPB::new("Google"); + let facebook_option = SelectOptionPB::new("Facebook"); + let twitter_option = SelectOptionPB::new("Twitter"); let multi_select = MultiSelectTypeOptionBuilder::default() .option(google_option.clone()) .option(facebook_option.clone()) @@ -172,7 +172,7 @@ mod tests { cell_data: String, type_option: &MultiSelectTypeOption, field_rev: &FieldRevision, - expected: Vec, + expected: Vec, ) { let field_type: FieldType = field_rev.field_type_rev.into(); assert_eq!( diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs index c06bf25957..e3dd16ef2f 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs @@ -1,6 +1,6 @@ use crate::entities::{CellChangeset, CellIdentifier, CellIdentifierPayload, FieldType}; use crate::services::cell::{CellBytes, CellBytesParser, CellData, CellDisplayable, FromCellChangeset, FromCellString}; -use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOption}; +use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB}; use bytes::Bytes; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_error::{internal_error, ErrorCode, FlowyResult}; @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; pub const SELECTION_IDS_SEPARATOR: &str = ","; #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, ProtoBuf)] -pub struct SelectOption { +pub struct SelectOptionPB { #[pb(index = 1)] pub id: String, @@ -20,20 +20,20 @@ pub struct SelectOption { pub name: String, #[pb(index = 3)] - pub color: SelectOptionColor, + pub color: SelectOptionColorPB, } -impl SelectOption { +impl SelectOptionPB { pub fn new(name: &str) -> Self { - SelectOption { + SelectOptionPB { id: nanoid!(4), name: name.to_owned(), - color: SelectOptionColor::default(), + color: SelectOptionColorPB::default(), } } - pub fn with_color(name: &str, color: SelectOptionColor) -> Self { - SelectOption { + pub fn with_color(name: &str, color: SelectOptionColorPB) -> Self { + SelectOptionPB { id: nanoid!(4), name: name.to_owned(), color, @@ -43,7 +43,7 @@ impl SelectOption { #[derive(ProtoBuf_Enum, PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] #[repr(u8)] -pub enum SelectOptionColor { +pub enum SelectOptionColorPB { Purple = 0, Pink = 1, LightPink = 2, @@ -55,16 +55,16 @@ pub enum SelectOptionColor { Blue = 8, } -impl std::default::Default for SelectOptionColor { +impl std::default::Default for SelectOptionColorPB { fn default() -> Self { - SelectOptionColor::Purple + SelectOptionColorPB::Purple } } pub fn make_selected_select_options( cell_data: CellData, - options: &[SelectOption], -) -> Vec { + options: &[SelectOptionPB], +) -> Vec { if let Ok(ids) = cell_data.try_into_inner() { ids.iter() .flat_map(|option_id| options.iter().find(|option| &option.id == option_id).cloned()) @@ -75,7 +75,7 @@ pub fn make_selected_select_options( } pub trait SelectOptionOperation: TypeOptionDataEntry + Send + Sync { - fn insert_option(&mut self, new_option: SelectOption) { + fn insert_option(&mut self, new_option: SelectOptionPB) { let options = self.mut_options(); if let Some(index) = options .iter() @@ -88,23 +88,23 @@ pub trait SelectOptionOperation: TypeOptionDataEntry + Send + Sync { } } - fn delete_option(&mut self, delete_option: SelectOption) { + fn delete_option(&mut self, delete_option: SelectOptionPB) { let options = self.mut_options(); if let Some(index) = options.iter().position(|option| option.id == delete_option.id) { options.remove(index); } } - fn create_option(&self, name: &str) -> SelectOption { + fn create_option(&self, name: &str) -> SelectOptionPB { let color = select_option_color_from_index(self.options().len()); - SelectOption::with_color(name, color) + SelectOptionPB::with_color(name, color) } - fn selected_select_option(&self, cell_data: CellData) -> SelectOptionCellData; + fn selected_select_option(&self, cell_data: CellData) -> SelectOptionCellDataPB; - fn options(&self) -> &Vec; + fn options(&self) -> &Vec; - fn mut_options(&mut self) -> &mut Vec; + fn mut_options(&mut self) -> &mut Vec; } impl CellDisplayable for T @@ -125,7 +125,7 @@ pub fn select_option_operation(field_rev: &FieldRevision) -> FlowyResult { - let type_option = SingleSelectTypeOption::from(field_rev); + let type_option = SingleSelectTypeOptionPB::from(field_rev); Ok(Box::new(type_option)) } FieldType::MultiSelect => { @@ -139,18 +139,18 @@ pub fn select_option_operation(field_rev: &FieldRevision) -> FlowyResult SelectOptionColor { +pub fn select_option_color_from_index(index: usize) -> SelectOptionColorPB { match index % 8 { - 0 => SelectOptionColor::Purple, - 1 => SelectOptionColor::Pink, - 2 => SelectOptionColor::LightPink, - 3 => SelectOptionColor::Orange, - 4 => SelectOptionColor::Yellow, - 5 => SelectOptionColor::Lime, - 6 => SelectOptionColor::Green, - 7 => SelectOptionColor::Aqua, - 8 => SelectOptionColor::Blue, - _ => SelectOptionColor::Purple, + 0 => SelectOptionColorPB::Purple, + 1 => SelectOptionColorPB::Pink, + 2 => SelectOptionColorPB::LightPink, + 3 => SelectOptionColorPB::Orange, + 4 => SelectOptionColorPB::Yellow, + 5 => SelectOptionColorPB::Lime, + 6 => SelectOptionColorPB::Green, + 7 => SelectOptionColorPB::Aqua, + 8 => SelectOptionColorPB::Blue, + _ => SelectOptionColorPB::Purple, } } pub struct SelectOptionIds(Vec); @@ -215,15 +215,15 @@ impl CellBytesParser for SelectOptionIdsParser { pub struct SelectOptionCellDataParser(); impl CellBytesParser for SelectOptionCellDataParser { - type Object = SelectOptionCellData; + type Object = SelectOptionCellDataPB; fn parse(&self, bytes: &Bytes) -> FlowyResult { - SelectOptionCellData::try_from(bytes.as_ref()).map_err(internal_error) + SelectOptionCellDataPB::try_from(bytes.as_ref()).map_err(internal_error) } } #[derive(Clone, Debug, Default, ProtoBuf)] -pub struct SelectOptionCellChangesetPayload { +pub struct SelectOptionCellChangesetPayloadPB { #[pb(index = 1)] pub cell_identifier: CellIdentifierPayload, @@ -256,7 +256,7 @@ impl std::convert::From for CellChangeset { } } -impl TryInto for SelectOptionCellChangesetPayload { +impl TryInto for SelectOptionCellChangesetPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -323,37 +323,37 @@ impl SelectOptionCellChangeset { } #[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)] -pub struct SelectOptionCellData { +pub struct SelectOptionCellDataPB { #[pb(index = 1)] - pub options: Vec, + pub options: Vec, #[pb(index = 2)] - pub select_options: Vec, + pub select_options: Vec, } #[derive(Clone, Debug, Default, ProtoBuf)] -pub struct SelectOptionChangesetPayload { +pub struct SelectOptionChangesetPayloadPB { #[pb(index = 1)] pub cell_identifier: CellIdentifierPayload, #[pb(index = 2, one_of)] - pub insert_option: Option, + pub insert_option: Option, #[pb(index = 3, one_of)] - pub update_option: Option, + pub update_option: Option, #[pb(index = 4, one_of)] - pub delete_option: Option, + pub delete_option: Option, } pub struct SelectOptionChangeset { pub cell_identifier: CellIdentifier, - pub insert_option: Option, - pub update_option: Option, - pub delete_option: Option, + pub insert_option: Option, + pub update_option: Option, + pub delete_option: Option, } -impl TryInto for SelectOptionChangesetPayload { +impl TryInto for SelectOptionChangesetPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -368,11 +368,11 @@ impl TryInto for SelectOptionChangesetPayload { } pub struct SelectedSelectOptions { - pub(crate) options: Vec, + pub(crate) options: Vec, } -impl std::convert::From for SelectedSelectOptions { - fn from(data: SelectOptionCellData) -> Self { +impl std::convert::From for SelectedSelectOptions { + fn from(data: SelectOptionCellDataPB) -> Self { Self { options: data.select_options, } diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs index 8aae4bf677..553425222e 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/single_select_type_option.rs @@ -2,8 +2,8 @@ use crate::entities::FieldType; use crate::impl_type_option; use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable}; use crate::services::field::{ - make_selected_select_options, SelectOption, SelectOptionCellChangeset, SelectOptionCellData, SelectOptionIds, - SelectOptionOperation, + make_selected_select_options, SelectOptionCellChangeset, SelectOptionCellDataPB, SelectOptionIds, + SelectOptionOperation, SelectOptionPB, }; use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder}; use bytes::Bytes; @@ -14,36 +14,36 @@ use serde::{Deserialize, Serialize}; // Single select #[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)] -pub struct SingleSelectTypeOption { +pub struct SingleSelectTypeOptionPB { #[pb(index = 1)] - pub options: Vec, + pub options: Vec, #[pb(index = 2)] pub disable_color: bool, } -impl_type_option!(SingleSelectTypeOption, FieldType::SingleSelect); +impl_type_option!(SingleSelectTypeOptionPB, FieldType::SingleSelect); -impl SelectOptionOperation for SingleSelectTypeOption { - fn selected_select_option(&self, cell_data: CellData) -> SelectOptionCellData { +impl SelectOptionOperation for SingleSelectTypeOptionPB { + fn selected_select_option(&self, cell_data: CellData) -> SelectOptionCellDataPB { let mut select_options = make_selected_select_options(cell_data, &self.options); // only keep option in single select select_options.truncate(1); - SelectOptionCellData { + SelectOptionCellDataPB { options: self.options.clone(), select_options, } } - fn options(&self) -> &Vec { + fn options(&self) -> &Vec { &self.options } - fn mut_options(&mut self) -> &mut Vec { + fn mut_options(&mut self) -> &mut Vec { &mut self.options } } -impl CellDataOperation for SingleSelectTypeOption { +impl CellDataOperation for SingleSelectTypeOptionPB { fn decode_cell_data( &self, cell_data: CellData, @@ -77,12 +77,12 @@ impl CellDataOperation for SingleSel } #[derive(Default)] -pub struct SingleSelectTypeOptionBuilder(SingleSelectTypeOption); +pub struct SingleSelectTypeOptionBuilder(SingleSelectTypeOptionPB); impl_into_box_type_option_builder!(SingleSelectTypeOptionBuilder); -impl_builder_from_json_str_and_from_bytes!(SingleSelectTypeOptionBuilder, SingleSelectTypeOption); +impl_builder_from_json_str_and_from_bytes!(SingleSelectTypeOptionBuilder, SingleSelectTypeOptionPB); impl SingleSelectTypeOptionBuilder { - pub fn option(mut self, opt: SelectOption) -> Self { + pub fn option(mut self, opt: SelectOptionPB) -> Self { self.0.options.push(opt); self } @@ -109,9 +109,9 @@ mod tests { #[test] fn single_select_test() { - let google_option = SelectOption::new("Google"); - let facebook_option = SelectOption::new("Facebook"); - let twitter_option = SelectOption::new("Twitter"); + let google_option = SelectOptionPB::new("Google"); + let facebook_option = SelectOptionPB::new("Facebook"); + let twitter_option = SelectOptionPB::new("Twitter"); let single_select = SingleSelectTypeOptionBuilder::default() .option(google_option.clone()) .option(facebook_option.clone()) @@ -122,7 +122,7 @@ mod tests { .visibility(true) .build(); - let type_option = SingleSelectTypeOption::from(&field_rev); + let type_option = SingleSelectTypeOptionPB::from(&field_rev); let option_ids = vec![google_option.id.clone(), facebook_option.id].join(SELECTION_IDS_SEPARATOR); let data = SelectOptionCellChangeset::from_insert(&option_ids).to_str(); @@ -152,9 +152,9 @@ mod tests { fn assert_single_select_options( cell_data: String, - type_option: &SingleSelectTypeOption, + type_option: &SingleSelectTypeOptionPB, field_rev: &FieldRevision, - expected: Vec, + expected: Vec, ) { let field_type: FieldType = field_rev.field_type_rev.into(); assert_eq!( diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs index 2716206dfd..b11bd026d2 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs @@ -131,7 +131,7 @@ mod tests { ); // Single select - let done_option = SelectOption::new("Done"); + let done_option = SelectOptionPB::new("Done"); let done_option_id = done_option.id.clone(); let single_select = SingleSelectTypeOptionBuilder::default().option(done_option.clone()); let single_select_field_rev = FieldBuilder::new(single_select).build(); @@ -151,8 +151,8 @@ mod tests { ); // Multiple select - let google_option = SelectOption::new("Google"); - let facebook_option = SelectOption::new("Facebook"); + let google_option = SelectOptionPB::new("Google"); + let facebook_option = SelectOptionPB::new("Facebook"); let ids = vec![google_option.id.clone(), facebook_option.id.clone()].join(SELECTION_IDS_SEPARATOR); let cell_data_changeset = SelectOptionCellChangeset::from_insert(&ids).to_str(); let multi_select = MultiSelectTypeOptionBuilder::default() diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs index 6f74bdb4d4..77f4ea767e 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs @@ -3,7 +3,7 @@ mod tests { use crate::entities::FieldType; use crate::services::cell::{CellData, CellDataOperation}; use crate::services::field::{FieldBuilder, URLCellDataParser}; - use crate::services::field::{URLCellData, URLTypeOption}; + use crate::services::field::{URLCellDataPB, URLTypeOption}; use flowy_grid_data_model::revision::FieldRevision; #[test] @@ -52,12 +52,12 @@ mod tests { assert_eq!(expected_url.to_owned(), decode_cell_data.url); } - fn decode_cell_data>>( + fn decode_cell_data>>( encoded_data: T, type_option: &URLTypeOption, field_rev: &FieldRevision, field_type: &FieldType, - ) -> URLCellData { + ) -> URLCellDataPB { type_option .decode_cell_data(encoded_data.into(), field_type, field_rev) .unwrap() diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs index 0d4ceb5caf..3fa49dac09 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option.rs @@ -1,7 +1,7 @@ use crate::entities::FieldType; use crate::impl_type_option; use crate::services::cell::{CellBytes, CellData, CellDataChangeset, CellDataOperation, CellDisplayable}; -use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder, URLCellData}; +use crate::services::field::{BoxTypeOptionBuilder, TypeOptionBuilder, URLCellDataPB}; use bytes::Bytes; use fancy_regex::Regex; use flowy_derive::ProtoBuf; @@ -32,22 +32,22 @@ pub struct URLTypeOption { } impl_type_option!(URLTypeOption, FieldType::URL); -impl CellDisplayable for URLTypeOption { +impl CellDisplayable for URLTypeOption { fn display_data( &self, - cell_data: CellData, + cell_data: CellData, _decoded_field_type: &FieldType, _field_rev: &FieldRevision, ) -> FlowyResult { - let cell_data: URLCellData = cell_data.try_into_inner()?; + let cell_data: URLCellDataPB = cell_data.try_into_inner()?; CellBytes::from(cell_data) } } -impl CellDataOperation for URLTypeOption { +impl CellDataOperation for URLTypeOption { fn decode_cell_data( &self, - cell_data: CellData, + cell_data: CellData, decoded_field_type: &FieldType, field_rev: &FieldRevision, ) -> FlowyResult { @@ -67,7 +67,7 @@ impl CellDataOperation for URLTypeOption { if let Ok(Some(m)) = URL_REGEX.find(&content) { url = auto_append_scheme(m.as_str()); } - URLCellData { url, content }.to_json() + URLCellDataPB { url, content }.to_json() } } diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option_entities.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option_entities.rs index ddb84cf9a7..6ff77cea9a 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_type_option_entities.rs @@ -5,7 +5,7 @@ use flowy_error::{internal_error, FlowyResult}; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Serialize, Deserialize, ProtoBuf)] -pub struct URLCellData { +pub struct URLCellDataPB { #[pb(index = 1)] pub url: String, @@ -13,7 +13,7 @@ pub struct URLCellData { pub content: String, } -impl URLCellData { +impl URLCellDataPB { pub fn new(s: &str) -> Self { Self { url: "".to_string(), @@ -28,15 +28,15 @@ impl URLCellData { pub struct URLCellDataParser(); impl CellBytesParser for URLCellDataParser { - type Object = URLCellData; + type Object = URLCellDataPB; fn parse(&self, bytes: &Bytes) -> FlowyResult { - URLCellData::try_from(bytes.as_ref()).map_err(internal_error) + URLCellDataPB::try_from(bytes.as_ref()).map_err(internal_error) } } -impl FromCellString for URLCellData { +impl FromCellString for URLCellDataPB { fn from_cell_str(s: &str) -> FlowyResult { - serde_json::from_str::(s).map_err(internal_error) + serde_json::from_str::(s).map_err(internal_error) } } diff --git a/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs b/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs index 6442dd4710..be02e80ebd 100644 --- a/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs +++ b/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs @@ -1,10 +1,10 @@ use crate::dart_notification::{send_dart_notification, GridNotification}; -use crate::entities::{FieldType, GridBlockChangeset}; +use crate::entities::{FieldType, GridBlockChangesetPB}; use crate::services::block_manager::GridBlockManager; use crate::services::cell::{AnyCellData, CellFilterOperation}; use crate::services::field::{ CheckboxTypeOption, DateTypeOption, MultiSelectTypeOption, NumberTypeOption, RichTextTypeOption, - SingleSelectTypeOption, URLTypeOption, + SingleSelectTypeOptionPB, URLTypeOption, }; use crate::services::filter::filter_cache::{ refresh_filter_cache, FilterCache, FilterId, FilterResult, FilterResultCache, @@ -90,7 +90,7 @@ impl GridFilterService { } } - let changeset = GridBlockChangeset { + let changeset = GridBlockChangesetPB { block_id: block.block_id, hide_rows, visible_rows, @@ -137,7 +137,7 @@ impl GridFilterService { } } - async fn notify(&self, changesets: Vec) { + async fn notify(&self, changesets: Vec) { for changeset in changesets { send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridBlock) .payload(changeset) @@ -213,7 +213,7 @@ fn filter_cell( FieldType::SingleSelect => filter_cache.select_option_filter.get(&filter_id).and_then(|filter| { Some( field_rev - .get_type_option_entry::(field_type_rev)? + .get_type_option_entry::(field_type_rev)? .apply_filter(any_cell_data, filter.value()) .ok(), ) diff --git a/frontend/rust-lib/flowy-grid/src/services/filter/impls/select_option_filter.rs b/frontend/rust-lib/flowy-grid/src/services/filter/impls/select_option_filter.rs index 82d5ab6a0b..e6cb9ff846 100644 --- a/frontend/rust-lib/flowy-grid/src/services/filter/impls/select_option_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/filter/impls/select_option_filter.rs @@ -2,7 +2,7 @@ use crate::entities::{GridSelectOptionFilter, SelectOptionCondition}; use crate::services::cell::{AnyCellData, CellFilterOperation}; -use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOption}; +use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB}; use crate::services::field::{SelectOptionOperation, SelectedSelectOptions}; use flowy_error::FlowyResult; @@ -50,7 +50,7 @@ impl CellFilterOperation for MultiSelectTypeOption { } } -impl CellFilterOperation for SingleSelectTypeOption { +impl CellFilterOperation for SingleSelectTypeOptionPB { fn apply_filter(&self, any_cell_data: AnyCellData, filter: &GridSelectOptionFilter) -> FlowyResult { if !any_cell_data.is_single_select() { return Ok(true); @@ -64,13 +64,13 @@ impl CellFilterOperation for SingleSelectTypeOption { mod tests { #![allow(clippy::all)] use crate::entities::{GridSelectOptionFilter, SelectOptionCondition}; - use crate::services::field::selection_type_option::{SelectOption, SelectedSelectOptions}; + use crate::services::field::selection_type_option::{SelectOptionPB, SelectedSelectOptions}; #[test] fn select_option_filter_is_test() { - let option_1 = SelectOption::new("A"); - let option_2 = SelectOption::new("B"); - let option_3 = SelectOption::new("C"); + let option_1 = SelectOptionPB::new("A"); + let option_2 = SelectOptionPB::new("B"); + let option_3 = SelectOptionPB::new("C"); let filter_1 = GridSelectOptionFilter { condition: SelectOptionCondition::OptionIs, 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 c312779487..a292ffa1ff 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs @@ -188,8 +188,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 = GridField::from(field_id); - let notified_changeset = GridFieldChangeset::delete(&self.grid_id, vec![field_order]); + let field_order = GridFieldPB::from(field_id); + let notified_changeset = GridFieldChangesetPB::delete(&self.grid_id, vec![field_order]); let _ = self.notify_did_update_grid(notified_changeset).await?; Ok(()) } @@ -268,13 +268,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(&field_revs).build(&block_id); - let row_order = Row::from(&row_rev); + let row_order = GridRowPB::from(&row_rev); // insert the row let row_count = self.block_manager.create_row(&block_id, row_rev, start_row_id).await?; @@ -285,12 +285,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(Row::from(&row_rev)); + row_orders.push(GridRowPB::from(&row_rev)); rows_by_block_id .entry(block_id.clone()) .or_insert_with(Vec::new) @@ -307,7 +307,7 @@ impl GridRevisionEditor { self.block_manager.update_row(changeset, make_row_from_row_rev).await } - pub async fn get_rows(&self, block_id: &str) -> FlowyResult { + pub async fn get_rows(&self, block_id: &str) -> FlowyResult { let block_ids = vec![block_id.to_owned()]; let mut grid_block_snapshot = self.grid_block_snapshots(Some(block_ids)).await?; @@ -402,7 +402,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) } @@ -412,7 +412,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?; @@ -420,31 +420,31 @@ impl GridRevisionEditor { Ok(()) } - pub async fn get_grid_data(&self) -> FlowyResult { + pub async fn get_grid_data(&self) -> FlowyResult { let pad_read_guard = self.grid_pad.read().await; let field_orders = pad_read_guard .get_field_revs(None)? .iter() - .map(GridField::from) + .map(GridFieldPB::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 = GridBlock { + let block_order = GridBlockPB { id: block_rev.block_id.clone(), rows: row_orders, }; block_orders.push(block_order); } - Ok(Grid { + Ok(GridPB { id: self.grid_id.clone(), fields: field_orders, blocks: block_orders, }) } - pub async fn get_grid_setting(&self) -> FlowyResult { + pub async fn get_grid_setting(&self) -> FlowyResult { let read_guard = self.grid_pad.read().await; let grid_setting_rev = read_guard.get_grid_setting_rev(); let field_revs = read_guard.get_field_revs(None)?; @@ -495,11 +495,11 @@ impl GridRevisionEditor { pub async fn move_item(&self, params: MoveItemParams) -> FlowyResult<()> { match params.ty { - MoveItemType::MoveField => { + MoveItemTypePB::MoveField => { self.move_field(¶ms.item_id, params.from_index, params.to_index) .await } - MoveItemType::MoveRow => self.move_row(¶ms.item_id, params.from_index, params.to_index).await, + MoveItemTypePB::MoveRow => self.move_row(¶ms.item_id, params.from_index, params.to_index).await, } } @@ -508,9 +508,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 = GridField::from(field_id); - let insert_field = IndexField::from_field_rev(field_rev, index); - let notified_changeset = GridFieldChangeset { + let delete_field_order = GridFieldPB::from(field_id); + let insert_field = IndexFieldPB::from_field_rev(field_rev, index); + let notified_changeset = GridFieldChangesetPB { grid_id: self.grid_id.clone(), inserted_fields: vec![insert_field], deleted_fields: vec![delete_field_order], @@ -599,8 +599,8 @@ impl GridRevisionEditor { #[tracing::instrument(level = "trace", skip_all, err)] 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 = IndexField::from_field_rev(field_rev, index); - let notified_changeset = GridFieldChangeset::insert(&self.grid_id, vec![index_field]); + let index_field = IndexFieldPB::from_field_rev(field_rev, index); + let notified_changeset = GridFieldChangesetPB::insert(&self.grid_id, vec![index_field]); let _ = self.notify_did_update_grid(notified_changeset).await?; } Ok(()) @@ -615,8 +615,8 @@ impl GridRevisionEditor { .get_field_rev(field_id) .map(|(index, field)| (index, field.clone())) { - let updated_field = Field::from(field_rev); - let notified_changeset = GridFieldChangeset::update(&self.grid_id, vec![updated_field.clone()]); + let updated_field = FieldPB::from(field_rev); + let notified_changeset = GridFieldChangesetPB::update(&self.grid_id, vec![updated_field.clone()]); let _ = self.notify_did_update_grid(notified_changeset).await?; send_dart_notification(field_id, GridNotification::DidUpdateField) @@ -627,7 +627,7 @@ impl GridRevisionEditor { Ok(()) } - async fn notify_did_update_grid(&self, changeset: GridFieldChangeset) -> FlowyResult<()> { + async fn notify_did_update_grid(&self, changeset: GridFieldChangesetPB) -> 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 c00604a40a..3a5aa58c6d 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::{GridBlock, RepeatedGridBlock, Row}; +use crate::entities::{GridBlockPB, GridRowPB, RepeatedGridBlockPB}; 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(|| GridBlock::new(&cloned_block_id, vec![])) + .or_insert_with(|| GridBlockPB::new(&cloned_block_id, vec![])) .rows .push(row_info); }); @@ -35,16 +35,16 @@ pub(crate) fn block_from_row_orders(row_orders: Vec) -> Vec { // Some((field_id, cell)) // } -pub(crate) fn make_row_orders_from_row_revs(row_revs: &[Arc]) -> Vec { - row_revs.iter().map(Row::from).collect::>() +pub(crate) fn make_row_orders_from_row_revs(row_revs: &[Arc]) -> Vec { + row_revs.iter().map(GridRowPB::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| Row { +pub(crate) fn make_rows_from_row_revs(row_revs: &[Arc]) -> Vec { + let make_row = |row_rev: &Arc| GridRowPB { 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 pub(crate) fn make_grid_blocks( block_ids: Option>, 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); - GridBlock::new(&snapshot.block_id, row_orders) + GridBlockPB::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(GridBlock::new(&block_id, row_orders)); + grid_blocks.push(GridBlockPB::new(&block_id, row_orders)); } } } diff --git a/frontend/rust-lib/flowy-grid/src/services/setting/setting_builder.rs b/frontend/rust-lib/flowy-grid/src/services/setting/setting_builder.rs index 6880db5277..be283981cf 100644 --- a/frontend/rust-lib/flowy-grid/src/services/setting/setting_builder.rs +++ b/frontend/rust-lib/flowy-grid/src/services/setting/setting_builder.rs @@ -1,5 +1,5 @@ use crate::entities::{ - GridLayout, GridLayoutType, GridSetting, RepeatedGridFilter, RepeatedGridGroup, RepeatedGridSort, + GridLayoutPB, GridLayoutType, GridSettingPB, RepeatedGridFilterPB, RepeatedGridGroupPB, RepeatedGridSortPB, }; use flowy_grid_data_model::revision::{FieldRevision, GridSettingRevision}; use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams}; @@ -40,7 +40,7 @@ impl GridSettingChangesetBuilder { } } -pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[Arc]) -> GridSetting { +pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[Arc]) -> GridSettingPB { let current_layout_type: GridLayoutType = grid_setting_rev.layout.clone().into(); let filters_by_field_id = grid_setting_rev .get_all_filter(field_revs) @@ -48,7 +48,7 @@ pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[A filters_by_field_id .into_iter() .map(|(k, v)| (k, v.into())) - .collect::>() + .collect::>() }) .unwrap_or_default(); let groups_by_field_id = grid_setting_rev @@ -57,7 +57,7 @@ pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[A groups_by_field_id .into_iter() .map(|(k, v)| (k, v.into())) - .collect::>() + .collect::>() }) .unwrap_or_default(); let sorts_by_field_id = grid_setting_rev @@ -66,12 +66,12 @@ pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[A sorts_by_field_id .into_iter() .map(|(k, v)| (k, v.into())) - .collect::>() + .collect::>() }) .unwrap_or_default(); - GridSetting { - layouts: GridLayout::all(), + GridSettingPB { + layouts: GridLayoutPB::all(), current_layout_type, filters_by_field_id, groups_by_field_id, 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 18810032f0..318910f217 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::{CellIdentifier, FieldType, Row}; +use flowy_grid::entities::{CellIdentifier, FieldType, GridRowPB}; 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; @@ -289,7 +289,7 @@ impl<'a> CreateRowScriptBuilder<'a> { pub fn insert_single_select_cell(&mut self, f: F, expected: &str) where - F: Fn(Vec) -> SelectOption, + F: Fn(Vec) -> SelectOptionPB, { let field_id = self.builder.insert_single_select_cell(f); self.output_by_field_type.insert( @@ -303,7 +303,7 @@ impl<'a> CreateRowScriptBuilder<'a> { pub fn insert_multi_select_cell(&mut self, f: F, expected: &str) where - F: Fn(Vec) -> Vec, + F: Fn(Vec) -> Vec, { let field_id = self.builder.insert_multi_select_cell(f); self.output_by_field_type.insert( diff --git a/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs b/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs index 7aade54a08..216a4d4acd 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/block_test/util.rs @@ -2,7 +2,7 @@ use flowy_grid::entities::FieldType; use std::sync::Arc; use flowy_grid::services::field::{ - DateCellChangeset, MultiSelectTypeOption, SelectOption, SingleSelectTypeOption, SELECTION_IDS_SEPARATOR, + DateCellChangesetPB, MultiSelectTypeOption, SelectOptionPB, SingleSelectTypeOptionPB, SELECTION_IDS_SEPARATOR, }; use flowy_grid::services::row::RowRevisionBuilder; use flowy_grid_data_model::revision::{FieldRevision, RowRevision}; @@ -44,7 +44,7 @@ impl<'a> GridRowTestBuilder<'a> { } pub fn insert_date_cell(&mut self, data: &str) -> String { - let value = serde_json::to_string(&DateCellChangeset { + let value = serde_json::to_string(&DateCellChangesetPB { date: Some(data.to_string()), time: None, }) @@ -71,10 +71,10 @@ impl<'a> GridRowTestBuilder<'a> { pub fn insert_single_select_cell(&mut self, f: F) -> String where - F: Fn(Vec) -> SelectOption, + F: Fn(Vec) -> SelectOptionPB, { let single_select_field = self.field_rev_with_type(&FieldType::SingleSelect); - let type_option = SingleSelectTypeOption::from(&single_select_field); + let type_option = SingleSelectTypeOptionPB::from(&single_select_field); let option = f(type_option.options); self.inner_builder .insert_select_option_cell(&single_select_field.id, option.id) @@ -85,7 +85,7 @@ impl<'a> GridRowTestBuilder<'a> { pub fn insert_multi_select_cell(&mut self, f: F) -> String where - F: Fn(Vec) -> Vec, + F: Fn(Vec) -> Vec, { let multi_select_field = self.field_rev_with_type(&FieldType::MultiSelect); let type_option = MultiSelectTypeOption::from(&multi_select_field); diff --git a/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs b/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs index ccdb8ea629..2334c89f9a 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs @@ -3,7 +3,7 @@ use crate::grid::cell_test::script::GridCellTest; use crate::grid::field_test::util::make_date_cell_string; use flowy_grid::entities::{CellChangeset, FieldType}; use flowy_grid::services::field::selection_type_option::SelectOptionCellChangeset; -use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOption}; +use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB}; #[tokio::test] async fn grid_cell_update() { @@ -24,7 +24,7 @@ async fn grid_cell_update() { FieldType::Number => "123".to_string(), FieldType::DateTime => make_date_cell_string("123"), FieldType::SingleSelect => { - let type_option = SingleSelectTypeOption::from(field_rev); + let type_option = SingleSelectTypeOptionPB::from(field_rev); SelectOptionCellChangeset::from_insert(&type_option.options.first().unwrap().id).to_str() } FieldType::MultiSelect => { diff --git a/frontend/rust-lib/flowy-grid/tests/grid/field_test/test.rs b/frontend/rust-lib/flowy-grid/tests/grid/field_test/test.rs index c53ba2a2fc..98cb3d0324 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/field_test/test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/field_test/test.rs @@ -1,8 +1,8 @@ use crate::grid::field_test::script::FieldScript::*; use crate::grid::field_test::script::GridFieldTest; use crate::grid::field_test::util::*; -use flowy_grid::services::field::selection_type_option::SelectOption; -use flowy_grid::services::field::SingleSelectTypeOption; +use flowy_grid::services::field::selection_type_option::SelectOptionPB; +use flowy_grid::services::field::SingleSelectTypeOptionPB; use flowy_grid_data_model::revision::TypeOptionDataEntry; use flowy_sync::entities::grid::FieldChangesetParams; @@ -71,8 +71,8 @@ async fn grid_update_field() { let mut test = GridFieldTest::new().await; let (params, single_select_field) = create_single_select_field(&test.grid_id()); - let mut single_select_type_option = SingleSelectTypeOption::from(&single_select_field); - single_select_type_option.options.push(SelectOption::new("Unknown")); + let mut single_select_type_option = SingleSelectTypeOptionPB::from(&single_select_field); + single_select_type_option.options.push(SelectOptionPB::new("Unknown")); let changeset = FieldChangesetParams { field_id: single_select_field.id.clone(), grid_id: test.grid_id(), 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 42c04e41f9..95b6759950 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 @@ -1,5 +1,5 @@ use flowy_grid::entities::*; -use flowy_grid::services::field::selection_type_option::SelectOption; +use flowy_grid::services::field::selection_type_option::SelectOptionPB; use flowy_grid::services::field::*; use flowy_grid_data_model::revision::*; @@ -17,7 +17,7 @@ pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) { .protobuf_bytes() .to_vec(); - let field = Field { + let field = FieldPB { id: field_rev.id, name: field_rev.name, desc: field_rev.desc, @@ -39,18 +39,18 @@ pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) { pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) { let single_select = SingleSelectTypeOptionBuilder::default() - .option(SelectOption::new("Done")) - .option(SelectOption::new("Progress")); + .option(SelectOptionPB::new("Done")) + .option(SelectOptionPB::new("Progress")); let field_rev = FieldBuilder::new(single_select).name("Name").visibility(true).build(); let cloned_field_rev = field_rev.clone(); let type_option_data = field_rev - .get_type_option_entry::(field_rev.field_type_rev) + .get_type_option_entry::(field_rev.field_type_rev) .unwrap() .protobuf_bytes() .to_vec(); - let field = Field { + let field = FieldPB { id: field_rev.id, name: field_rev.name, desc: field_rev.desc, @@ -73,7 +73,7 @@ pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldRev // The grid will contains all existing field types and there are three empty rows in this grid. pub fn make_date_cell_string(s: &str) -> String { - serde_json::to_string(&DateCellChangeset { + serde_json::to_string(&DateCellChangesetPB { date: Some(s.to_string()), time: None, }) diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs index 4a1ef3af83..267cb570eb 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs @@ -3,7 +3,7 @@ #![allow(dead_code)] #![allow(unused_imports)] -use flowy_grid::entities::{CreateGridFilterPayload, GridLayoutType, GridSetting}; +use flowy_grid::entities::{CreateGridFilterPayloadPB, GridLayoutType, GridSettingPB}; use flowy_grid::services::setting::GridSettingChangesetBuilder; use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision}; use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams}; @@ -15,7 +15,7 @@ pub enum FilterScript { params: GridSettingChangesetParams, }, InsertGridTableFilter { - payload: CreateGridFilterPayload, + payload: CreateGridFilterPayloadPB, }, AssertTableFilterCount { count: i32, @@ -26,7 +26,7 @@ pub enum FilterScript { }, #[allow(dead_code)] AssertGridSetting { - expected_setting: GridSetting, + expected_setting: GridSettingPB, }, } diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs index e954ebe512..3e45a4053d 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/text_filter_test.rs @@ -1,13 +1,13 @@ use crate::grid::filter_test::script::FilterScript::*; use crate::grid::filter_test::script::*; -use flowy_grid::entities::{CreateGridFilterPayload, FieldType, TextFilterCondition}; +use flowy_grid::entities::{CreateGridFilterPayloadPB, FieldType, TextFilterCondition}; use flowy_grid_data_model::revision::FieldRevision; #[tokio::test] async fn grid_filter_create_test() { let mut test = GridFilterTest::new().await; let field_rev = test.get_field_rev(FieldType::RichText); - let payload = CreateGridFilterPayload::new(field_rev, TextFilterCondition::TextIsEmpty, Some("abc".to_owned())); + let payload = CreateGridFilterPayloadPB::new(field_rev, TextFilterCondition::TextIsEmpty, Some("abc".to_owned())); let scripts = vec![InsertGridTableFilter { payload }, AssertTableFilterCount { count: 1 }]; test.run_scripts(scripts).await; } @@ -19,7 +19,7 @@ async fn grid_filter_invalid_condition_panic_test() { let field_rev = test.get_field_rev(FieldType::RichText).clone(); // 100 is not a valid condition, so this test should be panic. - let payload = CreateGridFilterPayload::new(&field_rev, 100, Some("".to_owned())); + let payload = CreateGridFilterPayloadPB::new(&field_rev, 100, Some("".to_owned())); let scripts = vec![InsertGridTableFilter { payload }]; test.run_scripts(scripts).await; } @@ -46,6 +46,6 @@ async fn grid_filter_delete_test() { #[tokio::test] async fn grid_filter_get_rows_test() {} -fn create_filter(field_rev: &FieldRevision, condition: TextFilterCondition, s: &str) -> CreateGridFilterPayload { - CreateGridFilterPayload::new(field_rev, condition, Some(s.to_owned())) +fn create_filter(field_rev: &FieldRevision, condition: TextFilterCondition, s: &str) -> CreateGridFilterPayloadPB { + CreateGridFilterPayloadPB::new(field_rev, condition, Some(s.to_owned())) } 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 d558390e25..f924b3e803 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs @@ -4,7 +4,7 @@ use crate::grid::block_test::util::GridRowTestBuilder; use bytes::Bytes; use flowy_grid::entities::*; -use flowy_grid::services::field::SelectOption; +use flowy_grid::services::field::SelectOptionPB; use flowy_grid::services::field::*; use flowy_grid::services::grid_editor::{GridPadBuilder, GridRevisionEditor}; use flowy_grid::services::row::{CreateRowRevisionPayload, RowRevisionBuilder}; @@ -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 { @@ -138,18 +138,18 @@ fn make_test_grid() -> BuildGridContext { FieldType::SingleSelect => { // Single Select let single_select = SingleSelectTypeOptionBuilder::default() - .option(SelectOption::new(COMPLETED)) - .option(SelectOption::new(PLANNED)) - .option(SelectOption::new(PAUSED)); + .option(SelectOptionPB::new(COMPLETED)) + .option(SelectOptionPB::new(PLANNED)) + .option(SelectOptionPB::new(PAUSED)); let single_select_field = FieldBuilder::new(single_select).name("Status").visibility(true).build(); grid_builder.add_field(single_select_field); } FieldType::MultiSelect => { // MultiSelect let multi_select = MultiSelectTypeOptionBuilder::default() - .option(SelectOption::new(GOOGLE)) - .option(SelectOption::new(FACEBOOK)) - .option(SelectOption::new(TWITTER)); + .option(SelectOptionPB::new(GOOGLE)) + .option(SelectOptionPB::new(FACEBOOK)) + .option(SelectOptionPB::new(TWITTER)); let multi_select_field = FieldBuilder::new(multi_select) .name("Platform") .visibility(true) From e45b14910b0be9042c83d3f891b4cc0451d85599 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sun, 17 Jul 2022 14:13:12 +0800 Subject: [PATCH 3/3] chore: add suffix PB to dart class --- .../app_flowy/lib/core/grid_notification.dart | 2 +- .../app_flowy/lib/startup/deps_resolver.dart | 2 +- .../grid/block/block_listener.dart | 4 +- .../cell/cell_service/cell_data_loader.dart | 20 +-- .../cell_service/cell_data_persistence.dart | 6 +- .../cell_service/cell_field_notifier.dart | 4 +- .../grid/cell/cell_service/cell_service.dart | 8 +- .../cell/cell_service/context_builder.dart | 14 +-- .../application/grid/cell/date_cal_bloc.dart | 12 +- .../application/grid/cell/date_cell_bloc.dart | 14 +-- .../grid/cell/select_option_cell_bloc.dart | 4 +- .../grid/cell/select_option_editor_bloc.dart | 22 ++-- .../grid/cell/select_option_service.dart | 24 ++-- .../application/grid/cell/url_cell_bloc.dart | 2 +- .../grid/cell/url_cell_editor_bloc.dart | 2 +- .../grid/field/field_action_sheet_bloc.dart | 8 +- .../grid/field/field_cell_bloc.dart | 4 +- .../grid/field/field_editor_bloc.dart | 6 +- .../grid/field/field_listener.dart | 4 +- .../application/grid/field/field_service.dart | 46 +++---- .../field/field_type_option_edit_bloc.dart | 4 +- .../application/grid/field/grid_listenr.dart | 4 +- .../type_option/edit_select_option_bloc.dart | 12 +- .../type_option/multi_select_type_option.dart | 10 +- .../select_option_type_option_bloc.dart | 22 ++-- .../single_select_type_option.dart | 18 +-- .../type_option/type_option_service.dart | 10 +- .../workspace/application/grid/grid_bloc.dart | 16 +-- .../application/grid/grid_header_bloc.dart | 12 +- .../application/grid/grid_service.dart | 46 +++---- .../workspace/application/grid/prelude.dart | 6 +- .../application/grid/row/row_bloc.dart | 4 +- .../application/grid/row/row_listener.dart | 6 +- .../application/grid/row/row_service.dart | 42 +++---- .../grid/setting/property_bloc.dart | 8 +- .../plugins/grid/src/layout/layout.dart | 2 +- .../cell/select_option_cell/extension.dart | 44 +++---- .../select_option_cell.dart | 2 +- .../select_option_editor.dart | 4 +- .../cell/select_option_cell/text_field.dart | 4 +- .../grid/src/widgets/header/field_cell.dart | 2 +- .../header/field_type_option_editor.dart | 6 +- .../grid/src/widgets/header/grid_header.dart | 2 +- .../header/type_option/select_option.dart | 8 +- .../type_option/select_option_editor.dart | 10 +- .../src/widgets/toolbar/grid_property.dart | 2 +- .../widgets/emoji_picker/src/emoji_lists.dart | 2 +- .../flowy-grid/src/entities/cell_entities.rs | 46 +++---- .../flowy-grid/src/entities/field_entities.rs | 116 +++++++++--------- .../flowy-grid/src/entities/grid_entities.rs | 4 +- .../rust-lib/flowy-grid/src/event_handler.rs | 40 +++--- frontend/rust-lib/flowy-grid/src/event_map.rs | 50 ++++---- .../flowy-grid/src/services/block_manager.rs | 6 +- .../src/services/field/field_builder.rs | 4 +- .../date_type_option_entities.rs | 14 +-- .../selection_type_option/select_option.rs | 16 +-- .../flowy-grid/src/services/grid_editor.rs | 22 ++-- .../tests/grid/block_test/script.rs | 6 +- .../flowy-grid/tests/grid/cell_test/script.rs | 4 +- .../flowy-grid/tests/grid/cell_test/test.rs | 4 +- .../flowy-grid/tests/grid/field_test/util.rs | 4 +- 61 files changed, 426 insertions(+), 426 deletions(-) diff --git a/frontend/app_flowy/lib/core/grid_notification.dart b/frontend/app_flowy/lib/core/grid_notification.dart index e45bf5efe2..9a2429a417 100644 --- a/frontend/app_flowy/lib/core/grid_notification.dart +++ b/frontend/app_flowy/lib/core/grid_notification.dart @@ -8,7 +8,7 @@ import 'package:flowy_sdk/rust_stream.dart'; import 'notification_helper.dart'; -// Grid +// GridPB typedef GridNotificationCallback = void Function(GridNotification, Either); class GridNotificationParser extends NotificationParser { diff --git a/frontend/app_flowy/lib/startup/deps_resolver.dart b/frontend/app_flowy/lib/startup/deps_resolver.dart index bd9c259575..bdb76996e9 100644 --- a/frontend/app_flowy/lib/startup/deps_resolver.dart +++ b/frontend/app_flowy/lib/startup/deps_resolver.dart @@ -134,7 +134,7 @@ void _resolveDocDeps(GetIt getIt) { } void _resolveGridDeps(GetIt getIt) { - // Grid + // GridPB getIt.registerFactoryParam( (view, _) => GridBloc(view: view), ); diff --git a/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart index 7a2bbe0cb3..91f93c61fe 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart @@ -7,7 +7,7 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; -typedef GridBlockUpdateNotifierValue = Either, FlowyError>; +typedef GridBlockUpdateNotifierValue = Either, FlowyError>; class GridBlockListener { final String blockId; @@ -33,7 +33,7 @@ class GridBlockListener { switch (ty) { case GridNotification.DidUpdateGridBlock: result.fold( - (payload) => _rowsUpdateNotifier?.value = left([GridBlockChangeset.fromBuffer(payload)]), + (payload) => _rowsUpdateNotifier?.value = left([GridBlockChangesetPB.fromBuffer(payload)]), (error) => _rowsUpdateNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart index 324c65c5f5..b779d227b1 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart @@ -24,7 +24,7 @@ class GridCellDataLoader { Future loadData() { final fut = service.getCell(cellId: cellId); return fut.then( - (result) => result.fold((Cell cell) { + (result) => result.fold((GridCellPB cell) { try { return parser.parserData(cell.data); } catch (e, s) { @@ -48,32 +48,32 @@ class StringCellDataParser implements ICellDataParser { } } -class DateCellDataParser implements ICellDataParser { +class DateCellDataParser implements ICellDataParser { @override - DateCellData? parserData(List data) { + DateCellDataPB? parserData(List data) { if (data.isEmpty) { return null; } - return DateCellData.fromBuffer(data); + return DateCellDataPB.fromBuffer(data); } } -class SelectOptionCellDataParser implements ICellDataParser { +class SelectOptionCellDataParser implements ICellDataParser { @override - SelectOptionCellData? parserData(List data) { + SelectOptionCellDataPB? parserData(List data) { if (data.isEmpty) { return null; } - return SelectOptionCellData.fromBuffer(data); + return SelectOptionCellDataPB.fromBuffer(data); } } -class URLCellDataParser implements ICellDataParser { +class URLCellDataParser implements ICellDataParser { @override - URLCellData? parserData(List data) { + URLCellDataPB? parserData(List data) { if (data.isEmpty) { return null; } - return URLCellData.fromBuffer(data); + return URLCellDataPB.fromBuffer(data); } } diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_persistence.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_persistence.dart index 4959adf3ed..a38a771158 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_persistence.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_persistence.dart @@ -40,7 +40,7 @@ class DateCellDataPersistence implements IGridCellDataPersistence @override Future> save(CalendarData data) { - var payload = DateChangesetPayload.create()..cellIdentifier = _makeCellIdPayload(cellId); + var payload = DateChangesetPayloadPB.create()..cellIdentifier = _makeCellIdPayload(cellId); final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString(); payload.date = date; @@ -58,8 +58,8 @@ class DateCellDataPersistence implements IGridCellDataPersistence } } -CellIdentifierPayload _makeCellIdPayload(GridCellIdentifier cellId) { - return CellIdentifierPayload.create() +GridCellIdentifierPayloadPB _makeCellIdPayload(GridCellIdentifier cellId) { + return GridCellIdentifierPayloadPB.create() ..gridId = cellId.gridId ..fieldId = cellId.fieldId ..rowId = cellId.rowId; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_field_notifier.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_field_notifier.dart index e4c909d501..72f1bc787d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_field_notifier.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_field_notifier.dart @@ -4,11 +4,11 @@ import 'package:flutter/foundation.dart'; import 'cell_service.dart'; abstract class GridFieldChangedNotifier { - void onFieldChanged(void Function(Field) callback); + void onFieldChanged(void Function(GridFieldPB) callback); void dispose(); } -/// Grid's cell helper wrapper that enables each cell will get notified when the corresponding field was changed. +/// GridPB's cell helper wrapper that enables each cell will get notified when the corresponding field was changed. /// You Register an onFieldChanged callback to listen to the cell changes, and unregister if you don't want to listen. class GridCellFieldNotifier { /// fieldId: {objectId: callback} diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_service.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_service.dart index fab9c1a724..3e8746c20a 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_service.dart @@ -35,7 +35,7 @@ class CellService { required GridCellIdentifier cellId, required String data, }) { - final payload = CellChangeset.create() + final payload = CellChangesetPB.create() ..gridId = cellId.gridId ..fieldId = cellId.fieldId ..rowId = cellId.rowId @@ -43,10 +43,10 @@ class CellService { return GridEventUpdateCell(payload).send(); } - Future> getCell({ + Future> getCell({ required GridCellIdentifier cellId, }) { - final payload = CellIdentifierPayload.create() + final payload = GridCellIdentifierPayloadPB.create() ..gridId = cellId.gridId ..fieldId = cellId.fieldId ..rowId = cellId.rowId; @@ -61,7 +61,7 @@ class GridCellIdentifier with _$GridCellIdentifier { const factory GridCellIdentifier({ required String gridId, required String rowId, - required Field field, + required GridFieldPB field, }) = _GridCellIdentifier; // ignore: unused_element diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart index 124835cf94..8e51e33f29 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart @@ -1,9 +1,9 @@ part of 'cell_service.dart'; typedef GridCellController = IGridCellController; -typedef GridSelectOptionCellController = IGridCellController; -typedef GridDateCellController = IGridCellController; -typedef GridURLCellController = IGridCellController; +typedef GridSelectOptionCellController = IGridCellController; +typedef GridDateCellController = IGridCellController; +typedef GridURLCellController = IGridCellController; class GridCellControllerBuilder { final GridCellIdentifier _cellId; @@ -159,7 +159,7 @@ class IGridCellController extends Equatable { String get fieldId => cellId.field.id; - Field get field => cellId.field; + GridFieldPB get field => cellId.field; FieldType get fieldType => cellId.field.fieldType; @@ -223,7 +223,7 @@ class IGridCellController extends Equatable { return data; } - /// Return the FieldTypeOptionData that can be parsed into corresponding class using the [parser]. + /// Return the FieldTypeOptionDataPB that can be parsed into corresponding class using the [parser]. /// [PD] is the type that the parser return. Future> getFieldTypeOption(P parser) { return _fieldService.getFieldTypeOptionData(fieldType: fieldType).then((result) { @@ -305,8 +305,8 @@ class _GridFieldChangedNotifierImpl extends GridFieldChangedNotifier { } @override - void onFieldChanged(void Function(Field p1) callback) { - _onChangesetFn = (GridFieldChangeset changeset) { + void onFieldChanged(void Function(GridFieldPB p1) callback) { + _onChangesetFn = (GridFieldChangesetPB changeset) { for (final updatedField in changeset.updatedFields) { callback(updatedField); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart index 77a7c7f066..d99bdbf817 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart @@ -22,7 +22,7 @@ class DateCalBloc extends Bloc { DateCalBloc({ required DateTypeOption dateTypeOption, - required DateCellData? cellData, + required DateCellDataPB? cellData, required this.cellContext, }) : super(DateCalState.initial(dateTypeOption, cellData)) { on( @@ -38,7 +38,7 @@ class DateCalBloc extends Bloc { setFocusedDay: (focusedDay) { emit(state.copyWith(focusedDay: focusedDay)); }, - didReceiveCellUpdate: (DateCellData? cellData) { + didReceiveCellUpdate: (DateCellDataPB? cellData) { final calData = calDataFromCellData(cellData); final time = calData.foldRight("", (dateData, previous) => dateData.time); emit(state.copyWith(calData: calData, time: time)); @@ -188,7 +188,7 @@ class DateCalEvent with _$DateCalEvent { const factory DateCalEvent.setDateFormat(DateFormat dateFormat) = _DateFormat; const factory DateCalEvent.setIncludeTime(bool includeTime) = _IncludeTime; const factory DateCalEvent.setTime(String time) = _Time; - const factory DateCalEvent.didReceiveCellUpdate(DateCellData? data) = _DidReceiveCellUpdate; + const factory DateCalEvent.didReceiveCellUpdate(DateCellDataPB? data) = _DidReceiveCellUpdate; const factory DateCalEvent.didUpdateCalData(Option data, Option timeFormatError) = _DidUpdateCalData; } @@ -207,7 +207,7 @@ class DateCalState with _$DateCalState { factory DateCalState.initial( DateTypeOption dateTypeOption, - DateCellData? cellData, + DateCellDataPB? cellData, ) { Option calData = calDataFromCellData(cellData); final time = calData.foldRight("", (dateData, previous) => dateData.time); @@ -233,7 +233,7 @@ String _timeHintText(DateTypeOption typeOption) { return ""; } -Option calDataFromCellData(DateCellData? cellData) { +Option calDataFromCellData(DateCellDataPB? cellData) { String? time = timeFromCellData(cellData); Option calData = none(); if (cellData != null) { @@ -249,7 +249,7 @@ $fixnum.Int64 timestampFromDateTime(DateTime dateTime) { return $fixnum.Int64(timestamp); } -String? timeFromCellData(DateCellData? cellData) { +String? timeFromCellData(DateCellDataPB? cellData) { String? time; if (cellData?.hasTime() ?? false) { time = cellData?.time; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/date_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/date_cell_bloc.dart index d42769549a..c4f79f1f90 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/date_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/date_cell_bloc.dart @@ -15,10 +15,10 @@ class DateCellBloc extends Bloc { (event, emit) async { event.when( initial: () => _startListening(), - didReceiveCellUpdate: (DateCellData? cellData) { + didReceiveCellUpdate: (DateCellDataPB? cellData) { emit(state.copyWith(data: cellData, dateStr: _dateStrFromCellData(cellData))); }, - didReceiveFieldUpdate: (Field value) => emit(state.copyWith(field: value)), + didReceiveFieldUpdate: (GridFieldPB value) => emit(state.copyWith(field: value)), ); }, ); @@ -48,16 +48,16 @@ class DateCellBloc extends Bloc { @freezed class DateCellEvent with _$DateCellEvent { const factory DateCellEvent.initial() = _InitialCell; - const factory DateCellEvent.didReceiveCellUpdate(DateCellData? data) = _DidReceiveCellUpdate; - const factory DateCellEvent.didReceiveFieldUpdate(Field field) = _DidReceiveFieldUpdate; + const factory DateCellEvent.didReceiveCellUpdate(DateCellDataPB? data) = _DidReceiveCellUpdate; + const factory DateCellEvent.didReceiveFieldUpdate(GridFieldPB field) = _DidReceiveFieldUpdate; } @freezed class DateCellState with _$DateCellState { const factory DateCellState({ - required DateCellData? data, + required DateCellDataPB? data, required String dateStr, - required Field field, + required GridFieldPB field, }) = _DateCellState; factory DateCellState.initial(GridDateCellController context) { @@ -71,7 +71,7 @@ class DateCellState with _$DateCellState { } } -String _dateStrFromCellData(DateCellData? cellData) { +String _dateStrFromCellData(DateCellDataPB? cellData) { String dateStr = ""; if (cellData != null) { dateStr = cellData.date + " " + cellData.time; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_cell_bloc.dart index a8a9a435e8..d0db8669fa 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_cell_bloc.dart @@ -56,14 +56,14 @@ class SelectOptionCellBloc extends Bloc selectedOptions, + List selectedOptions, ) = _DidReceiveOptions; } @freezed class SelectOptionCellState with _$SelectOptionCellState { const factory SelectOptionCellState({ - required List selectedOptions, + required List selectedOptions, }) = _SelectOptionCellState; factory SelectOptionCellState.initial(GridSelectOptionCellController context) { diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_editor_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_editor_bloc.dart index 2daabe1a98..0990dca28a 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_editor_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_editor_bloc.dart @@ -70,7 +70,7 @@ class SelectOptionCellEditorBloc extends Bloc {}, (err) => Log.error(err)); } - void _deleteOption(SelectOption option) async { + void _deleteOption(SelectOptionPB option) async { final result = await _selectOptionService.delete( option: option, ); @@ -78,7 +78,7 @@ class SelectOptionCellEditorBloc extends Bloc null, (err) => Log.error(err)); } - void _updateOption(SelectOption option) async { + void _updateOption(SelectOptionPB option) async { final result = await _selectOptionService.update( option: option, ); @@ -122,8 +122,8 @@ class SelectOptionCellEditorBloc extends Bloc filter, List allOptions) { - final List options = List.from(allOptions); + _MakeOptionResult _makeOptions(Option filter, List allOptions) { + final List options = List.from(allOptions); Option createOption = filter; filter.foldRight(null, (filter, previous) { @@ -165,20 +165,20 @@ class SelectOptionCellEditorBloc extends Bloc options, List selectedOptions) = _DidReceiveOptions; + List options, List selectedOptions) = _DidReceiveOptions; const factory SelectOptionEditorEvent.newOption(String optionName) = _NewOption; const factory SelectOptionEditorEvent.selectOption(String optionId) = _SelectOption; - const factory SelectOptionEditorEvent.updateOption(SelectOption option) = _UpdateOption; - const factory SelectOptionEditorEvent.deleteOption(SelectOption option) = _DeleteOption; + const factory SelectOptionEditorEvent.updateOption(SelectOptionPB option) = _UpdateOption; + const factory SelectOptionEditorEvent.deleteOption(SelectOptionPB option) = _DeleteOption; const factory SelectOptionEditorEvent.filterOption(String optionName) = _SelectOptionFilter; } @freezed class SelectOptionEditorState with _$SelectOptionEditorState { const factory SelectOptionEditorState({ - required List options, - required List allOptions, - required List selectedOptions, + required List options, + required List allOptions, + required List selectedOptions, required Option createOption, required Option filter, }) = _SelectOptionEditorState; @@ -196,7 +196,7 @@ class SelectOptionEditorState with _$SelectOptionEditorState { } class _MakeOptionResult { - List options; + List options; Option createOption; _MakeOptionResult({ diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_service.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_service.dart index 7b6fffa310..54ac384267 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/select_option_service.dart @@ -19,11 +19,11 @@ class SelectOptionService { (result) { return result.fold( (option) { - final cellIdentifier = CellIdentifierPayload.create() + final cellIdentifier = GridCellIdentifierPayloadPB.create() ..gridId = gridId ..fieldId = fieldId ..rowId = rowId; - final payload = SelectOptionChangesetPayload.create() + final payload = SelectOptionChangesetPayloadPB.create() ..insertOption = option ..cellIdentifier = cellIdentifier; return GridEventUpdateSelectOption(payload).send(); @@ -35,26 +35,26 @@ class SelectOptionService { } Future> update({ - required SelectOption option, + required SelectOptionPB option, }) { - final payload = SelectOptionChangesetPayload.create() + final payload = SelectOptionChangesetPayloadPB.create() ..updateOption = option ..cellIdentifier = _cellIdentifier(); return GridEventUpdateSelectOption(payload).send(); } Future> delete({ - required SelectOption option, + required SelectOptionPB option, }) { - final payload = SelectOptionChangesetPayload.create() + final payload = SelectOptionChangesetPayloadPB.create() ..deleteOption = option ..cellIdentifier = _cellIdentifier(); return GridEventUpdateSelectOption(payload).send(); } - Future> getOpitonContext() { - final payload = CellIdentifierPayload.create() + Future> getOpitonContext() { + final payload = GridCellIdentifierPayloadPB.create() ..gridId = gridId ..fieldId = fieldId ..rowId = rowId; @@ -63,21 +63,21 @@ class SelectOptionService { } Future> select({required String optionId}) { - final payload = SelectOptionCellChangesetPayload.create() + final payload = SelectOptionCellChangesetPayloadPB.create() ..cellIdentifier = _cellIdentifier() ..insertOptionId = optionId; return GridEventUpdateSelectOptionCell(payload).send(); } Future> unSelect({required String optionId}) { - final payload = SelectOptionCellChangesetPayload.create() + final payload = SelectOptionCellChangesetPayloadPB.create() ..cellIdentifier = _cellIdentifier() ..deleteOptionId = optionId; return GridEventUpdateSelectOptionCell(payload).send(); } - CellIdentifierPayload _cellIdentifier() { - return CellIdentifierPayload.create() + GridCellIdentifierPayloadPB _cellIdentifier() { + return GridCellIdentifierPayloadPB.create() ..gridId = gridId ..fieldId = fieldId ..rowId = rowId; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_bloc.dart index ed81f697f8..e43f561542 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_bloc.dart @@ -57,7 +57,7 @@ class URLCellBloc extends Bloc { class URLCellEvent with _$URLCellEvent { const factory URLCellEvent.initial() = _InitialCell; const factory URLCellEvent.updateURL(String url) = _UpdateURL; - const factory URLCellEvent.didReceiveCellUpdate(URLCellData? cell) = _DidReceiveCellUpdate; + const factory URLCellEvent.didReceiveCellUpdate(URLCellDataPB? cell) = _DidReceiveCellUpdate; } @freezed diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_editor_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_editor_bloc.dart index e69a150a38..067be84b7b 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_editor_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_editor_bloc.dart @@ -54,7 +54,7 @@ class URLCellEditorBloc extends Bloc { @freezed class URLCellEditorEvent with _$URLCellEditorEvent { const factory URLCellEditorEvent.initial() = _InitialCell; - const factory URLCellEditorEvent.didReceiveCellUpdate(URLCellData? cell) = _DidReceiveCellUpdate; + const factory URLCellEditorEvent.didReceiveCellUpdate(URLCellDataPB? cell) = _DidReceiveCellUpdate; const factory URLCellEditorEvent.updateText(String text) = _UpdateText; } diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_action_sheet_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_action_sheet_bloc.dart index 801678d929..3caef12f73 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_action_sheet_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_action_sheet_bloc.dart @@ -10,8 +10,8 @@ part 'field_action_sheet_bloc.freezed.dart'; class FieldActionSheetBloc extends Bloc { final FieldService fieldService; - FieldActionSheetBloc({required Field field, required this.fieldService}) - : super(FieldActionSheetState.initial(FieldTypeOptionData.create()..field_2 = field)) { + FieldActionSheetBloc({required GridFieldPB field, required this.fieldService}) + : super(FieldActionSheetState.initial(FieldTypeOptionDataPB.create()..field_2 = field)) { on( (event, emit) async { await event.map( @@ -67,12 +67,12 @@ class FieldActionSheetEvent with _$FieldActionSheetEvent { @freezed class FieldActionSheetState with _$FieldActionSheetState { const factory FieldActionSheetState({ - required FieldTypeOptionData fieldTypeOptionData, + required FieldTypeOptionDataPB fieldTypeOptionData, required String errorText, required String fieldName, }) = _FieldActionSheetState; - factory FieldActionSheetState.initial(FieldTypeOptionData data) => FieldActionSheetState( + factory FieldActionSheetState.initial(FieldTypeOptionDataPB data) => FieldActionSheetState( fieldTypeOptionData: data, errorText: '', fieldName: data.field_2.name, diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_cell_bloc.dart index 774a7fb82b..8a2a0e2d06 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_cell_bloc.dart @@ -62,7 +62,7 @@ class FieldCellBloc extends Bloc { @freezed class FieldCellEvent with _$FieldCellEvent { const factory FieldCellEvent.initial() = _InitialCell; - const factory FieldCellEvent.didReceiveFieldUpdate(Field field) = _DidReceiveFieldUpdate; + const factory FieldCellEvent.didReceiveFieldUpdate(GridFieldPB field) = _DidReceiveFieldUpdate; const factory FieldCellEvent.startUpdateWidth(double offset) = _StartUpdateWidth; const factory FieldCellEvent.endUpdateWidth() = _EndUpdateWidth; } @@ -71,7 +71,7 @@ class FieldCellEvent with _$FieldCellEvent { class FieldCellState with _$FieldCellState { const factory FieldCellState({ required String gridId, - required Field field, + required GridFieldPB field, required double width, }) = _FieldCellState; diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_editor_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_editor_bloc.dart index 19da67e557..8d44edf1ff 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_editor_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_editor_bloc.dart @@ -30,7 +30,7 @@ class FieldEditorBloc extends Bloc { dataController.fieldName = name; emit(state.copyWith(name: name)); }, - didReceiveFieldChanged: (Field field) { + didReceiveFieldChanged: (GridFieldPB field) { emit(state.copyWith(field: Some(field))); }, ); @@ -48,7 +48,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(Field field) = _DidReceiveFieldChanged; + const factory FieldEditorEvent.didReceiveFieldChanged(GridFieldPB field) = _DidReceiveFieldChanged; } @freezed @@ -57,7 +57,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/workspace/application/grid/field/field_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart index 21bd5befeb..d3b35e2bfc 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart @@ -7,7 +7,7 @@ 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; @@ -31,7 +31,7 @@ class SingleFieldListener { switch (ty) { case GridNotification.DidUpdateField: result.fold( - (payload) => _updateFieldNotifier?.value = left(Field.fromBuffer(payload)), + (payload) => _updateFieldNotifier?.value = left(GridFieldPB.fromBuffer(payload)), (error) => _updateFieldNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart index 828ea4cc74..a0c6fc7d21 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart @@ -39,7 +39,7 @@ class FieldService { double? width, List? typeOptionData, }) { - var payload = FieldChangesetPayload.create() + var payload = FieldChangesetPayloadPB.create() ..gridId = gridId ..fieldId = fieldId; @@ -73,11 +73,11 @@ class FieldService { // Create the field if it does not exist. Otherwise, update the field. static Future> insertField({ required String gridId, - required Field field, + required GridFieldPB field, List? typeOptionData, String? startFieldId, }) { - var payload = InsertFieldPayload.create() + var payload = InsertFieldPayloadPB.create() ..gridId = gridId ..field_2 = field ..typeOptionData = typeOptionData ?? []; @@ -94,7 +94,7 @@ class FieldService { required String fieldId, required List typeOptionData, }) { - var payload = UpdateFieldTypeOptionPayload.create() + var payload = UpdateFieldTypeOptionPayloadPB.create() ..gridId = gridId ..fieldId = fieldId ..typeOptionData = typeOptionData; @@ -103,7 +103,7 @@ class FieldService { } Future> deleteField() { - final payload = FieldIdentifierPayload.create() + final payload = GridFieldIdentifierPayloadPB.create() ..gridId = gridId ..fieldId = fieldId; @@ -111,17 +111,17 @@ class FieldService { } Future> duplicateField() { - final payload = FieldIdentifierPayload.create() + final payload = GridFieldIdentifierPayloadPB.create() ..gridId = gridId ..fieldId = fieldId; return GridEventDuplicateField(payload).send(); } - Future> getFieldTypeOptionData({ + Future> getFieldTypeOptionData({ required FieldType fieldType, }) { - final payload = EditFieldPayload.create() + final payload = EditFieldPayloadPB.create() ..gridId = gridId ..fieldId = fieldId ..fieldType = fieldType; @@ -138,16 +138,16 @@ class FieldService { class GridFieldCellContext with _$GridFieldCellContext { const factory GridFieldCellContext({ required String gridId, - required Field field, + required GridFieldPB field, }) = _GridFieldCellContext; } abstract class IFieldTypeOptionLoader { String get gridId; - Future> load(); + Future> load(); - Future> switchToField(String fieldId, FieldType fieldType) { - final payload = EditFieldPayload.create() + Future> switchToField(String fieldId, FieldType fieldType) { + final payload = EditFieldPayloadPB.create() ..gridId = gridId ..fieldId = fieldId ..fieldType = fieldType; @@ -164,8 +164,8 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader { }); @override - Future> load() { - final payload = EditFieldPayload.create() + Future> load() { + final payload = EditFieldPayloadPB.create() ..gridId = gridId ..fieldType = FieldType.RichText; @@ -176,7 +176,7 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader { class FieldTypeOptionLoader extends IFieldTypeOptionLoader { @override final String gridId; - final Field field; + final GridFieldPB field; FieldTypeOptionLoader({ required this.gridId, @@ -184,8 +184,8 @@ class FieldTypeOptionLoader extends IFieldTypeOptionLoader { }); @override - Future> load() { - final payload = EditFieldPayload.create() + Future> load() { + final payload = EditFieldPayloadPB.create() ..gridId = gridId ..fieldId = field.id ..fieldType = field.fieldType; @@ -198,8 +198,8 @@ class TypeOptionDataController { final String gridId; final IFieldTypeOptionLoader _loader; - late FieldTypeOptionData _data; - final PublishNotifier _fieldNotifier = PublishNotifier(); + late FieldTypeOptionDataPB _data; + final PublishNotifier _fieldNotifier = PublishNotifier(); TypeOptionDataController({ required this.gridId, @@ -222,9 +222,9 @@ class TypeOptionDataController { ); } - Field get field => _data.field_2; + GridFieldPB get field => _data.field_2; - set field(Field field) { + set field(GridFieldPB field) { _updateData(newField: field); } @@ -238,7 +238,7 @@ class TypeOptionDataController { _updateData(newTypeOptionData: typeOptionData); } - void _updateData({String? newName, Field? newField, List? newTypeOptionData}) { + void _updateData({String? newName, GridFieldPB? newField, List? newTypeOptionData}) { _data = _data.rebuild((rebuildData) { if (newName != null) { rebuildData.field_2 = rebuildData.field_2.rebuild((rebuildField) { @@ -280,7 +280,7 @@ class TypeOptionDataController { }); } - void Function() addFieldListener(void Function(Field) callback) { + void Function() addFieldListener(void Function(GridFieldPB) callback) { listener() { callback(field); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_type_option_edit_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_type_option_edit_bloc.dart index b9407ac2ad..e098f87d86 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_type_option_edit_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_type_option_edit_bloc.dart @@ -42,13 +42,13 @@ class FieldTypeOptionEditBloc extends Bloc FieldTypeOptionEditState( diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart index 00e94bb3e1..67bec17be7 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart @@ -7,7 +7,7 @@ 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; @@ -27,7 +27,7 @@ class GridFieldsListener { switch (ty) { case GridNotification.DidUpdateGridField: result.fold( - (payload) => updateFieldsNotifier?.value = left(GridFieldChangeset.fromBuffer(payload)), + (payload) => updateFieldsNotifier?.value = left(GridFieldChangesetPB.fromBuffer(payload)), (error) => updateFieldsNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/edit_select_option_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/edit_select_option_bloc.dart index f0969e2793..9f1dd4dd1d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/edit_select_option_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/edit_select_option_bloc.dart @@ -7,7 +7,7 @@ import 'package:dartz/dartz.dart'; part 'edit_select_option_bloc.freezed.dart'; class EditSelectOptionBloc extends Bloc { - EditSelectOptionBloc({required SelectOption option}) : super(EditSelectOptionState.initial(option)) { + EditSelectOptionBloc({required SelectOptionPB option}) : super(EditSelectOptionState.initial(option)) { on( (event, emit) async { event.map( @@ -30,14 +30,14 @@ class EditSelectOptionBloc extends Bloc deleted, }) = _EditSelectOptionState; - factory EditSelectOptionState.initial(SelectOption option) => EditSelectOptionState( + factory EditSelectOptionState.initial(SelectOptionPB option) => EditSelectOptionState( option: option, deleted: none(), ); diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/multi_select_type_option.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/multi_select_type_option.dart index 0d9d75d4c7..e0e242305b 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/multi_select_type_option.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/multi_select_type_option.dart @@ -21,8 +21,8 @@ class MultiSelectTypeOptionContext extends TypeOptionWidgetContext Function(SelectOption) get deleteOption { - return (SelectOption option) { + List Function(SelectOptionPB) get deleteOption { + return (SelectOptionPB option) { typeOption.freeze(); typeOption = typeOption.rebuild((typeOption) { final index = typeOption.options.indexWhere((element) => element.id == option.id); @@ -35,7 +35,7 @@ class MultiSelectTypeOptionContext extends TypeOptionWidgetContext> Function(String) get insertOption { + Future> Function(String) get insertOption { return (String optionName) { return service.newOption(name: optionName).then((result) { return result.fold( @@ -57,8 +57,8 @@ class MultiSelectTypeOptionContext extends TypeOptionWidgetContext Function(SelectOption) get udpateOption { - return (SelectOption option) { + List Function(SelectOptionPB) get udpateOption { + return (SelectOptionPB option) { typeOption.freeze(); typeOption = typeOption.rebuild((typeOption) { final index = typeOption.options.indexWhere((element) => element.id == option.id); diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/select_option_type_option_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/select_option_type_option_bloc.dart index ff8244546b..b77b9b86cd 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/select_option_type_option_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/select_option_type_option_bloc.dart @@ -6,25 +6,25 @@ import 'package:dartz/dartz.dart'; part 'select_option_type_option_bloc.freezed.dart'; abstract class SelectOptionTypeOptionAction { - Future> Function(String) get insertOption; + Future> Function(String) get insertOption; - List Function(SelectOption) get deleteOption; + List Function(SelectOptionPB) get deleteOption; - List Function(SelectOption) get udpateOption; + List Function(SelectOptionPB) get udpateOption; } class SelectOptionTypeOptionBloc extends Bloc { final SelectOptionTypeOptionAction typeOptionAction; SelectOptionTypeOptionBloc({ - required List options, + required List options, required this.typeOptionAction, }) : super(SelectOptionTypeOptionState.initial(options)) { on( (event, emit) async { await event.when( createOption: (optionName) async { - final List options = await typeOptionAction.insertOption(optionName); + final List options = await typeOptionAction.insertOption(optionName); emit(state.copyWith(options: options)); }, addingOption: () { @@ -34,11 +34,11 @@ class SelectOptionTypeOptionBloc extends Bloc options = typeOptionAction.udpateOption(option); + final List options = typeOptionAction.udpateOption(option); emit(state.copyWith(options: options)); }, deleteOption: (option) { - final List options = typeOptionAction.deleteOption(option); + final List options = typeOptionAction.deleteOption(option); emit(state.copyWith(options: options)); }, ); @@ -57,19 +57,19 @@ class SelectOptionTypeOptionEvent with _$SelectOptionTypeOptionEvent { const factory SelectOptionTypeOptionEvent.createOption(String optionName) = _CreateOption; const factory SelectOptionTypeOptionEvent.addingOption() = _AddingOption; const factory SelectOptionTypeOptionEvent.endAddingOption() = _EndAddingOption; - const factory SelectOptionTypeOptionEvent.updateOption(SelectOption option) = _UpdateOption; - const factory SelectOptionTypeOptionEvent.deleteOption(SelectOption option) = _DeleteOption; + const factory SelectOptionTypeOptionEvent.updateOption(SelectOptionPB option) = _UpdateOption; + const factory SelectOptionTypeOptionEvent.deleteOption(SelectOptionPB option) = _DeleteOption; } @freezed class SelectOptionTypeOptionState with _$SelectOptionTypeOptionState { const factory SelectOptionTypeOptionState({ - required List options, + required List options, required bool isEditingOption, required Option newOptionName, }) = _SelectOptionTyepOptionState; - factory SelectOptionTypeOptionState.initial(List options) => SelectOptionTypeOptionState( + factory SelectOptionTypeOptionState.initial(List options) => SelectOptionTypeOptionState( options: options, isEditingOption: false, newOptionName: none(), diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/single_select_type_option.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/single_select_type_option.dart index b2b4581d96..857838de38 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/single_select_type_option.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/single_select_type_option.dart @@ -7,7 +7,7 @@ import 'package:protobuf/protobuf.dart'; import 'select_option_type_option_bloc.dart'; import 'type_option_service.dart'; -class SingleSelectTypeOptionContext extends TypeOptionWidgetContext +class SingleSelectTypeOptionContext extends TypeOptionWidgetContext with SelectOptionTypeOptionAction { final TypeOptionService service; @@ -21,8 +21,8 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext Function(SelectOption) get deleteOption { - return (SelectOption option) { + List Function(SelectOptionPB) get deleteOption { + return (SelectOptionPB option) { typeOption.freeze(); typeOption = typeOption.rebuild((typeOption) { final index = typeOption.options.indexWhere((element) => element.id == option.id); @@ -35,7 +35,7 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext> Function(String) get insertOption { + Future> Function(String) get insertOption { return (String optionName) { return service.newOption(name: optionName).then((result) { return result.fold( @@ -57,8 +57,8 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext Function(SelectOption) get udpateOption { - return (SelectOption option) { + List Function(SelectOptionPB) get udpateOption { + return (SelectOptionPB option) { typeOption.freeze(); typeOption = typeOption.rebuild((typeOption) { final index = typeOption.options.indexWhere((element) => element.id == option.id); @@ -71,9 +71,9 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext { +class SingleSelectTypeOptionWidgetDataParser extends TypeOptionDataParser { @override - SingleSelectTypeOption fromBuffer(List buffer) { - return SingleSelectTypeOption.fromBuffer(buffer); + SingleSelectTypeOptionPB fromBuffer(List buffer) { + return SingleSelectTypeOptionPB.fromBuffer(buffer); } } diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/type_option_service.dart b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/type_option_service.dart index c7c86ae661..b45cc6f869 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/type_option/type_option_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/type_option/type_option_service.dart @@ -18,14 +18,14 @@ class TypeOptionService { required this.fieldId, }); - Future> newOption({ + Future> newOption({ required String name, }) { - final fieldIdentifier = FieldIdentifierPayload.create() + final fieldIdentifier = GridFieldIdentifierPayloadPB.create() ..gridId = gridId ..fieldId = fieldId; - final payload = CreateSelectOptionPayload.create() + final payload = CreateSelectOptionPayloadPB.create() ..optionName = name ..fieldIdentifier = fieldIdentifier; @@ -49,7 +49,7 @@ class TypeOptionWidgetContext { String get gridId => _dataController.gridId; - Field get field => _dataController.field; + GridFieldPB get field => _dataController.field; T get typeOption { if (_typeOptionObject != null) { @@ -74,7 +74,7 @@ abstract class TypeOptionFieldDelegate { class TypeOptionContext2 { final String gridId; - final Field field; + final GridFieldPB field; final FieldService _fieldService; T? _data; final TypeOptionDataParser dataBuilder; diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart index aaf47d8fc9..2129632338 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart @@ -93,8 +93,8 @@ class GridBloc extends Bloc { ); } - Future _loadFields(Grid grid, Emitter emit) async { - final result = await _gridService.getFields(fieldOrders: grid.fields); + Future _loadFields(GridPB grid, Emitter emit) async { + final result = await _gridService.getFields(fieldIds: grid.fields); return Future( () => result.fold( (fields) { @@ -112,7 +112,7 @@ class GridBloc extends Bloc { ); } - void _initialBlocks(List blocks) { + void _initialBlocks(List blocks) { for (final block in blocks) { if (_blocks[block.id] != null) { Log.warn("Intial duplicate block's cache: ${block.id}"); @@ -141,14 +141,14 @@ class GridEvent with _$GridEvent { const factory GridEvent.createRow() = _CreateRow; const factory GridEvent.didReceiveRowUpdate(List rows, GridRowChangeReason listState) = _DidReceiveRowUpdate; - const factory GridEvent.didReceiveFieldUpdate(List fields) = _DidReceiveFieldUpdate; + const factory GridEvent.didReceiveFieldUpdate(List fields) = _DidReceiveFieldUpdate; } @freezed class GridState with _$GridState { const factory GridState({ required String gridId, - required Option grid, + required Option grid, required GridFieldEquatable fields, required List rowInfos, required GridLoadingState loadingState, @@ -172,8 +172,8 @@ class GridLoadingState with _$GridLoadingState { } class GridFieldEquatable extends Equatable { - final List _fields; - const GridFieldEquatable(List fields) : _fields = fields; + final List _fields; + const GridFieldEquatable(List fields) : _fields = fields; @override List get props { @@ -183,5 +183,5 @@ class GridFieldEquatable extends Equatable { ]; } - UnmodifiableListView get value => UnmodifiableListView(_fields); + UnmodifiableListView get value => UnmodifiableListView(_fields); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart index 3e4db25b3d..b34064da13 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart @@ -34,7 +34,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)); @@ -62,16 +62,16 @@ class GridHeaderBloc extends Bloc { @freezed class GridHeaderEvent with _$GridHeaderEvent { const factory GridHeaderEvent.initial() = _InitialHeader; - const factory GridHeaderEvent.didReceiveFieldUpdate(List fields) = _DidReceiveFieldUpdate; - const factory GridHeaderEvent.moveField(Field field, int fromIndex, int toIndex) = _MoveField; + const factory GridHeaderEvent.didReceiveFieldUpdate(List fields) = _DidReceiveFieldUpdate; + const factory GridHeaderEvent.moveField(GridFieldPB field, int fromIndex, int toIndex) = _MoveField; } @freezed class GridHeaderState with _$GridHeaderState { - const factory GridHeaderState({required List fields}) = _GridHeaderState; + 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/workspace/application/grid/grid_service.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart index 1d0c309d51..e270e32bac 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart @@ -26,16 +26,16 @@ class GridService { return GridEventGetGrid(payload).send(); } - Future> createRow({Option? startRowId}) { - CreateRowPayload payload = CreateRowPayload.create()..gridId = gridId; + 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 fieldOrders}) { - final payload = QueryFieldPayload.create() + Future> getFields({required List fieldIds}) { + final payload = QueryFieldPayloadPB.create() ..gridId = gridId - ..fieldOrders = RepeatedFieldOrder(items: fieldOrders); + ..fieldIds = RepeatedGridFieldIdPB(items: fieldIds); return GridEventGetFields(payload).send(); } @@ -46,18 +46,18 @@ class GridService { } 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(GridFieldChangeset); -typedef FieldsCallback = void Function(List); +typedef FieldChangesetCallback = void Function(GridFieldChangesetPB); +typedef FieldsCallback = void Function(List); class GridFieldCache { final String gridId; @@ -88,11 +88,11 @@ class GridFieldCache { _fieldNotifier = null; } - UnmodifiableListView get unmodifiableFields => UnmodifiableListView(_fieldNotifier?.fields ?? []); + 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]; } @@ -141,12 +141,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 }; @@ -154,11 +154,11 @@ class GridFieldCache { _fieldNotifier?.fields = newFields; } - void _insertFields(List insertedFields) { + void _insertFields(List insertedFields) { 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); @@ -169,11 +169,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); if (index != -1) { @@ -192,7 +192,7 @@ class GridRowCacheFieldNotifierImpl extends GridRowCacheFieldNotifier { GridRowCacheFieldNotifierImpl(GridFieldCache cache) : _cache = cache; @override - UnmodifiableListView get fields => _cache.unmodifiableFields; + UnmodifiableListView get fields => _cache.unmodifiableFields; @override void onFieldsChanged(VoidCallback callback) { @@ -201,8 +201,8 @@ class GridRowCacheFieldNotifierImpl extends GridRowCacheFieldNotifier { } @override - void onFieldChanged(void Function(Field) callback) { - _onChangesetFn = (GridFieldChangeset changeset) { + void onFieldChanged(void Function(GridFieldPB) callback) { + _onChangesetFn = (GridFieldChangesetPB changeset) { for (final updatedField in changeset.updatedFields) { callback(updatedField); } diff --git a/frontend/app_flowy/lib/workspace/application/grid/prelude.dart b/frontend/app_flowy/lib/workspace/application/grid/prelude.dart index 9c09a038e1..2a19ca1134 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/prelude.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/prelude.dart @@ -4,18 +4,18 @@ export 'row/row_service.dart'; export 'grid_service.dart'; export 'grid_header_bloc.dart'; -// Field +// GridFieldPB 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'; -// Field Type Option +// GridFieldPB 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'; -// Cell +// GridCellPB export 'cell/text_cell_bloc.dart'; export 'cell/number_cell_bloc.dart'; export 'cell/select_option_cell_bloc.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart index 6fec53b441..1d7224383d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart @@ -90,9 +90,9 @@ class RowState with _$RowState { } class GridCellEquatable extends Equatable { - final Field _field; + final GridFieldPB _field; - const GridCellEquatable(Field field) : _field = field; + const GridCellEquatable(GridFieldPB field) : _field = field; @override List get props => [ diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart index 98fddaeccf..9aa829d617 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart @@ -8,8 +8,8 @@ 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; @@ -26,7 +26,7 @@ class RowListener { switch (ty) { case GridNotification.DidUpdateRow: result.fold( - (payload) => updateRowNotifier?.value = left(Row.fromBuffer(payload)), + (payload) => updateRowNotifier?.value = left(GridRowPB.fromBuffer(payload)), (error) => updateRowNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart index e733c6c20a..f8f9c7ee3c 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart @@ -15,9 +15,9 @@ part 'row_service.freezed.dart'; typedef RowUpdateCallback = void Function(); abstract class GridRowCacheFieldNotifier { - UnmodifiableListView get fields; + UnmodifiableListView get fields; void onFieldsChanged(VoidCallback callback); - void onFieldChanged(void Function(Field) callback); + void onFieldChanged(void Function(GridFieldPB) callback); void dispose(); } @@ -28,14 +28,14 @@ abstract class GridRowCacheFieldNotifier { class GridRowCache { final String gridId; - final GridBlock block; + final GridBlockPB block; /// _rows containers the current block's rows /// Use List to reverse the order of the GridRow. List _rowInfos = []; /// Use Map for faster access the raw row data. - final HashMap _rowByRowId; + final HashMap _rowByRowId; final GridCellCache _cellCache; final GridRowCacheFieldNotifier _fieldNotifier; @@ -64,7 +64,7 @@ class GridRowCache { await _cellCache.dispose(); } - void applyChangesets(List changesets) { + void applyChangesets(List changesets) { for (final changeset in changesets) { _deleteRows(changeset.deletedRows); _insertRows(changeset.insertedRows); @@ -95,7 +95,7 @@ class GridRowCache { _rowChangeReasonNotifier.receive(GridRowChangeReason.delete(deletedIndex)); } - void _insertRows(List insertRows) { + void _insertRows(List insertRows) { if (insertRows.isEmpty) { return; } @@ -113,7 +113,7 @@ class GridRowCache { _rowChangeReasonNotifier.receive(GridRowChangeReason.insert(insertIndexs)); } - void _updateRows(List updatedRows) { + void _updateRows(List updatedRows) { if (updatedRows.isEmpty) { return; } @@ -183,7 +183,7 @@ class GridRowCache { } GridCellMap loadGridCells(String rowId) { - final Row? data = _rowByRowId[rowId]; + final GridRowPB? data = _rowByRowId[rowId]; if (data == null) { _loadRow(rowId); } @@ -191,7 +191,7 @@ class GridRowCache { } Future _loadRow(String rowId) async { - final payload = GridRowIdPayload.create() + final payload = GridRowIdPayloadPB.create() ..gridId = gridId ..blockId = block.id ..rowId = rowId; @@ -203,7 +203,7 @@ class GridRowCache { ); } - GridCellMap _makeGridCells(String rowId, Row? row) { + GridCellMap _makeGridCells(String rowId, GridRowPB? row) { var cellDataMap = GridCellMap.new(); for (final field in _fieldNotifier.fields) { if (field.visibility) { @@ -217,7 +217,7 @@ class GridRowCache { return cellDataMap; } - void _refreshRow(OptionalRow optionRow) { + void _refreshRow(OptionalRowPB optionRow) { if (!optionRow.hasRow()) { return; } @@ -277,8 +277,8 @@ class RowService { RowService({required this.gridId, required this.blockId, required this.rowId}); - Future> createRow() { - CreateRowPayload payload = CreateRowPayload.create() + Future> createRow() { + CreateRowPayloadPB payload = CreateRowPayloadPB.create() ..gridId = gridId ..startRowId = rowId; @@ -286,18 +286,18 @@ class RowService { } Future> moveRow(String rowId, int fromIndex, int toIndex) { - final payload = MoveItemPayload.create() + final payload = MoveItemPayloadPB.create() ..gridId = gridId ..itemId = rowId - ..ty = MoveItemType.MoveRow + ..ty = MoveItemTypePB.MoveRow ..fromIndex = fromIndex ..toIndex = toIndex; return GridEventMoveItem(payload).send(); } - Future> getRow() { - final payload = GridRowIdPayload.create() + Future> getRow() { + final payload = GridRowIdPayloadPB.create() ..gridId = gridId ..blockId = blockId ..rowId = rowId; @@ -306,7 +306,7 @@ class RowService { } Future> deleteRow() { - final payload = GridRowIdPayload.create() + final payload = GridRowIdPayloadPB.create() ..gridId = gridId ..blockId = blockId ..rowId = rowId; @@ -315,7 +315,7 @@ class RowService { } Future> duplicateRow() { - final payload = GridRowIdPayload.create() + final payload = GridRowIdPayloadPB.create() ..gridId = gridId ..blockId = blockId ..rowId = rowId; @@ -330,9 +330,9 @@ class GridRowInfo with _$GridRowInfo { required String gridId, required String blockId, required String id, - required UnmodifiableListView fields, + required UnmodifiableListView fields, required double height, - Row? rawRow, + GridRowPB? rawRow, }) = _GridRowInfo; } diff --git a/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart index 10c59559d3..ee16eb0455 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart @@ -10,7 +10,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, @@ -62,7 +62,7 @@ class GridPropertyBloc extends Bloc { 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; } @@ -70,10 +70,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) => GridPropertyState( + factory GridPropertyState.initial(String gridId, List fields) => GridPropertyState( gridId: gridId, fields: fields, ); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/layout/layout.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/layout/layout.dart index 36c603b7b4..0b289ecd4b 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/layout/layout.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/layout/layout.dart @@ -2,7 +2,7 @@ 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); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/extension.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/extension.dart index 90a6503079..6946993bae 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/extension.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/extension.dart @@ -7,27 +7,27 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -extension SelectOptionColorExtension on SelectOptionColor { +extension SelectOptionColorExtension on SelectOptionColorPB { Color make(BuildContext context) { final theme = context.watch(); switch (this) { - case SelectOptionColor.Purple: + case SelectOptionColorPB.Purple: return theme.tint1; - case SelectOptionColor.Pink: + case SelectOptionColorPB.Pink: return theme.tint2; - case SelectOptionColor.LightPink: + case SelectOptionColorPB.LightPink: return theme.tint3; - case SelectOptionColor.Orange: + case SelectOptionColorPB.Orange: return theme.tint4; - case SelectOptionColor.Yellow: + case SelectOptionColorPB.Yellow: return theme.tint5; - case SelectOptionColor.Lime: + case SelectOptionColorPB.Lime: return theme.tint6; - case SelectOptionColor.Green: + case SelectOptionColorPB.Green: return theme.tint7; - case SelectOptionColor.Aqua: + case SelectOptionColorPB.Aqua: return theme.tint8; - case SelectOptionColor.Blue: + case SelectOptionColorPB.Blue: return theme.tint9; default: throw ArgumentError; @@ -36,23 +36,23 @@ extension SelectOptionColorExtension on SelectOptionColor { String optionName() { switch (this) { - case SelectOptionColor.Purple: + case SelectOptionColorPB.Purple: return LocaleKeys.grid_selectOption_purpleColor.tr(); - case SelectOptionColor.Pink: + case SelectOptionColorPB.Pink: return LocaleKeys.grid_selectOption_pinkColor.tr(); - case SelectOptionColor.LightPink: + case SelectOptionColorPB.LightPink: return LocaleKeys.grid_selectOption_lightPinkColor.tr(); - case SelectOptionColor.Orange: + case SelectOptionColorPB.Orange: return LocaleKeys.grid_selectOption_orangeColor.tr(); - case SelectOptionColor.Yellow: + case SelectOptionColorPB.Yellow: return LocaleKeys.grid_selectOption_yellowColor.tr(); - case SelectOptionColor.Lime: + case SelectOptionColorPB.Lime: return LocaleKeys.grid_selectOption_limeColor.tr(); - case SelectOptionColor.Green: + case SelectOptionColorPB.Green: return LocaleKeys.grid_selectOption_greenColor.tr(); - case SelectOptionColor.Aqua: + case SelectOptionColorPB.Aqua: return LocaleKeys.grid_selectOption_aquaColor.tr(); - case SelectOptionColor.Blue: + case SelectOptionColorPB.Blue: return LocaleKeys.grid_selectOption_blueColor.tr(); default: throw ArgumentError; @@ -75,7 +75,7 @@ class SelectOptionTag extends StatelessWidget { factory SelectOptionTag.fromSelectOption({ required BuildContext context, - required SelectOption option, + required SelectOptionPB option, VoidCallback? onSelected, bool isSelected = false, }) { @@ -107,8 +107,8 @@ class SelectOptionTag extends StatelessWidget { class SelectOptionTagCell extends StatelessWidget { final List children; - final void Function(SelectOption) onSelected; - final SelectOption option; + final void Function(SelectOptionPB) onSelected; + final SelectOptionPB option; const SelectOptionTagCell({ required this.option, required this.onSelected, diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_cell.dart index 4068507f5a..6669e84576 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_cell.dart @@ -128,7 +128,7 @@ class _MultiSelectCellState extends State { } class _SelectOptionCell extends StatelessWidget { - final List selectOptions; + final List selectOptions; final void Function(bool) onFocus; final SelectOptionCellStyle? cellStyle; final GridCellControllerBuilder cellContorllerBuilder; diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_editor.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_editor.dart index 45a641c39c..95f2bf1e03 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_editor.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/select_option_editor.dart @@ -146,7 +146,7 @@ class _TextField extends StatelessWidget { Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { - final optionMap = LinkedHashMap.fromIterable(state.selectedOptions, + final optionMap = LinkedHashMap.fromIterable(state.selectedOptions, key: (option) => option.name, value: (option) => option); return SizedBox( @@ -216,7 +216,7 @@ class _CreateOptionCell extends StatelessWidget { } class _SelectOptionCell extends StatelessWidget { - final SelectOption option; + final SelectOptionPB option; final bool isSelected; const _SelectOptionCell(this.option, this.isSelected, {Key? key}) : super(key: key); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/text_field.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/text_field.dart index 9bffd4554f..10b04cfb58 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/text_field.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/select_option_cell/text_field.dart @@ -15,8 +15,8 @@ class SelectOptionTextField extends StatelessWidget { final FocusNode _focusNode; final TextEditingController _controller; final TextfieldTagsController tagController; - final List options; - final LinkedHashMap selectedOptionMap; + final List options; + final LinkedHashMap selectedOptionMap; final double distanceToText; diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_cell.dart index 266ec5a619..8202a3537f 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_cell.dart @@ -135,7 +135,7 @@ class _DragToExpandLine extends StatelessWidget { class FieldCellButton extends StatelessWidget { final VoidCallback onTap; - final Field field; + final GridFieldPB field; const FieldCellButton({ required this.field, required this.onTap, diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_option_editor.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_option_editor.dart index 60592d1032..95dd39bae9 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_option_editor.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_type_option_editor.dart @@ -15,8 +15,8 @@ import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/header import 'field_type_extension.dart'; import 'type_option/builder.dart'; -typedef UpdateFieldCallback = void Function(Field, Uint8List); -typedef SwitchToFieldCallback = Future> Function( +typedef UpdateFieldCallback = void Function(GridFieldPB, Uint8List); +typedef SwitchToFieldCallback = Future> Function( String fieldId, FieldType fieldType, ); @@ -59,7 +59,7 @@ class _FieldTypeOptionEditorState extends State { ); } - Widget _switchFieldTypeButton(BuildContext context, Field field) { + Widget _switchFieldTypeButton(BuildContext context, GridFieldPB field) { final theme = context.watch(); return SizedBox( height: GridSize.typeOptionItemHeight, diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart index 2240d7f6aa..5a888129b5 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart @@ -160,7 +160,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/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option.dart index fea3e5df43..c0d54159e8 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option.dart @@ -17,7 +17,7 @@ import 'builder.dart'; import 'select_option_editor.dart'; class SelectOptionTypeOptionWidget extends StatelessWidget { - final List options; + final List options; final VoidCallback beginEdit; final TypeOptionOverlayDelegate overlayDelegate; final SelectOptionTypeOptionAction typeOptionAction; @@ -131,7 +131,7 @@ class _OptionList extends StatelessWidget { ); } - _OptionCell _makeOptionCell(BuildContext context, SelectOption option) { + _OptionCell _makeOptionCell(BuildContext context, SelectOptionPB option) { return _OptionCell( option: option, onSelected: (option) { @@ -154,8 +154,8 @@ class _OptionList extends StatelessWidget { } class _OptionCell extends StatelessWidget { - final SelectOption option; - final Function(SelectOption) onSelected; + final SelectOptionPB option; + final Function(SelectOptionPB) onSelected; const _OptionCell({ required this.option, required this.onSelected, diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option_editor.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option_editor.dart index 3abb0445c7..5381342d20 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option_editor.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/type_option/select_option_editor.dart @@ -15,9 +15,9 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; class SelectOptionTypeOptionEditor extends StatelessWidget { - final SelectOption option; + final SelectOptionPB option; final VoidCallback onDeleted; - final Function(SelectOption) onUpdated; + final Function(SelectOptionPB) onUpdated; const SelectOptionTypeOptionEditor({ required this.option, required this.onDeleted, @@ -110,12 +110,12 @@ class _OptionNameTextField extends StatelessWidget { } class SelectOptionColorList extends StatelessWidget { - final SelectOptionColor selectedColor; + final SelectOptionColorPB selectedColor; const SelectOptionColorList({required this.selectedColor, Key? key}) : super(key: key); @override Widget build(BuildContext context) { - final cells = SelectOptionColor.values.map((color) { + final cells = SelectOptionColorPB.values.map((color) { return _SelectOptionColorCell(color: color, isSelected: selectedColor == color); }).toList(); @@ -152,7 +152,7 @@ class SelectOptionColorList extends StatelessWidget { } class _SelectOptionColorCell extends StatelessWidget { - final SelectOptionColor color; + final SelectOptionColorPB color; final bool isSelected; const _SelectOptionColorCell({required this.color, required this.isSelected, Key? key}) : super(key: key); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dart index 99d70e93c7..b34007493b 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dart @@ -75,7 +75,7 @@ class GridPropertyList extends StatelessWidget with FlowyOverlayDelegate { } class _GridPropertyCell extends StatelessWidget { - final Field field; + final GridFieldPB 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 8bb45b51cd..b5d364f67e 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', - 'Field Hockey', + 'GridFieldPB Hockey', 'Ice Hockey', 'Lacrosse', 'Ping Pong', diff --git a/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs index 57993a27db..11cbdeb88e 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/cell_entities.rs @@ -1,4 +1,4 @@ -use crate::entities::{FieldIdentifier, FieldIdentifierPayloadPB}; +use crate::entities::{FieldIdentifierParams, GridFieldIdentifierPayloadPB}; use flowy_derive::ProtoBuf; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; @@ -6,28 +6,28 @@ use flowy_grid_data_model::revision::{CellRevision, RowMetaChangeset}; use std::collections::HashMap; #[derive(ProtoBuf, Default)] -pub struct CreateSelectOptionPayload { +pub struct CreateSelectOptionPayloadPB { #[pb(index = 1)] - pub field_identifier: FieldIdentifierPayloadPB, + pub field_identifier: GridFieldIdentifierPayloadPB, #[pb(index = 2)] pub option_name: String, } pub struct CreateSelectOptionParams { - pub field_identifier: FieldIdentifier, + pub field_identifier: FieldIdentifierParams, pub option_name: String, } impl std::ops::Deref for CreateSelectOptionParams { - type Target = FieldIdentifier; + type Target = FieldIdentifierParams; fn deref(&self) -> &Self::Target { &self.field_identifier } } -impl TryInto for CreateSelectOptionPayload { +impl TryInto for CreateSelectOptionPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -41,7 +41,7 @@ impl TryInto for CreateSelectOptionPayload { } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct CellIdentifierPayload { +pub struct GridCellIdentifierPayloadPB { #[pb(index = 1)] pub grid_id: String, @@ -52,20 +52,20 @@ pub struct CellIdentifierPayload { pub row_id: String, } -pub struct CellIdentifier { +pub struct CellIdentifierParams { pub grid_id: String, pub field_id: String, pub row_id: String, } -impl TryInto for CellIdentifierPayload { +impl TryInto for GridCellIdentifierPayloadPB { 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)?; let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?; - Ok(CellIdentifier { + Ok(CellIdentifierParams { grid_id: grid_id.0, field_id: field_id.0, row_id: row_id.0, @@ -73,7 +73,7 @@ impl TryInto for CellIdentifierPayload { } } #[derive(Debug, Default, ProtoBuf)] -pub struct Cell { +pub struct GridCellPB { #[pb(index = 1)] pub field_id: String, @@ -81,7 +81,7 @@ pub struct Cell { pub data: Vec, } -impl Cell { +impl GridCellPB { pub fn new(field_id: &str, data: Vec) -> Self { Self { field_id: field_id.to_owned(), @@ -98,32 +98,32 @@ impl Cell { } #[derive(Debug, Default, ProtoBuf)] -pub struct RepeatedCell { +pub struct RepeatedCellPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl std::ops::Deref for RepeatedCell { - type Target = Vec; +impl std::ops::Deref for RepeatedCellPB { + type Target = Vec; fn deref(&self) -> &Self::Target { &self.items } } -impl std::ops::DerefMut for RepeatedCell { +impl std::ops::DerefMut for RepeatedCellPB { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } } -impl std::convert::From> for RepeatedCell { - fn from(items: Vec) -> Self { +impl std::convert::From> for RepeatedCellPB { + fn from(items: Vec) -> Self { Self { items } } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct CellChangeset { +pub struct CellChangesetPB { #[pb(index = 1)] pub grid_id: String, @@ -137,8 +137,8 @@ pub struct CellChangeset { pub content: Option, } -impl std::convert::From for RowMetaChangeset { - fn from(changeset: CellChangeset) -> Self { +impl std::convert::From for RowMetaChangeset { + fn from(changeset: CellChangesetPB) -> Self { let mut cell_by_field_id = HashMap::with_capacity(1); let field_id = changeset.field_id; let cell_rev = CellRevision { 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 1a4fac2e8c..c769b4f08b 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/field_entities.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use strum_macros::{Display, EnumCount as EnumCountMacro, EnumIter, EnumString}; #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct FieldPB { +pub struct GridFieldPB { #[pb(index = 1)] pub id: String, @@ -35,7 +35,7 @@ pub struct FieldPB { pub is_primary: bool, } -impl std::convert::From for FieldPB { +impl std::convert::From for GridFieldPB { fn from(field_rev: FieldRevision) -> Self { Self { id: field_rev.id, @@ -50,31 +50,31 @@ impl std::convert::From for FieldPB { } } -impl std::convert::From> for FieldPB { +impl std::convert::From> for GridFieldPB { fn from(field_rev: Arc) -> Self { let field_rev = field_rev.as_ref().clone(); - FieldPB::from(field_rev) + GridFieldPB::from(field_rev) } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct GridFieldPB { +pub struct GridFieldIdPB { #[pb(index = 1)] pub field_id: String, } -impl std::convert::From<&str> for GridFieldPB { +impl std::convert::From<&str> for GridFieldIdPB { fn from(s: &str) -> Self { - GridFieldPB { field_id: s.to_owned() } + GridFieldIdPB { field_id: s.to_owned() } } } -impl std::convert::From for GridFieldPB { +impl std::convert::From for GridFieldIdPB { fn from(s: String) -> Self { - GridFieldPB { field_id: s } + GridFieldIdPB { field_id: s } } } -impl std::convert::From<&Arc> for GridFieldPB { +impl std::convert::From<&Arc> for GridFieldIdPB { fn from(field_rev: &Arc) -> Self { Self { field_id: field_rev.id.clone(), @@ -90,10 +90,10 @@ 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 { @@ -106,7 +106,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![], @@ -115,7 +115,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![], @@ -128,7 +128,7 @@ impl GridFieldChangesetPB { #[derive(Debug, Clone, Default, ProtoBuf)] pub struct IndexFieldPB { #[pb(index = 1)] - pub field: FieldPB, + pub field: GridFieldPB, #[pb(index = 2)] pub index: i32, @@ -137,7 +137,7 @@ pub struct IndexFieldPB { impl IndexFieldPB { pub fn from_field_rev(field_rev: &Arc, index: usize) -> Self { Self { - field: FieldPB::from(field_rev.as_ref().clone()), + field: GridFieldPB::from(field_rev.as_ref().clone()), index: index as i32, } } @@ -214,42 +214,17 @@ pub struct FieldTypeOptionDataPB { pub grid_id: String, #[pb(index = 2)] - pub field: FieldPB, + pub field: GridFieldPB, #[pb(index = 3)] pub type_option_data: Vec, } #[derive(Debug, Default, ProtoBuf)] -pub struct RepeatedFieldPB { - #[pb(index = 1)] - pub items: Vec, -} -impl std::ops::Deref for RepeatedFieldPB { - type Target = Vec; - fn deref(&self) -> &Self::Target { - &self.items - } -} - -impl std::ops::DerefMut for RepeatedFieldPB { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.items - } -} - -impl std::convert::From> for RepeatedFieldPB { - fn from(items: Vec) -> Self { - Self { items } - } -} - -#[derive(Debug, Clone, Default, ProtoBuf)] pub struct RepeatedGridFieldPB { #[pb(index = 1)] pub items: Vec, } - impl std::ops::Deref for RepeatedGridFieldPB { type Target = Vec; fn deref(&self) -> &Self::Target { @@ -257,16 +232,41 @@ impl std::ops::Deref for RepeatedGridFieldPB { } } -impl std::convert::From> for RepeatedGridFieldPB { - fn from(field_orders: Vec) -> Self { - RepeatedGridFieldPB { items: field_orders } +impl std::ops::DerefMut for RepeatedGridFieldPB { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.items } } -impl std::convert::From for RepeatedGridFieldPB { +impl std::convert::From> for RepeatedGridFieldPB { + fn from(items: Vec) -> Self { + Self { items } + } +} + +#[derive(Debug, Clone, Default, ProtoBuf)] +pub struct RepeatedGridFieldIdPB { + #[pb(index = 1)] + pub items: Vec, +} + +impl std::ops::Deref for RepeatedGridFieldIdPB { + 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 RepeatedGridFieldIdPB { fn from(s: String) -> Self { - RepeatedGridFieldPB { - items: vec![GridFieldPB::from(s)], + RepeatedGridFieldIdPB { + items: vec![GridFieldIdPB::from(s)], } } } @@ -277,7 +277,7 @@ pub struct InsertFieldPayloadPB { pub grid_id: String, #[pb(index = 2)] - pub field: FieldPB, + pub field: GridFieldPB, #[pb(index = 3)] pub type_option_data: Vec, @@ -289,7 +289,7 @@ pub struct InsertFieldPayloadPB { #[derive(Clone)] pub struct InsertFieldParams { pub grid_id: String, - pub field: FieldPB, + pub field: GridFieldPB, pub type_option_data: Vec, pub start_field_id: Option, } @@ -355,12 +355,12 @@ pub struct QueryFieldPayloadPB { pub grid_id: String, #[pb(index = 2)] - pub field_orders: RepeatedGridFieldPB, + pub field_ids: RepeatedGridFieldIdPB, } pub struct QueryFieldParams { pub grid_id: String, - pub field_orders: RepeatedGridFieldPB, + pub field_ids: RepeatedGridFieldIdPB, } impl TryInto for QueryFieldPayloadPB { @@ -370,7 +370,7 @@ impl TryInto for QueryFieldPayloadPB { let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; Ok(QueryFieldParams { grid_id: grid_id.0, - field_orders: self.field_orders, + field_ids: self.field_ids, }) } } @@ -557,7 +557,7 @@ impl std::convert::From for FieldType { } } #[derive(Debug, Clone, Default, ProtoBuf)] -pub struct FieldIdentifierPayloadPB { +pub struct GridFieldIdentifierPayloadPB { #[pb(index = 1)] pub field_id: String, @@ -565,18 +565,18 @@ pub struct FieldIdentifierPayloadPB { pub grid_id: String, } -pub struct FieldIdentifier { +pub struct FieldIdentifierParams { pub field_id: String, pub grid_id: String, } -impl TryInto for FieldIdentifierPayloadPB { +impl TryInto for GridFieldIdentifierPayloadPB { 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(FieldIdentifier { + Ok(FieldIdentifierParams { grid_id: grid_id.0, field_id: field_id.0, }) 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 d333f201a4..1be0412503 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, GridFieldPB}; +use crate::entities::{GridBlockPB, GridFieldIdPB}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; @@ -8,7 +8,7 @@ pub struct GridPB { pub id: String, #[pb(index = 2)] - pub fields: Vec, + pub fields: Vec, #[pb(index = 3)] pub blocks: Vec, diff --git a/frontend/rust-lib/flowy-grid/src/event_handler.rs b/frontend/rust-lib/flowy-grid/src/event_handler.rs index 81f74c8e32..4c4bfe5559 100644 --- a/frontend/rust-lib/flowy-grid/src/event_handler.rs +++ b/frontend/rust-lib/flowy-grid/src/event_handler.rs @@ -3,9 +3,9 @@ use crate::manager::GridManager; use crate::services::cell::AnyCellData; use crate::services::field::{ default_type_option_builder_from_type, select_option_operation, type_option_builder_from_json_str, - DateChangesetParams, DateChangesetPayloadPB, SelectOptionPB, SelectOptionCellChangeset, - SelectOptionCellChangesetParams, SelectOptionCellChangesetPayloadPB, SelectOptionCellDataPB, SelectOptionChangeset, - SelectOptionChangesetPayloadPB, + DateChangesetParams, DateChangesetPayloadPB, SelectOptionCellChangeset, SelectOptionCellChangesetParams, + SelectOptionCellChangesetPayloadPB, SelectOptionCellDataPB, SelectOptionChangeset, SelectOptionChangesetPayloadPB, + SelectOptionPB, }; use crate::services::row::make_row_from_row_rev; use flowy_error::{ErrorCode, FlowyError, FlowyResult}; @@ -62,17 +62,17 @@ 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 - .field_orders + .field_ids .items .into_iter() .map(|field_order| field_order.field_id) .collect(); let field_revs = editor.get_field_revs(Some(field_orders)).await?; - let repeated_field: RepeatedFieldPB = field_revs.into_iter().map(FieldPB::from).collect::>().into(); + let repeated_field: RepeatedGridFieldPB = field_revs.into_iter().map(GridFieldPB::from).collect::>().into(); data_result(repeated_field) } @@ -113,10 +113,10 @@ pub(crate) async fn update_field_type_option_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn delete_field_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { - let params: FieldIdentifier = data.into_inner().try_into()?; + let params: FieldIdentifierParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let _ = editor.delete_field(¶ms.field_id).await?; Ok(()) @@ -151,10 +151,10 @@ pub(crate) async fn switch_to_field_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn duplicate_field_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { - let params: FieldIdentifier = data.into_inner().try_into()?; + let params: FieldIdentifierParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; let _ = editor.duplicate_field(¶ms.field_id).await?; Ok(()) @@ -275,23 +275,23 @@ pub(crate) async fn create_row_handler( // #[tracing::instrument(level = "debug", skip_all, err)] pub(crate) async fn get_cell_handler( - data: Data, + data: Data, manager: AppData>, -) -> DataResult { - let params: CellIdentifier = data.into_inner().try_into()?; +) -> DataResult { + let params: CellIdentifierParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; match editor.get_cell(¶ms).await { - None => data_result(Cell::empty(¶ms.field_id)), + None => data_result(GridCellPB::empty(¶ms.field_id)), Some(cell) => data_result(cell), } } #[tracing::instrument(level = "trace", skip_all, err)] pub(crate) async fn update_cell_handler( - data: Data, + data: Data, manager: AppData>, ) -> Result<(), FlowyError> { - let changeset: CellChangeset = data.into_inner(); + let changeset: CellChangesetPB = data.into_inner(); let editor = manager.get_grid_editor(&changeset.grid_id)?; let _ = editor.update_cell(changeset).await?; Ok(()) @@ -299,7 +299,7 @@ pub(crate) async fn update_cell_handler( #[tracing::instrument(level = "trace", skip_all, err)] pub(crate) async fn new_select_option_handler( - data: Data, + data: Data, manager: AppData>, ) -> DataResult { let params: CreateSelectOptionParams = data.into_inner().try_into()?; @@ -344,7 +344,7 @@ pub(crate) async fn update_select_option_handler( mut_field_rev.insert_type_option_entry(&*type_option); let _ = editor.replace_field(field_rev).await?; - let changeset = CellChangeset { + let changeset = CellChangesetPB { grid_id: changeset.cell_identifier.grid_id, row_id: changeset.cell_identifier.row_id, field_id: changeset.cell_identifier.field_id, @@ -357,10 +357,10 @@ pub(crate) async fn update_select_option_handler( #[tracing::instrument(level = "trace", skip(data, manager), err)] pub(crate) async fn get_select_option_handler( - data: Data, + data: Data, manager: AppData>, ) -> DataResult { - let params: CellIdentifier = data.into_inner().try_into()?; + let params: CellIdentifierParams = data.into_inner().try_into()?; let editor = manager.get_grid_editor(¶ms.grid_id)?; match editor.get_field_rev(¶ms.field_id).await { None => { diff --git a/frontend/rust-lib/flowy-grid/src/event_map.rs b/frontend/rust-lib/flowy-grid/src/event_map.rs index 8739be5257..5abda48c1b 100644 --- a/frontend/rust-lib/flowy-grid/src/event_map.rs +++ b/frontend/rust-lib/flowy-grid/src/event_map.rs @@ -45,78 +45,78 @@ pub fn create(grid_manager: Arc) -> Module { #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] #[event_err = "FlowyError"] pub enum GridEvent { - #[event(input = "GridId", output = "Grid")] + #[event(input = "GridIdPB", output = "GridPB")] GetGrid = 0, - #[event(input = "QueryGridBlocksPayload", output = "RepeatedGridBlock")] + #[event(input = "QueryGridBlocksPayloadPB", output = "RepeatedGridBlockPB")] GetGridBlocks = 1, - #[event(input = "GridId", output = "GridSetting")] + #[event(input = "GridIdPB", output = "GridSettingPB")] GetGridSetting = 2, - #[event(input = "GridId", input = "GridSettingChangesetPayload")] + #[event(input = "GridIdPB", input = "GridSettingChangesetPayloadPB")] UpdateGridSetting = 3, - #[event(input = "QueryFieldPayload", output = "RepeatedField")] + #[event(input = "QueryFieldPayloadPB", output = "RepeatedGridFieldPB")] GetFields = 10, - #[event(input = "FieldChangesetPayload")] + #[event(input = "FieldChangesetPayloadPB")] UpdateField = 11, - #[event(input = "UpdateFieldTypeOptionPayload")] + #[event(input = "UpdateFieldTypeOptionPayloadPB")] UpdateFieldTypeOption = 12, - #[event(input = "InsertFieldPayload")] + #[event(input = "InsertFieldPayloadPB")] InsertField = 13, - #[event(input = "FieldIdentifierPayload")] + #[event(input = "GridFieldIdentifierPayloadPB")] DeleteField = 14, - #[event(input = "EditFieldPayload", output = "FieldTypeOptionData")] + #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")] SwitchToField = 20, - #[event(input = "FieldIdentifierPayload")] + #[event(input = "GridFieldIdentifierPayloadPB")] DuplicateField = 21, - #[event(input = "MoveItemPayload")] + #[event(input = "MoveItemPayloadPB")] MoveItem = 22, - #[event(input = "EditFieldPayload", output = "FieldTypeOptionData")] + #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")] GetFieldTypeOption = 23, - #[event(input = "EditFieldPayload", output = "FieldTypeOptionData")] + #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")] CreateFieldTypeOption = 24, - #[event(input = "CreateSelectOptionPayload", output = "SelectOption")] + #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")] NewSelectOption = 30, - #[event(input = "CellIdentifierPayload", output = "SelectOptionCellData")] + #[event(input = "GridCellIdentifierPayloadPB", output = "SelectOptionCellDataPB")] GetSelectOptionCellData = 31, - #[event(input = "SelectOptionChangesetPayload")] + #[event(input = "SelectOptionChangesetPayloadPB")] UpdateSelectOption = 32, - #[event(input = "CreateRowPayload", output = "Row")] + #[event(input = "CreateRowPayloadPB", output = "GridRowPB")] CreateRow = 50, - #[event(input = "GridRowIdPayload", output = "OptionalRow")] + #[event(input = "GridRowIdPayloadPB", output = "OptionalRowPB")] GetRow = 51, - #[event(input = "GridRowIdPayload")] + #[event(input = "GridRowIdPayloadPB")] DeleteRow = 52, - #[event(input = "GridRowIdPayload")] + #[event(input = "GridRowIdPayloadPB")] DuplicateRow = 53, - #[event(input = "CellIdentifierPayload", output = "Cell")] + #[event(input = "GridCellIdentifierPayloadPB", output = "GridCellPB")] GetCell = 70, - #[event(input = "CellChangeset")] + #[event(input = "CellChangesetPB")] UpdateCell = 71, - #[event(input = "SelectOptionCellChangesetPayload")] + #[event(input = "SelectOptionCellChangesetPayloadPB")] UpdateSelectOptionCell = 72, - #[event(input = "DateChangesetPayload")] + #[event(input = "DateChangesetPayloadPB")] UpdateDateCell = 80, } 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 0bbd3b09f0..39c1a442b5 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::{CellChangeset, GridBlockChangesetPB, GridRowPB, InsertedRowPB, UpdatedRowPB}; +use crate::entities::{CellChangesetPB, GridBlockChangesetPB, GridRowPB, InsertedRowPB, UpdatedRowPB}; use crate::manager::GridUser; use crate::services::block_revision_editor::GridBlockRevisionEditor; use crate::services::persistence::block_index::BlockIndexCache; @@ -196,7 +196,7 @@ impl GridBlockManager { Ok(()) } - pub async fn update_cell(&self, changeset: CellChangeset, row_builder: F) -> FlowyResult<()> + pub async fn update_cell(&self, changeset: CellChangesetPB, row_builder: F) -> FlowyResult<()> where F: FnOnce(Arc) -> Option, { @@ -254,7 +254,7 @@ impl GridBlockManager { Ok(()) } - async fn notify_did_update_cell(&self, changeset: CellChangeset) -> FlowyResult<()> { + async fn notify_did_update_cell(&self, changeset: CellChangesetPB) -> FlowyResult<()> { let id = format!("{}:{}", changeset.row_id, changeset.field_id); send_dart_notification(&id, GridNotification::DidUpdateCell).send(); Ok(()) 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 dea6686915..de1f37b04f 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::{FieldPB, FieldType}; +use crate::entities::{FieldType, GridFieldPB}; 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: FieldPB, type_option_builder: Box) -> Self { + pub fn from_field(field: GridFieldPB, 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/field/type_options/date_type_option/date_type_option_entities.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option_entities.rs index 28dfd90dcf..aa8fab221a 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/date_type_option/date_type_option_entities.rs @@ -1,5 +1,5 @@ -use crate::entities::CellChangeset; -use crate::entities::{CellIdentifier, CellIdentifierPayload}; +use crate::entities::CellChangesetPB; +use crate::entities::{CellIdentifierParams, GridCellIdentifierPayloadPB}; use crate::services::cell::{CellBytesParser, FromCellChangeset, FromCellString}; use bytes::Bytes; @@ -24,7 +24,7 @@ pub struct DateCellDataPB { #[derive(Clone, Debug, Default, ProtoBuf)] pub struct DateChangesetPayloadPB { #[pb(index = 1)] - pub cell_identifier: CellIdentifierPayload, + pub cell_identifier: GridCellIdentifierPayloadPB, #[pb(index = 2, one_of)] pub date: Option, @@ -34,7 +34,7 @@ pub struct DateChangesetPayloadPB { } pub struct DateChangesetParams { - pub cell_identifier: CellIdentifier, + pub cell_identifier: CellIdentifierParams, pub date: Option, pub time: Option, } @@ -43,7 +43,7 @@ impl TryInto for DateChangesetPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { - let cell_identifier: CellIdentifier = self.cell_identifier.try_into()?; + let cell_identifier: CellIdentifierParams = self.cell_identifier.try_into()?; Ok(DateChangesetParams { cell_identifier, date: self.date, @@ -52,14 +52,14 @@ impl TryInto for DateChangesetPayloadPB { } } -impl std::convert::From for CellChangeset { +impl std::convert::From for CellChangesetPB { fn from(params: DateChangesetParams) -> Self { let changeset = DateCellChangesetPB { date: params.date, time: params.time, }; let s = serde_json::to_string(&changeset).unwrap(); - CellChangeset { + CellChangesetPB { grid_id: params.cell_identifier.grid_id, row_id: params.cell_identifier.row_id, field_id: params.cell_identifier.field_id, diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs index e3dd16ef2f..dbffe79f56 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_option.rs @@ -1,4 +1,4 @@ -use crate::entities::{CellChangeset, CellIdentifier, CellIdentifierPayload, FieldType}; +use crate::entities::{CellChangesetPB, CellIdentifierParams, FieldType, GridCellIdentifierPayloadPB}; use crate::services::cell::{CellBytes, CellBytesParser, CellData, CellDisplayable, FromCellChangeset, FromCellString}; use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB}; use bytes::Bytes; @@ -225,7 +225,7 @@ impl CellBytesParser for SelectOptionCellDataParser { #[derive(Clone, Debug, Default, ProtoBuf)] pub struct SelectOptionCellChangesetPayloadPB { #[pb(index = 1)] - pub cell_identifier: CellIdentifierPayload, + pub cell_identifier: GridCellIdentifierPayloadPB, #[pb(index = 2, one_of)] pub insert_option_id: Option, @@ -235,19 +235,19 @@ pub struct SelectOptionCellChangesetPayloadPB { } pub struct SelectOptionCellChangesetParams { - pub cell_identifier: CellIdentifier, + pub cell_identifier: CellIdentifierParams, pub insert_option_id: Option, pub delete_option_id: Option, } -impl std::convert::From for CellChangeset { +impl std::convert::From for CellChangesetPB { fn from(params: SelectOptionCellChangesetParams) -> Self { let changeset = SelectOptionCellChangeset { insert_option_id: params.insert_option_id, delete_option_id: params.delete_option_id, }; let s = serde_json::to_string(&changeset).unwrap(); - CellChangeset { + CellChangesetPB { grid_id: params.cell_identifier.grid_id, row_id: params.cell_identifier.row_id, field_id: params.cell_identifier.field_id, @@ -260,7 +260,7 @@ impl TryInto for SelectOptionCellChangesetPaylo type Error = ErrorCode; fn try_into(self) -> Result { - let cell_identifier: CellIdentifier = self.cell_identifier.try_into()?; + let cell_identifier: CellIdentifierParams = self.cell_identifier.try_into()?; let insert_option_id = match self.insert_option_id { None => None, Some(insert_option_id) => Some( @@ -334,7 +334,7 @@ pub struct SelectOptionCellDataPB { #[derive(Clone, Debug, Default, ProtoBuf)] pub struct SelectOptionChangesetPayloadPB { #[pb(index = 1)] - pub cell_identifier: CellIdentifierPayload, + pub cell_identifier: GridCellIdentifierPayloadPB, #[pb(index = 2, one_of)] pub insert_option: Option, @@ -347,7 +347,7 @@ pub struct SelectOptionChangesetPayloadPB { } pub struct SelectOptionChangeset { - pub cell_identifier: CellIdentifier, + pub cell_identifier: CellIdentifierParams, pub insert_option: Option, pub update_option: Option, pub delete_option: Option, 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 a292ffa1ff..0fef3230de 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs @@ -1,5 +1,5 @@ use crate::dart_notification::{send_dart_notification, GridNotification}; -use crate::entities::CellIdentifier; +use crate::entities::CellIdentifierParams; use crate::entities::*; use crate::manager::{GridTaskSchedulerRwLock, GridUser}; use crate::services::block_manager::GridBlockManager; @@ -188,7 +188,7 @@ 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 = GridFieldPB::from(field_id); + let field_order = GridFieldIdPB::from(field_id); let notified_changeset = GridFieldChangesetPB::delete(&self.grid_id, vec![field_order]); let _ = self.notify_did_update_grid(notified_changeset).await?; Ok(()) @@ -339,12 +339,12 @@ impl GridRevisionEditor { Ok(()) } - pub async fn get_cell(&self, params: &CellIdentifier) -> Option { + pub async fn get_cell(&self, params: &CellIdentifierParams) -> Option { let cell_bytes = self.get_cell_bytes(params).await?; - Some(Cell::new(¶ms.field_id, cell_bytes.to_vec())) + Some(GridCellPB::new(¶ms.field_id, cell_bytes.to_vec())) } - pub async fn get_cell_bytes(&self, params: &CellIdentifier) -> Option { + pub async fn get_cell_bytes(&self, params: &CellIdentifierParams) -> Option { let field_rev = self.get_field_rev(¶ms.field_id).await?; let row_rev = self.block_manager.get_row_rev(¶ms.row_id).await.ok()??; @@ -364,12 +364,12 @@ impl GridRevisionEditor { } #[tracing::instrument(level = "trace", skip_all, err)] - pub async fn update_cell(&self, cell_changeset: CellChangeset) -> FlowyResult<()> { + pub async fn update_cell(&self, cell_changeset: CellChangesetPB) -> FlowyResult<()> { if cell_changeset.content.as_ref().is_none() { return Ok(()); } - let CellChangeset { + let CellChangesetPB { grid_id, row_id, field_id, @@ -387,7 +387,7 @@ impl GridRevisionEditor { let cell_rev = self.get_cell_rev(&row_id, &field_id).await?; // Update the changeset.data property with the return value. content = Some(apply_cell_data_changeset(content.unwrap(), cell_rev, field_rev)?); - let cell_changeset = CellChangeset { + let cell_changeset = CellChangesetPB { grid_id, row_id, field_id, @@ -425,7 +425,7 @@ impl GridRevisionEditor { let field_orders = pad_read_guard .get_field_revs(None)? .iter() - .map(GridFieldPB::from) + .map(GridFieldIdPB::from) .collect(); let mut block_orders = vec![]; for block_rev in pad_read_guard.get_block_meta_revs() { @@ -508,7 +508,7 @@ 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 = GridFieldPB::from(field_id); + let delete_field_order = GridFieldIdPB::from(field_id); let insert_field = IndexFieldPB::from_field_rev(field_rev, index); let notified_changeset = GridFieldChangesetPB { grid_id: self.grid_id.clone(), @@ -615,7 +615,7 @@ impl GridRevisionEditor { .get_field_rev(field_id) .map(|(index, field)| (index, field.clone())) { - let updated_field = FieldPB::from(field_rev); + let updated_field = GridFieldPB::from(field_rev); let notified_changeset = GridFieldChangesetPB::update(&self.grid_id, vec![updated_field.clone()]); let _ = self.notify_did_update_grid(notified_changeset).await?; 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 318910f217..33548f97c5 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::{CellIdentifier, FieldType, GridRowPB}; +use flowy_grid::entities::{CellIdentifierParams, FieldType, GridRowPB}; use flowy_grid::services::field::*; use flowy_grid_data_model::revision::{ GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision, @@ -109,7 +109,7 @@ impl GridRowTest { field_type, expected, } => { - let id = CellIdentifier { + let id = CellIdentifierParams { grid_id: self.grid_id.clone(), field_id, row_id, @@ -154,7 +154,7 @@ impl GridRowTest { } } - async fn compare_cell_content(&self, cell_id: CellIdentifier, field_type: FieldType, expected: String) { + async fn compare_cell_content(&self, cell_id: CellIdentifierParams, field_type: FieldType, expected: String) { match field_type { FieldType::RichText => { let cell_data = self diff --git a/frontend/rust-lib/flowy-grid/tests/grid/cell_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/cell_test/script.rs index a6c88ef1c9..4def72696d 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/cell_test/script.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/cell_test/script.rs @@ -1,8 +1,8 @@ use crate::grid::grid_editor::GridEditorTest; -use flowy_grid::entities::CellChangeset; +use flowy_grid::entities::CellChangesetPB; pub enum CellScript { - UpdateCell { changeset: CellChangeset, is_err: bool }, + UpdateCell { changeset: CellChangesetPB, is_err: bool }, } pub struct GridCellTest { diff --git a/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs b/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs index 2334c89f9a..e8435c2d00 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/cell_test/test.rs @@ -1,7 +1,7 @@ use crate::grid::cell_test::script::CellScript::*; use crate::grid::cell_test::script::GridCellTest; use crate::grid::field_test::util::make_date_cell_string; -use flowy_grid::entities::{CellChangeset, FieldType}; +use flowy_grid::entities::{CellChangesetPB, FieldType}; use flowy_grid::services::field::selection_type_option::SelectOptionCellChangeset; use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB}; @@ -36,7 +36,7 @@ async fn grid_cell_update() { }; scripts.push(UpdateCell { - changeset: CellChangeset { + changeset: CellChangesetPB { grid_id: block_id.to_string(), row_id: row_rev.id.clone(), field_id: field_rev.id.clone(), 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 95b6759950..01424cef74 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 = FieldPB { + let field = GridFieldPB { 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 = FieldPB { + let field = GridFieldPB { id: field_rev.id, name: field_rev.name, desc: field_rev.desc,