瀏覽代碼

feat: switching from text type to checkbox type (#1626)

Kelvin 2 年之前
父節點
當前提交
273aaeec75

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

@@ -49,7 +49,29 @@ impl TypeOption for CheckboxTypeOptionPB {
     type CellFilter = CheckboxFilterPB;
 }
 
-impl TypeOptionTransform for CheckboxTypeOptionPB {}
+impl TypeOptionTransform for CheckboxTypeOptionPB {
+    fn transformable(&self) -> bool {
+        true
+    }
+
+    fn transform_type_option(&mut self, _old_type_option_field_type: FieldType, _old_type_option_data: String) {}
+
+    fn transform_type_option_cell_str(
+        &self,
+        cell_str: &str,
+        decoded_field_type: &FieldType,
+        _field_rev: &FieldRevision,
+    ) -> Option<<Self as TypeOption>::CellData> {
+        if decoded_field_type.is_text() {
+            match CheckboxCellData::from_str(&cell_str) {
+                Ok(cell_data) => Some(cell_data),
+                Err(_) => None,
+            }
+        } else {
+            None
+        }
+    }
+}
 
 impl TypeOptionCellData for CheckboxTypeOptionPB {
     fn convert_to_protobuf(&self, cell_data: <Self as TypeOption>::CellData) -> <Self as TypeOption>::CellProtobufType {