Skip to content

Commit

Permalink
AAE-21380 Skip value override for constant field type (#9471)
Browse files Browse the repository at this point in the history
* AAE-21380 Skip value override for constant field type

* AAE-21380 improve method name
  • Loading branch information
tomgny committed Mar 26, 2024
1 parent 9d76088 commit 7c0d165
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
77 changes: 77 additions & 0 deletions lib/core/src/lib/form/components/mock/form.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down
19 changes: 18 additions & 1 deletion lib/core/src/lib/form/components/widgets/core/form.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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');
});
});
6 changes: 5 additions & 1 deletion lib/core/src/lib/form/components/widgets/core/form.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7c0d165

Please sign in to comment.