chore: add suffix PB to dart class

This commit is contained in:
appflowy 2022-07-17 14:13:12 +08:00
parent 1bf0f0f875
commit e45b14910b
61 changed files with 426 additions and 426 deletions

View File

@ -8,7 +8,7 @@ import 'package:flowy_sdk/rust_stream.dart';
import 'notification_helper.dart'; import 'notification_helper.dart';
// Grid // GridPB
typedef GridNotificationCallback = void Function(GridNotification, Either<Uint8List, FlowyError>); typedef GridNotificationCallback = void Function(GridNotification, Either<Uint8List, FlowyError>);
class GridNotificationParser extends NotificationParser<GridNotification, FlowyError> { class GridNotificationParser extends NotificationParser<GridNotification, FlowyError> {

View File

@ -134,7 +134,7 @@ void _resolveDocDeps(GetIt getIt) {
} }
void _resolveGridDeps(GetIt getIt) { void _resolveGridDeps(GetIt getIt) {
// Grid // GridPB
getIt.registerFactoryParam<GridBloc, View, void>( getIt.registerFactoryParam<GridBloc, View, void>(
(view, _) => GridBloc(view: view), (view, _) => GridBloc(view: view),
); );

View File

@ -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/block_entities.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart';
typedef GridBlockUpdateNotifierValue = Either<List<GridBlockChangeset>, FlowyError>; typedef GridBlockUpdateNotifierValue = Either<List<GridBlockChangesetPB>, FlowyError>;
class GridBlockListener { class GridBlockListener {
final String blockId; final String blockId;
@ -33,7 +33,7 @@ class GridBlockListener {
switch (ty) { switch (ty) {
case GridNotification.DidUpdateGridBlock: case GridNotification.DidUpdateGridBlock:
result.fold( result.fold(
(payload) => _rowsUpdateNotifier?.value = left([GridBlockChangeset.fromBuffer(payload)]), (payload) => _rowsUpdateNotifier?.value = left([GridBlockChangesetPB.fromBuffer(payload)]),
(error) => _rowsUpdateNotifier?.value = right(error), (error) => _rowsUpdateNotifier?.value = right(error),
); );
break; break;

View File

@ -24,7 +24,7 @@ class GridCellDataLoader<T> {
Future<T?> loadData() { Future<T?> loadData() {
final fut = service.getCell(cellId: cellId); final fut = service.getCell(cellId: cellId);
return fut.then( return fut.then(
(result) => result.fold((Cell cell) { (result) => result.fold((GridCellPB cell) {
try { try {
return parser.parserData(cell.data); return parser.parserData(cell.data);
} catch (e, s) { } catch (e, s) {
@ -48,32 +48,32 @@ class StringCellDataParser implements ICellDataParser<String> {
} }
} }
class DateCellDataParser implements ICellDataParser<DateCellData> { class DateCellDataParser implements ICellDataParser<DateCellDataPB> {
@override @override
DateCellData? parserData(List<int> data) { DateCellDataPB? parserData(List<int> data) {
if (data.isEmpty) { if (data.isEmpty) {
return null; return null;
} }
return DateCellData.fromBuffer(data); return DateCellDataPB.fromBuffer(data);
} }
} }
class SelectOptionCellDataParser implements ICellDataParser<SelectOptionCellData> { class SelectOptionCellDataParser implements ICellDataParser<SelectOptionCellDataPB> {
@override @override
SelectOptionCellData? parserData(List<int> data) { SelectOptionCellDataPB? parserData(List<int> data) {
if (data.isEmpty) { if (data.isEmpty) {
return null; return null;
} }
return SelectOptionCellData.fromBuffer(data); return SelectOptionCellDataPB.fromBuffer(data);
} }
} }
class URLCellDataParser implements ICellDataParser<URLCellData> { class URLCellDataParser implements ICellDataParser<URLCellDataPB> {
@override @override
URLCellData? parserData(List<int> data) { URLCellDataPB? parserData(List<int> data) {
if (data.isEmpty) { if (data.isEmpty) {
return null; return null;
} }
return URLCellData.fromBuffer(data); return URLCellDataPB.fromBuffer(data);
} }
} }

View File

@ -40,7 +40,7 @@ class DateCellDataPersistence implements IGridCellDataPersistence<CalendarData>
@override @override
Future<Option<FlowyError>> save(CalendarData data) { Future<Option<FlowyError>> save(CalendarData data) {
var payload = DateChangesetPayload.create()..cellIdentifier = _makeCellIdPayload(cellId); var payload = DateChangesetPayloadPB.create()..cellIdentifier = _makeCellIdPayload(cellId);
final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString(); final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString();
payload.date = date; payload.date = date;
@ -58,8 +58,8 @@ class DateCellDataPersistence implements IGridCellDataPersistence<CalendarData>
} }
} }
CellIdentifierPayload _makeCellIdPayload(GridCellIdentifier cellId) { GridCellIdentifierPayloadPB _makeCellIdPayload(GridCellIdentifier cellId) {
return CellIdentifierPayload.create() return GridCellIdentifierPayloadPB.create()
..gridId = cellId.gridId ..gridId = cellId.gridId
..fieldId = cellId.fieldId ..fieldId = cellId.fieldId
..rowId = cellId.rowId; ..rowId = cellId.rowId;

View File

@ -4,11 +4,11 @@ import 'package:flutter/foundation.dart';
import 'cell_service.dart'; import 'cell_service.dart';
abstract class GridFieldChangedNotifier { abstract class GridFieldChangedNotifier {
void onFieldChanged(void Function(Field) callback); void onFieldChanged(void Function(GridFieldPB) callback);
void dispose(); 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. /// You Register an onFieldChanged callback to listen to the cell changes, and unregister if you don't want to listen.
class GridCellFieldNotifier { class GridCellFieldNotifier {
/// fieldId: {objectId: callback} /// fieldId: {objectId: callback}

View File

@ -35,7 +35,7 @@ class CellService {
required GridCellIdentifier cellId, required GridCellIdentifier cellId,
required String data, required String data,
}) { }) {
final payload = CellChangeset.create() final payload = CellChangesetPB.create()
..gridId = cellId.gridId ..gridId = cellId.gridId
..fieldId = cellId.fieldId ..fieldId = cellId.fieldId
..rowId = cellId.rowId ..rowId = cellId.rowId
@ -43,10 +43,10 @@ class CellService {
return GridEventUpdateCell(payload).send(); return GridEventUpdateCell(payload).send();
} }
Future<Either<Cell, FlowyError>> getCell({ Future<Either<GridCellPB, FlowyError>> getCell({
required GridCellIdentifier cellId, required GridCellIdentifier cellId,
}) { }) {
final payload = CellIdentifierPayload.create() final payload = GridCellIdentifierPayloadPB.create()
..gridId = cellId.gridId ..gridId = cellId.gridId
..fieldId = cellId.fieldId ..fieldId = cellId.fieldId
..rowId = cellId.rowId; ..rowId = cellId.rowId;
@ -61,7 +61,7 @@ class GridCellIdentifier with _$GridCellIdentifier {
const factory GridCellIdentifier({ const factory GridCellIdentifier({
required String gridId, required String gridId,
required String rowId, required String rowId,
required Field field, required GridFieldPB field,
}) = _GridCellIdentifier; }) = _GridCellIdentifier;
// ignore: unused_element // ignore: unused_element

View File

@ -1,9 +1,9 @@
part of 'cell_service.dart'; part of 'cell_service.dart';
typedef GridCellController = IGridCellController<String, String>; typedef GridCellController = IGridCellController<String, String>;
typedef GridSelectOptionCellController = IGridCellController<SelectOptionCellData, String>; typedef GridSelectOptionCellController = IGridCellController<SelectOptionCellDataPB, String>;
typedef GridDateCellController = IGridCellController<DateCellData, CalendarData>; typedef GridDateCellController = IGridCellController<DateCellDataPB, CalendarData>;
typedef GridURLCellController = IGridCellController<URLCellData, String>; typedef GridURLCellController = IGridCellController<URLCellDataPB, String>;
class GridCellControllerBuilder { class GridCellControllerBuilder {
final GridCellIdentifier _cellId; final GridCellIdentifier _cellId;
@ -159,7 +159,7 @@ class IGridCellController<T, D> extends Equatable {
String get fieldId => cellId.field.id; String get fieldId => cellId.field.id;
Field get field => cellId.field; GridFieldPB get field => cellId.field;
FieldType get fieldType => cellId.field.fieldType; FieldType get fieldType => cellId.field.fieldType;
@ -223,7 +223,7 @@ class IGridCellController<T, D> extends Equatable {
return data; 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. /// [PD] is the type that the parser return.
Future<Either<PD, FlowyError>> getFieldTypeOption<PD, P extends TypeOptionDataParser>(P parser) { Future<Either<PD, FlowyError>> getFieldTypeOption<PD, P extends TypeOptionDataParser>(P parser) {
return _fieldService.getFieldTypeOptionData(fieldType: fieldType).then((result) { return _fieldService.getFieldTypeOptionData(fieldType: fieldType).then((result) {
@ -305,8 +305,8 @@ class _GridFieldChangedNotifierImpl extends GridFieldChangedNotifier {
} }
@override @override
void onFieldChanged(void Function(Field p1) callback) { void onFieldChanged(void Function(GridFieldPB p1) callback) {
_onChangesetFn = (GridFieldChangeset changeset) { _onChangesetFn = (GridFieldChangesetPB changeset) {
for (final updatedField in changeset.updatedFields) { for (final updatedField in changeset.updatedFields) {
callback(updatedField); callback(updatedField);
} }

View File

@ -22,7 +22,7 @@ class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
DateCalBloc({ DateCalBloc({
required DateTypeOption dateTypeOption, required DateTypeOption dateTypeOption,
required DateCellData? cellData, required DateCellDataPB? cellData,
required this.cellContext, required this.cellContext,
}) : super(DateCalState.initial(dateTypeOption, cellData)) { }) : super(DateCalState.initial(dateTypeOption, cellData)) {
on<DateCalEvent>( on<DateCalEvent>(
@ -38,7 +38,7 @@ class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
setFocusedDay: (focusedDay) { setFocusedDay: (focusedDay) {
emit(state.copyWith(focusedDay: focusedDay)); emit(state.copyWith(focusedDay: focusedDay));
}, },
didReceiveCellUpdate: (DateCellData? cellData) { didReceiveCellUpdate: (DateCellDataPB? cellData) {
final calData = calDataFromCellData(cellData); final calData = calDataFromCellData(cellData);
final time = calData.foldRight("", (dateData, previous) => dateData.time); final time = calData.foldRight("", (dateData, previous) => dateData.time);
emit(state.copyWith(calData: calData, time: 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.setDateFormat(DateFormat dateFormat) = _DateFormat;
const factory DateCalEvent.setIncludeTime(bool includeTime) = _IncludeTime; const factory DateCalEvent.setIncludeTime(bool includeTime) = _IncludeTime;
const factory DateCalEvent.setTime(String time) = _Time; 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<CalendarData> data, Option<String> timeFormatError) = const factory DateCalEvent.didUpdateCalData(Option<CalendarData> data, Option<String> timeFormatError) =
_DidUpdateCalData; _DidUpdateCalData;
} }
@ -207,7 +207,7 @@ class DateCalState with _$DateCalState {
factory DateCalState.initial( factory DateCalState.initial(
DateTypeOption dateTypeOption, DateTypeOption dateTypeOption,
DateCellData? cellData, DateCellDataPB? cellData,
) { ) {
Option<CalendarData> calData = calDataFromCellData(cellData); Option<CalendarData> calData = calDataFromCellData(cellData);
final time = calData.foldRight("", (dateData, previous) => dateData.time); final time = calData.foldRight("", (dateData, previous) => dateData.time);
@ -233,7 +233,7 @@ String _timeHintText(DateTypeOption typeOption) {
return ""; return "";
} }
Option<CalendarData> calDataFromCellData(DateCellData? cellData) { Option<CalendarData> calDataFromCellData(DateCellDataPB? cellData) {
String? time = timeFromCellData(cellData); String? time = timeFromCellData(cellData);
Option<CalendarData> calData = none(); Option<CalendarData> calData = none();
if (cellData != null) { if (cellData != null) {
@ -249,7 +249,7 @@ $fixnum.Int64 timestampFromDateTime(DateTime dateTime) {
return $fixnum.Int64(timestamp); return $fixnum.Int64(timestamp);
} }
String? timeFromCellData(DateCellData? cellData) { String? timeFromCellData(DateCellDataPB? cellData) {
String? time; String? time;
if (cellData?.hasTime() ?? false) { if (cellData?.hasTime() ?? false) {
time = cellData?.time; time = cellData?.time;

View File

@ -15,10 +15,10 @@ class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
(event, emit) async { (event, emit) async {
event.when( event.when(
initial: () => _startListening(), initial: () => _startListening(),
didReceiveCellUpdate: (DateCellData? cellData) { didReceiveCellUpdate: (DateCellDataPB? cellData) {
emit(state.copyWith(data: cellData, dateStr: _dateStrFromCellData(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<DateCellEvent, DateCellState> {
@freezed @freezed
class DateCellEvent with _$DateCellEvent { class DateCellEvent with _$DateCellEvent {
const factory DateCellEvent.initial() = _InitialCell; const factory DateCellEvent.initial() = _InitialCell;
const factory DateCellEvent.didReceiveCellUpdate(DateCellData? data) = _DidReceiveCellUpdate; const factory DateCellEvent.didReceiveCellUpdate(DateCellDataPB? data) = _DidReceiveCellUpdate;
const factory DateCellEvent.didReceiveFieldUpdate(Field field) = _DidReceiveFieldUpdate; const factory DateCellEvent.didReceiveFieldUpdate(GridFieldPB field) = _DidReceiveFieldUpdate;
} }
@freezed @freezed
class DateCellState with _$DateCellState { class DateCellState with _$DateCellState {
const factory DateCellState({ const factory DateCellState({
required DateCellData? data, required DateCellDataPB? data,
required String dateStr, required String dateStr,
required Field field, required GridFieldPB field,
}) = _DateCellState; }) = _DateCellState;
factory DateCellState.initial(GridDateCellController context) { factory DateCellState.initial(GridDateCellController context) {
@ -71,7 +71,7 @@ class DateCellState with _$DateCellState {
} }
} }
String _dateStrFromCellData(DateCellData? cellData) { String _dateStrFromCellData(DateCellDataPB? cellData) {
String dateStr = ""; String dateStr = "";
if (cellData != null) { if (cellData != null) {
dateStr = cellData.date + " " + cellData.time; dateStr = cellData.date + " " + cellData.time;

View File

@ -56,14 +56,14 @@ class SelectOptionCellBloc extends Bloc<SelectOptionCellEvent, SelectOptionCellS
class SelectOptionCellEvent with _$SelectOptionCellEvent { class SelectOptionCellEvent with _$SelectOptionCellEvent {
const factory SelectOptionCellEvent.initial() = _InitialCell; const factory SelectOptionCellEvent.initial() = _InitialCell;
const factory SelectOptionCellEvent.didReceiveOptions( const factory SelectOptionCellEvent.didReceiveOptions(
List<SelectOption> selectedOptions, List<SelectOptionPB> selectedOptions,
) = _DidReceiveOptions; ) = _DidReceiveOptions;
} }
@freezed @freezed
class SelectOptionCellState with _$SelectOptionCellState { class SelectOptionCellState with _$SelectOptionCellState {
const factory SelectOptionCellState({ const factory SelectOptionCellState({
required List<SelectOption> selectedOptions, required List<SelectOptionPB> selectedOptions,
}) = _SelectOptionCellState; }) = _SelectOptionCellState;
factory SelectOptionCellState.initial(GridSelectOptionCellController context) { factory SelectOptionCellState.initial(GridSelectOptionCellController context) {

View File

@ -70,7 +70,7 @@ class SelectOptionCellEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOpt
result.fold((l) => {}, (err) => Log.error(err)); result.fold((l) => {}, (err) => Log.error(err));
} }
void _deleteOption(SelectOption option) async { void _deleteOption(SelectOptionPB option) async {
final result = await _selectOptionService.delete( final result = await _selectOptionService.delete(
option: option, option: option,
); );
@ -78,7 +78,7 @@ class SelectOptionCellEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOpt
result.fold((l) => null, (err) => Log.error(err)); result.fold((l) => null, (err) => Log.error(err));
} }
void _updateOption(SelectOption option) async { void _updateOption(SelectOptionPB option) async {
final result = await _selectOptionService.update( final result = await _selectOptionService.update(
option: option, option: option,
); );
@ -122,8 +122,8 @@ class SelectOptionCellEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOpt
}); });
} }
_MakeOptionResult _makeOptions(Option<String> filter, List<SelectOption> allOptions) { _MakeOptionResult _makeOptions(Option<String> filter, List<SelectOptionPB> allOptions) {
final List<SelectOption> options = List.from(allOptions); final List<SelectOptionPB> options = List.from(allOptions);
Option<String> createOption = filter; Option<String> createOption = filter;
filter.foldRight(null, (filter, previous) { filter.foldRight(null, (filter, previous) {
@ -165,20 +165,20 @@ class SelectOptionCellEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOpt
class SelectOptionEditorEvent with _$SelectOptionEditorEvent { class SelectOptionEditorEvent with _$SelectOptionEditorEvent {
const factory SelectOptionEditorEvent.initial() = _Initial; const factory SelectOptionEditorEvent.initial() = _Initial;
const factory SelectOptionEditorEvent.didReceiveOptions( const factory SelectOptionEditorEvent.didReceiveOptions(
List<SelectOption> options, List<SelectOption> selectedOptions) = _DidReceiveOptions; List<SelectOptionPB> options, List<SelectOptionPB> selectedOptions) = _DidReceiveOptions;
const factory SelectOptionEditorEvent.newOption(String optionName) = _NewOption; const factory SelectOptionEditorEvent.newOption(String optionName) = _NewOption;
const factory SelectOptionEditorEvent.selectOption(String optionId) = _SelectOption; const factory SelectOptionEditorEvent.selectOption(String optionId) = _SelectOption;
const factory SelectOptionEditorEvent.updateOption(SelectOption option) = _UpdateOption; const factory SelectOptionEditorEvent.updateOption(SelectOptionPB option) = _UpdateOption;
const factory SelectOptionEditorEvent.deleteOption(SelectOption option) = _DeleteOption; const factory SelectOptionEditorEvent.deleteOption(SelectOptionPB option) = _DeleteOption;
const factory SelectOptionEditorEvent.filterOption(String optionName) = _SelectOptionFilter; const factory SelectOptionEditorEvent.filterOption(String optionName) = _SelectOptionFilter;
} }
@freezed @freezed
class SelectOptionEditorState with _$SelectOptionEditorState { class SelectOptionEditorState with _$SelectOptionEditorState {
const factory SelectOptionEditorState({ const factory SelectOptionEditorState({
required List<SelectOption> options, required List<SelectOptionPB> options,
required List<SelectOption> allOptions, required List<SelectOptionPB> allOptions,
required List<SelectOption> selectedOptions, required List<SelectOptionPB> selectedOptions,
required Option<String> createOption, required Option<String> createOption,
required Option<String> filter, required Option<String> filter,
}) = _SelectOptionEditorState; }) = _SelectOptionEditorState;
@ -196,7 +196,7 @@ class SelectOptionEditorState with _$SelectOptionEditorState {
} }
class _MakeOptionResult { class _MakeOptionResult {
List<SelectOption> options; List<SelectOptionPB> options;
Option<String> createOption; Option<String> createOption;
_MakeOptionResult({ _MakeOptionResult({

View File

@ -19,11 +19,11 @@ class SelectOptionService {
(result) { (result) {
return result.fold( return result.fold(
(option) { (option) {
final cellIdentifier = CellIdentifierPayload.create() final cellIdentifier = GridCellIdentifierPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId ..fieldId = fieldId
..rowId = rowId; ..rowId = rowId;
final payload = SelectOptionChangesetPayload.create() final payload = SelectOptionChangesetPayloadPB.create()
..insertOption = option ..insertOption = option
..cellIdentifier = cellIdentifier; ..cellIdentifier = cellIdentifier;
return GridEventUpdateSelectOption(payload).send(); return GridEventUpdateSelectOption(payload).send();
@ -35,26 +35,26 @@ class SelectOptionService {
} }
Future<Either<Unit, FlowyError>> update({ Future<Either<Unit, FlowyError>> update({
required SelectOption option, required SelectOptionPB option,
}) { }) {
final payload = SelectOptionChangesetPayload.create() final payload = SelectOptionChangesetPayloadPB.create()
..updateOption = option ..updateOption = option
..cellIdentifier = _cellIdentifier(); ..cellIdentifier = _cellIdentifier();
return GridEventUpdateSelectOption(payload).send(); return GridEventUpdateSelectOption(payload).send();
} }
Future<Either<Unit, FlowyError>> delete({ Future<Either<Unit, FlowyError>> delete({
required SelectOption option, required SelectOptionPB option,
}) { }) {
final payload = SelectOptionChangesetPayload.create() final payload = SelectOptionChangesetPayloadPB.create()
..deleteOption = option ..deleteOption = option
..cellIdentifier = _cellIdentifier(); ..cellIdentifier = _cellIdentifier();
return GridEventUpdateSelectOption(payload).send(); return GridEventUpdateSelectOption(payload).send();
} }
Future<Either<SelectOptionCellData, FlowyError>> getOpitonContext() { Future<Either<SelectOptionCellDataPB, FlowyError>> getOpitonContext() {
final payload = CellIdentifierPayload.create() final payload = GridCellIdentifierPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId ..fieldId = fieldId
..rowId = rowId; ..rowId = rowId;
@ -63,21 +63,21 @@ class SelectOptionService {
} }
Future<Either<void, FlowyError>> select({required String optionId}) { Future<Either<void, FlowyError>> select({required String optionId}) {
final payload = SelectOptionCellChangesetPayload.create() final payload = SelectOptionCellChangesetPayloadPB.create()
..cellIdentifier = _cellIdentifier() ..cellIdentifier = _cellIdentifier()
..insertOptionId = optionId; ..insertOptionId = optionId;
return GridEventUpdateSelectOptionCell(payload).send(); return GridEventUpdateSelectOptionCell(payload).send();
} }
Future<Either<void, FlowyError>> unSelect({required String optionId}) { Future<Either<void, FlowyError>> unSelect({required String optionId}) {
final payload = SelectOptionCellChangesetPayload.create() final payload = SelectOptionCellChangesetPayloadPB.create()
..cellIdentifier = _cellIdentifier() ..cellIdentifier = _cellIdentifier()
..deleteOptionId = optionId; ..deleteOptionId = optionId;
return GridEventUpdateSelectOptionCell(payload).send(); return GridEventUpdateSelectOptionCell(payload).send();
} }
CellIdentifierPayload _cellIdentifier() { GridCellIdentifierPayloadPB _cellIdentifier() {
return CellIdentifierPayload.create() return GridCellIdentifierPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId ..fieldId = fieldId
..rowId = rowId; ..rowId = rowId;

View File

@ -57,7 +57,7 @@ class URLCellBloc extends Bloc<URLCellEvent, URLCellState> {
class URLCellEvent with _$URLCellEvent { class URLCellEvent with _$URLCellEvent {
const factory URLCellEvent.initial() = _InitialCell; const factory URLCellEvent.initial() = _InitialCell;
const factory URLCellEvent.updateURL(String url) = _UpdateURL; const factory URLCellEvent.updateURL(String url) = _UpdateURL;
const factory URLCellEvent.didReceiveCellUpdate(URLCellData? cell) = _DidReceiveCellUpdate; const factory URLCellEvent.didReceiveCellUpdate(URLCellDataPB? cell) = _DidReceiveCellUpdate;
} }
@freezed @freezed

View File

@ -54,7 +54,7 @@ class URLCellEditorBloc extends Bloc<URLCellEditorEvent, URLCellEditorState> {
@freezed @freezed
class URLCellEditorEvent with _$URLCellEditorEvent { class URLCellEditorEvent with _$URLCellEditorEvent {
const factory URLCellEditorEvent.initial() = _InitialCell; 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; const factory URLCellEditorEvent.updateText(String text) = _UpdateText;
} }

View File

@ -10,8 +10,8 @@ part 'field_action_sheet_bloc.freezed.dart';
class FieldActionSheetBloc extends Bloc<FieldActionSheetEvent, FieldActionSheetState> { class FieldActionSheetBloc extends Bloc<FieldActionSheetEvent, FieldActionSheetState> {
final FieldService fieldService; final FieldService fieldService;
FieldActionSheetBloc({required Field field, required this.fieldService}) FieldActionSheetBloc({required GridFieldPB field, required this.fieldService})
: super(FieldActionSheetState.initial(FieldTypeOptionData.create()..field_2 = field)) { : super(FieldActionSheetState.initial(FieldTypeOptionDataPB.create()..field_2 = field)) {
on<FieldActionSheetEvent>( on<FieldActionSheetEvent>(
(event, emit) async { (event, emit) async {
await event.map( await event.map(
@ -67,12 +67,12 @@ class FieldActionSheetEvent with _$FieldActionSheetEvent {
@freezed @freezed
class FieldActionSheetState with _$FieldActionSheetState { class FieldActionSheetState with _$FieldActionSheetState {
const factory FieldActionSheetState({ const factory FieldActionSheetState({
required FieldTypeOptionData fieldTypeOptionData, required FieldTypeOptionDataPB fieldTypeOptionData,
required String errorText, required String errorText,
required String fieldName, required String fieldName,
}) = _FieldActionSheetState; }) = _FieldActionSheetState;
factory FieldActionSheetState.initial(FieldTypeOptionData data) => FieldActionSheetState( factory FieldActionSheetState.initial(FieldTypeOptionDataPB data) => FieldActionSheetState(
fieldTypeOptionData: data, fieldTypeOptionData: data,
errorText: '', errorText: '',
fieldName: data.field_2.name, fieldName: data.field_2.name,

View File

@ -62,7 +62,7 @@ class FieldCellBloc extends Bloc<FieldCellEvent, FieldCellState> {
@freezed @freezed
class FieldCellEvent with _$FieldCellEvent { class FieldCellEvent with _$FieldCellEvent {
const factory FieldCellEvent.initial() = _InitialCell; 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.startUpdateWidth(double offset) = _StartUpdateWidth;
const factory FieldCellEvent.endUpdateWidth() = _EndUpdateWidth; const factory FieldCellEvent.endUpdateWidth() = _EndUpdateWidth;
} }
@ -71,7 +71,7 @@ class FieldCellEvent with _$FieldCellEvent {
class FieldCellState with _$FieldCellState { class FieldCellState with _$FieldCellState {
const factory FieldCellState({ const factory FieldCellState({
required String gridId, required String gridId,
required Field field, required GridFieldPB field,
required double width, required double width,
}) = _FieldCellState; }) = _FieldCellState;

View File

@ -30,7 +30,7 @@ class FieldEditorBloc extends Bloc<FieldEditorEvent, FieldEditorState> {
dataController.fieldName = name; dataController.fieldName = name;
emit(state.copyWith(name: name)); emit(state.copyWith(name: name));
}, },
didReceiveFieldChanged: (Field field) { didReceiveFieldChanged: (GridFieldPB field) {
emit(state.copyWith(field: Some(field))); emit(state.copyWith(field: Some(field)));
}, },
); );
@ -48,7 +48,7 @@ class FieldEditorBloc extends Bloc<FieldEditorEvent, FieldEditorState> {
class FieldEditorEvent with _$FieldEditorEvent { class FieldEditorEvent with _$FieldEditorEvent {
const factory FieldEditorEvent.initial() = _InitialField; const factory FieldEditorEvent.initial() = _InitialField;
const factory FieldEditorEvent.updateName(String name) = _UpdateName; const factory FieldEditorEvent.updateName(String name) = _UpdateName;
const factory FieldEditorEvent.didReceiveFieldChanged(Field field) = _DidReceiveFieldChanged; const factory FieldEditorEvent.didReceiveFieldChanged(GridFieldPB field) = _DidReceiveFieldChanged;
} }
@freezed @freezed
@ -57,7 +57,7 @@ class FieldEditorState with _$FieldEditorState {
required String gridId, required String gridId,
required String errorText, required String errorText,
required String name, required String name,
required Option<Field> field, required Option<GridFieldPB> field,
}) = _FieldEditorState; }) = _FieldEditorState;
factory FieldEditorState.initial( factory FieldEditorState.initial(

View File

@ -7,7 +7,7 @@ import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
typedef UpdateFieldNotifiedValue = Either<Field, FlowyError>; typedef UpdateFieldNotifiedValue = Either<GridFieldPB, FlowyError>;
class SingleFieldListener { class SingleFieldListener {
final String fieldId; final String fieldId;
@ -31,7 +31,7 @@ class SingleFieldListener {
switch (ty) { switch (ty) {
case GridNotification.DidUpdateField: case GridNotification.DidUpdateField:
result.fold( result.fold(
(payload) => _updateFieldNotifier?.value = left(Field.fromBuffer(payload)), (payload) => _updateFieldNotifier?.value = left(GridFieldPB.fromBuffer(payload)),
(error) => _updateFieldNotifier?.value = right(error), (error) => _updateFieldNotifier?.value = right(error),
); );
break; break;

View File

@ -39,7 +39,7 @@ class FieldService {
double? width, double? width,
List<int>? typeOptionData, List<int>? typeOptionData,
}) { }) {
var payload = FieldChangesetPayload.create() var payload = FieldChangesetPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId; ..fieldId = fieldId;
@ -73,11 +73,11 @@ class FieldService {
// Create the field if it does not exist. Otherwise, update the field. // Create the field if it does not exist. Otherwise, update the field.
static Future<Either<Unit, FlowyError>> insertField({ static Future<Either<Unit, FlowyError>> insertField({
required String gridId, required String gridId,
required Field field, required GridFieldPB field,
List<int>? typeOptionData, List<int>? typeOptionData,
String? startFieldId, String? startFieldId,
}) { }) {
var payload = InsertFieldPayload.create() var payload = InsertFieldPayloadPB.create()
..gridId = gridId ..gridId = gridId
..field_2 = field ..field_2 = field
..typeOptionData = typeOptionData ?? []; ..typeOptionData = typeOptionData ?? [];
@ -94,7 +94,7 @@ class FieldService {
required String fieldId, required String fieldId,
required List<int> typeOptionData, required List<int> typeOptionData,
}) { }) {
var payload = UpdateFieldTypeOptionPayload.create() var payload = UpdateFieldTypeOptionPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId ..fieldId = fieldId
..typeOptionData = typeOptionData; ..typeOptionData = typeOptionData;
@ -103,7 +103,7 @@ class FieldService {
} }
Future<Either<Unit, FlowyError>> deleteField() { Future<Either<Unit, FlowyError>> deleteField() {
final payload = FieldIdentifierPayload.create() final payload = GridFieldIdentifierPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId; ..fieldId = fieldId;
@ -111,17 +111,17 @@ class FieldService {
} }
Future<Either<Unit, FlowyError>> duplicateField() { Future<Either<Unit, FlowyError>> duplicateField() {
final payload = FieldIdentifierPayload.create() final payload = GridFieldIdentifierPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId; ..fieldId = fieldId;
return GridEventDuplicateField(payload).send(); return GridEventDuplicateField(payload).send();
} }
Future<Either<FieldTypeOptionData, FlowyError>> getFieldTypeOptionData({ Future<Either<FieldTypeOptionDataPB, FlowyError>> getFieldTypeOptionData({
required FieldType fieldType, required FieldType fieldType,
}) { }) {
final payload = EditFieldPayload.create() final payload = EditFieldPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId ..fieldId = fieldId
..fieldType = fieldType; ..fieldType = fieldType;
@ -138,16 +138,16 @@ class FieldService {
class GridFieldCellContext with _$GridFieldCellContext { class GridFieldCellContext with _$GridFieldCellContext {
const factory GridFieldCellContext({ const factory GridFieldCellContext({
required String gridId, required String gridId,
required Field field, required GridFieldPB field,
}) = _GridFieldCellContext; }) = _GridFieldCellContext;
} }
abstract class IFieldTypeOptionLoader { abstract class IFieldTypeOptionLoader {
String get gridId; String get gridId;
Future<Either<FieldTypeOptionData, FlowyError>> load(); Future<Either<FieldTypeOptionDataPB, FlowyError>> load();
Future<Either<FieldTypeOptionData, FlowyError>> switchToField(String fieldId, FieldType fieldType) { Future<Either<FieldTypeOptionDataPB, FlowyError>> switchToField(String fieldId, FieldType fieldType) {
final payload = EditFieldPayload.create() final payload = EditFieldPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId ..fieldId = fieldId
..fieldType = fieldType; ..fieldType = fieldType;
@ -164,8 +164,8 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
}); });
@override @override
Future<Either<FieldTypeOptionData, FlowyError>> load() { Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
final payload = EditFieldPayload.create() final payload = EditFieldPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldType = FieldType.RichText; ..fieldType = FieldType.RichText;
@ -176,7 +176,7 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
class FieldTypeOptionLoader extends IFieldTypeOptionLoader { class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
@override @override
final String gridId; final String gridId;
final Field field; final GridFieldPB field;
FieldTypeOptionLoader({ FieldTypeOptionLoader({
required this.gridId, required this.gridId,
@ -184,8 +184,8 @@ class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
}); });
@override @override
Future<Either<FieldTypeOptionData, FlowyError>> load() { Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
final payload = EditFieldPayload.create() final payload = EditFieldPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = field.id ..fieldId = field.id
..fieldType = field.fieldType; ..fieldType = field.fieldType;
@ -198,8 +198,8 @@ class TypeOptionDataController {
final String gridId; final String gridId;
final IFieldTypeOptionLoader _loader; final IFieldTypeOptionLoader _loader;
late FieldTypeOptionData _data; late FieldTypeOptionDataPB _data;
final PublishNotifier<Field> _fieldNotifier = PublishNotifier(); final PublishNotifier<GridFieldPB> _fieldNotifier = PublishNotifier();
TypeOptionDataController({ TypeOptionDataController({
required this.gridId, 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); _updateData(newField: field);
} }
@ -238,7 +238,7 @@ class TypeOptionDataController {
_updateData(newTypeOptionData: typeOptionData); _updateData(newTypeOptionData: typeOptionData);
} }
void _updateData({String? newName, Field? newField, List<int>? newTypeOptionData}) { void _updateData({String? newName, GridFieldPB? newField, List<int>? newTypeOptionData}) {
_data = _data.rebuild((rebuildData) { _data = _data.rebuild((rebuildData) {
if (newName != null) { if (newName != null) {
rebuildData.field_2 = rebuildData.field_2.rebuild((rebuildField) { 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() { listener() {
callback(field); callback(field);
} }

View File

@ -42,13 +42,13 @@ class FieldTypeOptionEditBloc extends Bloc<FieldTypeOptionEditEvent, FieldTypeOp
@freezed @freezed
class FieldTypeOptionEditEvent with _$FieldTypeOptionEditEvent { class FieldTypeOptionEditEvent with _$FieldTypeOptionEditEvent {
const factory FieldTypeOptionEditEvent.initial() = _Initial; const factory FieldTypeOptionEditEvent.initial() = _Initial;
const factory FieldTypeOptionEditEvent.didReceiveFieldUpdated(Field field) = _DidReceiveFieldUpdated; const factory FieldTypeOptionEditEvent.didReceiveFieldUpdated(GridFieldPB field) = _DidReceiveFieldUpdated;
} }
@freezed @freezed
class FieldTypeOptionEditState with _$FieldTypeOptionEditState { class FieldTypeOptionEditState with _$FieldTypeOptionEditState {
const factory FieldTypeOptionEditState({ const factory FieldTypeOptionEditState({
required Field field, required GridFieldPB field,
}) = _FieldTypeOptionEditState; }) = _FieldTypeOptionEditState;
factory FieldTypeOptionEditState.initial(TypeOptionDataController fieldContext) => FieldTypeOptionEditState( factory FieldTypeOptionEditState.initial(TypeOptionDataController fieldContext) => FieldTypeOptionEditState(

View File

@ -7,7 +7,7 @@ import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
typedef UpdateFieldNotifiedValue = Either<GridFieldChangeset, FlowyError>; typedef UpdateFieldNotifiedValue = Either<GridFieldChangesetPB, FlowyError>;
class GridFieldsListener { class GridFieldsListener {
final String gridId; final String gridId;
@ -27,7 +27,7 @@ class GridFieldsListener {
switch (ty) { switch (ty) {
case GridNotification.DidUpdateGridField: case GridNotification.DidUpdateGridField:
result.fold( result.fold(
(payload) => updateFieldsNotifier?.value = left(GridFieldChangeset.fromBuffer(payload)), (payload) => updateFieldsNotifier?.value = left(GridFieldChangesetPB.fromBuffer(payload)),
(error) => updateFieldsNotifier?.value = right(error), (error) => updateFieldsNotifier?.value = right(error),
); );
break; break;

View File

@ -7,7 +7,7 @@ import 'package:dartz/dartz.dart';
part 'edit_select_option_bloc.freezed.dart'; part 'edit_select_option_bloc.freezed.dart';
class EditSelectOptionBloc extends Bloc<EditSelectOptionEvent, EditSelectOptionState> { class EditSelectOptionBloc extends Bloc<EditSelectOptionEvent, EditSelectOptionState> {
EditSelectOptionBloc({required SelectOption option}) : super(EditSelectOptionState.initial(option)) { EditSelectOptionBloc({required SelectOptionPB option}) : super(EditSelectOptionState.initial(option)) {
on<EditSelectOptionEvent>( on<EditSelectOptionEvent>(
(event, emit) async { (event, emit) async {
event.map( event.map(
@ -30,14 +30,14 @@ class EditSelectOptionBloc extends Bloc<EditSelectOptionEvent, EditSelectOptionS
return super.close(); return super.close();
} }
SelectOption _updateColor(SelectOptionColor color) { SelectOptionPB _updateColor(SelectOptionColorPB color) {
state.option.freeze(); state.option.freeze();
return state.option.rebuild((option) { return state.option.rebuild((option) {
option.color = color; option.color = color;
}); });
} }
SelectOption _updateName(String name) { SelectOptionPB _updateName(String name) {
state.option.freeze(); state.option.freeze();
return state.option.rebuild((option) { return state.option.rebuild((option) {
option.name = name; option.name = name;
@ -48,18 +48,18 @@ class EditSelectOptionBloc extends Bloc<EditSelectOptionEvent, EditSelectOptionS
@freezed @freezed
class EditSelectOptionEvent with _$EditSelectOptionEvent { class EditSelectOptionEvent with _$EditSelectOptionEvent {
const factory EditSelectOptionEvent.updateName(String name) = _UpdateName; const factory EditSelectOptionEvent.updateName(String name) = _UpdateName;
const factory EditSelectOptionEvent.updateColor(SelectOptionColor color) = _UpdateColor; const factory EditSelectOptionEvent.updateColor(SelectOptionColorPB color) = _UpdateColor;
const factory EditSelectOptionEvent.delete() = _Delete; const factory EditSelectOptionEvent.delete() = _Delete;
} }
@freezed @freezed
class EditSelectOptionState with _$EditSelectOptionState { class EditSelectOptionState with _$EditSelectOptionState {
const factory EditSelectOptionState({ const factory EditSelectOptionState({
required SelectOption option, required SelectOptionPB option,
required Option<bool> deleted, required Option<bool> deleted,
}) = _EditSelectOptionState; }) = _EditSelectOptionState;
factory EditSelectOptionState.initial(SelectOption option) => EditSelectOptionState( factory EditSelectOptionState.initial(SelectOptionPB option) => EditSelectOptionState(
option: option, option: option,
deleted: none(), deleted: none(),
); );

View File

@ -21,8 +21,8 @@ class MultiSelectTypeOptionContext extends TypeOptionWidgetContext<MultiSelectTy
super(dataParser: dataBuilder, dataController: dataController); super(dataParser: dataBuilder, dataController: dataController);
@override @override
List<SelectOption> Function(SelectOption) get deleteOption { List<SelectOptionPB> Function(SelectOptionPB) get deleteOption {
return (SelectOption option) { return (SelectOptionPB option) {
typeOption.freeze(); typeOption.freeze();
typeOption = typeOption.rebuild((typeOption) { typeOption = typeOption.rebuild((typeOption) {
final index = typeOption.options.indexWhere((element) => element.id == option.id); final index = typeOption.options.indexWhere((element) => element.id == option.id);
@ -35,7 +35,7 @@ class MultiSelectTypeOptionContext extends TypeOptionWidgetContext<MultiSelectTy
} }
@override @override
Future<List<SelectOption>> Function(String) get insertOption { Future<List<SelectOptionPB>> Function(String) get insertOption {
return (String optionName) { return (String optionName) {
return service.newOption(name: optionName).then((result) { return service.newOption(name: optionName).then((result) {
return result.fold( return result.fold(
@ -57,8 +57,8 @@ class MultiSelectTypeOptionContext extends TypeOptionWidgetContext<MultiSelectTy
} }
@override @override
List<SelectOption> Function(SelectOption) get udpateOption { List<SelectOptionPB> Function(SelectOptionPB) get udpateOption {
return (SelectOption option) { return (SelectOptionPB option) {
typeOption.freeze(); typeOption.freeze();
typeOption = typeOption.rebuild((typeOption) { typeOption = typeOption.rebuild((typeOption) {
final index = typeOption.options.indexWhere((element) => element.id == option.id); final index = typeOption.options.indexWhere((element) => element.id == option.id);

View File

@ -6,25 +6,25 @@ import 'package:dartz/dartz.dart';
part 'select_option_type_option_bloc.freezed.dart'; part 'select_option_type_option_bloc.freezed.dart';
abstract class SelectOptionTypeOptionAction { abstract class SelectOptionTypeOptionAction {
Future<List<SelectOption>> Function(String) get insertOption; Future<List<SelectOptionPB>> Function(String) get insertOption;
List<SelectOption> Function(SelectOption) get deleteOption; List<SelectOptionPB> Function(SelectOptionPB) get deleteOption;
List<SelectOption> Function(SelectOption) get udpateOption; List<SelectOptionPB> Function(SelectOptionPB) get udpateOption;
} }
class SelectOptionTypeOptionBloc extends Bloc<SelectOptionTypeOptionEvent, SelectOptionTypeOptionState> { class SelectOptionTypeOptionBloc extends Bloc<SelectOptionTypeOptionEvent, SelectOptionTypeOptionState> {
final SelectOptionTypeOptionAction typeOptionAction; final SelectOptionTypeOptionAction typeOptionAction;
SelectOptionTypeOptionBloc({ SelectOptionTypeOptionBloc({
required List<SelectOption> options, required List<SelectOptionPB> options,
required this.typeOptionAction, required this.typeOptionAction,
}) : super(SelectOptionTypeOptionState.initial(options)) { }) : super(SelectOptionTypeOptionState.initial(options)) {
on<SelectOptionTypeOptionEvent>( on<SelectOptionTypeOptionEvent>(
(event, emit) async { (event, emit) async {
await event.when( await event.when(
createOption: (optionName) async { createOption: (optionName) async {
final List<SelectOption> options = await typeOptionAction.insertOption(optionName); final List<SelectOptionPB> options = await typeOptionAction.insertOption(optionName);
emit(state.copyWith(options: options)); emit(state.copyWith(options: options));
}, },
addingOption: () { addingOption: () {
@ -34,11 +34,11 @@ class SelectOptionTypeOptionBloc extends Bloc<SelectOptionTypeOptionEvent, Selec
emit(state.copyWith(isEditingOption: false, newOptionName: none())); emit(state.copyWith(isEditingOption: false, newOptionName: none()));
}, },
updateOption: (option) { updateOption: (option) {
final List<SelectOption> options = typeOptionAction.udpateOption(option); final List<SelectOptionPB> options = typeOptionAction.udpateOption(option);
emit(state.copyWith(options: options)); emit(state.copyWith(options: options));
}, },
deleteOption: (option) { deleteOption: (option) {
final List<SelectOption> options = typeOptionAction.deleteOption(option); final List<SelectOptionPB> options = typeOptionAction.deleteOption(option);
emit(state.copyWith(options: options)); emit(state.copyWith(options: options));
}, },
); );
@ -57,19 +57,19 @@ class SelectOptionTypeOptionEvent with _$SelectOptionTypeOptionEvent {
const factory SelectOptionTypeOptionEvent.createOption(String optionName) = _CreateOption; const factory SelectOptionTypeOptionEvent.createOption(String optionName) = _CreateOption;
const factory SelectOptionTypeOptionEvent.addingOption() = _AddingOption; const factory SelectOptionTypeOptionEvent.addingOption() = _AddingOption;
const factory SelectOptionTypeOptionEvent.endAddingOption() = _EndAddingOption; const factory SelectOptionTypeOptionEvent.endAddingOption() = _EndAddingOption;
const factory SelectOptionTypeOptionEvent.updateOption(SelectOption option) = _UpdateOption; const factory SelectOptionTypeOptionEvent.updateOption(SelectOptionPB option) = _UpdateOption;
const factory SelectOptionTypeOptionEvent.deleteOption(SelectOption option) = _DeleteOption; const factory SelectOptionTypeOptionEvent.deleteOption(SelectOptionPB option) = _DeleteOption;
} }
@freezed @freezed
class SelectOptionTypeOptionState with _$SelectOptionTypeOptionState { class SelectOptionTypeOptionState with _$SelectOptionTypeOptionState {
const factory SelectOptionTypeOptionState({ const factory SelectOptionTypeOptionState({
required List<SelectOption> options, required List<SelectOptionPB> options,
required bool isEditingOption, required bool isEditingOption,
required Option<String> newOptionName, required Option<String> newOptionName,
}) = _SelectOptionTyepOptionState; }) = _SelectOptionTyepOptionState;
factory SelectOptionTypeOptionState.initial(List<SelectOption> options) => SelectOptionTypeOptionState( factory SelectOptionTypeOptionState.initial(List<SelectOptionPB> options) => SelectOptionTypeOptionState(
options: options, options: options,
isEditingOption: false, isEditingOption: false,
newOptionName: none(), newOptionName: none(),

View File

@ -7,7 +7,7 @@ import 'package:protobuf/protobuf.dart';
import 'select_option_type_option_bloc.dart'; import 'select_option_type_option_bloc.dart';
import 'type_option_service.dart'; import 'type_option_service.dart';
class SingleSelectTypeOptionContext extends TypeOptionWidgetContext<SingleSelectTypeOption> class SingleSelectTypeOptionContext extends TypeOptionWidgetContext<SingleSelectTypeOptionPB>
with SelectOptionTypeOptionAction { with SelectOptionTypeOptionAction {
final TypeOptionService service; final TypeOptionService service;
@ -21,8 +21,8 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext<SingleSelect
super(dataParser: dataBuilder, dataController: fieldContext); super(dataParser: dataBuilder, dataController: fieldContext);
@override @override
List<SelectOption> Function(SelectOption) get deleteOption { List<SelectOptionPB> Function(SelectOptionPB) get deleteOption {
return (SelectOption option) { return (SelectOptionPB option) {
typeOption.freeze(); typeOption.freeze();
typeOption = typeOption.rebuild((typeOption) { typeOption = typeOption.rebuild((typeOption) {
final index = typeOption.options.indexWhere((element) => element.id == option.id); final index = typeOption.options.indexWhere((element) => element.id == option.id);
@ -35,7 +35,7 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext<SingleSelect
} }
@override @override
Future<List<SelectOption>> Function(String) get insertOption { Future<List<SelectOptionPB>> Function(String) get insertOption {
return (String optionName) { return (String optionName) {
return service.newOption(name: optionName).then((result) { return service.newOption(name: optionName).then((result) {
return result.fold( return result.fold(
@ -57,8 +57,8 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext<SingleSelect
} }
@override @override
List<SelectOption> Function(SelectOption) get udpateOption { List<SelectOptionPB> Function(SelectOptionPB) get udpateOption {
return (SelectOption option) { return (SelectOptionPB option) {
typeOption.freeze(); typeOption.freeze();
typeOption = typeOption.rebuild((typeOption) { typeOption = typeOption.rebuild((typeOption) {
final index = typeOption.options.indexWhere((element) => element.id == option.id); final index = typeOption.options.indexWhere((element) => element.id == option.id);
@ -71,9 +71,9 @@ class SingleSelectTypeOptionContext extends TypeOptionWidgetContext<SingleSelect
} }
} }
class SingleSelectTypeOptionWidgetDataParser extends TypeOptionDataParser<SingleSelectTypeOption> { class SingleSelectTypeOptionWidgetDataParser extends TypeOptionDataParser<SingleSelectTypeOptionPB> {
@override @override
SingleSelectTypeOption fromBuffer(List<int> buffer) { SingleSelectTypeOptionPB fromBuffer(List<int> buffer) {
return SingleSelectTypeOption.fromBuffer(buffer); return SingleSelectTypeOptionPB.fromBuffer(buffer);
} }
} }

View File

@ -18,14 +18,14 @@ class TypeOptionService {
required this.fieldId, required this.fieldId,
}); });
Future<Either<SelectOption, FlowyError>> newOption({ Future<Either<SelectOptionPB, FlowyError>> newOption({
required String name, required String name,
}) { }) {
final fieldIdentifier = FieldIdentifierPayload.create() final fieldIdentifier = GridFieldIdentifierPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldId = fieldId; ..fieldId = fieldId;
final payload = CreateSelectOptionPayload.create() final payload = CreateSelectOptionPayloadPB.create()
..optionName = name ..optionName = name
..fieldIdentifier = fieldIdentifier; ..fieldIdentifier = fieldIdentifier;
@ -49,7 +49,7 @@ class TypeOptionWidgetContext<T extends GeneratedMessage> {
String get gridId => _dataController.gridId; String get gridId => _dataController.gridId;
Field get field => _dataController.field; GridFieldPB get field => _dataController.field;
T get typeOption { T get typeOption {
if (_typeOptionObject != null) { if (_typeOptionObject != null) {
@ -74,7 +74,7 @@ abstract class TypeOptionFieldDelegate {
class TypeOptionContext2<T> { class TypeOptionContext2<T> {
final String gridId; final String gridId;
final Field field; final GridFieldPB field;
final FieldService _fieldService; final FieldService _fieldService;
T? _data; T? _data;
final TypeOptionDataParser dataBuilder; final TypeOptionDataParser dataBuilder;

View File

@ -93,8 +93,8 @@ class GridBloc extends Bloc<GridEvent, GridState> {
); );
} }
Future<void> _loadFields(Grid grid, Emitter<GridState> emit) async { Future<void> _loadFields(GridPB grid, Emitter<GridState> emit) async {
final result = await _gridService.getFields(fieldOrders: grid.fields); final result = await _gridService.getFields(fieldIds: grid.fields);
return Future( return Future(
() => result.fold( () => result.fold(
(fields) { (fields) {
@ -112,7 +112,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
); );
} }
void _initialBlocks(List<GridBlock> blocks) { void _initialBlocks(List<GridBlockPB> blocks) {
for (final block in blocks) { for (final block in blocks) {
if (_blocks[block.id] != null) { if (_blocks[block.id] != null) {
Log.warn("Intial duplicate block's cache: ${block.id}"); 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.createRow() = _CreateRow;
const factory GridEvent.didReceiveRowUpdate(List<GridRowInfo> rows, GridRowChangeReason listState) = const factory GridEvent.didReceiveRowUpdate(List<GridRowInfo> rows, GridRowChangeReason listState) =
_DidReceiveRowUpdate; _DidReceiveRowUpdate;
const factory GridEvent.didReceiveFieldUpdate(List<Field> fields) = _DidReceiveFieldUpdate; const factory GridEvent.didReceiveFieldUpdate(List<GridFieldPB> fields) = _DidReceiveFieldUpdate;
} }
@freezed @freezed
class GridState with _$GridState { class GridState with _$GridState {
const factory GridState({ const factory GridState({
required String gridId, required String gridId,
required Option<Grid> grid, required Option<GridPB> grid,
required GridFieldEquatable fields, required GridFieldEquatable fields,
required List<GridRowInfo> rowInfos, required List<GridRowInfo> rowInfos,
required GridLoadingState loadingState, required GridLoadingState loadingState,
@ -172,8 +172,8 @@ class GridLoadingState with _$GridLoadingState {
} }
class GridFieldEquatable extends Equatable { class GridFieldEquatable extends Equatable {
final List<Field> _fields; final List<GridFieldPB> _fields;
const GridFieldEquatable(List<Field> fields) : _fields = fields; const GridFieldEquatable(List<GridFieldPB> fields) : _fields = fields;
@override @override
List<Object?> get props { List<Object?> get props {
@ -183,5 +183,5 @@ class GridFieldEquatable extends Equatable {
]; ];
} }
UnmodifiableListView<Field> get value => UnmodifiableListView(_fields); UnmodifiableListView<GridFieldPB> get value => UnmodifiableListView(_fields);
} }

View File

@ -34,7 +34,7 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
} }
Future<void> _moveField(_MoveField value, Emitter<GridHeaderState> emit) async { Future<void> _moveField(_MoveField value, Emitter<GridHeaderState> emit) async {
final fields = List<Field>.from(state.fields); final fields = List<GridFieldPB>.from(state.fields);
fields.insert(value.toIndex, fields.removeAt(value.fromIndex)); fields.insert(value.toIndex, fields.removeAt(value.fromIndex));
emit(state.copyWith(fields: fields)); emit(state.copyWith(fields: fields));
@ -62,16 +62,16 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
@freezed @freezed
class GridHeaderEvent with _$GridHeaderEvent { class GridHeaderEvent with _$GridHeaderEvent {
const factory GridHeaderEvent.initial() = _InitialHeader; const factory GridHeaderEvent.initial() = _InitialHeader;
const factory GridHeaderEvent.didReceiveFieldUpdate(List<Field> fields) = _DidReceiveFieldUpdate; const factory GridHeaderEvent.didReceiveFieldUpdate(List<GridFieldPB> fields) = _DidReceiveFieldUpdate;
const factory GridHeaderEvent.moveField(Field field, int fromIndex, int toIndex) = _MoveField; const factory GridHeaderEvent.moveField(GridFieldPB field, int fromIndex, int toIndex) = _MoveField;
} }
@freezed @freezed
class GridHeaderState with _$GridHeaderState { class GridHeaderState with _$GridHeaderState {
const factory GridHeaderState({required List<Field> fields}) = _GridHeaderState; const factory GridHeaderState({required List<GridFieldPB> fields}) = _GridHeaderState;
factory GridHeaderState.initial(List<Field> fields) { factory GridHeaderState.initial(List<GridFieldPB> fields) {
// final List<Field> newFields = List.from(fields); // final List<GridFieldPB> newFields = List.from(fields);
// newFields.retainWhere((field) => field.visibility); // newFields.retainWhere((field) => field.visibility);
return GridHeaderState(fields: fields); return GridHeaderState(fields: fields);
} }

View File

@ -26,16 +26,16 @@ class GridService {
return GridEventGetGrid(payload).send(); return GridEventGetGrid(payload).send();
} }
Future<Either<Row, FlowyError>> createRow({Option<String>? startRowId}) { Future<Either<GridRowPB, FlowyError>> createRow({Option<String>? startRowId}) {
CreateRowPayload payload = CreateRowPayload.create()..gridId = gridId; CreateRowPayloadPB payload = CreateRowPayloadPB.create()..gridId = gridId;
startRowId?.fold(() => null, (id) => payload.startRowId = id); startRowId?.fold(() => null, (id) => payload.startRowId = id);
return GridEventCreateRow(payload).send(); return GridEventCreateRow(payload).send();
} }
Future<Either<RepeatedField, FlowyError>> getFields({required List<GridFieldPB> fieldOrders}) { Future<Either<RepeatedGridFieldPB, FlowyError>> getFields({required List<GridFieldIdPB> fieldIds}) {
final payload = QueryFieldPayload.create() final payload = QueryFieldPayloadPB.create()
..gridId = gridId ..gridId = gridId
..fieldOrders = RepeatedFieldOrder(items: fieldOrders); ..fieldIds = RepeatedGridFieldIdPB(items: fieldIds);
return GridEventGetFields(payload).send(); return GridEventGetFields(payload).send();
} }
@ -46,18 +46,18 @@ class GridService {
} }
class FieldsNotifier extends ChangeNotifier { class FieldsNotifier extends ChangeNotifier {
List<Field> _fields = []; List<GridFieldPB> _fields = [];
set fields(List<Field> fields) { set fields(List<GridFieldPB> fields) {
_fields = fields; _fields = fields;
notifyListeners(); notifyListeners();
} }
List<Field> get fields => _fields; List<GridFieldPB> get fields => _fields;
} }
typedef FieldChangesetCallback = void Function(GridFieldChangeset); typedef FieldChangesetCallback = void Function(GridFieldChangesetPB);
typedef FieldsCallback = void Function(List<Field>); typedef FieldsCallback = void Function(List<GridFieldPB>);
class GridFieldCache { class GridFieldCache {
final String gridId; final String gridId;
@ -88,11 +88,11 @@ class GridFieldCache {
_fieldNotifier = null; _fieldNotifier = null;
} }
UnmodifiableListView<Field> get unmodifiableFields => UnmodifiableListView(_fieldNotifier?.fields ?? []); UnmodifiableListView<GridFieldPB> get unmodifiableFields => UnmodifiableListView(_fieldNotifier?.fields ?? []);
List<Field> get fields => [..._fieldNotifier?.fields ?? []]; List<GridFieldPB> get fields => [..._fieldNotifier?.fields ?? []];
set fields(List<Field> fields) { set fields(List<GridFieldPB> fields) {
_fieldNotifier?.fields = [...fields]; _fieldNotifier?.fields = [...fields];
} }
@ -141,12 +141,12 @@ class GridFieldCache {
} }
} }
void _deleteFields(List<GridFieldPB> deletedFields) { void _deleteFields(List<GridFieldIdPB> deletedFields) {
if (deletedFields.isEmpty) { if (deletedFields.isEmpty) {
return; return;
} }
final List<Field> newFields = fields; final List<GridFieldPB> newFields = fields;
final Map<String, GridFieldPB> deletedFieldMap = { final Map<String, GridFieldIdPB> deletedFieldMap = {
for (var fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder for (var fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder
}; };
@ -154,11 +154,11 @@ class GridFieldCache {
_fieldNotifier?.fields = newFields; _fieldNotifier?.fields = newFields;
} }
void _insertFields(List<IndexField> insertedFields) { void _insertFields(List<IndexFieldPB> insertedFields) {
if (insertedFields.isEmpty) { if (insertedFields.isEmpty) {
return; return;
} }
final List<Field> newFields = fields; final List<GridFieldPB> newFields = fields;
for (final indexField in insertedFields) { for (final indexField in insertedFields) {
if (newFields.length > indexField.index) { if (newFields.length > indexField.index) {
newFields.insert(indexField.index, indexField.field_1); newFields.insert(indexField.index, indexField.field_1);
@ -169,11 +169,11 @@ class GridFieldCache {
_fieldNotifier?.fields = newFields; _fieldNotifier?.fields = newFields;
} }
void _updateFields(List<Field> updatedFields) { void _updateFields(List<GridFieldPB> updatedFields) {
if (updatedFields.isEmpty) { if (updatedFields.isEmpty) {
return; return;
} }
final List<Field> newFields = fields; final List<GridFieldPB> newFields = fields;
for (final updatedField in updatedFields) { for (final updatedField in updatedFields) {
final index = newFields.indexWhere((field) => field.id == updatedField.id); final index = newFields.indexWhere((field) => field.id == updatedField.id);
if (index != -1) { if (index != -1) {
@ -192,7 +192,7 @@ class GridRowCacheFieldNotifierImpl extends GridRowCacheFieldNotifier {
GridRowCacheFieldNotifierImpl(GridFieldCache cache) : _cache = cache; GridRowCacheFieldNotifierImpl(GridFieldCache cache) : _cache = cache;
@override @override
UnmodifiableListView<Field> get fields => _cache.unmodifiableFields; UnmodifiableListView<GridFieldPB> get fields => _cache.unmodifiableFields;
@override @override
void onFieldsChanged(VoidCallback callback) { void onFieldsChanged(VoidCallback callback) {
@ -201,8 +201,8 @@ class GridRowCacheFieldNotifierImpl extends GridRowCacheFieldNotifier {
} }
@override @override
void onFieldChanged(void Function(Field) callback) { void onFieldChanged(void Function(GridFieldPB) callback) {
_onChangesetFn = (GridFieldChangeset changeset) { _onChangesetFn = (GridFieldChangesetPB changeset) {
for (final updatedField in changeset.updatedFields) { for (final updatedField in changeset.updatedFields) {
callback(updatedField); callback(updatedField);
} }

View File

@ -4,18 +4,18 @@ export 'row/row_service.dart';
export 'grid_service.dart'; export 'grid_service.dart';
export 'grid_header_bloc.dart'; export 'grid_header_bloc.dart';
// Field // GridFieldPB
export 'field/field_service.dart'; export 'field/field_service.dart';
export 'field/field_action_sheet_bloc.dart'; export 'field/field_action_sheet_bloc.dart';
export 'field/field_editor_bloc.dart'; export 'field/field_editor_bloc.dart';
export 'field/field_type_option_edit_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/date_bloc.dart';
export 'field/type_option/number_bloc.dart'; export 'field/type_option/number_bloc.dart';
export 'field/type_option/single_select_type_option.dart'; export 'field/type_option/single_select_type_option.dart';
// Cell // GridCellPB
export 'cell/text_cell_bloc.dart'; export 'cell/text_cell_bloc.dart';
export 'cell/number_cell_bloc.dart'; export 'cell/number_cell_bloc.dart';
export 'cell/select_option_cell_bloc.dart'; export 'cell/select_option_cell_bloc.dart';

View File

@ -90,9 +90,9 @@ class RowState with _$RowState {
} }
class GridCellEquatable extends Equatable { class GridCellEquatable extends Equatable {
final Field _field; final GridFieldPB _field;
const GridCellEquatable(Field field) : _field = field; const GridCellEquatable(GridFieldPB field) : _field = field;
@override @override
List<Object?> get props => [ List<Object?> get props => [

View File

@ -8,8 +8,8 @@ import 'dart:typed_data';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
typedef UpdateRowNotifiedValue = Either<Row, FlowyError>; typedef UpdateRowNotifiedValue = Either<GridRowPB, FlowyError>;
typedef UpdateFieldNotifiedValue = Either<List<Field>, FlowyError>; typedef UpdateFieldNotifiedValue = Either<List<GridFieldPB>, FlowyError>;
class RowListener { class RowListener {
final String rowId; final String rowId;
@ -26,7 +26,7 @@ class RowListener {
switch (ty) { switch (ty) {
case GridNotification.DidUpdateRow: case GridNotification.DidUpdateRow:
result.fold( result.fold(
(payload) => updateRowNotifier?.value = left(Row.fromBuffer(payload)), (payload) => updateRowNotifier?.value = left(GridRowPB.fromBuffer(payload)),
(error) => updateRowNotifier?.value = right(error), (error) => updateRowNotifier?.value = right(error),
); );
break; break;

View File

@ -15,9 +15,9 @@ part 'row_service.freezed.dart';
typedef RowUpdateCallback = void Function(); typedef RowUpdateCallback = void Function();
abstract class GridRowCacheFieldNotifier { abstract class GridRowCacheFieldNotifier {
UnmodifiableListView<Field> get fields; UnmodifiableListView<GridFieldPB> get fields;
void onFieldsChanged(VoidCallback callback); void onFieldsChanged(VoidCallback callback);
void onFieldChanged(void Function(Field) callback); void onFieldChanged(void Function(GridFieldPB) callback);
void dispose(); void dispose();
} }
@ -28,14 +28,14 @@ abstract class GridRowCacheFieldNotifier {
class GridRowCache { class GridRowCache {
final String gridId; final String gridId;
final GridBlock block; final GridBlockPB block;
/// _rows containers the current block's rows /// _rows containers the current block's rows
/// Use List to reverse the order of the GridRow. /// Use List to reverse the order of the GridRow.
List<GridRowInfo> _rowInfos = []; List<GridRowInfo> _rowInfos = [];
/// Use Map for faster access the raw row data. /// Use Map for faster access the raw row data.
final HashMap<String, Row> _rowByRowId; final HashMap<String, GridRowPB> _rowByRowId;
final GridCellCache _cellCache; final GridCellCache _cellCache;
final GridRowCacheFieldNotifier _fieldNotifier; final GridRowCacheFieldNotifier _fieldNotifier;
@ -64,7 +64,7 @@ class GridRowCache {
await _cellCache.dispose(); await _cellCache.dispose();
} }
void applyChangesets(List<GridBlockChangeset> changesets) { void applyChangesets(List<GridBlockChangesetPB> changesets) {
for (final changeset in changesets) { for (final changeset in changesets) {
_deleteRows(changeset.deletedRows); _deleteRows(changeset.deletedRows);
_insertRows(changeset.insertedRows); _insertRows(changeset.insertedRows);
@ -95,7 +95,7 @@ class GridRowCache {
_rowChangeReasonNotifier.receive(GridRowChangeReason.delete(deletedIndex)); _rowChangeReasonNotifier.receive(GridRowChangeReason.delete(deletedIndex));
} }
void _insertRows(List<InsertedRow> insertRows) { void _insertRows(List<InsertedRowPB> insertRows) {
if (insertRows.isEmpty) { if (insertRows.isEmpty) {
return; return;
} }
@ -113,7 +113,7 @@ class GridRowCache {
_rowChangeReasonNotifier.receive(GridRowChangeReason.insert(insertIndexs)); _rowChangeReasonNotifier.receive(GridRowChangeReason.insert(insertIndexs));
} }
void _updateRows(List<UpdatedRow> updatedRows) { void _updateRows(List<UpdatedRowPB> updatedRows) {
if (updatedRows.isEmpty) { if (updatedRows.isEmpty) {
return; return;
} }
@ -183,7 +183,7 @@ class GridRowCache {
} }
GridCellMap loadGridCells(String rowId) { GridCellMap loadGridCells(String rowId) {
final Row? data = _rowByRowId[rowId]; final GridRowPB? data = _rowByRowId[rowId];
if (data == null) { if (data == null) {
_loadRow(rowId); _loadRow(rowId);
} }
@ -191,7 +191,7 @@ class GridRowCache {
} }
Future<void> _loadRow(String rowId) async { Future<void> _loadRow(String rowId) async {
final payload = GridRowIdPayload.create() final payload = GridRowIdPayloadPB.create()
..gridId = gridId ..gridId = gridId
..blockId = block.id ..blockId = block.id
..rowId = rowId; ..rowId = rowId;
@ -203,7 +203,7 @@ class GridRowCache {
); );
} }
GridCellMap _makeGridCells(String rowId, Row? row) { GridCellMap _makeGridCells(String rowId, GridRowPB? row) {
var cellDataMap = GridCellMap.new(); var cellDataMap = GridCellMap.new();
for (final field in _fieldNotifier.fields) { for (final field in _fieldNotifier.fields) {
if (field.visibility) { if (field.visibility) {
@ -217,7 +217,7 @@ class GridRowCache {
return cellDataMap; return cellDataMap;
} }
void _refreshRow(OptionalRow optionRow) { void _refreshRow(OptionalRowPB optionRow) {
if (!optionRow.hasRow()) { if (!optionRow.hasRow()) {
return; return;
} }
@ -277,8 +277,8 @@ class RowService {
RowService({required this.gridId, required this.blockId, required this.rowId}); RowService({required this.gridId, required this.blockId, required this.rowId});
Future<Either<Row, FlowyError>> createRow() { Future<Either<GridRowPB, FlowyError>> createRow() {
CreateRowPayload payload = CreateRowPayload.create() CreateRowPayloadPB payload = CreateRowPayloadPB.create()
..gridId = gridId ..gridId = gridId
..startRowId = rowId; ..startRowId = rowId;
@ -286,18 +286,18 @@ class RowService {
} }
Future<Either<Unit, FlowyError>> moveRow(String rowId, int fromIndex, int toIndex) { Future<Either<Unit, FlowyError>> moveRow(String rowId, int fromIndex, int toIndex) {
final payload = MoveItemPayload.create() final payload = MoveItemPayloadPB.create()
..gridId = gridId ..gridId = gridId
..itemId = rowId ..itemId = rowId
..ty = MoveItemType.MoveRow ..ty = MoveItemTypePB.MoveRow
..fromIndex = fromIndex ..fromIndex = fromIndex
..toIndex = toIndex; ..toIndex = toIndex;
return GridEventMoveItem(payload).send(); return GridEventMoveItem(payload).send();
} }
Future<Either<OptionalRow, FlowyError>> getRow() { Future<Either<OptionalRowPB, FlowyError>> getRow() {
final payload = GridRowIdPayload.create() final payload = GridRowIdPayloadPB.create()
..gridId = gridId ..gridId = gridId
..blockId = blockId ..blockId = blockId
..rowId = rowId; ..rowId = rowId;
@ -306,7 +306,7 @@ class RowService {
} }
Future<Either<Unit, FlowyError>> deleteRow() { Future<Either<Unit, FlowyError>> deleteRow() {
final payload = GridRowIdPayload.create() final payload = GridRowIdPayloadPB.create()
..gridId = gridId ..gridId = gridId
..blockId = blockId ..blockId = blockId
..rowId = rowId; ..rowId = rowId;
@ -315,7 +315,7 @@ class RowService {
} }
Future<Either<Unit, FlowyError>> duplicateRow() { Future<Either<Unit, FlowyError>> duplicateRow() {
final payload = GridRowIdPayload.create() final payload = GridRowIdPayloadPB.create()
..gridId = gridId ..gridId = gridId
..blockId = blockId ..blockId = blockId
..rowId = rowId; ..rowId = rowId;
@ -330,9 +330,9 @@ class GridRowInfo with _$GridRowInfo {
required String gridId, required String gridId,
required String blockId, required String blockId,
required String id, required String id,
required UnmodifiableListView<Field> fields, required UnmodifiableListView<GridFieldPB> fields,
required double height, required double height,
Row? rawRow, GridRowPB? rawRow,
}) = _GridRowInfo; }) = _GridRowInfo;
} }

View File

@ -10,7 +10,7 @@ part 'property_bloc.freezed.dart';
class GridPropertyBloc extends Bloc<GridPropertyEvent, GridPropertyState> { class GridPropertyBloc extends Bloc<GridPropertyEvent, GridPropertyState> {
final GridFieldCache _fieldCache; final GridFieldCache _fieldCache;
Function(List<Field>)? _onFieldsFn; Function(List<GridFieldPB>)? _onFieldsFn;
GridPropertyBloc({required String gridId, required GridFieldCache fieldCache}) GridPropertyBloc({required String gridId, required GridFieldCache fieldCache})
: _fieldCache = fieldCache, : _fieldCache = fieldCache,
@ -62,7 +62,7 @@ class GridPropertyBloc extends Bloc<GridPropertyEvent, GridPropertyState> {
class GridPropertyEvent with _$GridPropertyEvent { class GridPropertyEvent with _$GridPropertyEvent {
const factory GridPropertyEvent.initial() = _Initial; const factory GridPropertyEvent.initial() = _Initial;
const factory GridPropertyEvent.setFieldVisibility(String fieldId, bool visibility) = _SetFieldVisibility; const factory GridPropertyEvent.setFieldVisibility(String fieldId, bool visibility) = _SetFieldVisibility;
const factory GridPropertyEvent.didReceiveFieldUpdate(List<Field> fields) = _DidReceiveFieldUpdate; const factory GridPropertyEvent.didReceiveFieldUpdate(List<GridFieldPB> fields) = _DidReceiveFieldUpdate;
const factory GridPropertyEvent.moveField(int fromIndex, int toIndex) = _MoveField; const factory GridPropertyEvent.moveField(int fromIndex, int toIndex) = _MoveField;
} }
@ -70,10 +70,10 @@ class GridPropertyEvent with _$GridPropertyEvent {
class GridPropertyState with _$GridPropertyState { class GridPropertyState with _$GridPropertyState {
const factory GridPropertyState({ const factory GridPropertyState({
required String gridId, required String gridId,
required List<Field> fields, required List<GridFieldPB> fields,
}) = _GridPropertyState; }) = _GridPropertyState;
factory GridPropertyState.initial(String gridId, List<Field> fields) => GridPropertyState( factory GridPropertyState.initial(String gridId, List<GridFieldPB> fields) => GridPropertyState(
gridId: gridId, gridId: gridId,
fields: fields, fields: fields,
); );

View File

@ -2,7 +2,7 @@ import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
import 'sizes.dart'; import 'sizes.dart';
class GridLayout { class GridLayout {
static double headerWidth(List<Field> fields) { static double headerWidth(List<GridFieldPB> fields) {
if (fields.isEmpty) return 0; if (fields.isEmpty) return 0;
final fieldsWidth = fields.map((field) => field.width.toDouble()).reduce((value, element) => value + element); final fieldsWidth = fields.map((field) => field.width.toDouble()).reduce((value, element) => value + element);

View File

@ -7,27 +7,27 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:app_flowy/generated/locale_keys.g.dart'; import 'package:app_flowy/generated/locale_keys.g.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
extension SelectOptionColorExtension on SelectOptionColor { extension SelectOptionColorExtension on SelectOptionColorPB {
Color make(BuildContext context) { Color make(BuildContext context) {
final theme = context.watch<AppTheme>(); final theme = context.watch<AppTheme>();
switch (this) { switch (this) {
case SelectOptionColor.Purple: case SelectOptionColorPB.Purple:
return theme.tint1; return theme.tint1;
case SelectOptionColor.Pink: case SelectOptionColorPB.Pink:
return theme.tint2; return theme.tint2;
case SelectOptionColor.LightPink: case SelectOptionColorPB.LightPink:
return theme.tint3; return theme.tint3;
case SelectOptionColor.Orange: case SelectOptionColorPB.Orange:
return theme.tint4; return theme.tint4;
case SelectOptionColor.Yellow: case SelectOptionColorPB.Yellow:
return theme.tint5; return theme.tint5;
case SelectOptionColor.Lime: case SelectOptionColorPB.Lime:
return theme.tint6; return theme.tint6;
case SelectOptionColor.Green: case SelectOptionColorPB.Green:
return theme.tint7; return theme.tint7;
case SelectOptionColor.Aqua: case SelectOptionColorPB.Aqua:
return theme.tint8; return theme.tint8;
case SelectOptionColor.Blue: case SelectOptionColorPB.Blue:
return theme.tint9; return theme.tint9;
default: default:
throw ArgumentError; throw ArgumentError;
@ -36,23 +36,23 @@ extension SelectOptionColorExtension on SelectOptionColor {
String optionName() { String optionName() {
switch (this) { switch (this) {
case SelectOptionColor.Purple: case SelectOptionColorPB.Purple:
return LocaleKeys.grid_selectOption_purpleColor.tr(); return LocaleKeys.grid_selectOption_purpleColor.tr();
case SelectOptionColor.Pink: case SelectOptionColorPB.Pink:
return LocaleKeys.grid_selectOption_pinkColor.tr(); return LocaleKeys.grid_selectOption_pinkColor.tr();
case SelectOptionColor.LightPink: case SelectOptionColorPB.LightPink:
return LocaleKeys.grid_selectOption_lightPinkColor.tr(); return LocaleKeys.grid_selectOption_lightPinkColor.tr();
case SelectOptionColor.Orange: case SelectOptionColorPB.Orange:
return LocaleKeys.grid_selectOption_orangeColor.tr(); return LocaleKeys.grid_selectOption_orangeColor.tr();
case SelectOptionColor.Yellow: case SelectOptionColorPB.Yellow:
return LocaleKeys.grid_selectOption_yellowColor.tr(); return LocaleKeys.grid_selectOption_yellowColor.tr();
case SelectOptionColor.Lime: case SelectOptionColorPB.Lime:
return LocaleKeys.grid_selectOption_limeColor.tr(); return LocaleKeys.grid_selectOption_limeColor.tr();
case SelectOptionColor.Green: case SelectOptionColorPB.Green:
return LocaleKeys.grid_selectOption_greenColor.tr(); return LocaleKeys.grid_selectOption_greenColor.tr();
case SelectOptionColor.Aqua: case SelectOptionColorPB.Aqua:
return LocaleKeys.grid_selectOption_aquaColor.tr(); return LocaleKeys.grid_selectOption_aquaColor.tr();
case SelectOptionColor.Blue: case SelectOptionColorPB.Blue:
return LocaleKeys.grid_selectOption_blueColor.tr(); return LocaleKeys.grid_selectOption_blueColor.tr();
default: default:
throw ArgumentError; throw ArgumentError;
@ -75,7 +75,7 @@ class SelectOptionTag extends StatelessWidget {
factory SelectOptionTag.fromSelectOption({ factory SelectOptionTag.fromSelectOption({
required BuildContext context, required BuildContext context,
required SelectOption option, required SelectOptionPB option,
VoidCallback? onSelected, VoidCallback? onSelected,
bool isSelected = false, bool isSelected = false,
}) { }) {
@ -107,8 +107,8 @@ class SelectOptionTag extends StatelessWidget {
class SelectOptionTagCell extends StatelessWidget { class SelectOptionTagCell extends StatelessWidget {
final List<Widget> children; final List<Widget> children;
final void Function(SelectOption) onSelected; final void Function(SelectOptionPB) onSelected;
final SelectOption option; final SelectOptionPB option;
const SelectOptionTagCell({ const SelectOptionTagCell({
required this.option, required this.option,
required this.onSelected, required this.onSelected,

View File

@ -128,7 +128,7 @@ class _MultiSelectCellState extends State<MultiSelectCell> {
} }
class _SelectOptionCell extends StatelessWidget { class _SelectOptionCell extends StatelessWidget {
final List<SelectOption> selectOptions; final List<SelectOptionPB> selectOptions;
final void Function(bool) onFocus; final void Function(bool) onFocus;
final SelectOptionCellStyle? cellStyle; final SelectOptionCellStyle? cellStyle;
final GridCellControllerBuilder cellContorllerBuilder; final GridCellControllerBuilder cellContorllerBuilder;

View File

@ -146,7 +146,7 @@ class _TextField extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<SelectOptionCellEditorBloc, SelectOptionEditorState>( return BlocBuilder<SelectOptionCellEditorBloc, SelectOptionEditorState>(
builder: (context, state) { builder: (context, state) {
final optionMap = LinkedHashMap<String, SelectOption>.fromIterable(state.selectedOptions, final optionMap = LinkedHashMap<String, SelectOptionPB>.fromIterable(state.selectedOptions,
key: (option) => option.name, value: (option) => option); key: (option) => option.name, value: (option) => option);
return SizedBox( return SizedBox(
@ -216,7 +216,7 @@ class _CreateOptionCell extends StatelessWidget {
} }
class _SelectOptionCell extends StatelessWidget { class _SelectOptionCell extends StatelessWidget {
final SelectOption option; final SelectOptionPB option;
final bool isSelected; final bool isSelected;
const _SelectOptionCell(this.option, this.isSelected, {Key? key}) : super(key: key); const _SelectOptionCell(this.option, this.isSelected, {Key? key}) : super(key: key);

View File

@ -15,8 +15,8 @@ class SelectOptionTextField extends StatelessWidget {
final FocusNode _focusNode; final FocusNode _focusNode;
final TextEditingController _controller; final TextEditingController _controller;
final TextfieldTagsController tagController; final TextfieldTagsController tagController;
final List<SelectOption> options; final List<SelectOptionPB> options;
final LinkedHashMap<String, SelectOption> selectedOptionMap; final LinkedHashMap<String, SelectOptionPB> selectedOptionMap;
final double distanceToText; final double distanceToText;

View File

@ -135,7 +135,7 @@ class _DragToExpandLine extends StatelessWidget {
class FieldCellButton extends StatelessWidget { class FieldCellButton extends StatelessWidget {
final VoidCallback onTap; final VoidCallback onTap;
final Field field; final GridFieldPB field;
const FieldCellButton({ const FieldCellButton({
required this.field, required this.field,
required this.onTap, required this.onTap,

View File

@ -15,8 +15,8 @@ import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/header
import 'field_type_extension.dart'; import 'field_type_extension.dart';
import 'type_option/builder.dart'; import 'type_option/builder.dart';
typedef UpdateFieldCallback = void Function(Field, Uint8List); typedef UpdateFieldCallback = void Function(GridFieldPB, Uint8List);
typedef SwitchToFieldCallback = Future<Either<FieldTypeOptionData, FlowyError>> Function( typedef SwitchToFieldCallback = Future<Either<FieldTypeOptionDataPB, FlowyError>> Function(
String fieldId, String fieldId,
FieldType fieldType, FieldType fieldType,
); );
@ -59,7 +59,7 @@ class _FieldTypeOptionEditorState extends State<FieldTypeOptionEditor> {
); );
} }
Widget _switchFieldTypeButton(BuildContext context, Field field) { Widget _switchFieldTypeButton(BuildContext context, GridFieldPB field) {
final theme = context.watch<AppTheme>(); final theme = context.watch<AppTheme>();
return SizedBox( return SizedBox(
height: GridSize.typeOptionItemHeight, height: GridSize.typeOptionItemHeight,

View File

@ -160,7 +160,7 @@ class CreateFieldButton extends StatelessWidget {
class SliverHeaderDelegateImplementation extends SliverPersistentHeaderDelegate { class SliverHeaderDelegateImplementation extends SliverPersistentHeaderDelegate {
final String gridId; final String gridId;
final List<Field> fields; final List<GridFieldPB> fields;
SliverHeaderDelegateImplementation({required this.gridId, required this.fields}); SliverHeaderDelegateImplementation({required this.gridId, required this.fields});

View File

@ -17,7 +17,7 @@ import 'builder.dart';
import 'select_option_editor.dart'; import 'select_option_editor.dart';
class SelectOptionTypeOptionWidget extends StatelessWidget { class SelectOptionTypeOptionWidget extends StatelessWidget {
final List<SelectOption> options; final List<SelectOptionPB> options;
final VoidCallback beginEdit; final VoidCallback beginEdit;
final TypeOptionOverlayDelegate overlayDelegate; final TypeOptionOverlayDelegate overlayDelegate;
final SelectOptionTypeOptionAction typeOptionAction; 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( return _OptionCell(
option: option, option: option,
onSelected: (option) { onSelected: (option) {
@ -154,8 +154,8 @@ class _OptionList extends StatelessWidget {
} }
class _OptionCell extends StatelessWidget { class _OptionCell extends StatelessWidget {
final SelectOption option; final SelectOptionPB option;
final Function(SelectOption) onSelected; final Function(SelectOptionPB) onSelected;
const _OptionCell({ const _OptionCell({
required this.option, required this.option,
required this.onSelected, required this.onSelected,

View File

@ -15,9 +15,9 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:app_flowy/generated/locale_keys.g.dart'; import 'package:app_flowy/generated/locale_keys.g.dart';
class SelectOptionTypeOptionEditor extends StatelessWidget { class SelectOptionTypeOptionEditor extends StatelessWidget {
final SelectOption option; final SelectOptionPB option;
final VoidCallback onDeleted; final VoidCallback onDeleted;
final Function(SelectOption) onUpdated; final Function(SelectOptionPB) onUpdated;
const SelectOptionTypeOptionEditor({ const SelectOptionTypeOptionEditor({
required this.option, required this.option,
required this.onDeleted, required this.onDeleted,
@ -110,12 +110,12 @@ class _OptionNameTextField extends StatelessWidget {
} }
class SelectOptionColorList extends StatelessWidget { class SelectOptionColorList extends StatelessWidget {
final SelectOptionColor selectedColor; final SelectOptionColorPB selectedColor;
const SelectOptionColorList({required this.selectedColor, Key? key}) : super(key: key); const SelectOptionColorList({required this.selectedColor, Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cells = SelectOptionColor.values.map((color) { final cells = SelectOptionColorPB.values.map((color) {
return _SelectOptionColorCell(color: color, isSelected: selectedColor == color); return _SelectOptionColorCell(color: color, isSelected: selectedColor == color);
}).toList(); }).toList();
@ -152,7 +152,7 @@ class SelectOptionColorList extends StatelessWidget {
} }
class _SelectOptionColorCell extends StatelessWidget { class _SelectOptionColorCell extends StatelessWidget {
final SelectOptionColor color; final SelectOptionColorPB color;
final bool isSelected; final bool isSelected;
const _SelectOptionColorCell({required this.color, required this.isSelected, Key? key}) : super(key: key); const _SelectOptionColorCell({required this.color, required this.isSelected, Key? key}) : super(key: key);

View File

@ -75,7 +75,7 @@ class GridPropertyList extends StatelessWidget with FlowyOverlayDelegate {
} }
class _GridPropertyCell extends StatelessWidget { class _GridPropertyCell extends StatelessWidget {
final Field field; final GridFieldPB field;
final String gridId; final String gridId;
const _GridPropertyCell({required this.gridId, required this.field, Key? key}) : super(key: key); const _GridPropertyCell({required this.gridId, required this.field, Key? key}) : super(key: key);

View File

@ -1632,7 +1632,7 @@ final Map<String, String> activities = Map.fromIterables([
'Flying Disc', 'Flying Disc',
'Bowling', 'Bowling',
'Cricket Game', 'Cricket Game',
'Field Hockey', 'GridFieldPB Hockey',
'Ice Hockey', 'Ice Hockey',
'Lacrosse', 'Lacrosse',
'Ping Pong', 'Ping Pong',

View File

@ -1,4 +1,4 @@
use crate::entities::{FieldIdentifier, FieldIdentifierPayloadPB}; use crate::entities::{FieldIdentifierParams, GridFieldIdentifierPayloadPB};
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use flowy_error::ErrorCode; use flowy_error::ErrorCode;
use flowy_grid_data_model::parser::NotEmptyStr; use flowy_grid_data_model::parser::NotEmptyStr;
@ -6,28 +6,28 @@ use flowy_grid_data_model::revision::{CellRevision, RowMetaChangeset};
use std::collections::HashMap; use std::collections::HashMap;
#[derive(ProtoBuf, Default)] #[derive(ProtoBuf, Default)]
pub struct CreateSelectOptionPayload { pub struct CreateSelectOptionPayloadPB {
#[pb(index = 1)] #[pb(index = 1)]
pub field_identifier: FieldIdentifierPayloadPB, pub field_identifier: GridFieldIdentifierPayloadPB,
#[pb(index = 2)] #[pb(index = 2)]
pub option_name: String, pub option_name: String,
} }
pub struct CreateSelectOptionParams { pub struct CreateSelectOptionParams {
pub field_identifier: FieldIdentifier, pub field_identifier: FieldIdentifierParams,
pub option_name: String, pub option_name: String,
} }
impl std::ops::Deref for CreateSelectOptionParams { impl std::ops::Deref for CreateSelectOptionParams {
type Target = FieldIdentifier; type Target = FieldIdentifierParams;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.field_identifier &self.field_identifier
} }
} }
impl TryInto<CreateSelectOptionParams> for CreateSelectOptionPayload { impl TryInto<CreateSelectOptionParams> for CreateSelectOptionPayloadPB {
type Error = ErrorCode; type Error = ErrorCode;
fn try_into(self) -> Result<CreateSelectOptionParams, Self::Error> { fn try_into(self) -> Result<CreateSelectOptionParams, Self::Error> {
@ -41,7 +41,7 @@ impl TryInto<CreateSelectOptionParams> for CreateSelectOptionPayload {
} }
#[derive(Debug, Clone, Default, ProtoBuf)] #[derive(Debug, Clone, Default, ProtoBuf)]
pub struct CellIdentifierPayload { pub struct GridCellIdentifierPayloadPB {
#[pb(index = 1)] #[pb(index = 1)]
pub grid_id: String, pub grid_id: String,
@ -52,20 +52,20 @@ pub struct CellIdentifierPayload {
pub row_id: String, pub row_id: String,
} }
pub struct CellIdentifier { pub struct CellIdentifierParams {
pub grid_id: String, pub grid_id: String,
pub field_id: String, pub field_id: String,
pub row_id: String, pub row_id: String,
} }
impl TryInto<CellIdentifier> for CellIdentifierPayload { impl TryInto<CellIdentifierParams> for GridCellIdentifierPayloadPB {
type Error = ErrorCode; type Error = ErrorCode;
fn try_into(self) -> Result<CellIdentifier, Self::Error> { fn try_into(self) -> Result<CellIdentifierParams, Self::Error> {
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; 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 field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?; let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
Ok(CellIdentifier { Ok(CellIdentifierParams {
grid_id: grid_id.0, grid_id: grid_id.0,
field_id: field_id.0, field_id: field_id.0,
row_id: row_id.0, row_id: row_id.0,
@ -73,7 +73,7 @@ impl TryInto<CellIdentifier> for CellIdentifierPayload {
} }
} }
#[derive(Debug, Default, ProtoBuf)] #[derive(Debug, Default, ProtoBuf)]
pub struct Cell { pub struct GridCellPB {
#[pb(index = 1)] #[pb(index = 1)]
pub field_id: String, pub field_id: String,
@ -81,7 +81,7 @@ pub struct Cell {
pub data: Vec<u8>, pub data: Vec<u8>,
} }
impl Cell { impl GridCellPB {
pub fn new(field_id: &str, data: Vec<u8>) -> Self { pub fn new(field_id: &str, data: Vec<u8>) -> Self {
Self { Self {
field_id: field_id.to_owned(), field_id: field_id.to_owned(),
@ -98,32 +98,32 @@ impl Cell {
} }
#[derive(Debug, Default, ProtoBuf)] #[derive(Debug, Default, ProtoBuf)]
pub struct RepeatedCell { pub struct RepeatedCellPB {
#[pb(index = 1)] #[pb(index = 1)]
pub items: Vec<Cell>, pub items: Vec<GridCellPB>,
} }
impl std::ops::Deref for RepeatedCell { impl std::ops::Deref for RepeatedCellPB {
type Target = Vec<Cell>; type Target = Vec<GridCellPB>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.items &self.items
} }
} }
impl std::ops::DerefMut for RepeatedCell { impl std::ops::DerefMut for RepeatedCellPB {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.items &mut self.items
} }
} }
impl std::convert::From<Vec<Cell>> for RepeatedCell { impl std::convert::From<Vec<GridCellPB>> for RepeatedCellPB {
fn from(items: Vec<Cell>) -> Self { fn from(items: Vec<GridCellPB>) -> Self {
Self { items } Self { items }
} }
} }
#[derive(Debug, Clone, Default, ProtoBuf)] #[derive(Debug, Clone, Default, ProtoBuf)]
pub struct CellChangeset { pub struct CellChangesetPB {
#[pb(index = 1)] #[pb(index = 1)]
pub grid_id: String, pub grid_id: String,
@ -137,8 +137,8 @@ pub struct CellChangeset {
pub content: Option<String>, pub content: Option<String>,
} }
impl std::convert::From<CellChangeset> for RowMetaChangeset { impl std::convert::From<CellChangesetPB> for RowMetaChangeset {
fn from(changeset: CellChangeset) -> Self { fn from(changeset: CellChangesetPB) -> Self {
let mut cell_by_field_id = HashMap::with_capacity(1); let mut cell_by_field_id = HashMap::with_capacity(1);
let field_id = changeset.field_id; let field_id = changeset.field_id;
let cell_rev = CellRevision { let cell_rev = CellRevision {

View File

@ -9,7 +9,7 @@ use std::sync::Arc;
use strum_macros::{Display, EnumCount as EnumCountMacro, EnumIter, EnumString}; use strum_macros::{Display, EnumCount as EnumCountMacro, EnumIter, EnumString};
#[derive(Debug, Clone, Default, ProtoBuf)] #[derive(Debug, Clone, Default, ProtoBuf)]
pub struct FieldPB { pub struct GridFieldPB {
#[pb(index = 1)] #[pb(index = 1)]
pub id: String, pub id: String,
@ -35,7 +35,7 @@ pub struct FieldPB {
pub is_primary: bool, pub is_primary: bool,
} }
impl std::convert::From<FieldRevision> for FieldPB { impl std::convert::From<FieldRevision> for GridFieldPB {
fn from(field_rev: FieldRevision) -> Self { fn from(field_rev: FieldRevision) -> Self {
Self { Self {
id: field_rev.id, id: field_rev.id,
@ -50,31 +50,31 @@ impl std::convert::From<FieldRevision> for FieldPB {
} }
} }
impl std::convert::From<Arc<FieldRevision>> for FieldPB { impl std::convert::From<Arc<FieldRevision>> for GridFieldPB {
fn from(field_rev: Arc<FieldRevision>) -> Self { fn from(field_rev: Arc<FieldRevision>) -> Self {
let field_rev = field_rev.as_ref().clone(); let field_rev = field_rev.as_ref().clone();
FieldPB::from(field_rev) GridFieldPB::from(field_rev)
} }
} }
#[derive(Debug, Clone, Default, ProtoBuf)] #[derive(Debug, Clone, Default, ProtoBuf)]
pub struct GridFieldPB { pub struct GridFieldIdPB {
#[pb(index = 1)] #[pb(index = 1)]
pub field_id: String, pub field_id: String,
} }
impl std::convert::From<&str> for GridFieldPB { impl std::convert::From<&str> for GridFieldIdPB {
fn from(s: &str) -> Self { fn from(s: &str) -> Self {
GridFieldPB { field_id: s.to_owned() } GridFieldIdPB { field_id: s.to_owned() }
} }
} }
impl std::convert::From<String> for GridFieldPB { impl std::convert::From<String> for GridFieldIdPB {
fn from(s: String) -> Self { fn from(s: String) -> Self {
GridFieldPB { field_id: s } GridFieldIdPB { field_id: s }
} }
} }
impl std::convert::From<&Arc<FieldRevision>> for GridFieldPB { impl std::convert::From<&Arc<FieldRevision>> for GridFieldIdPB {
fn from(field_rev: &Arc<FieldRevision>) -> Self { fn from(field_rev: &Arc<FieldRevision>) -> Self {
Self { Self {
field_id: field_rev.id.clone(), field_id: field_rev.id.clone(),
@ -90,10 +90,10 @@ pub struct GridFieldChangesetPB {
pub inserted_fields: Vec<IndexFieldPB>, pub inserted_fields: Vec<IndexFieldPB>,
#[pb(index = 3)] #[pb(index = 3)]
pub deleted_fields: Vec<GridFieldPB>, pub deleted_fields: Vec<GridFieldIdPB>,
#[pb(index = 4)] #[pb(index = 4)]
pub updated_fields: Vec<FieldPB>, pub updated_fields: Vec<GridFieldPB>,
} }
impl GridFieldChangesetPB { impl GridFieldChangesetPB {
@ -106,7 +106,7 @@ impl GridFieldChangesetPB {
} }
} }
pub fn delete(grid_id: &str, deleted_fields: Vec<GridFieldPB>) -> Self { pub fn delete(grid_id: &str, deleted_fields: Vec<GridFieldIdPB>) -> Self {
Self { Self {
grid_id: grid_id.to_string(), grid_id: grid_id.to_string(),
inserted_fields: vec![], inserted_fields: vec![],
@ -115,7 +115,7 @@ impl GridFieldChangesetPB {
} }
} }
pub fn update(grid_id: &str, updated_fields: Vec<FieldPB>) -> Self { pub fn update(grid_id: &str, updated_fields: Vec<GridFieldPB>) -> Self {
Self { Self {
grid_id: grid_id.to_string(), grid_id: grid_id.to_string(),
inserted_fields: vec![], inserted_fields: vec![],
@ -128,7 +128,7 @@ impl GridFieldChangesetPB {
#[derive(Debug, Clone, Default, ProtoBuf)] #[derive(Debug, Clone, Default, ProtoBuf)]
pub struct IndexFieldPB { pub struct IndexFieldPB {
#[pb(index = 1)] #[pb(index = 1)]
pub field: FieldPB, pub field: GridFieldPB,
#[pb(index = 2)] #[pb(index = 2)]
pub index: i32, pub index: i32,
@ -137,7 +137,7 @@ pub struct IndexFieldPB {
impl IndexFieldPB { impl IndexFieldPB {
pub fn from_field_rev(field_rev: &Arc<FieldRevision>, index: usize) -> Self { pub fn from_field_rev(field_rev: &Arc<FieldRevision>, index: usize) -> Self {
Self { Self {
field: FieldPB::from(field_rev.as_ref().clone()), field: GridFieldPB::from(field_rev.as_ref().clone()),
index: index as i32, index: index as i32,
} }
} }
@ -214,42 +214,17 @@ pub struct FieldTypeOptionDataPB {
pub grid_id: String, pub grid_id: String,
#[pb(index = 2)] #[pb(index = 2)]
pub field: FieldPB, pub field: GridFieldPB,
#[pb(index = 3)] #[pb(index = 3)]
pub type_option_data: Vec<u8>, pub type_option_data: Vec<u8>,
} }
#[derive(Debug, Default, ProtoBuf)] #[derive(Debug, Default, ProtoBuf)]
pub struct RepeatedFieldPB {
#[pb(index = 1)]
pub items: Vec<FieldPB>,
}
impl std::ops::Deref for RepeatedFieldPB {
type Target = Vec<FieldPB>;
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<Vec<FieldPB>> for RepeatedFieldPB {
fn from(items: Vec<FieldPB>) -> Self {
Self { items }
}
}
#[derive(Debug, Clone, Default, ProtoBuf)]
pub struct RepeatedGridFieldPB { pub struct RepeatedGridFieldPB {
#[pb(index = 1)] #[pb(index = 1)]
pub items: Vec<GridFieldPB>, pub items: Vec<GridFieldPB>,
} }
impl std::ops::Deref for RepeatedGridFieldPB { impl std::ops::Deref for RepeatedGridFieldPB {
type Target = Vec<GridFieldPB>; type Target = Vec<GridFieldPB>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@ -257,16 +232,41 @@ impl std::ops::Deref for RepeatedGridFieldPB {
} }
} }
impl std::convert::From<Vec<GridFieldPB>> for RepeatedGridFieldPB { impl std::ops::DerefMut for RepeatedGridFieldPB {
fn from(field_orders: Vec<GridFieldPB>) -> Self { fn deref_mut(&mut self) -> &mut Self::Target {
RepeatedGridFieldPB { items: field_orders } &mut self.items
} }
} }
impl std::convert::From<String> for RepeatedGridFieldPB { impl std::convert::From<Vec<GridFieldPB>> for RepeatedGridFieldPB {
fn from(items: Vec<GridFieldPB>) -> Self {
Self { items }
}
}
#[derive(Debug, Clone, Default, ProtoBuf)]
pub struct RepeatedGridFieldIdPB {
#[pb(index = 1)]
pub items: Vec<GridFieldIdPB>,
}
impl std::ops::Deref for RepeatedGridFieldIdPB {
type Target = Vec<GridFieldIdPB>;
fn deref(&self) -> &Self::Target {
&self.items
}
}
impl std::convert::From<Vec<GridFieldIdPB>> for RepeatedGridFieldIdPB {
fn from(items: Vec<GridFieldIdPB>) -> Self {
RepeatedGridFieldIdPB { items }
}
}
impl std::convert::From<String> for RepeatedGridFieldIdPB {
fn from(s: String) -> Self { fn from(s: String) -> Self {
RepeatedGridFieldPB { RepeatedGridFieldIdPB {
items: vec![GridFieldPB::from(s)], items: vec![GridFieldIdPB::from(s)],
} }
} }
} }
@ -277,7 +277,7 @@ pub struct InsertFieldPayloadPB {
pub grid_id: String, pub grid_id: String,
#[pb(index = 2)] #[pb(index = 2)]
pub field: FieldPB, pub field: GridFieldPB,
#[pb(index = 3)] #[pb(index = 3)]
pub type_option_data: Vec<u8>, pub type_option_data: Vec<u8>,
@ -289,7 +289,7 @@ pub struct InsertFieldPayloadPB {
#[derive(Clone)] #[derive(Clone)]
pub struct InsertFieldParams { pub struct InsertFieldParams {
pub grid_id: String, pub grid_id: String,
pub field: FieldPB, pub field: GridFieldPB,
pub type_option_data: Vec<u8>, pub type_option_data: Vec<u8>,
pub start_field_id: Option<String>, pub start_field_id: Option<String>,
} }
@ -355,12 +355,12 @@ pub struct QueryFieldPayloadPB {
pub grid_id: String, pub grid_id: String,
#[pb(index = 2)] #[pb(index = 2)]
pub field_orders: RepeatedGridFieldPB, pub field_ids: RepeatedGridFieldIdPB,
} }
pub struct QueryFieldParams { pub struct QueryFieldParams {
pub grid_id: String, pub grid_id: String,
pub field_orders: RepeatedGridFieldPB, pub field_ids: RepeatedGridFieldIdPB,
} }
impl TryInto<QueryFieldParams> for QueryFieldPayloadPB { impl TryInto<QueryFieldParams> for QueryFieldPayloadPB {
@ -370,7 +370,7 @@ impl TryInto<QueryFieldParams> for QueryFieldPayloadPB {
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
Ok(QueryFieldParams { Ok(QueryFieldParams {
grid_id: grid_id.0, grid_id: grid_id.0,
field_orders: self.field_orders, field_ids: self.field_ids,
}) })
} }
} }
@ -557,7 +557,7 @@ impl std::convert::From<FieldTypeRevision> for FieldType {
} }
} }
#[derive(Debug, Clone, Default, ProtoBuf)] #[derive(Debug, Clone, Default, ProtoBuf)]
pub struct FieldIdentifierPayloadPB { pub struct GridFieldIdentifierPayloadPB {
#[pb(index = 1)] #[pb(index = 1)]
pub field_id: String, pub field_id: String,
@ -565,18 +565,18 @@ pub struct FieldIdentifierPayloadPB {
pub grid_id: String, pub grid_id: String,
} }
pub struct FieldIdentifier { pub struct FieldIdentifierParams {
pub field_id: String, pub field_id: String,
pub grid_id: String, pub grid_id: String,
} }
impl TryInto<FieldIdentifier> for FieldIdentifierPayloadPB { impl TryInto<FieldIdentifierParams> for GridFieldIdentifierPayloadPB {
type Error = ErrorCode; type Error = ErrorCode;
fn try_into(self) -> Result<FieldIdentifier, Self::Error> { fn try_into(self) -> Result<FieldIdentifierParams, Self::Error> {
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?; 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 field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
Ok(FieldIdentifier { Ok(FieldIdentifierParams {
grid_id: grid_id.0, grid_id: grid_id.0,
field_id: field_id.0, field_id: field_id.0,
}) })

View File

@ -1,4 +1,4 @@
use crate::entities::{GridBlockPB, GridFieldPB}; use crate::entities::{GridBlockPB, GridFieldIdPB};
use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_error::ErrorCode; use flowy_error::ErrorCode;
use flowy_grid_data_model::parser::NotEmptyStr; use flowy_grid_data_model::parser::NotEmptyStr;
@ -8,7 +8,7 @@ pub struct GridPB {
pub id: String, pub id: String,
#[pb(index = 2)] #[pb(index = 2)]
pub fields: Vec<GridFieldPB>, pub fields: Vec<GridFieldIdPB>,
#[pb(index = 3)] #[pb(index = 3)]
pub blocks: Vec<GridBlockPB>, pub blocks: Vec<GridBlockPB>,

View File

@ -3,9 +3,9 @@ use crate::manager::GridManager;
use crate::services::cell::AnyCellData; use crate::services::cell::AnyCellData;
use crate::services::field::{ use crate::services::field::{
default_type_option_builder_from_type, select_option_operation, type_option_builder_from_json_str, default_type_option_builder_from_type, select_option_operation, type_option_builder_from_json_str,
DateChangesetParams, DateChangesetPayloadPB, SelectOptionPB, SelectOptionCellChangeset, DateChangesetParams, DateChangesetPayloadPB, SelectOptionCellChangeset, SelectOptionCellChangesetParams,
SelectOptionCellChangesetParams, SelectOptionCellChangesetPayloadPB, SelectOptionCellDataPB, SelectOptionChangeset, SelectOptionCellChangesetPayloadPB, SelectOptionCellDataPB, SelectOptionChangeset, SelectOptionChangesetPayloadPB,
SelectOptionChangesetPayloadPB, SelectOptionPB,
}; };
use crate::services::row::make_row_from_row_rev; use crate::services::row::make_row_from_row_rev;
use flowy_error::{ErrorCode, FlowyError, FlowyResult}; 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( pub(crate) async fn get_fields_handler(
data: Data<QueryFieldPayloadPB>, data: Data<QueryFieldPayloadPB>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> DataResult<RepeatedFieldPB, FlowyError> { ) -> DataResult<RepeatedGridFieldPB, FlowyError> {
let params: QueryFieldParams = data.into_inner().try_into()?; let params: QueryFieldParams = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&params.grid_id)?; let editor = manager.get_grid_editor(&params.grid_id)?;
let field_orders = params let field_orders = params
.field_orders .field_ids
.items .items
.into_iter() .into_iter()
.map(|field_order| field_order.field_id) .map(|field_order| field_order.field_id)
.collect(); .collect();
let field_revs = editor.get_field_revs(Some(field_orders)).await?; let field_revs = editor.get_field_revs(Some(field_orders)).await?;
let repeated_field: RepeatedFieldPB = field_revs.into_iter().map(FieldPB::from).collect::<Vec<_>>().into(); let repeated_field: RepeatedGridFieldPB = field_revs.into_iter().map(GridFieldPB::from).collect::<Vec<_>>().into();
data_result(repeated_field) 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)] #[tracing::instrument(level = "trace", skip(data, manager), err)]
pub(crate) async fn delete_field_handler( pub(crate) async fn delete_field_handler(
data: Data<FieldIdentifierPayloadPB>, data: Data<GridFieldIdentifierPayloadPB>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> Result<(), FlowyError> { ) -> Result<(), FlowyError> {
let params: FieldIdentifier = data.into_inner().try_into()?; let params: FieldIdentifierParams = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&params.grid_id)?; let editor = manager.get_grid_editor(&params.grid_id)?;
let _ = editor.delete_field(&params.field_id).await?; let _ = editor.delete_field(&params.field_id).await?;
Ok(()) Ok(())
@ -151,10 +151,10 @@ pub(crate) async fn switch_to_field_handler(
#[tracing::instrument(level = "trace", skip(data, manager), err)] #[tracing::instrument(level = "trace", skip(data, manager), err)]
pub(crate) async fn duplicate_field_handler( pub(crate) async fn duplicate_field_handler(
data: Data<FieldIdentifierPayloadPB>, data: Data<GridFieldIdentifierPayloadPB>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> Result<(), FlowyError> { ) -> Result<(), FlowyError> {
let params: FieldIdentifier = data.into_inner().try_into()?; let params: FieldIdentifierParams = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&params.grid_id)?; let editor = manager.get_grid_editor(&params.grid_id)?;
let _ = editor.duplicate_field(&params.field_id).await?; let _ = editor.duplicate_field(&params.field_id).await?;
Ok(()) Ok(())
@ -275,23 +275,23 @@ pub(crate) async fn create_row_handler(
// #[tracing::instrument(level = "debug", skip_all, err)] // #[tracing::instrument(level = "debug", skip_all, err)]
pub(crate) async fn get_cell_handler( pub(crate) async fn get_cell_handler(
data: Data<CellIdentifierPayload>, data: Data<GridCellIdentifierPayloadPB>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> DataResult<Cell, FlowyError> { ) -> DataResult<GridCellPB, FlowyError> {
let params: CellIdentifier = data.into_inner().try_into()?; let params: CellIdentifierParams = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&params.grid_id)?; let editor = manager.get_grid_editor(&params.grid_id)?;
match editor.get_cell(&params).await { match editor.get_cell(&params).await {
None => data_result(Cell::empty(&params.field_id)), None => data_result(GridCellPB::empty(&params.field_id)),
Some(cell) => data_result(cell), Some(cell) => data_result(cell),
} }
} }
#[tracing::instrument(level = "trace", skip_all, err)] #[tracing::instrument(level = "trace", skip_all, err)]
pub(crate) async fn update_cell_handler( pub(crate) async fn update_cell_handler(
data: Data<CellChangeset>, data: Data<CellChangesetPB>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> Result<(), FlowyError> { ) -> 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 = manager.get_grid_editor(&changeset.grid_id)?;
let _ = editor.update_cell(changeset).await?; let _ = editor.update_cell(changeset).await?;
Ok(()) Ok(())
@ -299,7 +299,7 @@ pub(crate) async fn update_cell_handler(
#[tracing::instrument(level = "trace", skip_all, err)] #[tracing::instrument(level = "trace", skip_all, err)]
pub(crate) async fn new_select_option_handler( pub(crate) async fn new_select_option_handler(
data: Data<CreateSelectOptionPayload>, data: Data<CreateSelectOptionPayloadPB>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> DataResult<SelectOptionPB, FlowyError> { ) -> DataResult<SelectOptionPB, FlowyError> {
let params: CreateSelectOptionParams = data.into_inner().try_into()?; 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); mut_field_rev.insert_type_option_entry(&*type_option);
let _ = editor.replace_field(field_rev).await?; let _ = editor.replace_field(field_rev).await?;
let changeset = CellChangeset { let changeset = CellChangesetPB {
grid_id: changeset.cell_identifier.grid_id, grid_id: changeset.cell_identifier.grid_id,
row_id: changeset.cell_identifier.row_id, row_id: changeset.cell_identifier.row_id,
field_id: changeset.cell_identifier.field_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)] #[tracing::instrument(level = "trace", skip(data, manager), err)]
pub(crate) async fn get_select_option_handler( pub(crate) async fn get_select_option_handler(
data: Data<CellIdentifierPayload>, data: Data<GridCellIdentifierPayloadPB>,
manager: AppData<Arc<GridManager>>, manager: AppData<Arc<GridManager>>,
) -> DataResult<SelectOptionCellDataPB, FlowyError> { ) -> DataResult<SelectOptionCellDataPB, FlowyError> {
let params: CellIdentifier = data.into_inner().try_into()?; let params: CellIdentifierParams = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&params.grid_id)?; let editor = manager.get_grid_editor(&params.grid_id)?;
match editor.get_field_rev(&params.field_id).await { match editor.get_field_rev(&params.field_id).await {
None => { None => {

View File

@ -45,78 +45,78 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
#[event_err = "FlowyError"] #[event_err = "FlowyError"]
pub enum GridEvent { pub enum GridEvent {
#[event(input = "GridId", output = "Grid")] #[event(input = "GridIdPB", output = "GridPB")]
GetGrid = 0, GetGrid = 0,
#[event(input = "QueryGridBlocksPayload", output = "RepeatedGridBlock")] #[event(input = "QueryGridBlocksPayloadPB", output = "RepeatedGridBlockPB")]
GetGridBlocks = 1, GetGridBlocks = 1,
#[event(input = "GridId", output = "GridSetting")] #[event(input = "GridIdPB", output = "GridSettingPB")]
GetGridSetting = 2, GetGridSetting = 2,
#[event(input = "GridId", input = "GridSettingChangesetPayload")] #[event(input = "GridIdPB", input = "GridSettingChangesetPayloadPB")]
UpdateGridSetting = 3, UpdateGridSetting = 3,
#[event(input = "QueryFieldPayload", output = "RepeatedField")] #[event(input = "QueryFieldPayloadPB", output = "RepeatedGridFieldPB")]
GetFields = 10, GetFields = 10,
#[event(input = "FieldChangesetPayload")] #[event(input = "FieldChangesetPayloadPB")]
UpdateField = 11, UpdateField = 11,
#[event(input = "UpdateFieldTypeOptionPayload")] #[event(input = "UpdateFieldTypeOptionPayloadPB")]
UpdateFieldTypeOption = 12, UpdateFieldTypeOption = 12,
#[event(input = "InsertFieldPayload")] #[event(input = "InsertFieldPayloadPB")]
InsertField = 13, InsertField = 13,
#[event(input = "FieldIdentifierPayload")] #[event(input = "GridFieldIdentifierPayloadPB")]
DeleteField = 14, DeleteField = 14,
#[event(input = "EditFieldPayload", output = "FieldTypeOptionData")] #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")]
SwitchToField = 20, SwitchToField = 20,
#[event(input = "FieldIdentifierPayload")] #[event(input = "GridFieldIdentifierPayloadPB")]
DuplicateField = 21, DuplicateField = 21,
#[event(input = "MoveItemPayload")] #[event(input = "MoveItemPayloadPB")]
MoveItem = 22, MoveItem = 22,
#[event(input = "EditFieldPayload", output = "FieldTypeOptionData")] #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")]
GetFieldTypeOption = 23, GetFieldTypeOption = 23,
#[event(input = "EditFieldPayload", output = "FieldTypeOptionData")] #[event(input = "EditFieldPayloadPB", output = "FieldTypeOptionDataPB")]
CreateFieldTypeOption = 24, CreateFieldTypeOption = 24,
#[event(input = "CreateSelectOptionPayload", output = "SelectOption")] #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
NewSelectOption = 30, NewSelectOption = 30,
#[event(input = "CellIdentifierPayload", output = "SelectOptionCellData")] #[event(input = "GridCellIdentifierPayloadPB", output = "SelectOptionCellDataPB")]
GetSelectOptionCellData = 31, GetSelectOptionCellData = 31,
#[event(input = "SelectOptionChangesetPayload")] #[event(input = "SelectOptionChangesetPayloadPB")]
UpdateSelectOption = 32, UpdateSelectOption = 32,
#[event(input = "CreateRowPayload", output = "Row")] #[event(input = "CreateRowPayloadPB", output = "GridRowPB")]
CreateRow = 50, CreateRow = 50,
#[event(input = "GridRowIdPayload", output = "OptionalRow")] #[event(input = "GridRowIdPayloadPB", output = "OptionalRowPB")]
GetRow = 51, GetRow = 51,
#[event(input = "GridRowIdPayload")] #[event(input = "GridRowIdPayloadPB")]
DeleteRow = 52, DeleteRow = 52,
#[event(input = "GridRowIdPayload")] #[event(input = "GridRowIdPayloadPB")]
DuplicateRow = 53, DuplicateRow = 53,
#[event(input = "CellIdentifierPayload", output = "Cell")] #[event(input = "GridCellIdentifierPayloadPB", output = "GridCellPB")]
GetCell = 70, GetCell = 70,
#[event(input = "CellChangeset")] #[event(input = "CellChangesetPB")]
UpdateCell = 71, UpdateCell = 71,
#[event(input = "SelectOptionCellChangesetPayload")] #[event(input = "SelectOptionCellChangesetPayloadPB")]
UpdateSelectOptionCell = 72, UpdateSelectOptionCell = 72,
#[event(input = "DateChangesetPayload")] #[event(input = "DateChangesetPayloadPB")]
UpdateDateCell = 80, UpdateDateCell = 80,
} }

View File

@ -1,5 +1,5 @@
use crate::dart_notification::{send_dart_notification, GridNotification}; 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::manager::GridUser;
use crate::services::block_revision_editor::GridBlockRevisionEditor; use crate::services::block_revision_editor::GridBlockRevisionEditor;
use crate::services::persistence::block_index::BlockIndexCache; use crate::services::persistence::block_index::BlockIndexCache;
@ -196,7 +196,7 @@ impl GridBlockManager {
Ok(()) Ok(())
} }
pub async fn update_cell<F>(&self, changeset: CellChangeset, row_builder: F) -> FlowyResult<()> pub async fn update_cell<F>(&self, changeset: CellChangesetPB, row_builder: F) -> FlowyResult<()>
where where
F: FnOnce(Arc<RowRevision>) -> Option<GridRowPB>, F: FnOnce(Arc<RowRevision>) -> Option<GridRowPB>,
{ {
@ -254,7 +254,7 @@ impl GridBlockManager {
Ok(()) 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); let id = format!("{}:{}", changeset.row_id, changeset.field_id);
send_dart_notification(&id, GridNotification::DidUpdateCell).send(); send_dart_notification(&id, GridNotification::DidUpdateCell).send();
Ok(()) Ok(())

View File

@ -1,4 +1,4 @@
use crate::entities::{FieldPB, FieldType}; use crate::entities::{FieldType, GridFieldPB};
use crate::services::field::type_options::*; use crate::services::field::type_options::*;
use bytes::Bytes; use bytes::Bytes;
use flowy_grid_data_model::revision::{FieldRevision, TypeOptionDataEntry}; use flowy_grid_data_model::revision::{FieldRevision, TypeOptionDataEntry};
@ -28,7 +28,7 @@ impl FieldBuilder {
Self::new(type_option_builder) Self::new(type_option_builder)
} }
pub fn from_field(field: FieldPB, type_option_builder: Box<dyn TypeOptionBuilder>) -> Self { pub fn from_field(field: GridFieldPB, type_option_builder: Box<dyn TypeOptionBuilder>) -> Self {
let field_rev = FieldRevision { let field_rev = FieldRevision {
id: field.id, id: field.id,
name: field.name, name: field.name,

View File

@ -1,5 +1,5 @@
use crate::entities::CellChangeset; use crate::entities::CellChangesetPB;
use crate::entities::{CellIdentifier, CellIdentifierPayload}; use crate::entities::{CellIdentifierParams, GridCellIdentifierPayloadPB};
use crate::services::cell::{CellBytesParser, FromCellChangeset, FromCellString}; use crate::services::cell::{CellBytesParser, FromCellChangeset, FromCellString};
use bytes::Bytes; use bytes::Bytes;
@ -24,7 +24,7 @@ pub struct DateCellDataPB {
#[derive(Clone, Debug, Default, ProtoBuf)] #[derive(Clone, Debug, Default, ProtoBuf)]
pub struct DateChangesetPayloadPB { pub struct DateChangesetPayloadPB {
#[pb(index = 1)] #[pb(index = 1)]
pub cell_identifier: CellIdentifierPayload, pub cell_identifier: GridCellIdentifierPayloadPB,
#[pb(index = 2, one_of)] #[pb(index = 2, one_of)]
pub date: Option<String>, pub date: Option<String>,
@ -34,7 +34,7 @@ pub struct DateChangesetPayloadPB {
} }
pub struct DateChangesetParams { pub struct DateChangesetParams {
pub cell_identifier: CellIdentifier, pub cell_identifier: CellIdentifierParams,
pub date: Option<String>, pub date: Option<String>,
pub time: Option<String>, pub time: Option<String>,
} }
@ -43,7 +43,7 @@ impl TryInto<DateChangesetParams> for DateChangesetPayloadPB {
type Error = ErrorCode; type Error = ErrorCode;
fn try_into(self) -> Result<DateChangesetParams, Self::Error> { fn try_into(self) -> Result<DateChangesetParams, Self::Error> {
let cell_identifier: CellIdentifier = self.cell_identifier.try_into()?; let cell_identifier: CellIdentifierParams = self.cell_identifier.try_into()?;
Ok(DateChangesetParams { Ok(DateChangesetParams {
cell_identifier, cell_identifier,
date: self.date, date: self.date,
@ -52,14 +52,14 @@ impl TryInto<DateChangesetParams> for DateChangesetPayloadPB {
} }
} }
impl std::convert::From<DateChangesetParams> for CellChangeset { impl std::convert::From<DateChangesetParams> for CellChangesetPB {
fn from(params: DateChangesetParams) -> Self { fn from(params: DateChangesetParams) -> Self {
let changeset = DateCellChangesetPB { let changeset = DateCellChangesetPB {
date: params.date, date: params.date,
time: params.time, time: params.time,
}; };
let s = serde_json::to_string(&changeset).unwrap(); let s = serde_json::to_string(&changeset).unwrap();
CellChangeset { CellChangesetPB {
grid_id: params.cell_identifier.grid_id, grid_id: params.cell_identifier.grid_id,
row_id: params.cell_identifier.row_id, row_id: params.cell_identifier.row_id,
field_id: params.cell_identifier.field_id, field_id: params.cell_identifier.field_id,

View File

@ -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::cell::{CellBytes, CellBytesParser, CellData, CellDisplayable, FromCellChangeset, FromCellString};
use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB}; use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB};
use bytes::Bytes; use bytes::Bytes;
@ -225,7 +225,7 @@ impl CellBytesParser for SelectOptionCellDataParser {
#[derive(Clone, Debug, Default, ProtoBuf)] #[derive(Clone, Debug, Default, ProtoBuf)]
pub struct SelectOptionCellChangesetPayloadPB { pub struct SelectOptionCellChangesetPayloadPB {
#[pb(index = 1)] #[pb(index = 1)]
pub cell_identifier: CellIdentifierPayload, pub cell_identifier: GridCellIdentifierPayloadPB,
#[pb(index = 2, one_of)] #[pb(index = 2, one_of)]
pub insert_option_id: Option<String>, pub insert_option_id: Option<String>,
@ -235,19 +235,19 @@ pub struct SelectOptionCellChangesetPayloadPB {
} }
pub struct SelectOptionCellChangesetParams { pub struct SelectOptionCellChangesetParams {
pub cell_identifier: CellIdentifier, pub cell_identifier: CellIdentifierParams,
pub insert_option_id: Option<String>, pub insert_option_id: Option<String>,
pub delete_option_id: Option<String>, pub delete_option_id: Option<String>,
} }
impl std::convert::From<SelectOptionCellChangesetParams> for CellChangeset { impl std::convert::From<SelectOptionCellChangesetParams> for CellChangesetPB {
fn from(params: SelectOptionCellChangesetParams) -> Self { fn from(params: SelectOptionCellChangesetParams) -> Self {
let changeset = SelectOptionCellChangeset { let changeset = SelectOptionCellChangeset {
insert_option_id: params.insert_option_id, insert_option_id: params.insert_option_id,
delete_option_id: params.delete_option_id, delete_option_id: params.delete_option_id,
}; };
let s = serde_json::to_string(&changeset).unwrap(); let s = serde_json::to_string(&changeset).unwrap();
CellChangeset { CellChangesetPB {
grid_id: params.cell_identifier.grid_id, grid_id: params.cell_identifier.grid_id,
row_id: params.cell_identifier.row_id, row_id: params.cell_identifier.row_id,
field_id: params.cell_identifier.field_id, field_id: params.cell_identifier.field_id,
@ -260,7 +260,7 @@ impl TryInto<SelectOptionCellChangesetParams> for SelectOptionCellChangesetPaylo
type Error = ErrorCode; type Error = ErrorCode;
fn try_into(self) -> Result<SelectOptionCellChangesetParams, Self::Error> { fn try_into(self) -> Result<SelectOptionCellChangesetParams, Self::Error> {
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 { let insert_option_id = match self.insert_option_id {
None => None, None => None,
Some(insert_option_id) => Some( Some(insert_option_id) => Some(
@ -334,7 +334,7 @@ pub struct SelectOptionCellDataPB {
#[derive(Clone, Debug, Default, ProtoBuf)] #[derive(Clone, Debug, Default, ProtoBuf)]
pub struct SelectOptionChangesetPayloadPB { pub struct SelectOptionChangesetPayloadPB {
#[pb(index = 1)] #[pb(index = 1)]
pub cell_identifier: CellIdentifierPayload, pub cell_identifier: GridCellIdentifierPayloadPB,
#[pb(index = 2, one_of)] #[pb(index = 2, one_of)]
pub insert_option: Option<SelectOptionPB>, pub insert_option: Option<SelectOptionPB>,
@ -347,7 +347,7 @@ pub struct SelectOptionChangesetPayloadPB {
} }
pub struct SelectOptionChangeset { pub struct SelectOptionChangeset {
pub cell_identifier: CellIdentifier, pub cell_identifier: CellIdentifierParams,
pub insert_option: Option<SelectOptionPB>, pub insert_option: Option<SelectOptionPB>,
pub update_option: Option<SelectOptionPB>, pub update_option: Option<SelectOptionPB>,
pub delete_option: Option<SelectOptionPB>, pub delete_option: Option<SelectOptionPB>,

View File

@ -1,5 +1,5 @@
use crate::dart_notification::{send_dart_notification, GridNotification}; use crate::dart_notification::{send_dart_notification, GridNotification};
use crate::entities::CellIdentifier; use crate::entities::CellIdentifierParams;
use crate::entities::*; use crate::entities::*;
use crate::manager::{GridTaskSchedulerRwLock, GridUser}; use crate::manager::{GridTaskSchedulerRwLock, GridUser};
use crate::services::block_manager::GridBlockManager; use crate::services::block_manager::GridBlockManager;
@ -188,7 +188,7 @@ impl GridRevisionEditor {
pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> { 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 _ = 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 notified_changeset = GridFieldChangesetPB::delete(&self.grid_id, vec![field_order]);
let _ = self.notify_did_update_grid(notified_changeset).await?; let _ = self.notify_did_update_grid(notified_changeset).await?;
Ok(()) Ok(())
@ -339,12 +339,12 @@ impl GridRevisionEditor {
Ok(()) Ok(())
} }
pub async fn get_cell(&self, params: &CellIdentifier) -> Option<Cell> { pub async fn get_cell(&self, params: &CellIdentifierParams) -> Option<GridCellPB> {
let cell_bytes = self.get_cell_bytes(params).await?; let cell_bytes = self.get_cell_bytes(params).await?;
Some(Cell::new(&params.field_id, cell_bytes.to_vec())) Some(GridCellPB::new(&params.field_id, cell_bytes.to_vec()))
} }
pub async fn get_cell_bytes(&self, params: &CellIdentifier) -> Option<CellBytes> { pub async fn get_cell_bytes(&self, params: &CellIdentifierParams) -> Option<CellBytes> {
let field_rev = self.get_field_rev(&params.field_id).await?; let field_rev = self.get_field_rev(&params.field_id).await?;
let row_rev = self.block_manager.get_row_rev(&params.row_id).await.ok()??; let row_rev = self.block_manager.get_row_rev(&params.row_id).await.ok()??;
@ -364,12 +364,12 @@ impl GridRevisionEditor {
} }
#[tracing::instrument(level = "trace", skip_all, err)] #[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() { if cell_changeset.content.as_ref().is_none() {
return Ok(()); return Ok(());
} }
let CellChangeset { let CellChangesetPB {
grid_id, grid_id,
row_id, row_id,
field_id, field_id,
@ -387,7 +387,7 @@ impl GridRevisionEditor {
let cell_rev = self.get_cell_rev(&row_id, &field_id).await?; let cell_rev = self.get_cell_rev(&row_id, &field_id).await?;
// Update the changeset.data property with the return value. // Update the changeset.data property with the return value.
content = Some(apply_cell_data_changeset(content.unwrap(), cell_rev, field_rev)?); content = Some(apply_cell_data_changeset(content.unwrap(), cell_rev, field_rev)?);
let cell_changeset = CellChangeset { let cell_changeset = CellChangesetPB {
grid_id, grid_id,
row_id, row_id,
field_id, field_id,
@ -425,7 +425,7 @@ impl GridRevisionEditor {
let field_orders = pad_read_guard let field_orders = pad_read_guard
.get_field_revs(None)? .get_field_revs(None)?
.iter() .iter()
.map(GridFieldPB::from) .map(GridFieldIdPB::from)
.collect(); .collect();
let mut block_orders = vec![]; let mut block_orders = vec![];
for block_rev in pad_read_guard.get_block_meta_revs() { 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)?)) .modify(|grid_pad| Ok(grid_pad.move_field(field_id, from as usize, to as usize)?))
.await?; .await?;
if let Some((index, field_rev)) = self.grid_pad.read().await.get_field_rev(field_id) { 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 insert_field = IndexFieldPB::from_field_rev(field_rev, index);
let notified_changeset = GridFieldChangesetPB { let notified_changeset = GridFieldChangesetPB {
grid_id: self.grid_id.clone(), grid_id: self.grid_id.clone(),
@ -615,7 +615,7 @@ impl GridRevisionEditor {
.get_field_rev(field_id) .get_field_rev(field_id)
.map(|(index, field)| (index, field.clone())) .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 notified_changeset = GridFieldChangesetPB::update(&self.grid_id, vec![updated_field.clone()]);
let _ = self.notify_did_update_grid(notified_changeset).await?; let _ = self.notify_did_update_grid(notified_changeset).await?;

View File

@ -2,7 +2,7 @@ use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow};
use crate::grid::block_test::util::GridRowTestBuilder; use crate::grid::block_test::util::GridRowTestBuilder;
use crate::grid::grid_editor::GridEditorTest; 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::services::field::*;
use flowy_grid_data_model::revision::{ use flowy_grid_data_model::revision::{
GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision, GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision,
@ -109,7 +109,7 @@ impl GridRowTest {
field_type, field_type,
expected, expected,
} => { } => {
let id = CellIdentifier { let id = CellIdentifierParams {
grid_id: self.grid_id.clone(), grid_id: self.grid_id.clone(),
field_id, field_id,
row_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 { match field_type {
FieldType::RichText => { FieldType::RichText => {
let cell_data = self let cell_data = self

View File

@ -1,8 +1,8 @@
use crate::grid::grid_editor::GridEditorTest; use crate::grid::grid_editor::GridEditorTest;
use flowy_grid::entities::CellChangeset; use flowy_grid::entities::CellChangesetPB;
pub enum CellScript { pub enum CellScript {
UpdateCell { changeset: CellChangeset, is_err: bool }, UpdateCell { changeset: CellChangesetPB, is_err: bool },
} }
pub struct GridCellTest { pub struct GridCellTest {

View File

@ -1,7 +1,7 @@
use crate::grid::cell_test::script::CellScript::*; use crate::grid::cell_test::script::CellScript::*;
use crate::grid::cell_test::script::GridCellTest; use crate::grid::cell_test::script::GridCellTest;
use crate::grid::field_test::util::make_date_cell_string; 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::selection_type_option::SelectOptionCellChangeset;
use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB}; use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOptionPB};
@ -36,7 +36,7 @@ async fn grid_cell_update() {
}; };
scripts.push(UpdateCell { scripts.push(UpdateCell {
changeset: CellChangeset { changeset: CellChangesetPB {
grid_id: block_id.to_string(), grid_id: block_id.to_string(),
row_id: row_rev.id.clone(), row_id: row_rev.id.clone(),
field_id: field_rev.id.clone(), field_id: field_rev.id.clone(),

View File

@ -17,7 +17,7 @@ pub fn create_text_field(grid_id: &str) -> (InsertFieldParams, FieldRevision) {
.protobuf_bytes() .protobuf_bytes()
.to_vec(); .to_vec();
let field = FieldPB { let field = GridFieldPB {
id: field_rev.id, id: field_rev.id,
name: field_rev.name, name: field_rev.name,
desc: field_rev.desc, desc: field_rev.desc,
@ -50,7 +50,7 @@ pub fn create_single_select_field(grid_id: &str) -> (InsertFieldParams, FieldRev
.protobuf_bytes() .protobuf_bytes()
.to_vec(); .to_vec();
let field = FieldPB { let field = GridFieldPB {
id: field_rev.id, id: field_rev.id,
name: field_rev.name, name: field_rev.name,
desc: field_rev.desc, desc: field_rev.desc,