Ver código fonte

fix: format number in percent format

appflowy 2 anos atrás
pai
commit
602f7e7b6c

+ 5 - 2
frontend/app_flowy/lib/plugins/grid/application/field/type_option/number_format_bloc.dart

@@ -11,7 +11,10 @@ class NumberFormatBloc extends Bloc<NumberFormatEvent, NumberFormatState> {
         event.map(setFilter: (_SetFilter value) {
           final List<NumberFormat> formats = List.from(NumberFormat.values);
           if (value.filter.isNotEmpty) {
-            formats.retainWhere((element) => element.title().toLowerCase().contains(value.filter.toLowerCase()));
+            formats.retainWhere((element) => element
+                .title()
+                .toLowerCase()
+                .contains(value.filter.toLowerCase()));
           }
           emit(state.copyWith(formats: formats, filter: value.filter));
         });
@@ -91,7 +94,7 @@ extension NumberFormatExtension on NumberFormat {
       case NumberFormat.Percent:
         return "Percent";
       case NumberFormat.PhilippinePeso:
-        return "Percent";
+        return "PhilippinePeso";
       case NumberFormat.Pound:
         return "Pound";
       case NumberFormat.Rand:

+ 10 - 1
frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/format.rs

@@ -70,6 +70,15 @@ define_currency_set!(
             symbol: "RUB",
             symbol_first: false,
         },
+        PERCENT : {
+            code: "",
+            exponent: 2,
+            locale: EnIn,
+            minor_units: 1,
+            name: "percent",
+            symbol: "%",
+            symbol_first: false,
+        },
         USD : {
             code: "USD",
             exponent: 2,
@@ -435,7 +444,7 @@ impl NumberFormat {
             NumberFormat::Leu => number_currency::RON,
             NumberFormat::ArgentinePeso => number_currency::ARS,
             NumberFormat::UruguayanPeso => number_currency::UYU,
-            NumberFormat::Percent => number_currency::USD,
+            NumberFormat::Percent => number_currency::PERCENT,
         }
     }
 

+ 5 - 0
frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_tests.rs

@@ -93,6 +93,11 @@ mod tests {
                     assert_number(&type_option, "€0.5", "€0,5", &field_type, &field_rev);
                     assert_number(&type_option, "€1844", "€1.844", &field_type, &field_rev);
                 }
+                NumberFormat::Percent => {
+                    assert_number(&type_option, "1", "1%", &field_type, &field_rev);
+                    assert_number(&type_option, "10.1", "10.1%", &field_type, &field_rev);
+                    assert_number(&type_option, "100", "100%", &field_type, &field_rev);
+                }
                 _ => {}
             }
         }

+ 1 - 1
frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_type_option.rs

@@ -77,7 +77,7 @@ impl NumberTypeOptionPB {
 
     pub(crate) fn format_cell_data(&self, s: &str) -> FlowyResult<NumberCellData> {
         match self.format {
-            NumberFormat::Num | NumberFormat::Percent => match Decimal::from_str(s) {
+            NumberFormat::Num => match Decimal::from_str(s) {
                 Ok(value, ..) => Ok(NumberCellData::from_decimal(value)),
                 Err(_) => Ok(NumberCellData::new()),
             },