mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
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:
@ -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>,
|
||||
|
@ -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?;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user