fix: number sort (#2507)

This commit is contained in:
Nathan.fooo 2023-05-11 18:35:36 +08:00 committed by GitHub
parent bd5250ae2f
commit cf27409c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -216,7 +216,17 @@ impl TypeOptionCellDataCompare for NumberTypeOptionPB {
cell_data: &<Self as TypeOption>::CellData, cell_data: &<Self as TypeOption>::CellData,
other_cell_data: &<Self as TypeOption>::CellData, other_cell_data: &<Self as TypeOption>::CellData,
) -> Ordering { ) -> Ordering {
cell_data.0.cmp(&other_cell_data.0) let left = NumberCellData::from_format_str(&cell_data.0, self.sign_positive, &self.format);
let right =
NumberCellData::from_format_str(&other_cell_data.0, self.sign_positive, &self.format);
match (left, right) {
(Ok(left), Ok(right)) => {
return left.decimal().cmp(&right.decimal());
},
(Ok(_), Err(_)) => Ordering::Greater,
(Err(_), Ok(_)) => Ordering::Less,
(Err(_), Err(_)) => Ordering::Equal,
}
} }
} }
impl std::default::Default for NumberTypeOptionPB { impl std::default::Default for NumberTypeOptionPB {

View File

@ -161,7 +161,7 @@ pub fn make_test_grid() -> BuildDatabaseContext {
for field_type in FieldType::iter() { for field_type in FieldType::iter() {
match field_type { match field_type {
FieldType::RichText => row_builder.insert_text_cell("DA"), FieldType::RichText => row_builder.insert_text_cell("DA"),
FieldType::Number => row_builder.insert_number_cell("4"), FieldType::Number => row_builder.insert_number_cell("14"),
FieldType::DateTime => row_builder.insert_date_cell("1668704685"), FieldType::DateTime => row_builder.insert_date_cell("1668704685"),
FieldType::SingleSelect => { FieldType::SingleSelect => {
row_builder.insert_single_select_cell(|mut options| options.remove(0)) row_builder.insert_single_select_cell(|mut options| options.remove(0))

View File

@ -212,7 +212,7 @@ async fn sort_number_by_descending_test() {
let scripts = vec![ let scripts = vec![
AssertCellContentOrder { AssertCellContentOrder {
field_id: number_field.id.clone(), field_id: number_field.id.clone(),
orders: vec!["$1", "$2", "$3", "$4", "", "$5"], orders: vec!["$1", "$2", "$3", "$14", "", "$5"],
}, },
InsertSort { InsertSort {
field_rev: number_field.clone(), field_rev: number_field.clone(),
@ -220,7 +220,7 @@ async fn sort_number_by_descending_test() {
}, },
AssertCellContentOrder { AssertCellContentOrder {
field_id: number_field.id.clone(), field_id: number_field.id.clone(),
orders: vec!["$5", "$4", "$3", "$2", "$1", ""], orders: vec!["$14", "$5", "$3", "$2", "$1", ""],
}, },
]; ];
test.run_scripts(scripts).await; test.run_scripts(scripts).await;