Feat/tauri build (#2378)

* fix: tauri compile

* ci: update
This commit is contained in:
Nathan.fooo
2023-04-28 20:47:40 +08:00
committed by GitHub
parent 070ac051b1
commit 2838cd5e0c
71 changed files with 321 additions and 341 deletions

View File

@ -106,7 +106,7 @@ impl TryInto<CalendarEventRequestParams> for CalendarEventRequestPB {
#[derive(Debug, Clone, Default, ProtoBuf)]
pub struct CalendarEventPB {
#[pb(index = 1)]
pub row_id: i64,
pub row_id: String,
#[pb(index = 2)]
pub title_field_id: String,

View File

@ -49,7 +49,7 @@ pub struct CellIdPB {
pub field_id: String,
#[pb(index = 3)]
pub row_id: i64,
pub row_id: String,
}
/// Represents as the cell identifier. It's used to locate the cell in corresponding
@ -81,7 +81,7 @@ pub struct CellPB {
pub field_id: String,
#[pb(index = 2)]
pub row_id: i64,
pub row_id: String,
/// Encoded the data using the helper struct `CellProtobufBlob`.
/// Check out the `CellProtobufBlob` for more information.
@ -94,7 +94,7 @@ pub struct CellPB {
}
impl CellPB {
pub fn new(field_id: &str, row_id: i64, field_type: FieldType, data: Vec<u8>) -> Self {
pub fn new(field_id: &str, row_id: String, field_type: FieldType, data: Vec<u8>) -> Self {
Self {
field_id: field_id.to_owned(),
row_id,
@ -103,7 +103,7 @@ impl CellPB {
}
}
pub fn empty(field_id: &str, row_id: i64) -> Self {
pub fn empty(field_id: &str, row_id: String) -> Self {
Self {
field_id: field_id.to_owned(),
row_id,
@ -144,7 +144,7 @@ pub struct CellChangesetPB {
pub view_id: String,
#[pb(index = 2)]
pub row_id: i64,
pub row_id: String,
#[pb(index = 3)]
pub field_id: String,
@ -159,7 +159,7 @@ pub struct CellChangesetNotifyPB {
pub view_id: String,
#[pb(index = 2)]
pub row_id: i64,
pub row_id: String,
#[pb(index = 3)]
pub field_id: String,

View File

@ -83,10 +83,10 @@ pub struct MoveRowPayloadPB {
pub view_id: String,
#[pb(index = 2)]
pub from_row_id: i64,
pub from_row_id: String,
#[pb(index = 3)]
pub to_row_id: i64,
pub to_row_id: String,
}
pub struct MoveRowParams {
@ -114,13 +114,13 @@ pub struct MoveGroupRowPayloadPB {
pub view_id: String,
#[pb(index = 2)]
pub from_row_id: i64,
pub from_row_id: String,
#[pb(index = 3)]
pub to_group_id: String,
#[pb(index = 4, one_of)]
pub to_row_id: Option<i64>,
pub to_row_id: Option<String>,
}
pub struct MoveGroupRowParams {

View File

@ -18,7 +18,7 @@ pub struct GroupRowsNotificationPB {
pub inserted_rows: Vec<InsertedRowPB>,
#[pb(index = 4)]
pub deleted_rows: Vec<i64>,
pub deleted_rows: Vec<String>,
#[pb(index = 5)]
pub updated_rows: Vec<RowPB>,
@ -72,7 +72,7 @@ impl GroupRowsNotificationPB {
}
}
pub fn delete(group_id: String, deleted_rows: Vec<i64>) -> Self {
pub fn delete(group_id: String, deleted_rows: Vec<String>) -> Self {
Self {
group_id,
deleted_rows,

View File

@ -13,7 +13,7 @@ use crate::services::database::{InsertedRow, UpdatedRow};
#[derive(Debug, Default, Clone, ProtoBuf, Eq, PartialEq)]
pub struct RowPB {
#[pb(index = 1)]
pub id: i64,
pub id: String,
#[pb(index = 2)]
pub height: i32,
@ -22,7 +22,7 @@ pub struct RowPB {
impl std::convert::From<&Row> for RowPB {
fn from(row: &Row) -> Self {
Self {
id: row.id.into(),
id: row.id.clone().into_inner(),
height: row.height,
}
}
@ -31,7 +31,7 @@ impl std::convert::From<&Row> for RowPB {
impl std::convert::From<Row> for RowPB {
fn from(row: Row) -> Self {
Self {
id: row.id.into(),
id: row.id.into_inner(),
height: row.height,
}
}
@ -39,7 +39,7 @@ impl std::convert::From<Row> for RowPB {
impl From<RowOrder> for RowPB {
fn from(data: RowOrder) -> Self {
Self {
id: data.id.into(),
id: data.id.into_inner(),
height: data.height,
}
}
@ -144,7 +144,7 @@ pub struct RowIdPB {
pub view_id: String,
#[pb(index = 2)]
pub row_id: i64,
pub row_id: String,
}
pub struct RowIdParams {
@ -180,7 +180,7 @@ pub struct CreateRowPayloadPB {
pub view_id: String,
#[pb(index = 2, one_of)]
pub start_row_id: Option<i64>,
pub start_row_id: Option<String>,
#[pb(index = 3, one_of)]
pub group_id: Option<String>,

View File

@ -247,7 +247,7 @@ pub struct ReorderAllRowsPB {
#[derive(Debug, Default, ProtoBuf)]
pub struct ReorderSingleRowPB {
#[pb(index = 1)]
pub row_id: i64,
pub row_id: String,
#[pb(index = 2)]
pub old_index: i32,

View File

@ -49,7 +49,7 @@ pub struct RepeatedSelectOptionPayload {
pub field_id: String,
#[pb(index = 3)]
pub row_id: i64,
pub row_id: String,
#[pb(index = 4)]
pub items: Vec<SelectOptionPB>,

View File

@ -11,7 +11,7 @@ pub struct RowsVisibilityChangesetPB {
pub visible_rows: Vec<InsertedRowPB>,
#[pb(index = 6)]
pub invisible_rows: Vec<i64>,
pub invisible_rows: Vec<String>,
}
#[derive(Debug, Default, Clone, ProtoBuf)]
@ -23,7 +23,7 @@ pub struct RowsChangesetPB {
pub inserted_rows: Vec<InsertedRowPB>,
#[pb(index = 3)]
pub deleted_rows: Vec<i64>,
pub deleted_rows: Vec<String>,
#[pb(index = 4)]
pub updated_rows: Vec<UpdatedRowPB>,
@ -38,7 +38,7 @@ impl RowsChangesetPB {
}
}
pub fn from_delete(view_id: String, deleted_rows: Vec<i64>) -> Self {
pub fn from_delete(view_id: String, deleted_rows: Vec<String>) -> Self {
Self {
view_id,
deleted_rows,
@ -56,7 +56,7 @@ impl RowsChangesetPB {
pub fn from_move(
view_id: String,
deleted_rows: Vec<i64>,
deleted_rows: Vec<String>,
inserted_rows: Vec<InsertedRowPB>,
) -> Self {
Self {

View File

@ -280,7 +280,7 @@ pub(crate) async fn get_row_handler(
) -> DataResult<OptionalRowPB, FlowyError> {
let params: RowIdParams = data.into_inner().try_into()?;
let database_editor = manager.get_database(&params.view_id).await?;
let row = database_editor.get_row(params.row_id).map(RowPB::from);
let row = database_editor.get_row(&params.row_id).map(RowPB::from);
data_result_ok(OptionalRowPB { row })
}
@ -291,7 +291,7 @@ pub(crate) async fn delete_row_handler(
) -> Result<(), FlowyError> {
let params: RowIdParams = data.into_inner().try_into()?;
let database_editor = manager.get_database(&params.view_id).await?;
database_editor.delete_row(params.row_id).await;
database_editor.delete_row(&params.row_id).await;
Ok(())
}
@ -303,7 +303,7 @@ pub(crate) async fn duplicate_row_handler(
let params: RowIdParams = data.into_inner().try_into()?;
let database_editor = manager.get_database(&params.view_id).await?;
database_editor
.duplicate_row(&params.view_id, params.row_id)
.duplicate_row(&params.view_id, &params.row_id)
.await;
Ok(())
}

View File

@ -285,7 +285,7 @@ impl DatabaseEditor {
Ok(())
}
pub async fn duplicate_row(&self, view_id: &str, row_id: RowId) {
pub async fn duplicate_row(&self, view_id: &str, row_id: &RowId) {
let _ = self.database.lock().duplicate_row(view_id, row_id);
}
@ -325,7 +325,7 @@ impl DatabaseEditor {
is_new: true,
}));
let row = self.database.lock().get_row(row_order.id);
let row = self.database.lock().get_row(&row_order.id);
if let Some(row) = row {
for view in self.database_views.editors().await {
view.v_did_create_row(&row, &params.group_id, index).await;
@ -413,17 +413,17 @@ impl DatabaseEditor {
Ok(view_editor.v_get_rows().await)
}
pub fn get_row(&self, row_id: RowId) -> Option<Row> {
pub fn get_row(&self, row_id: &RowId) -> Option<Row> {
self.database.lock().get_row(row_id)
}
pub async fn delete_row(&self, row_id: RowId) {
pub async fn delete_row(&self, row_id: &RowId) {
let row = self.database.lock().remove_row(row_id);
if let Some(row) = row {
tracing::trace!("Did delete row:{:?}", row);
let _ = self
.row_event_tx
.send(DatabaseRowEvent::DeleteRow(row.id.into()));
.send(DatabaseRowEvent::DeleteRow(row.id.clone()));
for view in self.database_views.editors().await {
view.v_did_delete_row(&row).await;
@ -433,7 +433,7 @@ impl DatabaseEditor {
pub async fn get_cell(&self, field_id: &str, row_id: RowId) -> CellPB {
let field = self.database.lock().fields.get_field(field_id);
let cell = self.database.lock().get_cell(field_id, row_id);
let cell = self.database.lock().get_cell(field_id, &row_id);
match (field, cell) {
(Some(field), Some(cell)) => {
let field_type = FieldType::from(field.field_type);
@ -445,7 +445,7 @@ impl DatabaseEditor {
field_type: Some(field_type),
}
},
_ => CellPB::empty(field_id, row_id.into()),
_ => CellPB::empty(field_id, row_id.into_inner()),
}
}
@ -467,7 +467,7 @@ impl DatabaseEditor {
let database = self.database.lock();
(
database.fields.get_field(field_id)?,
database.get_cell(field_id, row_id).map(|cell| cell.cell),
database.get_cell(field_id, &row_id).map(|cell| cell.cell),
)
};
let cell_changeset = cell_changeset.to_cell_changeset_str();
@ -485,15 +485,15 @@ impl DatabaseEditor {
) -> Option<()> {
let old_row = {
let database = self.database.lock();
database.get_row(row_id)
database.get_row(&row_id)
};
self.database.lock().update_row(row_id, |row_update| {
self.database.lock().update_row(&row_id, |row_update| {
row_update.update_cells(|cell_update| {
cell_update.insert(field_id, new_cell);
});
});
let option_row = self.database.lock().get_row(row_id);
let option_row = self.database.lock().get_row(&row_id);
if let Some(new_row) = option_row {
let _ = self
.row_event_tx
@ -508,7 +508,7 @@ impl DatabaseEditor {
notify_did_update_cell(vec![CellChangesetNotifyPB {
view_id: view_id.to_string(),
row_id: row_id.into(),
row_id: row_id.into_inner(),
field_id: field_id.to_string(),
}])
.await;
@ -593,7 +593,7 @@ impl DatabaseEditor {
match field {
None => SelectOptionCellDataPB::default(),
Some(field) => {
let row_cell = self.database.lock().get_cell(field_id, row_id);
let row_cell = self.database.lock().get_cell(field_id, &row_id);
let ids = match row_cell {
None => SelectOptionIds::new(),
Some(row_cell) => SelectOptionIds::from(&row_cell.cell),
@ -640,7 +640,7 @@ impl DatabaseEditor {
from_row: RowId,
to_row: Option<RowId>,
) -> FlowyResult<()> {
let row = self.database.lock().get_row(from_row);
let row = self.database.lock().get_row(&from_row);
match row {
None => {
tracing::warn!(
@ -649,14 +649,14 @@ impl DatabaseEditor {
)
},
Some(row) => {
let mut row_changeset = RowChangeset::new(row.id);
let mut row_changeset = RowChangeset::new(row.id.clone());
let view = self.database_views.get_view_editor(view_id).await?;
view
.v_move_group_row(&row, &mut row_changeset, to_group, to_row)
.await;
tracing::trace!("Row data changed: {:?}", row_changeset);
self.database.lock().update_row(row.id, |row| {
self.database.lock().update_row(&row.id, |row| {
row.set_cells(Cells::from(row_changeset.cell_by_field_id.clone()));
});
@ -811,12 +811,12 @@ fn cell_changesets_from_cell_by_field_id(
row_id: RowId,
cell_by_field_id: HashMap<String, Cell>,
) -> Vec<CellChangesetNotifyPB> {
let row_id = row_id.into();
let row_id = row_id.into_inner();
cell_by_field_id
.into_iter()
.map(|(field_id, _cell)| CellChangesetNotifyPB {
view_id: view_id.to_string(),
row_id,
row_id: row_id.clone(),
field_id,
})
.collect()
@ -879,14 +879,14 @@ impl DatabaseViewData for DatabaseViewDataImpl {
to_fut(async move { field })
}
fn index_of_row(&self, view_id: &str, row_id: RowId) -> Fut<Option<usize>> {
fn index_of_row(&self, view_id: &str, row_id: &RowId) -> Fut<Option<usize>> {
let index = self.database.lock().index_of_row(view_id, row_id);
to_fut(async move { index })
}
fn get_row(&self, view_id: &str, row_id: RowId) -> Fut<Option<(usize, Arc<Row>)>> {
fn get_row(&self, view_id: &str, row_id: &RowId) -> Fut<Option<(usize, Arc<Row>)>> {
let index = self.database.lock().index_of_row(view_id, row_id);
let row = self.database.lock().get_row(row_id);
let row = self.database.lock().get_row(&row_id);
to_fut(async move {
match (index, row) {
(Some(index), Some(row)) => Some((index, Arc::new(row))),
@ -905,7 +905,7 @@ impl DatabaseViewData for DatabaseViewDataImpl {
to_fut(async move { cells.into_iter().map(Arc::new).collect() })
}
fn get_cell_in_row(&self, field_id: &str, row_id: RowId) -> Fut<Option<Arc<RowCell>>> {
fn get_cell_in_row(&self, field_id: &str, row_id: &RowId) -> Fut<Option<Arc<RowCell>>> {
let cell = self.database.lock().get_cell(field_id, row_id);
to_fut(async move { cell.map(Arc::new) })
}

View File

@ -1,12 +1,13 @@
use collab_database::rows::RowId;
use collab_database::views::RowOrder;
#[derive(Debug, Clone)]
pub enum DatabaseRowEvent {
InsertRow(InsertedRow),
UpdateRow(UpdatedRow),
DeleteRow(i64),
DeleteRow(RowId),
Move {
deleted_row_id: i64,
deleted_row_id: RowId,
inserted_row: InsertedRow,
},
}

View File

@ -41,7 +41,11 @@ impl DatabaseViewChangedReceiverRunner {
let changeset = RowsVisibilityChangesetPB {
view_id: notification.view_id,
visible_rows: notification.visible_rows,
invisible_rows: notification.invisible_rows,
invisible_rows: notification
.invisible_rows
.into_iter()
.map(|row| row.into_inner())
.collect(),
};
send_notification(
@ -61,7 +65,7 @@ impl DatabaseViewChangedReceiverRunner {
},
DatabaseViewChanged::ReorderSingleRowNotification(notification) => {
let reorder_row = ReorderSingleRowPB {
row_id: notification.row_id,
row_id: notification.row_id.into_inner(),
old_index: notification.old_index as i32,
new_index: notification.new_index as i32,
};

View File

@ -50,16 +50,16 @@ pub trait DatabaseViewData: Send + Sync + 'static {
fn get_primary_field(&self) -> Fut<Option<Arc<Field>>>;
/// Returns the index of the row with row_id
fn index_of_row(&self, view_id: &str, row_id: RowId) -> Fut<Option<usize>>;
fn index_of_row(&self, view_id: &str, row_id: &RowId) -> Fut<Option<usize>>;
/// Returns the `index` and `RowRevision` with row_id
fn get_row(&self, view_id: &str, row_id: RowId) -> Fut<Option<(usize, Arc<Row>)>>;
fn get_row(&self, view_id: &str, row_id: &RowId) -> Fut<Option<(usize, Arc<Row>)>>;
fn get_rows(&self, view_id: &str) -> Fut<Vec<Arc<Row>>>;
fn get_cells_for_field(&self, view_id: &str, field_id: &str) -> Fut<Vec<Arc<RowCell>>>;
fn get_cell_in_row(&self, field_id: &str, row_id: RowId) -> Fut<Option<Arc<RowCell>>>;
fn get_cell_in_row(&self, field_id: &str, row_id: &RowId) -> Fut<Option<Arc<RowCell>>>;
fn get_layout_for_view(&self, view_id: &str) -> DatabaseLayout;
@ -248,9 +248,11 @@ impl DatabaseViewEditor {
let filter_controller = self.filter_controller.clone();
let sort_controller = self.sort_controller.clone();
let row_id = row.id;
let row_id = row.id.clone();
tokio::spawn(async move {
filter_controller.did_receive_row_changed(row_id).await;
filter_controller
.did_receive_row_changed(row_id.clone())
.await;
sort_controller
.read()
.await
@ -669,12 +671,12 @@ impl DatabaseViewEditor {
// Text
let primary_field = self.delegate.get_primary_field().await?;
let text_cell = get_cell_for_row(self.delegate.clone(), &primary_field.id, row_id).await?;
let text_cell = get_cell_for_row(self.delegate.clone(), &primary_field.id, &row_id).await?;
// Date
let date_field = self.delegate.get_field(&calendar_setting.field_id).await?;
let date_cell = get_cell_for_row(self.delegate.clone(), &date_field.id, row_id).await?;
let date_cell = get_cell_for_row(self.delegate.clone(), &date_field.id, &row_id).await?;
let title = text_cell
.into_text_field_cell_data()
.unwrap_or_default()
@ -687,7 +689,7 @@ impl DatabaseViewEditor {
.unwrap_or_default();
Some(CalendarEventPB {
row_id: row_id.into(),
row_id: row_id.into_inner(),
title_field_id: primary_field.id.clone(),
title,
timestamp,
@ -712,7 +714,7 @@ impl DatabaseViewEditor {
.await
.into_iter()
.map(|date_cell| {
let row_id = date_cell.row_id;
let row_id = date_cell.row_id.clone();
// timestamp
let timestamp = date_cell
@ -727,7 +729,7 @@ impl DatabaseViewEditor {
let mut events: Vec<CalendarEventPB> = vec![];
for text_cell in text_cells {
let title_field_id = text_cell.field_id.clone();
let row_id = text_cell.row_id;
let row_id = text_cell.row_id.clone();
let timestamp = timestamp_by_row_id
.get(&row_id)
.cloned()
@ -739,7 +741,7 @@ impl DatabaseViewEditor {
.into();
let event = CalendarEventPB {
row_id: row_id.into(),
row_id: row_id.into_inner(),
title_field_id,
title,
timestamp,
@ -758,14 +760,14 @@ impl DatabaseViewEditor {
RowsChangesetPB::from_update(self.view_id.clone(), vec![row.into()])
},
DatabaseRowEvent::DeleteRow(row_id) => {
RowsChangesetPB::from_delete(self.view_id.clone(), vec![row_id])
RowsChangesetPB::from_delete(self.view_id.clone(), vec![row_id.into_inner()])
},
DatabaseRowEvent::Move {
deleted_row_id,
inserted_row,
} => RowsChangesetPB::from_move(
self.view_id.clone(),
vec![deleted_row_id],
vec![deleted_row_id.into_inner()],
vec![inserted_row.into()],
),
};

View File

@ -60,7 +60,7 @@ impl FilterDelegate for DatabaseViewFilterDelegateImpl {
self.0.get_rows(view_id)
}
fn get_row(&self, view_id: &str, row_id: RowId) -> Fut<Option<(usize, Arc<Row>)>> {
self.0.get_row(view_id, row_id)
fn get_row(&self, view_id: &str, rows_id: &RowId) -> Fut<Option<(usize, Arc<Row>)>> {
self.0.get_row(view_id, rows_id)
}
}

View File

@ -90,16 +90,16 @@ impl GroupSettingReader for GroupSettingReaderImpl {
pub(crate) async fn get_cell_for_row(
delegate: Arc<dyn DatabaseViewData>,
field_id: &str,
row_id: RowId,
row_id: &RowId,
) -> Option<RowSingleCellData> {
let field = delegate.get_field(field_id).await?;
let cell = delegate.get_cell_in_row(field_id, row_id).await?;
let cell = delegate.get_cell_in_row(field_id, &row_id).await?;
let field_type = FieldType::from(field.field_type);
if let Some(handler) = delegate.get_type_option_cell_handler(&field, &field_type) {
return match handler.get_cell_data(&cell, &field_type, &field) {
Ok(cell_data) => Some(RowSingleCellData {
row_id: cell.row_id,
row_id: cell.row_id.clone(),
field_id: field.id.clone(),
field_type: field_type.clone(),
cell_data,
@ -125,7 +125,7 @@ pub(crate) async fn get_cells_for_field(
.flat_map(
|cell| match handler.get_cell_data(cell, &field_type, &field) {
Ok(cell_data) => Some(RowSingleCellData {
row_id: cell.row_id,
row_id: cell.row_id.clone(),
field_id: field.id.clone(),
field_type: field_type.clone(),
cell_data,

View File

@ -67,7 +67,7 @@ impl DatabaseViews {
recv_row_changeset: impl FnOnce(RowChangeset) -> Fut<()>,
) -> FlowyResult<()> {
let view_editor = self.get_view_editor(view_id).await?;
let mut row_changeset = RowChangeset::new(row.id);
let mut row_changeset = RowChangeset::new(row.id.clone());
view_editor
.v_move_group_row(&row, &mut row_changeset, &to_group_id, to_row_id)
.await;

View File

@ -24,7 +24,7 @@ pub trait FilterDelegate: Send + Sync + 'static {
fn get_field(&self, field_id: &str) -> Fut<Option<Arc<Field>>>;
fn get_fields(&self, view_id: &str, field_ids: Option<Vec<String>>) -> Fut<Vec<Arc<Field>>>;
fn get_rows(&self, view_id: &str) -> Fut<Vec<Arc<Row>>>;
fn get_row(&self, view_id: &str, rows_id: RowId) -> Fut<Option<(usize, Arc<Row>)>>;
fn get_row(&self, view_id: &str, rows_id: &RowId) -> Fut<Option<(usize, Arc<Row>)>>;
}
pub trait FromFilterString {
@ -149,7 +149,7 @@ impl FilterController {
}
async fn filter_row(&self, row_id: RowId) -> FlowyResult<()> {
if let Some((_, row)) = self.delegate.get_row(&self.view_id, row_id).await {
if let Some((_, row)) = self.delegate.get_row(&self.view_id, &row_id).await {
let field_by_field_id = self.get_field_map().await;
let mut notification = FilterResultNotification::new(self.view_id.clone());
if let Some((row_id, is_visible)) = filter_row(
@ -160,14 +160,14 @@ impl FilterController {
&self.cell_filter_cache,
) {
if is_visible {
if let Some((index, row)) = self.delegate.get_row(&self.view_id, row_id).await {
if let Some((index, row)) = self.delegate.get_row(&self.view_id, &row_id).await {
let row_pb = RowPB::from(row.as_ref());
notification
.visible_rows
.push(InsertedRowPB::with_index(row_pb, index as i32))
}
} else {
notification.invisible_rows.push(row_id.into());
notification.invisible_rows.push(row_id);
}
}
@ -201,7 +201,7 @@ impl FilterController {
let row_pb = RowPB::from(row.as_ref());
visible_rows.push(InsertedRowPB::with_index(row_pb, index as i32))
} else {
invisible_rows.push(i64::from(row_id));
invisible_rows.push(row_id);
}
}
}
@ -369,7 +369,7 @@ fn filter_row(
) -> Option<(RowId, bool)> {
// Create a filter result cache if it's not exist
let mut filter_result = result_by_row_id
.entry(row.id)
.entry(row.id.clone())
.or_insert_with(FilterResult::default);
let old_is_visible = filter_result.is_visible();
@ -395,7 +395,7 @@ fn filter_row(
let is_visible = filter_result.is_visible();
if old_is_visible != is_visible {
Some((row.id, is_visible))
Some((row.id.clone(), is_visible))
} else {
None
}

View File

@ -1,5 +1,6 @@
use anyhow::bail;
use collab::core::any_map::AnyMapExtension;
use collab_database::rows::RowId;
use collab_database::views::{FilterMap, FilterMapBuilder};
use crate::entities::{DeleteFilterParams, FieldType, FilterPB, InsertedRowPB};
@ -161,7 +162,7 @@ pub struct FilterResultNotification {
pub visible_rows: Vec<InsertedRowPB>,
// Indicates there will be some new rows being invisible from visible state.
pub invisible_rows: Vec<i64>,
pub invisible_rows: Vec<RowId>,
}
impl FilterResultNotification {

View File

@ -63,7 +63,7 @@ pub struct MoveGroupRowContext<'a> {
pub to_row_id: Option<RowId>,
}
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub struct RowChangeset {
pub row_id: RowId,
pub height: Option<i32>,
@ -77,7 +77,9 @@ impl RowChangeset {
pub fn new(row_id: RowId) -> Self {
Self {
row_id,
..Default::default()
height: None,
visibility: None,
cell_by_field_id: Default::default(),
}
}
@ -149,7 +151,7 @@ where
.iter()
.any(|inserted_row| &inserted_row.row.id == row_id)
})
.collect::<Vec<i64>>();
.collect::<Vec<String>>();
let mut changeset = GroupRowsNotificationPB::new(no_status_group.id.clone());
if !no_status_group_rows.is_empty() {
@ -158,7 +160,7 @@ where
}
// [other_group_delete_rows] contains all the deleted rows except the default group.
let other_group_delete_rows: Vec<i64> = other_group_changesets
let other_group_delete_rows: Vec<String> = other_group_changesets
.iter()
.flat_map(|changeset| &changeset.deleted_rows)
.cloned()
@ -172,29 +174,24 @@ where
// out from the default_group.
!other_group_delete_rows
.iter()
.any(|row_id| inserted_row.row.id == *row_id)
.any(|row_id| &inserted_row.row.id == row_id)
})
.collect::<Vec<&InsertedRowPB>>();
let mut deleted_row_ids = vec![];
for row in &no_status_group.rows {
let row_id: i64 = row.id.into();
let row_id = row.id.clone().into_inner();
if default_group_deleted_rows
.iter()
.any(|deleted_row| deleted_row.row.id == row_id)
{
deleted_row_ids.push(row.id);
deleted_row_ids.push(row_id);
}
}
no_status_group
.rows
.retain(|row| !deleted_row_ids.contains(&row.id));
changeset.deleted_rows.extend(
deleted_row_ids
.into_iter()
.map(|id| id.into())
.collect::<Vec<i64>>(),
);
changeset.deleted_rows.extend(deleted_row_ids);
Some(changeset)
}
}
@ -328,12 +325,12 @@ where
tracing::error!("Unexpected None value. It should have the no status group");
},
Some(no_status_group) => {
if !no_status_group.contains_row(row.id) {
if !no_status_group.contains_row(&row.id) {
tracing::error!("The row: {:?} should be in the no status group", row.id);
}
result.row_changesets = vec![GroupRowsNotificationPB::delete(
no_status_group.id.clone(),
vec![row.id.into()],
vec![row.id.clone().into_inner()],
)];
},
}

View File

@ -54,12 +54,12 @@ impl GroupCustomize for CheckboxGroupController {
let mut changesets = vec![];
self.group_ctx.iter_mut_status_groups(|group| {
let mut changeset = GroupRowsNotificationPB::new(group.id.clone());
let is_not_contained = !group.contains_row(row.id);
let is_not_contained = !group.contains_row(&row.id);
if group.id == CHECK {
if cell_data.is_uncheck() {
// Remove the row if the group.id is CHECK but the cell_data is UNCHECK
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
changeset.deleted_rows.push(row.id.clone().into_inner());
group.remove_row(&row.id);
} else {
// Add the row to the group if the group didn't contain the row
if is_not_contained {
@ -74,8 +74,8 @@ impl GroupCustomize for CheckboxGroupController {
if group.id == UNCHECK {
if cell_data.is_check() {
// Remove the row if the group.id is UNCHECK but the cell_data is CHECK
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
changeset.deleted_rows.push(row.id.clone().into_inner());
group.remove_row(&row.id);
} else {
// Add the row to the group if the group didn't contain the row
if is_not_contained {
@ -98,9 +98,9 @@ impl GroupCustomize for CheckboxGroupController {
let mut changesets = vec![];
self.group_ctx.iter_mut_groups(|group| {
let mut changeset = GroupRowsNotificationPB::new(group.id.clone());
if group.contains_row(row.id) {
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
if group.contains_row(&row.id) {
changeset.deleted_rows.push(row.id.clone().into_inner());
group.remove_row(&row.id);
}
if !changeset.is_empty() {

View File

@ -16,22 +16,22 @@ pub fn add_or_remove_select_option_row(
) -> Option<GroupRowsNotificationPB> {
let mut changeset = GroupRowsNotificationPB::new(group.id.clone());
if cell_data.select_options.is_empty() {
if group.contains_row(row.id) {
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
if group.contains_row(&row.id) {
group.remove_row(&row.id);
changeset.deleted_rows.push(row.id.clone().into_inner());
}
} else {
cell_data.select_options.iter().for_each(|option| {
if option.id == group.id {
if !group.contains_row(row.id) {
if !group.contains_row(&row.id) {
changeset
.inserted_rows
.push(InsertedRowPB::new(RowPB::from(row)));
group.add_row(row.clone());
}
} else if group.contains_row(row.id) {
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
} else if group.contains_row(&row.id) {
group.remove_row(&row.id);
changeset.deleted_rows.push(row.id.clone().into_inner());
}
});
}
@ -50,9 +50,9 @@ pub fn remove_select_option_row(
) -> Option<GroupRowsNotificationPB> {
let mut changeset = GroupRowsNotificationPB::new(group.id.clone());
cell_data.select_options.iter().for_each(|option| {
if option.id == group.id && group.contains_row(row.id) {
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
if option.id == group.id && group.contains_row(&row.id) {
group.remove_row(&row.id);
changeset.deleted_rows.push(row.id.clone().into_inner());
}
});
@ -76,17 +76,17 @@ pub fn move_group_row(
to_row_id,
} = context;
let from_index = group.index_of_row(row.id);
let from_index = group.index_of_row(&row.id);
let to_index = match to_row_id {
None => None,
Some(to_row_id) => group.index_of_row(*to_row_id),
Some(to_row_id) => group.index_of_row(to_row_id),
};
// Remove the row in which group contains it
if let Some(from_index) = &from_index {
changeset.deleted_rows.push(row.id.into());
changeset.deleted_rows.push(row.id.clone().into_inner());
tracing::debug!("Group:{} remove {} at {}", group.id, row.id, from_index);
group.remove_row(row.id);
group.remove_row(&row.id);
}
if group.id == *to_group_id {

View File

@ -97,15 +97,15 @@ impl GroupCustomize for URLGroupController {
self.group_ctx.iter_mut_status_groups(|group| {
let mut changeset = GroupRowsNotificationPB::new(group.id.clone());
if group.id == cell_data.content {
if !group.contains_row(row.id) {
if !group.contains_row(&row.id) {
changeset
.inserted_rows
.push(InsertedRowPB::new(RowPB::from(row)));
group.add_row(row.clone());
}
} else if group.contains_row(row.id) {
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
} else if group.contains_row(&row.id) {
group.remove_row(&row.id);
changeset.deleted_rows.push(row.id.clone().into_inner());
}
if !changeset.is_empty() {
@ -119,9 +119,9 @@ impl GroupCustomize for URLGroupController {
let mut changesets = vec![];
self.group_ctx.iter_mut_groups(|group| {
let mut changeset = GroupRowsNotificationPB::new(group.id.clone());
if group.contains_row(row.id) {
changeset.deleted_rows.push(row.id.into());
group.remove_row(row.id);
if group.contains_row(&row.id) {
group.remove_row(&row.id);
changeset.deleted_rows.push(row.id.clone().into_inner());
}
if !changeset.is_empty() {

View File

@ -143,12 +143,12 @@ impl GroupData {
}
}
pub fn contains_row(&self, row_id: RowId) -> bool {
self.rows.iter().any(|row| row.id == row_id)
pub fn contains_row(&self, row_id: &RowId) -> bool {
self.rows.iter().any(|row| &row.id == row_id)
}
pub fn remove_row(&mut self, row_id: RowId) {
match self.rows.iter().position(|row| row.id == row_id) {
pub fn remove_row(&mut self, row_id: &RowId) {
match self.rows.iter().position(|row| &row.id == row_id) {
None => {},
Some(pos) => {
self.rows.remove(pos);
@ -177,8 +177,8 @@ impl GroupData {
}
}
pub fn index_of_row(&self, row_id: RowId) -> Option<usize> {
self.rows.iter().position(|row| row.id == row_id)
pub fn index_of_row(&self, row_id: &RowId) -> Option<usize> {
self.rows.iter().position(|row| &row.id == row_id)
}
pub fn number_of_row(&self) -> usize {

View File

@ -118,7 +118,7 @@ impl SortController {
return Ok(());
}
let notification = ReorderSingleRowResult {
row_id: row_id.into(),
row_id,
view_id: self.view_id.clone(),
old_index: old_row_index,
new_index: new_row_index,
@ -158,7 +158,7 @@ impl SortController {
rows.par_sort_by(|left, right| cmp_row(left, right, sort, &field_revs, &self.cell_cache));
}
rows.iter().enumerate().for_each(|(index, row)| {
self.row_index_cache.insert(row.id, index);
self.row_index_cache.insert(row.id.clone(), index);
});
}

View File

@ -1,5 +1,6 @@
use anyhow::bail;
use collab::core::any_map::AnyMapExtension;
use collab_database::rows::RowId;
use collab_database::views::{SortMap, SortMapBuilder};
use crate::entities::{DeleteSortParams, FieldType};
@ -119,7 +120,7 @@ impl ReorderAllRowsResult {
#[derive(Clone)]
pub struct ReorderSingleRowResult {
pub view_id: String,
pub row_id: i64,
pub row_id: RowId,
pub old_index: usize,
pub new_index: usize,
}