From 6c2c3b0666233bd0a994c7d107dd2f5394ff5ec1 Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 4 May 2022 21:06:11 +0800 Subject: [PATCH] fix: alignment in date cell --- .../grid/src/widgets/cell/cell_builder.dart | 2 +- .../grid/src/widgets/cell/date_cell.dart | 19 +++++++++++++++++-- .../grid/src/widgets/row/row_detail.dart | 4 +++- .../field/type_options/number_type_option.rs | 12 +++++++----- .../flowy-grid/src/services/grid_editor.rs | 6 +++++- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart index 0b13aab846226..8efdffdb323c8 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart @@ -23,7 +23,7 @@ GridCellWidget buildGridCellWidget(GridCell gridCell, GridCellCache cellCache, { case FieldType.Checkbox: return CheckboxCell(cellContextBuilder: cellContextBuilder, key: key); case FieldType.DateTime: - return DateCell(cellContextBuilder: cellContextBuilder, key: key); + return DateCell(cellContextBuilder: cellContextBuilder, key: key, style: style); case FieldType.SingleSelect: return SingleSelectCell(cellContextBuilder: cellContextBuilder, style: style, key: key); case FieldType.MultiSelect: diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart index a68bfcb4bc35c..194e5adf6a336 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart @@ -8,6 +8,12 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:table_calendar/table_calendar.dart'; import 'cell_builder.dart'; +class DateCellStyle extends GridCellStyle { + Alignment alignment; + + DateCellStyle({this.alignment = Alignment.center}); +} + abstract class GridCellDelegate { void onFocus(bool isFocus); GridCellDelegate get delegate; @@ -15,11 +21,19 @@ abstract class GridCellDelegate { class DateCell extends GridCellWidget { final GridCellContextBuilder cellContextBuilder; + late final DateCellStyle? cellStyle; DateCell({ + GridCellStyle? style, required this.cellContextBuilder, Key? key, - }) : super(key: key); + }) : super(key: key) { + if (style != null) { + cellStyle = (style as DateCellStyle); + } else { + cellStyle = null; + } + } @override State createState() => _DateCellState(); @@ -37,6 +51,7 @@ class _DateCellState extends State { @override Widget build(BuildContext context) { + final alignment = widget.cellStyle != null ? widget.cellStyle!.alignment : Alignment.center; return BlocProvider.value( value: _cellBloc, child: BlocBuilder( @@ -57,7 +72,7 @@ class _DateCellState extends State { child: MouseRegion( opaque: false, cursor: SystemMouseCursors.click, - child: Center(child: FlowyText.medium(state.content, fontSize: 12)), + child: Align(alignment: alignment, child: FlowyText.medium(state.content, fontSize: 12)), ), ), ); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart index ae8203332026f..7e2ece2cf5b31 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart @@ -165,7 +165,9 @@ GridCellStyle? _buildCellStyle(AppTheme theme, FieldType fieldType) { case FieldType.Checkbox: return null; case FieldType.DateTime: - return null; + return DateCellStyle( + alignment: Alignment.centerLeft, + ); case FieldType.MultiSelect: return SelectOptionCellStyle( placeholder: LocaleKeys.grid_row_textPlaceholder.tr(), diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option.rs index f403a28272eae..2d03a0ab331e1 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option.rs @@ -110,11 +110,13 @@ impl CellDataOperation for NumberTypeOption { _cell_meta: Option, ) -> Result { let changeset = changeset.into(); - let data = changeset.to_string(); - let data = self.strip_symbol(data.trim()); + let mut data = changeset.trim().to_string(); - if !data.chars().all(char::is_numeric) { - return Err(FlowyError::invalid_data().context("Should only contain numbers")); + if self.format != NumberFormat::Number { + data = self.strip_symbol(data); + if !data.chars().all(char::is_numeric) { + return Err(FlowyError::invalid_data().context("Should only contain numbers")); + } } Ok(TypeOptionCellData::new(&data, self.field_type()).json()) @@ -168,7 +170,7 @@ impl NumberTypeOption { } } -#[derive(Clone, Copy, Debug, EnumIter, Serialize, Deserialize, ProtoBuf_Enum)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Deserialize, ProtoBuf_Enum)] pub enum NumberFormat { Number = 0, USD = 1, diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs index d8d909cabe529..5962386352cc8 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs @@ -316,7 +316,11 @@ impl ClientGridEditor { let cell_data_changeset = changeset.data.unwrap(); let cell_meta = self.get_cell_meta(&changeset.row_id, &changeset.field_id).await?; - tracing::trace!("{}: {:?}", &changeset.field_id, cell_meta); + tracing::trace!( + "field changeset: id:{} / value:{}", + &changeset.field_id, + cell_data_changeset + ); match self.grid_pad.read().await.get_field_meta(&changeset.field_id) { None => { let msg = format!("Field not found with id: {}", &changeset.field_id);