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
18 changed files with 159 additions and 197 deletions

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))