diff --git a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.html b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.html index 471d70d7508..fe72d110992 100644 --- a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.html +++ b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.html @@ -34,11 +34,13 @@ class="adf-permission-result-list" [class.adf-permission-result-list-search]="searchedWord.length === 0"> - + + disableRipple + [value]="EVERYONE">

{{'PERMISSION_MANAGER.ADD-PERMISSION.EVERYONE' | translate}} @@ -46,7 +48,8 @@ diff --git a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts index f6392694417..700033551c9 100644 --- a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts @@ -207,4 +207,41 @@ describe('AddPermissionPanelComponent', () => { expect(element.querySelector('#result_option_0 .mat-list-text').innerHTML).not.toEqual(element.querySelector('#result_option_1 .mat-list-text').innerHTML); }); })); + + it('should emit unique element in between multiple search', async(() => { + searchApiService = fixture.componentRef.injector.get(SearchService); + spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); + let searchAttempt = 0; + + component.select.subscribe((items) => { + searchAttempt++; + expect(items.length).toBe(1); + expect(items[0].entry.id).toBeDefined(); + expect(items[0].entry.id).not.toBeNull(); + expect(items[0].entry.id).toBe(fakeAuthorityListResult.list.entries[0].entry.id); + }); + + typeWordIntoSearchInput('a'); + fixture.whenStable().then(() => { + fixture.detectChanges(); + let listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0')); + expect(listElement).not.toBeNull(); + listElement.triggerEventHandler('click', {}); + + const clearButton = fixture.debugElement.query(By.css('#adf-permission-clear-input')); + expect(clearButton).not.toBeNull(); + clearButton.triggerEventHandler('click', {}); + fixture.detectChanges(); + + typeWordIntoSearchInput('abc'); + fixture.detectChanges(); + fixture.whenStable().then(() => { + fixture.detectChanges(); + listElement = fixture.debugElement.query(By.css('#result_option_0')); + expect(listElement).not.toBeNull(); + listElement.triggerEventHandler('click', {}); + expect(searchAttempt).toBe(2); + }); + }); + })); }); diff --git a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts index 095732f7db2..9bf41f6b3ec 100644 --- a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts +++ b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts @@ -15,13 +15,14 @@ * limitations under the License. */ -import { SearchService, SearchConfigurationService } from '@alfresco/adf-core'; +import { SearchConfigurationService, SearchService } from '@alfresco/adf-core'; import { NodeEntry } from '@alfresco/js-api'; -import { Component, ViewEncapsulation, EventEmitter, Output, ViewChild } from '@angular/core'; +import { Component, EventEmitter, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { FormControl } from '@angular/forms'; import { debounceTime } from 'rxjs/operators'; import { SearchPermissionConfigurationService } from './search-config-permission.service'; import { SearchComponent } from '../../../search/components/search.component'; +import { MatSelectionList } from '@angular/material/list'; @Component({ selector: 'adf-add-permission-panel', @@ -37,9 +38,12 @@ export class AddPermissionPanelComponent { @ViewChild('search', { static: true }) search: SearchComponent; + @ViewChild(MatSelectionList, { static: false }) + matSelectionList: MatSelectionList; + /** Emitted when a permission list item is selected. */ @Output() - select: EventEmitter = new EventEmitter(); + select: EventEmitter = new EventEmitter(); searchInput: FormControl = new FormControl(); searchedWord = ''; @@ -55,6 +59,9 @@ export class AddPermissionPanelComponent { debounceTime(this.debounceSearch) ) .subscribe((searchValue) => { + const selectionOptions = this.matSelectionList.selectedOptions.selected.map(option => option.value); + this.selectedItems.push(...selectionOptions); + this.matSelectionList.deselectAll(); this.searchedWord = searchValue; if (!searchValue) { this.search.resetResults(); @@ -62,24 +69,17 @@ export class AddPermissionPanelComponent { }); } - elementClicked(item: NodeEntry) { - if (this.isAlreadySelected(item)) { - this.selectedItems.splice(this.selectedItems.indexOf(item), 1); - } else { - this.selectedItems.push(item); - } - this.select.emit(this.selectedItems); - } - - selectAll(items: NodeEntry[]) { - if (items?.length > 0) { - this.selectedItems = items; - this.select.emit(this.selectedItems); - } - } - - private isAlreadySelected(item: NodeEntry): boolean { - return this.selectedItems.indexOf(item) >= 0; + onSelectionChange() { + const currentSelection = this.matSelectionList.selectedOptions.selected.map(option => option.value); + const uniqueSelection = [ ...currentSelection, ...this.selectedItems ] + .reduce((uniquesElements, currentElement) => { + const isExist = uniquesElements.find(uniqueElement => uniqueElement.entry.id === currentElement.entry.id); + if (!isExist) { + uniquesElements.push(currentElement); + } + return uniquesElements; + }, []); + this.select.emit(uniqueSelection); } clearSearch() {