-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into ADF-5543-enable-lint-accessibility
- Loading branch information
Showing
49 changed files
with
850 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
Title: Category selector dialog component | ||
Added: v6.8.0 | ||
Status: Active | ||
Last reviewed: 2024-03-12 | ||
--- | ||
|
||
# [Category selector dialog component](../../../lib/content-services/src/lib/dialogs/category-selector.dialog.ts "Defined in category-selector.dialog.ts") | ||
|
||
Allows the user to select one or multiple categories. | ||
|
||
![Category selector dialog component](../../docassets/images/adf-category-selector-dialog.png) | ||
|
||
## Dialog inputs | ||
|
||
| Name | Type | Default value | Description | | ||
| ---- |-----------| ------------- | ----------- | | ||
| select | [`Subject<Category[]>`](https://github.com/Alfresco/alfresco-ng2-components/blob/develop/lib/js-api/src/api/content-rest-api/docs/CategoriesApi.md) | | Emits an array of selected categories when the dialog closes | | ||
| multiSelect | `boolean` | `true` | (optional) Toggles multiselect mode | | ||
|
||
## Basic Usage | ||
|
||
```ts | ||
constructor(private dialog: MatDialog) {} | ||
|
||
... | ||
|
||
function openCatDialog() { | ||
const data: CategorySelectorDialogOptions = { | ||
select: new Subject<Category[]>(), | ||
multiSelect: false | ||
}; | ||
|
||
this.dialog.open(CategorySelectorDialogComponent, { | ||
data, | ||
width: '400px' | ||
}); | ||
|
||
data.select.subscribe( | ||
(selections: Category[]) => { | ||
... | ||
} | ||
); | ||
} | ||
``` | ||
All the results will be streamed to the select [subject](http://reactivex.io/rxjs/manual/overview.html#subject) present in the `CategorySelectorDialogOptions` object passed to the dialog. | ||
When the category is selected by clicking the `Select` button, the `options.select` stream will be completed. | ||
|
||
## Details | ||
|
||
This component lets the user select categories. Use the | ||
Angular [`MatDialog`](https://material.angular.io/components/dialog/overview) | ||
service to open the dialog, as shown in the example, and pass a `options` object | ||
with properties. | ||
|
||
## See also | ||
|
||
- [Categories management component](../components/categories-management.component.md) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
lib/content-services/src/lib/dialogs/category-selector.dialog.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<h1 mat-dialog-title> | ||
{{ 'CATEGORIES_MANAGEMENT.SELECT_EXISTING_CATEGORY' | translate }} | ||
</h1> | ||
|
||
<mat-dialog-content class="adf-dialog-content"> | ||
<adf-categories-management | ||
(categoriesChange)="categories = $event" | ||
[categoryNameControlVisible]="true" | ||
[managementMode]="categoriesManagementMode" | ||
[multiSelect]="multiSelect"> | ||
</adf-categories-management> | ||
</mat-dialog-content> | ||
<mat-dialog-actions align="end"> | ||
<button | ||
data-automation-id="category-selector-dialog-cancel-button" | ||
mat-button | ||
mat-dialog-close> | ||
{{ 'NODE_SELECTOR.CANCEL' | translate }} | ||
</button> | ||
<button | ||
(click)="selectCategories()" | ||
[disabled]="!categories.length" | ||
color="primary" | ||
data-automation-id="category-selector-dialog-select-button" | ||
mat-button> | ||
{{ 'NODE_SELECTOR.CHOOSE' | translate }} | ||
</button> | ||
</mat-dialog-actions> |
5 changes: 5 additions & 0 deletions
5
lib/content-services/src/lib/dialogs/category-selector.dialog.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
adf-category-selector-dialog { | ||
.adf-dialog-content { | ||
height: 400px; | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
lib/content-services/src/lib/dialogs/category-selector.dialog.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { CategorySelectorDialogComponent, CategorySelectorDialogOptions } from './category-selector.dialog'; | ||
import { Subject } from 'rxjs'; | ||
import { Category } from '@alfresco/js-api'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { CoreTestingModule } from '@alfresco/adf-core'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
describe('Category selector dialog component', () => { | ||
let fixture: ComponentFixture<CategorySelectorDialogComponent>; | ||
let component: CategorySelectorDialogComponent; | ||
let selectButton: HTMLButtonElement; | ||
|
||
const dialogRef = { | ||
close: jasmine.createSpy('close') | ||
}; | ||
|
||
const options: CategorySelectorDialogOptions = { | ||
select: new Subject<Category[]>() | ||
}; | ||
|
||
const categories: Category[] = [{id: 'id1', name: 'cat1'}, {id: 'id2', name: 'cat3'}]; | ||
|
||
const setCategories = () => { | ||
component.categories = categories; | ||
fixture.detectChanges(); | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [CoreTestingModule], | ||
providers: [ | ||
{ provide: MatDialogRef, useValue: dialogRef }, | ||
{ provide: MAT_DIALOG_DATA, useValue: options } | ||
] | ||
}); | ||
dialogRef.close.calls.reset(); | ||
fixture = TestBed.createComponent(CategorySelectorDialogComponent); | ||
component = fixture.componentInstance; | ||
|
||
fixture.detectChanges(); | ||
|
||
selectButton = fixture.debugElement.query(By.css(`[data-automation-id="category-selector-dialog-select-button"]`)).nativeElement; | ||
}); | ||
|
||
it('should set params if they are provided as dialog options', () => { | ||
options.multiSelect = true; | ||
component.ngOnInit(); | ||
|
||
expect(component.multiSelect).toBeTrue(); | ||
}); | ||
|
||
it('should close dialog on cancel button click', () => { | ||
fixture.debugElement.query(By.css(`[data-automation-id="category-selector-dialog-cancel-button"]`)).nativeElement.click(); | ||
expect(dialogRef.close).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should close dialog if category is selected and Select button was clicked', () => { | ||
selectButton.click(); | ||
expect(dialogRef.close).not.toHaveBeenCalled(); | ||
|
||
setCategories(); | ||
selectButton.click(); | ||
|
||
expect(dialogRef.close).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should provide selected categories as observable on Select click', () => { | ||
spyOn(options.select, 'next'); | ||
setCategories(); | ||
selectButton.click(); | ||
|
||
expect(options.select.next).toHaveBeenCalledWith(categories); | ||
}); | ||
|
||
it('should disable select button if no categories were selected', () => { | ||
expect(selectButton.disabled).toBeTruthy(); | ||
setCategories(); | ||
expect(selectButton.disabled).toBeFalse(); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
lib/content-services/src/lib/dialogs/category-selector.dialog.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { Subject } from 'rxjs'; | ||
import { Category } from '@alfresco/js-api'; | ||
import { CategoriesManagementMode } from '../category'; | ||
|
||
export interface CategorySelectorDialogOptions { | ||
select: Subject<Category[]>; | ||
multiSelect?: boolean; | ||
} | ||
|
||
@Component({ | ||
selector: 'adf-category-selector-dialog', | ||
templateUrl: './category-selector.dialog.html', | ||
styleUrls: ['./category-selector.dialog.scss'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class CategorySelectorDialogComponent implements OnInit { | ||
categories: Category[] = []; | ||
categoriesManagementMode = CategoriesManagementMode.ASSIGN; | ||
multiSelect = true; | ||
|
||
constructor( | ||
private dialog: MatDialogRef<CategorySelectorDialogComponent, boolean>, | ||
@Inject(MAT_DIALOG_DATA) private options: CategorySelectorDialogOptions | ||
) { | ||
} | ||
|
||
ngOnInit() { | ||
this.multiSelect = this.options.multiSelect ?? true; | ||
} | ||
|
||
selectCategories() { | ||
this.options.select.next(this.categories); | ||
this.dialog.close(true); | ||
} | ||
} |
Oops, something went wrong.