fix: changing field type from text to checkbox causes exception #5360 (#5366)

This commit is contained in:
Mohammad Zolfaghari 2024-05-20 12:49:58 +03:30 committed by GitHub
parent 0c0bd54f52
commit 9b7ee4b978
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 87 additions and 20 deletions

View File

@ -0,0 +1,37 @@
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../../shared/database_test_op.dart';
import '../../shared/util.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('board field test', () {
testWidgets('change field type whithin card #5360', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
await tester.createNewPageWithNameUnderParent(layout: ViewLayoutPB.Board);
const name = 'Card 1';
final card1 = find.text(name);
await tester.tapButton(card1);
const fieldName = "test change field";
await tester.createField(
FieldType.RichText,
fieldName,
layout: ViewLayoutPB.Board,
);
await tester.tapButton(card1);
await tester.changeFieldTypeOfFieldWithName(
fieldName,
FieldType.Checkbox,
layout: ViewLayoutPB.Board,
);
await tester.hoverOnWidget(find.text('Card 2'));
});
});
}

View File

@ -661,10 +661,13 @@ extension AppFlowyDatabaseTest on WidgetTester {
Future<void> changeFieldTypeOfFieldWithName(
String name,
FieldType type,
) async {
FieldType type, {
ViewLayoutPB layout = ViewLayoutPB.Grid,
}) async {
await tapGridFieldWithName(name);
await tapEditFieldButton();
if (layout == ViewLayoutPB.Grid) {
await tapEditFieldButton();
}
await tapSwitchFieldTypeButton();
await selectFieldType(type);
@ -881,8 +884,14 @@ extension AppFlowyDatabaseTest on WidgetTester {
await tapButtonWithName(LocaleKeys.grid_row_delete.tr());
}
Future<void> createField(FieldType fieldType, String name) async {
await scrollToRight(find.byType(GridPage));
Future<void> createField(
FieldType fieldType,
String name, {
ViewLayoutPB layout = ViewLayoutPB.Grid,
}) async {
if (layout == ViewLayoutPB.Grid) {
await scrollToRight(find.byType(GridPage));
}
await tapNewPropertyButton();
await renameField(name);
await tapSwitchFieldTypeButton();

View File

@ -1,5 +1,5 @@
import 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
import 'package:appflowy/plugins/database/widgets/card/card.dart';
import 'package:appflowy/plugins/database/widgets/card/card_bloc.dart';
import 'package:appflowy/plugins/database/widgets/cell/card_cell_builder.dart';
import 'package:appflowy/plugins/database/widgets/cell/card_cell_style_maps/mobile_board_card_cell_style.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
@ -16,7 +16,7 @@ class MobileCardContent extends StatelessWidget {
final RowMetaPB rowMeta;
final CardCellBuilder cellBuilder;
final List<CellContext> cells;
final List<CellMeta> cells;
final RowCardStyleConfiguration styleConfiguration;
@override
@ -26,9 +26,9 @@ class MobileCardContent extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
children: cells.map(
(cellContext) {
(cellMeta) {
return cellBuilder.build(
cellContext: cellContext,
cellContext: cellMeta.cellContext(),
styleMap: mobileBoardCardCellStyleMap(context),
hasNotes: !rowMeta.isDocumentEmpty,
);

View File

@ -1,6 +1,5 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/mobile/presentation/database/card/card.dart';
import 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
import 'package:appflowy/plugins/database/application/field/field_controller.dart';
import 'package:appflowy/plugins/database/application/row/row_cache.dart';
import 'package:appflowy/plugins/database/grid/presentation/widgets/row/action.dart';
@ -186,7 +185,7 @@ class _CardContent extends StatelessWidget {
final RowMetaPB rowMeta;
final CardCellBuilder cellBuilder;
final List<CellContext> cells;
final List<CellMeta> cells;
final RowCardStyleConfiguration styleConfiguration;
@override
@ -210,9 +209,9 @@ class _CardContent extends StatelessWidget {
List<Widget> _makeCells(
BuildContext context,
RowMetaPB rowMeta,
List<CellContext> cells,
List<CellMeta> cells,
) {
return cells.mapIndexed((int index, CellContext cellContext) {
return cells.mapIndexed((int index, CellMeta cellMeta) {
EditableCardNotifier? cellNotifier;
if (index == 0) {
@ -225,7 +224,7 @@ class _CardContent extends StatelessWidget {
}
return cellBuilder.build(
cellContext: cellContext,
cellContext: cellMeta.cellContext(),
cellNotifier: cellNotifier,
styleMap: styleConfiguration.cellStyleMap,
hasNotes: !rowMeta.isDocumentEmpty,

View File

@ -1,5 +1,7 @@
import 'dart:async';
import 'package:appflowy/plugins/database/application/row/row_service.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:flutter/foundation.dart';
import 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
@ -7,7 +9,6 @@ import 'package:appflowy/plugins/database/application/field/field_controller.dar
import 'package:appflowy/plugins/database/application/row/row_cache.dart';
import 'package:appflowy/plugins/database/domain/row_listener.dart';
import 'package:appflowy/plugins/database/widgets/setting/field_visibility_extension.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/row_entities.pb.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -104,7 +105,7 @@ class CardBloc extends Bloc<CardEvent, CardState> {
}
}
List<CellContext> _makeCells(
List<CellMeta> _makeCells(
FieldController fieldController,
String? groupFieldId,
List<CellContext> cellContexts,
@ -116,7 +117,15 @@ List<CellContext> _makeCells(
!(fieldInfo.visibility?.isVisibleState() ?? false) ||
(groupFieldId != null && cellContext.fieldId == groupFieldId);
});
return cellContexts.toList();
return cellContexts
.map(
(cellCtx) => CellMeta(
fieldId: cellCtx.fieldId,
rowId: cellCtx.rowId,
fieldType: fieldController.getField(cellCtx.fieldId)!.fieldType,
),
)
.toList();
}
@freezed
@ -124,17 +133,30 @@ class CardEvent with _$CardEvent {
const factory CardEvent.initial() = _InitialRow;
const factory CardEvent.setIsEditing(bool isEditing) = _IsEditing;
const factory CardEvent.didReceiveCells(
List<CellContext> cells,
List<CellMeta> cells,
ChangedReason reason,
) = _DidReceiveCells;
const factory CardEvent.didUpdateRowMeta(RowMetaPB rowMeta) =
_DidUpdateRowMeta;
}
@freezed
class CellMeta with _$CellMeta {
const CellMeta._();
const factory CellMeta({
required String fieldId,
required RowId rowId,
required FieldType fieldType,
}) = _DatabaseCellMeta;
CellContext cellContext() => CellContext(fieldId: fieldId, rowId: rowId);
}
@freezed
class CardState with _$CardState {
const factory CardState({
required List<CellContext> cells,
required List<CellMeta> cells,
required RowMetaPB rowMeta,
required bool isEditing,
ChangedReason? changeReason,
@ -142,7 +164,7 @@ class CardState with _$CardState {
factory CardState.initial(
RowMetaPB rowMeta,
List<CellContext> cells,
List<CellMeta> cells,
bool isEditing,
) =>
CardState(