diff --git a/frontend/app_flowy/assets/images/grid/field/checkbox.svg b/frontend/app_flowy/assets/images/grid/field/checkbox.svg
new file mode 100644
index 0000000000..37f52c47ed
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/field/checkbox.svg
@@ -0,0 +1,4 @@
+
diff --git a/frontend/app_flowy/assets/images/grid/field/checklist.svg b/frontend/app_flowy/assets/images/grid/field/checklist.svg
new file mode 100644
index 0000000000..3a88d236a1
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/field/checklist.svg
@@ -0,0 +1,4 @@
+
diff --git a/frontend/app_flowy/assets/images/grid/field/date.svg b/frontend/app_flowy/assets/images/grid/field/date.svg
new file mode 100644
index 0000000000..78243f1e75
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/field/date.svg
@@ -0,0 +1,6 @@
+
diff --git a/frontend/app_flowy/assets/images/grid/field/multi_select.svg b/frontend/app_flowy/assets/images/grid/field/multi_select.svg
new file mode 100644
index 0000000000..97a2e9c434
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/field/multi_select.svg
@@ -0,0 +1,8 @@
+
diff --git a/frontend/app_flowy/assets/images/grid/field/number.svg b/frontend/app_flowy/assets/images/grid/field/number.svg
new file mode 100644
index 0000000000..9d8b98d10d
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/field/number.svg
@@ -0,0 +1,3 @@
+
diff --git a/frontend/app_flowy/assets/images/grid/field/single_select.svg b/frontend/app_flowy/assets/images/grid/field/single_select.svg
new file mode 100644
index 0000000000..8ccbc9a2e3
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/field/single_select.svg
@@ -0,0 +1,4 @@
+
diff --git a/frontend/app_flowy/assets/images/grid/field/text.svg b/frontend/app_flowy/assets/images/grid/field/text.svg
new file mode 100644
index 0000000000..7befa5080f
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/field/text.svg
@@ -0,0 +1,4 @@
+
diff --git a/frontend/app_flowy/assets/images/grid/more.svg b/frontend/app_flowy/assets/images/grid/more.svg
new file mode 100644
index 0000000000..b191e64a10
--- /dev/null
+++ b/frontend/app_flowy/assets/images/grid/more.svg
@@ -0,0 +1,3 @@
+
diff --git a/frontend/app_flowy/assets/translations/en.json b/frontend/app_flowy/assets/translations/en.json
index 27574db94e..5646cdff58 100644
--- a/frontend/app_flowy/assets/translations/en.json
+++ b/frontend/app_flowy/assets/translations/en.json
@@ -148,7 +148,13 @@
"insertLeft": "Insert Left",
"insertRight": "Insert Right",
"duplicate": "Duplicate",
- "delete": "Delete"
+ "delete": "Delete",
+ "textFieldName": "Text",
+ "checkboxFieldName": "Number",
+ "dateFieldName": "Date",
+ "numberFieldName": "Number",
+ "singleSelectFieldName": "Select",
+ "multiSelectFieldName": "Multiselect"
}
}
}
diff --git a/frontend/app_flowy/lib/startup/home_deps_resolver.dart b/frontend/app_flowy/lib/startup/home_deps_resolver.dart
index 5c4fc6267f..1702544a64 100644
--- a/frontend/app_flowy/lib/startup/home_deps_resolver.dart
+++ b/frontend/app_flowy/lib/startup/home_deps_resolver.dart
@@ -103,15 +103,21 @@ class HomeDepsResolver {
getIt.registerFactoryParam>(
(gridId, fields) => GridHeaderBloc(
- data: GridColumnData(fields: fields),
- service: FieldService(),
+ data: GridHeaderData(gridId: gridId, fields: fields),
+ service: FieldService(gridId: gridId),
),
);
- getIt.registerFactoryParam(
- (field, _) => FieldEditBloc(
- field: field,
- service: FieldService(),
+ getIt.registerFactoryParam(
+ (data, _) => EditFieldBloc(
+ field: data.field,
+ service: FieldService(gridId: data.gridId),
+ ),
+ );
+
+ getIt.registerFactoryParam(
+ (gridId, _) => CreateFieldBloc(
+ service: FieldService(gridId: gridId),
),
);
diff --git a/frontend/app_flowy/lib/workspace/application/grid/data.dart b/frontend/app_flowy/lib/workspace/application/grid/data.dart
index ff1b1e3efc..7c508a6867 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/data.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/data.dart
@@ -1,7 +1,8 @@
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
-class GridColumnData {
+class GridHeaderData {
+ final String gridId;
final List fields;
- GridColumnData({required this.fields});
+ GridHeaderData({required this.gridId, required this.fields});
}
diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/create_field_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/create_field_bloc.dart
new file mode 100644
index 0000000000..0d9126cd1e
--- /dev/null
+++ b/frontend/app_flowy/lib/workspace/application/grid/field/create_field_bloc.dart
@@ -0,0 +1,47 @@
+import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:freezed_annotation/freezed_annotation.dart';
+import 'dart:async';
+import 'field_service.dart';
+import 'package:dartz/dartz.dart';
+
+part 'create_field_bloc.freezed.dart';
+
+class CreateFieldBloc extends Bloc {
+ final FieldService service;
+
+ CreateFieldBloc({required this.service}) : super(CreateFieldState.initial()) {
+ on(
+ (event, emit) async {
+ await event.map(
+ initial: (_InitialField value) {},
+ updateName: (_UpdateName value) {},
+ );
+ },
+ );
+ }
+
+ @override
+ Future close() async {
+ return super.close();
+ }
+}
+
+@freezed
+class CreateFieldEvent with _$CreateFieldEvent {
+ const factory CreateFieldEvent.initial() = _InitialField;
+ const factory CreateFieldEvent.updateName(String newName) = _UpdateName;
+}
+
+@freezed
+class CreateFieldState with _$CreateFieldState {
+ const factory CreateFieldState({
+ required String errorText,
+ required Option field,
+ }) = _CreateFieldState;
+
+ factory CreateFieldState.initial() => CreateFieldState(
+ field: none(),
+ errorText: '',
+ );
+}
diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/edit_field_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/edit_field_bloc.dart
new file mode 100644
index 0000000000..0944bdd1bb
--- /dev/null
+++ b/frontend/app_flowy/lib/workspace/application/grid/field/edit_field_bloc.dart
@@ -0,0 +1,54 @@
+import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:freezed_annotation/freezed_annotation.dart';
+import 'dart:async';
+import 'field_service.dart';
+
+part 'edit_field_bloc.freezed.dart';
+
+class EditFieldBloc extends Bloc {
+ final FieldService service;
+
+ EditFieldBloc({required Field field, required this.service}) : super(EditFieldState.initial(field)) {
+ on(
+ (event, emit) async {
+ await event.map(
+ initial: (_InitialField value) {},
+ updateFieldName: (_UpdateFieldName value) {
+ //
+ },
+ hideField: (_HideField value) {},
+ deleteField: (_DeleteField value) {},
+ duplicateField: (_DuplicateField value) {},
+ );
+ },
+ );
+ }
+
+ @override
+ Future close() async {
+ return super.close();
+ }
+}
+
+@freezed
+class EditFieldEvent with _$EditFieldEvent {
+ const factory EditFieldEvent.initial() = _InitialField;
+ const factory EditFieldEvent.updateFieldName(String name) = _UpdateFieldName;
+ const factory EditFieldEvent.hideField() = _HideField;
+ const factory EditFieldEvent.duplicateField() = _DuplicateField;
+ const factory EditFieldEvent.deleteField() = _DeleteField;
+}
+
+@freezed
+class EditFieldState with _$EditFieldState {
+ const factory EditFieldState({
+ required Field field,
+ required String errorText,
+ }) = _EditFieldState;
+
+ factory EditFieldState.initial(Field field) => EditFieldState(
+ field: field,
+ errorText: '',
+ );
+}
diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_edit_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_edit_bloc.dart
deleted file mode 100644
index 2d4aea16da..0000000000
--- a/frontend/app_flowy/lib/workspace/application/grid/field/field_edit_bloc.dart
+++ /dev/null
@@ -1,58 +0,0 @@
-import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:freezed_annotation/freezed_annotation.dart';
-import 'dart:async';
-import 'field_service.dart';
-
-part 'field_edit_bloc.freezed.dart';
-
-class FieldEditBloc extends Bloc {
- final FieldService service;
-
- FieldEditBloc({required Field field, required this.service}) : super(FieldEditState.initial(field)) {
- on(
- (event, emit) async {
- await event.map(
- initial: (_InitialField value) {},
- createField: (_CreateField value) {},
- updateFieldName: (_UpdateFieldName value) {
- //
- },
- hideField: (_HideField value) {},
- deleteField: (_DeleteField value) {},
- insertField: (_InsertField value) {},
- duplicateField: (_DuplicateField value) {},
- );
- },
- );
- }
-
- @override
- Future close() async {
- return super.close();
- }
-}
-
-@freezed
-class FieldEditEvent with _$FieldEditEvent {
- const factory FieldEditEvent.initial() = _InitialField;
- const factory FieldEditEvent.createField() = _CreateField;
- const factory FieldEditEvent.updateFieldName(String name) = _UpdateFieldName;
- const factory FieldEditEvent.hideField() = _HideField;
- const factory FieldEditEvent.duplicateField() = _DuplicateField;
- const factory FieldEditEvent.insertField({required bool onLeft}) = _InsertField;
- const factory FieldEditEvent.deleteField() = _DeleteField;
-}
-
-@freezed
-class FieldEditState with _$FieldEditState {
- const factory FieldEditState({
- required Field field,
- required String errorText,
- }) = _FieldEditState;
-
- factory FieldEditState.initial(Field field) => FieldEditState(
- field: field,
- errorText: '',
- );
-}
diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart
index 48d4aa21bd..5a8032b79a 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_service.dart
@@ -1 +1,99 @@
-class FieldService {}
+import 'dart:typed_data';
+
+import 'package:dartz/dartz.dart';
+import 'package:equatable/equatable.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-data-model/grid.pb.dart';
+import 'package:flowy_sdk/protobuf/flowy-grid/protobuf.dart';
+
+class FieldService {
+ final String gridId;
+
+ FieldService({required this.gridId});
+
+ Future> getDefaultField(
+ String gridId,
+ ) {
+ final payload = GridId.create()..value = gridId;
+ return GridEventCreateDefaultField(payload).send();
+ }
+
+ Future> createTextField(
+ String gridId,
+ Field field,
+ RichTextTypeOption typeOption,
+ String? startFieldId,
+ ) {
+ final typeOptionData = typeOption.writeToBuffer();
+ return _createField(gridId, field, typeOptionData, startFieldId);
+ }
+
+ Future> createSingleSelectField(
+ String gridId,
+ Field field,
+ SingleSelectTypeOption typeOption,
+ String? startFieldId,
+ ) {
+ final typeOptionData = typeOption.writeToBuffer();
+ return _createField(gridId, field, typeOptionData, startFieldId);
+ }
+
+ Future> createMultiSelectField(
+ String gridId,
+ Field field,
+ MultiSelectTypeOption typeOption,
+ String? startFieldId,
+ ) {
+ final typeOptionData = typeOption.writeToBuffer();
+ return _createField(gridId, field, typeOptionData, startFieldId);
+ }
+
+ Future> createNumberField(
+ String gridId,
+ Field field,
+ NumberTypeOption typeOption,
+ String? startFieldId,
+ ) {
+ final typeOptionData = typeOption.writeToBuffer();
+ return _createField(gridId, field, typeOptionData, startFieldId);
+ }
+
+ Future> createDateField(
+ String gridId,
+ Field field,
+ DateTypeOption typeOption,
+ String? startFieldId,
+ ) {
+ final typeOptionData = typeOption.writeToBuffer();
+ return _createField(gridId, field, typeOptionData, startFieldId);
+ }
+
+ Future> _createField(
+ String gridId,
+ Field field,
+ Uint8List typeOptionData,
+ String? startFieldId,
+ ) {
+ final payload = CreateFieldPayload.create()
+ ..gridId = gridId
+ ..field_2 = field
+ ..typeOptionData = typeOptionData
+ ..startFieldId = startFieldId ?? "";
+
+ return GridEventCreateField(payload).send();
+ }
+}
+
+class GridFieldData extends Equatable {
+ final String gridId;
+ final Field field;
+
+ const GridFieldData({
+ required this.gridId,
+ required this.field,
+ });
+
+ @override
+ List