Browse Source

Change attribute dialog UntypedFormGroup to FormGroup, simplified if statement on add

pull/9003/head
rusikv 3 years ago
parent
commit
41b0949046
  1. 11
      ui-ngx/src/app/modules/home/components/attribute/add-attribute-dialog.component.ts
  2. 2
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html
  3. 1
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts

11
ui-ngx/src/app/modules/home/components/attribute/add-attribute-dialog.component.ts

@ -19,7 +19,7 @@ import { ErrorStateMatcher } from '@angular/material/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { FormGroupDirective, NgForm, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { EntityId } from '@shared/models/id/entity-id';
import { Router } from '@angular/router';
import { DialogComponent } from '@app/shared/components/dialog.component';
@ -41,7 +41,7 @@ export interface AddAttributeDialogData {
export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDialogComponent, boolean>
implements OnInit, ErrorStateMatcher {
attributeFormGroup: UntypedFormGroup;
attributeFormGroup: FormGroup;
submitted = false;
@ -53,7 +53,7 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
private attributeService: AttributeService,
@SkipSelf() private errorStateMatcher: ErrorStateMatcher,
public dialogRef: MatDialogRef<AddAttributeDialogComponent, boolean>,
public fb: UntypedFormBuilder) {
public fb: FormBuilder) {
super(store, router, dialogRef);
}
@ -66,7 +66,7 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
'attribute.add-telemetry' : 'attribute.add'
}
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const originalErrorState = this.errorStateMatcher.isErrorState(control, form);
const customErrorState = !!(control && control.invalid && this.submitted);
return originalErrorState || customErrorState;
@ -87,8 +87,7 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
if (this.data.attributeScope === LatestTelemetry.LATEST_TELEMETRY) {
task = this.attributeService.saveEntityTimeseries(this.data.entityId,
this.data.attributeScope, [attribute]);
}
if (this.data.attributeScope in AttributeScope) {
} else {
task = this.attributeService.saveEntityAttributes(this.data.entityId,
this.data.attributeScope as AttributeScope, [attribute]);
}

2
ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html

@ -34,7 +34,7 @@
</div>
<span fxFlex></span>
<button mat-icon-button
*ngIf="!isClientSideTelemetryTypeMap.get(attributeScope) || attributeScope === latestTelemetryTypes.LATEST_TELEMETRY"
*ngIf="attributeScope !== attributeScopeTypes.CLIENT_SCOPE"
[disabled]="isLoading$ | async"
(click)="addAttribute($event)"
matTooltip="{{ 'action.add' | translate }}"

1
ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts

@ -100,6 +100,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
isClientSideTelemetryTypeMap = isClientSideTelemetryType;
latestTelemetryTypes = LatestTelemetry;
attributeScopeTypes = AttributeScope;
mode: 'default' | 'widget' = 'default';

Loading…
Cancel
Save