mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: number sort (#2507)
This commit is contained in:
parent
bd5250ae2f
commit
cf27409c8d
@ -216,7 +216,17 @@ impl TypeOptionCellDataCompare for NumberTypeOptionPB {
|
||||
cell_data: &<Self as TypeOption>::CellData,
|
||||
other_cell_data: &<Self as TypeOption>::CellData,
|
||||
) -> 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 {
|
||||
|
@ -161,7 +161,7 @@ pub fn make_test_grid() -> BuildDatabaseContext {
|
||||
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"),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
|
@ -212,7 +212,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_rev: number_field.clone(),
|
||||
@ -220,7 +220,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