Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: icons not display in search results (#7189)
Morn8df5d8dcb40d
diff --git a/frontend/appflowy_flutter/integration_test/desktop/command_palette/folder_search_test.dart b/frontend/appflowy_flutter/integration_test/desktop/command_palette/folder_search_test.dartindex f84310c188..3819a5eed8 100644--- a/frontend/appflowy_flutter/integration_test/desktop/command_palette/folder_search_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/command_palette/folder_search_test.dart@@ -1,7 +1,13 @@+import 'dart:convert';+import 'dart:math';++import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/shared/icon_emoji_picker/icon_picker.dart';import 'package:appflowy/workspace/presentation/command_palette/command_palette.dart';import 'package:appflowy/workspace/presentation/command_palette/widgets/search_field.dart';import 'package:appflowy/workspace/presentation/command_palette/widgets/search_result_tile.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:flowy_infra_ui/flowy_infra_ui.dart';@@ -11,7 +17,9 @@ import 'package:integration_test/integration_test.dart';import '../../shared/util.dart';void main() {- IntegrationTestWidgetsFlutterBinding.ensureInitialized();+ setUpAll(() {+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();+ });group('Folder Search', () {testWidgets('Search for views', (tester) async {@@ -48,48 +56,94 @@ void main() {await tester.pumpAndSettle(const Duration(seconds: 1));// The score should be higher for "ViewOne" thus it should be shown first- final firstDocumentWidget = tester- .widget(find.byType(SearchResultTile).first) as SearchResultTile;+ final firstDocumentWidget = tester.widget(+ find.byType(SearchResultTile).first,+ ) as SearchResultTile;expect(firstDocumentWidget.result.data, firstDocument);});- testWidgets('select the content in document and search', (tester) async {- const firstDocument = ''; // empty document+ testWidgets('Displaying icons in search results', (tester) async {+ final randomValue = Random().nextInt(10000) + 10000;+ final pageNames = ['First Page-$randomValue', 'Second Page-$randomValue'];await tester.initializeAppFlowy();await tester.tapAnonymousSignInButton();-- await tester.createNewPageWithNameUnderParent(name: firstDocument);- await tester.editor.updateSelection(- Selection(- start: Position(- path: [0],- ),- end: Position(- path: [0],- offset: 10,- ),- ),- );- await tester.pumpAndSettle();-- expect(- find.byType(FloatingToolbar),- findsOneWidget,- );+ final emojiIconData = await tester.loadIcon();++ /// create two pages+ for (final pageName in pageNames) {+ await tester.createNewPageWithNameUnderParent(name: pageName);+ await tester.updatePageIconInTitleBarByName(+ name: pageName,+ layout: ViewLayoutPB.Document,+ icon: emojiIconData,+ );+ }await tester.toggleCommandPalette();- expect(find.byType(CommandPaletteModal), findsOneWidget);- expect(- find.text(LocaleKeys.menuAppHeader_defaultNewPageName.tr()),- findsOneWidget,+ /// search for `Page`+ final searchFieldFinder = find.descendant(+ of: find.byType(SearchField),+ matching: find.byType(FlowyTextField),);+ await tester.enterText(searchFieldFinder, 'Page-$randomValue');+ await tester.pumpAndSettle(const Duration(milliseconds: 200));+ expect(find.byType(SearchResultTile), findsNWidgets(2));- expect(- find.text(firstDocument),- findsOneWidget,+ /// check results+ final svgs = find.descendant(+ of: find.byType(SearchResultTile),+ matching: find.byType(FlowySvg),);+ expect(svgs, findsNWidgets(2));++ final firstSvg = svgs.first.evaluate().first.widget as FlowySvg,+ lastSvg = svgs.last.evaluate().first.widget as FlowySvg;+ final iconData = IconsData.fromJson(jsonDecode(emojiIconData.emoji));++ /// icon displayed correctly+ expect(firstSvg.svgString, iconData.iconContent);+ expect(lastSvg.svgString, iconData.iconContent);++ testWidgets('select the content in document and search', (tester) async {+ const firstDocument = ''; // empty document++ await tester.initializeAppFlowy();+ await tester.tapAnonymousSignInButton();++ await tester.createNewPageWithNameUnderParent(name: firstDocument);+ await tester.editor.updateSelection(+ Selection(+ start: Position(+ path: [0],+ ),+ end: Position(+ path: [0],+ offset: 10,+ ),+ ),+ );+ await tester.pumpAndSettle();++ expect(+ find.byType(FloatingToolbar),+ findsOneWidget,+ );++ await tester.toggleCommandPalette();+ expect(find.byType(CommandPaletteModal), findsOneWidget);++ expect(+ find.text(LocaleKeys.menuAppHeader_defaultNewPageName.tr()),+ findsOneWidget,+ );++ expect(+ find.text(firstDocument),+ findsOneWidget,+ );+ });});});}diff --git a/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_recent_icon_test.dart b/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_recent_icon_test.dartnew file mode 100644index 0000000000..2b724ffac1--- /dev/null+++ b/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_recent_icon_test.dart@@ -0,0 +1,56 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/emoji_picker_button.dart';+import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';+import 'package:appflowy/shared/icon_emoji_picker/icon.dart';+import 'package:appflowy/shared/icon_emoji_picker/icon_picker.dart';+import 'package:appflowy/shared/icon_emoji_picker/recent_icons.dart';+import 'package:appflowy/shared/icon_emoji_picker/tab.dart';+import 'package:appflowy/workspace/presentation/widgets/view_title_bar.dart';+import 'package:flutter_test/flutter_test.dart';++import '../../shared/base.dart';+import '../../shared/common_operations.dart';+import '../../shared/expectation.dart';++void main() {+ testWidgets('Skip the empty group name icon in recent icons', (tester) async {+ await tester.initializeAppFlowy();+ await tester.tapAnonymousSignInButton();++ /// clear local data+ RecentIcons.clear();+ await loadIconGroups();+ final groups = kIconGroups!;+ final List<RecentIcon> localIcons = [];+ for (final e in groups) {+ localIcons.addAll(e.icons.map((e) => RecentIcon(e, e.name)).toList());+ }+ await RecentIcons.putIcon(RecentIcon(localIcons.first.icon, ''));+ await tester.openPage(gettingStarted);+ final title = find.descendant(+ of: find.byType(ViewTitleBar),+ matching: find.text(gettingStarted),+ );+ await tester.tapButton(title);++ /// tap emoji picker button+ await tester.tapButton(find.byType(EmojiPickerButton));+ expect(find.byType(FlowyIconEmojiPicker), findsOneWidget);++ /// tap icon tab+ final pickTab = find.byType(PickerTab);+ final iconTab = find.descendant(+ of: pickTab,+ matching: find.text(PickerTabType.icon.tr),+ );+ await tester.tapButton(iconTab);++ expect(find.byType(FlowyIconPicker), findsOneWidget);++ /// no recent icons+ final recentText = find.descendant(+ of: find.byType(FlowyIconPicker),+ matching: find.text('Recent'),+ );+ expect(recentText, findsNothing);+ });+}diff --git a/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test_runner.dart b/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test_runner.dartindex 9e4212f955..ef7d3dbc8b 100644--- a/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test_runner.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test_runner.dart@@ -2,6 +2,7 @@ import 'package:integration_test/integration_test.dart';import 'sidebar_favorites_test.dart' as sidebar_favorite_test;import 'sidebar_icon_test.dart' as sidebar_icon_test;+import 'sidebar_recent_icon_test.dart' as sidebar_recent_icon_test;import 'sidebar_test.dart' as sidebar_test;import 'sidebar_view_item_test.dart' as sidebar_view_item_test;@@ -14,4 +15,5 @@ void main() {sidebar_favorite_test.main();sidebar_icon_test.main();sidebar_view_item_test.main();+ sidebar_recent_icon_test.main();}diff --git a/frontend/appflowy_flutter/integration_test/shared/emoji.dart b/frontend/appflowy_flutter/integration_test/shared/emoji.dartindex c2032eef6b..2fd797b941 100644--- a/frontend/appflowy_flutter/integration_test/shared/emoji.dart+++ b/frontend/appflowy_flutter/integration_test/shared/emoji.dart@@ -38,13 +38,8 @@ extension EmojiTestExtension on WidgetTester {(w) => w is FlowySvg && w.svgString == iconsData.iconContent,),);- expect(find.byType(IconColorPicker), findsNothing);- /// test for tapping down, it should not display the ColorPicker unless tapping up- await tapDown(selectedSvg);- expect(find.byType(IconColorPicker), findsNothing);-- await tapButton(selectedSvg);+ await tapButton(selectedSvg.first);final colorPicker = find.byType(IconColorPicker);expect(colorPicker, findsOneWidget);final selectedColor = find.descendant(diff --git a/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/icon_picker.dart b/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/icon_picker.dartindex f06e333477..a2d9e4cd76 100644--- a/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/icon_picker.dart+++ b/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/icon_picker.dart@@ -115,18 +115,22 @@ class _FlowyIconPickerState extends State<FlowyIconPicker> {final localIcons = await loadIconGroups();final recentIcons = await RecentIcons.getIcons();if (recentIcons.isNotEmpty) {- iconGroups.add(- IconGroup(- name: _kRecentIconGroupName,- icons: recentIcons- .sublist(- 0,- min(recentIcons.length, widget.iconPerLine),- )- .map((e) => e.icon)- .toList(),- ),- );+ final filterRecentIcons = recentIcons+ .sublist(+ 0,+ min(recentIcons.length, widget.iconPerLine),+ )+ .skipWhile((e) => e.groupName.isEmpty)+ .map((e) => e.icon)+ .toList();+ if (filterRecentIcons.isNotEmpty) {+ iconGroups.add(+ IconGroup(+ name: _kRecentIconGroupName,+ icons: filterRecentIcons,+ ),+ );+ }}iconGroups.addAll(localIcons);if (mounted) {diff --git a/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/recent_icons.dart b/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/recent_icons.dartindex 199bb7f725..d90d4d10dc 100644--- a/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/recent_icons.dart+++ b/frontend/appflowy_flutter/lib/shared/icon_emoji_picker/recent_icons.dart@@ -57,6 +57,12 @@ class RecentIcons {return [];}+ @visibleForTesting+ static void clear() {+ _dataMap.clear();+ getIt<KeyValueStorage>().remove(KVKeys.recentIcons);+ }+static Future<void> _save() async {await getIt<KeyValueStorage>().set(KVKeys.recentIcons,diff --git a/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dart b/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dartindex 7b2eece965..610c666667 100644--- a/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dart@@ -1,31 +1,54 @@-import 'package:flutter/material.dart';-import 'package:appflowy/generated/flowy_svgs.g.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';+import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';+import 'package:flowy_infra_ui/style_widget/text.dart';+import 'package:flutter/material.dart';extension GetIcon on SearchResultPB {Widget? getIcon() {- if (icon.ty == ResultIconTypePB.Emoji) {- return icon.value.isNotEmpty- ? Text(- icon.value,- style: const TextStyle(fontSize: 18.0),- )+ final iconValue = icon.value, iconType = icon.ty;+ if (iconType == ResultIconTypePB.Emoji) {+ return iconValue.isNotEmpty+ ? FlowyText.emoji(iconValue, fontSize: 18): null;} else if (icon.ty == ResultIconTypePB.Icon) {- return FlowySvg(icon.getViewSvg(), size: const Size.square(20));+ if (_resultIconValueTypes.contains(iconValue)) {+ return FlowySvg(icon.getViewSvg(), size: const Size.square(18));+ }+ return RawEmojiIconWidget(+ emoji: EmojiIconData(iconType.toFlowyIconType(), icon.value),+ emojiSize: 18,+ );}-return null;}}+extension ResultIconTypePBToFlowyIconType on ResultIconTypePB {+ FlowyIconType toFlowyIconType() {+ switch (this) {+ case ResultIconTypePB.Emoji:+ return FlowyIconType.emoji;+ case ResultIconTypePB.Icon:+ return FlowyIconType.icon;+ case ResultIconTypePB.Url:+ return FlowyIconType.custom;+ default:+ return FlowyIconType.custom;+ }+ }+}+extension _ToViewIcon on ResultIconPB {FlowySvgData getViewSvg() => switch (value) {"0" => FlowySvgs.icon_document_s,"1" => FlowySvgs.icon_grid_s,"2" => FlowySvgs.icon_board_s,"3" => FlowySvgs.icon_calendar_s,+ "4" => FlowySvgs.chat_ai_page_s,_ => FlowySvgs.icon_document_s,};}++const _resultIconValueTypes = {'0', '1', '2', '3', '4'};diff --git a/frontend/appflowy_flutter/test/unit_test/util/recent_icons_test.dart b/frontend/appflowy_flutter/test/unit_test/util/recent_icons_test.dartindex 51ec4dd6cd..a2326a3e33 100644--- a/frontend/appflowy_flutter/test/unit_test/util/recent_icons_test.dart+++ b/frontend/appflowy_flutter/test/unit_test/util/recent_icons_test.dart@@ -16,6 +16,12 @@ void main() {Log.shared.disableLog = true;});+ bool equalIcon(RecentIcon a, RecentIcon b) =>+ a.groupName == b.groupName &&+ a.name == b.name &&+ a.keywords.equals(b.keywords) &&+ a.content == b.content;+test('putEmoji', () async {List<String> emojiIds = await RecentIcons.getEmojiIds();assert(emojiIds.isEmpty);@@ -55,12 +61,6 @@ void main() {localIcons.addAll(e.icons.map((e) => RecentIcon(e, e.name)).toList());}- bool equalIcon(RecentIcon a, RecentIcon b) =>- a.groupName == b.groupName &&- a.name == b.name &&- a.keywords.equals(b.keywords) &&- a.content == b.content;-await RecentIcons.putIcon(localIcons.first);icons = await RecentIcons.getIcons();assert(icons.length == 1);@@ -91,4 +91,26 @@ void main() {);}});++ test('put without group name', () async {+ RecentIcons.clear();+ List<RecentIcon> icons = await RecentIcons.getIcons();+ assert(icons.isEmpty);+ await loadIconGroups();+ final groups = kIconGroups!;+ final List<RecentIcon> localIcons = [];+ for (final e in groups) {+ localIcons.addAll(e.icons.map((e) => RecentIcon(e, e.name)).toList());+ }++ await RecentIcons.putIcon(RecentIcon(localIcons.first.icon, ''));+ icons = await RecentIcons.getIcons();+ assert(icons.isEmpty);++ await RecentIcons.putIcon(+ RecentIcon(localIcons.first.icon, 'Test group name'),+ );+ icons = await RecentIcons.getIcons();+ assert(icons.isNotEmpty);+ });}