-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add conditional rendering #403
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5451357
feat(viewer): add condition property to field
barmac b6eaa94
chore: ignore luxon circular dependency
barmac c4205e7
feat(editor): add condition group to properties panel
barmac 4553e2a
chore: remove unnecessary change
barmac 3fbb320
fix(condition): removed reliance on intialData
Skaiir 0d78530
feat(editor): extract useVariables
barmac cb3f0f9
docs: document useCondition
barmac 75b45c8
chore: add comment
barmac 7ee5473
feat: make condition checker report error on broken condition
barmac d33c813
test: add conditional field to main package test
barmac ee54b1e
feat(viewer): use conditional#hide for conditions
barmac 2646e81
feat(editor): use conditional#hide
barmac 894c28d
feat: retrieve variables mentioned in conditions
barmac 1e134cc
chore: update field description
barmac edb09b9
chore: do not memoize variables
barmac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
69 changes: 69 additions & 0 deletions
69
packages/form-js-editor/src/features/properties-panel/entries/ConditionEntry.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,69 @@ | ||
import { useMemo } from 'preact/hooks'; | ||
import { FeelEntry, isFeelEntryEdited } from '@bpmn-io/properties-panel'; | ||
import { get } from 'min-dash'; | ||
|
||
import { | ||
useService, | ||
useVariables | ||
} from '../hooks'; | ||
|
||
|
||
export function ConditionEntry(props) { | ||
const { | ||
editField, | ||
field | ||
} = props; | ||
|
||
return [ | ||
{ | ||
id: 'conditional-hide', | ||
component: Condition, | ||
editField: editField, | ||
field: field, | ||
isEdited: isFeelEntryEdited | ||
} | ||
]; | ||
} | ||
|
||
|
||
function Condition(props) { | ||
const { | ||
editField, | ||
field, | ||
id | ||
} = props; | ||
|
||
const debounce = useService('debounce'); | ||
|
||
const variablesList = useVariables(); | ||
|
||
// keep stable reference until https://github.com/bpmn-io/properties-panel/issues/196 is fixed | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const variables = useMemo(() => variablesList.map(name => ({ name })), variablesList); | ||
|
||
const path = [ 'conditional', 'hide' ]; | ||
|
||
const getValue = () => { | ||
return get(field, path, ''); | ||
}; | ||
|
||
const setValue = (value) => { | ||
if (!value) { | ||
return editField(field, 'conditional', undefined); | ||
} | ||
|
||
return editField(field, 'conditional', { hide: value }); | ||
}; | ||
|
||
return FeelEntry({ | ||
debounce, | ||
description: 'Condition under which the field is hidden', | ||
element: field, | ||
feel: 'required', | ||
getValue, | ||
id, | ||
label: 'Hide if', | ||
setValue, | ||
variables | ||
}); | ||
} |
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
23 changes: 23 additions & 0 deletions
23
packages/form-js-editor/src/features/properties-panel/groups/ConditionGroup.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,23 @@ | ||
import { | ||
ConditionEntry | ||
} from '../entries'; | ||
|
||
|
||
export function ConditionGroup(field, editField) { | ||
|
||
const { type } = field; | ||
|
||
if (type === 'default') { | ||
return null; | ||
} | ||
|
||
const entries = [ | ||
...ConditionEntry({ field, editField }) | ||
]; | ||
|
||
return { | ||
id: 'condition', | ||
label: 'Condition', | ||
entries | ||
}; | ||
} |
3 changes: 2 additions & 1 deletion
3
packages/form-js-editor/src/features/properties-panel/groups/index.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as GeneralGroup } from './GeneralGroup'; | ||
export { default as ValidationGroup } from './ValidationGroup'; | ||
export { default as ValuesGroups } from './ValuesGroups'; | ||
export { default as CustomValuesGroup } from './CustomValuesGroup'; | ||
export { default as CustomValuesGroup } from './CustomValuesGroup'; | ||
export { ConditionGroup } from './ConditionGroup'; |
3 changes: 2 additions & 1 deletion
3
packages/form-js-editor/src/features/properties-panel/hooks/index.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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as useService } from './usePropertiesPanelService'; | ||
export { default as useService } from './usePropertiesPanelService'; | ||
export { useVariables } from './useVariables'; |
14 changes: 14 additions & 0 deletions
14
packages/form-js-editor/src/features/properties-panel/hooks/useVariables.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,14 @@ | ||
import { getSchemaVariables } from '@bpmn-io/form-js-viewer'; | ||
import useService from './usePropertiesPanelService'; | ||
|
||
/** | ||
* Retrieve list of variables from the form schema. | ||
* | ||
* @returns { string[] } list of variables used in form schema | ||
*/ | ||
export function useVariables() { | ||
const form = useService('formEditor'); | ||
const schema = form.getSchema(); | ||
|
||
return getSchemaVariables(schema); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { default as useService } from './useService'; | ||
export { default as usePrevious } from './usePrevious'; | ||
export { default as useDebounce } from './useDebounce'; | ||
export { default as useDebounce } from './useDebounce'; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be resolved now via 3a51c37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! Let's check this in action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK done