AdvancedRuleItem.js
2 years ago
AdvancedRuleModalItem.js
2 years ago
AdvancedRulesIsEmpty.js
2 years ago
AdvancedRulesList.js
2 years ago
AdvancedRulesModal.js
2 years ago
ChooseRelatedField.js
2 years ago
EditAdvancedRulesButton.js
2 years ago
EditRulesModalContext.js
2 years ago
HumanReadableRule.js
2 years ago
ValidationBlockMessage.js
2 years ago
ValidationMetaMessage.js
2 years ago
ValidationToggleGroup.js
2 years ago
AdvancedRuleItem.js
77 lines
| 1 | import EditRulesModalContext from './EditRulesModalContext'; |
| 2 | import useBlockAttributes from '../../blocks/hooks/useBlockAttributes'; |
| 3 | import DetailsContainer from '../../components/DetailsContainer'; |
| 4 | import HoverContainer from '../../components/HoverContainer'; |
| 5 | import HumanReadableRule from './HumanReadableRule'; |
| 6 | |
| 7 | const { |
| 8 | useContext, |
| 9 | useState, |
| 10 | } = wp.element; |
| 11 | const { |
| 12 | __, |
| 13 | } = wp.i18n; |
| 14 | const { |
| 15 | Button, |
| 16 | } = wp.components; |
| 17 | |
| 18 | function AdvancedRuleItem( { rule, index = 0 } ) { |
| 19 | const { setShowModal } = useContext( EditRulesModalContext ); |
| 20 | const [ attributes, setAttributes ] = useBlockAttributes(); |
| 21 | |
| 22 | const [ isHover, setHover ] = useState( false ); |
| 23 | |
| 24 | return <div |
| 25 | className="jet-fb p-relative" |
| 26 | onMouseOver={ () => setHover( true ) } |
| 27 | onMouseOut={ () => setHover( false ) } |
| 28 | > |
| 29 | <HoverContainer isHover={ isHover }> |
| 30 | <Button |
| 31 | isSmall |
| 32 | isSecondary |
| 33 | icon={ 'edit' } |
| 34 | onClick={ () => { |
| 35 | setAttributes( { |
| 36 | validation: { |
| 37 | ...attributes.validation, |
| 38 | rules: attributes.validation.rules.map( |
| 39 | ( current, currentIndex ) => { |
| 40 | current.__visible = index === currentIndex; |
| 41 | return current; |
| 42 | }, |
| 43 | ), |
| 44 | }, |
| 45 | } ); |
| 46 | setShowModal( prev => !prev ); |
| 47 | } } |
| 48 | > |
| 49 | { __( 'Edit', 'jet-form-builder' ) } |
| 50 | </Button> |
| 51 | <Button |
| 52 | isSmall |
| 53 | isDestructive |
| 54 | icon={ 'trash' } |
| 55 | onClick={ () => { |
| 56 | setAttributes( { |
| 57 | validation: { |
| 58 | ...attributes.validation, |
| 59 | rules: attributes.validation.rules.filter( |
| 60 | ( current, currentIndex ) => ( |
| 61 | currentIndex !== index |
| 62 | ), |
| 63 | ), |
| 64 | }, |
| 65 | } ); |
| 66 | } } |
| 67 | > |
| 68 | { __( 'Delete', 'jet-form-builder' ) } |
| 69 | </Button> |
| 70 | </HoverContainer> |
| 71 | <DetailsContainer> |
| 72 | <HumanReadableRule rule={ rule }/> |
| 73 | </DetailsContainer> |
| 74 | </div>; |
| 75 | } |
| 76 | |
| 77 | export default AdvancedRuleItem; |