mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: hide ref database view (#2682)
This commit is contained in:
@ -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)]
|
||||
|
@ -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>,
|
||||
|
@ -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]
|
||||
|
@ -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>> {
|
||||
|
Reference in New Issue
Block a user