mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: get view ancestors (#5096)
This commit is contained in:
@ -6,11 +6,8 @@ import 'package:appflowy/plugins/database/grid/presentation/mobile_grid_page.dar
|
||||
import 'package:appflowy/plugins/database/tab_bar/tab_bar_view.dart';
|
||||
import 'package:appflowy/plugins/document/document.dart';
|
||||
import 'package:appflowy/startup/plugin/plugin.dart';
|
||||
import 'package:appflowy/workspace/application/view/view_service.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:appflowy_result/appflowy_result.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum FlowyPlugin {
|
||||
@ -84,29 +81,6 @@ extension ViewExtension on ViewPB {
|
||||
};
|
||||
|
||||
FlowySvgData get iconData => layout.icon;
|
||||
|
||||
Future<List<ViewPB>> getAncestors({
|
||||
bool includeSelf = false,
|
||||
bool includeRoot = false,
|
||||
}) async {
|
||||
final ancestors = <ViewPB>[];
|
||||
if (includeSelf) {
|
||||
final self = await ViewBackendService.getView(id);
|
||||
ancestors.add(self.fold((s) => s, (e) => this));
|
||||
}
|
||||
FlowyResult<ViewPB, FlowyError> parent =
|
||||
await ViewBackendService.getView(parentViewId);
|
||||
while (parent.isSuccess) {
|
||||
// parent is not null
|
||||
final view = parent.fold((s) => s, (e) => null);
|
||||
if (view == null || (!includeRoot && view.parentViewId.isEmpty)) {
|
||||
break;
|
||||
}
|
||||
ancestors.add(view);
|
||||
parent = await ViewBackendService.getView(view.parentViewId);
|
||||
}
|
||||
return ancestors.reversed.toList();
|
||||
}
|
||||
}
|
||||
|
||||
extension ViewLayoutExtension on ViewLayoutPB {
|
||||
|
@ -260,12 +260,19 @@ class ViewBackendService {
|
||||
}
|
||||
|
||||
static Future<FlowyResult<ViewPB, FlowyError>> getView(
|
||||
String viewID,
|
||||
String viewId,
|
||||
) async {
|
||||
final payload = ViewIdPB.create()..value = viewID;
|
||||
final payload = ViewIdPB.create()..value = viewId;
|
||||
return FolderEventGetView(payload).send();
|
||||
}
|
||||
|
||||
static Future<FlowyResult<RepeatedViewPB, FlowyError>> getViewAncestors(
|
||||
String viewId,
|
||||
) async {
|
||||
final payload = ViewIdPB.create()..value = viewId;
|
||||
return FolderEventGetViewAncestors(payload).send();
|
||||
}
|
||||
|
||||
Future<FlowyResult<ViewPB, FlowyError>> getChildView({
|
||||
required String parentViewId,
|
||||
required String childViewId,
|
||||
|
Reference in New Issue
Block a user