Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: create a new property from grid

nathan299e771877c9
diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart
index 327edf9def..f644f4d2a0 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart
+++ b/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;
diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart
index d11a35e764..bcb308c20f 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart
+++ b/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';
diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart
index 735a179c1e..f155fdd88c 100644
--- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/grid_header.dart
+++ b/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),
);
},