Ejemplo n.º 1
0
	return createHigherOrderComponent( ( OriginalComponent ) => {
		return compose(
			withDispatch( ( dispatch ) => {
				const { showField, hideField } = dispatch( 'carbon-fields/core' );

				return {
					showField,
					hideField
				};
			} ),
			withSelect( ( select, props ) => ( {
				visible: select( 'carbon-fields/core' ).isFieldVisible( props.id )
			} ) ),
			withEffects( aperture, { handler } )
		)( OriginalComponent );
	}, 'withConditionalLogic' );
Ejemplo n.º 2
0
/**
 * The function that causes the side effects.
 *
 * @param  {Object} props
 * @return {Function}
 */
function handler( props ) {
	return function() {
		// Collects identifiers of current fields so we can remove them later.
		const oldFieldIds = _.map( props.container.fields, 'id' );

		// Get a fresh copy of the container and fields.
		const { containers, fields } = normalizePreloadedState( _.get( window.cf, 'preloaded.containers', [] ) );
		const container = _.find( containers, [ 'id', props.id ] );
		const containerFields = _.filter( fields, [ 'container_id', props.id ] );

		// Replace the container and add the new fields.
		const { updateState, removeFields } = dispatch( 'carbon-fields/metaboxes' );

		updateState(
			_.keyBy( [ container ], 'id' ),
			_.keyBy( containerFields, 'id' )
		);

		removeFields( oldFieldIds );
	};
}

addFilter( 'carbon-fields.term_meta.classic', 'carbon-fields/metaboxes', withEffects( aperture, { handler } ) );
Ejemplo n.º 3
0
/**
 * Internal dependencies.
 */
import aperture from './aperture';
import handler from './handler';

/**
 * Performs the evaluation of conditions.
 *
 * @return {null}
 */
function ConditionalDisplay() {
	return null;
}

const applyWithSelect = withSelect( ( select ) => {
	const containers = select( 'carbon-fields/metaboxes' ).getContainers();

	return {
		containers
	};
} );

const applyWitEffects = withEffects( aperture, { handler } );

export default compose(
	applyWithSelect,
	applyWitEffects
)( ConditionalDisplay );