mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: create a new property from grid
This commit is contained in:
parent
ad9a4b7d71
commit
299e771877
@ -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() {
|
||||
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();
|
||||
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,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';
|
||||
|
@ -195,7 +195,6 @@ class CreateFieldButton extends StatelessWidget {
|
||||
popupBuilder: (BuildContext popover) {
|
||||
return FieldEditor(
|
||||
gridId: gridId,
|
||||
fieldName: "",
|
||||
typeOptionLoader: NewFieldTypeOptionLoader(gridId: gridId),
|
||||
);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user