Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEEL support for min, max, minLength and maxLength #668

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]`);
vsgoulart marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions packages/form-js-playground/test/spec/Playground.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ describe('playground', function() {
(singleStartBasic ? it.only : it)('should render', async function() {

// given
this.timeout(5000);

const data = {
logo: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160px' viewBox='0 0 58 23'%3E%3Cpath fill='currentColor' d='M7.75 3.8v.58c0 1.7-.52 2.78-1.67 3.32C7.46 8.24 8 9.5 8 11.24v1.34c0 2.54-1.35 3.9-3.93 3.9H0V0h3.91c2.68 0 3.84 1.25 3.84 3.8zM2.59 2.35V6.7H3.6c.97 0 1.56-.42 1.56-1.74v-.92c0-1.18-.4-1.7-1.32-1.7zm0 6.7v5.07h1.48c.87 0 1.34-.4 1.34-1.63v-1.43c0-1.53-.5-2-1.67-2H2.6zm14.65-4.98v2.14c0 2.64-1.27 4.08-3.87 4.08h-1.22v6.2H9.56V0h3.82c2.59 0 3.86 1.44 3.86 4.07zm-5.09-1.71v5.57h1.22c.83 0 1.28-.37 1.28-1.55V3.91c0-1.18-.45-1.56-1.28-1.56h-1.22zm11.89 9.34L25.81 0h3.6v16.48h-2.44V4.66l-1.8 11.82h-2.45L20.8 4.83v11.65h-2.26V0h3.6zm9.56-7.15v11.93h-2.33V0h3.25l2.66 9.87V0h2.31v16.48h-2.66zm10.25 9.44v2.5h-2.5v-2.5zM50 4.16C50 1.52 51.38.02 53.93.02c2.54 0 3.93 1.5 3.93 4.14v8.37c0 2.64-1.4 4.14-3.93 4.14-2.55 0-3.93-1.5-3.93-4.14zm2.58 8.53c0 1.18.52 1.63 1.35 1.63.82 0 1.34-.45 1.34-1.63V4c0-1.17-.52-1.62-1.34-1.62-.83 0-1.35.45-1.35 1.62zM0 18.7h57.86V23H0zM45.73 0h2.6v2.58h-2.6zm2.59 16.48V4.16h-2.59v12.32z'%3E%3C/path%3E%3C/svg%3E",
invoiceNumber: 'C-123',
Expand Down
Loading