feat: hide ref database view (#2682)

This commit is contained in:
Nathan.fooo
2023-06-02 12:04:14 +08:00
committed by GitHub
parent 82dcd4b99e
commit 265177e444
7 changed files with 50 additions and 9 deletions

View File

@ -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();

View File

@ -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,
},
),