mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: deleting a sort doesn't allow creating a new sort on that field (#4660)
This commit is contained in:
parent
e81a2ff577
commit
3e0a003872
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:collection';
|
||||||
|
|
||||||
import 'package:appflowy/plugins/database/application/database_view_service.dart';
|
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_listener.dart';
|
||||||
import 'package:appflowy/plugins/database/application/field_settings/field_settings_service.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(
|
_sortsListener.start(
|
||||||
onSortChanged: (result) {
|
onSortChanged: (result) {
|
||||||
if (_isDisposed) {
|
if (_isDisposed) {
|
||||||
@ -346,6 +374,7 @@ class FieldController {
|
|||||||
updateSortFromChangeset(newSortInfos, changeset);
|
updateSortFromChangeset(newSortInfos, changeset);
|
||||||
|
|
||||||
_sortNotifier?.sorts = newSortInfos;
|
_sortNotifier?.sorts = newSortInfos;
|
||||||
|
updateFieldInfos(newSortInfos, changeset);
|
||||||
},
|
},
|
||||||
(err) => Log.error(err),
|
(err) => Log.error(err),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user