Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: add card at the beginning (#3835)

Mathias Mogensend358e18f332f
diff --git a/frontend/appflowy_flutter/integration_test/board/board_add_row_test.dart b/frontend/appflowy_flutter/integration_test/board/board_add_row_test.dart
new file mode 100644
index 0000000000..0ef813bec6
--- /dev/null
+++ b/frontend/appflowy_flutter/integration_test/board/board_add_row_test.dart
@@ -0,0 +1,101 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
+import 'package:appflowy_board/appflowy_board.dart';
+import 'package:flowy_infra_ui/style_widget/text.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:integration_test/integration_test.dart';
+
+import '../util/util.dart';
+
+const defaultFirstCardName = 'Card 1';
+const defaultLastCardName = 'Card 3';
+
+void main() {
+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();
+
+ group('board add row test', () {
+ testWidgets('Add card from header', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapGoButton();
+
+ await tester.createNewPageWithName(layout: ViewLayoutPB.Board);
+
+ final findFirstCard = find.descendant(
+ of: find.byType(AppFlowyGroupCard),
+ matching: find.byType(FlowyText),
+ );
+
+ FlowyText firstCardText = tester.firstWidget(findFirstCard);
+ expect(firstCardText.text, defaultFirstCardName);
+
+ await tester.tap(
+ find
+ .descendant(
+ of: find.byType(AppFlowyGroupHeader),
+ matching: find.byType(FlowySvg),
+ )
+ .first,
+ );
+ await tester.pumpAndSettle();
+
+ const newCardName = 'Card 4';
+ await tester.enterText(
+ find.descendant(
+ of: find.byType(IntrinsicHeight),
+ matching: find.byType(TextField),
+ ),
+ newCardName,
+ );
+ await tester.pumpAndSettle();
+
+ await tester.tap(find.byType(AppFlowyBoard));
+ await tester.pumpAndSettle();
+
+ firstCardText = tester.firstWidget(findFirstCard);
+ expect(firstCardText.text, newCardName);
+ });
+
+ testWidgets('Add card from footer', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapGoButton();
+
+ await tester.createNewPageWithName(layout: ViewLayoutPB.Board);
+
+ final findLastCard = find.descendant(
+ of: find.byType(AppFlowyGroupCard),
+ matching: find.byType(FlowyText),
+ );
+
+ FlowyText? lastCardText =
+ tester.widgetList(findLastCard).last as FlowyText;
+ expect(lastCardText.text, defaultLastCardName);
+
+ await tester.tap(
+ find
+ .descendant(
+ of: find.byType(AppFlowyGroupFooter),
+ matching: find.byType(FlowySvg),
+ )
+ .first,
+ );
+ await tester.pumpAndSettle();
+
+ const newCardName = 'Card 4';
+ await tester.enterText(
+ find.descendant(
+ of: find.byType(IntrinsicHeight),
+ matching: find.byType(TextField),
+ ),
+ newCardName,
+ );
+ await tester.pumpAndSettle();
+
+ await tester.tap(find.byType(AppFlowyBoard));
+ await tester.pumpAndSettle();
+
+ lastCardText = tester.widgetList(findLastCard).last as FlowyText;
+ expect(lastCardText.text, newCardName);
+ });
+ });
+}
diff --git a/frontend/appflowy_flutter/integration_test/board/board_test_runner.dart b/frontend/appflowy_flutter/integration_test/board/board_test_runner.dart
index ebed667fb2..d95c1cbdd7 100644
--- a/frontend/appflowy_flutter/integration_test/board/board_test_runner.dart
+++ b/frontend/appflowy_flutter/integration_test/board/board_test_runner.dart
@@ -1,10 +1,12 @@
import 'package:integration_test/integration_test.dart';
import 'board_row_test.dart' as board_row_test;
+import 'board_add_row_test.dart' as board_add_row_test;
void startTesting() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
// Board integration tests
board_row_test.main();
+ board_add_row_test.main();
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart
index 0640c1fc6f..8cf1d7d4c1 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart
@@ -177,6 +177,7 @@ class DatabaseController {
Future<Either<RowMetaPB, FlowyError>> createRow({
RowId? startRowId,
String? groupId,
+ bool fromBeginning = false,
void Function(RowDataBuilder builder)? withCells,
}) {
Map<String, String>? cellDataByFieldId;
@@ -191,6 +192,7 @@ class DatabaseController {
startRowId: startRowId,
groupId: groupId,
cellDataByFieldId: cellDataByFieldId,
+ fromBeginning: fromBeginning,
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart
index 4cfeff8075..bdada95d69 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart
@@ -35,9 +35,13 @@ class DatabaseViewBackendService {
RowId? startRowId,
String? groupId,
Map<String, String>? cellDataByFieldId,
+ bool fromBeginning = false,
}) {
final payload = CreateRowPayloadPB.create()..viewId = viewId;
- payload.startRowId = startRowId ?? "";
+
+ if (!fromBeginning || startRowId != null) {
+ payload.startRowId = startRowId ?? "";
+ }
if (groupId != null) {
payload.groupId = groupId;
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart
index 517700b8a2..8c5d99c126 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart
@@ -90,7 +90,11 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
);
},
createHeaderRow: (String groupId) async {
- final result = await databaseController.createRow(groupId: groupId);
+ final result = await databaseController.createRow(
+ groupId: groupId,
+ fromBeginning: true,
+ );
+
result.fold(
(_) {},
(err) => Log.error(err),