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

Sub-PR: expression fields base #1095

Merged
merged 11 commits into from
Mar 20, 2024
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { PaletteEntry } from './PaletteEntry';

export const PALETTE_GROUPS = [
{
label: 'Basic input',
label: 'Input',
id: 'basic-input'
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/form-js-editor/src/features/palette/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PaletteRenderer } from './PaletteRenderer';

export const PaletteModule = {
__init__: [ 'palette' ],
palette: [ 'type', PaletteRenderer ]
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useService } from './hooks';
const headerlessTypes = [
'spacer',
'separator',
'expression',
'html'
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ function Condition(props) {
return editField(field, 'conditional', { hide: value });
};

let label = 'Hide if';
let description = 'Condition under which the field is hidden';

// special case for expression fields which do not render
if (field.type === 'expression') {
label = 'Deactivate if';
description = 'Condition under which the field is deactivated';
}

return FeelEntry({
debounce,
description: 'Condition under which the field is hidden',
description,
element: field,
feel: 'required',
getValue,
id,
label: 'Hide if',
label,
setValue,
variables
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { FeelEntry, isFeelEntryEdited, SelectEntry, isSelectEntryEdited } from '@bpmn-io/properties-panel';
import { useService, useVariables } from '../hooks';

export function ExpressionFieldEntries(props) {
const { editField, field, id } = props;

const entries = [];

entries.push({
id: `${id}-expression`,
component: ExpressionFieldExpression,
isEdited: isFeelEntryEdited,
editField,
field,
isDefaultVisible: (field) => field.type === 'expression'
});

entries.push({
id: `${id}-computeOn`,
component: ExpressionFieldComputeOn,
isEdited: isSelectEntryEdited,
editField,
field,
isDefaultVisible: (field) => field.type === 'expression'
});

return entries;
Comment on lines +7 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This could be simplified to a list comprehension

return [
 {/* ... */},
 {/* ... */},
];

}

function ExpressionFieldExpression(props) {
const { editField, field, id } = props;

const debounce = useService('debounce');
const variables = useVariables().map(name => ({ name }));

const getValue = () => field.expression || '';

const setValue = (value) => {
editField(field, [ 'expression' ], value);
};

return FeelEntry({
debounce,
description: 'Define an expression to calculate the value of this field',
element: field,
feel: 'required',
getValue,
id,
label: 'Target value',
setValue,
variables
});
}

function ExpressionFieldComputeOn(props) {
const { editField, field, id } = props;

const getValue = () => field.computeOn || '';

const setValue = (value) => {
editField(field, [ 'computeOn' ], value);
};

const getOptions = () => ([
{ value: 'change', label: 'Value changes' },
{ value: 'presubmit', label: 'Form submission' }
]);

return SelectEntry({
id,
label: 'Compute on',
getValue,
setValue,
getOptions
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { TextEntry } from './TextEntry';
export { HtmlEntry } from './HtmlEntry';
export { HeightEntry } from './HeightEntry';
export { NumberEntries } from './NumberEntries';
export { ExpressionFieldEntries } from './ExpressionFieldEntries';
export { NumberSerializationEntry } from './NumberSerializationEntry';
export { DateTimeEntry } from './DateTimeEntry';
export { DateTimeConstraintsEntry } from './DateTimeConstraintsEntry';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
HtmlEntry,
HeightEntry,
NumberEntries,
ExpressionFieldEntries,
DateTimeEntry,
TableDataSourceEntry,
PaginationEntry,
Expand All @@ -43,6 +44,7 @@ export function GeneralGroup(field, editField, getService) {
...IFrameHeightEntry({ field, editField }),
...HeightEntry({ field, editField }),
...NumberEntries({ field, editField }),
...ExpressionFieldEntries({ field, editField }),
...ImageSourceEntry({ field, editField }),
...AltTextEntry({ field, editField }),
...SelectEntries({ field, editField }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ExpressionField, iconsByType } from '@bpmn-io/form-js-viewer';
import { editorFormFieldClasses } from '../Util';
import { useService } from '../../hooks';

const type = 'expression';

export function EditorExpressionField(props) {
const { field } = props;
const { expression = '' } = field;

const Icon = iconsByType('expression');
const expressionLanguage = useService('expressionLanguage');

let placeholderContent = 'Expression is empty';

if (expression.trim() && expressionLanguage.isExpression(expression)) {
placeholderContent = 'Expression';
}

return (
<div class={ editorFormFieldClasses(type) }>
<div class="fjs-form-field-placeholder">
<Icon viewBox="0 0 54 54" />{placeholderContent}
</div>
</div>
);
}

EditorExpressionField.config = {
...ExpressionField.config,
escapeGridRender: false
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { EditorIFrame } from './EditorIFrame';
import { EditorText } from './EditorText';
import { EditorHtml } from './EditorHtml';
import { EditorTable } from './EditorTable';
import { EditorExpressionField } from './EditorExpressionField';

export const editorFormFields = [
EditorIFrame,
EditorText,
EditorHtml,
EditorTable
EditorTable,
EditorExpressionField
];
4 changes: 2 additions & 2 deletions packages/form-js-editor/test/spec/FormEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@ describe('FormEditor', function() {
const exportedSchema = formEditor.saveSchema();

// then
expect(exportedSchema).to.eql(exportTagged(schema));
const tagged = exportTagged(schema);
expect(exportedSchema).to.eql(tagged);

const exportedString = JSON.stringify(exportedSchema);

expect(exportedString).not.to.contain('"_path"');
expect(exportedString).not.to.contain('"_parent"');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,45 +116,6 @@ describe('features/palette', function() {
});


it('should attach when section rendered late', async function() {

// given
const node = document.createElement('div');
document.body.appendChild(node);

let formEditor;

await act(async () => {
const result = await createEditor(schema);
formEditor = result.formEditor;
});

const palette = formEditor.get('palette');
const eventBus = formEditor.get('eventBus');

// when
await act(() => {
return palette.attachTo(node);
});

// then
expect(domQuery('.fjs-palette', paletteContainer)).to.exist;
expect(domQuery('.fjs-palette', node)).to.not.exist;

// when
await act(() => {
eventBus.fire('palette.section.rendered');
});

// then
expect(domQuery('.fjs-palette', paletteContainer)).to.not.exist;
expect(domQuery('.fjs-palette', node)).to.exist;

// cleanup
document.body.removeChild(node);
});


it('should detach', async function() {

// given
Expand Down
Loading