refactor: enhance site dropdown component structure and improve template syntax

- Updated the HTML structure for better readability and maintainability.
- Replaced the ngFor syntax with a more concise @for syntax.
- Improved the conditional rendering syntax for loading state.
- Removed unused CommonModule import from the component.
This commit is contained in:
Denys Vuika
2026-02-27 13:05:51 +00:00
parent 478482b3b6
commit 4fc599522c
2 changed files with 30 additions and 29 deletions
@@ -13,14 +13,18 @@
placeholder="{{placeholder | translate}}" placeholder="{{placeholder | translate}}"
(selectionChange)="selectedSite($event)"> (selectionChange)="selectedSite($event)">
<mat-select-trigger class="adf-sites-dropdown-select-trigger"> <mat-select-trigger class="adf-sites-dropdown-select-trigger">
{{ selected?.entry.title | translate}} {{ selected?.entry?.title | translate}}
</mat-select-trigger> </mat-select-trigger>
<mat-option *ngFor="let site of siteList?.list.entries;" [value]="site"> @for (site of siteList?.list?.entries; track site?.entry?.id) {
<mat-option [value]="site">
{{ site.entry.title | translate}} {{ site.entry.title | translate}}
</mat-option> </mat-option>
<mat-option *ngIf="showLoading()" disabled="true" data-automation-id="site-loading"> }
@if (showLoading()) {
<mat-option disabled="true" data-automation-id="site-loading">
{{ 'ADF_DROPDOWN.LOADING' | translate}} {{ 'ADF_DROPDOWN.LOADING' | translate}}
</mat-option> </mat-option>
}
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
</div> </div>
@@ -22,11 +22,8 @@ import { MatSelectChange, MatSelectModule } from '@angular/material/select';
import { LiveAnnouncer } from '@angular/cdk/a11y'; import { LiveAnnouncer } from '@angular/cdk/a11y';
import { TranslatePipe, TranslateService } from '@ngx-translate/core'; import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { SitesService } from '../../common/services/sites.service'; import { SitesService } from '../../common/services/sites.service';
import { CommonModule } from '@angular/common';
import { MatFormFieldModule } from '@angular/material/form-field';
/* eslint-disable no-shadow */ import { MatFormFieldModule } from '@angular/material/form-field';
/* eslint-disable @typescript-eslint/naming-convention */
export const Relations = { export const Relations = {
Members: 'members', Members: 'members',
@@ -37,7 +34,7 @@ export type Relations = (typeof Relations)[keyof typeof Relations];
@Component({ @Component({
selector: 'adf-sites-dropdown', selector: 'adf-sites-dropdown',
imports: [CommonModule, TranslatePipe, MatFormFieldModule, MatSelectModule, InfiniteSelectScrollDirective], imports: [TranslatePipe, MatFormFieldModule, MatSelectModule, InfiniteSelectScrollDirective],
templateUrl: './sites-dropdown.component.html', templateUrl: './sites-dropdown.component.html',
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
host: { class: 'adf-sites-dropdown' } host: { class: 'adf-sites-dropdown' }