diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts
index eb7a37cfde..dd5f52dbc2 100644
--- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts
@@ -32,7 +32,7 @@ import {
RateLimits,
rateLimitsArrayToString,
stringToRateLimitsArray
-} from '@shared/models/rate-limits.models';
+} from './rate-limits.models';
import { isDefinedAndNotNull } from '@core/utils';
@Component({
@@ -68,17 +68,17 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator,
}
ngOnInit(): void {
- this.rateLimitsListFormGroup = this.fb.group({});
- this.rateLimitsListFormGroup.addControl('rateLimits',
- this.fb.array([]));
+ this.rateLimitsListFormGroup = this.fb.group({
+ rateLimits: this.fb.array([])
+ });
this.rateLimitsControl = this.fb.control(null);
- this.rateLimitsListFormGroup.valueChanges.subscribe((value) => {
+ this.valueChangeSubscription = this.rateLimitsListFormGroup.valueChanges.subscribe((value) => {
this.updateView(value?.rateLimits);
}
);
}
- rateLimitsFormArray(): FormArray {
+ get rateLimitsFormArray(): FormArray {
return this.rateLimitsListFormGroup.get('rateLimits') as FormArray;
}
@@ -107,16 +107,11 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator,
}
writeValue(value: string) {
- if (this.valueChangeSubscription) {
- this.valueChangeSubscription.unsubscribe();
- }
const rateLimitsControls: Array
= [];
if (value) {
let rateLimitsArray = value.split(',');
for (let i = 0; i < rateLimitsArray.length; i++) {
- let valueTime = rateLimitsArray[i].split(':');
- let value = valueTime[0];
- let time = valueTime[1];
+ const [value, time] = rateLimitsArray[i].split(':');
const rateLimitsControl = this.fb.group({
value: [value, [Validators.required]],
time: [time, [Validators.required]]
@@ -127,11 +122,8 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator,
rateLimitsControls.push(rateLimitsControl);
}
}
- this.rateLimitsListFormGroup.setControl('rateLimits', this.fb.array(rateLimitsControls));
+ this.rateLimitsListFormGroup.setControl('rateLimits', this.fb.array(rateLimitsControls), {emitEvent: false});
this.rateLimitsControl.patchValue(stringToRateLimitsArray(value), {emitEvent: false});
- this.valueChangeSubscription = this.rateLimitsListFormGroup.valueChanges.subscribe((value) => {
- this.updateView(value?.rateLimits);
- });
}
public removeRateLimits(index: number) {
@@ -139,17 +131,17 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator,
}
public addRateLimits() {
- const rateLimitsArray = this.rateLimitsListFormGroup.get('rateLimits') as FormArray;
- rateLimitsArray.push(this.fb.group({
+ this.rateLimitsFormArray.push(this.fb.group({
value: [null, [Validators.required]],
time: [null, [Validators.required]]
}));
- this.rateLimitsListFormGroup.updateValueAndValidity();
}
updateView(rateLimitsArray: Array) {
if (rateLimitsArray.length > 0) {
- const notNullRateLimits = rateLimitsArray.filter(rateLimits => isDefinedAndNotNull(rateLimits.value) && isDefinedAndNotNull(rateLimits.time));
+ const notNullRateLimits = rateLimitsArray.filter(rateLimits =>
+ isDefinedAndNotNull(rateLimits.value) && isDefinedAndNotNull(rateLimits.time)
+ );
const rateLimitsString = rateLimitsArrayToString(notNullRateLimits);
this.propagateChange(rateLimitsString);
this.rateLimitsControl.patchValue(stringToRateLimitsArray(rateLimitsString), {emitEvent: false});
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html
index 98a30b055e..077ede2e0b 100644
--- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html
+++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html
@@ -15,5 +15,5 @@
limitations under the License.
-->
-
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss
index a8f8f8553f..b78f1033bd 100644
--- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss
+++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss
@@ -20,14 +20,6 @@
&.disabled {
opacity: 0.7;
}
- &.required {
- color: #f44336;
- padding: 0 4px;
- }
- &.nowrap {
- white-space: nowrap;
- overflow: hidden;
- }
}
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts
index 9ab7e9b56b..604318d6fd 100644
--- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts
@@ -18,8 +18,7 @@ import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, FormBuilder, NG_VALUE_ACCESSOR } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { TranslateService } from '@ngx-translate/core';
-import { coerceBooleanProperty } from '@angular/cdk/coercion';
-import { RateLimits, rateLimitsArrayToHtml } from '@shared/models/rate-limits.models';
+import { RateLimits, rateLimitsArrayToHtml } from './rate-limits.models';
@Component({
selector: 'tb-rate-limits-text',
@@ -35,26 +34,11 @@ import { RateLimits, rateLimitsArrayToHtml } from '@shared/models/rate-limits.mo
})
export class RateLimitsTextComponent implements ControlValueAccessor, OnInit {
- private requiredValue: boolean;
- get required(): boolean {
- return this.requiredValue;
- }
- @Input()
- set required(value: boolean) {
- this.requiredValue = coerceBooleanProperty(value);
- }
-
@Input()
disabled: boolean;
- @Input()
noRateLimitsText = this.translate.instant('tenant-profile.rate-limits.not-set');
- @Input()
- nowrap = false;
-
- requiredClass = false;
-
public rateLimitsText: string;
private propagateChange = (v: any) => { };
@@ -83,15 +67,10 @@ export class RateLimitsTextComponent implements ControlValueAccessor, OnInit {
}
private updateText(value: Array) {
- this.requiredClass = false;
if (value && value.length) {
this.rateLimitsText = rateLimitsArrayToHtml(this.translate, value);
} else {
- if (this.required && !this.disabled) {
- this.requiredClass = true;
- } else {
- this.rateLimitsText = this.noRateLimitsText;
- }
+ this.rateLimitsText = this.noRateLimitsText;
}
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts
index 753ef133a9..dcf0403a22 100644
--- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts
@@ -34,7 +34,7 @@ import {
rateLimitsLabelTranslationMap,
RateLimitsType,
stringToRateLimitsArray
-} from '@shared/models/rate-limits.models';
+} from './rate-limits.models';
@Component({
selector: 'tb-rate-limits',
diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.models.ts
similarity index 100%
rename from ui-ngx/src/app/shared/models/rate-limits.models.ts
rename to ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.models.ts