UI: Minor fixes

This commit is contained in:
Igor Kulikov 2023-11-09 10:35:06 +02:00
parent a8947eae9e
commit 4286ee8bf6
5 changed files with 17 additions and 6 deletions

View File

@ -69,9 +69,11 @@ import { coerceBoolean } from '@shared/decorators/coercion';
import { alarmFields } from '@shared/models/alarm.models';
import { UtilsService } from '@core/services/utils.service';
export const dataKeyValid = (key: DataKey): boolean => !!key && !!key.type && !!key.name;
export const dataKeyRowValidator = (control: AbstractControl): ValidationErrors | null => {
const dataKey: DataKey = control.value;
if (!dataKey || !dataKey.type || !dataKey.name) {
if (!dataKeyValid(dataKey)) {
return {
dataKey: true
};

View File

@ -38,7 +38,7 @@ import {
import { MatDialog } from '@angular/material/dialog';
import { WidgetConfigComponent } from '@home/components/widget/widget-config.component';
import { DataKey, DatasourceType, JsonSettingsSchema, widgetType } from '@shared/models/widget.models';
import { dataKeyRowValidator } from '@home/components/widget/config/basic/common/data-key-row.component';
import { dataKeyRowValidator, dataKeyValid } from '@home/components/widget/config/basic/common/data-key-row.component';
import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
import { UtilsService } from '@core/services/utils.service';
@ -168,7 +168,13 @@ export class DataKeysPanelComponent implements ControlValueAccessor, OnInit, OnC
keys: [this.fb.array([]), []]
});
this.keysListFormGroup.valueChanges.subscribe(
(val) => this.propagateChange(this.keysListFormGroup.get('keys').value)
() => {
let keys: DataKey[] = this.keysListFormGroup.get('keys').value;
if (keys) {
keys = keys.filter(k => dataKeyValid(k));
}
this.propagateChange(keys);
}
);
this.updateParams();
}

View File

@ -263,7 +263,7 @@ export class DatasourceComponent implements ControlValueAccessor, OnInit, Valida
}
public isDataKeysOptional(type?: DatasourceType): boolean {
if (this.hasAdditionalLatestDataKeys) {
if (this.hasAdditionalLatestDataKeys || this.hideDataKeys) {
return true;
} else {
return this.dataKeysOptional

View File

@ -424,6 +424,9 @@ export class DoughnutWidgetComponent implements OnInit, OnDestroy, AfterViewInit
if (this.settings.showTooltip) {
this.doughnutOptions.series[0].tooltip = {
formatter: (params) => {
if (!params.name) {
return null;
}
let value: string;
if (this.settings.tooltipValueType === DoughnutTooltipValueType.percentage) {
const percents = params.value / this.total * 100;

View File

@ -426,8 +426,8 @@ export const datasourcesHasOnlyComparisonAggregation = (datasources?: Array<Data
}
if (datasources) {
const foundDatasource = datasources.find(datasource => {
const found = datasource.dataKeys && datasource.dataKeys.find(key => key.type === DataKeyType.timeseries &&
key.aggregationType && key.aggregationType !== AggregationType.NONE && !key.comparisonEnabled);
const found = datasource.dataKeys && datasource.dataKeys.find(key => key?.type === DataKeyType.timeseries &&
key?.aggregationType && key.aggregationType !== AggregationType.NONE && !key.comparisonEnabled);
return !!found;
});
if (foundDatasource) {