Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: auto update field title when creating a new field (#6159)
Nathan.fooo08bf5db2de42
diff --git a/.github/workflows/flutter_ci.yaml b/.github/workflows/flutter_ci.yamlindex 761e75f6b0..9b9725a09f 100644--- a/.github/workflows/flutter_ci.yaml+++ b/.github/workflows/flutter_ci.yaml@@ -248,12 +248,24 @@ jobs:env:APPFLOWY_CLOUD_VERSION: 0.6.4-amd64run: |- if [ "$(docker ps --filter name=appflowy-cloud -q)" == "" ]; then+ container_id=$(docker ps --filter name=appflowy-cloud-appflowy_cloud-1 -q)+ if [ -z "$container_id" ]; then+ echo "AppFlowy-Cloud container is not running. Pulling and starting the container..."docker compose pulldocker compose up -d+ echo "Waiting for the container to be ready..."sleep 10else- echo "Docker container 'appflowy-cloud' is already running."+ running_image=$(docker inspect --format='{{index .Config.Image}}' "$container_id")+ if [ "$running_image" != "appflowy-cloud:$APPFLOWY_CLOUD_VERSION" ]; then+ echo "AppFlowy-Cloud is running with an incorrect version. Pulling the correct version..."+ docker compose pull+ docker compose up -d+ echo "Waiting for the container to be ready..."+ sleep 10+ else+ echo "AppFlowy-Cloud is running with the correct version."+ fifi- name: Checkout source codediff --git a/.github/workflows/rust_ci.yaml b/.github/workflows/rust_ci.yamlindex e6b7017023..566aef3b7b 100644--- a/.github/workflows/rust_ci.yaml+++ b/.github/workflows/rust_ci.yaml@@ -129,17 +129,29 @@ jobs:sed -i 's|RUST_LOG=.*|RUST_LOG=trace|' .envsed -i 's|API_EXTERNAL_URL=.*|API_EXTERNAL_URL=http://localhost|' .env- - name: Run Docker-Compose+ - name: Ensure AppFlowy-Cloud is Running with Correct Versionworking-directory: AppFlowy-Cloudenv:APPFLOWY_CLOUD_VERSION: 0.6.4-amd64run: |- if [ "$(docker ps --filter name=appflowy-cloud -q)" == "" ]; then+ container_id=$(docker ps --filter name=appflowy-cloud-appflowy_cloud-1 -q)+ if [ -z "$container_id" ]; then+ echo "AppFlowy-Cloud container is not running. Pulling and starting the container..."docker compose pulldocker compose up -d+ echo "Waiting for the container to be ready..."sleep 10else- echo "Docker container 'appflowy-cloud' is already running."+ running_image=$(docker inspect --format='{{index .Config.Image}}' "$container_id")+ if [ "$running_image" != "appflowy-cloud:$APPFLOWY_CLOUD_VERSION" ]; then+ echo "AppFlowy-Cloud is running with an incorrect version. Pulling the correct version..."+ docker compose pull+ docker compose up -d+ echo "Waiting for the container to be ready..."+ sleep 10+ else+ echo "AppFlowy-Cloud is running with the correct version."+ fifi- name: Run rust-lib testsdiff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_quick_field_editor.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_quick_field_editor.dartindex 0b415b04a6..5444805708 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_quick_field_editor.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_quick_field_editor.dart@@ -62,6 +62,7 @@ class _QuickEditFieldState extends State<QuickEditField> {viewId: widget.viewId,fieldController: widget.fieldController,field: widget.fieldInfo.field,+ isNew: false,),child: BlocConsumer<FieldEditorBloc, FieldEditorState>(listenWhen: (previous, current) =>diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dartindex dab09c02f7..700cd86cc2 100644--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dart@@ -43,9 +43,6 @@ class TextCellBloc extends Bloc<TextCellEvent, TextCellState> {emit(state.copyWith(wrap: wrap));}},- didUpdateEmoji: (String emoji, bool hasDocument) {- // emit(state.copyWith(emoji: emoji, hasDocument: hasDocument));- },updateText: (String text) {if (state.content != text) {cellController.saveCellData(text, debounce: true);@@ -85,10 +82,6 @@ class TextCellEvent with _$TextCellEvent {_DidUpdateField;const factory TextCellEvent.updateText(String text) = _UpdateText;const factory TextCellEvent.enableEdit(bool enabled) = _EnableEdit;- const factory TextCellEvent.didUpdateEmoji(- String emoji,- bool hasDocument,- ) = _UpdateEmoji;}@freezed@@ -105,15 +98,17 @@ class TextCellState with _$TextCellState {final cellData = cellController.getCellData() ?? "";final wrap = cellController.fieldInfo.wrapCellContent ?? true;ValueNotifier<String>? emoji;+ ValueNotifier<bool>? hasDocument;if (cellController.fieldInfo.isPrimary) {emoji = cellController.icon;+ hasDocument = cellController.hasDocument;}return TextCellState(content: cellData,emoji: emoji,enableEdit: false,- hasDocument: cellController.hasDocument,+ hasDocument: hasDocument,wrap: wrap,);}diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/field/field_editor_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/field/field_editor_bloc.dartindex b33f9f44ee..a4748c0143 100644--- a/frontend/appflowy_flutter/lib/plugins/database/application/field/field_editor_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/application/field/field_editor_bloc.dart@@ -2,6 +2,7 @@ import 'dart:typed_data';import 'package:appflowy/plugins/database/domain/field_service.dart';import 'package:appflowy/plugins/database/domain/field_settings_service.dart';+import 'package:appflowy/util/field_type_extension.dart';import 'package:appflowy_backend/log.dart';import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';@@ -20,6 +21,7 @@ class FieldEditorBloc extends Bloc<FieldEditorEvent, FieldEditorState> {required this.fieldController,this.onFieldInserted,required FieldPB field,+ required this.isNew,}) : fieldId = field.id,fieldService = FieldBackendService(viewId: viewId,@@ -34,6 +36,7 @@ class FieldEditorBloc extends Bloc<FieldEditorEvent, FieldEditorState> {final String viewId;final String fieldId;+ final bool isNew;final FieldController fieldController;final FieldBackendService fieldService;final FieldSettingsBackendService fieldSettingsService;@@ -58,11 +61,20 @@ class FieldEditorBloc extends Bloc<FieldEditorEvent, FieldEditorState> {emit(state.copyWith(field: fieldInfo));},switchFieldType: (fieldType) async {- await fieldService.updateType(fieldType: fieldType);+ String? fieldName;+ if (!state.wasRenameManually && isNew) {+ fieldName = fieldType.i18n;+ }++ await fieldService.updateType(+ fieldType: fieldType,+ fieldName: fieldName,+ );},renameField: (newName) async {final result = await fieldService.updateField(name: newName);_logIfError(result);+ emit(state.copyWith(wasRenameManually: true));},updateTypeOption: (typeOptionData) async {final result = await FieldBackendService.updateFieldTypeOption(@@ -164,5 +176,6 @@ class FieldEditorEvent with _$FieldEditorEvent {class FieldEditorState with _$FieldEditorState {const factory FieldEditorState({required final FieldInfo field,+ @Default(false) bool wasRenameManually,}) = _FieldEditorState;}diff --git a/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dart b/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dartindex 9bc873f7f1..fe23916d2d 100644--- a/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/domain/field_service.dart@@ -110,12 +110,18 @@ class FieldBackendService {required String viewId,required String fieldId,required FieldType fieldType,+ String? fieldName,}) {final payload = UpdateFieldTypePayloadPB()..viewId = viewId..fieldId = fieldId..fieldType = fieldType;+ // Only set if fieldName is not null+ if (fieldName != null) {+ payload.fieldName = fieldName;+ }+return DatabaseEventUpdateFieldType(payload).send();}@@ -177,11 +183,13 @@ class FieldBackendService {Future<FlowyResult<void, FlowyError>> updateType({required FieldType fieldType,+ String? fieldName,}) =>updateFieldType(viewId: viewId,fieldId: fieldId,fieldType: fieldType,+ fieldName: fieldName,);Future<FlowyResult<void, FlowyError>> delete() =>diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/desktop_field_cell.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/desktop_field_cell.dartindex d127ef6f91..b14643381d 100755--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/desktop_field_cell.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/desktop_field_cell.dart@@ -87,6 +87,7 @@ class _GridFieldCellState extends State<GridFieldCell> {viewId: widget.viewId,fieldController: widget.fieldController,field: widget.fieldInfo.field,+ isNewField: widget.isNew,initialPage: widget.isNew? FieldEditorPage.details: FieldEditorPage.general,diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/field/field_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/field/field_editor.dartindex 8ff2ccea13..e0d040ea64 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/field/field_editor.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/field/field_editor.dart@@ -33,6 +33,7 @@ class FieldEditor extends StatefulWidget {required this.viewId,required this.field,required this.fieldController,+ required this.isNewField,this.initialPage = FieldEditorPage.details,this.onFieldInserted,});@@ -42,6 +43,7 @@ class FieldEditor extends StatefulWidget {final FieldController fieldController;final FieldEditorPage initialPage;final void Function(String fieldId)? onFieldInserted;+ final bool isNewField;@overrideState<StatefulWidget> createState() => _FieldEditorState();@@ -72,6 +74,7 @@ class _FieldEditorState extends State<FieldEditor> {field: widget.field,fieldController: widget.fieldController,onFieldInserted: widget.onFieldInserted,+ isNew: widget.isNewField,),child: _currentPage == FieldEditorPage.details? _fieldDetails()diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_property.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_property.dartindex 60dc940cea..6dd81fc501 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_property.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_property.dart@@ -153,6 +153,7 @@ class _PropertyCellState extends State<_PropertyCell> {.getField(widget.cellContext.fieldId)!.field,fieldController: widget.fieldController,+ isNewField: false,),child: ValueListenableBuilder(valueListenable: _isFieldHover,@@ -230,6 +231,7 @@ class _PropertyCellState extends State<_PropertyCell> {viewId: widget.fieldController.viewId,field: fieldInfo.field,fieldController: widget.fieldController,+ isNewField: false,),child: SizedBox(width: 160,@@ -415,6 +417,7 @@ class _CreateRowFieldButtonState extends State<CreateRowFieldButton> {viewId: widget.viewId,field: createdField!,fieldController: widget.fieldController,+ isNewField: true,);},);diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dartindex f7dd93d9bc..125e0b08f9 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/setting/setting_property_list.dart@@ -206,6 +206,7 @@ class _DatabasePropertyCellState extends State<DatabasePropertyCell> {viewId: widget.viewId,field: widget.fieldInfo.field,fieldController: widget.fieldController,+ isNewField: false,);},);diff --git a/frontend/appflowy_flutter/test/bloc_test/board_test/create_or_edit_field_test.dart b/frontend/appflowy_flutter/test/bloc_test/board_test/create_or_edit_field_test.dartindex 752ff272da..187fa6d5e9 100644--- a/frontend/appflowy_flutter/test/bloc_test/board_test/create_or_edit_field_test.dart+++ b/frontend/appflowy_flutter/test/bloc_test/board_test/create_or_edit_field_test.dart@@ -36,6 +36,7 @@ void main() {viewId: context.gridView.id,field: fieldInfo.field,fieldController: context.fieldController,+ isNew: false,);await boardResponseFuture();diff --git a/frontend/appflowy_flutter/test/bloc_test/board_test/util.dart b/frontend/appflowy_flutter/test/bloc_test/board_test/util.dartindex e29c6a4a73..e89f5a8815 100644--- a/frontend/appflowy_flutter/test/bloc_test/board_test/util.dart+++ b/frontend/appflowy_flutter/test/bloc_test/board_test/util.dart@@ -83,6 +83,7 @@ class BoardTestContext {viewId: databaseController.viewId,fieldController: fieldController,field: fieldInfo.field,+ isNew: false,);return editorBloc;}diff --git a/frontend/appflowy_flutter/test/bloc_test/grid_test/field/edit_field_test.dart b/frontend/appflowy_flutter/test/bloc_test/grid_test/field/edit_field_test.dartindex 32b1d603d9..b3a3a3b5cf 100644--- a/frontend/appflowy_flutter/test/bloc_test/grid_test/field/edit_field_test.dart+++ b/frontend/appflowy_flutter/test/bloc_test/grid_test/field/edit_field_test.dart@@ -11,6 +11,7 @@ Future<FieldEditorBloc> createEditorBloc(AppFlowyGridTest gridTest) async {viewId: context.gridView.id,fieldController: context.fieldController,field: fieldInfo.field,+ isNew: false,);}diff --git a/frontend/appflowy_flutter/test/bloc_test/grid_test/util.dart b/frontend/appflowy_flutter/test/bloc_test/grid_test/util.dartindex 66502b44cf..c652bfcb6a 100644--- a/frontend/appflowy_flutter/test/bloc_test/grid_test/util.dart+++ b/frontend/appflowy_flutter/test/bloc_test/grid_test/util.dart@@ -103,6 +103,7 @@ Future<FieldEditorBloc> createFieldEditor({viewId: databaseController.viewId,fieldController: databaseController.fieldController,field: field,+ isNew: true,);},(err) => throw Exception(err),diff --git a/frontend/rust-lib/event-integration-test/src/database_event.rs b/frontend/rust-lib/event-integration-test/src/database_event.rsindex 41757b99d1..041849bf87 100644--- a/frontend/rust-lib/event-integration-test/src/database_event.rs+++ b/frontend/rust-lib/event-integration-test/src/database_event.rs@@ -184,6 +184,7 @@ impl EventIntegrationTest {view_id: view_id.to_string(),field_id: field_id.to_string(),field_type,+ field_name: None,}).async_send().awaitdiff --git a/frontend/rust-lib/flowy-database2/src/entities/field_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/field_entities.rsindex 3263986db8..a2c35d32a8 100644--- a/frontend/rust-lib/flowy-database2/src/entities/field_entities.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/field_entities.rs@@ -207,12 +207,16 @@ pub struct UpdateFieldTypePayloadPB {#[pb(index = 3)]pub field_type: FieldType,++ #[pb(index = 4, one_of)]+ pub field_name: Option<String>,}pub struct EditFieldParams {pub view_id: String,pub field_id: String,pub field_type: FieldType,+ pub field_name: Option<String>,}impl TryInto<EditFieldParams> for UpdateFieldTypePayloadPB {@@ -225,6 +229,7 @@ impl TryInto<EditFieldParams> for UpdateFieldTypePayloadPB {view_id: view_id.0,field_id: field_id.0,field_type: self.field_type,+ field_name: self.field_name,})}}diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rsindex fd1a7bf276..4c85e15024 100644--- a/frontend/rust-lib/flowy-database2/src/event_handler.rs+++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs@@ -332,7 +332,12 @@ pub(crate) async fn switch_to_field_handler(.await?;let old_field = database_editor.get_field(¶ms.field_id).await;database_editor- .switch_to_field_type(¶ms.view_id, ¶ms.field_id, params.field_type)+ .switch_to_field_type(+ ¶ms.view_id,+ ¶ms.field_id,+ params.field_type,+ params.field_name,+ ).await?;if let Some(new_type_option) = database_editordiff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rsindex fc1facf0b2..7d42b41ffc 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@@ -443,6 +443,7 @@ impl DatabaseEditor {view_id: &str,field_id: &str,new_field_type: FieldType,+ field_name: Option<String>,) -> FlowyResult<()> {let mut database = self.database.write().await;let field = database.get_field(field_id);@@ -476,6 +477,7 @@ impl DatabaseEditor {database.update_field(field_id, |update| {update.set_field_type(new_field_type.into())+ .set_name_if_not_none(field_name).set_type_option(new_field_type.into(), Some(transformed_type_option));});diff --git a/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rsindex 64a41d869d..c2c3472395 100644--- a/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rs@@ -88,7 +88,7 @@ impl DatabaseFieldTest {//self.editor- .switch_to_field_type(&view_id, &field_id, new_field_type)+ .switch_to_field_type(&view_id, &field_id, new_field_type, None).await.unwrap();},