Sfoglia il codice sorgente

fix: create a new property from grid

nathan 2 anni fa
parent
commit
299e771877

+ 28 - 5
frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart

@@ -156,23 +156,46 @@ abstract class IFieldTypeOptionLoader {
   }
 }
 
+/// Uses when creating a new field
 class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
+  FieldTypeOptionDataPB? fieldTypeOption;
+
   @override
   final String gridId;
   NewFieldTypeOptionLoader({
     required this.gridId,
   });
 
+  /// Creates the field type option if the fieldTypeOption is null.
+  /// Otherwise, it loads the type option data from the backend.
   @override
   Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
-    final payload = CreateFieldPayloadPB.create()
-      ..gridId = gridId
-      ..fieldType = FieldType.RichText;
-
-    return GridEventCreateFieldTypeOption(payload).send();
+    if (fieldTypeOption != null) {
+      final payload = FieldTypeOptionIdPB.create()
+        ..gridId = gridId
+        ..fieldId = fieldTypeOption!.field_2.id
+        ..fieldType = fieldTypeOption!.field_2.fieldType;
+
+      return GridEventGetFieldTypeOption(payload).send();
+    } else {
+      final payload = CreateFieldPayloadPB.create()
+        ..gridId = gridId
+        ..fieldType = FieldType.RichText;
+
+      return GridEventCreateFieldTypeOption(payload).send().then((result) {
+        return result.fold(
+          (newFieldTypeOption) {
+            fieldTypeOption = newFieldTypeOption;
+            return left(newFieldTypeOption);
+          },
+          (err) => right(err),
+        );
+      });
+    }
   }
 }
 
+/// Uses when editing a existing field
 class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
   @override
   final String gridId;

+ 1 - 0
frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart

@@ -1,5 +1,6 @@
 import 'package:app_flowy/plugins/grid/application/field/field_controller.dart';
 import 'package:flowy_infra/notifier.dart';
+import 'package:flowy_sdk/dispatch/dispatch.dart';
 import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
 import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
 import 'package:app_flowy/plugins/grid/application/field/field_service.dart';

+ 0 - 1
frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart

@@ -195,7 +195,6 @@ class CreateFieldButton extends StatelessWidget {
       popupBuilder: (BuildContext popover) {
         return FieldEditor(
           gridId: gridId,
-          fieldName: "",
           typeOptionLoader: NewFieldTypeOptionLoader(gridId: gridId),
         );
       },