Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search filter private views #5646

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:appflowy_backend/protobuf/flowy-search/notification.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:protobuf/protobuf.dart';

part 'command_palette_bloc.freezed.dart';

Expand Down Expand Up @@ -90,7 +91,8 @@ class CommandPaletteBloc

_messagesReceived++;

final searchResults = _filterDuplicates(results.items);
final allItems = [...state.results, ...results.items];
final searchResults = _removeDuplicates(allItems);
searchResults.sort((a, b) => b.score.compareTo(a.score));

emit(
Expand Down Expand Up @@ -133,29 +135,30 @@ class CommandPaletteBloc
);
}

List<SearchResultPB> _filterDuplicates(List<SearchResultPB> results) {
final currentItems = [...state.results];
final res = [...results];
/// Remove duplicates, where retained item is the one with the highest score.
List<SearchResultPB> _removeDuplicates(List<SearchResultPB> items) {
final res = <SearchResultPB>[];

for (final item in results) {
if (item.data.trim().isEmpty) {
continue;
}

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

final duplicate = currentItems[duplicateIndex];
if (item.score < duplicate.score) {
res.remove(item);
} else {
currentItems.remove(duplicate);
var (keep, discard) = item.score > res[duplicateIndex].score
? (item, res[duplicateIndex])
: (res[duplicateIndex], item);

if (keep.preview.isEmpty && discard.preview.isNotEmpty) {
keep.freeze();
keep = keep.rebuild((i) => i.preview = discard.preview);
}

res[duplicateIndex] = keep;
}

return res..addAll(currentItems);
return res;
}

void _performSearch(String value) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class RecentViewTile extends StatelessWidget {
children: [
icon,
const HSpace(6),
FlowyText(view.name),
Flexible(
child: FlowyText(
view.name,
overflow: TextOverflow.ellipsis,
),
),
],
),
focusColor: Theme.of(context).colorScheme.primary.withOpacity(0.1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class _SearchResultTileState extends State<SearchResultTile> {
style: HoverStyle(
hoverColor: Theme.of(context).colorScheme.primary.withOpacity(0.1),
foregroundColorOnHover: AFThemeExtension.of(context).textColor,
borderRadius: BorderRadius.zero,
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:flutter/material.dart';

import 'package:appflowy/startup/startup.dart';
Expand All @@ -15,6 +14,7 @@ import 'package:appflowy/workspace/presentation/settings/widgets/feature_flags/f
import 'package:appflowy/workspace/presentation/settings/widgets/members/workspace_member_page.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_menu.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_notifications_view.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Expand All @@ -41,15 +41,16 @@ class SettingsDialog extends StatelessWidget {
child: BlocBuilder<SettingsDialogBloc, SettingsDialogState>(
builder: (context, state) => FlowyDialog(
width: MediaQuery.of(context).size.width * 0.7,
constraints: const BoxConstraints(maxWidth: 784, minWidth: 564),
constraints: const BoxConstraints(maxWidth: 894, minWidth: 674),
heightFactor: 0.8,
child: ScaffoldMessenger(
child: Scaffold(
backgroundColor: Colors.transparent,
body: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 200,
width: 230,
child: SettingsMenu(
userProfile: user,
changeSelectedPage: (index) => context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class FlowyDialog extends StatelessWidget {
this.alignment,
this.insetPadding,
this.width,
this.heightFactor = 0.7,
});

final Widget? title;
Expand All @@ -39,10 +40,12 @@ class FlowyDialog extends StatelessWidget {

final double? width;

final double heightFactor;

@override
Widget build(BuildContext context) {
final windowSize = MediaQuery.of(context).size;
final size = windowSize * 0.7;
final size = windowSize * heightFactor;

return SimpleDialog(
alignment: alignment,
Expand Down
7 changes: 0 additions & 7 deletions frontend/appflowy_tauri/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions frontend/appflowy_tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]

[patch.crates-io]
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab = { path = "../../AppFlowy-Collab/collab" }
collab-entity = { path = "../../AppFlowy-Collab/collab-entity" }
collab-folder = { path = "../../AppFlowy-Collab/collab-folder" }
collab-document = { path = "../../AppFlowy-Collab/collab-document" }
collab-database = { path = "../../AppFlowy-Collab/collab-database" }
collab-plugins = { path = "../../AppFlowy-Collab/collab-plugins" }
collab-user = { path = "../../AppFlowy-Collab/collab-user" }
15 changes: 8 additions & 7 deletions frontend/appflowy_web/wasm-libs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions frontend/rust-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions frontend/rust-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ rocksdb = { git = "https://github.com/LucasXu0/rust-rocksdb", rev = "21cf4a23ec1
# To switch to the local path, run:
# scripts/tool/update_collab_source.sh
# ⚠️⚠️⚠️️
collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "5048762" }
collab = { path = "../AppFlowy-Collab/collab" }
collab-entity = { path = "../AppFlowy-Collab/collab-entity" }
collab-folder = { path = "../AppFlowy-Collab/collab-folder" }
collab-document = { path = "../AppFlowy-Collab/collab-document" }
collab-database = { path = "../AppFlowy-Collab/collab-database" }
collab-plugins = { path = "../AppFlowy-Collab/collab-plugins" }
collab-user = { path = "../AppFlowy-Collab/collab-user" }
10 changes: 8 additions & 2 deletions frontend/rust-lib/flowy-core/src/deps_resolve/search_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ impl SearchDepsResolver {
folder_manager: Arc<FolderManager>,
) -> Arc<SearchManager> {
let folder_handler = Arc::new(FolderSearchHandler::new(folder_indexer));
let document_handler = Arc::new(DocumentSearchHandler::new(cloud_service, folder_manager));
Arc::new(SearchManager::new(vec![folder_handler, document_handler]))
let document_handler = Arc::new(DocumentSearchHandler::new(
cloud_service,
folder_manager.clone(),
));
Arc::new(SearchManager::new(
folder_manager,
vec![folder_handler, document_handler],
))
}
}
2 changes: 1 addition & 1 deletion frontend/rust-lib/flowy-folder/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ impl FolderManager {
}

/// Filter the views that are in the trash and belong to the other private sections.
fn get_view_ids_should_be_filtered(&self, folder: &Folder) -> Vec<String> {
pub fn get_view_ids_should_be_filtered(&self, folder: &Folder) -> Vec<String> {
let trash_ids = self.get_all_trash_ids(folder);
let other_private_view_ids = self.get_other_private_view_ids(folder);
[trash_ids, other_private_view_ids].concat()
Expand Down
1 change: 1 addition & 0 deletions frontend/rust-lib/flowy-folder/src/user_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl DefaultFolderBuilder {
recent: Default::default(),
trash: Default::default(),
private: Default::default(),
section_view_relations: Default::default(),
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/rust-lib/flowy-search/src/folder/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ impl IndexManager for FolderIndexManagerImpl {

let (icon, icon_ty) = self.extract_icon(data.icon, data.layout);

let delete_term = Term::from_field_text(id_field, &data.id.clone());
// Remove old index just in case we have duplicate messages
// from the index content receiver.
index_writer.delete_term(delete_term);

// Add new index
let _ = index_writer.add_document(doc![
id_field => data.id,
Expand Down
Loading