jetformbuilder
/
assets
/
src
/
package
/
block-conditions
/
components
/
HumanReadableConditions.js
BeforeConditionOptions.js
2 years ago
ConditionItem.js
2 years ago
ConditionOptions.js
2 years ago
ConditionsRepeaterContextProvider.js
2 years ago
EditCustomRenderStates.js
2 years ago
HumanReadableConditions.js
2 years ago
RenderStateOptions.js
2 years ago
HumanReadableConditions.js
50 lines
| 1 | import humanReadableCondition from '../helpers/humanReadableCondition'; |
| 2 | |
| 3 | const { |
| 4 | __, |
| 5 | } = wp.i18n; |
| 6 | const { |
| 7 | Children, |
| 8 | cloneElement, |
| 9 | } = wp.element; |
| 10 | |
| 11 | function HumanReadableConditions( { conditions, showWarning = false } ) { |
| 12 | let conditionsElements = []; |
| 13 | let firstReadCondition = ''; |
| 14 | |
| 15 | if ( Boolean( conditions?.length ) ) { |
| 16 | firstReadCondition = humanReadableCondition( conditions[ 0 ] ); |
| 17 | |
| 18 | conditionsElements = conditions.filter( |
| 19 | // Exclude first item |
| 20 | ( c, index ) => 0 !== index, |
| 21 | ).map( |
| 22 | condition => <span |
| 23 | data-title={ __( 'And', 'jet-form-builder' ) + ':' } |
| 24 | dangerouslySetInnerHTML={ { |
| 25 | __html: humanReadableCondition( condition ), |
| 26 | } } |
| 27 | />, |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | return firstReadCondition ? <> |
| 32 | <span |
| 33 | data-title={ __( |
| 34 | 'If', 'jet-form-builder', |
| 35 | ) + ':' } |
| 36 | dangerouslySetInnerHTML={ { |
| 37 | __html: firstReadCondition, |
| 38 | } } |
| 39 | /> |
| 40 | { Children.map( conditionsElements, cloneElement ) } |
| 41 | </> : showWarning && <span |
| 42 | data-title={ __( |
| 43 | 'The condition is not fully configured.', |
| 44 | 'jet-form-builder', |
| 45 | ) } |
| 46 | />; |
| 47 | |
| 48 | } |
| 49 | |
| 50 | export default HumanReadableConditions; |