feat: add basic relation field (#4397)

* feat: add basic relation field

* fix: clippy

* fix: tauri build 🤞

* chore: merge changes

* fix: merge main

* chore: initial code review pass

* fix: rust-lib test

* chore: code cleanup

* fix: unwrap or default
This commit is contained in:
Richard Shiue
2024-02-29 14:38:18 +08:00
committed by GitHub
parent f826d05f03
commit f4ca3ef782
54 changed files with 1804 additions and 34 deletions

View File

@ -3,7 +3,8 @@ use std::time::Duration;
use flowy_database2::entities::FieldType;
use flowy_database2::services::field::{
ChecklistCellChangeset, DateCellChangeset, DateCellData, MultiSelectTypeOption,
SelectOptionCellChangeset, SingleSelectTypeOption, StrCellData, URLCellData,
RelationCellChangeset, SelectOptionCellChangeset, SingleSelectTypeOption, StrCellData,
URLCellData,
};
use lib_infra::box_any::BoxAny;
@ -52,6 +53,10 @@ async fn grid_cell_update() {
}),
FieldType::Checkbox => BoxAny::new("1".to_string()),
FieldType::URL => BoxAny::new("1".to_string()),
FieldType::Relation => BoxAny::new(RelationCellChangeset {
inserted_row_ids: vec!["abcdefabcdef".to_string().into()],
..Default::default()
}),
_ => BoxAny::new("".to_string()),
};

View File

@ -5,8 +5,8 @@ use strum::IntoEnumIterator;
use flowy_database2::entities::FieldType;
use flowy_database2::services::field::checklist_type_option::ChecklistTypeOption;
use flowy_database2::services::field::{
DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption, SelectOption, SelectOptionColor,
SingleSelectTypeOption, TimeFormat, TimestampTypeOption,
DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption, RelationTypeOption,
SelectOption, SelectOptionColor, SingleSelectTypeOption, TimeFormat, TimestampTypeOption,
};
use flowy_database2::services::field_settings::default_field_settings_for_fields;
use flowy_database2::services::setting::BoardLayoutSetting;
@ -126,6 +126,16 @@ pub fn make_test_board() -> DatabaseData {
.build();
fields.push(checklist_field);
},
FieldType::Relation => {
let type_option = RelationTypeOption {
database_id: "".to_string(),
};
let relation_field = FieldBuilder::new(field_type, type_option)
.name("Related")
.visibility(true)
.build();
fields.push(relation_field);
},
}
}
@ -227,7 +237,6 @@ pub fn make_test_board() -> DatabaseData {
FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(2))
},
FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
_ => "".to_owned(),
};

View File

@ -3,10 +3,10 @@ use collab_database::views::{DatabaseLayout, DatabaseView};
use strum::IntoEnumIterator;
use flowy_database2::entities::FieldType;
use flowy_database2::services::field::checklist_type_option::ChecklistTypeOption;
use flowy_database2::services::field::{
DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption, NumberFormat, NumberTypeOption,
SelectOption, SelectOptionColor, SingleSelectTypeOption, TimeFormat, TimestampTypeOption,
ChecklistTypeOption, DateFormat, DateTypeOption, FieldBuilder, MultiSelectTypeOption,
NumberFormat, NumberTypeOption, RelationTypeOption, SelectOption, SelectOptionColor,
SingleSelectTypeOption, TimeFormat, TimestampTypeOption,
};
use flowy_database2::services::field_settings::default_field_settings_for_fields;
@ -128,6 +128,16 @@ pub fn make_test_grid() -> DatabaseData {
.build();
fields.push(checklist_field);
},
FieldType::Relation => {
let type_option = RelationTypeOption {
database_id: "".to_string(),
};
let relation_field = FieldBuilder::new(field_type, type_option)
.name("Related")
.visibility(true)
.build();
fields.push(relation_field);
},
}
}

View File

@ -27,14 +27,14 @@ async fn export_csv_test() {
let test = DatabaseEditorTest::new_grid().await;
let database = test.editor.clone();
let s = database.export_csv(CSVFormat::Original).await.unwrap();
let expected = r#"Name,Price,Time,Status,Platform,is urgent,link,TODO,Last Modified,Created At
A,$1,2022/03/14,,"Google,Facebook",Yes,AppFlowy website - https://www.appflowy.io,First thing,,
,$2,2022/03/14,,"Google,Twitter",Yes,,"Have breakfast,Have lunch,Take a nap,Have dinner,Shower and head to bed",,
C,$3,2022/03/14,Completed,"Facebook,Google,Twitter",No,,,,
DA,$14,2022/11/17,Completed,,No,,Task 1,,
AE,,2022/11/13,Planned,"Facebook,Twitter",No,,,,
AE,$5,2022/12/25,Planned,Facebook,Yes,,"Sprint,Sprint some more,Rest",,
CB,,,,,,,,,
let expected = r#"Name,Price,Time,Status,Platform,is urgent,link,TODO,Last Modified,Created At,Related
A,$1,2022/03/14,,"Google,Facebook",Yes,AppFlowy website - https://www.appflowy.io,First thing,,,
,$2,2022/03/14,,"Google,Twitter",Yes,,"Have breakfast,Have lunch,Take a nap,Have dinner,Shower and head to bed",,,
C,$3,2022/03/14,Completed,"Facebook,Google,Twitter",No,,,,,
DA,$14,2022/11/17,Completed,,No,,Task 1,,,
AE,,2022/11/13,Planned,"Facebook,Twitter",No,,,,,
AE,$5,2022/12/25,Planned,Facebook,Yes,,"Sprint,Sprint some more,Rest",,,
CB,,,,,,,,,,
"#;
println!("{}", s);
assert_eq!(s, expected);
@ -99,6 +99,7 @@ async fn export_and_then_import_meta_csv_test() {
FieldType::Checklist => {},
FieldType::LastEditedTime => {},
FieldType::CreatedTime => {},
FieldType::Relation => {},
}
} else {
panic!(
@ -180,6 +181,7 @@ async fn history_database_import_test() {
FieldType::Checklist => {},
FieldType::LastEditedTime => {},
FieldType::CreatedTime => {},
FieldType::Relation => {},
}
} else {
panic!(