From 65a910291bfde81b806c9b9f448799539910afe8 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Tue, 30 May 2023 10:43:19 +0800 Subject: [PATCH] fix: disable edit update or create field (#2657) * feat: enable hide the grid property in row detail page * feat: disable update the updatedAt or createdAt cell --- .../widgets/row/cell_builder.dart | 6 ++ .../row/cells/date_cell/date_cell.dart | 63 +++++++++++-------- frontend/appflowy_flutter/pubspec.lock | 4 +- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart index 5abd09d84a..ad64cee38d 100755 --- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart @@ -34,11 +34,17 @@ class GridCellBuilder { key: key, ); case FieldType.DateTime: + return GridDateCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + style: style, + ); case FieldType.UpdatedAt: case FieldType.CreatedAt: return GridDateCell( cellControllerBuilder: cellControllerBuilder, key: key, + editable: false, style: style, ); case FieldType.SingleSelect: diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cell.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cell.dart index b88110e6e0..faede408f2 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cell.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/date_cell/date_cell.dart @@ -21,12 +21,14 @@ abstract class GridCellDelegate { } class GridDateCell extends GridCellWidget { + final bool editable; final CellControllerBuilder cellControllerBuilder; late final DateCellStyle? cellStyle; GridDateCell({ GridCellStyle? style, required this.cellControllerBuilder, + this.editable = true, Key? key, }) : super(key: key) { if (style != null) { @@ -63,35 +65,41 @@ class _DateCellState extends GridCellState { value: _cellBloc, child: BlocBuilder( builder: (context, state) { - return AppFlowyPopover( - controller: _popover, - triggerActions: PopoverTriggerFlags.none, - direction: PopoverDirection.bottomWithLeftAligned, - constraints: BoxConstraints.loose(const Size(260, 500)), - margin: EdgeInsets.zero, - child: SizedBox.expand( - child: Align( - alignment: alignment, - child: Padding( - padding: GridSize.cellContentInsets, - child: FlowyText.medium( - state.dateStr, - overflow: TextOverflow.ellipsis, - ), + Widget dateTextWidget = SizedBox.expand( + child: Align( + alignment: alignment, + child: Padding( + padding: GridSize.cellContentInsets, + child: FlowyText.medium( + state.dateStr, + overflow: TextOverflow.ellipsis, ), ), ), - popupBuilder: (BuildContext popoverContent) { - return DateCellEditor( - cellController: - widget.cellControllerBuilder.build() as DateCellController, - onDismissed: () => widget.onCellEditing.value = false, - ); - }, - onClose: () { - widget.onCellEditing.value = false; - }, ); + + // If the cell is editable, wrap it in a popover. + if (widget.editable) { + dateTextWidget = AppFlowyPopover( + controller: _popover, + triggerActions: PopoverTriggerFlags.none, + direction: PopoverDirection.bottomWithLeftAligned, + constraints: BoxConstraints.loose(const Size(260, 500)), + margin: EdgeInsets.zero, + child: dateTextWidget, + popupBuilder: (BuildContext popoverContent) { + return DateCellEditor( + cellController: widget.cellControllerBuilder.build() + as DateCellController, + onDismissed: () => widget.onCellEditing.value = false, + ); + }, + onClose: () { + widget.onCellEditing.value = false; + }, + ); + } + return dateTextWidget; }, ), ); @@ -106,7 +114,10 @@ class _DateCellState extends GridCellState { @override void requestBeginFocus() { _popover.show(); - widget.onCellEditing.value = true; + + if (widget.editable) { + widget.onCellEditing.value = true; + } } @override diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock index 2d731706c1..c4659fdbe5 100644 --- a/frontend/appflowy_flutter/pubspec.lock +++ b/frontend/appflowy_flutter/pubspec.lock @@ -53,8 +53,8 @@ packages: dependency: "direct main" description: path: "." - ref: "29ee7a3" - resolved-ref: "29ee7a343f4ded8a15bc74ea0df6a458e70cb231" + ref: "9732d30" + resolved-ref: "9732d30e852ccb832785d6fff3923966452ffcf4" url: "https://github.com/AppFlowy-IO/appflowy-editor.git" source: git version: "0.1.12"