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 { alarmFields } from '@shared/models/alarm.models';
import { UtilsService } from '@core/services/utils.service'; 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 => { export const dataKeyRowValidator = (control: AbstractControl): ValidationErrors | null => {
const dataKey: DataKey = control.value; const dataKey: DataKey = control.value;
if (!dataKey || !dataKey.type || !dataKey.name) { if (!dataKeyValid(dataKey)) {
return { return {
dataKey: true dataKey: true
}; };

View File

@ -38,7 +38,7 @@ import {
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { WidgetConfigComponent } from '@home/components/widget/widget-config.component'; import { WidgetConfigComponent } from '@home/components/widget/widget-config.component';
import { DataKey, DatasourceType, JsonSettingsSchema, widgetType } from '@shared/models/widget.models'; 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 { CdkDragDrop } from '@angular/cdk/drag-drop';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
import { UtilsService } from '@core/services/utils.service'; import { UtilsService } from '@core/services/utils.service';
@ -168,7 +168,13 @@ export class DataKeysPanelComponent implements ControlValueAccessor, OnInit, OnC
keys: [this.fb.array([]), []] keys: [this.fb.array([]), []]
}); });
this.keysListFormGroup.valueChanges.subscribe( 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(); this.updateParams();
} }

View File

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

View File

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

View File

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