Skip to content

Commit

Permalink
feat(editor): edit FEEL in validation properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Jun 15, 2023
1 parent b711bec commit 335904e
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
import {
CheckboxEntry,
isCheckboxEntryEdited,
isNumberFieldEntryEdited,
isFeelEntryEdited,
FeelNumberEntry,
isTextFieldEntryEdited,
NumberFieldEntry,
TextFieldEntry,
SelectEntry
} from '@bpmn-io/properties-panel';

import { useService } from '../hooks';
import { useService, useVariables } from '../hooks';

import { INPUTS } from '../Util';

Expand Down Expand Up @@ -87,15 +87,15 @@ export default function ValidationGroup(field, editField) {
component: MinLength,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
},
{
id: 'maxLength',
component: MaxLength,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
}
);
Expand All @@ -121,15 +121,15 @@ export default function ValidationGroup(field, editField) {
component: Min,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
},
{
id: 'max',
component: Max,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
}
);
Expand Down Expand Up @@ -169,14 +169,18 @@ function MinLength(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
getValue: getValue('minLength'),
id,
label: 'Minimum length',
min: 0,
setValue: onChange('minLength')
setValue: onChange('minLength'),
variables
});
}

Expand All @@ -190,14 +194,18 @@ function MaxLength(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
getValue: getValue('maxLength'),
id,
label: 'Maximum length',
min: 0,
setValue: onChange('maxLength')
setValue: onChange('maxLength'),
variables
});
}

Expand Down Expand Up @@ -231,14 +239,18 @@ function Min(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
id,
label: 'Minimum',
step: 'any',
getValue: getValue('min'),
setValue: onChange('min')
setValue: onChange('min'),
variables
});
}

Expand All @@ -252,14 +264,18 @@ function Max(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
id,
label: 'Maximum',
step: 'any',
getValue: getValue('max'),
setValue: onChange('max')
setValue: onChange('max'),
variables
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,8 @@ describe('properties panel', function() {
});

// assume
const input = screen.getByLabelText('Maximum length');
// the fx toggle is screened as well
const input = screen.getAllByLabelText('Maximum length').find((el) => el.type === 'number');

expect(input.min).to.equal('0');

Expand Down Expand Up @@ -2521,7 +2522,7 @@ describe('properties panel', function() {
});

// assume
const input = screen.getByLabelText('Minimum length');
const input = screen.getAllByLabelText('Minimum length').find((el) => el.type === 'number');

expect(input.min).to.equal('0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ValidationGroup } from '../../../../../src/features/properties-panel/gr

import { WithPropertiesPanelContext, WithPropertiesPanel } from '../helper';

import { setEditorValue } from '../../../../helper';


describe('ValidationGroup', function() {

Expand Down Expand Up @@ -78,6 +80,7 @@ describe('ValidationGroup', function() {

});


describe('validationType', function() {

it('should render for textfield', function() {
Expand Down Expand Up @@ -462,6 +465,21 @@ describe('ValidationGroup', function() {
});


it('should read (expression)', function() {

// given
const field = { type: 'number', validate: { min: '=2' } };

// when
const { container } = renderValidationGroup({ field });

// then
const minInput = findTextbox('min', container);

expect(minInput.textContent).to.eql('2');
});


it('should write', function() {

// given
Expand All @@ -487,6 +505,34 @@ describe('ValidationGroup', function() {
});


it('should write (expression)', async function() {

// given
const field = {
type: 'number',
validate: {
min: '=3'
}
};

const editFieldSpy = sinon.spy();

const { container } = renderValidationGroup({ field, editField: editFieldSpy });

const minInput = findTextbox('min', container);

// assume
expect(minInput.textContent).to.equal('3');

// when
await setEditorValue(minInput, '2');

// then
expect(editFieldSpy).to.have.been.calledOnce;
expect(field.validate.min).to.equal('=2');
});


it('should write decimal', function() {

// given
Expand Down Expand Up @@ -567,6 +613,21 @@ describe('ValidationGroup', function() {
});


it('should read (expression)', function() {

// given
const field = { type: 'number', validate: { max: '=2' } };

// when
const { container } = renderValidationGroup({ field });

// then
const maxInput = findTextbox('max', container);

expect(maxInput.textContent).to.eql('2');
});


it('should write', function() {

// given
Expand All @@ -592,6 +653,34 @@ describe('ValidationGroup', function() {
});


it('should write (expression)', async function() {

// given
const field = {
type: 'number',
validate: {
max: '=3'
}
};

const editFieldSpy = sinon.spy();

const { container } = renderValidationGroup({ field, editField: editFieldSpy });

const maxInput = findTextbox('max', container);

// assume
expect(maxInput.textContent).to.equal('3');

// when
await setEditorValue(maxInput, '2');

// then
expect(editFieldSpy).to.have.been.calledOnce;
expect(field.validate.max).to.equal('=2');
});


it('should write decimal', function() {

// given
Expand Down Expand Up @@ -643,4 +732,8 @@ function findInput(id, container) {

function findSelect(id, container) {
return container.querySelector(`select[name="${id}"]`);
}

function findTextbox(id, container) {
return container.querySelector(`[name=${id}] [role="textbox"]`);
}

0 comments on commit 335904e

Please sign in to comment.