mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: delete the view from the db when the view is deleted (#2703)
This commit is contained in:
@ -132,6 +132,12 @@ impl DatabaseManager2 {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_database_view(&self, view_id: &str) -> FlowyResult<()> {
|
||||
let database = self.get_database_with_view_id(view_id).await?;
|
||||
let _ = database.delete_database_view(view_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn duplicate_database(&self, view_id: &str) -> FlowyResult<Vec<u8>> {
|
||||
let database_data = self.with_user_database(Err(FlowyError::internal()), |database| {
|
||||
let data = database.get_database_duplicated_data(view_id)?;
|
||||
|
@ -1,5 +1,6 @@
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use flowy_notification::NotificationBuilder;
|
||||
|
||||
const OBSERVABLE_CATEGORY: &str = "Grid";
|
||||
|
||||
#[derive(ProtoBuf_Enum, Debug)]
|
||||
@ -37,6 +38,10 @@ pub enum DatabaseNotification {
|
||||
DidSetNewLayoutField = 81,
|
||||
// Trigger when the layout of the database is changed
|
||||
DidUpdateDatabaseLayout = 82,
|
||||
// Trigger when the database view is deleted
|
||||
DidDeleteDatabaseView = 83,
|
||||
// Trigger when the database view is moved to trash
|
||||
DidMoveDatabaseViewToTrash = 84,
|
||||
}
|
||||
|
||||
impl std::default::Default for DatabaseNotification {
|
||||
|
@ -312,7 +312,7 @@ impl<'a> CellBuilder<'a> {
|
||||
.collect::<HashMap<String, &Field>>();
|
||||
|
||||
let mut cells = Cells::new();
|
||||
for (field_id, cell_str) in cell_by_field_id.clone() {
|
||||
for (field_id, cell_str) in cell_by_field_id {
|
||||
if let Some(field) = field_maps.get(&field_id) {
|
||||
let field_type = FieldType::from(field.field_type);
|
||||
match field_type {
|
||||
|
@ -125,6 +125,14 @@ impl DatabaseEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the delete view ids.
|
||||
/// If the view is inline view, all the reference views will be deleted. So the return value
|
||||
/// will be the reference view ids and the inline view id. Otherwise, the return value will
|
||||
/// be the view id.
|
||||
pub async fn delete_database_view(&self, view_id: &str) -> FlowyResult<Vec<String>> {
|
||||
Ok(self.database.lock().delete_view(view_id))
|
||||
}
|
||||
|
||||
pub async fn update_group_setting(
|
||||
&self,
|
||||
view_id: &str,
|
||||
@ -942,7 +950,7 @@ impl DatabaseEditor {
|
||||
let view = database_view
|
||||
.get_view()
|
||||
.await
|
||||
.ok_or_else(|| FlowyError::record_not_found())?;
|
||||
.ok_or_else(FlowyError::record_not_found)?;
|
||||
let rows = database_view.v_get_rows().await;
|
||||
let (database_id, fields) = {
|
||||
let database = self.database.lock();
|
||||
|
@ -108,7 +108,7 @@ pub(crate) async fn get_cell_for_row(
|
||||
|
||||
let cell_data = match &row_cell.cell {
|
||||
None => None,
|
||||
Some(cell) => handler.get_cell_data(&cell, &field_type, &field).ok(),
|
||||
Some(cell) => handler.get_cell_data(cell, &field_type, &field).ok(),
|
||||
};
|
||||
Some(RowSingleCellData {
|
||||
row_id: row_cell.row_id.clone(),
|
||||
@ -133,7 +133,7 @@ pub(crate) async fn get_cells_for_field(
|
||||
.map(|row_cell| {
|
||||
let cell_data = match &row_cell.cell {
|
||||
None => None,
|
||||
Some(cell) => handler.get_cell_data(&cell, &field_type, &field).ok(),
|
||||
Some(cell) => handler.get_cell_data(cell, &field_type, &field).ok(),
|
||||
};
|
||||
RowSingleCellData {
|
||||
row_id: row_cell.row_id.clone(),
|
||||
|
Reference in New Issue
Block a user