chore: rename some pb structs

This commit is contained in:
appflowy
2022-11-14 09:59:23 +08:00
parent a0a16cc493
commit 6aba344583
24 changed files with 162 additions and 171 deletions

View File

@ -234,7 +234,7 @@ class IGridCellController<T, D> extends Equatable {
return data;
}
/// Return the FieldTypeOptionDataPB that can be parsed into corresponding class using the [parser].
/// Return the TypeOptionPB that can be parsed into corresponding class using the [parser].
/// [PD] is the type that the parser return.
Future<Either<PD, FlowyError>>
getFieldTypeOption<PD, P extends TypeOptionDataParser>(P parser) {
@ -329,7 +329,7 @@ class GridCellFieldNotifierImpl extends IGridCellFieldNotifier {
@override
void onCellFieldChanged(void Function(FieldPB p1) callback) {
_onChangesetFn = (FieldChangesetPB changeset) {
_onChangesetFn = (GridFieldChangesetPB changeset) {
for (final updatedField in changeset.updatedFields) {
callback(updatedField);
}

View File

@ -25,7 +25,7 @@ class GridCellDataLoader<T> {
final fut = service.getCell(cellId: cellId);
return fut.then(
(result) => result.fold(
(GridCellPB cell) {
(CellPB cell) {
try {
return parser.parserData(cell.data);
} catch (e, s) {

View File

@ -29,10 +29,12 @@ class CellDataPersistence implements IGridCellDataPersistence<String> {
@freezed
class CalendarData with _$CalendarData {
const factory CalendarData({required DateTime date, String? time}) = _CalendarData;
const factory CalendarData({required DateTime date, String? time}) =
_CalendarData;
}
class DateCellDataPersistence implements IGridCellDataPersistence<CalendarData> {
class DateCellDataPersistence
implements IGridCellDataPersistence<CalendarData> {
final GridCellIdentifier cellId;
DateCellDataPersistence({
required this.cellId,
@ -40,7 +42,8 @@ class DateCellDataPersistence implements IGridCellDataPersistence<CalendarData>
@override
Future<Option<FlowyError>> save(CalendarData data) {
var payload = DateChangesetPayloadPB.create()..cellIdentifier = _makeCellIdPayload(cellId);
var payload = DateChangesetPB.create()
..cellIdentifier = _makeCellIdPayload(cellId);
final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString();
payload.date = date;
@ -58,8 +61,8 @@ class DateCellDataPersistence implements IGridCellDataPersistence<CalendarData>
}
}
GridCellIdPB _makeCellIdPayload(GridCellIdentifier cellId) {
return GridCellIdPB.create()
CellPathPB _makeCellIdPayload(GridCellIdentifier cellId) {
return CellPathPB.create()
..gridId = cellId.gridId
..fieldId = cellId.fieldId
..rowId = cellId.rowId;

View File

@ -42,10 +42,10 @@ class CellService {
return GridEventUpdateCell(payload).send();
}
Future<Either<GridCellPB, FlowyError>> getCell({
Future<Either<CellPB, FlowyError>> getCell({
required GridCellIdentifier cellId,
}) {
final payload = GridCellIdPB.create()
final payload = CellPathPB.create()
..gridId = cellId.gridId
..fieldId = cellId.fieldId
..rowId = cellId.rowId;

View File

@ -21,11 +21,11 @@ class SelectOptionService {
(result) {
return result.fold(
(option) {
final cellIdentifier = GridCellIdPB.create()
final cellIdentifier = CellPathPB.create()
..gridId = gridId
..fieldId = fieldId
..rowId = rowId;
final payload = SelectOptionChangesetPayloadPB.create()
final payload = SelectOptionChangesetPB.create()
..insertOptions.add(option)
..cellIdentifier = cellIdentifier;
return GridEventUpdateSelectOption(payload).send();
@ -39,7 +39,7 @@ class SelectOptionService {
Future<Either<Unit, FlowyError>> update({
required SelectOptionPB option,
}) {
final payload = SelectOptionChangesetPayloadPB.create()
final payload = SelectOptionChangesetPB.create()
..updateOptions.add(option)
..cellIdentifier = _cellIdentifier();
return GridEventUpdateSelectOption(payload).send();
@ -47,7 +47,7 @@ class SelectOptionService {
Future<Either<Unit, FlowyError>> delete(
{required Iterable<SelectOptionPB> options}) {
final payload = SelectOptionChangesetPayloadPB.create()
final payload = SelectOptionChangesetPB.create()
..deleteOptions.addAll(options)
..cellIdentifier = _cellIdentifier();
@ -55,7 +55,7 @@ class SelectOptionService {
}
Future<Either<SelectOptionCellDataPB, FlowyError>> getOptionContext() {
final payload = GridCellIdPB.create()
final payload = CellPathPB.create()
..gridId = gridId
..fieldId = fieldId
..rowId = rowId;
@ -65,7 +65,7 @@ class SelectOptionService {
Future<Either<void, FlowyError>> select(
{required Iterable<String> optionIds}) {
final payload = SelectOptionCellChangesetPayloadPB.create()
final payload = SelectOptionCellChangesetPB.create()
..cellIdentifier = _cellIdentifier()
..insertOptionIds.addAll(optionIds);
return GridEventUpdateSelectOptionCell(payload).send();
@ -73,14 +73,14 @@ class SelectOptionService {
Future<Either<void, FlowyError>> unSelect(
{required Iterable<String> optionIds}) {
final payload = SelectOptionCellChangesetPayloadPB.create()
final payload = SelectOptionCellChangesetPB.create()
..cellIdentifier = _cellIdentifier()
..deleteOptionIds.addAll(optionIds);
return GridEventUpdateSelectOptionCell(payload).send();
}
GridCellIdPB _cellIdentifier() {
return GridCellIdPB.create()
CellPathPB _cellIdentifier() {
return CellPathPB.create()
..gridId = gridId
..fieldId = fieldId
..rowId = rowId;

View File

@ -18,7 +18,7 @@ class FieldActionSheetBloc
),
super(
FieldActionSheetState.initial(
FieldTypeOptionDataPB.create()..field_2 = fieldCellContext.field,
TypeOptionPB.create()..field_2 = fieldCellContext.field,
),
) {
on<FieldActionSheetEvent>(
@ -85,12 +85,12 @@ class FieldActionSheetEvent with _$FieldActionSheetEvent {
@freezed
class FieldActionSheetState with _$FieldActionSheetState {
const factory FieldActionSheetState({
required FieldTypeOptionDataPB fieldTypeOptionData,
required TypeOptionPB fieldTypeOptionData,
required String errorText,
required String fieldName,
}) = _FieldActionSheetState;
factory FieldActionSheetState.initial(FieldTypeOptionDataPB data) =>
factory FieldActionSheetState.initial(TypeOptionPB data) =>
FieldActionSheetState(
fieldTypeOptionData: data,
errorText: '',

View File

@ -27,7 +27,7 @@ class _GridFieldNotifier extends ChangeNotifier {
List<GridFieldContext> get fieldContexts => _fieldContexts;
}
typedef OnChangeset = void Function(FieldChangesetPB);
typedef OnChangeset = void Function(GridFieldChangesetPB);
typedef OnReceiveFields = void Function(List<GridFieldContext>);
class GridFieldController {
@ -247,7 +247,7 @@ class GridRowFieldNotifierImpl extends IGridRowFieldNotifier {
@override
void onRowFieldChanged(void Function(FieldPB) callback) {
_onChangesetFn = (FieldChangesetPB changeset) {
_onChangesetFn = (GridFieldChangesetPB changeset) {
for (final updatedField in changeset.updatedFields) {
callback(updatedField);
}

View File

@ -36,7 +36,7 @@ class FieldService {
double? width,
List<int>? typeOptionData,
}) {
var payload = FieldChangesetPayloadPB.create()
var payload = FieldChangesetPB.create()
..gridId = gridId
..fieldId = fieldId;
@ -72,7 +72,7 @@ class FieldService {
required String fieldId,
required List<int> typeOptionData,
}) {
var payload = UpdateFieldTypeOptionPayloadPB.create()
var payload = TypeOptionChangesetPB.create()
..gridId = gridId
..fieldId = fieldId
..typeOptionData = typeOptionData;
@ -96,10 +96,10 @@ class FieldService {
return GridEventDuplicateField(payload).send();
}
Future<Either<FieldTypeOptionDataPB, FlowyError>> getFieldTypeOptionData({
Future<Either<TypeOptionPB, FlowyError>> getFieldTypeOptionData({
required FieldType fieldType,
}) {
final payload = FieldTypeOptionIdPB.create()
final payload = TypeOptionPathPB.create()
..gridId = gridId
..fieldId = fieldId
..fieldType = fieldType;

View File

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

View File

@ -143,11 +143,11 @@ abstract class TypeOptionFieldDelegate {
abstract class IFieldTypeOptionLoader {
String get gridId;
Future<Either<FieldTypeOptionDataPB, FlowyError>> load();
Future<Either<TypeOptionPB, FlowyError>> load();
Future<Either<Unit, FlowyError>> switchToField(
String fieldId, FieldType fieldType) {
final payload = EditFieldPayloadPB.create()
final payload = EditFieldChangesetPB.create()
..gridId = gridId
..fieldId = fieldId
..fieldType = fieldType;
@ -158,7 +158,7 @@ abstract class IFieldTypeOptionLoader {
/// Uses when creating a new field
class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
FieldTypeOptionDataPB? fieldTypeOption;
TypeOptionPB? fieldTypeOption;
@override
final String gridId;
@ -169,9 +169,9 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
/// Creates the field type option if the fieldTypeOption is null.
/// Otherwise, it loads the type option data from the backend.
@override
Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
Future<Either<TypeOptionPB, FlowyError>> load() {
if (fieldTypeOption != null) {
final payload = FieldTypeOptionIdPB.create()
final payload = TypeOptionPathPB.create()
..gridId = gridId
..fieldId = fieldTypeOption!.field_2.id
..fieldType = fieldTypeOption!.field_2.fieldType;
@ -207,8 +207,8 @@ class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
});
@override
Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
final payload = FieldTypeOptionIdPB.create()
Future<Either<TypeOptionPB, FlowyError>> load() {
final payload = TypeOptionPathPB.create()
..gridId = gridId
..fieldId = field.id
..fieldType = field.fieldType;

View File

@ -12,7 +12,7 @@ import 'type_option_context.dart';
class TypeOptionDataController {
final String gridId;
final IFieldTypeOptionLoader loader;
late FieldTypeOptionDataPB _data;
late TypeOptionPB _data;
final PublishNotifier<FieldPB> _fieldNotifier = PublishNotifier();
/// Returns a [TypeOptionDataController] used to modify the specified
@ -27,7 +27,7 @@ class TypeOptionDataController {
GridFieldContext? fieldContext,
}) {
if (fieldContext != null) {
_data = FieldTypeOptionDataPB.create()
_data = TypeOptionPB.create()
..gridId = gridId
..field_2 = fieldContext.field;
}

View File

@ -44,7 +44,7 @@ class GridFFIService {
Future<Either<RepeatedFieldPB, FlowyError>> getFields(
{required List<FieldIdPB> fieldIds}) {
final payload = QueryFieldPayloadPB.create()
final payload = GetFieldPayloadPB.create()
..gridId = gridId
..fieldIds = RepeatedFieldIdPB(items: fieldIds);
return GridEventGetFields(payload).send();

View File

@ -15,7 +15,7 @@ export 'field/type_option/date_bloc.dart';
export 'field/type_option/number_bloc.dart';
export 'field/type_option/single_select_type_option.dart';
// GridCellPB
// CellPB
export 'cell/text_cell_bloc.dart';
export 'cell/number_cell_bloc.dart';
export 'cell/select_option_cell_bloc.dart';

View File

@ -23,7 +23,7 @@ class SettingFFIService {
final insertGroupPayload = InsertGroupPayloadPB.create()
..fieldId = fieldId
..fieldType = fieldType;
final payload = GridSettingChangesetPayloadPB.create()
final payload = GridSettingChangesetPB.create()
..gridId = viewId
..insertGroup = insertGroupPayload;

View File

@ -17,8 +17,8 @@ import 'field_type_list.dart';
import 'type_option/builder.dart';
typedef UpdateFieldCallback = void Function(FieldPB, Uint8List);
typedef SwitchToFieldCallback
= Future<Either<FieldTypeOptionDataPB, FlowyError>> Function(
typedef SwitchToFieldCallback = Future<Either<TypeOptionPB, FlowyError>>
Function(
String fieldId,
FieldType fieldType,
);