mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: implement move row in backend (#2575)
This commit is contained in:
@ -84,12 +84,9 @@ impl InsertedRowPB {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_index(row: RowPB, index: i32) -> Self {
|
||||
Self {
|
||||
row,
|
||||
index: Some(index),
|
||||
is_new: false,
|
||||
}
|
||||
pub fn with_index(mut self, index: i32) -> Self {
|
||||
self.index = Some(index);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ use crate::entities::{
|
||||
AlterFilterParams, AlterSortParams, CalendarEventPB, CellChangesetNotifyPB, CellPB,
|
||||
CreateRowParams, DatabaseFieldChangesetPB, DatabasePB, DatabaseViewSettingPB, DeleteFilterParams,
|
||||
DeleteGroupParams, DeleteSortParams, FieldChangesetParams, FieldIdPB, FieldPB, FieldType,
|
||||
GroupPB, IndexFieldPB, InsertGroupParams, LayoutSettingParams, RepeatedFilterPB, RepeatedGroupPB,
|
||||
RepeatedSortPB, RowPB, SelectOptionCellDataPB, SelectOptionPB,
|
||||
GroupPB, IndexFieldPB, InsertGroupParams, InsertedRowPB, LayoutSettingParams, RepeatedFilterPB,
|
||||
RepeatedGroupPB, RepeatedSortPB, RowPB, RowsChangesetPB, SelectOptionCellDataPB, SelectOptionPB,
|
||||
};
|
||||
use crate::notification::{send_notification, DatabaseNotification};
|
||||
use crate::services::cell::{
|
||||
@ -278,18 +278,26 @@ impl DatabaseEditor {
|
||||
let _ = self.database.lock().duplicate_row(view_id, row_id);
|
||||
}
|
||||
|
||||
pub async fn move_row(&self, _view_id: &str, _from: RowId, _to: RowId) {
|
||||
// self.database.lock().views.update_view(view_id, |view| {
|
||||
// view.move_row_order(from as u32, to as u32);
|
||||
// });
|
||||
// let changeset = RowsChangesetPB::from_move(
|
||||
// view_id.to_string(),
|
||||
// vec![from.into_inner()],
|
||||
// vec![to.into()],
|
||||
// );
|
||||
// send_notification(&self.view_id, DatabaseNotification::DidUpdateViewRows)
|
||||
// .payload(changeset)
|
||||
// .send();
|
||||
pub async fn move_row(&self, view_id: &str, from: RowId, to: RowId) {
|
||||
let database = self.database.lock();
|
||||
if let (Some(row), Some(from_index), Some(to_index)) = (
|
||||
database.get_row(&from),
|
||||
database.index_of_row(view_id, &from),
|
||||
database.index_of_row(view_id, &to),
|
||||
) {
|
||||
database.views.update_view(view_id, |view| {
|
||||
view.move_row_order(from_index as u32, to_index as u32);
|
||||
});
|
||||
drop(database);
|
||||
|
||||
let delete_row_id = from.into_inner();
|
||||
let insert_row = InsertedRowPB::from(&row).with_index(to_index as i32);
|
||||
let changeset =
|
||||
RowsChangesetPB::from_move(view_id.to_string(), vec![delete_row_id], vec![insert_row]);
|
||||
send_notification(view_id, DatabaseNotification::DidUpdateViewRows)
|
||||
.payload(changeset)
|
||||
.send();
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_row(&self, params: CreateRowParams) -> FlowyResult<Option<Row>> {
|
||||
|
@ -164,7 +164,7 @@ impl FilterController {
|
||||
let row_pb = RowPB::from(row.as_ref());
|
||||
notification
|
||||
.visible_rows
|
||||
.push(InsertedRowPB::with_index(row_pb, index as i32))
|
||||
.push(InsertedRowPB::new(row_pb).with_index(index as i32))
|
||||
}
|
||||
} else {
|
||||
notification.invisible_rows.push(row_id);
|
||||
@ -199,7 +199,7 @@ impl FilterController {
|
||||
) {
|
||||
if is_visible {
|
||||
let row_pb = RowPB::from(row.as_ref());
|
||||
visible_rows.push(InsertedRowPB::with_index(row_pb, index as i32))
|
||||
visible_rows.push(InsertedRowPB::new(row_pb).with_index(index as i32))
|
||||
} else {
|
||||
invisible_rows.push(row_id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user