Skip to content

Commit

Permalink
fix: filter the search results by duplicate ids (AppFlowy-IO#7173)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jan 8, 2025
1 parent 64994b3 commit 0ef1b27
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ More actions for published page:
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.sites);
// wait the backend return the sites data
await tester.wait(1000);
await tester.wait(2000);

// check if the page is published in sites page
final pageItem = find.byWidgetPredicate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ void main() {
await tester.pumpAndSettle();

await tester.hoverOnWidget(
find.descendant(
of: find.byType(ShortcutSettingTile),
matching: find.text(backspaceCmd),
),
find
.descendant(
of: find.byType(ShortcutSettingTile),
matching: find.text(backspaceCmd),
)
.first,
onHover: () async {
await tester.tap(find.byFlowySvg(FlowySvgs.edit_s));
await tester.pumpAndSettle();
Expand Down Expand Up @@ -85,7 +87,7 @@ void main() {
as ShortcutSettingTile;
expect(
second.command.command,
'',
'backspace, shift+backspace',
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CommandPaletteBloc

emit(
state.copyWith(
results: results.items,
results: _filterDuplicates(results.items),
isLoading: _messagesReceived != results.sends.toInt(),
),
);
Expand Down Expand Up @@ -129,6 +129,27 @@ class CommandPaletteBloc
);
}

List<SearchResultPB> _filterDuplicates(List<SearchResultPB> results) {
final currentItems = [...state.results];
final res = [...results];

for (final item in results) {
final duplicateIndex = currentItems.indexWhere((a) => a.id == item.id);
if (duplicateIndex == -1) {
continue;
}

final duplicate = currentItems[duplicateIndex];
if (item.score < duplicate.score) {
res.remove(item);
} else {
currentItems.remove(duplicate);
}
}

return res..addAll(currentItems);
}

void _performSearch(String value) =>
add(CommandPaletteEvent.performSearch(search: value));

Expand Down

0 comments on commit 0ef1b27

Please sign in to comment.