[ACS-8824] Disable node properties save button if values are invalid (#10560)

* [ACS-8824] Disable node properties save button if values are invalid

* [ACS-8824] remove commented code

* [ACS-8824] unit tests [ci:force]

* [ACS-8824] cr fixes
This commit is contained in:
Mykyta Maliarchuk
2025-01-28 15:49:32 +01:00
committed by GitHub
parent 1634716bbe
commit eaa1008018
7 changed files with 160 additions and 34 deletions

View File

@@ -505,7 +505,7 @@ describe('CardViewTextItemComponent', () => {
await fixture.whenStable();
expect(itemUpdatedSpy).toHaveBeenCalledWith({
target: { ...component.property },
target: { ...component.property, isValidValue: true },
changed: {
textkey: expectedText
}
@@ -580,11 +580,11 @@ describe('CardViewTextItemComponent', () => {
await updateTextField(component.property.key, 'updated-value');
await fixture.whenStable();
const property = { ...component.property };
const property = { ...component.property, isValidValue: true };
expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, 'updated-value');
});
it('should NOT trigger the update event if the editedValue is invalid', async () => {
it('should trigger the update event if the editedValue is NOT valid', async () => {
const cardViewUpdateService = TestBed.inject(CardViewUpdateService);
spyOn(cardViewUpdateService, 'update');
component.property.isValid = () => false;
@@ -592,7 +592,8 @@ describe('CardViewTextItemComponent', () => {
await updateTextField(component.property.key, '@invalid-value');
await fixture.whenStable();
expect(cardViewUpdateService.update).not.toHaveBeenCalled();
const property = { ...component.property, isValidValue: false };
expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, '@invalid-value');
});
it('should trigger the update event if the editedValue is valid', async () => {
@@ -666,7 +667,7 @@ describe('CardViewTextItemComponent', () => {
await fixture.whenStable();
expect(itemUpdatedSpy).toHaveBeenCalledWith({
target: { ...component.property },
target: { ...component.property, isValidValue: true },
changed: {
textkey: expectedText
}
@@ -711,7 +712,7 @@ describe('CardViewTextItemComponent', () => {
await fixture.whenStable();
expect(itemUpdatedSpy).toHaveBeenCalledWith({
target: { ...component.property },
target: { ...component.property, isValidValue: true },
changed: {
textkey: expectedText
}
@@ -826,7 +827,7 @@ describe('CardViewTextItemComponent', () => {
await fixture.whenStable();
expect(itemUpdatedSpy).toHaveBeenCalledWith({
target: { ...component.property },
target: { ...component.property, isValidValue: true },
changed: {
textkey: expectedNumber.toString()
}
@@ -882,7 +883,7 @@ describe('CardViewTextItemComponent', () => {
await fixture.whenStable();
expect(itemUpdatedSpy).toHaveBeenCalledWith({
target: { ...component.property },
target: { ...component.property, isValidValue: true },
changed: {
textkey: expectedNumber.toString()
}

View File

@@ -15,16 +15,7 @@
* limitations under the License.
*/
import {
ChangeDetectorRef,
Component,
DestroyRef,
inject,
Input,
OnChanges,
SimpleChanges,
ViewEncapsulation
} from '@angular/core';
import { ChangeDetectorRef, Component, DestroyRef, inject, Input, OnChanges, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
import { BaseCardView } from '../base-card-view';
import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips';
@@ -91,7 +82,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
errors: CardViewItemValidator[];
templateType: string;
textInput = new UntypedFormControl();
private readonly destroyRef = inject(DestroyRef);
constructor(private clipboardService: ClipboardService, private translateService: TranslationService, private cd: ChangeDetectorRef) {
@@ -158,9 +149,10 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
this.resetErrorMessages();
if (this.property.isValid(this.editedValue)) {
this.property.value = this.prepareValueForUpload(this.property, this.editedValue);
this.cardViewUpdateService.update({ ...this.property } as CardViewTextItemModel, this.property.value);
this.cardViewUpdateService.update({ ...this.property, isValidValue: true } as CardViewTextItemModel, this.property.value);
} else {
this.errors = this.property.getValidationErrors(this.editedValue);
this.cardViewUpdateService.update({ ...this.property, isValidValue: false } as CardViewTextItemModel, this.editedValue);
}
}
}

View File

@@ -31,6 +31,7 @@ export abstract class CardViewBaseItemModel<T = any> {
data?: any;
type?: string;
multivalued?: boolean;
isValidValue?: boolean;
constructor(props: CardViewItemProperties) {
this.label = props.label || '';