From 7f5b88f5f0b28d1f9cd5546315a2585c3df7ca73 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Mon, 31 Mar 2025 17:35:52 +0300 Subject: [PATCH] UI: Fixed AdditionalMapDataSourceRowComponent duplicate code --- ...dditional-map-data-source-row.component.ts | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/additional-map-data-source-row.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/additional-map-data-source-row.component.ts index 0957d991f5..60adb60cb7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/additional-map-data-source-row.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/additional-map-data-source-row.component.ts @@ -33,7 +33,7 @@ import { Validators } from '@angular/forms'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { AdditionalMapDataSourceSettings } from '@shared/models/widget/maps/map.models'; +import { AdditionalMapDataSourceSettings, updateDataKeyToNewDsType } from '@shared/models/widget/maps/map.models'; import { DataKey, DatasourceType, datasourceTypeTranslationMap, widgetType } from '@shared/models/widget.models'; import { EntityType } from '@shared/models/entity-type.models'; import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; @@ -156,7 +156,7 @@ export class AdditionalMapDataSourceRowComponent implements ControlValueAccessor const dataKeys: DataKey[] = this.dataSourceFormGroup.get('dataKeys').value; if (dataKeys?.length) { for (const key of dataKeys) { - updateModel = this.updateDataKeyToNewDsType(key, newDsType) || updateModel; + updateModel = updateDataKeyToNewDsType(key, newDsType) || updateModel; } if (updateModel) { this.dataSourceFormGroup.get('dataKeys').patchValue(dataKeys, {emitEvent: false}); @@ -168,21 +168,6 @@ export class AdditionalMapDataSourceRowComponent implements ControlValueAccessor } } - private updateDataKeyToNewDsType(dataKey: DataKey, newDsType: DatasourceType): boolean { - if (newDsType === DatasourceType.function) { - if (dataKey.type !== DataKeyType.function) { - dataKey.type = DataKeyType.function; - return true; - } - } else { - if (dataKey.type === DataKeyType.function) { - dataKey.type = DataKeyType.attribute; - return true; - } - } - return false; - } - private updateValidators() { const dsType: DatasourceType = this.dataSourceFormGroup.get('dsType').value; if (dsType === DatasourceType.function) {