mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: sort by last modified time or created time (#4601)
This commit is contained in:
parent
95c4cb241a
commit
ef4bce25d8
@ -71,6 +71,8 @@ class FieldInfo with _$FieldInfo {
|
|||||||
case FieldType.DateTime:
|
case FieldType.DateTime:
|
||||||
case FieldType.SingleSelect:
|
case FieldType.SingleSelect:
|
||||||
case FieldType.MultiSelect:
|
case FieldType.MultiSelect:
|
||||||
|
case FieldType.LastEditedTime:
|
||||||
|
case FieldType.CreatedTime:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int64_t init_sdk(char *data);
|
int64_t init_sdk(int64_t port, char *data);
|
||||||
|
|
||||||
void async_event(int64_t port, const uint8_t *input, uintptr_t len);
|
void async_event(int64_t port, const uint8_t *input, uintptr_t len);
|
||||||
|
|
||||||
|
@ -160,6 +160,9 @@ impl DatabaseViewEditor {
|
|||||||
send_notification(&self.view_id, DatabaseNotification::DidUpdateViewRows)
|
send_notification(&self.view_id, DatabaseNotification::DidUpdateViewRows)
|
||||||
.payload(changes)
|
.payload(changes)
|
||||||
.send();
|
.send();
|
||||||
|
self
|
||||||
|
.gen_view_tasks(row_detail.row.id.clone(), "".to_string())
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn v_did_duplicate_row(&self, row_detail: &RowDetail) {
|
pub async fn v_did_duplicate_row(&self, row_detail: &RowDetail) {
|
||||||
@ -253,31 +256,10 @@ impl DatabaseViewEditor {
|
|||||||
|
|
||||||
// Each row update will trigger a calculations, filter and sort operation. We don't want
|
// Each row update will trigger a calculations, filter and sort operation. We don't want
|
||||||
// to block the main thread, so we spawn a new task to do the work.
|
// to block the main thread, so we spawn a new task to do the work.
|
||||||
let row_id = row_detail.row.id.clone();
|
self
|
||||||
let weak_filter_controller = Arc::downgrade(&self.filter_controller);
|
.gen_view_tasks(row_detail.row.id.clone(), field_id)
|
||||||
let weak_sort_controller = Arc::downgrade(&self.sort_controller);
|
|
||||||
let weak_calculations_controller = Arc::downgrade(&self.calculations_controller);
|
|
||||||
af_spawn(async move {
|
|
||||||
if let Some(filter_controller) = weak_filter_controller.upgrade() {
|
|
||||||
filter_controller
|
|
||||||
.did_receive_row_changed(row_id.clone())
|
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
if let Some(sort_controller) = weak_sort_controller.upgrade() {
|
|
||||||
sort_controller
|
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.did_receive_row_changed(row_id.clone())
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(calculations_controller) = weak_calculations_controller.upgrade() {
|
|
||||||
calculations_controller
|
|
||||||
.did_receive_cell_changed(field_id)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn v_filter_rows(&self, row_details: &mut Vec<Arc<RowDetail>>) {
|
pub async fn v_filter_rows(&self, row_details: &mut Vec<Arc<RowDetail>>) {
|
||||||
self.filter_controller.filter_rows(row_details).await
|
self.filter_controller.filter_rows(row_details).await
|
||||||
@ -1073,4 +1055,29 @@ impl DatabaseViewEditor {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn gen_view_tasks(&self, row_id: RowId, field_id: String) {
|
||||||
|
let weak_filter_controller = Arc::downgrade(&self.filter_controller);
|
||||||
|
let weak_sort_controller = Arc::downgrade(&self.sort_controller);
|
||||||
|
let weak_calculations_controller = Arc::downgrade(&self.calculations_controller);
|
||||||
|
af_spawn(async move {
|
||||||
|
if let Some(filter_controller) = weak_filter_controller.upgrade() {
|
||||||
|
filter_controller
|
||||||
|
.did_receive_row_changed(row_id.clone())
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
if let Some(sort_controller) = weak_sort_controller.upgrade() {
|
||||||
|
sort_controller
|
||||||
|
.read()
|
||||||
|
.await
|
||||||
|
.did_receive_row_changed(row_id)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
if let Some(calculations_controller) = weak_calculations_controller.upgrade() {
|
||||||
|
calculations_controller
|
||||||
|
.did_receive_cell_changed(field_id)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ use crate::entities::SortChangesetNotificationPB;
|
|||||||
use crate::entities::{FieldType, SortWithIndexPB};
|
use crate::entities::{FieldType, SortWithIndexPB};
|
||||||
use crate::services::cell::CellCache;
|
use crate::services::cell::CellCache;
|
||||||
use crate::services::database_view::{DatabaseViewChanged, DatabaseViewChangedNotifier};
|
use crate::services::database_view::{DatabaseViewChanged, DatabaseViewChangedNotifier};
|
||||||
use crate::services::field::{default_order, TypeOptionCellExt};
|
use crate::services::field::{
|
||||||
|
default_order, TimestampCellData, TimestampCellDataWrapper, TypeOptionCellExt,
|
||||||
|
};
|
||||||
use crate::services::sort::{
|
use crate::services::sort::{
|
||||||
ReorderAllRowsResult, ReorderSingleRowResult, Sort, SortChangeset, SortCondition,
|
ReorderAllRowsResult, ReorderSingleRowResult, Sort, SortChangeset, SortCondition,
|
||||||
};
|
};
|
||||||
@ -81,9 +83,13 @@ impl SortController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn did_receive_row_changed(&self, row_id: RowId) {
|
pub async fn did_receive_row_changed(&self, row_id: RowId) {
|
||||||
let task_type = SortEvent::RowDidChanged(row_id);
|
|
||||||
if !self.sorts.is_empty() {
|
if !self.sorts.is_empty() {
|
||||||
self.gen_task(task_type, QualityOfService::Background).await;
|
self
|
||||||
|
.gen_task(
|
||||||
|
SortEvent::RowDidChanged(row_id),
|
||||||
|
QualityOfService::Background,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,14 +258,36 @@ fn cmp_row(
|
|||||||
.find(|field_rev| field_rev.id == sort.field_id)
|
.find(|field_rev| field_rev.id == sort.field_id)
|
||||||
{
|
{
|
||||||
None => default_order(),
|
None => default_order(),
|
||||||
Some(field_rev) => cmp_cell(
|
Some(field_rev) => {
|
||||||
left.cells.get(&sort.field_id),
|
let timestamp_cells = match field_type {
|
||||||
right.cells.get(&sort.field_id),
|
FieldType::LastEditedTime | FieldType::CreatedTime => {
|
||||||
|
let (left_cell, right_cell) = if field_type.is_created_time() {
|
||||||
|
(left.created_at, right.created_at)
|
||||||
|
} else {
|
||||||
|
(left.modified_at, right.modified_at)
|
||||||
|
};
|
||||||
|
let (left_cell, right_cell) = (
|
||||||
|
TimestampCellDataWrapper::from((field_type, TimestampCellData::new(left_cell))),
|
||||||
|
TimestampCellDataWrapper::from((field_type, TimestampCellData::new(right_cell))),
|
||||||
|
);
|
||||||
|
Some((Some(left_cell.into()), Some(right_cell.into())))
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
cmp_cell(
|
||||||
|
timestamp_cells
|
||||||
|
.as_ref()
|
||||||
|
.map_or_else(|| left.cells.get(&sort.field_id), |cell| cell.0.as_ref()),
|
||||||
|
timestamp_cells
|
||||||
|
.as_ref()
|
||||||
|
.map_or_else(|| right.cells.get(&sort.field_id), |cell| cell.1.as_ref()),
|
||||||
field_rev,
|
field_rev,
|
||||||
field_type,
|
field_type,
|
||||||
cell_data_cache,
|
cell_data_cache,
|
||||||
sort.condition,
|
sort.condition,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,13 +304,7 @@ fn cmp_cell(
|
|||||||
{
|
{
|
||||||
None => default_order(),
|
None => default_order(),
|
||||||
Some(handler) => {
|
Some(handler) => {
|
||||||
let cal_order = || {
|
handler.handle_cell_compare(left_cell, right_cell, field.as_ref(), sort_condition)
|
||||||
let order =
|
|
||||||
handler.handle_cell_compare(left_cell, right_cell, field.as_ref(), sort_condition);
|
|
||||||
Option::<Ordering>::Some(order)
|
|
||||||
};
|
|
||||||
|
|
||||||
cal_order().unwrap_or_else(default_order)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user