Skip to content

Commit 4feba2f

Browse files
[ACS-10332] Search: Editable Combobox Without Autocomplete Does Not D… (#11310)
1 parent a4f5cfc commit 4feba2f

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

lib/content-services/src/lib/search/components/search-chip-autocomplete-input/search-chip-autocomplete-input.component.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
</mat-chip-grid>
3434
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)" id="adf-search-chip-autocomplete"
3535
(optionActivated)="activeAnyOption = true" (closed)="activeAnyOption = false">
36-
<ng-container *ngIf="optionInput.value.length > 0">
3736
<mat-option
3837
*ngFor="let option of filteredOptions"
3938
[value]="option"
@@ -46,6 +45,5 @@
4645
>
4746
{{ option.fullPath || option.value }}
4847
</mat-option>
49-
</ng-container>
5048
</mat-autocomplete>
5149
</mat-form-field>

lib/content-services/src/lib/search/components/search-chip-autocomplete-input/search-chip-autocomplete-input.component.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,5 +340,17 @@ describe('SearchChipAutocompleteInputComponent', () => {
340340
component.selectedOptions = [option];
341341
expect(component.isOptionSelected(option)).toBeTrue();
342342
});
343+
344+
it('should clear filteredOptions after input is cleared', async () => {
345+
enterNewInputValue('option');
346+
await fixture.whenStable();
347+
fixture.detectChanges();
348+
expect(component.filteredOptions.length).toBe(component.autocompleteOptions.length);
349+
350+
enterNewInputValue('');
351+
await fixture.whenStable();
352+
fixture.detectChanges();
353+
expect(component.filteredOptions.length).toBe(component.autocompleteOptions.length);
354+
});
343355
});
344356
});

lib/content-services/src/lib/search/components/search-chip-autocomplete-input/search-chip-autocomplete-input.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { ENTER } from '@angular/cdk/keycodes';
3333
import { FormControl, ReactiveFormsModule } from '@angular/forms';
3434
import { MatAutocompleteModule, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
3535
import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips';
36-
import { EMPTY, Observable, timer } from 'rxjs';
36+
import { Observable, timer } from 'rxjs';
3737
import { debounce, startWith, tap } from 'rxjs/operators';
3838
import { AutocompleteOption } from '../../models/autocomplete-option.interface';
3939
import { CommonModule } from '@angular/common';
@@ -77,7 +77,7 @@ export class SearchChipAutocompleteInputComponent implements OnInit, OnChanges {
7777
@Input()
7878
filter = (options: AutocompleteOption[], value: string): AutocompleteOption[] => {
7979
const filterValue = value.toLowerCase();
80-
return options.filter((option) => option.value.toLowerCase().includes(filterValue)).slice(0, 15);
80+
return options?.filter((option) => option.value.toLowerCase().includes(filterValue)).slice(0, 15) ?? [];
8181
};
8282

8383
@Output()
@@ -104,11 +104,11 @@ export class SearchChipAutocompleteInputComponent implements OnInit, OnChanges {
104104
.pipe(
105105
startWith(''),
106106
tap(() => (this.activeAnyOption = false)),
107-
debounce((value: string) => (value ? timer(300) : EMPTY)),
107+
debounce(() => timer(300)),
108108
takeUntilDestroyed(this.destroyRef)
109109
)
110110
.subscribe((value: string) => {
111-
this.filteredOptions = value ? this.filter(this.autocompleteOptions, value) : [];
111+
this.filteredOptions = this.filter(this.autocompleteOptions, value);
112112
this.inputChanged.emit(value);
113113
});
114114
this.onReset$?.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.reset());

lib/content-services/src/lib/search/components/search-filter-autocomplete-chips/search-filter-autocomplete-chips.component.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { AutocompleteField } from '../../models/autocomplete-option.interface';
2424
import { TagService } from '../../../tag/services/tag.service';
2525
import { SitesService } from '../../../common/services/sites.service';
2626
import { SitePaging } from '@alfresco/js-api';
27+
import { CategoryService } from '../../../category';
2728

2829
describe('SearchFilterAutocompleteChipsComponent', () => {
2930
let component: SearchFilterAutocompleteChipsComponent;
@@ -211,4 +212,31 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
211212
done();
212213
});
213214
});
215+
216+
it('should still call sitesService.getSites when input is empty for LOCATION field', () => {
217+
component.settings.field = AutocompleteField.LOCATION;
218+
const getSitesSpy = spyOn(sitesService, 'getSites').and.returnValue(
219+
of({
220+
list: { entries: [], pagination: {} }
221+
})
222+
);
223+
224+
component.onInputChange('');
225+
226+
expect(getSitesSpy).toHaveBeenCalled();
227+
});
228+
229+
it('should still call categoryService.searchCategories when input is empty for CATEGORIES field', () => {
230+
component.settings.field = AutocompleteField.CATEGORIES;
231+
const categoryService = TestBed.inject(CategoryService);
232+
const searchSpy = spyOn(categoryService, 'searchCategories').and.returnValue(
233+
of({
234+
list: { entries: [], pagination: {} }
235+
})
236+
);
237+
238+
component.onInputChange('');
239+
240+
expect(searchSpy).toHaveBeenCalledWith('', 0, 15);
241+
});
214242
});

lib/content-services/src/lib/search/components/search-filter-autocomplete-chips/search-filter-autocomplete-chips.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ export class SearchFilterAutocompleteChipsComponent implements SearchWidget, OnI
122122
}
123123

124124
onInputChange(value: string) {
125-
if (value) {
126-
if (this.settings.field === AutocompleteField.CATEGORIES) {
127-
this.searchForExistingCategories(value);
128-
} else if (this.settings.field === AutocompleteField.LOCATION) {
129-
this.populateSitesOptions();
130-
}
125+
if (this.settings.field === AutocompleteField.CATEGORIES) {
126+
this.searchForExistingCategories(value);
127+
} else if (this.settings.field === AutocompleteField.LOCATION) {
128+
this.populateSitesOptions();
131129
}
132130
}
133131

0 commit comments

Comments
 (0)