refactor: remove date cell persistence (#3095)

* refactor: remove date cell persistence

* refactor: use i64 rather than String in DateChangeset

* chore: code cleanup

* fix: tauri build

---------

Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
Richard Shiue 2023-09-02 11:50:16 +08:00 committed by GitHub
parent f3aaff77b9
commit b73a34ed94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 159 additions and 197 deletions

View File

@ -13,7 +13,7 @@ typedef NumberCellController = CellController<String, String>;
typedef SelectOptionCellController
= CellController<SelectOptionCellDataPB, String>;
typedef ChecklistCellController = CellController<ChecklistCellDataPB, String>;
typedef DateCellController = CellController<DateCellDataPB, DateCellData>;
typedef DateCellController = CellController<DateCellDataPB, String>;
typedef URLCellController = CellController<URLCellDataPB, String>;
class CellControllerBuilder {
@ -54,7 +54,7 @@ class CellControllerBuilder {
cellCache: _cellCache,
cellDataLoader: cellDataLoader,
cellDataPersistence:
DateCellDataPersistence(cellContext: _cellContext),
TextCellDataPersistence(cellContext: _cellContext),
);
case FieldType.Number:
final cellDataLoader = CellDataLoader(

View File

@ -1,7 +1,7 @@
part of 'cell_service.dart';
/// Save the cell data to disk
/// You can extend this class to do custom operations. For example, the DateCellDataPersistence.
/// You can extend this class to do custom operations.
abstract class CellDataPersistence<D> {
Future<Option<FlowyError>> save(D data);
}
@ -28,51 +28,3 @@ class TextCellDataPersistence implements CellDataPersistence<String> {
});
}
}
@freezed
class DateCellData with _$DateCellData {
const factory DateCellData({
DateTime? dateTime,
String? time,
required bool includeTime,
bool? clearFlag,
}) = _DateCellData;
}
class DateCellDataPersistence implements CellDataPersistence<DateCellData> {
final DatabaseCellContext cellContext;
DateCellDataPersistence({
required this.cellContext,
});
@override
Future<Option<FlowyError>> save(DateCellData data) {
final payload = DateChangesetPB.create()
..cellId = _makeCellPath(cellContext);
if (data.dateTime != null) {
final date = (data.dateTime!.millisecondsSinceEpoch ~/ 1000).toString();
payload.date = date;
}
if (data.time != null) {
payload.time = data.time!;
}
if (data.clearFlag != null) {
payload.clearFlag = data.clearFlag!;
}
payload.includeTime = data.includeTime;
return DatabaseEventUpdateDateCell(payload).send().then((result) {
return result.fold(
(l) => none(),
(err) => Some(err),
);
});
}
}
CellIdPB _makeCellPath(DatabaseCellContext cellId) {
return CellIdPB.create()
..viewId = cellId.viewId
..fieldId = cellId.fieldId
..rowId = cellId.rowId;
}

View File

@ -0,0 +1,47 @@
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/cell_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/date_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:dartz/dartz.dart';
import 'package:fixnum/fixnum.dart';
final class DateCellBackendService {
final CellIdPB cellId;
DateCellBackendService({
required String viewId,
required String fieldId,
required String rowId,
}) : cellId = CellIdPB.create()
..viewId = viewId
..fieldId = fieldId
..rowId = rowId;
Future<Either<Unit, FlowyError>> update({
DateTime? date,
String? time,
required includeTime,
}) {
final payload = DateChangesetPB.create()
..cellId = cellId
..includeTime = includeTime;
if (date != null) {
final dateTimestamp = date.millisecondsSinceEpoch ~/ 1000;
payload.date = Int64(dateTimestamp);
}
if (time != null) {
payload.time = time;
}
return DatabaseEventUpdateDateCell(payload).send();
}
Future<Either<Unit, FlowyError>> clear() {
final payload = DateChangesetPB.create()
..cellId = cellId
..clearFlag = true;
return DatabaseEventUpdateDateCell(payload).send();
}
}

View File

