Skip to content

Commit

Permalink
fix: alignment in date cell
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed May 4, 2022
1 parent 0b8083c commit 6c2c3b0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,32 @@ 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;
}

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();
Expand All @@ -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>(
Expand All @@ -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)),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6c2c3b0

Please sign in to comment.