Skip to content

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.

fix: deleting a sort doesn't allow creating a new sort on that field (#4660)

Richard Shiue3e0a003872b0
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dart b/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dart
index 60d1037b10..832c21440f 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/field/field_controller.dart
@@ -1,3 +1,5 @@
+import 'dart:collection';
+
import 'package:appflowy/plugins/database/application/database_view_service.dart';
import 'package:appflowy/plugins/database/application/field_settings/field_settings_listener.dart';
import 'package:appflowy/plugins/database/application/field_settings/field_settings_service.dart';
@@ -333,6 +335,32 @@ class FieldController {
}
}
+ void updateFieldInfos(
+ List<SortInfo> newSortInfos,
+ SortChangesetNotificationPB changeset,
+ ) {
+ final changedFieldIds = HashSet<String>.from([
+ ...changeset.insertSorts.map((sort) => sort.sort.fieldId),
+ ...changeset.updateSorts.map((sort) => sort.fieldId),
+ ...changeset.deleteSorts.map((sort) => sort.fieldId),
+ ]);
+
+ final newFieldInfos = [...fieldInfos];
+
+ for (final fieldId in changedFieldIds) {
+ final index =
+ newFieldInfos.indexWhere((fieldInfo) => fieldInfo.id == fieldId);
+ if (index == -1) {
+ continue;
+ }
+ newFieldInfos[index] = newFieldInfos[index].copyWith(
+ hasSort: newSortInfos.any((sort) => sort.fieldId == fieldId),
+ );
+ }
+
+ _fieldNotifier.fieldInfos = newFieldInfos;
+ }
+
_sortsListener.start(
onSortChanged: (result) {
if (_isDisposed) {
@@ -346,6 +374,7 @@ class FieldController {
updateSortFromChangeset(newSortInfos, changeset);
_sortNotifier?.sorts = newSortInfos;
+ updateFieldInfos(newSortInfos, changeset);
},
(err) => Log.error(err),
);