Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: implement move row in backend (#2575)
Nathan.foooca7777e891f9
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex 591497edb9..293f5b39f5 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -128,7 +128,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -139,7 +139,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -590,7 +590,7 @@ dependencies = ["regex","rustc-hash","shlex",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -1229,7 +1229,7 @@ dependencies = ["proc-macro2","quote","scratch",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -1246,7 +1246,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -1984,7 +1984,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -2934,7 +2934,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -3086,7 +3086,7 @@ dependencies = ["pest_meta","proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -3276,12 +3276,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"[[package]]name = "prettyplease"-version = "0.2.4"+version = "0.2.5"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "1ceca8aaf45b5c46ec7ed39fff75f57290368c1846d33d24a122ca81416ab058"+checksum = "617feabb81566b593beb4886fb8c1f38064169dae4dccad0e3220160c3b37203"dependencies = ["proc-macro2",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -4083,7 +4083,7 @@ checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -4105,7 +4105,7 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -4327,9 +4327,9 @@ dependencies = [[[package]]name = "syn"-version = "2.0.15"+version = "2.0.16"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"+checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01"dependencies = ["proc-macro2","quote",@@ -4424,7 +4424,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]@@ -4537,7 +4537,7 @@ checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce"dependencies = ["proc-macro2","quote",- "syn 2.0.15",+ "syn 2.0.16",][[package]]diff --git a/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/row_entities.rsindex 82ea8c8bec..f7a005b0f2 100644--- a/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs@@ -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}}diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rsindex 691b50a56e..b9ea2fb4af 100644--- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs@@ -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>> {diff --git a/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs b/frontend/rust-lib/flowy-database2/src/services/filter/controller.rsindex 6deb42fc4d..4fc1707556 100644--- a/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs+++ b/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs@@ -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);}