Skip to content

Commit

Permalink
NAS-128795 / 24.10 / Various improvements for global search (#10039)
Browse files Browse the repository at this point in the history
* NAS-128795: Various improvements for global search

* NAS-128795: Various improvements for global search

* NAS-128795: Various improvements for global search

* NAS-128795: Various improvements for global search
  • Loading branch information
AlexKarpov98 committed May 13, 2024
1 parent 4fc801a commit fea96e0
Show file tree
Hide file tree
Showing 96 changed files with 122 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ <h2 class="section">
*ngFor="let result of getLimitedSectionResults(section.value); trackBy: trackById"
class="search-result"
tabindex="0"
[class.highlighted-result]="isSearchInputFocused && isSameHierarchyResult(firstAvailableSearchResult, result)"
[ixTest]="['search-result', result.hierarchy.join('-')]"
(click)="selectElement(result)"
(keydown.enter)="selectElement(result)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
cursor: pointer;
padding: 13px 20px;

&.highlighted-result {
background-color: var(--bg1);
opacity: 0.8;
}

&:hover {
background-color: var(--bg1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { AuthService } from 'app/services/auth/auth.service';
export class GlobalSearchResultsComponent implements OnChanges {
@Input() searchTerm = '';
@Input() isLoading = false;
@Input() isSearchInputFocused = false;
@Input() results: UiSearchableElement[] = [];

readonly initialResultsLimit = this.globalSearchSectionsProvider.globalSearchInitialLimit;
Expand Down Expand Up @@ -55,6 +56,10 @@ export class GlobalSearchResultsComponent implements OnChanges {
);
}

get firstAvailableSearchResult(): UiSearchableElement | null {
return this.availableSections.flatMap((section) => this.getLimitedSectionResults(section.value))[0];
}

constructor(
protected authService: AuthService,
private searchProvider: UiSearchProvider,
Expand Down Expand Up @@ -101,6 +106,10 @@ export class GlobalSearchResultsComponent implements OnChanges {
return this.results.filter((element) => element?.section === section);
}

isSameHierarchyResult(a: UiSearchableElement, b: UiSearchableElement): boolean {
return isEqual(a.hierarchy, b.hierarchy);
}

private saveSearchResult(result: UiSearchableElement): void {
const existingResults = JSON.parse(
this.window.localStorage.getItem('recentSearches') || '[]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
matInput
ixTest="global-search"
class="search-input"
[placeholder]="'Search' | translate"
[placeholder]="'Search UI' | translate"
(click)="showOverlay()"
(focus)="overlayRef.detach(); searchInput.blur(); showOverlay()"
(blur)="overlayRef.detach()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
matInput
ixTest="global-search"
class="search-input"
[placeholder]="'Search' | translate"
[placeholder]="'Search UI' | translate"
[formControl]="searchControl"
(keydown)="handleKeyDown($event)"
/>
Expand All @@ -27,6 +27,7 @@
[searchTerm]="searchControl.value"
[results]="searchResults"
[isLoading]="isLoading"
[isSearchInputFocused]="isSearchInputFocused"
(keydown)="handleKeyDown($event)"
></ix-global-search-results>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class GlobalSearchComponent implements OnInit {
isLoading = false;
systemVersion: string;

get isSearchInputFocused(): boolean {
return document.activeElement === this.searchInput?.nativeElement;
}

constructor(
protected sidenavService: SidenavService,
private searchProvider: UiSearchProvider,
Expand Down Expand Up @@ -70,6 +74,11 @@ export class GlobalSearchComponent implements OnInit {
break;
case 'Enter':
event.preventDefault();

if (this.isSearchInputFocused) {
moveToNextFocusableElement();
(this.document.activeElement as HTMLElement)?.click();
}
break;
default:
if (event.key.length === 1 && !event.metaKey) {
Expand Down
12 changes: 6 additions & 6 deletions src/app/modules/global-search/services/ui-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export class UiSearchProvider implements GlobalSearchProvider {
search(term: string, limit: number): Observable<UiSearchableElement[]> {
// sort results by showing hierarchy match first, then synonyms match
const sortedResults = this.translatedTerms.filter((item) => {
return item.synonyms.find((synonym) => synonym?.toLowerCase().startsWith(term.toLowerCase()))
|| item.hierarchy[item.hierarchy.length - 1]?.toLowerCase().startsWith(term.toLowerCase());
return item.synonyms.find((synonym) => synonym?.toLowerCase().includes(term.toLowerCase()))
|| item.hierarchy[item.hierarchy.length - 1]?.toLowerCase().includes(term.toLowerCase());
}).sort((a, b) => {
const aHierarchyMatch = a.hierarchy[a.hierarchy.length - 1]?.toLowerCase().startsWith(term.toLowerCase()) ? 1 : 0;
const bHierarchyMatch = b.hierarchy[b.hierarchy.length - 1]?.toLowerCase().startsWith(term.toLowerCase()) ? 1 : 0;
const aHierarchyMatch = a.hierarchy[a.hierarchy.length - 1]?.toLowerCase().includes(term.toLowerCase()) ? 1 : 0;
const bHierarchyMatch = b.hierarchy[b.hierarchy.length - 1]?.toLowerCase().includes(term.toLowerCase()) ? 1 : 0;

const aSynonymMatch = a.synonyms.find((synonym) => synonym?.toLowerCase().startsWith(term.toLowerCase())) ? 1 : 0;
const bSynonymMatch = b.synonyms.find((synonym) => synonym?.toLowerCase().startsWith(term.toLowerCase())) ? 1 : 0;
const aSynonymMatch = a.synonyms.find((synonym) => synonym?.toLowerCase().includes(term.toLowerCase())) ? 1 : 0;
const bSynonymMatch = b.synonyms.find((synonym) => synonym?.toLowerCase().includes(term.toLowerCase())) ? 1 : 0;

return bHierarchyMatch - aHierarchyMatch || aSynonymMatch - bSynonymMatch;
}).slice(0, limit);
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2904,6 +2904,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary Email": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Email": "",
"Secondary Name": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/dsb.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en-au.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en-gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/eo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Email": "",
"Secondary Name": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-co.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-mx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-ni.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-ve.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3077,6 +3077,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
"SNMP": "",
"Saving settings": "",
"Search Documentation for «{value}»": "",
"Search UI": "",
"Secret Confirm must match Secret": "",
"Select Image Tag": "",
"Select Rating": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/ga.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/gd.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/gl.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,7 @@
"Search Documentation for «{value}»": "",
"Search Input Fields": "",
"Search Results for «{query}»": "",
"Search UI": "",
"Search or enter value": "",
"Secondary Contact": "",
"Secondary DNS server.": "",
Expand Down

0 comments on commit fea96e0

Please sign in to comment.