[AAE-15522] Fix - Dropdown variable error messages are displayed at modeling part 2 (#8734)

* Revert preview flag changes

* add get preview state method to form cloud service
This commit is contained in:
Tomasz Gnyp 2023-07-04 14:39:02 +02:00 committed by GitHub
parent b50b701da8
commit 0ffbf9fbe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 9 additions and 80 deletions

View File

@ -103,29 +103,6 @@ describe('FormFieldComponent', () => {
});
});
it('should set field preview state', () => {
const field = new FormFieldModel(form, {
type: FormFieldTypes.DROPDOWN,
id: 'FAKE-DROPDOWN-WIDGET'
});
component.field = field;
component.preview = true;
fixture.detectChanges();
expect(component.field.preview).toBe(true);
});
it('should field preview state be false as default', () => {
const field = new FormFieldModel(form, {
type: FormFieldTypes.DROPDOWN,
id: 'FAKE-DROPDOWN-WIDGET'
});
component.field = field;
fixture.detectChanges();
expect(component.field.preview).toBe(false);
});
it('should hide the field when it is not visible', (done) => {
const field = new FormFieldModel(form, {
type: FormFieldTypes.TEXT,

View File

@ -63,9 +63,6 @@ export class FormFieldComponent implements OnInit, OnDestroy {
@Input()
field: FormFieldModel = null;
@Input()
preview: boolean = false;
componentRef: ComponentRef<any>;
focus: boolean = false;
@ -83,7 +80,6 @@ export class FormFieldComponent implements OnInit, OnDestroy {
}
const originalField = this.getField();
if (originalField) {
this.setFieldPreviewState();
const customTemplate = this.field.form.customFieldTemplates[originalField.type];
if (customTemplate && this.hasController(originalField.type)) {
const factory = this.getComponentFactorySync(originalField.type, customTemplate);
@ -158,10 +154,6 @@ export class FormFieldComponent implements OnInit, OnDestroy {
return module.componentFactories.find((x) => x.componentType === decoratedCmp);
}
private setFieldPreviewState(): void {
this.field.preview = this.preview;
}
focusToggle() {
setTimeout(() => {
this.focus = !this.focus;

View File

@ -83,7 +83,6 @@ export class FormFieldModel extends FormWidgetModel {
groupsRestriction: string[];
leftLabels: boolean = false;
variableConfig: VariableConfig;
preview: boolean = false;
// container model members
numberOfColumns: number = 1;

View File

@ -90,7 +90,6 @@ export class FormModel implements ProcessFormModel {
isValid = true;
processVariables: ProcessVariableModel[] = [];
variables: FormVariableModel[] = [];
preview: boolean = false;
constructor(
json?: any,

View File

@ -1093,30 +1093,6 @@ describe('FormCloudComponent', () => {
expect(formComponent.disableSaveButton).toBeTrue();
});
it('should set form preview state', () => {
const formModel = new FormModel();
formComponent.form = formModel;
formComponent.preview = true;
formComponent.ngOnChanges({
preview: {
currentValue: true,
previousValue: undefined,
firstChange: false,
isFirstChange: () => false
}
});
expect(formComponent.form.preview).toBe(true);
});
it('should form preview state be false as default', () => {
const formModel = new FormModel();
formComponent.form = formModel;
fixture.detectChanges();
expect(formComponent.form.preview).toBe(false);
});
describe('form validations', () => {
it('should be able to set visibility conditions for Attach File widget', async () => {
spyOn(formCloudService, 'getForm').and.returnValue(of(conditionalUploadWidgetsMock));

View File

@ -82,9 +82,6 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
@Input()
fieldValidators: FormFieldValidator[] = [...FORM_FIELD_VALIDATORS];
@Input()
preview: boolean = false;
/** Emitted when the form is submitted with the `Save` or custom outcomes. */
@Output()
formSaved = new EventEmitter<FormModel>();
@ -179,10 +176,6 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
this.refreshFormData();
return;
}
if (changes?.preview?.currentValue) {
this.setFormPreviewState();
}
}
/**
@ -364,10 +357,6 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
this.onFormDataRefreshed(this.form);
}
private setFormPreviewState(): void {
this.form.preview = this.preview;
}
protected onFormLoaded(form: FormModel) {
this.formLoaded.emit(form);
}

View File

@ -1023,18 +1023,9 @@ describe('DropdownCloudWidgetComponent', () => {
expect(logServiceSpy).toHaveBeenCalledWith('variables.json-variable not found');
});
it('should NOT display errors if field is in the preview state', () => {
widget.field = getVariableDropdownWidget('variables.json-variable', 'response.wrongPath.players', 'playerId', 'playerFullName', mockProcessVariablesWithJson);
widget.field.preview = true;
fixture.detectChanges();
const failedErrorMsgElement = fixture.debugElement.query(By.css('.adf-dropdown-failed-message'));
expect(failedErrorMsgElement).toBeNull();
});
it('should NOT display errors if form is in the preview state', () => {
widget.field = getVariableDropdownWidget('variables.json-variable', 'response.wrongPath.players', 'playerId', 'playerFullName', mockProcessVariablesWithJson);
widget.field.form.preview = true;
spyOn(formCloudService, 'getPreviewState').and.returnValue(true);
fixture.detectChanges();
const failedErrorMsgElement = fixture.debugElement.query(By.css('.adf-dropdown-failed-message'));

View File

@ -375,12 +375,14 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
}
private setPreviewState(): void {
this.previewState = this.field?.form?.preview ||this.field?.preview;
this.previewState = this.formCloudService.getPreviewState();
}
private handleError(error: any) {
if (!this.previewState) {
this.logService.error(error);
}
}
isReadOnlyType(): boolean {
return this.field.type === 'readonly';

View File

@ -229,4 +229,8 @@ export class FormCloudService extends BaseCloudService implements FormCloudServi
}
return null;
}
getPreviewState(): boolean {
return false;
}
}