mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: number sort (#2508)
This commit is contained in:
parent
2a35787dd1
commit
a2b592a59b
@ -243,7 +243,17 @@ impl TypeOptionCellDataCompare for NumberTypeOption {
|
||||
cell_data: &<Self as TypeOption>::CellData,
|
||||
other_cell_data: &<Self as TypeOption>::CellData,
|
||||
) -> Ordering {
|
||||
cell_data.0.cmp(&other_cell_data.0)
|
||||
let left = NumberCellFormat::from_format_str(&cell_data.0, self.sign_positive, &self.format);
|
||||
let right =
|
||||
NumberCellFormat::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 NumberTypeOption {
|
||||
|
@ -179,7 +179,7 @@ pub fn make_test_grid() -> DatabaseData {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
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",
|
||||
None,
|
||||
|
@ -213,7 +213,7 @@ async fn sort_number_by_descending_test() {
|
||||
let scripts = vec![
|
||||
AssertCellContentOrder {
|
||||
field_id: number_field.id.clone(),
|
||||
orders: vec!["$1", "$2", "$3", "$4", "", "$5"],
|
||||
orders: vec!["$1", "$2", "$3", "$14", "", "$5"],
|
||||
},
|
||||
InsertSort {
|
||||
field: number_field.clone(),
|
||||
@ -221,7 +221,7 @@ async fn sort_number_by_descending_test() {
|
||||
},
|
||||
AssertCellContentOrder {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user