Browse Source

Merge pull request #12023 from maxunbearable/fix/4175-metadata-not-required

Made value not required property in Rule Node
pull/12089/head
Andrew Shvayka 2 years ago
committed by GitHub
parent
commit
895eb79845
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.html
  2. 2
      ui-ngx/src/app/shared/components/kv-map.component.html
  3. 27
      ui-ngx/src/app/shared/components/kv-map.component.ts

1
ui-ngx/src/app/shared/components/dialog/node-script-test-dialog.component.html

@ -62,6 +62,7 @@
<tb-key-val-map <tb-key-val-map
subscriptSizing="dynamic" subscriptSizing="dynamic"
formControlName="metadata" formControlName="metadata"
[isValueRequired]="false"
titleText="rulenode.metadata"> titleText="rulenode.metadata">
</tb-key-val-map> </tb-key-val-map>
</div> </div>

2
ui-ngx/src/app/shared/components/kv-map.component.html

@ -25,7 +25,7 @@
placeholder="{{ (keyPlaceholderText ? keyPlaceholderText : 'key-val.key') | translate }}"/> placeholder="{{ (keyPlaceholderText ? keyPlaceholderText : 'key-val.key') | translate }}"/>
</mat-form-field> </mat-form-field>
<mat-form-field class="mat-block flex-1" subscriptSizing="{{ subscriptSizing }}"> <mat-form-field class="mat-block flex-1" subscriptSizing="{{ subscriptSizing }}">
<input [formControl]="keyValControl.get('value')" matInput required <input [formControl]="keyValControl.get('value')" matInput [required]="isValueRequired"
placeholder="{{ (valuePlaceholderText ? valuePlaceholderText : 'key-val.value') | translate }}"/> placeholder="{{ (valuePlaceholderText ? valuePlaceholderText : 'key-val.value') | translate }}"/>
</mat-form-field> </mat-form-field>
<button mat-icon-button color="primary" <button mat-icon-button color="primary"

27
ui-ngx/src/app/shared/components/kv-map.component.ts

@ -20,12 +20,12 @@ import {
ControlValueAccessor, ControlValueAccessor,
UntypedFormArray, UntypedFormArray,
UntypedFormBuilder, UntypedFormBuilder,
UntypedFormControl,
UntypedFormGroup, UntypedFormGroup,
NG_VALIDATORS, NG_VALIDATORS,
NG_VALUE_ACCESSOR, NG_VALUE_ACCESSOR,
Validator, Validator,
Validators Validators,
ValidationErrors
} from '@angular/forms'; } from '@angular/forms';
import { PageComponent } from '@shared/components/page.component'; import { PageComponent } from '@shared/components/page.component';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@ -33,6 +33,7 @@ import { AppState } from '@core/core.state';
import { SubscriptSizing } from '@angular/material/form-field'; import { SubscriptSizing } from '@angular/material/form-field';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-key-val-map', selector: 'tb-key-val-map',
@ -55,6 +56,8 @@ export class KeyValMapComponent extends PageComponent implements ControlValueAcc
@Input() disabled: boolean; @Input() disabled: boolean;
@Input() @coerceBoolean() isValueRequired = true;
@Input() titleText: string; @Input() titleText: string;
@Input() keyPlaceholderText: string; @Input() keyPlaceholderText: string;
@ -118,7 +121,7 @@ export class KeyValMapComponent extends PageComponent implements ControlValueAcc
if (Object.prototype.hasOwnProperty.call(keyValMap, property)) { if (Object.prototype.hasOwnProperty.call(keyValMap, property)) {
keyValsControls.push(this.fb.group({ keyValsControls.push(this.fb.group({
key: [property, [Validators.required]], key: [property, [Validators.required]],
value: [keyValMap[property], [Validators.required]] value: [keyValMap[property], this.isValueRequired ? [Validators.required] : []]
})); }));
} }
} }
@ -139,24 +142,12 @@ export class KeyValMapComponent extends PageComponent implements ControlValueAcc
const keyValsFormArray = this.kvListFormGroup.get('keyVals') as UntypedFormArray; const keyValsFormArray = this.kvListFormGroup.get('keyVals') as UntypedFormArray;
keyValsFormArray.push(this.fb.group({ keyValsFormArray.push(this.fb.group({
key: ['', [Validators.required]], key: ['', [Validators.required]],
value: ['', [Validators.required]] value: ['', this.isValueRequired ? [Validators.required] : []]
})); }));
} }
public validate(c: UntypedFormControl) { public validate(): ValidationErrors | null {
const kvList: {key: string; value: string}[] = this.kvListFormGroup.get('keyVals').value; return this.kvListFormGroup.valid ? null : { keyVals: { valid: false } };
let valid = true;
for (const entry of kvList) {
if (!entry.key || !entry.value) {
valid = false;
break;
}
}
return (valid) ? null : {
keyVals: {
valid: false,
},
};
} }
private updateModel() { private updateModel() {

Loading…
Cancel
Save