diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart b/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart index 8479120d7b..1b0d73de8f 100644 --- a/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart +++ b/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart @@ -28,16 +28,10 @@ class RowBackendService { ), ); - Map? cellDataByFieldId; - if (withCells != null) { final rowBuilder = RowDataBuilder(); withCells(rowBuilder); - cellDataByFieldId = rowBuilder.build(); - } - - if (cellDataByFieldId != null) { - payload.data = RowDataPB(cellDataByFieldId: cellDataByFieldId); + payload.data.addAll(rowBuilder.build()); } return DatabaseEventCreateRow(payload).send(); diff --git a/frontend/appflowy_tauri/src/appflowy_app/application/database/row/row_service.ts b/frontend/appflowy_tauri/src/appflowy_app/application/database/row/row_service.ts index 0e06199b89..029da3b0c9 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/application/database/row/row_service.ts +++ b/frontend/appflowy_tauri/src/appflowy_app/application/database/row/row_service.ts @@ -30,7 +30,7 @@ export async function createRow(viewId: string, params?: { object_id: params?.rowId, }, group_id: params?.groupId, - data: params?.data ? { cell_data_by_field_id: params.data } : undefined, + data: params?.data, }); const result = await DatabaseEventCreateRow(payload); diff --git a/frontend/rust-lib/event-integration/src/database_event.rs b/frontend/rust-lib/event-integration/src/database_event.rs index 3f2a84a34c..3f91fd8441 100644 --- a/frontend/rust-lib/event-integration/src/database_event.rs +++ b/frontend/rust-lib/event-integration/src/database_event.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::convert::TryFrom; use bytes::Bytes; @@ -200,7 +201,7 @@ impl EventIntegrationTest { &self, view_id: &str, row_position: OrderObjectPositionPB, - data: Option, + data: Option>, ) -> RowMetaPB { EventBuilder::new(self.clone()) .event(DatabaseEvent::CreateRow) @@ -208,7 +209,7 @@ impl EventIntegrationTest { view_id: view_id.to_string(), row_position, group_id: None, - data, + data: data.unwrap_or_default(), }) .async_send() .await diff --git a/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs index 42e9341839..9bad92197f 100644 --- a/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs +++ b/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs @@ -1,10 +1,12 @@ use std::collections::HashMap; use collab_database::rows::{Row, RowDetail, RowId}; -use collab_database::views::{OrderObjectPosition, RowOrder}; +use collab_database::views::RowOrder; use flowy_derive::ProtoBuf; use flowy_error::ErrorCode; +use lib_infra::validator_fn::required_not_empty_str; +use validator::Validate; use crate::entities::parser::NotEmptyStr; use crate::entities::position_entities::OrderObjectPositionPB; @@ -335,46 +337,25 @@ impl TryInto for RowIdPB { } } -#[derive(ProtoBuf, Default)] +#[derive(ProtoBuf, Default, Validate)] pub struct CreateRowPayloadPB { #[pb(index = 1)] + #[validate(custom = "required_not_empty_str")] pub view_id: String, #[pb(index = 2)] pub row_position: OrderObjectPositionPB, #[pb(index = 3, one_of)] + #[validate(custom = "required_not_empty_str")] pub group_id: Option, - #[pb(index = 4, one_of)] - pub data: Option, -} - -#[derive(ProtoBuf, Default)] -pub struct RowDataPB { - #[pb(index = 1)] - pub cell_data_by_field_id: HashMap, + #[pb(index = 4)] + pub data: HashMap, } #[derive(Default)] pub struct CreateRowParams { - pub view_id: String, - pub row_position: OrderObjectPosition, - pub group_id: Option, - pub cell_data_by_field_id: Option>, -} - -impl TryInto for CreateRowPayloadPB { - type Error = ErrorCode; - - fn try_into(self) -> Result { - let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::ViewIdIsInvalid)?; - let position = self.row_position.try_into()?; - Ok(CreateRowParams { - view_id: view_id.0, - row_position: position, - group_id: self.group_id, - cell_data_by_field_id: self.data.map(|data| data.cell_data_by_field_id), - }) - } + pub collab_params: collab_database::rows::CreateRowParams, + pub open_after_create: bool, } diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rs index c58e825af5..6e6180b251 100644 --- a/frontend/rust-lib/flowy-database2/src/event_handler.rs +++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs @@ -1,17 +1,14 @@ use std::sync::{Arc, Weak}; -use collab_database::database::gen_row_id; use collab_database::rows::RowId; use lib_infra::box_any::BoxAny; use tokio::sync::oneshot; use flowy_error::{FlowyError, FlowyResult}; use lib_dispatch::prelude::{af_spawn, data_result_ok, AFPluginData, AFPluginState, DataResult}; -use lib_infra::util::timestamp; use crate::entities::*; use crate::manager::DatabaseManager; -use crate::services::cell::CellBuilder; use crate::services::field::{ type_option_data_from_pb, ChecklistCellChangeset, DateCellChangeset, RelationCellChangeset, SelectOptionCellChangeset, @@ -393,7 +390,7 @@ pub(crate) async fn duplicate_row_handler( let database_editor = manager.get_database_with_view_id(¶ms.view_id).await?; database_editor .duplicate_row(¶ms.view_id, ¶ms.row_id) - .await; + .await?; Ok(()) } @@ -417,27 +414,12 @@ pub(crate) async fn create_row_handler( manager: AFPluginState>, ) -> DataResult { let manager = upgrade_manager(manager)?; - let params: CreateRowParams = data.into_inner().try_into()?; + let params = data.try_into_inner()?; let database_editor = manager.get_database_with_view_id(¶ms.view_id).await?; - let fields = database_editor.get_fields(¶ms.view_id, None); - let cells = - CellBuilder::with_cells(params.cell_data_by_field_id.unwrap_or_default(), &fields).build(); - let view_id = params.view_id; - let group_id = params.group_id; - let params = collab_database::rows::CreateRowParams { - id: gen_row_id(), - cells, - height: 60, - visibility: true, - row_position: params.row_position, - timestamp: timestamp(), - }; - match database_editor - .create_row(&view_id, group_id, params) - .await? - { - None => Err(FlowyError::internal().with_context("Create row fail")), + + match database_editor.create_row(params).await? { Some(row) => data_result_ok(RowMetaPB::from(row)), + None => Err(FlowyError::internal().with_context("Error creating row")), } } 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.rs index 0e8b90fbbc..7f5878ab53 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 @@ -3,7 +3,7 @@ use std::sync::Arc; use collab_database::database::MutexDatabase; use collab_database::fields::{Field, TypeOptionData}; -use collab_database::rows::{Cell, Cells, CreateRowParams, Row, RowCell, RowDetail, RowId}; +use collab_database::rows::{Cell, Cells, Row, RowCell, RowDetail, RowId}; use collab_database::views::{ DatabaseLayout, DatabaseView, FilterMap, LayoutSetting, OrderObjectPosition, }; @@ -457,20 +457,33 @@ impl DatabaseEditor { Ok(()) } - // consider returning a result. But most of the time, it should be fine to just ignore the error. - pub async fn duplicate_row(&self, view_id: &str, row_id: &RowId) { - let params = self.database.lock().duplicate_row(row_id); - match params { - None => warn!("Failed to duplicate row: {}", row_id), - Some(params) => { - let result = self.create_row(view_id, None, params).await; - if let Some(row_detail) = result.unwrap_or(None) { - for view in self.database_views.editors().await { - view.v_did_duplicate_row(&row_detail).await; - } - } - }, + pub async fn duplicate_row(&self, view_id: &str, row_id: &RowId) -> FlowyResult<()> { + let (row_detail, index) = { + let database = self.database.lock(); + + let params = database + .duplicate_row(row_id) + .ok_or_else(|| FlowyError::internal().with_context("error while copying row"))?; + + let (index, row_order) = database + .create_row_in_view(view_id, params) + .ok_or_else(|| { + FlowyError::internal().with_context("error while inserting duplicated row") + })?; + + tracing::trace!("duplicated row: {:?} at {}", row_order, index); + let row_detail = database.get_row_detail(&row_order.id); + + (row_detail, index) + }; + + if let Some(row_detail) = row_detail { + for view in self.database_views.editors().await { + view.v_did_create_row(&row_detail, index).await; + } } + + Ok(()) } pub async fn move_row( @@ -506,18 +519,21 @@ impl DatabaseEditor { Ok(()) } - pub async fn create_row( - &self, - view_id: &str, - group_id: Option, - mut params: CreateRowParams, - ) -> FlowyResult> { - for view in self.database_views.editors().await { - view.v_will_create_row(&mut params.cells, &group_id).await; - } - let result = self.database.lock().create_row_in_view(view_id, params); + pub async fn create_row(&self, params: CreateRowPayloadPB) -> FlowyResult> { + let view_editor = self.database_views.get_view_editor(¶ms.view_id).await?; + + let CreateRowParams { + collab_params, + open_after_create: _, + } = view_editor.v_will_create_row(params).await?; + + let result = self + .database + .lock() + .create_row_in_view(&view_editor.view_id, collab_params); + if let Some((index, row_order)) = result { - tracing::trace!("create row: {:?} at {}", row_order, index); + tracing::trace!("created row: {:?} at {}", row_order, index); let row_detail = self.database.lock().get_row_detail(&row_order.id); if let Some(row_detail) = row_detail { for view in self.database_views.editors().await { @@ -1380,9 +1396,9 @@ impl DatabaseViewOperation for DatabaseViewOperationImpl { to_fut(async move { view }) } - fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>> { + fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut> { let fields = self.database.lock().get_fields_in_view(view_id, field_ids); - to_fut(async move { fields.into_iter().map(Arc::new).collect() }) + to_fut(async move { fields }) } fn get_field(&self, field_id: &str) -> Option { diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs index 7b86a960ea..dd3ee55f26 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs @@ -2,10 +2,11 @@ use std::borrow::Cow; use std::collections::HashMap; use std::sync::Arc; -use collab_database::database::{gen_database_calculation_id, gen_database_sort_id}; +use collab_database::database::{gen_database_calculation_id, gen_database_sort_id, gen_row_id}; use collab_database::fields::{Field, TypeOptionData}; use collab_database::rows::{Cells, Row, RowDetail, RowId}; use collab_database::views::{DatabaseLayout, DatabaseView}; +use lib_infra::util::timestamp; use tokio::sync::{broadcast, RwLock}; use tracing::instrument; @@ -13,14 +14,15 @@ use flowy_error::{FlowyError, FlowyResult}; use lib_dispatch::prelude::af_spawn; use crate::entities::{ - CalendarEventPB, DatabaseLayoutMetaPB, DatabaseLayoutSettingPB, DeleteSortPayloadPB, FieldType, - FieldVisibility, GroupChangesPB, GroupPB, InsertedRowPB, LayoutSettingChangeset, - LayoutSettingParams, RemoveCalculationChangesetPB, ReorderSortPayloadPB, RowMetaPB, RowsChangePB, + CalendarEventPB, CreateRowParams, CreateRowPayloadPB, DatabaseLayoutMetaPB, + DatabaseLayoutSettingPB, DeleteSortPayloadPB, FieldType, FieldVisibility, GroupChangesPB, + GroupPB, InsertedRowPB, LayoutSettingChangeset, LayoutSettingParams, + RemoveCalculationChangesetPB, ReorderSortPayloadPB, RowMetaPB, RowsChangePB, SortChangesetNotificationPB, SortPB, UpdateCalculationChangesetPB, UpdateSortPayloadPB, }; use crate::notification::{send_notification, DatabaseNotification}; use crate::services::calculations::{Calculation, CalculationChangeset, CalculationsController}; -use crate::services::cell::CellCache; +use crate::services::cell::{CellBuilder, CellCache}; use crate::services::database::{database_view_setting_pb_from_view, DatabaseRowEvent, UpdatedRow}; use crate::services::database_view::view_filter::make_filter_controller; use crate::services::database_view::view_group::{ @@ -115,17 +117,42 @@ impl DatabaseViewEditor { self.delegate.get_view(&self.view_id).await } - pub async fn v_will_create_row(&self, cells: &mut Cells, group_id: &Option) { - if group_id.is_none() { - return; + pub async fn v_will_create_row( + &self, + params: CreateRowPayloadPB, + ) -> FlowyResult { + let mut result = CreateRowParams { + collab_params: collab_database::rows::CreateRowParams { + id: gen_row_id(), + cells: Cells::new(), + height: 60, + visibility: true, + row_position: params.row_position.try_into()?, + timestamp: timestamp(), + }, + open_after_create: false, + }; + + // fill in cells from the frontend + let fields = self.delegate.get_fields(¶ms.view_id, None).await; + let mut cells = CellBuilder::with_cells(params.data, &fields).build(); + + // fill in cells according to group_id if supplied + if let Some(group_id) = params.group_id { + let _ = self + .mut_group_controller(|group_controller, field| { + group_controller.will_create_row(&mut cells, &field, &group_id); + Ok(()) + }) + .await; } - let group_id = group_id.as_ref().unwrap(); - let _ = self - .mut_group_controller(|group_controller, field| { - group_controller.will_create_row(cells, &field, group_id); - Ok(()) - }) - .await; + + // fill in cells according to active filters + // TODO(RS) + + result.collab_params.cells = cells; + + Ok(result) } pub async fn v_did_update_row_meta(&self, row_id: &RowId, row_detail: &RowDetail) { @@ -160,13 +187,6 @@ impl DatabaseViewEditor { .await; } - pub async fn v_did_duplicate_row(&self, row_detail: &RowDetail) { - self - .calculations_controller - .did_receive_row_changed(row_detail.row.clone()) - .await; - } - #[tracing::instrument(level = "trace", skip_all)] pub async fn v_did_delete_row(&self, row: &Row) { let deleted_row = row.clone(); @@ -796,12 +816,8 @@ impl DatabaseViewEditor { #[tracing::instrument(level = "debug", skip_all, err)] pub async fn v_grouping_by_field(&self, field_id: &str) -> FlowyResult<()> { if let Some(field) = self.delegate.get_field(field_id) { - let new_group_controller = new_group_controller_with_field( - self.view_id.clone(), - self.delegate.clone(), - Arc::new(field), - ) - .await?; + let new_group_controller = + new_group_controller_with_field(self.view_id.clone(), self.delegate.clone(), field).await?; let new_groups = new_group_controller .get_all_groups() diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_filter.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_filter.rs index 7944cacf4e..8e7daa472c 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_filter.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_filter.rs @@ -50,7 +50,7 @@ impl FilterDelegate for DatabaseViewFilterDelegateImpl { self.0.get_field(field_id) } - fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>> { + fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut> { self.0.get_fields(view_id, field_ids) } diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_group.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_group.rs index 963e8a45dd..0dba71a570 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_group.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_group.rs @@ -18,7 +18,7 @@ use crate::services::group::{ pub async fn new_group_controller_with_field( view_id: String, delegate: Arc, - grouping_field: Arc, + grouping_field: Field, ) -> FlowyResult> { let setting_reader = GroupSettingReaderImpl(delegate.clone()); let rows = delegate.get_rows(&view_id).await; diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs index 5779fd6faf..e64d9b494e 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs @@ -27,7 +27,7 @@ pub trait DatabaseViewOperation: Send + Sync + 'static { /// Get the view of the database with the view_id fn get_view(&self, view_id: &str) -> Fut>; /// If the field_ids is None, then it will return all the field revisions - fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>>; + fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>; /// Returns the field with the field_id fn get_field(&self, field_id: &str) -> Option; diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_sort.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_sort.rs index 6587d9ea0e..8be72e7da1 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_sort.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_sort.rs @@ -74,7 +74,7 @@ impl SortDelegate for DatabaseViewSortDelegateImpl { self.delegate.get_field(field_id) } - fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>> { + fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut> { self.delegate.get_fields(view_id, field_ids) } } diff --git a/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs b/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs index 11b8224c36..2323a3ce02 100644 --- a/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs +++ b/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs @@ -22,7 +22,7 @@ use crate::services::filter::{Filter, FilterChangeset, FilterInner, FilterResult pub trait FilterDelegate: Send + Sync + 'static { fn get_field(&self, field_id: &str) -> Option; - fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>>; + fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>; fn get_rows(&self, view_id: &str) -> Fut>>; fn get_row(&self, view_id: &str, rows_id: &RowId) -> Fut)>>; fn save_filters(&self, view_id: &str, filters: &[Filter]); @@ -116,14 +116,14 @@ impl FilterController { }); } - async fn get_field_map(&self) -> HashMap> { + async fn get_field_map(&self) -> HashMap { self .delegate .get_fields(&self.view_id, None) .await .into_iter() .map(|field| (field.id.clone(), field)) - .collect::>>() + .collect::>() } #[tracing::instrument( @@ -333,7 +333,7 @@ impl FilterController { fn filter_row( row: &Row, result_by_row_id: &DashMap, - field_by_field_id: &HashMap>, + field_by_field_id: &HashMap, cell_data_cache: &CellCache, filters: &Vec, ) -> Option<(RowId, bool)> { @@ -360,7 +360,7 @@ fn filter_row( /// Recursively applies a `Filter` to a `Row`'s cells. fn apply_filter( row: &Row, - field_by_field_id: &HashMap>, + field_by_field_id: &HashMap, cell_data_cache: &CellCache, filter: &Filter, ) -> Option { @@ -405,14 +405,10 @@ fn apply_filter( } let cell = row.cells.get(field_id).cloned(); let field_type = FieldType::from(field.field_type); - if let Some(handler) = TypeOptionCellExt::new(field.as_ref(), Some(cell_data_cache.clone())) + if let Some(handler) = TypeOptionCellExt::new(field, Some(cell_data_cache.clone())) .get_type_option_cell_data_handler(&field_type) { - Some(handler.handle_cell_filter( - field.as_ref(), - &cell.unwrap_or_default(), - condition_and_content, - )) + Some(handler.handle_cell_filter(field, &cell.unwrap_or_default(), condition_and_content)) } else { Some(true) } diff --git a/frontend/rust-lib/flowy-database2/src/services/group/configuration.rs b/frontend/rust-lib/flowy-database2/src/services/group/configuration.rs index 128dd30543..0498f77eed 100644 --- a/frontend/rust-lib/flowy-database2/src/services/group/configuration.rs +++ b/frontend/rust-lib/flowy-database2/src/services/group/configuration.rs @@ -71,7 +71,7 @@ pub struct GroupContext { configuration_phantom: PhantomData, /// The grouping field - field: Arc, + field: Field, /// Cache all the groups. Cache the group by its id. /// We use the id of the [Field] as the [No Status] group id. @@ -94,7 +94,7 @@ where #[tracing::instrument(level = "trace", skip_all, err)] pub async fn new( view_id: String, - field: Arc, + field: Field, reader: Arc, writer: Arc, ) -> FlowyResult { diff --git a/frontend/rust-lib/flowy-database2/src/services/group/controller.rs b/frontend/rust-lib/flowy-database2/src/services/group/controller.rs index acc240a9e3..62396fb293 100644 --- a/frontend/rust-lib/flowy-database2/src/services/group/controller.rs +++ b/frontend/rust-lib/flowy-database2/src/services/group/controller.rs @@ -1,5 +1,4 @@ use std::marker::PhantomData; -use std::sync::Arc; use async_trait::async_trait; use collab_database::fields::{Field, TypeOptionData}; @@ -75,7 +74,7 @@ where I: GroupOperationInterceptor + Send + Sync, { pub async fn new( - grouping_field: &Arc, + grouping_field: &Field, mut configuration: GroupContext, operation_interceptor: I, ) -> FlowyResult { diff --git a/frontend/rust-lib/flowy-database2/src/services/group/controller_impls/default_controller.rs b/frontend/rust-lib/flowy-database2/src/services/group/controller_impls/default_controller.rs index 021615b359..ba54c6e4b0 100644 --- a/frontend/rust-lib/flowy-database2/src/services/group/controller_impls/default_controller.rs +++ b/frontend/rust-lib/flowy-database2/src/services/group/controller_impls/default_controller.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use async_trait::async_trait; use collab_database::fields::{Field, TypeOptionData}; use collab_database::rows::{Cells, Row, RowDetail, RowId}; @@ -26,7 +24,7 @@ pub struct DefaultGroupController { const DEFAULT_GROUP_CONTROLLER: &str = "DefaultGroupController"; impl DefaultGroupController { - pub fn new(field: &Arc) -> Self { + pub fn new(field: &Field) -> Self { let group = GroupData::new( DEFAULT_GROUP_CONTROLLER.to_owned(), field.id.clone(), diff --git a/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs b/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs index c221c7fdaf..1c6c372e81 100644 --- a/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs +++ b/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs @@ -96,7 +96,7 @@ impl RowChangeset { )] pub async fn make_group_controller( view_id: String, - grouping_field: Arc, + grouping_field: Field, row_details: Vec>, setting_reader: R, setting_writer: W, @@ -200,10 +200,7 @@ where } #[tracing::instrument(level = "debug", skip_all)] -pub fn find_new_grouping_field( - fields: &[Arc], - _layout: &DatabaseLayout, -) -> Option> { +pub fn find_new_grouping_field(fields: &[Field], _layout: &DatabaseLayout) -> Option { let mut groupable_field_revs = fields .iter() .flat_map(|field_rev| { @@ -213,7 +210,7 @@ pub fn find_new_grouping_field( false => None, } }) - .collect::>>(); + .collect::>(); if groupable_field_revs.is_empty() { // If there is not groupable fields then we use the primary field. diff --git a/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs b/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs index 8ff25772e2..c4ad1f79ea 100644 --- a/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs +++ b/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs @@ -30,7 +30,7 @@ pub trait SortDelegate: Send + Sync { /// Returns all the rows after applying grid's filter fn get_rows(&self, view_id: &str) -> Fut>>; fn get_field(&self, field_id: &str) -> Option; - fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>>; + fn get_fields(&self, view_id: &str, field_ids: Option>) -> Fut>; } pub struct SortController { @@ -290,7 +290,7 @@ fn cmp_row( left: &Row, right: &Row, sort: &Arc, - fields: &[Arc], + fields: &[Field], cell_data_cache: &CellCache, ) -> Ordering { match fields @@ -335,18 +335,16 @@ fn cmp_row( fn cmp_cell( left_cell: Option<&Cell>, right_cell: Option<&Cell>, - field: &Arc, + field: &Field, field_type: FieldType, cell_data_cache: &CellCache, sort_condition: SortCondition, ) -> Ordering { - match TypeOptionCellExt::new(field.as_ref(), Some(cell_data_cache.clone())) + match TypeOptionCellExt::new(field, Some(cell_data_cache.clone())) .get_type_option_cell_data_handler(&field_type) { None => default_order(), - Some(handler) => { - handler.handle_cell_compare(left_cell, right_cell, field.as_ref(), sort_condition) - }, + Some(handler) => handler.handle_cell_compare(left_cell, right_cell, field, sort_condition), } } diff --git a/frontend/rust-lib/flowy-database2/tests/database/block_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/block_test/script.rs index c253422242..72b62b55df 100644 --- a/frontend/rust-lib/flowy-database2/tests/database/block_test/script.rs +++ b/frontend/rust-lib/flowy-database2/tests/database/block_test/script.rs @@ -1,7 +1,6 @@ -use collab_database::database::gen_row_id; use collab_database::rows::RowId; -use lib_infra::util::timestamp; +use flowy_database2::entities::CreateRowPayloadPB; use crate::database::database_editor::DatabaseEditorTest; @@ -30,17 +29,11 @@ impl DatabaseRowTest { pub async fn run_script(&mut self, script: RowScript) { match script { RowScript::CreateEmptyRow => { - let params = collab_database::rows::CreateRowParams { - id: gen_row_id(), - timestamp: timestamp(), + let params = CreateRowPayloadPB { + view_id: self.view_id.clone(), ..Default::default() }; - let row_detail = self - .editor - .create_row(&self.view_id, None, params) - .await - .unwrap() - .unwrap(); + let row_detail = self.editor.create_row(params).await.unwrap().unwrap(); self .row_by_row_id .insert(row_detail.row.id.to_string(), row_detail.into()); diff --git a/frontend/rust-lib/flowy-database2/tests/database/group_test/date_group_test.rs b/frontend/rust-lib/flowy-database2/tests/database/group_test/date_group_test.rs index 5ee7161868..27215ec794 100644 --- a/frontend/rust-lib/flowy-database2/tests/database/group_test/date_group_test.rs +++ b/frontend/rust-lib/flowy-database2/tests/database/group_test/date_group_test.rs @@ -3,12 +3,8 @@ use std::vec; use chrono::NaiveDateTime; use chrono::{offset, Duration}; -use collab_database::database::gen_row_id; -use collab_database::rows::CreateRowParams; -use collab_database::views::OrderObjectPosition; -use flowy_database2::entities::FieldType; -use flowy_database2::services::cell::CellBuilder; +use flowy_database2::entities::{CreateRowPayloadPB, FieldType}; use flowy_database2::services::field::DateCellData; use crate::database::group_test::script::DatabaseGroupTest; @@ -26,19 +22,17 @@ async fn group_by_date_test() { .unwrap() .timestamp() .to_string(); + let mut cells = HashMap::new(); cells.insert(date_field.id.clone(), timestamp); - let cells = CellBuilder::with_cells(cells, &[date_field.clone()]).build(); - let params = CreateRowParams { - id: gen_row_id(), - cells, - height: 60, - visibility: true, - row_position: OrderObjectPosition::default(), - timestamp: 0, + let params = CreateRowPayloadPB { + view_id: test.view_id.clone(), + data: cells, + ..Default::default() }; - let res = test.editor.create_row(&test.view_id, None, params).await; + + let res = test.editor.create_row(params).await; assert!(res.is_ok()); } diff --git a/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rs index e1d24b29da..6d1207cbdd 100644 --- a/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rs +++ b/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rs @@ -1,8 +1,7 @@ -use collab_database::database::gen_row_id; use collab_database::fields::Field; -use collab_database::rows::{CreateRowParams, RowId}; +use collab_database::rows::RowId; -use flowy_database2::entities::{FieldType, GroupPB, RowMetaPB}; +use flowy_database2::entities::{CreateRowPayloadPB, FieldType, GroupPB, RowMetaPB}; use flowy_database2::services::cell::{ delete_select_option_cell, insert_date_cell, insert_select_option_cell, insert_url_cell, }; @@ -10,7 +9,6 @@ use flowy_database2::services::field::{ edit_single_select_type_option, SelectOption, SelectTypeOptionSharedAction, SingleSelectTypeOption, }; -use lib_infra::util::timestamp; use crate::database::database_editor::DatabaseEditorTest; @@ -138,16 +136,13 @@ impl DatabaseGroupTest { }, GroupScript::CreateRow { group_index } => { let group = self.group_at_index(group_index).await; - let params = CreateRowParams { - id: gen_row_id(), - timestamp: timestamp(), - ..Default::default() + let params = CreateRowPayloadPB { + view_id: self.view_id.clone(), + row_position: Default::default(), + group_id: Some(group.group_id), + data: Default::default(), }; - let _ = self - .editor - .create_row(&self.view_id, Some(group.group_id.clone()), params) - .await - .unwrap(); + let _ = self.editor.create_row(params).await.unwrap(); }, GroupScript::DeleteRow { group_index, diff --git a/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rs index 90c0c5f17b..6ef3506056 100644 --- a/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rs +++ b/frontend/rust-lib/flowy-database2/tests/database/sort_test/script.rs @@ -8,7 +8,7 @@ use futures::stream::StreamExt; use tokio::sync::broadcast::Receiver; use flowy_database2::entities::{ - DeleteSortPayloadPB, FieldType, ReorderSortPayloadPB, UpdateSortPayloadPB, + CreateRowPayloadPB, DeleteSortPayloadPB, FieldType, ReorderSortPayloadPB, UpdateSortPayloadPB, }; use flowy_database2::services::cell::stringify_cell_data; use flowy_database2::services::database_view::DatabaseViewChanged; @@ -155,15 +155,10 @@ impl DatabaseSortTest { ); self .editor - .create_row( - &self.view_id, - None, - collab_database::rows::CreateRowParams { - id: collab_database::database::gen_row_id(), - timestamp: collab_database::database::timestamp(), - ..Default::default() - }, - ) + .create_row(CreateRowPayloadPB { + view_id: self.view_id.clone(), + ..Default::default() + }) .await .unwrap(); },