feat: reorder sort precedence (#4592)

* feat: reorder sorts

* chore: add tests, fix tests, fix tauri build and fix clippy

* fix: add missing import
This commit is contained in:
Richard Shiue
2024-02-05 13:52:59 +08:00
committed by GitHub
parent fda70ff560
commit a515715543
28 changed files with 589 additions and 134 deletions

View File

@ -47,3 +47,55 @@ async fn sort_checkbox_and_then_text_by_descending_test() {
];
test.run_scripts(scripts).await;
}
#[tokio::test]
async fn reorder_sort_test() {
let mut test = DatabaseSortTest::new().await;
let checkbox_field = test.get_first_field(FieldType::Checkbox);
let text_field = test.get_first_field(FieldType::RichText);
// Use the same sort set up as above
let scripts = vec![
AssertCellContentOrder {
field_id: checkbox_field.id.clone(),
orders: vec!["Yes", "Yes", "No", "No", "No", "Yes", ""],
},
AssertCellContentOrder {
field_id: text_field.id.clone(),
orders: vec!["A", "", "C", "DA", "AE", "AE", "CB"],
},
InsertSort {
field: checkbox_field.clone(),
condition: SortCondition::Descending,
},
InsertSort {
field: text_field.clone(),
condition: SortCondition::Ascending,
},
AssertCellContentOrder {
field_id: checkbox_field.id.clone(),
orders: vec!["Yes", "Yes", "Yes", "No", "No", "", "No"],
},
AssertCellContentOrder {
field_id: text_field.id.clone(),
orders: vec!["A", "AE", "", "AE", "C", "CB", "DA"],
},
];
test.run_scripts(scripts).await;
let sorts = test.editor.get_all_sorts(&test.view_id).await.items;
let scripts = vec![
ReorderSort {
from_sort_id: sorts[1].id.clone(),
to_sort_id: sorts[0].id.clone(),
},
AssertCellContentOrder {
field_id: checkbox_field.id.clone(),
orders: vec!["Yes", "Yes", "No", "No", "", "No", "Yes"],
},
AssertCellContentOrder {
field_id: text_field.id.clone(),
orders: vec!["A", "AE", "AE", "C", "CB", "DA", ""],
},
];
test.run_scripts(scripts).await;
}

View File

@ -7,10 +7,12 @@ use collab_database::rows::RowId;
use futures::stream::StreamExt;
use tokio::sync::broadcast::Receiver;
use flowy_database2::entities::{DeleteSortPayloadPB, FieldType, UpdateSortPayloadPB};
use flowy_database2::entities::{
DeleteSortPayloadPB, FieldType, ReorderSortPayloadPB, UpdateSortPayloadPB,
};
use flowy_database2::services::cell::stringify_cell_data;
use flowy_database2::services::database_view::DatabaseViewChanged;
use flowy_database2::services::sort::{Sort, SortCondition};
use flowy_database2::services::sort::SortCondition;
use crate::database::database_editor::DatabaseEditorTest;
@ -19,6 +21,10 @@ pub enum SortScript {
field: Field,
condition: SortCondition,
},
ReorderSort {
from_sort_id: String,
to_sort_id: String,
},
DeleteSort {
sort_id: String,
},
@ -41,7 +47,6 @@ pub enum SortScript {
pub struct DatabaseSortTest {
inner: DatabaseEditorTest,
pub current_sort_rev: Option<Sort>,
recv: Option<Receiver<DatabaseViewChanged>>,
}
@ -50,7 +55,6 @@ impl DatabaseSortTest {
let editor_test = DatabaseEditorTest::new_grid().await;
Self {
inner: editor_test,
current_sort_rev: None,
recv: None,
}
}
@ -77,8 +81,25 @@ impl DatabaseSortTest {
field_type: FieldType::from(field.field_type),
condition: condition.into(),
};
let sort_rev = self.editor.create_or_update_sort(params).await.unwrap();
self.current_sort_rev = Some(sort_rev);
let _ = self.editor.create_or_update_sort(params).await.unwrap();
},
SortScript::ReorderSort {
from_sort_id,
to_sort_id,
} => {
self.recv = Some(
self
.editor
.subscribe_view_changed(&self.view_id)
.await
.unwrap(),
);
let params = ReorderSortPayloadPB {
view_id: self.view_id.clone(),
from_sort_id,
to_sort_id,
};
self.editor.reorder_sort(params).await.unwrap();
},
SortScript::DeleteSort { sort_id } => {
self.recv = Some(
@ -93,7 +114,6 @@ impl DatabaseSortTest {
sort_id,
};
self.editor.delete_sort(params).await.unwrap();
self.current_sort_rev = None;
},
SortScript::AssertCellContentOrder { field_id, orders } => {
let mut cells = vec![];

View File

@ -85,16 +85,21 @@ async fn sort_change_notification_by_update_text_test() {
async fn sort_text_by_ascending_and_delete_sort_test() {
let mut test = DatabaseSortTest::new().await;
let text_field = test.get_first_field(FieldType::RichText).clone();
let scripts = vec![InsertSort {
field: text_field.clone(),
condition: SortCondition::Ascending,
}];
test.run_scripts(scripts).await;
let sort = test.current_sort_rev.as_ref().unwrap();
let scripts = vec![
DeleteSort {
sort_id: sort.id.clone(),
InsertSort {
field: text_field.clone(),
condition: SortCondition::Ascending,
},
AssertCellContentOrder {
field_id: text_field.id.clone(),
orders: vec!["A", "AE", "AE", "C", "CB", "DA", ""],
},
];
test.run_scripts(scripts).await;
let sort = test.editor.get_all_sorts(&test.view_id).await.items[0].clone();
let scripts = vec![
DeleteSort { sort_id: sort.id },
AssertCellContentOrder {
field_id: text_field.id.clone(),
orders: vec!["A", "", "C", "DA", "AE", "AE", "CB"],