mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-07 14:12:20 +00:00
fix: grid filters (#6317)
This commit is contained in:
parent
d67d77f442
commit
710e894446
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{DatabaseSyncStatePB, DidFetchRowPB, InsertedRowPB, RowMetaPB, RowsChangePB};
|
use crate::entities::{DatabaseSyncStatePB, DidFetchRowPB, RowsChangePB};
|
||||||
use crate::notification::{send_notification, DatabaseNotification, DATABASE_OBSERVABLE_SOURCE};
|
use crate::notification::{send_notification, DatabaseNotification, DATABASE_OBSERVABLE_SOURCE};
|
||||||
use crate::services::database::{DatabaseEditor, UpdatedRow};
|
use crate::services::database::{DatabaseEditor, UpdatedRow};
|
||||||
use crate::services::database_view::DatabaseViewEditor;
|
use crate::services::database_view::DatabaseViewEditor;
|
||||||
@ -189,7 +189,7 @@ async fn handle_did_update_row_orders(
|
|||||||
// Delete row: Next, we delete a from its original position at index 0.
|
// Delete row: Next, we delete a from its original position at index 0.
|
||||||
// Delete row indexes: [0]
|
// Delete row indexes: [0]
|
||||||
// Final state after delete: [b, a, c]
|
// Final state after delete: [b, a, c]
|
||||||
let database_view_rows = DashMap::new();
|
let row_changes = DashMap::new();
|
||||||
// 1. handle insert row orders
|
// 1. handle insert row orders
|
||||||
for (row_order, index) in insert_row_orders {
|
for (row_order, index) in insert_row_orders {
|
||||||
if let Err(err) = database_editor.init_database_row(&row_order.id).await {
|
if let Err(err) = database_editor.init_database_row(&row_order.id).await {
|
||||||
@ -204,7 +204,7 @@ async fn handle_did_update_row_orders(
|
|||||||
is_local_change
|
is_local_change
|
||||||
);
|
);
|
||||||
|
|
||||||
// insert row order
|
// insert row order in database view cache
|
||||||
{
|
{
|
||||||
let mut view_row_orders = database_view.row_orders.write().await;
|
let mut view_row_orders = database_view.row_orders.write().await;
|
||||||
if view_row_orders.len() >= index as usize {
|
if view_row_orders.len() >= index as usize {
|
||||||
@ -219,26 +219,17 @@ async fn handle_did_update_row_orders(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let is_move_row = is_move_row(&database_view, &row_order, &delete_row_indexes).await;
|
let is_move_row = is_move_row(&database_view, &row_order, &delete_row_indexes).await;
|
||||||
if let Some(row) = database_editor
|
|
||||||
.get_row(&database_view.view_id, &row_order.id)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
database_view
|
|
||||||
.v_did_create_row(&row, index, is_move_row, is_local_change)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
// gather changes for notification
|
|
||||||
if let Some((index, row_detail)) = database_view.v_get_row(&row_order.id).await {
|
if let Some((index, row_detail)) = database_view.v_get_row(&row_order.id).await {
|
||||||
database_view_rows
|
database_view
|
||||||
.entry(database_view.view_id.clone())
|
.v_did_create_row(
|
||||||
.or_insert_with(|| {
|
&row_detail,
|
||||||
let mut change = RowsChangePB::new();
|
index as u32,
|
||||||
change.is_move_row = is_move_row;
|
is_move_row,
|
||||||
change
|
is_local_change,
|
||||||
})
|
&row_changes,
|
||||||
.inserted_rows
|
)
|
||||||
.push(InsertedRowPB::new(RowMetaPB::from(row_detail.as_ref())).with_index(index as i32));
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,7 +243,7 @@ async fn handle_did_update_row_orders(
|
|||||||
let lazy_row = view_row_orders.remove(index);
|
let lazy_row = view_row_orders.remove(index);
|
||||||
// Update changeset in RowsChangePB
|
// Update changeset in RowsChangePB
|
||||||
let row_id = lazy_row.id.to_string();
|
let row_id = lazy_row.id.to_string();
|
||||||
let mut row_change = database_view_rows
|
let mut row_change = row_changes
|
||||||
.entry(database_view.view_id.clone())
|
.entry(database_view.view_id.clone())
|
||||||
.or_default();
|
.or_default();
|
||||||
row_change.deleted_rows.push(row_id);
|
row_change.deleted_rows.push(row_id);
|
||||||
@ -283,7 +274,7 @@ async fn handle_did_update_row_orders(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. notify the view
|
// 3. notify the view
|
||||||
for entry in database_view_rows.into_iter() {
|
for entry in row_changes.into_iter() {
|
||||||
let (view_id, changes) = entry;
|
let (view_id, changes) = entry;
|
||||||
trace!("[RowOrder]: {}", changes);
|
trace!("[RowOrder]: {}", changes);
|
||||||
send_notification(&view_id, DatabaseNotification::DidUpdateRow)
|
send_notification(&view_id, DatabaseNotification::DidUpdateRow)
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
#![allow(clippy::while_let_loop)]
|
#![allow(clippy::while_let_loop)]
|
||||||
use crate::entities::{
|
use crate::entities::{
|
||||||
CalculationChangesetNotificationPB, DatabaseViewSettingPB, FilterChangesetNotificationPB,
|
CalculationChangesetNotificationPB, DatabaseViewSettingPB, FilterChangesetNotificationPB,
|
||||||
GroupChangesPB, GroupRowsNotificationPB, InsertedRowPB, ReorderAllRowsPB, ReorderSingleRowPB,
|
GroupChangesPB, GroupRowsNotificationPB, ReorderAllRowsPB, ReorderSingleRowPB,
|
||||||
RowMetaPB, RowsChangePB, RowsVisibilityChangePB, SortChangesetNotificationPB,
|
RowsVisibilityChangePB, SortChangesetNotificationPB,
|
||||||
};
|
};
|
||||||
use crate::notification::{send_notification, DatabaseNotification};
|
use crate::notification::{send_notification, DatabaseNotification};
|
||||||
use crate::services::filter::FilterResultNotification;
|
use crate::services::filter::FilterResultNotification;
|
||||||
use crate::services::sort::{InsertRowResult, ReorderAllRowsResult, ReorderSingleRowResult};
|
use crate::services::sort::{ReorderAllRowsResult, ReorderSingleRowResult};
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
@ -16,7 +16,6 @@ pub enum DatabaseViewChanged {
|
|||||||
FilterNotification(FilterResultNotification),
|
FilterNotification(FilterResultNotification),
|
||||||
ReorderAllRowsNotification(ReorderAllRowsResult),
|
ReorderAllRowsNotification(ReorderAllRowsResult),
|
||||||
ReorderSingleRowNotification(ReorderSingleRowResult),
|
ReorderSingleRowNotification(ReorderSingleRowResult),
|
||||||
InsertRowNotification(InsertRowResult),
|
|
||||||
CalculationValueNotification(CalculationChangesetNotificationPB),
|
CalculationValueNotification(CalculationChangesetNotificationPB),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,17 +78,6 @@ impl DatabaseViewChangedReceiverRunner {
|
|||||||
.payload(reorder_row)
|
.payload(reorder_row)
|
||||||
.send()
|
.send()
|
||||||
},
|
},
|
||||||
DatabaseViewChanged::InsertRowNotification(result) => {
|
|
||||||
let inserted_row = InsertedRowPB {
|
|
||||||
row_meta: RowMetaPB::from(result.row),
|
|
||||||
index: Some(result.index as i32),
|
|
||||||
is_new: true,
|
|
||||||
};
|
|
||||||
let changes = RowsChangePB::from_insert(inserted_row);
|
|
||||||
send_notification(&result.view_id, DatabaseNotification::DidUpdateRow)
|
|
||||||
.payload(changes)
|
|
||||||
.send();
|
|
||||||
},
|
|
||||||
DatabaseViewChanged::CalculationValueNotification(notification) => send_notification(
|
DatabaseViewChanged::CalculationValueNotification(notification) => send_notification(
|
||||||
¬ification.view_id,
|
¬ification.view_id,
|
||||||
DatabaseNotification::DidUpdateCalculation,
|
DatabaseNotification::DidUpdateCalculation,
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use super::notify_did_update_calculation;
|
|||||||
use crate::entities::{
|
use crate::entities::{
|
||||||
CalendarEventPB, CreateRowParams, CreateRowPayloadPB, DatabaseLayoutMetaPB,
|
CalendarEventPB, CreateRowParams, CreateRowPayloadPB, DatabaseLayoutMetaPB,
|
||||||
DatabaseLayoutSettingPB, DeleteSortPayloadPB, FieldSettingsChangesetPB, FieldType,
|
DatabaseLayoutSettingPB, DeleteSortPayloadPB, FieldSettingsChangesetPB, FieldType,
|
||||||
GroupChangesPB, GroupPB, LayoutSettingChangeset, LayoutSettingParams,
|
GroupChangesPB, GroupPB, InsertedRowPB, LayoutSettingChangeset, LayoutSettingParams,
|
||||||
RemoveCalculationChangesetPB, ReorderSortPayloadPB, RowMetaPB, RowsChangePB,
|
RemoveCalculationChangesetPB, ReorderSortPayloadPB, RowMetaPB, RowsChangePB,
|
||||||
SortChangesetNotificationPB, SortPB, UpdateCalculationChangesetPB, UpdateSortPayloadPB,
|
SortChangesetNotificationPB, SortPB, UpdateCalculationChangesetPB, UpdateSortPayloadPB,
|
||||||
};
|
};
|
||||||
@ -208,16 +208,15 @@ impl DatabaseViewEditor {
|
|||||||
|
|
||||||
pub async fn v_did_create_row(
|
pub async fn v_did_create_row(
|
||||||
&self,
|
&self,
|
||||||
row: &Row,
|
row_detail: &RowDetail,
|
||||||
index: u32,
|
index: u32,
|
||||||
is_move_row: bool,
|
_is_move_row: bool,
|
||||||
is_local_change: bool,
|
_is_local_change: bool,
|
||||||
|
row_changes: &DashMap<String, RowsChangePB>,
|
||||||
) {
|
) {
|
||||||
// Send the group notification if the current view has groups
|
// Send the group notification if the current view has groups
|
||||||
|
|
||||||
if !is_move_row || !is_local_change {
|
|
||||||
if let Some(controller) = self.group_controller.write().await.as_mut() {
|
if let Some(controller) = self.group_controller.write().await.as_mut() {
|
||||||
let rows = vec![Arc::new(row.clone())];
|
let rows = vec![Arc::new(row_detail.row.clone())];
|
||||||
let mut rows = self.v_filter_rows(rows).await;
|
let mut rows = self.v_filter_rows(rows).await;
|
||||||
if let Some(row) = rows.pop() {
|
if let Some(row) = rows.pop() {
|
||||||
let changesets = controller.did_create_row(&row, index as usize);
|
let changesets = controller.did_create_row(&row, index as usize);
|
||||||
@ -226,9 +225,24 @@ impl DatabaseViewEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.gen_did_create_row_view_tasks(index, row.clone()).await;
|
if let Some(index) = self
|
||||||
|
.sort_controller
|
||||||
|
.write()
|
||||||
|
.await
|
||||||
|
.did_create_row(&row_detail.row)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
row_changes
|
||||||
|
.entry(self.view_id.clone())
|
||||||
|
.or_default()
|
||||||
|
.inserted_rows
|
||||||
|
.push(InsertedRowPB::new(RowMetaPB::from(row_detail)).with_index(index as i32));
|
||||||
|
};
|
||||||
|
|
||||||
|
self
|
||||||
|
.gen_did_create_row_view_tasks(row_detail.row.clone())
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all)]
|
#[tracing::instrument(level = "trace", skip_all)]
|
||||||
@ -1190,18 +1204,9 @@ impl DatabaseViewEditor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn gen_did_create_row_view_tasks(&self, preliminary_index: u32, row: Row) {
|
async fn gen_did_create_row_view_tasks(&self, row: Row) {
|
||||||
let weak_sort_controller = Arc::downgrade(&self.sort_controller);
|
|
||||||
let weak_calculations_controller = Arc::downgrade(&self.calculations_controller);
|
let weak_calculations_controller = Arc::downgrade(&self.calculations_controller);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Some(sort_controller) = weak_sort_controller.upgrade() {
|
|
||||||
sort_controller
|
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.did_create_row(preliminary_index, &row)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(calculations_controller) = weak_calculations_controller.upgrade() {
|
if let Some(calculations_controller) = weak_calculations_controller.upgrade() {
|
||||||
calculations_controller
|
calculations_controller
|
||||||
.did_receive_row_changed(row.clone())
|
.did_receive_row_changed(row.clone())
|
||||||
|
|||||||
@ -21,7 +21,7 @@ use crate::services::field::{
|
|||||||
default_order, TimestampCellData, TimestampCellDataWrapper, TypeOptionCellExt,
|
default_order, TimestampCellData, TimestampCellDataWrapper, TypeOptionCellExt,
|
||||||
};
|
};
|
||||||
use crate::services::sort::{
|
use crate::services::sort::{
|
||||||
InsertRowResult, ReorderAllRowsResult, ReorderSingleRowResult, Sort, SortChangeset, SortCondition,
|
ReorderAllRowsResult, ReorderSingleRowResult, Sort, SortChangeset, SortCondition,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -99,27 +99,31 @@ impl SortController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn did_create_row(&self, preliminary_index: u32, row: &Row) {
|
pub async fn did_create_row(&mut self, row: &Row) -> Option<u32> {
|
||||||
if !self.delegate.filter_row(row).await {
|
if !self.delegate.filter_row(row).await {
|
||||||
return;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.sorts.is_empty() {
|
if !self.sorts.is_empty() {
|
||||||
self
|
let mut rows = self.delegate.get_rows(&self.view_id).await;
|
||||||
.gen_task(
|
self.sort_rows(&mut rows).await;
|
||||||
SortEvent::NewRowInserted(row.clone()),
|
|
||||||
QualityOfService::Background,
|
let row_index = self
|
||||||
)
|
.row_index_cache
|
||||||
.await;
|
.get(&row.id)
|
||||||
|
.cloned()
|
||||||
|
.map(|val| val as u32);
|
||||||
|
|
||||||
|
if row_index.is_none() {
|
||||||
|
tracing::trace!("The row index cache is outdated");
|
||||||
|
}
|
||||||
|
row_index
|
||||||
} else {
|
} else {
|
||||||
let result = InsertRowResult {
|
let rows = self.delegate.get_rows(&self.view_id).await;
|
||||||
view_id: self.view_id.clone(),
|
rows
|
||||||
row: row.clone(),
|
.iter()
|
||||||
index: preliminary_index,
|
.position(|val| val.id == row.id)
|
||||||
};
|
.map(|val| val as u32)
|
||||||
let _ = self
|
|
||||||
.notifier
|
|
||||||
.send(DatabaseViewChanged::InsertRowNotification(result));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,24 +168,6 @@ impl SortController {
|
|||||||
_ => tracing::trace!("The row index cache is outdated"),
|
_ => tracing::trace!("The row index cache is outdated"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SortEvent::NewRowInserted(row) => {
|
|
||||||
self.sort_rows(&mut rows).await;
|
|
||||||
let row_index = self.row_index_cache.get(&row.id).cloned();
|
|
||||||
match row_index {
|
|
||||||
Some(row_index) => {
|
|
||||||
let notification = InsertRowResult {
|
|
||||||
view_id: self.view_id.clone(),
|
|
||||||
row: row.clone(),
|
|
||||||
index: row_index as u32,
|
|
||||||
};
|
|
||||||
self.row_index_cache.insert(row.id, row_index);
|
|
||||||
let _ = self
|
|
||||||
.notifier
|
|
||||||
.send(DatabaseViewChanged::InsertRowNotification(notification));
|
|
||||||
},
|
|
||||||
_ => tracing::trace!("The row index cache is outdated"),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -363,7 +349,6 @@ fn cmp_cell(
|
|||||||
enum SortEvent {
|
enum SortEvent {
|
||||||
SortDidChanged,
|
SortDidChanged,
|
||||||
RowDidChanged(RowId),
|
RowDidChanged(RowId),
|
||||||
NewRowInserted(Row),
|
|
||||||
DeleteAllSorts,
|
DeleteAllSorts,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use std::cmp::Ordering;
|
|||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use collab::preclude::Any;
|
use collab::preclude::Any;
|
||||||
use collab::util::AnyMapExt;
|
use collab::util::AnyMapExt;
|
||||||
use collab_database::rows::{Row, RowId};
|
use collab_database::rows::RowId;
|
||||||
use collab_database::views::{SortMap, SortMapBuilder};
|
use collab_database::views::{SortMap, SortMapBuilder};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -110,13 +110,6 @@ pub struct ReorderSingleRowResult {
|
|||||||
pub new_index: usize,
|
pub new_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct InsertRowResult {
|
|
||||||
pub view_id: String,
|
|
||||||
pub row: Row,
|
|
||||||
pub index: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct SortChangeset {
|
pub struct SortChangeset {
|
||||||
pub(crate) insert_sort: Option<Sort>,
|
pub(crate) insert_sort: Option<Sort>,
|
||||||
|
|||||||
@ -232,7 +232,6 @@ async fn assert_sort_changed(
|
|||||||
old_row_orders.insert(changed.new_index, old);
|
old_row_orders.insert(changed.new_index, old);
|
||||||
assert_eq!(old_row_orders, new_row_orders);
|
assert_eq!(old_row_orders, new_row_orders);
|
||||||
},
|
},
|
||||||
DatabaseViewChanged::InsertRowNotification(_changed) => {},
|
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user