mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-25 07:07:32 -04:00
fix: create a new property from grid
This commit is contained in:
parent
ad9a4b7d71
commit
299e771877
3 changed files with 28 additions and 5 deletions
|
@ -156,23 +156,46 @@ abstract class IFieldTypeOptionLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Uses when creating a new field
|
||||||
class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
||||||
|
FieldTypeOptionDataPB? fieldTypeOption;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String gridId;
|
final String gridId;
|
||||||
NewFieldTypeOptionLoader({
|
NewFieldTypeOptionLoader({
|
||||||
required this.gridId,
|
required this.gridId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// Creates the field type option if the fieldTypeOption is null.
|
||||||
|
/// Otherwise, it loads the type option data from the backend.
|
||||||
@override
|
@override
|
||||||
Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
|
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()
|
final payload = CreateFieldPayloadPB.create()
|
||||||
..gridId = gridId
|
..gridId = gridId
|
||||||
..fieldType = FieldType.RichText;
|
..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 {
|
class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
||||||
@override
|
@override
|
||||||
final String gridId;
|
final String gridId;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:app_flowy/plugins/grid/application/field/field_controller.dart';
|
import 'package:app_flowy/plugins/grid/application/field/field_controller.dart';
|
||||||
import 'package:flowy_infra/notifier.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-error/errors.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
||||||
import 'package:app_flowy/plugins/grid/application/field/field_service.dart';
|
import 'package:app_flowy/plugins/grid/application/field/field_service.dart';
|
||||||
|
|
|
@ -195,7 +195,6 @@ class CreateFieldButton extends StatelessWidget {
|
||||||
popupBuilder: (BuildContext popover) {
|
popupBuilder: (BuildContext popover) {
|
||||||
return FieldEditor(
|
return FieldEditor(
|
||||||
gridId: gridId,
|
gridId: gridId,
|
||||||
fieldName: "",
|
|
||||||
typeOptionLoader: NewFieldTypeOptionLoader(gridId: gridId),
|
typeOptionLoader: NewFieldTypeOptionLoader(gridId: gridId),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue