fix: some bugs (#2639)

* fix: invalid index when insert row

* fix: auto fill 0 in front of number start with .

* fix: #2591

* chore: split the update at and create at test

* chore: fix tauri build
This commit is contained in:
Nathan.fooo
2023-05-28 16:14:25 +08:00
committed by GitHub
parent cdfb634aa6
commit 75d40b79d0
29 changed files with 304 additions and 220 deletions

View File

@ -83,13 +83,13 @@ class RowCache {
await _cellCache.dispose();
}
void applyRowsChanged(RowsChangesetPB changeset) {
void applyRowsChanged(RowsChangePB changeset) {
_deleteRows(changeset.deletedRows);
_insertRows(changeset.insertedRows);
_updateRows(changeset.updatedRows);
}
void applyRowsVisibility(RowsVisibilityChangesetPB changeset) {
void applyRowsVisibility(RowsVisibilityChangePB changeset) {
_hideRows(changeset.invisibleRows);
_showRows(changeset.visibleRows);
}

View File

@ -7,6 +7,7 @@ typedef OnRowChanged = void Function(CellByFieldId, RowsChangedReason);
class RowController {
final RowId rowId;
final String? groupId;
final String viewId;
final List<VoidCallback> _onRowChangedListeners = [];
final RowCache _rowCache;
@ -17,6 +18,7 @@ class RowController {
required this.rowId,
required this.viewId,
required RowCache rowCache,
this.groupId,
}) : _rowCache = rowCache;
CellByFieldId loadData() {

View File

@ -36,10 +36,16 @@ class RowBackendService {
return DatabaseEventDeleteRow(payload).send();
}
Future<Either<Unit, FlowyError>> duplicateRow(RowId rowId) {
Future<Either<Unit, FlowyError>> duplicateRow({
required RowId rowId,
String? groupId,
}) {
final payload = RowIdPB.create()
..viewId = viewId
..rowId = rowId;
if (groupId != null) {
payload.groupId = groupId;
}
return DatabaseEventDuplicateRow(payload).send();
}

View File

@ -9,9 +9,9 @@ import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/view_entities.pb.dart';
typedef RowsVisibilityNotifierValue
= Either<RowsVisibilityChangesetPB, FlowyError>;
= Either<RowsVisibilityChangePB, FlowyError>;
typedef NumberOfRowsNotifierValue = Either<RowsChangesetPB, FlowyError>;
typedef NumberOfRowsNotifierValue = Either<RowsChangePB, FlowyError>;
typedef ReorderAllRowsNotifierValue = Either<List<String>, FlowyError>;
typedef SingleRowNotifierValue = Either<ReorderSingleRowPB, FlowyError>;
@ -54,14 +54,14 @@ class DatabaseViewListener {
case DatabaseNotification.DidUpdateViewRowsVisibility:
result.fold(
(payload) => _rowsVisibility?.value =
left(RowsVisibilityChangesetPB.fromBuffer(payload)),
left(RowsVisibilityChangePB.fromBuffer(payload)),
(error) => _rowsVisibility?.value = right(error),
);
break;
case DatabaseNotification.DidUpdateViewRows:
result.fold(
(payload) =>
_rowsNotifier?.value = left(RowsChangesetPB.fromBuffer(payload)),
_rowsNotifier?.value = left(RowsChangePB.fromBuffer(payload)),
(error) => _rowsNotifier?.value = right(error),
);
break;

View File

@ -265,6 +265,7 @@ class _BoardContentState extends State<BoardContent> {
renderHook: renderHook,
openCard: (context) => _openCard(
viewId,
groupData.group.groupId,
fieldController,
rowPB,
rowCache,
@ -302,6 +303,7 @@ class _BoardContentState extends State<BoardContent> {
void _openCard(
String viewId,
String groupId,
FieldController fieldController,
RowPB rowPB,
RowCache rowCache,
@ -317,6 +319,7 @@ class _BoardContentState extends State<BoardContent> {
rowId: rowInfo.rowPB.id,
viewId: rowInfo.viewId,
rowCache: rowCache,
groupId: groupId,
);
FlowyOverlay.show(
@ -324,7 +327,7 @@ class _BoardContentState extends State<BoardContent> {
builder: (BuildContext context) {
return RowDetailPage(
cellBuilder: GridCellBuilder(cellCache: dataController.cellCache),
dataController: dataController,
rowController: dataController,
);
},
);

View File

@ -241,7 +241,7 @@ void showEventDetails({
cellBuilder: GridCellBuilder(
cellCache: rowCache.cellCache,
),
dataController: dataController,
rowController: dataController,
);
},
);

View File

@ -18,14 +18,14 @@ class RowActionSheetBloc
super(RowActionSheetState.initial(rowInfo)) {
on<RowActionSheetEvent>(
(event, emit) async {
await event.map(
deleteRow: (_DeleteRow value) async {
await event.when(
deleteRow: () async {
final result = await _rowService.deleteRow(state.rowData.rowPB.id);
logResult(result);
},
duplicateRow: (_DuplicateRow value) async {
duplicateRow: () async {
final result =
await _rowService.duplicateRow(state.rowData.rowPB.id);
await _rowService.duplicateRow(rowId: state.rowData.rowPB.id);
logResult(result);
},
);

View File

@ -38,8 +38,11 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
deleteRow: (rowId) async {
await rowService.deleteRow(rowId);
},
duplicateRow: (String rowId) async {
await rowService.duplicateRow(rowId);
duplicateRow: (String rowId, String? groupId) async {
await rowService.duplicateRow(
rowId: rowId,
groupId: groupId,
);
},
);
},
@ -68,7 +71,8 @@ class RowDetailEvent with _$RowDetailEvent {
const factory RowDetailEvent.initial() = _Initial;
const factory RowDetailEvent.deleteField(String fieldId) = _DeleteField;
const factory RowDetailEvent.deleteRow(String rowId) = _DeleteRow;
const factory RowDetailEvent.duplicateRow(String rowId) = _DuplicateRow;
const factory RowDetailEvent.duplicateRow(String rowId, String? groupId) =
_DuplicateRow;
const factory RowDetailEvent.didReceiveCellDatas(
List<CellIdentifier> gridCells,
) = _DidReceiveCellDatas;

View File

@ -348,7 +348,7 @@ class _GridRowsState extends State<_GridRows> {
builder: (BuildContext context) {
return RowDetailPage(
cellBuilder: cellBuilder,
dataController: dataController,
rowController: dataController,
);
},
);

View File

@ -26,11 +26,11 @@ import '../../grid/presentation/widgets/header/field_cell.dart';
import '../../grid/presentation/widgets/header/field_editor.dart';
class RowDetailPage extends StatefulWidget with FlowyOverlayDelegate {
final RowController dataController;
final RowController rowController;
final GridCellBuilder cellBuilder;
const RowDetailPage({
required this.dataController,
required this.rowController,
required this.cellBuilder,
Key? key,
}) : super(key: key);
@ -49,7 +49,7 @@ class _RowDetailPageState extends State<RowDetailPage> {
return FlowyDialog(
child: BlocProvider(
create: (context) {
return RowDetailBloc(dataController: widget.dataController)
return RowDetailBloc(dataController: widget.rowController)
..add(const RowDetailEvent.initial());
},
child: ListView(
@ -69,11 +69,11 @@ class _RowDetailPageState extends State<RowDetailPage> {
Widget _responsiveRowInfo() {
final rowDataColumn = _PropertyColumn(
cellBuilder: widget.cellBuilder,
viewId: widget.dataController.viewId,
viewId: widget.rowController.viewId,
);
final rowOptionColumn = _RowOptionColumn(
viewId: widget.dataController.viewId,
rowId: widget.dataController.rowId,
viewId: widget.rowController.viewId,
rowController: widget.rowController,
);
if (MediaQuery.of(context).size.width > 800) {
return Row(
@ -372,10 +372,10 @@ GridCellStyle? _customCellStyle(FieldType fieldType) {
}
class _RowOptionColumn extends StatelessWidget {
final String rowId;
final RowController rowController;
const _RowOptionColumn({
required String viewId,
required this.rowId,
required this.rowController,
Key? key,
}) : super(key: key);
@ -390,8 +390,11 @@ class _RowOptionColumn extends StatelessWidget {
child: FlowyText(LocaleKeys.grid_row_action.tr()),
),
const VSpace(15),
_DeleteButton(rowId: rowId),
_DuplicateButton(rowId: rowId),
_DeleteButton(rowId: rowController.rowId),
_DuplicateButton(
rowId: rowController.rowId,
groupId: rowController.groupId,
),
],
);
}
@ -419,7 +422,12 @@ class _DeleteButton extends StatelessWidget {
class _DuplicateButton extends StatelessWidget {
final String rowId;
const _DuplicateButton({required this.rowId, Key? key}) : super(key: key);
final String? groupId;
const _DuplicateButton({
required this.rowId,
this.groupId,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -429,7 +437,9 @@ class _DuplicateButton extends StatelessWidget {
text: FlowyText.regular(LocaleKeys.grid_row_duplicate.tr()),
leftIcon: const FlowySvg(name: "grid/duplicate"),
onTap: () {
context.read<RowDetailBloc>().add(RowDetailEvent.duplicateRow(rowId));
context
.read<RowDetailBloc>()
.add(RowDetailEvent.duplicateRow(rowId, groupId));
FlowyOverlay.pop(context);
},
),