Browse Source

Merge pull request #8503 from vvlladd28/bug/widget-config/change-datasource-type

Fixed incorrect updated dataSource validator when changing dataSource type
pull/8506/head
Igor Kulikov 3 years ago
committed by GitHub
parent
commit
762412f964
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ui-ngx/src/app/modules/home/components/widget/widget-config.component.html
  2. 8
      ui-ngx/src/app/modules/home/components/widget/widget-config.component.ts

2
ui-ngx/src/app/modules/home/components/widget/widget-config.component.html

@ -156,7 +156,7 @@
[widgetType]="widgetType" [widgetType]="widgetType"
[datasourceType]="datasourceControl.get('type').value" [datasourceType]="datasourceControl.get('type').value"
[maxDataKeys]="modelValue?.typeParameters?.maxDataKeys" [maxDataKeys]="modelValue?.typeParameters?.maxDataKeys"
[optDataKeys]="dataKeysOptional(datasourceControl.value)" [optDataKeys]="dataKeysOptional(datasourceControl.get('type').value)"
[aliasController]="aliasController" [aliasController]="aliasController"
[datakeySettingsSchema]="modelValue?.dataKeySettingsSchema" [datakeySettingsSchema]="modelValue?.dataKeySettingsSchema"
[dataKeySettingsDirective]="modelValue?.dataKeySettingsDirective" [dataKeySettingsDirective]="modelValue?.dataKeySettingsDirective"

8
ui-ngx/src/app/modules/home/components/widget/widget-config.component.ts

@ -538,17 +538,17 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont
} }
} }
public dataKeysOptional(datasource?: Datasource): boolean { public dataKeysOptional(type?: DatasourceType): boolean {
if (this.widgetType === widgetType.timeseries && this.modelValue?.typeParameters?.hasAdditionalLatestDataKeys) { if (this.widgetType === widgetType.timeseries && this.modelValue?.typeParameters?.hasAdditionalLatestDataKeys) {
return true; return true;
} else { } else {
return this.modelValue.typeParameters && this.modelValue.typeParameters.dataKeysOptional return this.modelValue.typeParameters && this.modelValue.typeParameters.dataKeysOptional
&& datasource?.type !== DatasourceType.entityCount && datasource?.type !== DatasourceType.alarmCount; && type !== DatasourceType.entityCount && type !== DatasourceType.alarmCount;
} }
} }
private buildDatasourceForm(datasource?: Datasource): UntypedFormGroup { private buildDatasourceForm(datasource?: Datasource): UntypedFormGroup {
const dataKeysRequired = !this.dataKeysOptional(datasource); const dataKeysRequired = !this.dataKeysOptional(datasource?.type);
const datasourceFormGroup = this.fb.group( const datasourceFormGroup = this.fb.group(
{ {
type: [datasource ? datasource.type : null, [Validators.required]], type: [datasource ? datasource.type : null, [Validators.required]],
@ -569,7 +569,7 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont
datasourceFormGroup.get('entityAliasId').setValidators( datasourceFormGroup.get('entityAliasId').setValidators(
(type === DatasourceType.entity || type === DatasourceType.entityCount) ? [Validators.required] : [] (type === DatasourceType.entity || type === DatasourceType.entityCount) ? [Validators.required] : []
); );
const newDataKeysRequired = !this.dataKeysOptional(datasourceFormGroup.value); const newDataKeysRequired = !this.dataKeysOptional(type);
datasourceFormGroup.get('dataKeys').setValidators(newDataKeysRequired ? [Validators.required] : []); datasourceFormGroup.get('dataKeys').setValidators(newDataKeysRequired ? [Validators.required] : []);
datasourceFormGroup.get('entityAliasId').updateValueAndValidity(); datasourceFormGroup.get('entityAliasId').updateValueAndValidity();
datasourceFormGroup.get('dataKeys').updateValueAndValidity(); datasourceFormGroup.get('dataKeys').updateValueAndValidity();

Loading…
Cancel
Save