Skip to content

Commit 757009a

Browse files
authored
chore: revert reorder rows in grid (#2533) (#2669)
This reverts commit f8f0599.
1 parent e8665dc commit 757009a

File tree

16 files changed

+196
-315
lines changed

16 files changed

+196
-315
lines changed

frontend/appflowy_flutter/assets/translations/en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
"openAsPage": "Open as a Page",
110110
"addNewRow": "Add a new row",
111111
"openMenu": "Click to open menu",
112-
"dragRow": "Long press to reorder the row",
113112
"viewDataBase": "View database",
114113
"referencePage": "This {name} is referenced"
115114
},

frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,18 @@ class DatabaseController {
175175
);
176176
}
177177

178-
Future<Either<Unit, FlowyError>> moveGroupRow({
178+
Future<Either<Unit, FlowyError>> moveRow({
179179
required RowPB fromRow,
180180
required String groupId,
181181
RowPB? toRow,
182182
}) {
183-
return _databaseViewBackendSvc.moveGroupRow(
183+
return _databaseViewBackendSvc.moveRow(
184184
fromRowId: fromRow.id,
185185
toGroupId: groupId,
186186
toRowId: toRow?.id,
187187
);
188188
}
189189

190-
Future<Either<Unit, FlowyError>> moveRow({
191-
required RowPB fromRow,
192-
required RowPB toRow,
193-
}) {
194-
return _databaseViewBackendSvc.moveRow(
195-
fromRowId: fromRow.id,
196-
toRowId: toRow.id,
197-
);
198-
}
199-
200190
Future<Either<Unit, FlowyError>> moveGroup({
201191
required String fromGroupId,
202192
required String toGroupId,

frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DatabaseViewBackendService {
4444
return DatabaseEventCreateRow(payload).send();
4545
}
4646

47-
Future<Either<Unit, FlowyError>> moveGroupRow({
47+
Future<Either<Unit, FlowyError>> moveRow({
4848
required String fromRowId,
4949
required String toGroupId,
5050
String? toRowId,
@@ -61,18 +61,6 @@ class DatabaseViewBackendService {
6161
return DatabaseEventMoveGroupRow(payload).send();
6262
}
6363

64-
Future<Either<Unit, FlowyError>> moveRow({
65-
required String fromRowId,
66-
required String toRowId,
67-
}) {
68-
var payload = MoveRowPayloadPB.create()
69-
..viewId = viewId
70-
..fromRowId = fromRowId
71-
..toRowId = toRowId;
72-
73-
return DatabaseEventMoveRow(payload).send();
74-
}
75-
7664
Future<Either<Unit, FlowyError>> moveGroup({
7765
required String fromGroupId,
7866
required String toGroupId,

frontend/appflowy_flutter/lib/plugins/database_view/application/row/row_cache.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class RowCacheDelegate {
2929
class RowCache {
3030
final String viewId;
3131

32-
/// _rows contains the current block's rows
32+
/// _rows containers the current block's rows
3333
/// Use List to reverse the order of the GridRow.
3434
final RowList _rowList = RowList();
3535

frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
5353
final fromRow = groupControllers[groupId]?.rowAtIndex(fromIndex);
5454
final toRow = groupControllers[groupId]?.rowAtIndex(toIndex);
5555
if (fromRow != null) {
56-
_databaseController.moveGroupRow(
56+
_databaseController.moveRow(
5757
fromRow: fromRow,
5858
toRow: toRow,
5959
groupId: groupId,
@@ -69,7 +69,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
6969
final fromRow = groupControllers[fromGroupId]?.rowAtIndex(fromIndex);
7070
final toRow = groupControllers[toGroupId]?.rowAtIndex(toIndex);
7171
if (fromRow != null) {
72-
_databaseController.moveGroupRow(
72+
_databaseController.moveRow(
7373
fromRow: fromRow,
7474
toRow: toRow,
7575
groupId: toGroupId,

frontend/appflowy_flutter/lib/plugins/database_view/grid/application/grid_bloc.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ class GridBloc extends Bloc<GridEvent, GridState> {
3535
);
3636
await rowService.deleteRow(rowInfo.rowPB.id);
3737
},
38-
moveRow: (int from, int to) {
39-
final List<RowInfo> rows = [...state.rowInfos];
40-
41-
final fromRow = rows[from].rowPB;
42-
final toRow = rows[to].rowPB;
43-
44-
rows.insert(to, rows.removeAt(from));
45-
emit(state.copyWith(rowInfos: rows));
46-
47-
databaseController.moveRow(fromRow: fromRow, toRow: toRow);
48-
},
4938
didReceiveGridUpdate: (grid) {
5039
emit(state.copyWith(grid: Some(grid)));
5140
},
@@ -121,7 +110,6 @@ class GridEvent with _$GridEvent {
121110
const factory GridEvent.initial() = InitialGrid;
122111
const factory GridEvent.createRow() = _CreateRow;
123112
const factory GridEvent.deleteRow(RowInfo rowInfo) = _DeleteRow;
124-
const factory GridEvent.moveRow(int from, int to) = _MoveRow;
125113
const factory GridEvent.didReceiveRowUpdate(
126114
List<RowInfo> rows,
127115
RowsChangedReason listState,

frontend/appflowy_flutter/lib/plugins/database_view/grid/presentation/grid_page.dart

Lines changed: 77 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ class _GridPageState extends State<GridPage> {
9191
),
9292
);
9393
}
94+
95+
@override
96+
void dispose() {
97+
super.dispose();
98+
}
99+
100+
@override
101+
void deactivate() {
102+
super.deactivate();
103+
}
104+
105+
@override
106+
void didUpdateWidget(covariant GridPage oldWidget) {
107+
super.didUpdateWidget(oldWidget);
108+
}
94109
}
95110

96111
class FlowyGrid extends StatefulWidget {
@@ -104,12 +119,12 @@ class _FlowyGridState extends State<FlowyGrid> {
104119
final _scrollController = GridScrollController(
105120
scrollGroupController: LinkedScrollControllerGroup(),
106121
);
107-
late final ScrollController headerScrollController;
122+
late ScrollController headerScrollController;
108123

109124
@override
110125
void initState() {
111-
super.initState();
112126
headerScrollController = _scrollController.linkHorizontalController();
127+
super.initState();
113128
}
114129

115130
@override
@@ -201,78 +216,49 @@ class _GridRowsState extends State<_GridRows> {
201216

202217
@override
203218
Widget build(BuildContext context) {
204-
return Builder(
205-
builder: (context) {
206-
final filterState = context.watch<GridFilterMenuBloc>().state;
207-
final sortState = context.watch<SortMenuBloc>().state;
208-
209-
return BlocConsumer<GridBloc, GridState>(
210-
listenWhen: (previous, current) => previous.reason != current.reason,
211-
listener: (context, state) {
212-
state.reason.whenOrNull(
213-
insert: (item) {
214-
_key.currentState?.insertItem(item.index);
215-
},
216-
delete: (item) {
217-
_key.currentState?.removeItem(
218-
item.index,
219-
(context, animation) => _renderRow(
220-
context,
221-
item.rowInfo,
222-
animation: animation,
223-
),
224-
);
225-
},
219+
return BlocConsumer<GridBloc, GridState>(
220+
listenWhen: (previous, current) => previous.reason != current.reason,
221+
listener: (context, state) {
222+
state.reason.whenOrNull(
223+
insert: (item) {
224+
_key.currentState?.insertItem(item.index);
225+
},
226+
delete: (item) {
227+
_key.currentState?.removeItem(
228+
item.index,
229+
(context, animation) =>
230+
_renderRow(context, item.rowInfo, animation),
226231
);
227232
},
228-
buildWhen: (previous, current) {
229-
return current.reason.maybeWhen(
233+
reorderSingleRow: (reorderRow, rowInfo) {
234+
// _key.currentState?.removeItem(
235+
// reorderRow.oldIndex,
236+
// (context, animation) => _renderRow(context, rowInfo, animation),
237+
// );
238+
// _key.currentState?.insertItem(reorderRow.newIndex);
239+
},
240+
);
241+
},
242+
buildWhen: (previous, current) {
243+
return current.reason.whenOrNull(
230244
reorderRows: () => true,
231245
reorderSingleRow: (reorderRow, rowInfo) => true,
232-
delete: (item) => true,
233-
insert: (item) => true,
234-
orElse: () => false,
235-
);
236-
},
237-
builder: (context, state) {
238-
final rowInfos = context.watch<GridBloc>().state.rowInfos;
239-
240-
return SliverFillRemaining(
241-
child: ReorderableListView.builder(
242-
key: _key,
243-
buildDefaultDragHandles: false,
244-
proxyDecorator: (child, index, animation) => Material(
245-
color: Colors.white.withOpacity(.1),
246-
child: Opacity(
247-
opacity: .5,
248-
child: child,
249-
),
250-
),
251-
onReorder: (fromIndex, newIndex) {
252-
final toIndex =
253-
newIndex > fromIndex ? newIndex - 1 : newIndex;
254-
255-
if (fromIndex == toIndex) {
256-
return;
257-
}
258-
259-
context
260-
.read<GridBloc>()
261-
.add(GridEvent.moveRow(fromIndex, toIndex));
262-
},
263-
itemCount: rowInfos.length,
264-
itemBuilder: (BuildContext context, int index) {
265-
final RowInfo rowInfo = rowInfos[index];
266-
return _renderRow(
267-
context,
268-
rowInfo,
269-
index: index,
270-
isSortEnabled: sortState.sortInfos.isNotEmpty,
271-
isFilterEnabled: filterState.filters.isNotEmpty,
272-
);
273-
},
274-
),
275-
);
246+
) ??
247+
false;
248+
},
249+
builder: (context, state) {
250+
return SliverAnimatedList(
251+
key: _key,
252+
initialItemCount: context.read<GridBloc>().state.rowInfos.length,
253+
itemBuilder:
254+
(BuildContext context, int index, Animation<double> animation) {
255+
final rowInfos = context.read<GridBloc>().state.rowInfos;
256+
if (index >= rowInfos.length) {
257+
return const SizedBox();
258+
} else {
259+
final RowInfo rowInfo = rowInfos[index];
260+
return _renderRow(context, rowInfo, animation);
261+
}
276262
},
277263
);
278264
},
@@ -281,19 +267,16 @@ class _GridRowsState extends State<_GridRows> {
281267

282268
Widget _renderRow(
283269
BuildContext context,
284-
RowInfo rowInfo, {
285-
int? index,
286-
bool isSortEnabled = false,
287-
bool isFilterEnabled = false,
288-
Animation<double>? animation,
289-
}) {
270+
RowInfo rowInfo,
271+
Animation<double> animation,
272+
) {
290273
final rowCache = context.read<GridBloc>().getRowCache(
291274
rowInfo.rowPB.blockId,
292275
rowInfo.rowPB.id,
293276
);
294277

295278
/// Return placeholder widget if the rowCache is null.
296-
if (rowCache == null) return const SizedBox.shrink();
279+
if (rowCache == null) return const SizedBox();
297280

298281
final fieldController =
299282
context.read<GridBloc>().databaseController.fieldController;
@@ -303,32 +286,24 @@ class _GridRowsState extends State<_GridRows> {
303286
rowCache: rowCache,
304287
);
305288

306-
final child = GridRow(
307-
key: ValueKey(rowInfo.rowPB.id),
308-
index: index,
309-
isDraggable: !isSortEnabled && !isFilterEnabled,
310-
rowInfo: rowInfo,
311-
dataController: dataController,
312-
cellBuilder: GridCellBuilder(cellCache: dataController.cellCache),
313-
openDetailPage: (context, cellBuilder) {
314-
_openRowDetailPage(
315-
context,
316-
rowInfo,
317-
fieldController,
318-
rowCache,
319-
cellBuilder,
320-
);
321-
},
289+
return SizeTransition(
290+
sizeFactor: animation,
291+
child: GridRow(
292+
rowInfo: rowInfo,
293+
dataController: dataController,
294+
cellBuilder: GridCellBuilder(cellCache: dataController.cellCache),
295+
openDetailPage: (context, cellBuilder) {
296+
_openRowDetailPage(
297+
context,
298+
rowInfo,
299+
fieldController,
300+
rowCache,
301+
cellBuilder,
302+
);
303+
},
304+
key: ValueKey(rowInfo.rowPB.id),
305+
),
322306
);
323-
324-
if (animation != null) {
325-
return SizeTransition(
326-
sizeFactor: animation,
327-
child: child,
328-
);
329-
}
330-
331-
return child;
332307
}
333308

334309
void _openRowDetailPage(

0 commit comments

Comments
 (0)