mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-10165] filter out inaccessible locations from autocomplete (#11240)
This commit is contained in:
+28
-5
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+6
-4
@@ -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];
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user