@ -2,7 +2,7 @@ import 'dart:async';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database_view/application/cell/cell_controller_builder.dart';
import 'package:appflowy/plugins/database_view/application/cell/cell_service.dart';
import 'package:appflowy/plugins/database_view/application/cell/date_cell_service.dart';
import 'package:appflowy/plugins/database_view/application/field/field_service.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/date_entities.pb.dart';
@ -19,6 +19,7 @@ part 'date_cal_bloc.freezed.dart';
class DateCellCalendarBloc
extends Bloc<DateCellCalendarEvent, DateCellCalendarState> {
final DateCellBackendService _dateCellBackendService;
final DateCellController cellController;
void Function()? _onCellChangedFn;
@ -26,18 +27,24 @@ class DateCellCalendarBloc
required DateTypeOptionPB dateTypeOptionPB,
required DateCellDataPB? cellData,
required this.cellController,
}) : super(DateCellCalendarState.initial(dateTypeOptionPB, cellData)) {
}) : _dateCellBackendService = DateCellBackendService(
viewId: cellController.viewId,
fieldId: cellController.fieldId,
rowId: cellController.rowId,
),
super(DateCellCalendarState.initial(dateTypeOptionPB, cellData)) {
on<DateCellCalendarEvent>(
(event, emit) async {
await event.when(
initial: () async => _startListening(),
didReceiveCellUpdate: (DateCellDataPB? cellData) {
final dateData = _dateDataFromCellData(cellData);
final (dateTime, time, includeTime) =
_dateDataFromCellData(cellData);
emit(
state.copyWith(
dateTime: dateData.dateTime,
time: dateData.time,
includeTime: dateData.includeTime,
dateTime: dateTime,
time: time,
includeTime: includeTime,
),
);
},
@ -45,13 +52,13 @@ class DateCellCalendarBloc
emit(state.copyWith(timeFormatError: timeFormatError));
},
selectDay: (date) async {
await _updateDateData(emit, date: date);
await _updateDateData(date: date);
},
setIncludeTime: (includeTime) async {
await _updateDateData(emit, includeTime: includeTime);
await _updateDateData(includeTime: includeTime);
},
setTime: (time) async {
await _updateDateData(emit, time: time);
await _updateDateData(time: time);
},
setDateFormat: (dateFormat) async {
await _updateTypeOption(emit, dateFormat: dateFormat);
@ -66,15 +73,14 @@ class DateCellCalendarBloc
emit(state.copyWith(focusedDay: focusedDay));
},
clearDate: () async {
await _clearDate(emit);
await _clearDate();
},
);
},
);
}
Future<void> _updateDateData(
Emitter<DateCellCalendarState> emit, {
Future<void> _updateDateData({
DateTime? date,
String? time,
bool? includeTime,
@ -86,76 +92,60 @@ class DateCellCalendarBloc
date != null && time == null,
);
final String? newTime = time ?? state.time;
DateTime? newDate = _utcToLocalAddTime(date);
DateTime? newDate = _utcToLocalAndAddCurrentTime(date);
if (time != null && time.isNotEmpty) {
newDate = state.dateTime ?? DateTime.now();
}
final DateCellData newDateData = DateCellData(
dateTime: newDate,
final result = await _dateCellBackendService.update(
date: newDate,
time: newTime,
includeTime: includeTime ?? state.includeTime,
);
cellController.saveCellData(
newDateData,
onFinish: (result) {
result.fold(
() {
if (!isClosed && state.timeFormatError != null) {
add(const DateCellCalendarEvent.didReceiveTimeFormatError(null));
}
},
(err) {
switch (err.code) {
case ErrorCode.InvalidDateTimeFormat:
if (isClosed) return;
add(
DateCellCalendarEvent.didReceiveTimeFormatError(
timeFormatPrompt(err),
),
);
break;
default:
Log.error(err);
}
},
);
result.fold(
(_) {
if (!isClosed && state.timeFormatError != null) {
add(const DateCellCalendarEvent.didReceiveTimeFormatError(null));
}
},
(err) {
switch (err.code) {
case ErrorCode.InvalidDateTimeFormat:
if (isClosed) return;
add(
DateCellCalendarEvent.didReceiveTimeFormatError(
timeFormatPrompt(err),
),
);
break;
default:
Log.error(err);
}
},
);
}
Future<void> _clearDate(Emitter<DateCellCalendarState> emit) async {
final DateCellData newDateData = DateCellData(
dateTime: null,
time: null,
includeTime: state.includeTime,
clearFlag: true,
);
cellController.saveCellData(
newDateData,
onFinish: (result) {
result.fold(
() {
if (!isClosed) {
add(const DateCellCalendarEvent.didReceiveTimeFormatError(null));
}
},
(err) => Log.error(err),
);
Future<void> _clearDate() async {
final result = await _dateCellBackendService.clear();
result.fold(
(_) {
if (!isClosed) {
add(const DateCellCalendarEvent.didReceiveTimeFormatError(null));
}
},
(err) => Log.error(err),
);
}
DateTime? _utcToLocalAddTime(DateTime? date) {
DateTime? _utcToLocalAndAddCurrentTime(DateTime? date) {
if (date == null) {
return null;
}
final now = DateTime.now();
// the incoming date is Utc. this trick converts it into Local
// and add the current time, though the time may be overwritten by
// explicitly provided time string
// the incoming date is Utc. This trick converts it into Local
// and add the current time. The time may be overwritten by
// explicitly provided time string in the backend though
return DateTime(
date.year,
date.month,
@ -285,14 +275,14 @@ class DateCellCalendarState with _$DateCellCalendarState {
DateTypeOptionPB dateTypeOptionPB,
DateCellDataPB? cellData,
) {
final dateData = _dateDataFromCellData(cellData);
final (dateTime, time, includeTime) = _dateDataFromCellData(cellData);
return DateCellCalendarState(
dateTypeOptionPB: dateTypeOptionPB,
format: CalendarFormat.month,
focusedDay: DateTime.now(),
dateTime: dateData.dateTime,
time: dateData.time,
includeTime: dateData.includeTime,
dateTime: dateTime,
time: time,
includeTime: includeTime,
timeFormatError: null,
timeHintText: _timeHintText(dateTypeOptionPB),
);
@ -310,11 +300,11 @@ String _timeHintText(DateTypeOptionPB typeOption) {
}
}
DateCellData _dateDataFromCellData(DateCellDataPB? cellData) {
(DateTime?, String?, bool) _dateDataFromCellData(DateCellDataPB? cellData) {
// a null DateCellDataPB may be returned, indicating that all the fields are
// at their default values: empty strings and false booleans
if (cellData == null) {
return const DateCellData(includeTime: false);
return (null, null, false);
}
DateTime? dateTime;
@ -326,5 +316,5 @@ DateCellData _dateDataFromCellData(DateCellDataPB? cellData) {
}
final bool includeTime = cellData.includeTime;
return DateCellData(dateTime: dateTime, time: time, includeTime: includeTime);
return (dateTime, time, includeTime);
}

View File

@ -25,7 +25,7 @@ export class DateCellDataPersistence extends CellDataPersistence<CalendarData> {
save(data: CalendarData): Promise<Result<void, FlowyError>> {
const payload = DateChangesetPB.fromObject({ cell_id: _makeCellId(this.cellIdentifier) });
payload.date = ((data.date.getTime() / 1000) | 0).toString();
payload.date = (data.date.getTime() / 1000) | 0;
if (data.time !== undefined) {
payload.time = data.time;
}

View File

@ -28,7 +28,7 @@ pub struct DateChangesetPB {
pub cell_id: CellIdPB,
#[pb(index = 2, one_of)]
pub date: Option<String>,
pub date: Option<i64>,
#[pb(index = 3, one_of)]
pub time: Option<String>,

View File

@ -843,7 +843,7 @@ pub(crate) async fn move_calendar_event_handler(
let data = data.into_inner();
let cell_id: CellIdParams = data.cell_path.try_into()?;
let cell_changeset = DateCellChangeset {
date: Some(data.timestamp.to_string()),
date: Some(data.timestamp),
..Default::default()
};
let database_editor = manager.get_database_with_view_id(&cell_id.view_id).await?;

View File

@ -209,7 +209,7 @@ pub fn insert_checkbox_cell(is_check: bool, field: &Field) -> Cell {
pub fn insert_date_cell(timestamp: i64, include_time: Option<bool>, field: &Field) -> Cell {
let cell_data = serde_json::to_string(&DateCellChangeset {
date: Some(timestamp.to_string()),
date: Some(timestamp),
time: None,
include_time,
clear_flag: None,

View File

@ -25,7 +25,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1647251762".to_owned()),
date: Some(1647251762),
time: None,
include_time: None,
clear_flag: None,
@ -39,7 +39,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1647251762".to_owned()),
date: Some(1647251762),
time: None,
include_time: None,
clear_flag: None,
@ -53,7 +53,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1647251762".to_owned()),
date: Some(1647251762),
time: None,
include_time: None,
clear_flag: None,
@ -67,7 +67,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1647251762".to_owned()),
date: Some(1647251762),
time: None,
include_time: None,
clear_flag: None,
@ -81,7 +81,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1647251762".to_owned()),
date: Some(1647251762),
time: None,
include_time: None,
clear_flag: None,
@ -107,7 +107,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: None,
include_time: Some(true),
clear_flag: None,
@ -119,7 +119,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("9:00".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -131,7 +131,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("23:00".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -145,7 +145,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: None,
include_time: Some(true),
clear_flag: None,
@ -157,7 +157,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("9:00 AM".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -169,7 +169,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("11:23 pm".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -182,25 +182,6 @@ mod tests {
}
}
#[test]
fn date_type_option_invalid_date_str_test() {
let field_type = FieldType::DateTime;
let type_option = DateTypeOption::test();
let field = FieldBuilder::from_field_type(field_type).build();
assert_date(
&type_option,
&field,
DateCellChangeset {
date: Some("abc".to_owned()),
time: None,
include_time: None,
clear_flag: None,
},
None,
"",
);
}
#[test]
#[should_panic]
fn date_type_option_invalid_include_time_str_test() {
@ -212,7 +193,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("1:".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -233,7 +214,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -252,7 +233,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("00:00".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -273,7 +254,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("1:00 am".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -297,7 +278,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1653609600".to_owned()),
date: Some(1653609600),
time: Some("20:00".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -345,7 +326,7 @@ mod tests {
let old_cell_data = initialize_date_cell(
&type_option,
DateCellChangeset {
date: Some("1700006400".to_owned()),
date: Some(1700006400),
time: Some("08:00".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -355,7 +336,7 @@ mod tests {
&type_option,
&field,
DateCellChangeset {
date: Some("1701302400".to_owned()),
date: Some(1701302400),
time: None,
include_time: None,
clear_flag: None,
@ -373,7 +354,7 @@ mod tests {
let old_cell_data = initialize_date_cell(
&type_option,
DateCellChangeset {
date: Some("1700006400".to_owned()),
date: Some(1700006400),
time: Some("08:00".to_owned()),
include_time: Some(true),
clear_flag: None,
@ -401,7 +382,7 @@ mod tests {
let old_cell_data = initialize_date_cell(
&type_option,
DateCellChangeset {
date: Some("1700006400".to_owned()),
date: Some(1700006400),
time: Some("08:00".to_owned()),
include_time: Some(true),
clear_flag: None,

View File

@ -256,7 +256,7 @@ impl CellDataChangeset for DateTypeOption {
// order to change the day without changing the time, the old time string
// should be passed in as well.
let changeset_timestamp = changeset.date_timestamp();
let changeset_timestamp = changeset.date;
// parse the time string, which is in the local timezone
let parsed_time = match (include_time, changeset.time) {

View File

@ -18,18 +18,12 @@ use crate::services::field::{TypeOptionCellData, CELL_DATA};
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct DateCellChangeset {
pub date: Option<String>,
pub date: Option<i64>,
pub time: Option<String>,
pub include_time: Option<bool>,
pub clear_flag: Option<bool>,
}
impl DateCellChangeset {
pub fn date_timestamp(&self) -> Option<i64> {
self.date.as_ref().and_then(|date| date.parse::<i64>().ok())
}
}
impl FromCellChangeset for DateCellChangeset {
fn from_changeset(changeset: String) -> FlowyResult<Self>
where

View File

@ -26,7 +26,7 @@ async fn grid_cell_update() {
FieldType::RichText => "".to_string(),
FieldType::Number => "123".to_string(),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
make_date_cell_string("123")
make_date_cell_string(123)
},
FieldType::SingleSelect => {
let type_option = field

View File

@ -322,13 +322,13 @@ impl<'a> TestRowBuilder<'a> {
pub fn insert_date_cell(
&mut self,
data: &str,
data: i64,
time: Option<String>,
include_time: Option<bool>,
field_type: &FieldType,
) -> String {
let value = serde_json::to_string(&DateCellChangeset {
date: Some(data.to_string()),
date: Some(data),
time,
include_time,
clear_flag: None,

View File

@ -78,9 +78,9 @@ pub fn create_date_field(grid_id: &str, field_type: FieldType) -> (CreateFieldPa
// The grid will contains all existing field types and there are three empty rows in this grid.
pub fn make_date_cell_string(s: &str) -> String {
pub fn make_date_cell_string(timestamp: i64) -> String {
serde_json::to_string(&DateCellChangeset {
date: Some(s.to_string()),
date: Some(timestamp),
time: None,
include_time: Some(false),
clear_flag: None,

View File

@ -129,7 +129,7 @@ pub fn make_test_board() -> DatabaseData {
FieldType::Number => row_builder.insert_number_cell("1"),
// 1647251762 => Mar 14,2022
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1647251762", None, None, &field_type)
row_builder.insert_date_cell(1647251762, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(0))
@ -149,7 +149,7 @@ pub fn make_test_board() -> DatabaseData {
FieldType::Number => row_builder.insert_number_cell("2"),
// 1647251762 => Mar 14,2022
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1647251762", None, None, &field_type)
row_builder.insert_date_cell(1647251762, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(0))
@ -168,7 +168,7 @@ pub fn make_test_board() -> DatabaseData {
FieldType::Number => row_builder.insert_number_cell("3"),
// 1647251762 => Mar 14,2022
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1647251762", None, None, &field_type)
row_builder.insert_date_cell(1647251762, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(1))
@ -190,7 +190,7 @@ pub fn make_test_board() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell("DA"),
FieldType::Number => row_builder.insert_number_cell("4"),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1668704685", None, None, &field_type)
row_builder.insert_date_cell(1668704685, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(1))
@ -207,7 +207,7 @@ pub fn make_test_board() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell("AE"),
FieldType::Number => row_builder.insert_number_cell(""),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1668359085", None, None, &field_type)
row_builder.insert_date_cell(1668359085, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(2))

View File

@ -51,7 +51,7 @@ pub fn make_test_calendar() -> DatabaseData {
match field_type {
FieldType::RichText => row_builder.insert_text_cell("A"),
FieldType::DateTime => {
row_builder.insert_date_cell("1678090778", None, None, &field_type)
row_builder.insert_date_cell(1678090778, None, None, &field_type)
},
_ => "".to_owned(),
};
@ -62,7 +62,7 @@ pub fn make_test_calendar() -> DatabaseData {
match field_type {
FieldType::RichText => row_builder.insert_text_cell("B"),
FieldType::DateTime => {
row_builder.insert_date_cell("1677917978", None, None, &field_type)
row_builder.insert_date_cell(1677917978, None, None, &field_type)
},
_ => "".to_owned(),
};
@ -73,7 +73,7 @@ pub fn make_test_calendar() -> DatabaseData {
match field_type {
FieldType::RichText => row_builder.insert_text_cell("C"),
FieldType::DateTime => {
row_builder.insert_date_cell("1679213978", None, None, &field_type)
row_builder.insert_date_cell(1679213978, None, None, &field_type)
},
_ => "".to_owned(),
};
@ -84,7 +84,7 @@ pub fn make_test_calendar() -> DatabaseData {
match field_type {
FieldType::RichText => row_builder.insert_text_cell("D"),
FieldType::DateTime => {
row_builder.insert_date_cell("1678695578", None, None, &field_type)
row_builder.insert_date_cell(1678695578, None, None, &field_type)
},
_ => "".to_owned(),
};
@ -95,7 +95,7 @@ pub fn make_test_calendar() -> DatabaseData {
match field_type {
FieldType::RichText => row_builder.insert_text_cell("E"),
FieldType::DateTime => {
row_builder.insert_date_cell("1678695578", None, None, &field_type)
row_builder.insert_date_cell(1678695578, None, None, &field_type)
},
_ => "".to_owned(),
};

View File

@ -130,7 +130,7 @@ pub fn make_test_grid() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell("A"),
FieldType::Number => row_builder.insert_number_cell("1"),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1647251762", None, None, &field_type)
row_builder.insert_date_cell(1647251762, None, None, &field_type)
},
FieldType::MultiSelect => row_builder
.insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
@ -151,7 +151,7 @@ pub fn make_test_grid() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell(""),
FieldType::Number => row_builder.insert_number_cell("2"),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1647251762", None, None, &field_type)
row_builder.insert_date_cell(1647251762, None, None, &field_type)
},
FieldType::MultiSelect => row_builder
.insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(1)]),
@ -166,7 +166,7 @@ pub fn make_test_grid() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell("C"),
FieldType::Number => row_builder.insert_number_cell("3"),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1647251762", None, None, &field_type)
row_builder.insert_date_cell(1647251762, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(0))
@ -185,7 +185,7 @@ pub fn make_test_grid() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell("DA"),
FieldType::Number => row_builder.insert_number_cell("14"),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1668704685", None, None, &field_type)
row_builder.insert_date_cell(1668704685, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(0))
@ -201,7 +201,7 @@ pub fn make_test_grid() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell("AE"),
FieldType::Number => row_builder.insert_number_cell(""),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1668359085", None, None, &field_type)
row_builder.insert_date_cell(1668359085, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(1))
@ -219,7 +219,7 @@ pub fn make_test_grid() -> DatabaseData {
FieldType::RichText => row_builder.insert_text_cell("AE"),
FieldType::Number => row_builder.insert_number_cell("5"),
FieldType::DateTime | FieldType::LastEditedTime | FieldType::CreatedTime => {
row_builder.insert_date_cell("1671938394", None, None, &field_type)
row_builder.insert_date_cell(1671938394, None, None, &field_type)
},
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(1))

View File

@ -524,11 +524,10 @@ async fn update_date_cell_event_test() {
// Insert data into the date cell of the first row.
let timestamp = 1686300557;
let timestamp_str = 1686300557.to_string();
let error = test
.update_date_cell(DateChangesetPB {
cell_id: cell_path,
date: Some(timestamp_str.clone()),
date: Some(timestamp.clone()),
time: None,
include_time: None,
clear_flag: None,
@ -566,7 +565,7 @@ async fn update_date_cell_event_with_empty_time_str_test() {
let error = test
.update_date_cell(DateChangesetPB {
cell_id: cell_path,
date: Some("".to_string()),
date: None,
..Default::default()
})
.await;
@ -885,7 +884,6 @@ async fn create_calendar_event_test() {
let row = test.create_row(&calendar_view.id, None, None).await;
// Insert data into the date cell of the first row.
let timestamp_str = timestamp().to_string();
let error = test
.update_date_cell(DateChangesetPB {
cell_id: CellIdPB {
@ -893,7 +891,7 @@ async fn create_calendar_event_test() {
field_id: date_field.id.clone(),
row_id: row.id,
},
date: Some(timestamp_str.clone()),
date: Some(timestamp()),
time: None,
include_time: None,
clear_flag: None,