[ACS-7981] UI fixes for create categories dialog (#9754)

* [ACS-7981] Fixed UI for create categories dialog

* [ACS-7981] Adding mat selectors for create categories dialog

* [ACS-7981] Create category dialog no longer allows ability to add existing categories
This commit is contained in:
swapnil-verma-gl
2024-06-03 17:19:26 +05:30
committed by VitoAlbano
parent 2eb0b7a225
commit 8d9666bed6
5 changed files with 67 additions and 61 deletions

View File

@@ -1,8 +1,6 @@
<div class="adf-categories-management"> <div class="adf-categories-management">
<div *ngIf="categoryNameControlVisible" class="adf-category-name-field"> <div *ngIf="categoryNameControlVisible" class="adf-category-name-field">
<input #categoryNameInput <input #categoryNameInput
matInput
autocomplete="off"
[formControl]="categoryNameControl" [formControl]="categoryNameControl"
(keyup.enter)="addCategory()" (keyup.enter)="addCategory()"
placeholder="{{'CATEGORIES_MANAGEMENT.CATEGORIES_SEARCH_PLACEHOLDER' | translate }}" placeholder="{{'CATEGORIES_MANAGEMENT.CATEGORIES_SEARCH_PLACEHOLDER' | translate }}"
@@ -52,7 +50,7 @@
<mat-list-item <mat-list-item
*ngFor="let category of existingCategories" *ngFor="let category of existingCategories"
class="adf-category" class="adf-category"
(click)='addCategoryToAssign(category)'> (click)='addCategoryToAssign(category, isCRUDMode || !multiSelect && categories.length > 0)'>
{{ category.name }} {{ category.name }}
</mat-list-item> </mat-list-item>
<p *ngIf="!existingCategories?.length && !existingCategoriesLoading" <p *ngIf="!existingCategories?.length && !existingCategoriesLoading"

View File

@@ -1,8 +1,9 @@
@import 'styles/mat-selectors';
.adf-categories-management { .adf-categories-management {
.adf-category-name-field { .adf-category-name-field {
justify-content: space-between; justify-content: space-between;
width: 100%; padding: 0 10px;
color: var(--adf-metadata-property-panel-text-color);
background: var(--adf-metadata-buttons-background-color); background: var(--adf-metadata-buttons-background-color);
height: 32px; height: 32px;
border-radius: 12px; border-radius: 12px;
@@ -10,8 +11,15 @@
input { input {
background-color: transparent; background-color: transparent;
padding: 7px 8px 8px; color: var(--adf-metadata-property-panel-text-color);
padding: 7px 0;
width: 100%; width: 100%;
border: none;
outline: none;
}
#{$mat-form-field-error} {
padding-top: 5px;
} }
} }
@@ -46,7 +54,7 @@
background-color: inherit; background-color: inherit;
color: inherit; color: inherit;
&:hover { &:not(#{$mat-list-item-disabled}):hover {
cursor: pointer; cursor: pointer;
background: var(--adf-theme-mat-grey-color-a200); background: var(--adf-theme-mat-grey-color-a200);
} }
@@ -73,4 +81,8 @@
cursor: pointer; cursor: pointer;
overflow-wrap: anywhere; overflow-wrap: anywhere;
} }
#{$mat-list-item-disabled} #{$mat-list-item-primary-text} {
opacity: 1;
}
} }

View File

