Skip to content

Commit

Permalink
Merge pull request #215 from cozy/feat/sort-login-before
Browse files Browse the repository at this point in the history
feat: Logins before every other types in search result
  • Loading branch information
zatteo authored Jul 9, 2024
2 parents 54e5b91 + 8b57bdb commit a76c3a3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions libs/common/src/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ export class SearchService implements SearchServiceAbstraction {
filter: ((cipher: CipherView) => boolean) | ((cipher: CipherView) => boolean)[] = null,
ciphers: CipherView[] = null
): Promise<CipherView[]> {
// Cozy customization, display logins before every other types (see below)
/*
const results: CipherView[] = [];
*/
if (query != null) {
query = SearchService.normalizeSearchQuery(query.trim().toLowerCase());
}
Expand Down Expand Up @@ -168,13 +171,35 @@ export class SearchService implements SearchServiceAbstraction {
});
}

// Cozy customization, display logins before every other types
// For example, it avoids to have 100 Free invoices before 1 Free login
//*
const loginResults: CipherView[] = [];
const otherResults: CipherView[] = [];

if (searchResults != null) {
searchResults.forEach((r) => {
if (ciphersMap.has(r.ref)) {
const cipher = ciphersMap.get(r.ref);
if (cipher.type === CipherType.Login) {
loginResults.push(cipher);
} else {
otherResults.push(cipher);
}
}
});
}

const results = loginResults.concat(otherResults);
/*/
if (searchResults != null) {
searchResults.forEach((r) => {
if (ciphersMap.has(r.ref)) {
results.push(ciphersMap.get(r.ref));
}
});
}
//*/
return results;
}

Expand Down

0 comments on commit a76c3a3

Please sign in to comment.