소스 검색

fix: alignment in date cell

appflowy 3 년 전
부모
커밋
6c2c3b0666

+ 1 - 1
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:

+ 17 - 2
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<DateCell> createState() => _DateCellState();
@@ -37,6 +51,7 @@ class _DateCellState extends State<DateCell> {
 
   @override
   Widget build(BuildContext context) {
+    final alignment = widget.cellStyle != null ? widget.cellStyle!.alignment : Alignment.center;
     return BlocProvider.value(
       value: _cellBloc,
       child: BlocBuilder<DateCellBloc, DateCellState>(
@@ -57,7 +72,7 @@ class _DateCellState extends State<DateCell> {
               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)),
               ),
             ),
           );

+ 3 - 1
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(),

+ 7 - 5
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<CellMeta>,
     ) -> Result<String, FlowyError> {
         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,

+ 5 - 1
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);