mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
AAE-21380 Skip value override for constant field type (#9471)
* AAE-21380 Skip value override for constant field type * AAE-21380 improve method name
This commit is contained in:
parent
9d7608817d
commit
7c0d165db7
@ -1234,6 +1234,83 @@ export const fakeMetadataForm = {
|
||||
}
|
||||
};
|
||||
|
||||
export const mockDisplayExternalPropertyForm = {
|
||||
id: 'form-29483aa4-ebd4-4eab-b024-65ce7b268286',
|
||||
name: 'external-form',
|
||||
description: '',
|
||||
version: 0,
|
||||
key: 'external-form',
|
||||
tabs: [],
|
||||
fields: [
|
||||
{
|
||||
id: '48120e00-e0d5-4d15-be49-ccf328ecb24d',
|
||||
name: 'Label',
|
||||
type: 'container',
|
||||
tab: null,
|
||||
numberOfColumns: 2,
|
||||
fields: {
|
||||
1: [
|
||||
{
|
||||
id: 'DisplayExternalProperty02kj65',
|
||||
name: 'Display External Property',
|
||||
type: 'display-external-property',
|
||||
readOnly: true,
|
||||
required: true,
|
||||
colspan: 1,
|
||||
rowspan: 1,
|
||||
visibilityCondition: null,
|
||||
params: {
|
||||
existingColspan: 1,
|
||||
maxColspan: 2
|
||||
},
|
||||
externalProperty: 'firstName',
|
||||
value: 'hr'
|
||||
}
|
||||
],
|
||||
2: [
|
||||
{
|
||||
id: 'DisplayExternalProperty0ei65x',
|
||||
name: 'Display External Property',
|
||||
type: 'display-external-property',
|
||||
readOnly: true,
|
||||
colspan: 1,
|
||||
rowspan: 1,
|
||||
visibilityCondition: null,
|
||||
params: {
|
||||
existingColspan: 1,
|
||||
maxColspan: 2
|
||||
},
|
||||
externalProperty: 'username',
|
||||
required: false,
|
||||
value: 'hruser'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
outcomes: [],
|
||||
metadata: {},
|
||||
variables: [],
|
||||
taskId: '2764e7b3-eaad-11ee-b14c-86722ede7d5b',
|
||||
taskName: 'widgets',
|
||||
processDefinitionId: 'Process_xQy3Ev89:1:aa78eca9-eaac-11ee-b14c-86722ede7d5b',
|
||||
processInstanceId: '275d94ab-eaad-11ee-b14c-86722ede7d5b',
|
||||
processVariables: [
|
||||
{
|
||||
id: 'DisplayExternalProperty0ei65x',
|
||||
name: 'DisplayExternalProperty0ei65x',
|
||||
value: 'email',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
id: 'DisplayExternalProperty02kj65',
|
||||
name: 'DisplayExternalProperty02kj65',
|
||||
value: 'test',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const fakeViewerForm = {
|
||||
id: 'form-de8895be-d0d7-4434-beef-559b15305d72',
|
||||
name: 'StartEventForm',
|
||||
|
@ -61,6 +61,10 @@ export class FormFieldTypes {
|
||||
FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY
|
||||
];
|
||||
|
||||
static CONSTANT_VALUE_TYPES: string[] = [
|
||||
FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY
|
||||
];
|
||||
|
||||
static isReadOnlyType(type: string) {
|
||||
return FormFieldTypes.READONLY_TYPES.includes(type);
|
||||
}
|
||||
@ -69,6 +73,10 @@ export class FormFieldTypes {
|
||||
return FormFieldTypes.VALIDATABLE_TYPES.includes(type);
|
||||
}
|
||||
|
||||
static isConstantValueType(type: string) {
|
||||
return FormFieldTypes.CONSTANT_VALUE_TYPES.includes(type);
|
||||
}
|
||||
|
||||
static isContainerType(type: string) {
|
||||
return type === FormFieldTypes.CONTAINER || type === FormFieldTypes.GROUP;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import { FormFieldModel } from './form-field.model';
|
||||
import { FormOutcomeModel } from './form-outcome.model';
|
||||
import { FormModel } from './form.model';
|
||||
import { TabModel } from './tab.model';
|
||||
import { fakeMetadataForm } from '../../mock/form.mock';
|
||||
import { fakeMetadataForm, mockDisplayExternalPropertyForm } from '../../mock/form.mock';
|
||||
import { CoreTestingModule } from '../../../../testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
@ -607,4 +607,21 @@ describe('FormModel', () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should NOT override value by provided form values for constant value field type', () => {
|
||||
const mockFormValues = {
|
||||
DisplayExternalProperty0ei65x: 'email',
|
||||
DisplayExternalProperty02kj65: 'test'
|
||||
};
|
||||
|
||||
const formModel = new FormModel(mockDisplayExternalPropertyForm, mockFormValues);
|
||||
const displayExternalPropertyWidget = formModel.fields[0].form.fields[0].field.fields[1][0];
|
||||
|
||||
expect(formModel.processVariables[1].name).toBe('DisplayExternalProperty02kj65');
|
||||
expect(formModel.processVariables[1].value).toBe('test');
|
||||
expect(formModel.values['DisplayExternalProperty02kj65']).toBe('hr');
|
||||
|
||||
expect(FormFieldTypes.isConstantValueType(displayExternalPropertyWidget.type)).toBeTrue();
|
||||
expect(displayExternalPropertyWidget.value).toBe('hr');
|
||||
});
|
||||
});
|
||||
|
@ -236,13 +236,17 @@ export class FormModel implements ProcessFormModel {
|
||||
for (const field of this.fieldsCache) {
|
||||
const variableId = `variables.${field.name}`;
|
||||
|
||||
if (this.isDefined(formValues[variableId]) || this.isDefined(formValues[field.id])) {
|
||||
if (this.canOverrideFieldValueWithProcessValue(field, variableId, formValues)) {
|
||||
field.json.value = formValues[variableId] || formValues[field.id];
|
||||
field.value = field.parseValue(field.json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private canOverrideFieldValueWithProcessValue(field: FormFieldModel, variableId: string, formValues: FormValues): boolean {
|
||||
return !FormFieldTypes.isConstantValueType(field.type) && (this.isDefined(formValues[variableId]) || this.isDefined(formValues[field.id]));
|
||||
}
|
||||
|
||||
private isDefined(value: string): boolean {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user