mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: enable hide the grid property in row detail page (#2656)
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import 'package:appflowy/plugins/database_view/application/row/row_service.dart';
|
import 'package:appflowy/plugins/database_view/application/row/row_service.dart';
|
||||||
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
@ -29,11 +30,16 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
|
|||||||
emit(state.copyWith(gridCells: cells));
|
emit(state.copyWith(gridCells: cells));
|
||||||
},
|
},
|
||||||
deleteField: (fieldId) {
|
deleteField: (fieldId) {
|
||||||
final fieldService = FieldBackendService(
|
_fieldBackendService(fieldId).deleteField();
|
||||||
viewId: dataController.viewId,
|
},
|
||||||
fieldId: fieldId,
|
hideField: (fieldId) async {
|
||||||
|
final result = await _fieldBackendService(fieldId).updateField(
|
||||||
|
visibility: false,
|
||||||
|
);
|
||||||
|
result.fold(
|
||||||
|
(l) {},
|
||||||
|
(err) => Log.error(err),
|
||||||
);
|
);
|
||||||
fieldService.deleteField();
|
|
||||||
},
|
},
|
||||||
deleteRow: (rowId) async {
|
deleteRow: (rowId) async {
|
||||||
await rowService.deleteRow(rowId);
|
await rowService.deleteRow(rowId);
|
||||||
@ -64,12 +70,20 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FieldBackendService _fieldBackendService(String fieldId) {
|
||||||
|
return FieldBackendService(
|
||||||
|
viewId: dataController.viewId,
|
||||||
|
fieldId: fieldId,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class RowDetailEvent with _$RowDetailEvent {
|
class RowDetailEvent with _$RowDetailEvent {
|
||||||
const factory RowDetailEvent.initial() = _Initial;
|
const factory RowDetailEvent.initial() = _Initial;
|
||||||
const factory RowDetailEvent.deleteField(String fieldId) = _DeleteField;
|
const factory RowDetailEvent.deleteField(String fieldId) = _DeleteField;
|
||||||
|
const factory RowDetailEvent.hideField(String fieldId) = _HideField;
|
||||||
const factory RowDetailEvent.deleteRow(String rowId) = _DeleteRow;
|
const factory RowDetailEvent.deleteRow(String rowId) = _DeleteRow;
|
||||||
const factory RowDetailEvent.duplicateRow(String rowId, String? groupId) =
|
const factory RowDetailEvent.duplicateRow(String rowId, String? groupId) =
|
||||||
_DuplicateRow;
|
_DuplicateRow;
|
||||||
|
@ -108,8 +108,8 @@ class _FlowyGridState extends State<FlowyGrid> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
|
||||||
headerScrollController = _scrollController.linkHorizontalController();
|
headerScrollController = _scrollController.linkHorizontalController();
|
||||||
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -19,6 +19,7 @@ class FieldEditor extends StatefulWidget {
|
|||||||
final String fieldName;
|
final String fieldName;
|
||||||
final bool isGroupingField;
|
final bool isGroupingField;
|
||||||
final Function(String)? onDeleted;
|
final Function(String)? onDeleted;
|
||||||
|
final Function(String)? onHidden;
|
||||||
final IFieldTypeOptionLoader typeOptionLoader;
|
final IFieldTypeOptionLoader typeOptionLoader;
|
||||||
|
|
||||||
const FieldEditor({
|
const FieldEditor({
|
||||||
@ -27,6 +28,7 @@ class FieldEditor extends StatefulWidget {
|
|||||||
required this.typeOptionLoader,
|
required this.typeOptionLoader,
|
||||||
this.isGroupingField = false,
|
this.isGroupingField = false,
|
||||||
this.onDeleted,
|
this.onDeleted,
|
||||||
|
this.onHidden,
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@ -55,6 +57,7 @@ class _FieldEditorState extends State<FieldEditor> {
|
|||||||
_FieldNameTextField(popoverMutex: popoverMutex),
|
_FieldNameTextField(popoverMutex: popoverMutex),
|
||||||
const VSpace(10),
|
const VSpace(10),
|
||||||
if (widget.onDeleted != null) _addDeleteFieldButton(),
|
if (widget.onDeleted != null) _addDeleteFieldButton(),
|
||||||
|
if (widget.onHidden != null) _addHideFieldButton(),
|
||||||
_FieldTypeOptionCell(popoverMutex: popoverMutex),
|
_FieldTypeOptionCell(popoverMutex: popoverMutex),
|
||||||
];
|
];
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
@ -91,6 +94,25 @@ class _FieldEditorState extends State<FieldEditor> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _addHideFieldButton() {
|
||||||
|
return BlocBuilder<FieldEditorBloc, FieldEditorState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
|
child: _HideFieldButton(
|
||||||
|
popoverMutex: popoverMutex,
|
||||||
|
onHidden: () {
|
||||||
|
state.field.fold(
|
||||||
|
() => Log.error('Can not hidden the field'),
|
||||||
|
(field) => widget.onHidden?.call(field.id),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FieldTypeOptionCell extends StatelessWidget {
|
class _FieldTypeOptionCell extends StatelessWidget {
|
||||||
@ -221,3 +243,34 @@ class _DeleteFieldButton extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _HideFieldButton extends StatelessWidget {
|
||||||
|
final PopoverMutex popoverMutex;
|
||||||
|
final VoidCallback? onHidden;
|
||||||
|
|
||||||
|
const _HideFieldButton({
|
||||||
|
required this.popoverMutex,
|
||||||
|
required this.onHidden,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<FieldEditorBloc, FieldEditorState>(
|
||||||
|
buildWhen: (previous, current) => previous != current,
|
||||||
|
builder: (context, state) {
|
||||||
|
Widget button = FlowyButton(
|
||||||
|
text: FlowyText.medium(
|
||||||
|
LocaleKeys.grid_field_hide.tr(),
|
||||||
|
),
|
||||||
|
onTap: () => onHidden?.call(),
|
||||||
|
onHover: (_) => popoverMutex.close(),
|
||||||
|
);
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4.0),
|
||||||
|
child: SizedBox(height: GridSize.popoverItemHeight, child: button),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -229,7 +229,6 @@ class _CreatePropertyButtonState extends State<_CreatePropertyButton> {
|
|||||||
typeOptionLoader: NewFieldTypeOptionLoader(viewId: widget.viewId),
|
typeOptionLoader: NewFieldTypeOptionLoader(viewId: widget.viewId),
|
||||||
onDeleted: (fieldId) {
|
onDeleted: (fieldId) {
|
||||||
popoverController.close();
|
popoverController.close();
|
||||||
|
|
||||||
NavigatorAlertDialog(
|
NavigatorAlertDialog(
|
||||||
title: LocaleKeys.grid_field_deleteFieldPromptMessage.tr(),
|
title: LocaleKeys.grid_field_deleteFieldPromptMessage.tr(),
|
||||||
confirm: () {
|
confirm: () {
|
||||||
@ -314,6 +313,10 @@ class _PropertyCellState extends State<_PropertyCell> {
|
|||||||
viewId: widget.cellId.viewId,
|
viewId: widget.cellId.viewId,
|
||||||
field: widget.cellId.fieldInfo.field,
|
field: widget.cellId.fieldInfo.field,
|
||||||
),
|
),
|
||||||
|
onHidden: (fieldId) {
|
||||||
|
popover.close();
|
||||||
|
context.read<RowDetailBloc>().add(RowDetailEvent.hideField(fieldId));
|
||||||
|
},
|
||||||
onDeleted: (fieldId) {
|
onDeleted: (fieldId) {
|
||||||
popover.close();
|
popover.close();
|
||||||
|
|
||||||
|
@ -87,7 +87,6 @@ enum ImportType {
|
|||||||
case ImportType.historyDocument:
|
case ImportType.historyDocument:
|
||||||
return ['afdoc'];
|
return ['afdoc'];
|
||||||
case ImportType.historyDatabase:
|
case ImportType.historyDatabase:
|
||||||
// FIXME: @nathan.
|
|
||||||
return ['afdb'];
|
return ['afdb'];
|
||||||
case ImportType.markdownOrText:
|
case ImportType.markdownOrText:
|
||||||
return ['md', 'txt'];
|
return ['md', 'txt'];
|
||||||
|
Reference in New Issue
Block a user