Skip to content

Commit 0695195

Browse files
authored
Fix/grid group (#1787)
* ci: config rust log * chore: rename flowy-sdk to appflowy-core * fix: create group after editing the url * fix: start listen on new group * chore: add tests * refactor: mock data * ci: update command
1 parent d095749 commit 0695195

File tree

73 files changed

+1570
-1901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1570
-1901
lines changed

.github/workflows/rust_ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
- name: Build FlowySDK
6060
working-directory: frontend
6161
run: |
62-
cargo make --profile development-linux-x86_64 appflowy-sdk-dev
62+
cargo make --profile development-linux-x86_64 appflowy-core-dev
6363
6464
- name: rustfmt rust-lib
6565
run: cargo fmt --all -- --check

frontend/.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"type": "dart",
2424
"preLaunchTask": "AF: build_flowy_sdk",
2525
"env": {
26-
"RUST_LOG": "info"
26+
"RUST_LOG": "debug"
2727
},
2828
"cwd": "${workspaceRoot}/app_flowy"
2929
},

frontend/.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
{
4949
"label": "AF: build_flowy_sdk_for_android",
5050
"type": "shell",
51-
"command": "cargo make --profile development-android appflowy-sdk-dev-android",
51+
"command": "cargo make --profile development-android appflowy-core-dev-android",
5252
"group": "build",
5353
"options": {
5454
"cwd": "${workspaceFolder}"

frontend/Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on_error_task = "catch"
1818
run_task = { name = ["restore-crate-type"] }
1919

2020
[env]
21-
RUST_LOG = "info"
21+
RUST_LOG = "debug"
2222
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
2323
CARGO_MAKE_CRATE_FS_NAME = "dart_ffi"
2424
CARGO_MAKE_CRATE_NAME = "dart-ffi"

frontend/app_flowy/lib/plugins/board/application/board_bloc.dart

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -186,43 +186,20 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
186186
return super.close();
187187
}
188188

189-
void initializeGroups(List<GroupPB> groupsData) {
189+
void initializeGroups(List<GroupPB> groups) {
190190
for (var controller in groupControllers.values) {
191191
controller.dispose();
192192
}
193193
groupControllers.clear();
194194
boardController.clear();
195195

196-
//
197-
List<AppFlowyGroupData> groups = groupsData
196+
boardController.addGroups(groups
198197
.where((group) => fieldController.getField(group.fieldId) != null)
199-
.map((group) {
200-
return AppFlowyGroupData(
201-
id: group.groupId,
202-
name: group.desc,
203-
items: _buildGroupItems(group),
204-
customData: GroupData(
205-
group: group,
206-
fieldInfo: fieldController.getField(group.fieldId)!,
207-
),
208-
);
209-
}).toList();
210-
boardController.addGroups(groups);
211-
212-
for (final group in groupsData) {
213-
final delegate = GroupControllerDelegateImpl(
214-
controller: boardController,
215-
fieldController: fieldController,
216-
onNewColumnItem: (groupId, row, index) {
217-
add(BoardEvent.didCreateRow(group, row, index));
218-
},
219-
);
220-
final controller = GroupController(
221-
databaseId: state.databaseId,
222-
group: group,
223-
delegate: delegate,
224-
);
225-
controller.startListening();
198+
.map((group) => initializeGroupData(group))
199+
.toList());
200+
201+
for (final group in groups) {
202+
final controller = initializeGroupController(group);
226203
groupControllers[controller.group.groupId] = (controller);
227204
}
228205
}
@@ -245,11 +222,15 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
245222
},
246223
onDeletedGroup: (groupIds) {
247224
if (isClosed) return;
248-
//
225+
boardController.removeGroups(groupIds);
249226
},
250-
onInsertedGroup: (insertedGroups) {
227+
onInsertedGroup: (insertedGroup) {
251228
if (isClosed) return;
252-
//
229+
final group = insertedGroup.group;
230+
final newGroup = initializeGroupData(group);
231+
final controller = initializeGroupController(group);
232+
groupControllers[controller.group.groupId] = (controller);
233+
boardController.addGroup(newGroup);
253234
},
254235
onUpdatedGroup: (updatedGroups) {
255236
if (isClosed) return;
@@ -294,6 +275,35 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
294275
),
295276
);
296277
}
278+
279+
GroupController initializeGroupController(GroupPB group) {
280+
final delegate = GroupControllerDelegateImpl(
281+
controller: boardController,
282+
fieldController: fieldController,
283+
onNewColumnItem: (groupId, row, index) {
284+
add(BoardEvent.didCreateRow(group, row, index));
285+
},
286+
);
287+
final controller = GroupController(
288+
databaseId: state.databaseId,
289+
group: group,
290+
delegate: delegate,
291+
);
292+
controller.startListening();
293+
return controller;
294+
}
295+
296+
AppFlowyGroupData initializeGroupData(GroupPB group) {
297+
return AppFlowyGroupData(
298+
id: group.groupId,
299+
name: group.desc,
300+
items: _buildGroupItems(group),
301+
customData: GroupData(
302+
group: group,
303+
fieldInfo: fieldController.getField(group.fieldId)!,
304+
),
305+
);
306+
}
297307
}
298308

299309
@freezed

frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef OnGridChanged = void Function(DatabasePB);
1717
typedef DidLoadGroups = void Function(List<GroupPB>);
1818
typedef OnUpdatedGroup = void Function(List<GroupPB>);
1919
typedef OnDeletedGroup = void Function(List<String>);
20-
typedef OnInsertedGroup = void Function(List<InsertedGroupPB>);
20+
typedef OnInsertedGroup = void Function(InsertedGroupPB);
2121
typedef OnResetGroups = void Function(List<GroupPB>);
2222

