From 1c11b30eacb43589eb258a3941a6f588d6b40765 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 28 Mar 2025 15:11:45 +0200 Subject: [PATCH 1/2] UI: Fix incorrect datasource type switching behavior in map settings when 'keys' field is not set --- .../map/map-data-layer-dialog.component.ts | 28 +++++-------------- .../map/map-data-layer-row.component.ts | 26 ++++------------- .../map/map-data-source-row.component.ts | 19 ++----------- .../shared/models/widget/maps/map.models.ts | 15 ++++++++++ 4 files changed, 30 insertions(+), 58 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-data-layer-dialog.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-data-layer-dialog.component.ts index dc0123406a..ae752ebca7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-data-layer-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-data-layer-dialog.component.ts @@ -31,7 +31,8 @@ import { pathDecoratorSymbolTranslationMap, PolygonsDataLayerSettings, ShapeDataLayerSettings, - TripsDataLayerSettings + TripsDataLayerSettings, + updateDataKeyToNewDsType } from '@shared/models/widget/maps/map.models'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; @@ -293,23 +294,23 @@ export class MapDataLayerDialogComponent extends DialogComponent { + if (newDsType === DatasourceType.function) { + if (dataKey && dataKey.type !== DataKeyType.function) { + dataKey.type = DataKeyType.function; + return true; + } + } else { + if (dataKey?.type === DataKeyType.function) { + dataKey.type = timeSeries ? DataKeyType.timeseries : DataKeyType.attribute; + return true; + } + } + return false; +} + export const mergeMapDatasources = (target: TbMapDatasource[], source: TbMapDatasource[]): TbMapDatasource[] => { const appendDatasources: TbMapDatasource[] = []; for (const sourceDs of source) { From 7f5b88f5f0b28d1f9cd5546315a2585c3df7ca73 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Mon, 31 Mar 2025 17:35:52 +0300 Subject: [PATCH 2/2] 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) {