feat: duplicate field with cell data (#4737)

* feat: duplicate field with cell data

* chore: code review remove extra option
This commit is contained in:
Mathias Mogensen 2024-02-27 14:42:16 +01:00 committed by GitHub
parent d67e904f56
commit 26f8397624
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 7 deletions

View File

@ -67,10 +67,7 @@ class FieldBackendService {
required String viewId, required String viewId,
required String fieldId, required String fieldId,
}) { }) {
final payload = DuplicateFieldPayloadPB( final payload = DuplicateFieldPayloadPB(viewId: viewId, fieldId: fieldId);
viewId: viewId,
fieldId: fieldId,
);
return DatabaseEventDuplicateField(payload).send(); return DatabaseEventDuplicateField(payload).send();
} }

View File

@ -1,5 +1,7 @@
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/field/field_controller.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:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';

View File

@ -281,7 +281,7 @@ pub(crate) async fn duplicate_field_handler(
manager: AFPluginState<Weak<DatabaseManager>>, manager: AFPluginState<Weak<DatabaseManager>>,
) -> Result<(), FlowyError> { ) -> Result<(), FlowyError> {
let manager = upgrade_manager(manager)?; 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(&params.view_id).await?; let database_editor = manager.get_database_with_view_id(&params.view_id).await?;
database_editor database_editor
.duplicate_field(&params.view_id, &params.field_id) .duplicate_field(&params.view_id, &params.field_id)

View File

@ -441,8 +441,18 @@ impl DatabaseEditor {
.duplicate_field(view_id, field_id, |field| format!("{} (copy)", field.name)); .duplicate_field(view_id, field_id, |field| format!("{} (copy)", field.name));
if let Some((index, duplicated_field)) = value { if let Some((index, duplicated_field)) = value {
let _ = self let _ = self
.notify_did_insert_database_field(duplicated_field, index) .notify_did_insert_database_field(duplicated_field.clone(), index)
.await; .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(()) Ok(())
} }