fix: implement move row in backend (#2575)

This commit is contained in:
Nathan.fooo 2023-05-21 22:47:08 +08:00 committed by GitHub
parent d842f228e8
commit ca7777e891
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 39 deletions

View File

@ -128,7 +128,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -139,7 +139,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -590,7 +590,7 @@ dependencies = [
"regex", "regex",
"rustc-hash", "rustc-hash",
"shlex", "shlex",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -1229,7 +1229,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"scratch", "scratch",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -1246,7 +1246,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -1984,7 +1984,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -2934,7 +2934,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -3086,7 +3086,7 @@ dependencies = [
"pest_meta", "pest_meta",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -3276,12 +3276,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]] [[package]]
name = "prettyplease" name = "prettyplease"
version = "0.2.4" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ceca8aaf45b5c46ec7ed39fff75f57290368c1846d33d24a122ca81416ab058" checksum = "617feabb81566b593beb4886fb8c1f38064169dae4dccad0e3220160c3b37203"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -4083,7 +4083,7 @@ checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -4105,7 +4105,7 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -4327,9 +4327,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.15" version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -4424,7 +4424,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -4537,7 +4537,7 @@ checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]

View File

@ -84,12 +84,9 @@ impl InsertedRowPB {
} }
} }
pub fn with_index(row: RowPB, index: i32) -> Self { pub fn with_index(mut self, index: i32) -> Self {
Self { self.index = Some(index);
row, self
index: Some(index),
is_new: false,
}
} }
} }

View File

@ -18,8 +18,8 @@ use crate::entities::{
AlterFilterParams, AlterSortParams, CalendarEventPB, CellChangesetNotifyPB, CellPB, AlterFilterParams, AlterSortParams, CalendarEventPB, CellChangesetNotifyPB, CellPB,
CreateRowParams, DatabaseFieldChangesetPB, DatabasePB, DatabaseViewSettingPB, DeleteFilterParams, CreateRowParams, DatabaseFieldChangesetPB, DatabasePB, DatabaseViewSettingPB, DeleteFilterParams,
DeleteGroupParams, DeleteSortParams, FieldChangesetParams, FieldIdPB, FieldPB, FieldType, DeleteGroupParams, DeleteSortParams, FieldChangesetParams, FieldIdPB, FieldPB, FieldType,
GroupPB, IndexFieldPB, InsertGroupParams, LayoutSettingParams, RepeatedFilterPB, RepeatedGroupPB, GroupPB, IndexFieldPB, InsertGroupParams, InsertedRowPB, LayoutSettingParams, RepeatedFilterPB,
RepeatedSortPB, RowPB, SelectOptionCellDataPB, SelectOptionPB, RepeatedGroupPB, RepeatedSortPB, RowPB, RowsChangesetPB, SelectOptionCellDataPB, SelectOptionPB,
}; };
use crate::notification::{send_notification, DatabaseNotification}; use crate::notification::{send_notification, DatabaseNotification};
use crate::services::cell::{ use crate::services::cell::{
@ -278,18 +278,26 @@ impl DatabaseEditor {
let _ = self.database.lock().duplicate_row(view_id, row_id); let _ = self.database.lock().duplicate_row(view_id, row_id);
} }
pub async fn move_row(&self, _view_id: &str, _from: RowId, _to: RowId) { pub async fn move_row(&self, view_id: &str, from: RowId, to: RowId) {
// self.database.lock().views.update_view(view_id, |view| { let database = self.database.lock();
// view.move_row_order(from as u32, to as u32); if let (Some(row), Some(from_index), Some(to_index)) = (
// }); database.get_row(&from),
// let changeset = RowsChangesetPB::from_move( database.index_of_row(view_id, &from),
// view_id.to_string(), database.index_of_row(view_id, &to),
// vec![from.into_inner()], ) {
// vec![to.into()], database.views.update_view(view_id, |view| {
// ); view.move_row_order(from_index as u32, to_index as u32);
// send_notification(&self.view_id, DatabaseNotification::DidUpdateViewRows) });
// .payload(changeset) drop(database);
// .send();
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>> { pub async fn create_row(&self, params: CreateRowParams) -> FlowyResult<Option<Row>> {

View File

@ -164,7 +164,7 @@ impl FilterController {
let row_pb = RowPB::from(row.as_ref()); let row_pb = RowPB::from(row.as_ref());
notification notification
.visible_rows .visible_rows
.push(InsertedRowPB::with_index(row_pb, index as i32)) .push(InsertedRowPB::new(row_pb).with_index(index as i32))
} }
} else { } else {
notification.invisible_rows.push(row_id); notification.invisible_rows.push(row_id);
@ -199,7 +199,7 @@ impl FilterController {
) { ) {
if is_visible { if is_visible {
let row_pb = RowPB::from(row.as_ref()); 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 { } else {
invisible_rows.push(row_id); invisible_rows.push(row_id);
} }