mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-15522] Fix - Dropdown variable error messages are displayed at modeling level (#8730)
This commit is contained in:
@@ -103,6 +103,29 @@ 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) => {
|
it('should hide the field when it is not visible', (done) => {
|
||||||
const field = new FormFieldModel(form, {
|
const field = new FormFieldModel(form, {
|
||||||
type: FormFieldTypes.TEXT,
|
type: FormFieldTypes.TEXT,
|
||||||
|
@@ -63,6 +63,9 @@ export class FormFieldComponent implements OnInit, OnDestroy {
|
|||||||
@Input()
|
@Input()
|
||||||
field: FormFieldModel = null;
|
field: FormFieldModel = null;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
preview: boolean = false;
|
||||||
|
|
||||||
componentRef: ComponentRef<any>;
|
componentRef: ComponentRef<any>;
|
||||||
|
|
||||||
focus: boolean = false;
|
focus: boolean = false;
|
||||||
@@ -80,6 +83,7 @@ export class FormFieldComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
const originalField = this.getField();
|
const originalField = this.getField();
|
||||||
if (originalField) {
|
if (originalField) {
|
||||||
|
this.setFieldPreviewState();
|
||||||
const customTemplate = this.field.form.customFieldTemplates[originalField.type];
|
const customTemplate = this.field.form.customFieldTemplates[originalField.type];
|
||||||
if (customTemplate && this.hasController(originalField.type)) {
|
if (customTemplate && this.hasController(originalField.type)) {
|
||||||
const factory = this.getComponentFactorySync(originalField.type, customTemplate);
|
const factory = this.getComponentFactorySync(originalField.type, customTemplate);
|
||||||
@@ -154,6 +158,10 @@ export class FormFieldComponent implements OnInit, OnDestroy {
|
|||||||
return module.componentFactories.find((x) => x.componentType === decoratedCmp);
|
return module.componentFactories.find((x) => x.componentType === decoratedCmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setFieldPreviewState(): void {
|
||||||
|
this.field.preview = this.preview;
|
||||||
|
}
|
||||||
|
|
||||||
focusToggle() {
|
focusToggle() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.focus = !this.focus;
|
this.focus = !this.focus;
|
||||||
|
@@ -83,6 +83,7 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
groupsRestriction: string[];
|
groupsRestriction: string[];
|
||||||
leftLabels: boolean = false;
|
leftLabels: boolean = false;
|
||||||
variableConfig: VariableConfig;
|
variableConfig: VariableConfig;
|
||||||
|
preview: boolean = false;
|
||||||
|
|
||||||
// container model members
|
// container model members
|
||||||
numberOfColumns: number = 1;
|
numberOfColumns: number = 1;
|
||||||
|
@@ -90,6 +90,7 @@ export class FormModel implements ProcessFormModel {
|
|||||||
isValid = true;
|
isValid = true;
|
||||||
processVariables: ProcessVariableModel[] = [];
|
processVariables: ProcessVariableModel[] = [];
|
||||||
variables: FormVariableModel[] = [];
|
variables: FormVariableModel[] = [];
|
||||||
|
preview: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
json?: any,
|
json?: any,
|
||||||
|
@@ -1093,6 +1093,30 @@ describe('FormCloudComponent', () => {
|
|||||||
expect(formComponent.disableSaveButton).toBeTrue();
|
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', () => {
|
describe('form validations', () => {
|
||||||
it('should be able to set visibility conditions for Attach File widget', async () => {
|
it('should be able to set visibility conditions for Attach File widget', async () => {
|
||||||
spyOn(formCloudService, 'getForm').and.returnValue(of(conditionalUploadWidgetsMock));
|
spyOn(formCloudService, 'getForm').and.returnValue(of(conditionalUploadWidgetsMock));
|
||||||
|
@@ -82,6 +82,9 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
@Input()
|
@Input()
|
||||||
fieldValidators: FormFieldValidator[] = [...FORM_FIELD_VALIDATORS];
|
fieldValidators: FormFieldValidator[] = [...FORM_FIELD_VALIDATORS];
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
preview: boolean = false;
|
||||||
|
|
||||||
/** Emitted when the form is submitted with the `Save` or custom outcomes. */
|
/** Emitted when the form is submitted with the `Save` or custom outcomes. */
|
||||||
@Output()
|
@Output()
|
||||||
formSaved = new EventEmitter<FormModel>();
|
formSaved = new EventEmitter<FormModel>();
|
||||||
@@ -176,6 +179,10 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
this.refreshFormData();
|
this.refreshFormData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changes?.preview?.currentValue) {
|
||||||
|
this.setFormPreviewState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -357,6 +364,10 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
this.onFormDataRefreshed(this.form);
|
this.onFormDataRefreshed(this.form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setFormPreviewState(): void {
|
||||||
|
this.form.preview = this.preview;
|
||||||
|
}
|
||||||
|
|
||||||
protected onFormLoaded(form: FormModel) {
|
protected onFormLoaded(form: FormModel) {
|
||||||
this.formLoaded.emit(form);
|
this.formLoaded.emit(form);
|
||||||
}
|
}
|
||||||
|
@@ -32,12 +32,14 @@
|
|||||||
<mat-option id="readonlyOption" *ngIf="isReadOnlyType()" [value]="field.value">{{field.value}}</mat-option>
|
<mat-option id="readonlyOption" *ngIf="isReadOnlyType()" [value]="field.value">{{field.value}}</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<error-widget [error]="field.validationSummary"></error-widget>
|
<div *ngIf="!previewState">
|
||||||
<error-widget class="adf-dropdown-required-message" *ngIf="showRequiredMessage()"
|
<error-widget [error]="field.validationSummary"></error-widget>
|
||||||
required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
|
<error-widget class="adf-dropdown-required-message" *ngIf="showRequiredMessage()"
|
||||||
<error-widget class="adf-dropdown-failed-message" *ngIf="isRestApiFailed"
|
required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
|
||||||
required="{{ 'FORM.FIELD.REST_API_FAILED' | translate: { hostname: restApiHostName } }}"></error-widget>
|
<error-widget class="adf-dropdown-failed-message" *ngIf="isRestApiFailed"
|
||||||
<error-widget class="adf-dropdown-failed-message" *ngIf="variableOptionsFailed"
|
required="{{ 'FORM.FIELD.REST_API_FAILED' | translate: { hostname: restApiHostName } }}"></error-widget>
|
||||||
required="{{ 'FORM.FIELD.VARIABLE_DROPDOWN_OPTIONS_FAILED' | translate }}"></error-widget>
|
<error-widget class="adf-dropdown-failed-message" *ngIf="variableOptionsFailed"
|
||||||
|
required="{{ 'FORM.FIELD.VARIABLE_DROPDOWN_OPTIONS_FAILED' | translate }}"></error-widget>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1022,5 +1022,23 @@ describe('DropdownCloudWidgetComponent', () => {
|
|||||||
checkDropdownVariableOptionsFailed();
|
checkDropdownVariableOptionsFailed();
|
||||||
expect(logServiceSpy).toHaveBeenCalledWith('variables.json-variable not found');
|
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;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const failedErrorMsgElement = fixture.debugElement.query(By.css('.adf-dropdown-failed-message'));
|
||||||
|
expect(failedErrorMsgElement).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -62,6 +62,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
|||||||
showInputFilter = false;
|
showInputFilter = false;
|
||||||
isRestApiFailed = false;
|
isRestApiFailed = false;
|
||||||
variableOptionsFailed = false;
|
variableOptionsFailed = false;
|
||||||
|
previewState = false;
|
||||||
restApiHostName: string;
|
restApiHostName: string;
|
||||||
list$: Observable<FormFieldOption[]>;
|
list$: Observable<FormFieldOption[]>;
|
||||||
filter$ = new BehaviorSubject<string>('');
|
filter$ = new BehaviorSubject<string>('');
|
||||||
@@ -80,6 +81,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.setPreviewState();
|
||||||
this.checkFieldOptionsSource();
|
this.checkFieldOptionsSource();
|
||||||
this.updateOptions();
|
this.updateOptions();
|
||||||
}
|
}
|
||||||
@@ -372,6 +374,10 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
|||||||
return this.field.optionType === 'rest' && !!this.field.restUrl;
|
return this.field.optionType === 'rest' && !!this.field.restUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setPreviewState(): void {
|
||||||
|
this.previewState = this.field?.form?.preview ||this.field?.preview;
|
||||||
|
}
|
||||||
|
|
||||||
private handleError(error: any) {
|
private handleError(error: any) {
|
||||||
this.logService.error(error);
|
this.logService.error(error);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user