Skip to content

Commit 6c2c3b0

Browse files
committed
fix: alignment in date cell
1 parent 0b8083c commit 6c2c3b0

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GridCellWidget buildGridCellWidget(GridCell gridCell, GridCellCache cellCache, {
2323
case FieldType.Checkbox:
2424
return CheckboxCell(cellContextBuilder: cellContextBuilder, key: key);
2525
case FieldType.DateTime:
26-
return DateCell(cellContextBuilder: cellContextBuilder, key: key);
26+
return DateCell(cellContextBuilder: cellContextBuilder, key: key, style: style);
2727
case FieldType.SingleSelect:
2828
return SingleSelectCell(cellContextBuilder: cellContextBuilder, style: style, key: key);
2929
case FieldType.MultiSelect:

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,32 @@ import 'package:flutter_bloc/flutter_bloc.dart';
88
import 'package:table_calendar/table_calendar.dart';
99
import 'cell_builder.dart';
1010

11+
class DateCellStyle extends GridCellStyle {
12+
Alignment alignment;
13+
14+
DateCellStyle({this.alignment = Alignment.center});
15+
}
16+
1117
abstract class GridCellDelegate {
1218
void onFocus(bool isFocus);
1319
GridCellDelegate get delegate;
1420
}
1521

1622
class DateCell extends GridCellWidget {
1723
final GridCellContextBuilder cellContextBuilder;
24+
late final DateCellStyle? cellStyle;
1825

1926
DateCell({
27+
GridCellStyle? style,
2028
required this.cellContextBuilder,
2129
Key? key,
22-
}) : super(key: key);
30+
}) : super(key: key) {
31+
if (style != null) {
32+
cellStyle = (style as DateCellStyle);
33+
} else {
34+
cellStyle = null;
35+
}
36+
}
2337

2438
@override
2539
State<DateCell> createState() => _DateCellState();
@@ -37,6 +51,7 @@ class _DateCellState extends State<DateCell> {
3751

3852
@override
3953
Widget build(BuildContext context) {
54+
final alignment = widget.cellStyle != null ? widget.cellStyle!.alignment : Alignment.center;
4055
return BlocProvider.value(
4156
value: _cellBloc,
4257
child: BlocBuilder<DateCellBloc, DateCellState>(
@@ -57,7 +72,7 @@ class _DateCellState extends State<DateCell> {
5772
child: MouseRegion(
5873
opaque: false,
5974
cursor: SystemMouseCursors.click,
60-
child: Center(child: FlowyText.medium(state.content, fontSize: 12)),
75+
child: Align(alignment: alignment, child: FlowyText.medium(state.content, fontSize: 12)),
6176
),
6277
),
6378
);

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/row_detail.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ GridCellStyle? _buildCellStyle(AppTheme theme, FieldType fieldType) {
165165
case FieldType.Checkbox:
166166
return null;
167167
case FieldType.DateTime:
168-
return null;
168+
return DateCellStyle(
169+
alignment: Alignment.centerLeft,
170+
);
169171
case FieldType.MultiSelect:
170172
return SelectOptionCellStyle(
171173
placeholder: LocaleKeys.grid_row_textPlaceholder.tr(),

frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ impl CellDataOperation for NumberTypeOption {
110110
_cell_meta: Option<CellMeta>,
111111
) -> Result<String, FlowyError> {
112112
let changeset = changeset.into();
113-
let data = changeset.to_string();
114-
let data = self.strip_symbol(data.trim());
113+
let mut data = changeset.trim().to_string();
115114

116-
if !data.chars().all(char::is_numeric) {
117-
return Err(FlowyError::invalid_data().context("Should only contain numbers"));
115+
if self.format != NumberFormat::Number {
116+
data = self.strip_symbol(data);
117+
if !data.chars().all(char::is_numeric) {
118+
return Err(FlowyError::invalid_data().context("Should only contain numbers"));
119+
}
118120
}
119121

120122
Ok(TypeOptionCellData::new(&data, self.field_type()).json())
@@ -168,7 +170,7 @@ impl NumberTypeOption {
168170
}
169171
}
170172

171-
#[derive(Clone, Copy, Debug, EnumIter, Serialize, Deserialize, ProtoBuf_Enum)]
173+
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Deserialize, ProtoBuf_Enum)]
172174
pub enum NumberFormat {
173175
Number = 0,
174176
USD = 1,

frontend/rust-lib/flowy-grid/src/services/grid_editor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ impl ClientGridEditor {
316316

317317
let cell_data_changeset = changeset.data.unwrap();
318318
let cell_meta = self.get_cell_meta(&changeset.row_id, &changeset.field_id).await?;
319-
tracing::trace!("{}: {:?}", &changeset.field_id, cell_meta);
319+
tracing::trace!(
320+
"field changeset: id:{} / value:{}",
321+
&changeset.field_id,
322+
cell_data_changeset
323+
);
320324
match self.grid_pad.read().await.get_field_meta(&changeset.field_id) {
321325
None => {
322326
let msg = format!("Field not found with id: {}", &changeset.field_id);

0 commit comments

Comments
 (0)