Browse Source

docs/update database documentation (#1824)

* chore: update event name

* chore: add events and notifications documentation & remove unused code
Nathan.fooo 2 years ago
parent
commit
e157c19174
56 changed files with 253 additions and 411 deletions
  1. 5 5
      frontend/app_flowy/lib/plugins/board/application/board_listener.dart
  2. 1 1
      frontend/app_flowy/lib/plugins/board/application/group_listener.dart
  3. 2 2
      frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_data_persistence.dart
  4. 1 1
      frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_service.dart
  5. 4 4
      frontend/app_flowy/lib/plugins/grid/application/cell/select_option_service.dart
  6. 1 1
      frontend/app_flowy/lib/plugins/grid/application/field/field_service.dart
  7. 1 1
      frontend/app_flowy/lib/plugins/grid/application/field/grid_listener.dart
  8. 5 5
      frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_context.dart
  9. 1 1
      frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_service.dart
  10. 2 2
      frontend/app_flowy/lib/plugins/grid/application/grid_service.dart
  11. 0 46
      frontend/app_flowy/lib/plugins/grid/application/row/row_listener.dart
  12. 2 2
      frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart
  13. 1 1
      frontend/app_flowy/lib/plugins/grid/application/setting/setting_listener.dart
  14. 2 2
      frontend/app_flowy/lib/plugins/grid/application/view/grid_view_listener.dart
  15. 1 1
      frontend/app_flowy/lib/plugins/trash/application/trash_listener.dart
  16. 3 12
      frontend/app_flowy/lib/user/application/user_listener.dart
  17. 1 1
      frontend/app_flowy/lib/workspace/application/app/app_listener.dart
  18. 4 4
      frontend/app_flowy/lib/workspace/application/view/view_listener.dart
  19. 2 2
      frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart
  20. 7 7
      frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
  21. 5 5
      frontend/rust-lib/flowy-database/src/entities/cell_entities.rs
  22. 2 2
      frontend/rust-lib/flowy-database/src/entities/field_entities.rs
  23. 2 2
      frontend/rust-lib/flowy-database/src/entities/group_entities/group.rs
  24. 2 2
      frontend/rust-lib/flowy-database/src/entities/group_entities/group_changeset.rs
  25. 5 5
      frontend/rust-lib/flowy-database/src/entities/row_entities.rs
  26. 21 21
      frontend/rust-lib/flowy-database/src/entities/setting_entities.rs
  27. 7 7
      frontend/rust-lib/flowy-database/src/event_handler.rs
  28. 18 21
      frontend/rust-lib/flowy-database/src/event_map.rs
  29. 2 2
      frontend/rust-lib/flowy-database/src/manager.rs
  30. 20 9
      frontend/rust-lib/flowy-database/src/notification.rs
  31. 2 2
      frontend/rust-lib/flowy-database/src/services/field/type_options/date_type_option/date_type_option_entities.rs
  32. 6 6
      frontend/rust-lib/flowy-database/src/services/field/type_options/selection_type_option/select_type_option.rs
  33. 7 3
      frontend/rust-lib/flowy-database/src/services/filter/controller.rs
  34. 8 8
      frontend/rust-lib/flowy-database/src/services/grid_editor.rs
  35. 2 2
      frontend/rust-lib/flowy-database/src/services/group/action.rs
  36. 3 3
      frontend/rust-lib/flowy-database/src/services/group/configuration.rs
  37. 2 2
      frontend/rust-lib/flowy-database/src/services/group/controller.rs
  38. 2 2
      frontend/rust-lib/flowy-database/src/services/group/controller_impls/default_controller.rs
  39. 2 2
      frontend/rust-lib/flowy-database/src/services/setting/setting_builder.rs
  40. 3 3
      frontend/rust-lib/flowy-database/src/services/sort/controller.rs
  41. 9 12
      frontend/rust-lib/flowy-database/src/services/view_editor/changed_notifier.rs
  42. 13 13
      frontend/rust-lib/flowy-database/src/services/view_editor/editor.rs
  43. 1 1
      frontend/rust-lib/flowy-database/src/services/view_editor/editor_manager.rs
  44. 4 4
      frontend/rust-lib/flowy-database/src/services/view_editor/trait_impl.rs
  45. 4 4
      frontend/rust-lib/flowy-database/tests/grid/block_test/script.rs
  46. 6 6
      frontend/rust-lib/flowy-database/tests/grid/database_editor.rs
  47. 4 4
      frontend/rust-lib/flowy-database/tests/grid/filter_test/script.rs
  48. 2 2
      frontend/rust-lib/flowy-database/tests/grid/group_test/script.rs
  49. 7 7
      frontend/rust-lib/flowy-database/tests/grid/sort_test/script.rs
  50. 1 3
      frontend/rust-lib/flowy-folder/src/manager.rs
  51. 22 13
      frontend/rust-lib/flowy-folder/src/notification.rs
  52. 2 31
      frontend/rust-lib/flowy-folder/src/services/app/controller.rs
  53. 1 1
      frontend/rust-lib/flowy-folder/src/services/trash/controller.rs
  54. 6 35
      frontend/rust-lib/flowy-folder/src/services/view/controller.rs
  55. 4 4
      frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs
  56. 0 61
      frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs

+ 5 - 5
frontend/app_flowy/lib/plugins/board/application/board_listener.dart

@@ -8,7 +8,7 @@ import 'package:dartz/dartz.dart';
 import 'package:appflowy_backend/protobuf/flowy-database/group.pb.dart';
 import 'package:appflowy_backend/protobuf/flowy-database/group_changeset.pb.dart';
 
-typedef GroupUpdateValue = Either<GroupViewChangesetPB, FlowyError>;
+typedef GroupUpdateValue = Either<GroupChangesetPB, FlowyError>;
 typedef GroupByNewFieldValue = Either<List<GroupPB>, FlowyError>;
 
 class BoardListener {
@@ -36,17 +36,17 @@ class BoardListener {
     Either<Uint8List, FlowyError> result,
   ) {
     switch (ty) {
-      case DatabaseNotification.DidUpdateGroupView:
+      case DatabaseNotification.DidUpdateGroups:
         result.fold(
           (payload) => _groupUpdateNotifier?.value =
-              left(GroupViewChangesetPB.fromBuffer(payload)),
+              left(GroupChangesetPB.fromBuffer(payload)),
           (error) => _groupUpdateNotifier?.value = right(error),
         );
         break;
-      case DatabaseNotification.DidGroupByNewField:
+      case DatabaseNotification.DidGroupByField:
         result.fold(
           (payload) => _groupByNewFieldNotifier?.value =
-              left(GroupViewChangesetPB.fromBuffer(payload).initialGroups),
+              left(GroupChangesetPB.fromBuffer(payload).initialGroups),
           (error) => _groupByNewFieldNotifier?.value = right(error),
         );
         break;

+ 1 - 1
frontend/app_flowy/lib/plugins/board/application/group_listener.dart

@@ -31,7 +31,7 @@ class GroupListener {
     Either<Uint8List, FlowyError> result,
   ) {
     switch (ty) {
-      case DatabaseNotification.DidUpdateGroup:
+      case DatabaseNotification.DidUpdateGroupRow:
         result.fold(
           (payload) => _groupNotifier?.value =
               left(GroupRowsNotificationPB.fromBuffer(payload)),

+ 2 - 2
frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_data_persistence.dart

@@ -60,8 +60,8 @@ class DateCellDataPersistence implements GridCellDataPersistence<CalendarData> {
   }
 }
 
-CellPathPB _makeCellPath(GridCellIdentifier cellId) {
-  return CellPathPB.create()
+CellIdPB _makeCellPath(GridCellIdentifier cellId) {
+  return CellIdPB.create()
     ..databaseId = cellId.databaseId
     ..fieldId = cellId.fieldId
     ..rowId = cellId.rowId;

+ 1 - 1
frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_service.dart

@@ -45,7 +45,7 @@ class CellService {
   Future<Either<CellPB, FlowyError>> getCell({
     required GridCellIdentifier cellId,
   }) {
-    final payload = CellPathPB.create()
+    final payload = CellIdPB.create()
       ..databaseId = cellId.databaseId
       ..fieldId = cellId.fieldId
       ..rowId = cellId.rowId;

+ 4 - 4
frontend/app_flowy/lib/plugins/grid/application/cell/select_option_service.dart

@@ -22,7 +22,7 @@ class SelectOptionFFIService {
       (result) {
         return result.fold(
           (option) {
-            final cellIdentifier = CellPathPB.create()
+            final cellIdentifier = CellIdPB.create()
               ..databaseId = databaseId
               ..fieldId = fieldId
               ..rowId = rowId;
@@ -61,7 +61,7 @@ class SelectOptionFFIService {
   }
 
   Future<Either<SelectOptionCellDataPB, FlowyError>> getOptionContext() {
-    final payload = CellPathPB.create()
+    final payload = CellIdPB.create()
       ..databaseId = databaseId
       ..fieldId = fieldId
       ..rowId = rowId;
@@ -85,8 +85,8 @@ class SelectOptionFFIService {
     return DatabaseEventUpdateSelectOptionCell(payload).send();
   }
 
-  CellPathPB _cellIdentifier() {
-    return CellPathPB.create()
+  CellIdPB _cellIdentifier() {
+    return CellIdPB.create()
       ..databaseId = databaseId
       ..fieldId = fieldId
       ..rowId = rowId;

+ 1 - 1
frontend/app_flowy/lib/plugins/grid/application/field/field_service.dart

@@ -97,7 +97,7 @@ class FieldService {
       ..databaseId = databaseId
       ..fieldId = fieldId
       ..fieldType = fieldType;
-    return DatabaseEventGetFieldTypeOption(payload).send().then((result) {
+    return DatabaseEventGetTypeOption(payload).send().then((result) {
       return result.fold(
         (data) => left(data),
         (err) => right(err),

+ 1 - 1
frontend/app_flowy/lib/plugins/grid/application/field/grid_listener.dart

@@ -27,7 +27,7 @@ class DatabaseFieldsListener {
 
   void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
     switch (ty) {
-      case DatabaseNotification.DidUpdateDatabaseFields:
+      case DatabaseNotification.DidUpdateFields:
         result.fold(
           (payload) => updateFieldsNotifier?.value =
               left(DatabaseFieldChangesetPB.fromBuffer(payload)),

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

@@ -160,12 +160,12 @@ abstract class IFieldTypeOptionLoader {
 
   Future<Either<Unit, FlowyError>> switchToField(
       String fieldId, FieldType fieldType) {
-    final payload = EditFieldChangesetPB.create()
+    final payload = UpdateFieldTypePayloadPB.create()
       ..databaseId = databaseId
       ..fieldId = fieldId
       ..fieldType = fieldType;
 
-    return DatabaseEventSwitchToField(payload).send();
+    return DatabaseEventUpdateFieldType(payload).send();
   }
 }
 
@@ -189,13 +189,13 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
         ..fieldId = fieldTypeOption!.field_2.id
         ..fieldType = fieldTypeOption!.field_2.fieldType;
 
-      return DatabaseEventGetFieldTypeOption(payload).send();
+      return DatabaseEventGetTypeOption(payload).send();
     } else {
       final payload = CreateFieldPayloadPB.create()
         ..databaseId = databaseId
         ..fieldType = FieldType.RichText;
 
-      return DatabaseEventCreateFieldTypeOption(payload).send().then((result) {
+      return DatabaseEventCreateTypeOption(payload).send().then((result) {
         return result.fold(
           (newFieldTypeOption) {
             fieldTypeOption = newFieldTypeOption;
@@ -226,6 +226,6 @@ class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
       ..fieldId = field.id
       ..fieldType = field.fieldType;
 
-    return DatabaseEventGetFieldTypeOption(payload).send();
+    return DatabaseEventGetTypeOption(payload).send();
   }
 }

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

@@ -21,6 +21,6 @@ class TypeOptionFFIService {
       ..databaseId = databaseId
       ..fieldId = fieldId;
 
-    return DatabaseEventNewSelectOption(payload).send();
+    return DatabaseEventCreateSelectOption(payload).send();
   }
 }

+ 2 - 2
frontend/app_flowy/lib/plugins/grid/application/grid_service.dart

@@ -21,9 +21,9 @@ class DatabaseFFIService {
   }
 
   Future<Either<RowPB, FlowyError>> createRow({Option<String>? startRowId}) {
-    var payload = CreateTableRowPayloadPB.create()..databaseId = databaseId;
+    var payload = CreateRowPayloadPB.create()..databaseId = databaseId;
     startRowId?.fold(() => null, (id) => payload.startRowId = id);
-    return DatabaseEventCreateTableRow(payload).send();
+    return DatabaseEventCreateRow(payload).send();
   }
 
   Future<Either<RowPB, FlowyError>> createBoardCard(

+ 0 - 46
frontend/app_flowy/lib/plugins/grid/application/row/row_listener.dart

@@ -1,46 +0,0 @@
-import 'package:app_flowy/core/grid_notification.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-database/notification.pb.dart';
-import 'package:flowy_infra/notifier.dart';
-import 'dart:async';
-import 'dart:typed_data';
-import 'package:dartz/dartz.dart';
-import 'package:appflowy_backend/protobuf/flowy-database/field_entities.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-database/row_entities.pb.dart';
-
-typedef UpdateRowNotifiedValue = Either<RowPB, FlowyError>;
-typedef UpdateFieldNotifiedValue = Either<List<FieldPB>, FlowyError>;
-
-class RowListener {
-  final String rowId;
-  PublishNotifier<UpdateRowNotifiedValue>? updateRowNotifier =
-      PublishNotifier();
-  DatabaseNotificationListener? _listener;
-
-  RowListener({required this.rowId});
-
-  void start() {
-    _listener =
-        DatabaseNotificationListener(objectId: rowId, handler: _handler);
-  }
-
-  void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
-    switch (ty) {
-      case DatabaseNotification.DidUpdateRow:
-        result.fold(
-          (payload) =>
-              updateRowNotifier?.value = left(RowPB.fromBuffer(payload)),
-          (error) => updateRowNotifier?.value = right(error),
-        );
-        break;
-      default:
-        break;
-    }
-  }
-
-  Future<void> stop() async {
-    await _listener?.stop();
-    updateRowNotifier?.dispose();
-    updateRowNotifier = null;
-  }
-}

+ 2 - 2
frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart

@@ -13,11 +13,11 @@ class RowFFIService {
   });
 
   Future<Either<RowPB, FlowyError>> createRow(String rowId) {
-    final payload = CreateTableRowPayloadPB.create()
+    final payload = CreateRowPayloadPB.create()
       ..databaseId = databaseId
       ..startRowId = rowId;
 
-    return DatabaseEventCreateTableRow(payload).send();
+    return DatabaseEventCreateRow(payload).send();
   }
 
   Future<Either<OptionalRowPB, FlowyError>> getRow(String rowId) {

+ 1 - 1
frontend/app_flowy/lib/plugins/grid/application/setting/setting_listener.dart

@@ -27,7 +27,7 @@ class DatabaseSettingListener {
 
   void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
     switch (ty) {
-      case DatabaseNotification.DidUpdateDatabaseSetting:
+      case DatabaseNotification.DidUpdateSettings:
         result.fold(
           (payload) => _updateSettingNotifier?.value = left(
             DatabaseViewSettingPB.fromBuffer(payload),

+ 2 - 2
frontend/app_flowy/lib/plugins/grid/application/view/grid_view_listener.dart

@@ -53,14 +53,14 @@ class GridViewListener {
 
   void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
     switch (ty) {
-      case DatabaseNotification.DidUpdateDatabaseViewRowsVisibility:
+      case DatabaseNotification.DidUpdateViewRowsVisibility:
         result.fold(
           (payload) => _rowsVisibility?.value =
               left(ViewRowsVisibilityChangesetPB.fromBuffer(payload)),
           (error) => _rowsVisibility?.value = right(error),
         );
         break;
-      case DatabaseNotification.DidUpdateDatabaseViewRows:
+      case DatabaseNotification.DidUpdateViewRows:
         result.fold(
           (payload) => _rowsNotifier?.value =
               left(ViewRowsChangesetPB.fromBuffer(payload)),

+ 1 - 1
frontend/app_flowy/lib/plugins/trash/application/trash_listener.dart

@@ -29,7 +29,7 @@ class TrashListener {
     Either<Uint8List, FlowyError> result,
   ) {
     switch (ty) {
-      case FolderNotification.TrashUpdated:
+      case FolderNotification.DidUpdateTrash:
         if (_trashUpdated != null) {
           result.fold(
             (payload) {

+ 3 - 12
frontend/app_flowy/lib/user/application/user_listener.dart

@@ -2,7 +2,6 @@ import 'dart:async';
 import 'package:app_flowy/core/folder_notification.dart';
 import 'package:app_flowy/core/user_notification.dart';
 import 'package:dartz/dartz.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/code.pb.dart';
 import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
 import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
 import 'dart:typed_data';
@@ -122,29 +121,21 @@ class UserWorkspaceListener {
   void _handleObservableType(
       FolderNotification ty, Either<Uint8List, FlowyError> result) {
     switch (ty) {
-      case FolderNotification.UserCreateWorkspace:
-      case FolderNotification.UserDeleteWorkspace:
-      case FolderNotification.WorkspaceListUpdated:
+      case FolderNotification.DidCreateWorkspace:
+      case FolderNotification.DidDeleteWorkspace:
         result.fold(
           (payload) => _workspacesChangedNotifier?.value =
               left(RepeatedWorkspacePB.fromBuffer(payload).items),
           (error) => _workspacesChangedNotifier?.value = right(error),
         );
         break;
-      case FolderNotification.WorkspaceSetting:
+      case FolderNotification.DidUpdateWorkspaceSetting:
         result.fold(
           (payload) => _settingChangedNotifier?.value =
               left(WorkspaceSettingPB.fromBuffer(payload)),
           (error) => _settingChangedNotifier?.value = right(error),
         );
         break;
-      case FolderNotification.UserUnauthorized:
-        result.fold(
-          (_) {},
-          (error) => _authNotifier?.value = right(
-              FlowyError.create()..code = ErrorCode.UserUnauthorized.value),
-        );
-        break;
       default:
         break;
     }

+ 1 - 1
frontend/app_flowy/lib/workspace/application/app/app_listener.dart

@@ -34,7 +34,7 @@ class AppListener {
   void _handleCallback(
       FolderNotification ty, Either<Uint8List, FlowyError> result) {
     switch (ty) {
-      case FolderNotification.AppUpdated:
+      case FolderNotification.DidUpdateApp:
         if (_updated != null) {
           result.fold(
             (payload) {

+ 4 - 4
frontend/app_flowy/lib/workspace/application/view/view_listener.dart

@@ -75,28 +75,28 @@ class ViewListener {
   void _handleObservableType(
       FolderNotification ty, Either<Uint8List, FlowyError> result) {
     switch (ty) {
-      case FolderNotification.ViewUpdated:
+      case FolderNotification.DidUpdateView:
         result.fold(
           (payload) =>
               _updatedViewNotifier.value = left(ViewPB.fromBuffer(payload)),
           (error) => _updatedViewNotifier.value = right(error),
         );
         break;
-      case FolderNotification.ViewDeleted:
+      case FolderNotification.DidDeleteView:
         result.fold(
           (payload) =>
               _deletedNotifier.value = left(ViewPB.fromBuffer(payload)),
           (error) => _deletedNotifier.value = right(error),
         );
         break;
-      case FolderNotification.ViewRestored:
+      case FolderNotification.DidRestoreView:
         result.fold(
           (payload) =>
               _restoredNotifier.value = left(ViewPB.fromBuffer(payload)),
           (error) => _restoredNotifier.value = right(error),
         );
         break;
-      case FolderNotification.ViewMoveToTrash:
+      case FolderNotification.DidMoveViewToTrash:
         result.fold(
           (payload) => _moveToTrashNotifier.value =
               left(DeletedViewPB.fromBuffer(payload)),

+ 2 - 2
frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart

@@ -48,14 +48,14 @@ class WorkspaceListener {
   void _handleObservableType(
       FolderNotification ty, Either<Uint8List, FlowyError> result) {
     switch (ty) {
-      case FolderNotification.WorkspaceUpdated:
+      case FolderNotification.DidUpdateWorkspace:
         result.fold(
           (payload) => _workspaceUpdatedNotifier?.value =
               left(WorkspacePB.fromBuffer(payload)),
           (error) => _workspaceUpdatedNotifier?.value = right(error),
         );
         break;
-      case FolderNotification.WorkspaceAppsChanged:
+      case FolderNotification.DidUpdateWorkspaceApps:
         result.fold(
           (payload) => _appsChangedNotifier?.value =
               left(RepeatedAppPB.fromBuffer(payload).items),

+ 7 - 7
frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs

@@ -2,7 +2,7 @@ use bytes::Bytes;
 use flowy_sqlite::ConnectionPool;
 
 use flowy_client_ws::FlowyWebSocketConnect;
-use flowy_database::entities::DatabaseViewLayout;
+use flowy_database::entities::LayoutTypePB;
 use flowy_database::manager::{make_database_view_data, DatabaseManager};
 use flowy_database::util::{make_default_board, make_default_calendar, make_default_grid};
 use flowy_document::DocumentManager;
@@ -261,9 +261,9 @@ impl ViewDataProcessor for GridViewDataProcessor {
     ) -> FutureResult<Bytes, FlowyError> {
         debug_assert_eq!(data_format, ViewDataFormatPB::DatabaseFormat);
         let (build_context, layout) = match layout {
-            ViewLayoutTypePB::Grid => (make_default_grid(), DatabaseViewLayout::Grid),
-            ViewLayoutTypePB::Board => (make_default_board(), DatabaseViewLayout::Board),
-            ViewLayoutTypePB::Calendar => (make_default_calendar(), DatabaseViewLayout::Calendar),
+            ViewLayoutTypePB::Grid => (make_default_grid(), LayoutTypePB::Grid),
+            ViewLayoutTypePB::Board => (make_default_board(), LayoutTypePB::Board),
+            ViewLayoutTypePB::Calendar => (make_default_calendar(), LayoutTypePB::Calendar),
             ViewLayoutTypePB::Document => {
                 return FutureResult::new(async move {
                     Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))
@@ -291,9 +291,9 @@ impl ViewDataProcessor for GridViewDataProcessor {
         let grid_manager = self.0.clone();
 
         let layout = match layout {
-            ViewLayoutTypePB::Grid => DatabaseViewLayout::Grid,
-            ViewLayoutTypePB::Board => DatabaseViewLayout::Board,
-            ViewLayoutTypePB::Calendar => DatabaseViewLayout::Calendar,
+            ViewLayoutTypePB::Grid => LayoutTypePB::Grid,
+            ViewLayoutTypePB::Board => LayoutTypePB::Board,
+            ViewLayoutTypePB::Calendar => LayoutTypePB::Calendar,
             ViewLayoutTypePB::Document => {
                 return FutureResult::new(async move {
                     Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))

+ 5 - 5
frontend/rust-lib/flowy-database/src/entities/cell_entities.rs

@@ -39,7 +39,7 @@ impl TryInto<CreateSelectOptionParams> for CreateSelectOptionPayloadPB {
 }
 
 #[derive(Debug, Clone, Default, ProtoBuf)]
-pub struct CellPathPB {
+pub struct CellIdPB {
     #[pb(index = 1)]
     pub database_id: String,
 
@@ -52,20 +52,20 @@ pub struct CellPathPB {
 
 /// Represents as the cell identifier. It's used to locate the cell in corresponding
 /// view's row with the field id.
-pub struct CellPathParams {
+pub struct CellIdParams {
     pub database_id: String,
     pub field_id: String,
     pub row_id: String,
 }
 
-impl TryInto<CellPathParams> for CellPathPB {
+impl TryInto<CellIdParams> for CellIdPB {
     type Error = ErrorCode;
 
-    fn try_into(self) -> Result<CellPathParams, Self::Error> {
+    fn try_into(self) -> Result<CellIdParams, Self::Error> {
         let database_id = NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
         let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
         let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
-        Ok(CellPathParams {
+        Ok(CellIdParams {
             database_id: database_id.0,
             field_id: field_id.0,
             row_id: row_id.0,

+ 2 - 2
frontend/rust-lib/flowy-database/src/entities/field_entities.rs

@@ -178,7 +178,7 @@ impl TryInto<CreateFieldParams> for CreateFieldPayloadPB {
 }
 
 #[derive(Debug, Default, ProtoBuf)]
-pub struct EditFieldChangesetPB {
+pub struct UpdateFieldTypePayloadPB {
     #[pb(index = 1)]
     pub database_id: String,
 
@@ -198,7 +198,7 @@ pub struct EditFieldParams {
     pub field_type: FieldType,
 }
 
-impl TryInto<EditFieldParams> for EditFieldChangesetPB {
+impl TryInto<EditFieldParams> for UpdateFieldTypePayloadPB {
     type Error = ErrorCode;
 
     fn try_into(self) -> Result<EditFieldParams, Self::Error> {

+ 2 - 2
frontend/rust-lib/flowy-database/src/entities/group_entities/group.rs

@@ -1,5 +1,5 @@
 use crate::entities::parser::NotEmptyStr;
-use crate::entities::{CreateRowParams, DatabaseViewLayout, FieldType, RowPB};
+use crate::entities::{CreateRowParams, FieldType, LayoutTypePB, RowPB};
 use crate::services::group::Group;
 use flowy_derive::ProtoBuf;
 use flowy_error::ErrorCode;
@@ -33,7 +33,7 @@ impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
             database_id: database_id.0,
             start_row_id,
             group_id: Some(group_id.0),
-            layout: DatabaseViewLayout::Board,
+            layout: LayoutTypePB::Board,
         })
     }
 }

+ 2 - 2
frontend/rust-lib/flowy-database/src/entities/group_entities/group_changeset.rs

@@ -127,7 +127,7 @@ impl TryInto<MoveGroupParams> for MoveGroupPayloadPB {
 }
 
 #[derive(Debug, Default, ProtoBuf)]
-pub struct GroupViewChangesetPB {
+pub struct GroupChangesetPB {
     #[pb(index = 1)]
     pub view_id: String,
 
@@ -144,7 +144,7 @@ pub struct GroupViewChangesetPB {
     pub update_groups: Vec<GroupPB>,
 }
 
-impl GroupViewChangesetPB {
+impl GroupChangesetPB {
     pub fn is_empty(&self) -> bool {
         self.initial_groups.is_empty()
             && self.inserted_groups.is_empty()

+ 5 - 5
frontend/rust-lib/flowy-database/src/entities/row_entities.rs

@@ -1,5 +1,5 @@
 use crate::entities::parser::NotEmptyStr;
-use crate::entities::DatabaseViewLayout;
+use crate::entities::LayoutTypePB;
 use flowy_derive::ProtoBuf;
 use flowy_error::ErrorCode;
 use grid_model::RowRevision;
@@ -171,7 +171,7 @@ pub struct BlockRowIdPB {
 }
 
 #[derive(ProtoBuf, Default)]
-pub struct CreateTableRowPayloadPB {
+pub struct CreateRowPayloadPB {
     #[pb(index = 1)]
     pub database_id: String,
 
@@ -184,10 +184,10 @@ pub struct CreateRowParams {
     pub database_id: String,
     pub start_row_id: Option<String>,
     pub group_id: Option<String>,
-    pub layout: DatabaseViewLayout,
+    pub layout: LayoutTypePB,
 }
 
-impl TryInto<CreateRowParams> for CreateTableRowPayloadPB {
+impl TryInto<CreateRowParams> for CreateRowPayloadPB {
     type Error = ErrorCode;
 
     fn try_into(self) -> Result<CreateRowParams, Self::Error> {
@@ -197,7 +197,7 @@ impl TryInto<CreateRowParams> for CreateTableRowPayloadPB {
             database_id: database_id.0,
             start_row_id: self.start_row_id,
             group_id: None,
-            layout: DatabaseViewLayout::Grid,
+            layout: LayoutTypePB::Grid,
         })
     }
 }

+ 21 - 21
frontend/rust-lib/flowy-database/src/entities/setting_entities.rs

@@ -15,10 +15,10 @@ use strum_macros::EnumIter;
 #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
 pub struct DatabaseViewSettingPB {
     #[pb(index = 1)]
-    pub layouts: Vec<ViewLayoutConfigPB>,
+    pub support_layouts: Vec<ViewLayoutPB>,
 
     #[pb(index = 2)]
-    pub layout_type: DatabaseViewLayout,
+    pub current_layout: LayoutTypePB,
 
     #[pb(index = 3)]
     pub filters: RepeatedFilterPB,
@@ -31,16 +31,16 @@ pub struct DatabaseViewSettingPB {
 }
 
 #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
-pub struct ViewLayoutConfigPB {
+pub struct ViewLayoutPB {
     #[pb(index = 1)]
-    ty: DatabaseViewLayout,
+    ty: LayoutTypePB,
 }
 
-impl ViewLayoutConfigPB {
-    pub fn all() -> Vec<ViewLayoutConfigPB> {
+impl ViewLayoutPB {
+    pub fn all() -> Vec<ViewLayoutPB> {
         let mut layouts = vec![];
-        for layout_ty in DatabaseViewLayout::iter() {
-            layouts.push(ViewLayoutConfigPB { ty: layout_ty })
+        for layout_ty in LayoutTypePB::iter() {
+            layouts.push(ViewLayoutPB { ty: layout_ty })
         }
 
         layouts
@@ -49,34 +49,34 @@ impl ViewLayoutConfigPB {
 
 #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]
 #[repr(u8)]
-pub enum DatabaseViewLayout {
+pub enum LayoutTypePB {
     Grid = 0,
     Board = 1,
     Calendar = 2,
 }
 
-impl std::default::Default for DatabaseViewLayout {
+impl std::default::Default for LayoutTypePB {
     fn default() -> Self {
-        DatabaseViewLayout::Grid
+        LayoutTypePB::Grid
     }
 }
 
-impl std::convert::From<LayoutRevision> for DatabaseViewLayout {
+impl std::convert::From<LayoutRevision> for LayoutTypePB {
     fn from(rev: LayoutRevision) -> Self {
         match rev {
-            LayoutRevision::Grid => DatabaseViewLayout::Grid,
-            LayoutRevision::Board => DatabaseViewLayout::Board,
-            LayoutRevision::Calendar => DatabaseViewLayout::Calendar,
+            LayoutRevision::Grid => LayoutTypePB::Grid,
+            LayoutRevision::Board => LayoutTypePB::Board,
+            LayoutRevision::Calendar => LayoutTypePB::Calendar,
         }
     }
 }
 
-impl std::convert::From<DatabaseViewLayout> for LayoutRevision {
-    fn from(layout: DatabaseViewLayout) -> Self {
+impl std::convert::From<LayoutTypePB> for LayoutRevision {
+    fn from(layout: LayoutTypePB) -> Self {
         match layout {
-            DatabaseViewLayout::Grid => LayoutRevision::Grid,
-            DatabaseViewLayout::Board => LayoutRevision::Board,
-            DatabaseViewLayout::Calendar => LayoutRevision::Calendar,
+            LayoutTypePB::Grid => LayoutRevision::Grid,
+            LayoutTypePB::Board => LayoutRevision::Board,
+            LayoutTypePB::Calendar => LayoutRevision::Calendar,
         }
     }
 }
@@ -87,7 +87,7 @@ pub struct DatabaseSettingChangesetPB {
     pub database_id: String,
 
     #[pb(index = 2)]
-    pub layout_type: DatabaseViewLayout,
+    pub layout_type: LayoutTypePB,
 
     #[pb(index = 3, one_of)]
     pub alter_filter: Option<AlterFilterPayloadPB>,

+ 7 - 7
frontend/rust-lib/flowy-database/src/event_handler.rs

@@ -160,7 +160,7 @@ pub(crate) async fn delete_field_handler(
 
 #[tracing::instrument(level = "trace", skip(data, manager), err)]
 pub(crate) async fn switch_to_field_handler(
-    data: AFPluginData<EditFieldChangesetPB>,
+    data: AFPluginData<UpdateFieldTypePayloadPB>,
     manager: AFPluginState<Arc<DatabaseManager>>,
 ) -> Result<(), FlowyError> {
     let params: EditFieldParams = data.into_inner().try_into()?;
@@ -315,7 +315,7 @@ pub(crate) async fn move_row_handler(
 
 #[tracing::instrument(level = "debug", skip(data, manager), err)]
 pub(crate) async fn create_table_row_handler(
-    data: AFPluginData<CreateTableRowPayloadPB>,
+    data: AFPluginData<CreateRowPayloadPB>,
     manager: AFPluginState<Arc<DatabaseManager>>,
 ) -> DataResult<RowPB, FlowyError> {
     let params: CreateRowParams = data.into_inner().try_into()?;
@@ -326,10 +326,10 @@ pub(crate) async fn create_table_row_handler(
 
 #[tracing::instrument(level = "trace", skip_all, err)]
 pub(crate) async fn get_cell_handler(
-    data: AFPluginData<CellPathPB>,
+    data: AFPluginData<CellIdPB>,
     manager: AFPluginState<Arc<DatabaseManager>>,
 ) -> DataResult<CellPB, FlowyError> {
-    let params: CellPathParams = data.into_inner().try_into()?;
+    let params: CellIdParams = data.into_inner().try_into()?;
     let editor = manager.get_database_editor(&params.database_id).await?;
     match editor.get_cell(&params).await {
         None => data_result(CellPB::empty(&params.field_id, &params.row_id)),
@@ -427,10 +427,10 @@ pub(crate) async fn update_select_option_handler(
 
 #[tracing::instrument(level = "trace", skip(data, manager), err)]
 pub(crate) async fn get_select_option_handler(
-    data: AFPluginData<CellPathPB>,
+    data: AFPluginData<CellIdPB>,
     manager: AFPluginState<Arc<DatabaseManager>>,
 ) -> DataResult<SelectOptionCellDataPB, FlowyError> {
-    let params: CellPathParams = data.into_inner().try_into()?;
+    let params: CellIdParams = data.into_inner().try_into()?;
     let editor = manager.get_database_editor(&params.database_id).await?;
     match editor.get_field_rev(&params.field_id).await {
         None => {
@@ -483,7 +483,7 @@ pub(crate) async fn update_date_cell_handler(
     manager: AFPluginState<Arc<DatabaseManager>>,
 ) -> Result<(), FlowyError> {
     let data = data.into_inner();
-    let cell_path: CellPathParams = data.cell_path.try_into()?;
+    let cell_path: CellIdParams = data.cell_path.try_into()?;
     let cell_changeset = DateCellChangeset {
         date: data.date,
         time: data.time,

+ 18 - 21
frontend/rust-lib/flowy-database/src/event_map.rs

@@ -20,16 +20,13 @@ pub fn init(database_manager: Arc<DatabaseManager>) -> AFPlugin {
         .event(DatabaseEvent::UpdateField, update_field_handler)
         .event(DatabaseEvent::UpdateFieldTypeOption, update_field_type_option_handler)
         .event(DatabaseEvent::DeleteField, delete_field_handler)
-        .event(DatabaseEvent::SwitchToField, switch_to_field_handler)
+        .event(DatabaseEvent::UpdateFieldType, switch_to_field_handler)
         .event(DatabaseEvent::DuplicateField, duplicate_field_handler)
         .event(DatabaseEvent::MoveField, move_field_handler)
-        .event(DatabaseEvent::GetFieldTypeOption, get_field_type_option_data_handler)
-        .event(
-            DatabaseEvent::CreateFieldTypeOption,
-            create_field_type_option_data_handler,
-        )
+        .event(DatabaseEvent::GetTypeOption, get_field_type_option_data_handler)
+        .event(DatabaseEvent::CreateTypeOption, create_field_type_option_data_handler)
         // Row
-        .event(DatabaseEvent::CreateTableRow, create_table_row_handler)
+        .event(DatabaseEvent::CreateRow, create_table_row_handler)
         .event(DatabaseEvent::GetRow, get_row_handler)
         .event(DatabaseEvent::DeleteRow, delete_row_handler)
         .event(DatabaseEvent::DuplicateRow, duplicate_row_handler)
@@ -38,7 +35,7 @@ pub fn init(database_manager: Arc<DatabaseManager>) -> AFPlugin {
         .event(DatabaseEvent::GetCell, get_cell_handler)
         .event(DatabaseEvent::UpdateCell, update_cell_handler)
         // SelectOption
-        .event(DatabaseEvent::NewSelectOption, new_select_option_handler)
+        .event(DatabaseEvent::CreateSelectOption, new_select_option_handler)
         .event(DatabaseEvent::UpdateSelectOption, update_select_option_handler)
         .event(DatabaseEvent::GetSelectOptionCellData, get_select_option_handler)
         .event(DatabaseEvent::UpdateSelectOptionCell, update_select_option_cell_handler)
@@ -118,11 +115,11 @@ pub enum DatabaseEvent {
     #[event(input = "DeleteFieldPayloadPB")]
     DeleteField = 14,
 
-    /// [SwitchToField] event is used to update the current Field's type.
+    /// [UpdateFieldType] event is used to update the current Field's type.
     /// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
     /// reuse the existing FieldTypeOptionData. You could check the [DatabaseRevisionPad] for more details.
-    #[event(input = "EditFieldChangesetPB")]
-    SwitchToField = 20,
+    #[event(input = "UpdateFieldTypePayloadPB")]
+    UpdateFieldType = 20,
 
     /// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
     /// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
@@ -145,21 +142,21 @@ pub enum DatabaseEvent {
     ///
     /// Return the [TypeOptionPB] if there are no errors.
     #[event(input = "TypeOptionPathPB", output = "TypeOptionPB")]
-    GetFieldTypeOption = 23,
+    GetTypeOption = 23,
 
-    /// [CreateFieldTypeOption] event is used to create a new FieldTypeOptionData.
+    /// [CreateTypeOption] event is used to create a new FieldTypeOptionData.
     #[event(input = "CreateFieldPayloadPB", output = "TypeOptionPB")]
-    CreateFieldTypeOption = 24,
+    CreateTypeOption = 24,
 
-    /// [NewSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
+    /// [CreateSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
     /// there are no errors.
     #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
-    NewSelectOption = 30,
+    CreateSelectOption = 30,
 
     /// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
-    /// [CellPathPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
+    /// [CellIdPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
     /// contains the available options and the currently selected options.
-    #[event(input = "CellPathPB", output = "SelectOptionCellDataPB")]
+    #[event(input = "CellIdPB", output = "SelectOptionCellDataPB")]
     GetSelectOptionCellData = 31,
 
     /// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
@@ -171,8 +168,8 @@ pub enum DatabaseEvent {
     #[event(input = "SelectOptionChangesetPB")]
     UpdateSelectOption = 32,
 
-    #[event(input = "CreateTableRowPayloadPB", output = "RowPB")]
-    CreateTableRow = 50,
+    #[event(input = "CreateRowPayloadPB", output = "RowPB")]
+    CreateRow = 50,
 
     /// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
     /// to return a nullable row data.
@@ -188,7 +185,7 @@ pub enum DatabaseEvent {
     #[event(input = "MoveRowPayloadPB")]
     MoveRow = 54,
 
-    #[event(input = "CellPathPB", output = "CellPB")]
+    #[event(input = "CellIdPB", output = "CellPB")]
     GetCell = 70,
 
     /// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],

+ 2 - 2
frontend/rust-lib/flowy-database/src/manager.rs

@@ -1,4 +1,4 @@
-use crate::entities::DatabaseViewLayout;
+use crate::entities::LayoutTypePB;
 use crate::services::grid_editor::{
     DatabaseRevisionEditor, GridRevisionCloudService, GridRevisionMergeable, GridRevisionSerde,
 };
@@ -196,7 +196,7 @@ impl DatabaseManager {
 pub async fn make_database_view_data(
     _user_id: &str,
     view_id: &str,
-    layout: DatabaseViewLayout,
+    layout: LayoutTypePB,
     database_manager: Arc<DatabaseManager>,
     build_context: BuildDatabaseContext,
 ) -> FlowyResult<Bytes> {

+ 20 - 9
frontend/rust-lib/flowy-database/src/notification.rs

@@ -5,21 +5,32 @@ const OBSERVABLE_CATEGORY: &str = "Grid";
 #[derive(ProtoBuf_Enum, Debug)]
 pub enum DatabaseNotification {
     Unknown = 0,
-    DidCreateBlock = 11,
-    DidUpdateDatabaseViewRows = 20,
-    DidUpdateDatabaseViewRowsVisibility = 21,
-    DidUpdateDatabaseFields = 22,
-    DidUpdateRow = 30,
+    /// Trigger after inserting/deleting/updating a row
+    DidUpdateViewRows = 20,
+    /// Trigger when the visibility of the row was changed. For example, updating the filter will trigger the notification
+    DidUpdateViewRowsVisibility = 21,
+    /// Trigger after inserting/deleting/updating a field
+    DidUpdateFields = 22,
+    /// Trigger after editing a cell
     DidUpdateCell = 40,
+    /// Trigger after editing a field properties including rename,update type option, etc
     DidUpdateField = 50,
-    DidUpdateGroupView = 60,
-    DidUpdateGroup = 61,
-    DidGroupByNewField = 62,
+    /// Trigger after the number of groups is changed
+    DidUpdateGroups = 60,
+    /// Trigger after inserting/deleting/updating/moving a row
+    DidUpdateGroupRow = 61,
+    /// Trigger when setting a new grouping field
+    DidGroupByField = 62,
+    /// Trigger after inserting/deleting/updating a filter
     DidUpdateFilter = 63,
+    /// Trigger after inserting/deleting/updating a sort
     DidUpdateSort = 64,
+    /// Trigger after the sort configurations are changed
     DidReorderRows = 65,
+    /// Trigger after editing the row that hit the sort rule
     DidReorderSingleRow = 66,
-    DidUpdateDatabaseSetting = 70,
+    /// Trigger when the settings of the database are changed
+    DidUpdateSettings = 70,
 }
 
 impl std::default::Default for DatabaseNotification {

+ 2 - 2
frontend/rust-lib/flowy-database/src/services/field/type_options/date_type_option/date_type_option_entities.rs

@@ -1,4 +1,4 @@
-use crate::entities::CellPathPB;
+use crate::entities::CellIdPB;
 use crate::services::cell::{
     CellProtobufBlobParser, DecodedCellData, FromCellChangesetString, FromCellString, ToCellChangesetString,
 };
@@ -23,7 +23,7 @@ pub struct DateCellDataPB {
 #[derive(Clone, Debug, Default, ProtoBuf)]
 pub struct DateChangesetPB {
     #[pb(index = 1)]
-    pub cell_path: CellPathPB,
+    pub cell_path: CellIdPB,
 
     #[pb(index = 2, one_of)]
     pub date: Option<String>,

+ 6 - 6
frontend/rust-lib/flowy-database/src/services/field/type_options/selection_type_option/select_type_option.rs

@@ -1,5 +1,5 @@
 use crate::entities::parser::NotEmptyStr;
-use crate::entities::{CellPathPB, CellPathParams, FieldType};
+use crate::entities::{CellIdPB, CellIdParams, FieldType};
 use crate::services::cell::{
     CellDataDecoder, CellProtobufBlobParser, DecodedCellData, FromCellChangesetString, FromCellString,
     ToCellChangesetString,
@@ -366,7 +366,7 @@ impl CellProtobufBlobParser for SelectOptionCellDataParser {
 #[derive(Clone, Debug, Default, ProtoBuf)]
 pub struct SelectOptionCellChangesetPB {
     #[pb(index = 1)]
-    pub cell_identifier: CellPathPB,
+    pub cell_identifier: CellIdPB,
 
     #[pb(index = 2)]
     pub insert_option_ids: Vec<String>,
@@ -376,7 +376,7 @@ pub struct SelectOptionCellChangesetPB {
 }
 
 pub struct SelectOptionCellChangesetParams {
-    pub cell_identifier: CellPathParams,
+    pub cell_identifier: CellIdParams,
     pub insert_option_ids: Vec<String>,
     pub delete_option_ids: Vec<String>,
 }
@@ -385,7 +385,7 @@ impl TryInto<SelectOptionCellChangesetParams> for SelectOptionCellChangesetPB {
     type Error = ErrorCode;
 
     fn try_into(self) -> Result<SelectOptionCellChangesetParams, Self::Error> {
-        let cell_identifier: CellPathParams = self.cell_identifier.try_into()?;
+        let cell_identifier: CellIdParams = self.cell_identifier.try_into()?;
         let insert_option_ids = self
             .insert_option_ids
             .into_iter()
@@ -487,7 +487,7 @@ pub struct SelectOptionCellDataPB {
 #[derive(Clone, Debug, Default, ProtoBuf)]
 pub struct SelectOptionChangesetPB {
     #[pb(index = 1)]
-    pub cell_identifier: CellPathPB,
+    pub cell_identifier: CellIdPB,
 
     #[pb(index = 2)]
     pub insert_options: Vec<SelectOptionPB>,
@@ -500,7 +500,7 @@ pub struct SelectOptionChangesetPB {
 }
 
 pub struct SelectOptionChangeset {
-    pub cell_path: CellPathParams,
+    pub cell_path: CellIdParams,
     pub insert_options: Vec<SelectOptionPB>,
     pub update_options: Vec<SelectOptionPB>,
     pub delete_options: Vec<SelectOptionPB>,

+ 7 - 3
frontend/rust-lib/flowy-database/src/services/filter/controller.rs

@@ -4,7 +4,7 @@ use crate::services::cell::{AnyTypeCache, AtomicCellDataCache, AtomicCellFilterC
 use crate::services::field::*;
 use crate::services::filter::{FilterChangeset, FilterResult, FilterResultNotification, FilterType};
 use crate::services::row::DatabaseBlockRowRevision;
-use crate::services::view_editor::{GridViewChanged, GridViewChangedNotifier};
+use crate::services::view_editor::{DatabaseViewChanged, GridViewChangedNotifier};
 use dashmap::DashMap;
 use flowy_error::FlowyResult;
 use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
@@ -149,7 +149,9 @@ impl FilterController {
                 }
             }
 
-            let _ = self.notifier.send(GridViewChanged::FilterNotification(notification));
+            let _ = self
+                .notifier
+                .send(DatabaseViewChanged::FilterNotification(notification));
         }
         Ok(())
     }
@@ -185,7 +187,9 @@ impl FilterController {
                 visible_rows,
             };
             tracing::Span::current().record("filter_result", format!("{:?}", &notification).as_str());
-            let _ = self.notifier.send(GridViewChanged::FilterNotification(notification));
+            let _ = self
+                .notifier
+                .send(DatabaseViewChanged::FilterNotification(notification));
         }
         Ok(())
     }

+ 8 - 8
frontend/rust-lib/flowy-database/src/services/grid_editor.rs

@@ -1,4 +1,4 @@
-use crate::entities::CellPathParams;
+use crate::entities::CellIdParams;
 use crate::entities::*;
 use crate::manager::DatabaseUser;
 use crate::notification::{send_notification, DatabaseNotification};
@@ -16,7 +16,7 @@ use crate::services::filter::FilterType;
 use crate::services::grid_editor_trait_impl::GridViewEditorDelegateImpl;
 use crate::services::persistence::block_index::BlockIndexCache;
 use crate::services::row::{DatabaseBlockRow, DatabaseBlockRowRevision, RowRevisionBuilder};
-use crate::services::view_editor::{DatabaseViewManager, GridViewChanged};
+use crate::services::view_editor::{DatabaseViewChanged, DatabaseViewManager};
 use bytes::Bytes;
 use flowy_client_sync::client_database::{DatabaseRevisionChangeset, DatabaseRevisionPad, JsonDeserializer};
 use flowy_client_sync::errors::{SyncError, SyncResult};
@@ -428,7 +428,7 @@ impl DatabaseRevisionEditor {
         Ok(())
     }
 
-    pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<GridViewChanged>> {
+    pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<DatabaseViewChanged>> {
         self.view_manager.subscribe_view_changed(view_id).await
     }
 
@@ -437,7 +437,7 @@ impl DatabaseRevisionEditor {
     }
 
     /// Returns the cell data that encoded in protobuf.
-    pub async fn get_cell(&self, params: &CellPathParams) -> Option<CellPB> {
+    pub async fn get_cell(&self, params: &CellIdParams) -> Option<CellPB> {
         let (field_type, cell_bytes) = self.get_type_cell_protobuf(params).await?;
         Some(CellPB::new(
             &params.field_id,
@@ -453,7 +453,7 @@ impl DatabaseRevisionEditor {
     /// Number: 123 => $123 if the currency set.
     /// Date: 1653609600 => May 27,2022
     ///
-    pub async fn get_cell_display_str(&self, params: &CellPathParams) -> String {
+    pub async fn get_cell_display_str(&self, params: &CellIdParams) -> String {
         let display_str = || async {
             let field_rev = self.get_field_rev(&params.field_id).await?;
             let field_type: FieldType = field_rev.ty.into();
@@ -470,12 +470,12 @@ impl DatabaseRevisionEditor {
         display_str().await.unwrap_or_default()
     }
 
-    pub async fn get_cell_protobuf(&self, params: &CellPathParams) -> Option<CellProtobufBlob> {
+    pub async fn get_cell_protobuf(&self, params: &CellIdParams) -> Option<CellProtobufBlob> {
         let (_, cell_data) = self.get_type_cell_protobuf(params).await?;
         Some(cell_data)
     }
 
-    async fn get_type_cell_protobuf(&self, params: &CellPathParams) -> Option<(FieldType, CellProtobufBlob)> {
+    async fn get_type_cell_protobuf(&self, params: &CellIdParams) -> Option<(FieldType, CellProtobufBlob)> {
         let field_rev = self.get_field_rev(&params.field_id).await?;
         let (_, row_rev) = self.block_manager.get_row_rev(&params.row_id).await.ok()??;
         let cell_rev = row_rev.cells.get(&params.field_id)?.clone();
@@ -861,7 +861,7 @@ impl DatabaseRevisionEditor {
     }
 
     async fn notify_did_update_grid(&self, changeset: DatabaseFieldChangesetPB) -> FlowyResult<()> {
-        send_notification(&self.database_id, DatabaseNotification::DidUpdateDatabaseFields)
+        send_notification(&self.database_id, DatabaseNotification::DidUpdateFields)
             .payload(changeset)
             .send();
         Ok(())

+ 2 - 2
frontend/rust-lib/flowy-database/src/services/group/action.rs

@@ -1,4 +1,4 @@
-use crate::entities::{GroupPB, GroupRowsNotificationPB, GroupViewChangesetPB, InsertedGroupPB};
+use crate::entities::{GroupChangesetPB, GroupPB, GroupRowsNotificationPB, InsertedGroupPB};
 use crate::services::cell::DecodedCellData;
 use crate::services::group::controller::MoveGroupRowContext;
 use crate::services::group::Group;
@@ -91,7 +91,7 @@ pub trait GroupControllerActions: Send + Sync {
     fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<DidMoveGroupRowResult>;
 
     /// Update the group if the corresponding field is changed
-    fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>>;
+    fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupChangesetPB>>;
 }
 
 #[derive(Debug)]

+ 3 - 3
frontend/rust-lib/flowy-database/src/services/group/configuration.rs

@@ -1,4 +1,4 @@
-use crate::entities::{GroupPB, GroupViewChangesetPB, InsertedGroupPB};
+use crate::entities::{GroupChangesetPB, GroupPB, InsertedGroupPB};
 use crate::services::field::RowSingleCellData;
 use crate::services::group::{default_group_configuration, GeneratedGroupContext, Group};
 use flowy_error::{FlowyError, FlowyResult};
@@ -223,7 +223,7 @@ where
     pub(crate) fn init_groups(
         &mut self,
         generated_group_context: GeneratedGroupContext,
-    ) -> FlowyResult<Option<GroupViewChangesetPB>> {
+    ) -> FlowyResult<Option<GroupChangesetPB>> {
         let GeneratedGroupContext {
             no_status_group,
             group_configs,
@@ -312,7 +312,7 @@ where
             })
             .collect();
 
-        let changeset = GroupViewChangesetPB {
+        let changeset = GroupChangesetPB {
             view_id: self.view_id.clone(),
             initial_groups,
             deleted_groups: deleted_group_ids,

+ 2 - 2
frontend/rust-lib/flowy-database/src/services/group/controller.rs

@@ -1,4 +1,4 @@
-use crate::entities::{GroupRowsNotificationPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
+use crate::entities::{GroupChangesetPB, GroupRowsNotificationPB, InsertedRowPB, RowPB};
 use crate::services::cell::{get_type_cell_protobuf, CellProtobufBlobParser, DecodedCellData};
 
 use crate::services::group::action::{
@@ -319,7 +319,7 @@ where
         Ok(result)
     }
 
-    fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>> {
+    fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupChangesetPB>> {
         Ok(None)
     }
 }

+ 2 - 2
frontend/rust-lib/flowy-database/src/services/group/controller_impls/default_controller.rs

@@ -1,4 +1,4 @@
-use crate::entities::{GroupViewChangesetPB, RowPB};
+use crate::entities::{GroupChangesetPB, RowPB};
 use crate::services::group::action::{DidMoveGroupRowResult, DidUpdateGroupRowResult, GroupControllerActions};
 use crate::services::group::{Group, GroupController, MoveGroupRowContext};
 use flowy_error::FlowyResult;
@@ -86,7 +86,7 @@ impl GroupControllerActions for DefaultGroupController {
         })
     }
 
-    fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>> {
+    fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupChangesetPB>> {
         Ok(None)
     }
 }

+ 2 - 2
frontend/rust-lib/flowy-database/src/services/setting/setting_builder.rs

@@ -1,11 +1,11 @@
-use crate::entities::{AlterFilterParams, DatabaseSettingChangesetParams, DatabaseViewLayout, DeleteFilterParams};
+use crate::entities::{AlterFilterParams, DatabaseSettingChangesetParams, DeleteFilterParams, LayoutTypePB};
 
 pub struct GridSettingChangesetBuilder {
     params: DatabaseSettingChangesetParams,
 }
 
 impl GridSettingChangesetBuilder {
-    pub fn new(grid_id: &str, layout_type: &DatabaseViewLayout) -> Self {
+    pub fn new(grid_id: &str, layout_type: &LayoutTypePB) -> Self {
         let params = DatabaseSettingChangesetParams {
             database_id: grid_id.to_string(),
             layout_type: layout_type.clone().into(),

+ 3 - 3
frontend/rust-lib/flowy-database/src/services/sort/controller.rs

@@ -3,7 +3,7 @@ use crate::entities::SortChangesetNotificationPB;
 use crate::services::cell::{AtomicCellDataCache, TypeCellData};
 use crate::services::field::{default_order, TypeOptionCellExt};
 use crate::services::sort::{ReorderAllRowsResult, ReorderSingleRowResult, SortChangeset, SortType};
-use crate::services::view_editor::{GridViewChanged, GridViewChangedNotifier};
+use crate::services::view_editor::{DatabaseViewChanged, GridViewChangedNotifier};
 use flowy_error::FlowyResult;
 use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
 use grid_model::{CellRevision, FieldRevision, RowRevision, SortCondition, SortRevision};
@@ -92,7 +92,7 @@ impl SortController {
 
                 let _ = self
                     .notifier
-                    .send(GridViewChanged::ReorderAllRowsNotification(notification));
+                    .send(DatabaseViewChanged::ReorderAllRowsNotification(notification));
             }
             SortEvent::RowDidChanged(row_id) => {
                 let old_row_index = self.row_index_cache.get(&row_id).cloned();
@@ -111,7 +111,7 @@ impl SortController {
                         };
                         let _ = self
                             .notifier
-                            .send(GridViewChanged::ReorderSingleRowNotification(notification));
+                            .send(DatabaseViewChanged::ReorderSingleRowNotification(notification));
                     }
                     _ => tracing::trace!("The row index cache is outdated"),
                 }

+ 9 - 12
frontend/rust-lib/flowy-database/src/services/view_editor/changed_notifier.rs

@@ -7,15 +7,15 @@ use futures::stream::StreamExt;
 use tokio::sync::broadcast;
 
 #[derive(Clone)]
-pub enum GridViewChanged {
+pub enum DatabaseViewChanged {
     FilterNotification(FilterResultNotification),
     ReorderAllRowsNotification(ReorderAllRowsResult),
     ReorderSingleRowNotification(ReorderSingleRowResult),
 }
 
-pub type GridViewChangedNotifier = broadcast::Sender<GridViewChanged>;
+pub type GridViewChangedNotifier = broadcast::Sender<DatabaseViewChanged>;
 
-pub(crate) struct GridViewChangedReceiverRunner(pub(crate) Option<broadcast::Receiver<GridViewChanged>>);
+pub(crate) struct GridViewChangedReceiverRunner(pub(crate) Option<broadcast::Receiver<DatabaseViewChanged>>);
 impl GridViewChangedReceiverRunner {
     pub(crate) async fn run(mut self) {
         let mut receiver = self.0.take().expect("Only take once");
@@ -30,21 +30,18 @@ impl GridViewChangedReceiverRunner {
         stream
             .for_each(|changed| async {
                 match changed {
-                    GridViewChanged::FilterNotification(notification) => {
+                    DatabaseViewChanged::FilterNotification(notification) => {
                         let changeset = ViewRowsVisibilityChangesetPB {
                             view_id: notification.view_id,
                             visible_rows: notification.visible_rows,
                             invisible_rows: notification.invisible_rows,
                         };
 
-                        send_notification(
-                            &changeset.view_id,
-                            DatabaseNotification::DidUpdateDatabaseViewRowsVisibility,
-                        )
-                        .payload(changeset)
-                        .send()
+                        send_notification(&changeset.view_id, DatabaseNotification::DidUpdateViewRowsVisibility)
+                            .payload(changeset)
+                            .send()
                     }
-                    GridViewChanged::ReorderAllRowsNotification(notification) => {
+                    DatabaseViewChanged::ReorderAllRowsNotification(notification) => {
                         let row_orders = ReorderAllRowsPB {
                             row_orders: notification.row_orders,
                         };
@@ -52,7 +49,7 @@ impl GridViewChangedReceiverRunner {
                             .payload(row_orders)
                             .send()
                     }
-                    GridViewChanged::ReorderSingleRowNotification(notification) => {
+                    DatabaseViewChanged::ReorderSingleRowNotification(notification) => {
                         let reorder_row = ReorderSingleRowPB {
                             row_id: notification.row_id,
                             old_index: notification.old_index as i32,

+ 13 - 13
frontend/rust-lib/flowy-database/src/services/view_editor/editor.rs

@@ -184,7 +184,7 @@ impl DatabaseViewRevisionEditor {
             }
         };
 
-        send_notification(&self.view_id, DatabaseNotification::DidUpdateDatabaseViewRows)
+        send_notification(&self.view_id, DatabaseNotification::DidUpdateViewRows)
             .payload(changeset)
             .send();
     }
@@ -262,7 +262,7 @@ impl DatabaseViewRevisionEditor {
             .await;
 
         if let Some(Ok(result)) = result {
-            let mut changeset = GroupViewChangesetPB {
+            let mut changeset = GroupChangesetPB {
                 view_id: self.view_id.clone(),
                 ..Default::default()
             };
@@ -274,7 +274,7 @@ impl DatabaseViewRevisionEditor {
                 tracing::trace!("Delete group after editing the row: {:?}", delete_group);
                 changeset.deleted_groups.push(delete_group.group_id);
             }
-            self.notify_did_update_view(changeset).await;
+            self.notify_did_update_groups(changeset).await;
 
             tracing::trace!("Group changesets after editing the row: {:?}", result.row_changesets);
             for changeset in result.row_changesets {
@@ -312,7 +312,7 @@ impl DatabaseViewRevisionEditor {
             .await;
 
         if let Some(result) = result {
-            let mut changeset = GroupViewChangesetPB {
+            let mut changeset = GroupChangesetPB {
                 view_id: self.view_id.clone(),
                 ..Default::default()
             };
@@ -320,7 +320,7 @@ impl DatabaseViewRevisionEditor {
                 tracing::info!("Delete group after moving the row: {:?}", delete_group);
                 changeset.deleted_groups.push(delete_group.group_id);
             }
-            self.notify_did_update_view(changeset).await;
+            self.notify_did_update_groups(changeset).await;
 
             for changeset in result.row_changesets {
                 self.notify_did_update_group_rows(changeset).await;
@@ -356,7 +356,7 @@ impl DatabaseViewRevisionEditor {
                     index: index as i32,
                 };
 
-                let changeset = GroupViewChangesetPB {
+                let changeset = GroupChangesetPB {
                     view_id: self.view_id.clone(),
                     inserted_groups: vec![inserted_group],
                     deleted_groups: vec![params.from_group_id.clone()],
@@ -364,7 +364,7 @@ impl DatabaseViewRevisionEditor {
                     initial_groups: vec![],
                 };
 
-                self.notify_did_update_view(changeset).await;
+                self.notify_did_update_groups(changeset).await;
             }
         }
         Ok(())
@@ -632,7 +632,7 @@ impl DatabaseViewRevisionEditor {
                 .collect();
 
             *self.group_controller.write().await = new_group_controller;
-            let changeset = GroupViewChangesetPB {
+            let changeset = GroupChangesetPB {
                 view_id: self.view_id.clone(),
                 initial_groups: new_groups,
                 ..Default::default()
@@ -640,7 +640,7 @@ impl DatabaseViewRevisionEditor {
 
             debug_assert!(!changeset.is_empty());
             if !changeset.is_empty() {
-                send_notification(&changeset.view_id, DatabaseNotification::DidGroupByNewField)
+                send_notification(&changeset.view_id, DatabaseNotification::DidGroupByField)
                     .payload(changeset)
                     .send();
             }
@@ -654,13 +654,13 @@ impl DatabaseViewRevisionEditor {
 
     async fn notify_did_update_setting(&self) {
         let setting = self.get_view_setting().await;
-        send_notification(&self.view_id, DatabaseNotification::DidUpdateDatabaseSetting)
+        send_notification(&self.view_id, DatabaseNotification::DidUpdateSettings)
             .payload(setting)
             .send();
     }
 
     pub async fn notify_did_update_group_rows(&self, payload: GroupRowsNotificationPB) {
-        send_notification(&payload.group_id, DatabaseNotification::DidUpdateGroup)
+        send_notification(&payload.group_id, DatabaseNotification::DidUpdateGroupRow)
             .payload(payload)
             .send();
     }
@@ -679,8 +679,8 @@ impl DatabaseViewRevisionEditor {
         }
     }
 
-    async fn notify_did_update_view(&self, changeset: GroupViewChangesetPB) {
-        send_notification(&self.view_id, DatabaseNotification::DidUpdateGroupView)
+    async fn notify_did_update_groups(&self, changeset: GroupChangesetPB) {
+        send_notification(&self.view_id, DatabaseNotification::DidUpdateGroups)
             .payload(changeset)
             .send();
     }

+ 1 - 1
frontend/rust-lib/flowy-database/src/services/view_editor/editor_manager.rs

@@ -53,7 +53,7 @@ impl DatabaseViewManager {
         self.view_editors.write().await.remove(view_id).await;
     }
 
-    pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<GridViewChanged>> {
+    pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<DatabaseViewChanged>> {
         Ok(self.get_view_editor(view_id).await?.notifier.subscribe())
     }
 

+ 4 - 4
frontend/rust-lib/flowy-database/src/services/view_editor/trait_impl.rs

@@ -1,4 +1,4 @@
-use crate::entities::{DatabaseViewLayout, DatabaseViewSettingPB, ViewLayoutConfigPB};
+use crate::entities::{DatabaseViewSettingPB, LayoutTypePB, ViewLayoutPB};
 use crate::services::field::RowSingleCellData;
 use crate::services::filter::{FilterController, FilterDelegate, FilterType};
 use crate::services::group::{GroupConfigurationReader, GroupConfigurationWriter};
@@ -132,13 +132,13 @@ pub(crate) async fn apply_change(
 }
 
 pub fn make_grid_setting(view_pad: &GridViewRevisionPad, field_revs: &[Arc<FieldRevision>]) -> DatabaseViewSettingPB {
-    let layout_type: DatabaseViewLayout = view_pad.layout.clone().into();
+    let layout_type: LayoutTypePB = view_pad.layout.clone().into();
     let filters = view_pad.get_all_filters(field_revs);
     let group_configurations = view_pad.get_groups_by_field_revs(field_revs);
     let sorts = view_pad.get_all_sorts(field_revs);
     DatabaseViewSettingPB {
-        layouts: ViewLayoutConfigPB::all(),
-        layout_type,
+        support_layouts: ViewLayoutPB::all(),
+        current_layout: layout_type,
         filters: filters.into(),
         sorts: sorts.into(),
         group_configurations: group_configurations.into(),

+ 4 - 4
frontend/rust-lib/flowy-database/tests/grid/block_test/script.rs

@@ -1,7 +1,7 @@
 use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow};
 use crate::grid::block_test::util::GridRowTestBuilder;
 use crate::grid::database_editor::DatabaseEditorTest;
-use flowy_database::entities::{CellPathParams, CreateRowParams, DatabaseViewLayout, FieldType, RowPB};
+use flowy_database::entities::{CellIdParams, CreateRowParams, FieldType, LayoutTypePB, RowPB};
 use flowy_database::services::field::*;
 use flowy_database::services::row::DatabaseBlockRow;
 use grid_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision};
@@ -79,7 +79,7 @@ impl DatabaseRowTest {
                     database_id: self.editor.database_id.clone(),
                     start_row_id: None,
                     group_id: None,
-                    layout: DatabaseViewLayout::Grid,
+                    layout: LayoutTypePB::Grid,
                 };
                 let row_order = self.editor.create_row(params).await.unwrap();
                 self.row_by_row_id.insert(row_order.row_id().to_owned(), row_order);
@@ -112,7 +112,7 @@ impl DatabaseRowTest {
                 field_type,
                 expected,
             } => {
-                let id = CellPathParams {
+                let id = CellIdParams {
                     database_id: self.view_id.clone(),
                     field_id,
                     row_id,
@@ -157,7 +157,7 @@ impl DatabaseRowTest {
         }
     }
 
-    async fn compare_cell_content(&self, cell_id: CellPathParams, field_type: FieldType, expected: String) {
+    async fn compare_cell_content(&self, cell_id: CellIdParams, field_type: FieldType, expected: String) {
         match field_type {
             FieldType::RichText => {
                 let cell_data = self

+ 6 - 6
frontend/rust-lib/flowy-database/tests/grid/database_editor.rs

@@ -25,28 +25,28 @@ pub struct DatabaseEditorTest {
 
 impl DatabaseEditorTest {
     pub async fn new_table() -> Self {
-        Self::new(DatabaseViewLayout::Grid).await
+        Self::new(LayoutTypePB::Grid).await
     }
 
     pub async fn new_board() -> Self {
-        Self::new(DatabaseViewLayout::Board).await
+        Self::new(LayoutTypePB::Board).await
     }
 
-    pub async fn new(layout: DatabaseViewLayout) -> Self {
+    pub async fn new(layout: LayoutTypePB) -> Self {
         let sdk = FlowySDKTest::default();
         let _ = sdk.init_user().await;
         let test = match layout {
-            DatabaseViewLayout::Grid => {
+            LayoutTypePB::Grid => {
                 let build_context = make_test_grid();
                 let view_data: Bytes = build_context.into();
                 ViewTest::new_grid_view(&sdk, view_data.to_vec()).await
             }
-            DatabaseViewLayout::Board => {
+            LayoutTypePB::Board => {
                 let build_context = make_test_board();
                 let view_data: Bytes = build_context.into();
                 ViewTest::new_board_view(&sdk, view_data.to_vec()).await
             }
-            DatabaseViewLayout::Calendar => {
+            LayoutTypePB::Calendar => {
                 let build_context = make_test_calendar();
                 let view_data: Bytes = build_context.into();
                 ViewTest::new_calendar_view(&sdk, view_data.to_vec()).await

+ 4 - 4
frontend/rust-lib/flowy-database/tests/grid/filter_test/script.rs

@@ -7,14 +7,14 @@ use std::time::Duration;
 use bytes::Bytes;
 use futures::TryFutureExt;
 use tokio::sync::broadcast::Receiver;
-use flowy_database::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, DatabaseViewLayout, DatabaseSettingChangesetParams, DatabaseViewSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB};
+use flowy_database::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, LayoutTypePB, DatabaseSettingChangesetParams, DatabaseViewSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB};
 use flowy_database::services::field::{SelectOptionCellChangeset, SelectOptionIds};
 use flowy_database::services::setting::GridSettingChangesetBuilder;
 use grid_model::{FieldRevision, FieldTypeRevision};
 use flowy_sqlite::schema::view_table::dsl::view_table;
 use flowy_database::services::cell::insert_select_option_cell;
 use flowy_database::services::filter::FilterType;
-use flowy_database::services::view_editor::GridViewChanged;
+use flowy_database::services::view_editor::DatabaseViewChanged;
 use crate::grid::database_editor::DatabaseEditorTest;
 
 pub struct FilterRowChanged {
@@ -101,7 +101,7 @@ pub enum FilterScript {
 
 pub struct DatabaseFilterTest {
     inner: DatabaseEditorTest,
-    recv: Option<Receiver<GridViewChanged>>,
+    recv: Option<Receiver<DatabaseViewChanged>>,
 }
 
 impl DatabaseFilterTest {
@@ -274,7 +274,7 @@ impl DatabaseFilterTest {
         tokio::spawn(async move {
             match tokio::time::timeout(Duration::from_secs(2), receiver.recv()).await {
                 Ok(changed) =>  {
-                    match changed.unwrap() { GridViewChanged::FilterNotification(notification) => {
+                    match changed.unwrap() { DatabaseViewChanged::FilterNotification(notification) => {
                         assert_eq!(notification.visible_rows.len(), change.showing_num_of_rows, "visible rows not match");
                         assert_eq!(notification.invisible_rows.len(), change.hiding_num_of_rows, "invisible rows not match");
                     }

+ 2 - 2
frontend/rust-lib/flowy-database/tests/grid/group_test/script.rs

@@ -1,6 +1,6 @@
 use crate::grid::database_editor::DatabaseEditorTest;
 use flowy_database::entities::{
-    CreateRowParams, DatabaseViewLayout, FieldType, GroupPB, MoveGroupParams, MoveGroupRowParams, RowPB,
+    CreateRowParams, FieldType, GroupPB, LayoutTypePB, MoveGroupParams, MoveGroupRowParams, RowPB,
 };
 use flowy_database::services::cell::{delete_select_option_cell, insert_select_option_cell, insert_url_cell};
 use flowy_database::services::field::{
@@ -119,7 +119,7 @@ impl DatabaseGroupTest {
                     database_id: self.editor.database_id.clone(),
                     start_row_id: None,
                     group_id: Some(group.group_id.clone()),
-                    layout: DatabaseViewLayout::Board,
+                    layout: LayoutTypePB::Board,
                 };
                 let _ = self.editor.create_row(params).await.unwrap();
             }

+ 7 - 7
frontend/rust-lib/flowy-database/tests/grid/sort_test/script.rs

@@ -1,8 +1,8 @@
 use crate::grid::database_editor::DatabaseEditorTest;
 use async_stream::stream;
-use flowy_database::entities::{AlterSortParams, CellPathParams, DeleteSortParams};
+use flowy_database::entities::{AlterSortParams, CellIdParams, DeleteSortParams};
 use flowy_database::services::sort::SortType;
-use flowy_database::services::view_editor::GridViewChanged;
+use flowy_database::services::view_editor::DatabaseViewChanged;
 use futures::stream::StreamExt;
 use grid_model::{FieldRevision, SortCondition, SortRevision};
 use std::cmp::min;
@@ -39,7 +39,7 @@ pub enum SortScript {
 pub struct DatabaseSortTest {
     inner: DatabaseEditorTest,
     pub current_sort_rev: Option<SortRevision>,
-    recv: Option<Receiver<GridViewChanged>>,
+    recv: Option<Receiver<DatabaseViewChanged>>,
 }
 
 impl DatabaseSortTest {
@@ -85,7 +85,7 @@ impl DatabaseSortTest {
                 let mut cells = vec![];
                 let rows = self.editor.get_database(&self.view_id).await.unwrap().rows;
                 for row in rows {
-                    let params = CellPathParams {
+                    let params = CellIdParams {
                         database_id: self.view_id.clone(),
                         field_id: field_id.clone(),
                         row_id: row.id,
@@ -125,7 +125,7 @@ impl DatabaseSortTest {
 }
 
 async fn assert_sort_changed(
-    mut receiver: Receiver<GridViewChanged>,
+    mut receiver: Receiver<DatabaseViewChanged>,
     new_row_orders: Vec<String>,
     old_row_orders: Vec<String>,
 ) {
@@ -141,8 +141,8 @@ async fn assert_sort_changed(
     stream
         .for_each(|changed| async {
             match changed {
-                GridViewChanged::ReorderAllRowsNotification(_changed) => {}
-                GridViewChanged::ReorderSingleRowNotification(changed) => {
+                DatabaseViewChanged::ReorderAllRowsNotification(_changed) => {}
+                DatabaseViewChanged::ReorderSingleRowNotification(changed) => {
                     let mut old_row_orders = old_row_orders.clone();
                     let old = old_row_orders.remove(changed.old_index);
                     old_row_orders.insert(changed.new_index, old);

+ 1 - 3
frontend/rust-lib/flowy-folder/src/manager.rs

@@ -61,7 +61,6 @@ impl AsRef<str> for FolderId {
 
 pub struct FolderManager {
     pub user: Arc<dyn WorkspaceUser>,
-    pub(crate) cloud_service: Arc<dyn FolderCouldServiceV1>,
     pub(crate) persistence: Arc<FolderPersistence>,
     pub(crate) workspace_controller: Arc<WorkspaceController>,
     pub(crate) app_controller: Arc<AppController>,
@@ -118,7 +117,6 @@ impl FolderManager {
 
         Self {
             user,
-            cloud_service,
             persistence,
             workspace_controller,
             app_controller,
@@ -249,7 +247,7 @@ impl DefaultFolderBuilder {
         let repeated_workspace = RepeatedWorkspacePB {
             items: vec![workspace_rev.into()],
         };
-        send_notification(token, FolderNotification::UserCreateWorkspace)
+        send_notification(token, FolderNotification::DidCreateWorkspace)
             .payload(repeated_workspace)
             .send();
         Ok(())

+ 22 - 13
frontend/rust-lib/flowy-folder/src/notification.rs

@@ -5,19 +5,28 @@ const OBSERVABLE_CATEGORY: &str = "Workspace";
 #[derive(ProtoBuf_Enum, Debug)]
 pub(crate) enum FolderNotification {
     Unknown = 0,
-    UserCreateWorkspace = 10,
-    UserDeleteWorkspace = 11,
-    WorkspaceUpdated = 12,
-    WorkspaceListUpdated = 13,
-    WorkspaceAppsChanged = 14,
-    WorkspaceSetting = 15,
-    AppUpdated = 21,
-    ViewUpdated = 31,
-    ViewDeleted = 32,
-    ViewRestored = 33,
-    ViewMoveToTrash = 34,
-    UserUnauthorized = 100,
-    TrashUpdated = 1000,
+    /// Trigger after creating a workspace
+    DidCreateWorkspace = 1,
+    /// Trigger after deleting a workspace
+    DidDeleteWorkspace = 2,
+    /// Trigger after updating a workspace
+    DidUpdateWorkspace = 3,
+    /// Trigger when the number of apps of the workspace is changed
+    DidUpdateWorkspaceApps = 4,
+    /// Trigger when the settings of the workspace are changed. The changes including the latest visiting view, etc
+    DidUpdateWorkspaceSetting = 5,
+    /// Trigger when the properties including rename,update description of the app are changed
+    DidUpdateApp = 20,
+    /// Trigger when the properties including rename,update description of the view are changed
+    DidUpdateView = 30,
+    /// Trigger after deleting the view
+    DidDeleteView = 31,
+    /// Trigger when restore the view from trash
+    DidRestoreView = 32,
+    /// Trigger after moving the view to trash
+    DidMoveViewToTrash = 33,
+    /// Trigger when the number of trash is changed
+    DidUpdateTrash = 34,
 }
 
 impl std::default::Default for FolderNotification {

+ 2 - 31
frontend/rust-lib/flowy-folder/src/services/app/controller.rs

@@ -72,7 +72,6 @@ impl AppController {
                 Ok(Some(app))
             })
             .await?;
-        self.read_app_on_server(params)?;
         Ok(app)
     }
 
@@ -89,7 +88,7 @@ impl AppController {
             })
             .await?
             .into();
-        send_notification(&app_id, FolderNotification::AppUpdated)
+        send_notification(&app_id, FolderNotification::DidUpdateApp)
             .payload(app)
             .send();
         self.update_app_on_server(params)?;
@@ -147,34 +146,6 @@ impl AppController {
         Ok(())
     }
 
-    #[tracing::instrument(level = "trace", skip(self), err)]
-    fn read_app_on_server(&self, params: AppIdPB) -> Result<(), FlowyError> {
-        let token = self.user.token()?;
-        let server = self.cloud_service.clone();
-        let persistence = self.persistence.clone();
-        tokio::spawn(async move {
-            match server.read_app(&token, params).await {
-                Ok(Some(app_rev)) => {
-                    match persistence
-                        .begin_transaction(|transaction| transaction.create_app(app_rev.clone()))
-                        .await
-                    {
-                        Ok(_) => {
-                            let app: AppPB = app_rev.into();
-                            send_notification(&app.id, FolderNotification::AppUpdated)
-                                .payload(app)
-                                .send();
-                        }
-                        Err(e) => log::error!("Save app failed: {:?}", e),
-                    }
-                }
-                Ok(None) => {}
-                Err(e) => log::error!("Read app failed: {:?}", e),
-            }
-        });
-        Ok(())
-    }
-
     fn listen_trash_controller_event(&self) {
         let mut rx = self.trash_controller.subscribe();
         let persistence = self.persistence.clone();
@@ -246,7 +217,7 @@ fn notify_apps_changed<'a>(
         .map(|app_rev| app_rev.into())
         .collect();
     let repeated_app = RepeatedAppPB { items };
-    send_notification(workspace_id, FolderNotification::WorkspaceAppsChanged)
+    send_notification(workspace_id, FolderNotification::DidUpdateWorkspaceApps)
         .payload(repeated_app)
         .send();
     Ok(())

+ 1 - 1
frontend/rust-lib/flowy-folder/src/services/trash/controller.rs

@@ -206,7 +206,7 @@ impl TrashController {
 fn notify_trash_changed<T: Into<RepeatedTrashPB>>(repeated_trash: T) {
     let repeated_trash = repeated_trash.into();
     tracing::Span::current().record("n_trash", repeated_trash.len());
-    send_anonymous_notification(FolderNotification::TrashUpdated)
+    send_anonymous_notification(FolderNotification::DidUpdateTrash)
         .payload(repeated_trash)
         .send();
 }

+ 6 - 35
frontend/rust-lib/flowy-folder/src/services/view/controller.rs

@@ -4,7 +4,7 @@ use crate::manager::{ViewDataProcessor, ViewDataProcessorMap};
 use crate::{
     entities::{
         trash::{RepeatedTrashIdPB, TrashType},
-        view::{CreateViewParams, UpdateViewParams, ViewIdPB, ViewPB},
+        view::{CreateViewParams, UpdateViewParams, ViewPB},
     },
     errors::{FlowyError, FlowyResult},
     event_map::{FolderCouldServiceV1, WorkspaceUser},
@@ -194,7 +194,7 @@ impl ViewController {
             })
             .await?;
 
-        send_notification(view_id, FolderNotification::ViewMoveToTrash)
+        send_notification(view_id, FolderNotification::DidMoveViewToTrash)
             .payload(deleted_view)
             .send();
 
@@ -260,7 +260,7 @@ impl ViewController {
                 transaction.update_view(changeset)?;
                 let view_rev = transaction.read_view(&view_id)?;
                 let view: ViewPB = view_rev.clone().into();
-                send_notification(&view_id, FolderNotification::ViewUpdated)
+                send_notification(&view_id, FolderNotification::DidUpdateView)
                     .payload(view)
                     .send();
                 notify_views_changed(&view_rev.app_id, self.trash_controller.clone(), &transaction)?;
@@ -310,35 +310,6 @@ impl ViewController {
         Ok(())
     }
 
-    #[tracing::instrument(level = "debug", skip(self), err)]
-    fn read_view_on_server(&self, params: ViewIdPB) -> Result<(), FlowyError> {
-        let token = self.user.token()?;
-        let server = self.cloud_service.clone();
-        let persistence = self.persistence.clone();
-        // TODO: Retry with RetryAction?
-        tokio::spawn(async move {
-            match server.read_view(&token, params).await {
-                Ok(Some(view_rev)) => {
-                    match persistence
-                        .begin_transaction(|transaction| transaction.create_view(view_rev.clone()))
-                        .await
-                    {
-                        Ok(_) => {
-                            let view: ViewPB = view_rev.into();
-                            send_notification(&view.id, FolderNotification::ViewUpdated)
-                                .payload(view)
-                                .send();
-                        }
-                        Err(e) => log::error!("Save view failed: {:?}", e),
-                    }
-                }
-                Ok(None) => {}
-                Err(e) => log::error!("Read view failed: {:?}", e),
-            }
-        });
-        Ok(())
-    }
-
     fn listen_trash_can_event(&self) {
         let mut rx = self.trash_controller.subscribe();
         let persistence = self.persistence.clone();
@@ -407,7 +378,7 @@ async fn handle_trash_event(
                     let view_revs = read_local_views_with_transaction(identifiers, &transaction)?;
                     for view_rev in view_revs {
                         notify_views_changed(&view_rev.app_id, trash_can.clone(), &transaction)?;
-                        notify_dart(view_rev.into(), FolderNotification::ViewDeleted);
+                        notify_dart(view_rev.into(), FolderNotification::DidDeleteView);
                     }
                     Ok(())
                 })
@@ -420,7 +391,7 @@ async fn handle_trash_event(
                     let view_revs = read_local_views_with_transaction(identifiers, &transaction)?;
                     for view_rev in view_revs {
                         notify_views_changed(&view_rev.app_id, trash_can.clone(), &transaction)?;
-                        notify_dart(view_rev.into(), FolderNotification::ViewRestored);
+                        notify_dart(view_rev.into(), FolderNotification::DidRestoreView);
                     }
                     Ok(())
                 })
@@ -506,7 +477,7 @@ fn notify_views_changed<'a>(
     app_rev.belongings.retain(|view| !trash_ids.contains(&view.id));
     let app: AppPB = app_rev.into();
 
-    send_notification(belong_to_id, FolderNotification::AppUpdated)
+    send_notification(belong_to_id, FolderNotification::DidUpdateApp)
         .payload(app)
         .send();
 

+ 4 - 4
frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs

@@ -53,7 +53,7 @@ impl WorkspaceController {
             .map(|workspace_rev| workspace_rev.into())
             .collect();
         let repeated_workspace = RepeatedWorkspacePB { items: workspaces };
-        send_notification(&token, FolderNotification::UserCreateWorkspace)
+        send_notification(&token, FolderNotification::DidCreateWorkspace)
             .payload(repeated_workspace)
             .send();
         set_current_workspace(&user_id, &workspace.id);
@@ -73,7 +73,7 @@ impl WorkspaceController {
             })
             .await?;
 
-        send_notification(&workspace_id, FolderNotification::WorkspaceUpdated)
+        send_notification(&workspace_id, FolderNotification::DidUpdateWorkspace)
             .payload(workspace)
             .send();
         self.update_workspace_on_server(params)?;
@@ -92,7 +92,7 @@ impl WorkspaceController {
                 self.read_workspaces(None, &user_id, &transaction)
             })
             .await?;
-        send_notification(&token, FolderNotification::UserDeleteWorkspace)
+        send_notification(&token, FolderNotification::DidDeleteWorkspace)
             .payload(repeated_workspace)
             .send();
         self.delete_workspace_on_server(workspace_id)?;
@@ -236,7 +236,7 @@ pub async fn notify_workspace_setting_did_change(
         })
         .await?;
 
-    send_notification(&token, FolderNotification::WorkspaceSetting)
+    send_notification(&token, FolderNotification::DidUpdateWorkspaceSetting)
         .payload(workspace_setting)
         .send();
     Ok(())

+ 0 - 61
frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs

@@ -6,7 +6,6 @@ use crate::entities::{
 use crate::{
     errors::FlowyError,
     manager::FolderManager,
-    notification::{send_notification, FolderNotification},
     services::{get_current_workspace, read_workspace_apps, WorkspaceController},
 };
 use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
@@ -71,7 +70,6 @@ pub(crate) async fn read_workspaces_handler(
             Ok(workspaces)
         })
         .await?;
-    let _ = read_workspaces_on_server(folder, user_id, params);
     data_result(workspaces)
 }
 
@@ -81,10 +79,6 @@ pub async fn read_cur_workspace_handler(
 ) -> DataResult<WorkspaceSettingPB, FlowyError> {
     let user_id = folder.user.user_id()?;
     let workspace_id = get_current_workspace(&user_id)?;
-    let params = WorkspaceIdPB {
-        value: Some(workspace_id.clone()),
-    };
-
     let workspace = folder
         .persistence
         .begin_transaction(|transaction| {
@@ -101,60 +95,5 @@ pub async fn read_cur_workspace_handler(
         .unwrap_or(None)
         .map(|view_rev| view_rev.into());
     let setting = WorkspaceSettingPB { workspace, latest_view };
-    let _ = read_workspaces_on_server(folder, user_id, params);
     data_result(setting)
 }
-
-#[tracing::instrument(level = "trace", skip(folder_manager), err)]
-fn read_workspaces_on_server(
-    folder_manager: AFPluginState<Arc<FolderManager>>,
-    user_id: String,
-    params: WorkspaceIdPB,
-) -> Result<(), FlowyError> {
-    let (token, server) = (folder_manager.user.token()?, folder_manager.cloud_service.clone());
-    let persistence = folder_manager.persistence.clone();
-
-    tokio::spawn(async move {
-        let workspace_revs = server.read_workspace(&token, params).await?;
-        persistence
-            .begin_transaction(|transaction| {
-                for workspace_rev in &workspace_revs {
-                    let m_workspace = workspace_rev.clone();
-                    let app_revs = m_workspace.apps.clone();
-                    transaction.create_workspace(&user_id, m_workspace)?;
-                    tracing::trace!("Save {} apps", app_revs.len());
-                    for app_rev in app_revs {
-                        let view_revs = app_rev.belongings.clone();
-                        match transaction.create_app(app_rev) {
-                            Ok(_) => {}
-                            Err(e) => log::error!("create app failed: {:?}", e),
-                        }
-
-                        tracing::trace!("Save {} views", view_revs.len());
-                        for view_rev in view_revs {
-                            match transaction.create_view(view_rev) {
-                                Ok(_) => {}
-                                Err(e) => log::error!("create view failed: {:?}", e),
-                            }
-                        }
-                    }
-                }
-                Ok(())
-            })
-            .await?;
-
-        let repeated_workspace = RepeatedWorkspacePB {
-            items: workspace_revs
-                .into_iter()
-                .map(|workspace_rev| workspace_rev.into())
-                .collect(),
-        };
-
-        send_notification(&token, FolderNotification::WorkspaceListUpdated)
-            .payload(repeated_workspace)
-            .send();
-        Result::<(), FlowyError>::Ok(())
-    });
-
-    Ok(())
-}