From 26f8397624834ddcbbe74aced99555bfb1307aa7 Mon Sep 17 00:00:00 2001 From: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:42:16 +0100 Subject: [PATCH] feat: duplicate field with cell data (#4737) * feat: duplicate field with cell data * chore: code review remove extra option --- .../lib/plugins/database/domain/field_service.dart | 5 +---- .../presentation/widgets/header/field_editor.dart | 3 ++- .../rust-lib/flowy-database2/src/event_handler.rs | 2 +- .../src/services/database/database_editor.rs | 12 +++++++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dart b/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dart index 6574b903a4..4274c97c87 100644 --- a/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dart +++ b/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dart @@ -67,10 +67,7 @@ class FieldBackendService { required String viewId, required String fieldId, }) { - final payload = DuplicateFieldPayloadPB( - viewId: viewId, - fieldId: fieldId, - ); + final payload = DuplicateFieldPayloadPB(viewId: viewId, fieldId: fieldId); return DatabaseEventDuplicateField(payload).send(); } diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/field_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/field_editor.dart index d7040d54c2..1456f15996 100644 --- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/field_editor.dart +++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/field_editor.dart @@ -1,5 +1,7 @@ import 'dart:typed_data'; +import 'package:flutter/material.dart'; + import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/plugins/database/application/field/field_controller.dart'; @@ -14,7 +16,6 @@ import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart'; import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart'; -import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:styled_widget/styled_widget.dart'; diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rs index b92bfc9484..c61b89b583 100644 --- a/frontend/rust-lib/flowy-database2/src/event_handler.rs +++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs @@ -281,7 +281,7 @@ pub(crate) async fn duplicate_field_handler( manager: AFPluginState>, ) -> Result<(), FlowyError> { let manager = upgrade_manager(manager)?; - let params: FieldIdParams = data.into_inner().try_into()?; + let params: DuplicateFieldPayloadPB = data.into_inner(); let database_editor = manager.get_database_with_view_id(¶ms.view_id).await?; database_editor .duplicate_field(¶ms.view_id, ¶ms.field_id) diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs index bf77ce7e7e..ab62f80286 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs @@ -441,8 +441,18 @@ impl DatabaseEditor { .duplicate_field(view_id, field_id, |field| format!("{} (copy)", field.name)); if let Some((index, duplicated_field)) = value { let _ = self - .notify_did_insert_database_field(duplicated_field, index) + .notify_did_insert_database_field(duplicated_field.clone(), index) .await; + + let new_field_id = duplicated_field.id.clone(); + let cells = self.get_cells_for_field(view_id, field_id).await; + for cell in cells { + if let Some(new_cell) = cell.cell.clone() { + self + .update_cell(view_id, cell.row_id, &new_field_id, new_cell) + .await?; + } + } } Ok(()) }