fix: deleting a sorting field doesn't delete existing sorts (#4611)

This commit is contained in:
Richard Shiue 2024-02-07 10:47:17 +08:00 committed by GitHub
parent a9c6b80f4a
commit b781c9aa0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 27 deletions

View File

@ -769,6 +769,35 @@ impl DatabaseViewEditor {
Ok(())
}
pub async fn v_did_delete_field(&self, deleted_field_id: &str) {
let sorts = self.delegate.get_all_sorts(&self.view_id);
if let Some(sort) = sorts.iter().find(|sort| sort.field_id == deleted_field_id) {
self.delegate.remove_sort(&self.view_id, &sort.id);
let notification = self
.sort_controller
.write()
.await
.apply_changeset(SortChangeset::from_delete(sort.id.clone()))
.await;
if !notification.is_empty() {
notify_did_update_sort(notification).await;
}
}
self
.calculations_controller
.did_receive_field_deleted(deleted_field_id.to_string())
.await;
}
pub async fn v_did_update_field_type(&self, field_id: &str, new_field_type: &FieldType) {
self
.calculations_controller
.did_receive_field_type_changed(field_id.to_owned(), new_field_type.to_owned())
.await;
}
/// Notifies the view's field type-option data is changed
/// For the moment, only the groups will be generated after the type-option data changed. A
/// [Field] has a property named type_options contains a list of type-option data.
@ -1023,20 +1052,6 @@ impl DatabaseViewEditor {
Ok(())
}
pub async fn v_did_delete_field(&self, field_id: &str) {
self
.calculations_controller
.did_receive_field_deleted(field_id.to_owned())
.await;
}
pub async fn v_did_update_field_type(&self, field_id: &str, new_field_type: &FieldType) {
self
.calculations_controller
.did_receive_field_type_changed(field_id.to_owned(), new_field_type.to_owned())
.await;
}
async fn mut_group_controller<F, T>(&self, f: F) -> Option<T>
where
F: FnOnce(&mut Box<dyn GroupController>, Field) -> FlowyResult<T>,

View File

@ -121,7 +121,7 @@ pub struct ReorderSingleRowResult {
pub new_index: usize,
}
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct SortChangeset {
pub(crate) insert_sort: Option<Sort>,
pub(crate) update_sort: Option<Sort>,
@ -133,36 +133,28 @@ impl SortChangeset {
pub fn from_insert(sort: Sort) -> Self {
Self {
insert_sort: Some(sort),
update_sort: None,
delete_sort: None,
reorder_sort: None,
..Default::default()
}
}
pub fn from_update(sort: Sort) -> Self {
Self {
insert_sort: None,
update_sort: Some(sort),
delete_sort: None,
reorder_sort: None,
..Default::default()
}
}
pub fn from_delete(sort_id: String) -> Self {
Self {
insert_sort: None,
update_sort: None,
delete_sort: Some(sort_id),
reorder_sort: None,
..Default::default()
}
}
pub fn from_reorder(from_sort_id: String, to_sort_id: String) -> Self {
Self {
insert_sort: None,
update_sort: None,
delete_sort: None,
reorder_sort: Some((from_sort_id, to_sort_id)),
..Default::default()
}
}
}