2323
typedef OnRowsChanged = void Function(
@@ -90,8 +90,8 @@ class BoardDataController {
9090
onDeletedGroup.call(changeset.deletedGroups);
9191
}
9292

93-
if (changeset.insertedGroups.isNotEmpty) {
94-
onInsertedGroup.call(changeset.insertedGroups);
93+
for (final insertedGroup in changeset.insertedGroups) {
94+
onInsertedGroup.call(insertedGroup);
9595
}
9696
},
9797
(e) => _onError?.call(e),

frontend/app_flowy/lib/plugins/board/application/board_listener.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BoardListener {
4646
case DatabaseNotification.DidGroupByNewField:
4747
result.fold(
4848
(payload) => _groupByNewFieldNotifier?.value =
49-
left(GroupViewChangesetPB.fromBuffer(payload).newGroups),
49+
left(GroupViewChangesetPB.fromBuffer(payload).initialGroups),
5050
(error) => _groupByNewFieldNotifier?.value = right(error),
5151
);
5252
break;

frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class GridCellController<T, D> extends Equatable {
270270
/// You can set [deduplicate] to true (default is false) to reduce the save operation.
271271
/// It's useful when you call this method when user editing the [TextField].
272272
/// The default debounce interval is 300 milliseconds.
273-
void saveCellData(
273+
Future<void> saveCellData(
274274
D data, {
275275
bool deduplicate = false,
276276
void Function(Option<FlowyError>)? onFinish,

frontend/app_flowy/lib/plugins/grid/application/cell/url_cell_editor_bloc.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ class URLCellEditorBloc extends Bloc<URLCellEditorEvent, URLCellEditorState> {
1414
}) : super(URLCellEditorState.initial(cellController)) {
1515
on<URLCellEditorEvent>(
1616
(event, emit) async {
17-
event.when(
17+
await event.when(
1818
initial: () {
1919
_startListening();
2020
},
21-
updateText: (text) {
22-
cellController.saveCellData(text, deduplicate: true);
23-
emit(state.copyWith(content: text));
21+
updateText: (text) async {
22+
await cellController.saveCellData(text);
23+
emit(state.copyWith(
24+
content: text,
25+
isFinishEditing: true,
26+
));
2427
},
2528
didReceiveCellUpdate: (cellData) {
2629
emit(state.copyWith(content: cellData?.content ?? ""));
@@ -63,12 +66,14 @@ class URLCellEditorEvent with _$URLCellEditorEvent {
6366
class URLCellEditorState with _$URLCellEditorState {
6467
const factory URLCellEditorState({
6568
required String content,
69+
required bool isFinishEditing,
6670
}) = _URLCellEditorState;
6771

6872
factory URLCellEditorState.initial(GridURLCellController context) {
6973
final cellData = context.getCellData();
7074
return URLCellEditorState(
7175
content: cellData?.content ?? "",
76+
isFinishEditing: true,
7277
);
7378
}
7479
}

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/url_cell/cell_editor.dart

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import 'dart:async';
66
import 'package:flutter_bloc/flutter_bloc.dart';
77

88
class URLCellEditor extends StatefulWidget {
9+
final VoidCallback onExit;
910
final GridURLCellController cellController;
10-
const URLCellEditor({required this.cellController, Key? key})
11-
: super(key: key);
11+
const URLCellEditor({
12+
required this.cellController,
13+
required this.onExit,
14+
Key? key,
15+
}) : super(key: key);
1216

1317
@override
1418
State<URLCellEditor> createState() => _URLCellEditorState();
@@ -36,12 +40,17 @@ class _URLCellEditorState extends State<URLCellEditor> {
3640
if (_controller.text != state.content) {
3741
_controller.text = state.content;
3842
}
43+
44+
if (state.isFinishEditing) {
45+
widget.onExit();
46+
}
3947
},
4048
child: TextField(
4149
autofocus: true,
4250
controller: _controller,
43-
onChanged: (value) => focusChanged(),
44-
maxLines: null,
51+
onSubmitted: (value) => focusChanged(),
52+
onEditingComplete: () => focusChanged(),
53+
maxLines: 1,
4554
style: Theme.of(context).textTheme.bodyMedium,
4655
decoration: const InputDecoration(
4756
contentPadding: EdgeInsets.zero,
@@ -57,11 +66,10 @@ class _URLCellEditorState extends State<URLCellEditor> {
5766
@override
5867
Future<void> dispose() async {
5968
_cellBloc.close();
60-
6169
super.dispose();
6270
}
6371

64-
Future<void> focusChanged() async {
72+
void focusChanged() {
6573
if (mounted) {
6674
if (_cellBloc.isClosed == false &&
6775
_controller.text != _cellBloc.state.content) {
@@ -72,9 +80,13 @@ class _URLCellEditorState extends State<URLCellEditor> {
7280
}
7381

7482
class URLEditorPopover extends StatelessWidget {
83+
final VoidCallback onExit;
7584
final GridURLCellController cellController;
76-
const URLEditorPopover({required this.cellController, Key? key})
77-
: super(key: key);
85+
const URLEditorPopover({
86+
required this.cellController,
87+
required this.onExit,
88+
Key? key,
89+
}) : super(key: key);
7890

7991
@override
8092
Widget build(BuildContext context) {
@@ -84,6 +96,7 @@ class URLEditorPopover extends StatelessWidget {
8496
padding: const EdgeInsets.all(6),
8597
child: URLCellEditor(
8698
cellController: cellController,
99+
onExit: onExit,
87100
),
88101
),
89102
);

0 commit comments

Comments
 (0)