mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: alignment in date cell
This commit is contained in:
parent
0b8083cfc6
commit
6c2c3b0666
@ -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:
|
||||
|
@ -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)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -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(),
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user