From 98c91187ae5b8a21598e63cd5ceb271757e322b3 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Wed, 2 Apr 2025 15:46:29 +0300 Subject: [PATCH] UI: Refactoring for error --- .../common/map/map-settings.component.html | 8 ++++---- .../components/toggle-header.component.html | 2 +- .../components/toggle-header.component.ts | 20 ++++++++----------- .../assets/locale/locale.constant-en_US.json | 6 +++--- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.html index de3a3aa66c..fe2afa3b19 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.html @@ -41,10 +41,10 @@ - {{ 'widgets.maps.overlays.trips' | translate }} - {{ 'widgets.maps.overlays.markers' | translate }} - {{ 'widgets.maps.overlays.polygons' | translate }} - {{ 'widgets.maps.overlays.circles' | translate }} + {{ 'widgets.maps.overlays.trips' | translate }} + {{ 'widgets.maps.overlays.markers' | translate }} + {{ 'widgets.maps.overlays.polygons' | translate }} + {{ 'widgets.maps.overlays.circles' | translate }} warning diff --git a/ui-ngx/src/app/shared/components/toggle-header.component.ts b/ui-ngx/src/app/shared/components/toggle-header.component.ts index 4d3e56bd0f..3058ad285d 100644 --- a/ui-ngx/src/app/shared/components/toggle-header.component.ts +++ b/ui-ngx/src/app/shared/components/toggle-header.component.ts @@ -46,13 +46,12 @@ import { coerceBoolean } from '@shared/decorators/coercion'; import { startWith, takeUntil } from 'rxjs/operators'; import { Platform } from '@angular/cdk/platform'; import { MatButtonToggle, MatButtonToggleGroup } from '@angular/material/button-toggle'; -import { isDefinedAndNotNull } from '@core/utils'; +import { isDefined } from '@core/utils'; export interface ToggleHeaderOption { name: string; value: any; - error?: boolean; - errorText?: any; + error?: string; } export type ToggleHeaderAppearance = 'fill' | 'fill-invert' | 'stroked'; @@ -70,11 +69,9 @@ export class ToggleOption implements OnChanges { @Input() value: any; - @Input() error: boolean; + @Input() error: string; - @Input() errorText: any; - - @Output() errorChange = new EventEmitter(); + @Output() errorChange = new EventEmitter(); get viewValue(): string { return (this._element?.nativeElement.textContent || '').trim(); @@ -85,8 +82,8 @@ export class ToggleOption implements OnChanges { ) {} ngOnChanges(changes: SimpleChanges) { - if (changes['error']) { - if (!changes['error'].firstChange && changes['error'].currentValue !== changes['error'].previousValue) { + if (changes?.error) { + if (!changes.error.firstChange && changes.error.currentValue !== changes.error.previousValue) { this.errorChange.emit(this.error); } } @@ -121,7 +118,7 @@ export abstract class _ToggleBase extends PageComponent implements AfterContentI private subscribeToToggleOptions() { this.toggleOptions.forEach(option => { - if (isDefinedAndNotNull(option.error) || isDefinedAndNotNull(option.errorText)) { + if (isDefined(option.error)) { option.errorChange.pipe(takeUntil(this._destroyed)).subscribe(() => { this.syncToggleHeaderOptions(); }); @@ -137,8 +134,7 @@ export abstract class _ToggleBase extends PageComponent implements AfterContentI { name: option.viewValue, value: option.value, - error: option.error, - errorText: option.errorText + error: option.error } ); }); diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 7c5eae3f75..608bb0917a 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1137,7 +1137,8 @@ "key-required": "Key is required.", "key-pattern": "Key is invalid.", "key-max-length": "Key should be less than 256 characters." - } + }, + "required-fields": "Missing required fields" }, "content-type": { "json": "Json", @@ -7980,8 +7981,7 @@ "trips": "Trips", "markers": "Markers", "polygons": "Polygons", - "circles": "Circles", - "required-fields": "Required fields are not filled in." + "circles": "Circles" }, "data-layer": { "source": "Source",