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
feat: hide ref database view (#2682)
Nathan.fooo265177e4443b
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dartindex cff62ead7f..b09b96077b 100644--- a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart+++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart@@ -17,6 +17,14 @@ class DatabaseViewBackendService {required this.viewId,});+ /// Returns the datbaase id associated with the view.+ Future<Either<String, FlowyError>> getDatabaseId() async {+ final payload = DatabaseViewIdPB(value: viewId);+ return DatabaseEventGetDatabaseId(payload)+ .send()+ .then((value) => value.leftMap((l) => l.value));+ }+Future<Either<DatabasePB, FlowyError>> openGrid() async {await FolderEventSetLatestView(ViewIdPB(value: viewId)).send();diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dartindex a33a154f10..b30b4eb9f7 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dart@@ -25,12 +25,12 @@ extension InsertDatabase on EditorState {return;}- // get the database that the view is associated with- final database = await DatabaseViewBackendService(viewId: childView.id)- .openGrid()+ // get the database id that the view is associated with+ final databaseId = await DatabaseViewBackendService(viewId: childView.id)+ .getDatabaseId().then((value) => value.swap().toOption().toNullable());- if (database == null) {+ if (databaseId == null) {throw StateError('The database associated with ${childView.id} could not be found while attempting to create a referenced ${childView.layout.name}.',);@@ -38,10 +38,10 @@ extension InsertDatabase on EditorState {final prefix = _referencedDatabasePrefix(childView.layout);final ref = await ViewBackendService.createDatabaseReferenceView(- parentViewId: parentView.id,+ parentViewId: childView.id,name: "$prefix ${childView.name}",layoutType: childView.layout,- databaseId: database.id,+ databaseId: databaseId,).then((value) => value.swap().toOption().toNullable());// TODO(a-wallen): Show error dialog here.@@ -55,7 +55,7 @@ extension InsertDatabase on EditorState {Node(type: _convertPageType(childView),attributes: {- DatabaseBlockKeys.parentID: parentView.id,+ DatabaseBlockKeys.parentID: childView.id,DatabaseBlockKeys.viewID: ref.id,},),diff --git a/frontend/rust-lib/flowy-database2/src/entities/database_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/database_entities.rsindex fe986af9fc..689386af69 100644--- a/frontend/rust-lib/flowy-database2/src/entities/database_entities.rs+++ b/frontend/rust-lib/flowy-database2/src/entities/database_entities.rs@@ -50,6 +50,18 @@ impl TryInto<CreateDatabaseViewParams> for CreateDatabaseViewPayloadPB {}}+#[derive(Clone, ProtoBuf, Default, Debug)]+pub struct DatabaseIdPB {+ #[pb(index = 1)]+ pub value: String,+}++impl AsRef<str> for DatabaseIdPB {+ fn as_ref(&self) -> &str {+ &self.value+ }+}+#[derive(Clone, ProtoBuf, Default, Debug)]pub struct DatabaseViewIdPB {#[pb(index = 1)]diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rsindex 79bf2536d6..fd76329ff7 100644--- a/frontend/rust-lib/flowy-database2/src/event_handler.rs+++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs@@ -29,6 +29,18 @@ pub(crate) async fn get_database_data_handler(data_result_ok(data)}+#[tracing::instrument(level = "trace", skip_all, err)]+pub(crate) async fn get_database_id_handler(+ data: AFPluginData<DatabaseViewIdPB>,+ manager: AFPluginState<Arc<DatabaseManager2>>,+) -> DataResult<DatabaseIdPB, FlowyError> {+ let view_id: DatabaseViewIdPB = data.into_inner();+ let database_id = manager+ .get_database_id_with_view_id(view_id.as_ref())+ .await?;+ data_result_ok(DatabaseIdPB { value: database_id })+}+#[tracing::instrument(level = "trace", skip(data, manager), err)]pub(crate) async fn get_database_setting_handler(data: AFPluginData<DatabaseViewIdPB>,diff --git a/frontend/rust-lib/flowy-database2/src/event_map.rs b/frontend/rust-lib/flowy-database2/src/event_map.rsindex 27bfb741d6..a39c7ffbe4 100644--- a/frontend/rust-lib/flowy-database2/src/event_map.rs+++ b/frontend/rust-lib/flowy-database2/src/event_map.rs@@ -14,6 +14,7 @@ pub fn init(database_manager: Arc<DatabaseManager2>) -> AFPlugin {.state(database_manager);plugin.event(DatabaseEvent::GetDatabase, get_database_data_handler)+ .event(DatabaseEvent::GetDatabaseId, get_database_id_handler).event(DatabaseEvent::GetDatabaseSetting, get_database_setting_handler).event(DatabaseEvent::UpdateDatabaseSetting, update_database_setting_handler).event(DatabaseEvent::GetAllFilters, get_all_filters_handler)@@ -81,6 +82,9 @@ pub enum DatabaseEvent {#[event(input = "DatabaseViewIdPB", output = "DatabasePB")]GetDatabase = 0,+ #[event(input = "DatabaseViewIdPB", output = "DatabaseIdPB")]+ GetDatabaseId = 1,+/// [GetDatabaseSetting] event is used to get the database's settings.////// The event handler accepts [DatabaseViewIdPB] and return [DatabaseViewSettingPB]diff --git a/frontend/rust-lib/flowy-database2/src/manager.rs b/frontend/rust-lib/flowy-database2/src/manager.rsindex 089faef999..4648ab2652 100644--- a/frontend/rust-lib/flowy-database2/src/manager.rs+++ b/frontend/rust-lib/flowy-database2/src/manager.rs@@ -79,12 +79,17 @@ impl DatabaseManager2 {}pub async fn get_database_with_view_id(&self, view_id: &str) -> FlowyResult<Arc<DatabaseEditor>> {+ let database_id = self.get_database_id_with_view_id(view_id).await?;+ self.get_database(&database_id).await+ }++ pub async fn get_database_id_with_view_id(&self, view_id: &str) -> FlowyResult<String> {let database_id = self.with_user_database(Err(FlowyError::internal()), |database| {database.get_database_id_with_view_id(view_id).ok_or_else(FlowyError::record_not_found)})?;- self.get_database(&database_id).await+ Ok(database_id)}pub async fn get_database(&self, database_id: &str) -> FlowyResult<Arc<DatabaseEditor>> {diff --git a/frontend/rust-lib/flowy-document2/src/manager.rs b/frontend/rust-lib/flowy-document2/src/manager.rsindex 1c7499c6d6..925c3a38d5 100644--- a/frontend/rust-lib/flowy-document2/src/manager.rs+++ b/frontend/rust-lib/flowy-document2/src/manager.rs@@ -67,7 +67,7 @@ impl DocumentManager {// subscribe to the document changes.document.lock().open(move |events, is_remote| {- tracing::debug!(+ tracing::trace!("document changed: {:?}, from remote: {}",&events,is_remote