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:
parent
82dcd4b99e
commit
265177e444
@ -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();
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
),
|
||||
|
@ -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>> {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user