Skip to content

Commit

Permalink
fix: navigation bar issue on linked pages(#7111) (#7142)
Browse files Browse the repository at this point in the history
  • Loading branch information
asjqkkkk authored Jan 9, 2025
1 parent 89c4629 commit 155817a
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

expect(
find.text(LocaleKeys.menuAppHeader_defaultNewPageName.tr()),
findsNWidgets(3),
Expand All @@ -77,12 +72,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);
await tester.pumpAndSettle();

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand All @@ -101,11 +90,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand Down Expand Up @@ -154,11 +138,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand Down Expand Up @@ -212,11 +191,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand Down Expand Up @@ -253,11 +227,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand Down Expand Up @@ -303,11 +272,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand Down Expand Up @@ -346,11 +310,6 @@ void main() {

await tester.insertSubPageFromSlashMenu(true);

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand Down Expand Up @@ -394,11 +353,6 @@ void main() {

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));
expect(find.byType(SubPageBlockComponent), findsOneWidget);
Expand All @@ -421,12 +375,6 @@ void main() {
await tester.createNewPageWithNameUnderParent(name: 'SubPageBlock');

await tester.insertSubPageFromSlashMenu();

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

await tester.renamePageWithSecondary(_defaultPageName, 'Child page');
expect(find.text('Child page'), findsNWidgets(2));

Expand All @@ -447,11 +395,6 @@ void main() {

await tester.insertSubPageFromSlashMenu(true);

await tester.expandOrCollapsePage(
pageName: 'SubPageBlock',
layout: ViewLayoutPB.Document,
);

expect(find.byType(SubPageBlockComponent), findsOneWidget);

final beforeNode = tester.editor.getNodeAtPath([1]);
Expand Down Expand Up @@ -532,6 +475,11 @@ void main() {
await tester.pumpAndSettle();
await tester.openPage(firstPage);

await tester.expandOrCollapsePage(
pageName: firstPage,
layout: ViewLayoutPB.Document,
);

/// check if there is a icon in document
final iconWidget = find.byWidgetPredicate((w) {
if (w is! RawEmojiIconWidget) return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/inline_actions/widgets/inline_actions_handler.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebar_folder.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pbenum.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand Down Expand Up @@ -44,5 +48,82 @@ void main() {
);
expect(isExpanded(type: FolderSpaceType.private), true);
});

testWidgets('Expanding with subpage', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
const page1 = 'SubPageBloc', page2 = '$page1 2';
await tester.createNewPageWithNameUnderParent(name: page1);
await tester.createNewPageWithNameUnderParent(
name: page2,
parentName: page1,
);

await tester.expandOrCollapsePage(
pageName: gettingStarted,
layout: ViewLayoutPB.Document,
);

await tester.tapNewPageButton();

await tester.editor.tapLineOfEditorAt(0);
await tester.pumpAndSettle();
await tester.editor.showSlashMenu();
await tester.pumpAndSettle();

final slashMenu = find
.ancestor(
of: find.byType(SelectionMenuItemWidget),
matching: find.byWidgetPredicate(
(widget) => widget is Scrollable,
),
)
.first;
final slashMenuItem = find.text(
LocaleKeys.document_slashMenu_name_linkedDoc.tr(),
);
await tester.scrollUntilVisible(
slashMenuItem,
100,
scrollable: slashMenu,
duration: const Duration(milliseconds: 250),
);

final menuItemFinder = find.byWidgetPredicate(
(w) =>
w is SelectionMenuItemWidget &&
w.item.name == LocaleKeys.document_slashMenu_name_linkedDoc.tr(),
);

final menuItem =
menuItemFinder.evaluate().first.widget as SelectionMenuItemWidget;

/// tapSlashMenuItemWithName is not working, so invoke this function directly
menuItem.item.handler(
menuItem.editorState,
menuItem.menuService,
menuItemFinder.evaluate().first,
);

await tester.pumpAndSettle();
final actionHandler = find.byType(InlineActionsHandler);
final subPage = find.descendant(
of: actionHandler,
matching: find.text(page2, findRichText: true),
);
await tester.tapButton(subPage);

final subpageBlock = find.descendant(
of: find.byType(AppFlowyEditor),
matching: find.text(page2, findRichText: true),
);

expect(find.text(page2, findRichText: true), findsOneWidget);
await tester.tapButton(subpageBlock);

/// one is in SectionFolder, another one is in CoverTitle
/// the last one is in FlowyNavigation
expect(find.text(page2, findRichText: true), findsNWidgets(3));
});
});
}
5 changes: 5 additions & 0 deletions frontend/appflowy_flutter/lib/startup/startup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';

import 'package:appflowy/env/cloud_env.dart';
import 'package:appflowy/startup/tasks/feature_flag_task.dart';
import 'package:appflowy/util/expand_views.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:appflowy_backend/appflowy_backend.dart';
import 'package:appflowy_backend/log.dart';
Expand Down Expand Up @@ -182,6 +183,7 @@ Future<void> initGetIt(
},
);
getIt.registerSingleton<PluginSandbox>(PluginSandbox());
getIt.registerSingleton<ViewExpanderRegistry>(ViewExpanderRegistry());

await DependencyResolver.resolve(getIt, mode);
}
Expand All @@ -207,6 +209,7 @@ abstract class LaunchTask {
LaunchTaskType get type => LaunchTaskType.dataProcessing;

Future<void> initialize(LaunchContext context);

Future<void> dispose();
}

Expand Down Expand Up @@ -248,7 +251,9 @@ enum IntegrationMode {

// test mode
bool get isTest => isUnitTest || isIntegrationTest;

bool get isUnitTest => this == IntegrationMode.unitTest;

bool get isIntegrationTest => this == IntegrationMode.integrationTest;

// release mode
Expand Down
40 changes: 40 additions & 0 deletions frontend/appflowy_flutter/lib/util/expand_views.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/cupertino.dart';

class ViewExpanderRegistry {
/// the key is view id
final Map<String, Set<ViewExpander>> _viewExpanders = {};

bool isViewExpanded(String id) => getExpander(id)?.isViewExpanded ?? false;

void register(String id, ViewExpander expander) {
final expanders = _viewExpanders[id] ?? {};
expanders.add(expander);
_viewExpanders[id] = expanders;
}

void unregister(String id, ViewExpander expander) {
final expanders = _viewExpanders[id] ?? {};
expanders.remove(expander);
if (expanders.isEmpty) {
_viewExpanders.remove(id);
} else {
_viewExpanders[id] = expanders;
}
}

ViewExpander? getExpander(String id) {
final expanders = _viewExpanders[id] ?? {};
return expanders.isEmpty ? null : expanders.first;
}
}

class ViewExpander {
ViewExpander(this._isExpandedCallback, this._expandCallback);

final ValueGetter<bool> _isExpandedCallback;
final VoidCallback _expandCallback;

bool get isViewExpanded => _isExpandedCallback.call();

void expand() => _expandCallback.call();
}
Loading

0 comments on commit 155817a

Please sign in to comment.