-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
425 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
packages/form-js-editor/src/features/properties-panel/entries/JSFunctionEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { FeelEntry, isFeelEntryEdited, TextAreaEntry, isTextAreaEntryEdited, SelectEntry, isSelectEntryEdited } from '@bpmn-io/properties-panel'; | ||
import { get } from 'min-dash'; | ||
import { simpleRangeIntegerEntryFactory } from './factories'; | ||
|
||
import { useService, useVariables } from '../hooks'; | ||
|
||
export function JSFunctionEntry(props) { | ||
const { | ||
editField, | ||
field | ||
} = props; | ||
|
||
const entries = [ | ||
{ | ||
id: 'variable-mappings', | ||
component: FunctionParameters, | ||
editField: editField, | ||
field: field, | ||
isEdited: isFeelEntryEdited, | ||
isDefaultVisible: (field) => field.type === 'script' | ||
}, | ||
{ | ||
id: 'function', | ||
component: FunctionDefinition, | ||
editField: editField, | ||
field: field, | ||
isEdited: isTextAreaEntryEdited, | ||
isDefaultVisible: (field) => field.type === 'script' | ||
}, | ||
{ | ||
id: 'computeOn', | ||
component: JSFunctionComputeOn, | ||
isEdited: isSelectEntryEdited, | ||
editField, | ||
field, | ||
isDefaultVisible: (field) => field.type === 'script' | ||
}, | ||
simpleRangeIntegerEntryFactory({ | ||
id: 'interval', | ||
label: 'Time interval (ms)', | ||
path: [ 'interval' ], | ||
min: 100, | ||
max: 60000, | ||
props, | ||
isDefaultVisible: (field) => field.type === 'script' && field.computeOn === 'interval' | ||
}) | ||
]; | ||
|
||
return entries; | ||
} | ||
|
||
function FunctionParameters(props) { | ||
const { | ||
editField, | ||
field, | ||
id | ||
} = props; | ||
|
||
const debounce = useService('debounce'); | ||
|
||
const variables = useVariables().map(name => ({ name })); | ||
|
||
const path = [ 'functionParameters' ]; | ||
|
||
const getValue = () => { | ||
return get(field, path, ''); | ||
}; | ||
|
||
const setValue = (value) => { | ||
return editField(field, path, value || ''); | ||
}; | ||
|
||
const tooltip = <div> | ||
Functions parameters should be described as an object, e.g.: | ||
<pre><code>{`{ | ||
name: user.name, | ||
age: user.age | ||
}`}</code></pre> | ||
</div>; | ||
|
||
return FeelEntry({ | ||
debounce, | ||
feel: 'required', | ||
element: field, | ||
getValue, | ||
id, | ||
label: 'Function parameters', | ||
tooltip, | ||
description: 'Define the parameters to pass to the javascript sandbox.', | ||
setValue, | ||
variables | ||
}); | ||
} | ||
|
||
function FunctionDefinition(props) { | ||
const { | ||
editField, | ||
field, | ||
id | ||
} = props; | ||
|
||
const debounce = useService('debounce'); | ||
|
||
const path = [ 'jsFunction' ]; | ||
|
||
const getValue = () => { | ||
return get(field, path, ''); | ||
}; | ||
|
||
const setValue = (value) => { | ||
return editField(field, path, value || ''); | ||
}; | ||
|
||
return TextAreaEntry({ | ||
debounce, | ||
element: field, | ||
getValue, | ||
description: 'Define the javascript function to execute.\nAccess the `data` object and use `setValue` to update the form state.', | ||
id, | ||
label: 'Javascript code', | ||
setValue | ||
}); | ||
} | ||
|
||
function JSFunctionComputeOn(props) { | ||
const { editField, field, id } = props; | ||
|
||
const getValue = () => field.computeOn || ''; | ||
|
||
const setValue = (value) => { | ||
editField(field, [ 'computeOn' ], value); | ||
}; | ||
|
||
const getOptions = () => ([ | ||
{ value: 'load', label: 'Form load' }, | ||
{ value: 'change', label: 'Value change' }, | ||
{ value: 'interval', label: 'Time interval' } | ||
]); | ||
|
||
return SelectEntry({ | ||
id, | ||
label: 'Compute on', | ||
description: 'Define when to execute the function', | ||
getValue, | ||
setValue, | ||
getOptions | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.