[ACS-10165] filter out inaccessible locations from autocomplete (#11240)

This commit is contained in:
Grzegorz Jaśkowski
2025-10-10 18:20:38 +02:00
committed by GitHub
parent 816601fcec
commit 84d32157ad
2 changed files with 34 additions and 9 deletions
@@ -169,10 +169,7 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
const sitesMock: SitePaging = {
list: {
pagination: {},
entries: [
{ entry: { guid: 'site1', id: 'site1', title: 'Marketing', visibility: 'public' } },
{ entry: { guid: 'site2', id: 'site2', title: 'Finance', visibility: 'private' } }
]
entries: [{ entry: { guid: 'site1', id: 'site1', title: 'Marketing', visibility: 'public' } }]
}
};
component.settings.field = AutocompleteField.LOCATION;
@@ -182,10 +179,36 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
component.autocompleteOptions$.subscribe((result) => {
expect(result).toEqual([
{ id: 'site1', value: 'Marketing' },
{ id: 'site2', value: 'Finance' },
{ value: 'Repository', query: `PATH:'somePath'` }
]);
done();
});
});
it('should filter LOCATION field options', (done) => {
const sitesMock: SitePaging = {
list: {
pagination: {},
entries: [
{ entry: { guid: 'site1', id: 'site1', title: 'Marketing', visibility: 'public' } },
{ entry: { guid: 'site2', id: 'site2', title: 'Finance', visibility: 'moderated' } },
{ entry: { guid: 'site3', id: 'site3', title: 'HR', visibility: 'private' } },
{ entry: { guid: 'site4', id: 'site4', title: 'Legal', visibility: 'private', role: 'Consumer' } },
{ entry: { guid: 'site5', id: 'site5', title: 'IT', visibility: 'moderated', role: 'SiteManager' } }
]
}
};
component.settings.field = AutocompleteField.LOCATION;
component.settings.autocompleteOptions = [];
spyOn(sitesService, 'getSites').and.returnValue(of(sitesMock));
component.onInputChange('mark');
component.autocompleteOptions$.subscribe((result) => {
expect(result).toEqual([
{ id: 'site1', value: 'Marketing' },
{ id: 'site4', value: 'Legal' },
{ id: 'site5', value: 'IT' }
]);
done();
});
});
});
@@ -198,10 +198,12 @@ export class SearchFilterAutocompleteChipsComponent implements SearchWidget, OnI
.pipe(
map((sites) => {
const predefinedOptions = this.settings?.autocompleteOptions || [];
const sitesOptions = sites.list.entries.map<AutocompleteOption>((siteEntry) => ({
id: siteEntry.entry.id,
value: siteEntry.entry.title
}));
const sitesOptions = sites.list.entries
.filter((siteEntry) => siteEntry.entry.visibility === 'public' || siteEntry.entry?.role)
.map<AutocompleteOption>((siteEntry) => ({
id: siteEntry.entry.id,
value: siteEntry.entry.title
}));
return [...sitesOptions, ...predefinedOptions];
})
)