Skip to content

Commit 5d96341

Browse files
authored
Fix keyword search (#252)
1 parent b50a5a1 commit 5d96341

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/app/metadata/features/metadata-browser-filter/metadata-browser-filter.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919
<mat-card appearance="outlined" class="p-3">
2020
<form (submit)="submit($event)">
2121
<mat-form-field
22-
[class.mb-3]="!activeKeyword()"
22+
[class.mb-3]="!activeQuery()"
2323
class="w-full [&_.mat-mdc-form-field-subscript-wrapper]:h-2"
2424
><input type="submit" class="cdk-visually-hidden" aria-hidden="true" />
2525
<input
2626
type="search"
2727
matInput
28-
placeholder="Enter any keyword or ID"
29-
aria-label="Enter any keyword or ID"
28+
placeholder="Enter any search terms"
29+
aria-label="Enter any search terms"
3030
[matAutocomplete]="options"
31-
[field]="searchForm.searchTerm"
31+
[field]="searchForm.query"
3232
/>
3333
<mat-icon matSuffix fontIcon="search"></mat-icon>
3434
</mat-form-field>
35-
@if (activeKeyword()) {
35+
@if (activeQuery()) {
3636
<mat-chip-set class="chip-set-tertiary mb-3">
3737
<mat-chip (removed)="clearSearchQuery()">
38-
Keyword: {{ activeKeyword() }}
38+
Search for: {{ activeQuery() }}
3939
<button
4040
matChipRemove
4141
data-umami-event="Metadata Browser Search Query Clear Clicked"
@@ -88,9 +88,9 @@
8888
hideSingleSelectionIndicator="true"
8989
(optionSelected)="onOptionSelected($event)"
9090
>
91-
@if (searchModel().searchTerm) {
91+
@if (searchModel().query) {
9292
<mat-option disabled="true">
93-
Press Enter to filter for the keyword '{{ searchModel().searchTerm }}'
93+
Press Enter to search for: {{ searchModel().query }}
9494
</mat-option>
9595
@for (facet of filteredFacets(); track facet.key) {
9696
<mat-optgroup [label]="facet.name" class="larger-optgroup-label">

src/app/metadata/features/metadata-browser-filter/metadata-browser-filter.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('MetadataBrowserFilterComponent', () => {
6262
});
6363

6464
it('should correctly filter by query', async () => {
65-
const searchInput = screen.getByPlaceholderText('Enter any keyword or ID');
65+
const searchInput = screen.getByPlaceholderText('Enter any search terms');
6666
const routerSpy = vitest.spyOn(router, 'navigate');
6767
await userEvent.type(searchInput, 'test query');
6868
await userEvent.type(searchInput, '{Enter}');
@@ -78,7 +78,7 @@ describe('MetadataBrowserFilterComponent', () => {
7878

7979
it('should show the autocomplete options correctly', async () => {
8080
const searchInput = screen.getByRole('combobox', {
81-
name: 'Enter any keyword or ID',
81+
name: 'Enter any search terms',
8282
});
8383
searchInput.focus();
8484
await userEvent.keyboard('opt');
@@ -87,7 +87,7 @@ describe('MetadataBrowserFilterComponent', () => {
8787
const autoCompleteOptions = screen.getAllByRole('option');
8888
expect(autoCompleteOptions.length).toBe(9);
8989
expect(autoCompleteOptions[0].textContent.trim()).toBe(
90-
"Press Enter to filter for the keyword 'opt'",
90+
'Press Enter to search for: opt',
9191
);
9292
expect(autoCompleteOptions[1].ariaLabel!).toBe('Option 1 (62 results)');
9393
});

src/app/metadata/features/metadata-browser-filter/metadata-browser-filter.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export class MetadataBrowserFilterComponent implements OnInit {
7272
protected expandedPanels: { [facetKey: string]: boolean } = {};
7373

7474
protected facetData = signal<FacetFilterSetting>({});
75-
protected activeKeyword = signal<string>('');
76-
protected searchModel = signal({ searchTerm: '' });
75+
protected activeQuery = signal<string>('');
76+
protected searchModel = signal({ query: '' });
7777
protected searchForm = form(this.searchModel);
7878

7979
readonly paginated = this.#metadataSearch.paginated;
@@ -88,7 +88,7 @@ export class MetadataBrowserFilterComponent implements OnInit {
8888
);
8989

9090
protected filteredFacets = computed(() => {
91-
const filter = this.searchModel().searchTerm.toLocaleLowerCase();
91+
const filter = this.searchModel().query.toLocaleLowerCase();
9292
return this.facetWithExpanded()
9393
.map((f) => {
9494
const selectedFacets = new Set(this.facetData()[f.key] ?? []);
@@ -142,7 +142,7 @@ export class MetadataBrowserFilterComponent implements OnInit {
142142
* On init, define the default values of the search variables
143143
*/
144144
ngOnInit(): void {
145-
this.#loadSearchTermsFromRoute();
145+
this.#loadQueryFromRoute();
146146
}
147147

148148
/**
@@ -174,7 +174,7 @@ export class MetadataBrowserFilterComponent implements OnInit {
174174
* Syncs the data between this component and the search service and initiates a new search.
175175
*/
176176
#performSearch(): void {
177-
this.#updateMetadataServiceSearchTermsAndRoute();
177+
this.#updateMetadataServiceQueryAndRoute();
178178
}
179179

180180
/**
@@ -199,29 +199,29 @@ export class MetadataBrowserFilterComponent implements OnInit {
199199
/**
200200
* Pushes the local filters, search term and page setup to the search service.
201201
*/
202-
async #updateMetadataServiceSearchTermsAndRoute(): Promise<void> {
202+
async #updateMetadataServiceQueryAndRoute(): Promise<void> {
203203
await this.#router.navigate([], {
204204
relativeTo: this.#route,
205205
queryParams: {
206206
s: this.#skip() !== DEFAULT_SKIP_VALUE ? this.#skip() : undefined,
207-
q: this.activeKeyword() !== '' ? this.activeKeyword() : undefined,
207+
q: this.activeQuery() !== '' ? this.activeQuery() : undefined,
208208
f:
209209
Object.keys(this.facetData()).length !== 0
210210
? encodeURIComponent(this.#facetDataToString(this.facetData()))
211211
: undefined,
212212
p: this.pageSize() !== DEFAULT_PAGE_SIZE ? this.pageSize() : undefined,
213213
},
214214
});
215-
this.#loadSearchTermsFromRoute();
215+
this.#loadQueryFromRoute();
216216
}
217217

218218
/**
219219
* This function takes the current URL, determines the query parameters and sets them accordingly in the metadata search service.
220220
*/
221-
#loadSearchTermsFromRoute(): void {
221+
#loadQueryFromRoute(): void {
222222
const { s, q, f, p } = this.#router.routerState.snapshot.root.queryParams;
223223
const pageSize = parseInt(p) || DEFAULT_PAGE_SIZE;
224-
this.activeKeyword.set(q || '');
224+
this.activeQuery.set(q || '');
225225
if (f) {
226226
const paramVals = this.#facetDataFromString(decodeURIComponent(f));
227227
if (paramVals) {
@@ -233,7 +233,7 @@ export class MetadataBrowserFilterComponent implements OnInit {
233233
this.#className,
234234
pageSize,
235235
skip,
236-
this.searchModel().searchTerm,
236+
this.activeQuery(),
237237
this.facetData(),
238238
);
239239
}
@@ -254,13 +254,13 @@ export class MetadataBrowserFilterComponent implements OnInit {
254254
*/
255255
protected submit(event: SubmitEvent | Event): void {
256256
event.preventDefault();
257-
const searchTerm = this.searchModel().searchTerm;
258-
if (searchTerm !== this.activeKeyword()) {
259-
this.activeKeyword.set(searchTerm);
257+
const query = this.searchModel().query;
258+
if (query !== this.activeQuery()) {
259+
this.activeQuery.set(query);
260260
this.#metadataSearch.resetSkip();
261261
this.facets.set([]);
262262
this.#currentFacet = undefined;
263-
this.searchModel.set({ searchTerm: '' });
263+
this.searchModel.set({ query: '' });
264264
this.#performSearch();
265265
}
266266
}
@@ -283,7 +283,7 @@ export class MetadataBrowserFilterComponent implements OnInit {
283283
* Resets the search query and triggers a reload of the results.
284284
*/
285285
protected clearSearchQuery(): void {
286-
this.activeKeyword.set('');
286+
this.activeQuery.set('');
287287
this.#metadataSearch.resetSkip();
288288
this.facets.set([]);
289289
this.#currentFacet = undefined;
@@ -336,7 +336,7 @@ export class MetadataBrowserFilterComponent implements OnInit {
336336
facetData = input.option.value.split('#');
337337
checked = (facetData[2] ?? 'false') === 'true' ? true : false;
338338
facetData = facetData.slice(0, 2) ?? [];
339-
this.searchModel.set({ searchTerm: '' });
339+
this.searchModel.set({ query: '' });
340340
} else {
341341
facetData = input.source.name?.split('#') ?? [];
342342
checked = input.checked;

0 commit comments

Comments
 (0)