chore: auto update field title when creating a new field (#6159)

* chore: auto update field title when creating a new field

* chore: fix test
This commit is contained in:
Nathan.fooo 2024-09-02 13:54:21 +08:00 committed by GitHub
parent 080b7db605
commit 08bf5db2de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 82 additions and 16 deletions

View File

@ -248,12 +248,24 @@ jobs:
env:
APPFLOWY_CLOUD_VERSION: 0.6.4-amd64
run: |
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 pull
docker compose up -d
echo "Waiting for the container to be ready..."
sleep 10
else
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."
fi
fi
- name: Checkout source code

View File

@ -129,17 +129,29 @@ jobs:
sed -i 's|RUST_LOG=.*|RUST_LOG=trace|' .env
sed -i 's|API_EXTERNAL_URL=.*|API_EXTERNAL_URL=http://localhost|' .env
- name: Run Docker-Compose
- name: Ensure AppFlowy-Cloud is Running with Correct Version
working-directory: AppFlowy-Cloud
env:
APPFLOWY_CLOUD_VERSION: 0.6.4-amd64
run: |
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 pull
docker compose up -d
echo "Waiting for the container to be ready..."
sleep 10
else
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."
fi
fi
- name: Run rust-lib tests

View File

@ -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) =>

View File

@ -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,
);
}

View File

@ -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;
}

View File

@ -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() =>

View File

@ -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,

View File

@ -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;
@override
State<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()

View File

@ -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,
);
},
);

View File

@ -206,6 +206,7 @@ class _DatabasePropertyCellState extends State<DatabasePropertyCell> {
viewId: widget.viewId,
field: widget.fieldInfo.field,
fieldController: widget.fieldController,
isNewField: false,
);
},
);

View File

@ -36,6 +36,7 @@ void main() {
viewId: context.gridView.id,
field: fieldInfo.field,
fieldController: context.fieldController,
isNew: false,
);
await boardResponseFuture();

View File

@ -83,6 +83,7 @@ class BoardTestContext {
viewId: databaseController.viewId,
fieldController: fieldController,
field: fieldInfo.field,
isNew: false,
);
return editorBloc;
}

View File

@ -11,6 +11,7 @@ Future<FieldEditorBloc> createEditorBloc(AppFlowyGridTest gridTest) async {
viewId: context.gridView.id,
fieldController: context.fieldController,
field: fieldInfo.field,
isNew: false,
);
}

View File

@ -103,6 +103,7 @@ Future<FieldEditorBloc> createFieldEditor({
viewId: databaseController.viewId,
fieldController: databaseController.fieldController,
field: field,
isNew: true,
);
},
(err) => throw Exception(err),

View File

@ -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()
.await

View File

@ -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,
})
}
}

View File

@ -332,7 +332,12 @@ pub(crate) async fn switch_to_field_handler(
.await?;
let old_field = database_editor.get_field(&params.field_id).await;
database_editor
.switch_to_field_type(&params.view_id, &params.field_id, params.field_type)
.switch_to_field_type(
&params.view_id,
&params.field_id,
params.field_type,
params.field_name,
)
.await?;
if let Some(new_type_option) = database_editor

View File

@ -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));
});

View File

@ -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();
},