@@ -49,11 +49,7 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<void>(); private onDestroy$ = new Subject<void>();
private _categoryNameControl = new FormControl<string>( private _categoryNameControl = new FormControl<string>(
'', '',
[ [this.validateIfNotAlreadyAdded.bind(this), this.validateEmptyCategory, Validators.required],
this.validateIfNotAlreadyAdded.bind(this),
this.validateEmptyCategory,
Validators.required
],
this.validateIfNotAlreadyCreated.bind(this) this.validateIfNotAlreadyCreated.bind(this)
); );
private _existingCategories: Category[]; private _existingCategories: Category[];
@@ -150,9 +146,7 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
) )
.subscribe((name: string) => this.onNameControlValueChange(name)); .subscribe((name: string) => this.onNameControlValueChange(name));
this.categoryNameControl.statusChanges this.categoryNameControl.statusChanges.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.setCategoryNameControlErrorMessageKey());
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => this.setCategoryNameControlErrorMessageKey());
this.setCategoryNameControlErrorMessageKey(); this.setCategoryNameControlErrorMessageKey();
@@ -164,9 +158,7 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
this._categoryNameControl.removeValidators(Validators.required); this._categoryNameControl.removeValidators(Validators.required);
this.categories.forEach((category) => this.initialCategories.push(category)); this.categories.forEach((category) => this.initialCategories.push(category));
if (this.classifiableChanged) { if (this.classifiableChanged) {
this.classifiableChanged this.classifiableChanged.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => {
this.categories = []; this.categories = [];
this.categoryNameControlVisible = false; this.categoryNameControlVisible = false;
this.categoryNameControlVisibleChange.emit(false); this.categoryNameControlVisibleChange.emit(false);
@@ -235,14 +227,17 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
* Adds existing category to categories list and removes it from existing categories list. * Adds existing category to categories list and removes it from existing categories list.
* *
* @param category - selection list change containing selected category * @param category - selection list change containing selected category
* @param disableAddCategory - allow or disallow the ability to add a new category for assigning
*/ */
addCategoryToAssign(category: Category) { addCategoryToAssign(category: Category, disableAddCategory: boolean) {
if (!disableAddCategory) {
const selectedCategory: Category = category; const selectedCategory: Category = category;
this.categories.push(selectedCategory); this.categories.push(selectedCategory);
this._existingCategories.splice(this._existingCategories.indexOf(selectedCategory), 1); this._existingCategories.splice(this._existingCategories.indexOf(selectedCategory), 1);
this.categoryNameControl.updateValueAndValidity(); this.categoryNameControl.updateValueAndValidity();
this.categoriesChange.emit(this.categories); this.categoriesChange.emit(this.categories);
} }
}
/** /**
* Removes the category from categories list and adds it to existing categories list in ASSIGN mode. * Removes the category from categories list and adds it to existing categories list in ASSIGN mode.
@@ -283,7 +278,9 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
existingCat.name = path ? `${path}/${rowEntry.entry.name}` : rowEntry.entry.name; existingCat.name = path ? `${path}/${rowEntry.entry.name}` : rowEntry.entry.name;
return existingCat; return existingCat;
}); });
this._existingCategories = this._existingCategories.filter((existingCat) => this.categories.find((category) => existingCat.id === category.id) === undefined); this._existingCategories = this._existingCategories.filter(
(existingCat) => this.categories.find((category) => existingCat.id === category.id) === undefined
);
this.sortCategoriesList(this._existingCategories); this.sortCategoriesList(this._existingCategories);
this._existingCategoriesLoading = false; this._existingCategoriesLoading = false;
this._typing = false; this._typing = false;
@@ -294,7 +291,9 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
private getChildrenCategories(searchTerm: string) { private getChildrenCategories(searchTerm: string) {
this.categoryService.getSubcategories(this.parentId).subscribe((childrenCategories) => { this.categoryService.getSubcategories(this.parentId).subscribe((childrenCategories) => {
this._existingCategories = childrenCategories.list.entries.map((categoryEntry) => categoryEntry.entry); this._existingCategories = childrenCategories.list.entries.map((categoryEntry) => categoryEntry.entry);
this._existingCategories = this._existingCategories.filter((existingCat) => existingCat.name.toLowerCase().includes(searchTerm.toLowerCase())); this._existingCategories = this._existingCategories.filter((existingCat) =>
existingCat.name.toLowerCase().includes(searchTerm.toLowerCase())
);
this.sortCategoriesList(this._existingCategories); this.sortCategoriesList(this._existingCategories);
this._existingCategoriesLoading = false; this._existingCategoriesLoading = false;
this._typing = false; this._typing = false;
@@ -310,9 +309,11 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
private validateIfNotAlreadyCreated(nameControl: FormControl<string>): Observable<CategoryNameControlErrors | null> { private validateIfNotAlreadyCreated(nameControl: FormControl<string>): Observable<CategoryNameControlErrors | null> {
return this.existingCategoryLoaded$.pipe( return this.existingCategoryLoaded$.pipe(
map<void, CategoryNameControlErrors | null>(() => this.existingCategories.some((category) => this.compareCategories(category, nameControl.value)) && this.isCRUDMode map<void, CategoryNameControlErrors | null>(() =>
this.existingCategories.some((category) => this.compareCategories(category, nameControl.value)) && this.isCRUDMode
? { duplicatedExistingCategory: true } ? { duplicatedExistingCategory: true }
: null), : null
),
first() first()
); );
} }
@@ -322,9 +323,7 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy {
} }
private validateEmptyCategory(categoryNameControl: FormControl<string>): CategoryNameControlErrors | null { private validateEmptyCategory(categoryNameControl: FormControl<string>): CategoryNameControlErrors | null {
return categoryNameControl.value.length && !categoryNameControl.value.trim() return categoryNameControl.value.length && !categoryNameControl.value.trim() ? { emptyCategory: true } : null;
? { emptyCategory: true }
: null;
} }
private setCategoryNameControlErrorMessageKey() { private setCategoryNameControlErrorMessageKey() {

View File

@@ -9,9 +9,5 @@
& .adf-confirm-dialog-content { & .adf-confirm-dialog-content {
margin: 0 -24px; margin: 0 -24px;
p {
margin-bottom: 0;
}
} }
} }

View File

@@ -140,3 +140,4 @@ $mat-text-field-disabled: '.mdc-text-field--disabled';
$mat-form-field-focus-overlay: '.mat-mdc-form-field-focus-overlay'; $mat-form-field-focus-overlay: '.mat-mdc-form-field-focus-overlay';
$mat-form-field-error-wrapper: '.mat-mdc-form-field-error-wrapper'; $mat-form-field-error-wrapper: '.mat-mdc-form-field-error-wrapper';
$mat-text-field-textarea: '.mdc-text-field--textarea'; $mat-text-field-textarea: '.mdc-text-field--textarea';
$mat-list-item-disabled: '.mdc-list-item--disabled';