How to use the @wordpress/data.withSelect function in @wordpress/data

To help you get started, we’ve selected a few @wordpress/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wp-calypso / apps / full-site-editing / full-site-editing-plugin / starter-page-templates / page-template-modal / index.js View on Github external
disabled={ isEmpty( previewedTemplate ) || isLoading }
						onClick={ this.handleConfirmation }
					>
						{ sprintf(
							__( 'Use %s layout', 'full-site-editing' ),
							this.getTitleByTemplateSlug( previewedTemplate )
						) }
					
				
			
		);
	}
}

export const PageTemplatesPlugin = compose(
	withSelect( select => {
		const getMeta = () => select( 'core/editor' ).getEditedPostAttribute( 'meta' );
		const { _starter_page_template } = getMeta();
		return {
			getMeta,
			_starter_page_template,
			postContentBlock: select( 'core/editor' )
				.getBlocks()
				.find( block => block.name === 'a8c/post-content' ),
		};
	} ),
	withDispatch( ( dispatch, ownProps ) => {
		// Disable tips right away as the collide with the modal window.
		dispatch( 'core/nux' ).disableTips();

		const editorDispatcher = dispatch( 'core/editor' );
		return {
github Automattic / jetpack / extensions / blocks / subscriptions-toggle / subscriptions-checkbox.js View on Github external
const SubscriptionsCheckbox = ( { isPostExcludedFromSubs, editPost } ) => (
	
		
			 {
					editPost( { jetpack_dont_email_post_to_subs: value } );
				} }
			/>
		
	
);

// Fetch the post meta.
const applyWithSelect = withSelect( select => {
	const { getEditedPostAttribute } = select( 'core/editor' );
	const isPostExcludedFromSubs = getEditedPostAttribute( 'jetpack_dont_email_post_to_subs' );

	return { isPostExcludedFromSubs };
} );

// Provide method to update post meta.
const applyWithDispatch = withDispatch( dispatch => {
	const { editPost } = dispatch( 'core/editor' );

	return { editPost };
} );

// Combine the higher-order components.
export default compose( [ applyWithSelect, applyWithDispatch ] )( SubscriptionsCheckbox );
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / index.js View on Github external
}
	},
} )( Sidebar );

function AnimatedSidebarFill( props ) {
	return (
		
			
				{ () =>  }
			
		
	);
}

const WrappedSidebar = compose(
	withSelect( ( select, { name } ) => ( {
		isActive: select( 'core/edit-post' ).getActiveGeneralSidebarName() === name,
	} ) ),
	ifCondition( ( { isActive } ) => isActive ),
)( AnimatedSidebarFill );

WrappedSidebar.Slot = Slot;

export default WrappedSidebar;
github ampproject / amp-wp / assets / src / components / inserter / child-blocks.js View on Github external
return (
		<div>
			{ ( rootBlockIcon || rootBlockTitle ) &amp;&amp; (
				<div>
					
					{ rootBlockTitle &amp;&amp; <h2>{ rootBlockTitle }</h2> }
				</div>
			) }
			
		</div>
	);
}

export default compose(
	ifCondition( ( { items } ) =&gt; items &amp;&amp; items.length &gt; 0 ),
	withSelect( ( select, { rootClientId } ) =&gt; {
		const {
			getBlockType,
		} = select( 'core/blocks' );
		const {
			getBlockName,
		} = select( 'core/block-editor' );
		const rootBlockName = getBlockName( rootClientId );
		const rootBlockType = getBlockType( rootBlockName );
		return {
			rootBlockTitle: rootBlockType &amp;&amp; rootBlockType.title,
			rootBlockIcon: rootBlockType &amp;&amp; rootBlockType.icon,
		};
	} ),
)( ChildBlocks );
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / plugin-sidebar / index.js View on Github external
* 			{ __( 'My sidebar content' ) }
 * 		
 * 	
 * );
 * ```
 *
 * @return {WPComponent} Plugin sidebar component.
 */
export default compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
			sidebarName: `${ context.name }/${ ownProps.name }`,
		};
	} ),
	withSelect( ( select, { sidebarName } ) =&gt; {
		const {
			getActiveGeneralSidebarName,
			isPluginItemPinned,
		} = select( 'core/edit-post' );

		return {
			isActive: getActiveGeneralSidebarName() === sidebarName,
			isPinned: isPluginItemPinned( sidebarName ),
		};
	} ),
	withDispatch( ( dispatch, { isActive, sidebarName } ) =&gt; {
		const {
			closeGeneralSidebar,
			openGeneralSidebar,
			togglePinnedPluginItem,
		} = dispatch( 'core/edit-post' );
github ampproject / amp-wp / assets / src / block-editor / plugins / amp-toggle.js View on Github external
}
		
	);
}

AMPToggle.propTypes = {
	isEnabled: PropTypes.bool.isRequired,
	onChange: PropTypes.func.isRequired,
};

export const name = 'amp';

export const icon = 'hidden';

export const render = compose(
	withSelect( () =&gt; {
		return {
			isEnabled: isAMPEnabled(),
		};
	} ),
	withDispatch( ( dispatch ) =&gt; {
		return {
			onChange: ( isEnabled ) =&gt; {
				dispatch( 'core/editor' ).editPost( { amp_enabled: isEnabled } );
			},
		};
	} ),
	withInstanceId,
)( AMPToggle );
github woocommerce / woocommerce-gutenberg-products-block / assets / js / blocks / products / all-products / edit.js View on Github external
&gt;
						{ this.getBlockControls() }
						{ this.getInspectorControls() }
						{ isEditing
							? this.renderEditMode()
							: this.renderViewMode() }
					
				
			
		);
	};
}

export default compose(
	withSpokenMessages,
	withSelect( ( select, { clientId } ) =&gt; {
		const { getBlock } = select( 'core/block-editor' );
		return {
			block: getBlock( clientId ),
		};
	} ),
	withDispatch( ( dispatch ) =&gt; {
		const { replaceInnerBlocks } = dispatch( 'core/block-editor' );
		return {
			replaceInnerBlocks,
		};
	} )
)( Editor );
github php4dev / heroku-wordpress / wp-content / plugins / woocommerce / packages / woocommerce-blocks / assets / js / blocks / products / all-products / edit.js View on Github external
className={ getBlockClassName(
					'wc-block-all-products',
					attributes
				) }
			&gt;
				{ this.getBlockControls() }
				{ this.getInspectorControls() }
				{ isEditing ? this.renderEditMode() : this.renderViewMode() }
			
		);
	};
}

export default compose(
	withSpokenMessages,
	withSelect( ( select, { clientId } ) =&gt; {
		const { getBlock } = select( 'core/block-editor' );
		return {
			block: getBlock( clientId ),
		};
	} ),
	withDispatch( ( dispatch ) =&gt; {
		const { replaceInnerBlocks } = dispatch( 'core/block-editor' );
		return {
			replaceInnerBlocks,
		};
	} )
)( Editor );
github WordPress / gutenberg / packages / block-editor / src / components / link-control / index.js View on Github external
onKeyPress={ onKeyPress }
						/&gt;
					) }

					{ ! isEditingLink &amp;&amp; (
						
					) }
				
			
		
	);
}

export default compose(
	withInstanceId,
	withSelect( ( select, ownProps ) =&gt; {
		if ( ownProps.fetchSearchSuggestions &amp;&amp; isFunction( ownProps.fetchSearchSuggestions ) ) {
			return;
		}

		const { getSettings } = select( 'core/block-editor' );
		return {
			fetchSearchSuggestions: getSettings().__experimentalFetchLinkSuggestions,
		};
	} )
)( LinkControl );
github ampproject / amp-wp / assets / src / stories-editor / plugins / story-settings-panel.js View on Github external
) }
		
	);
};

MetaFields.propTypes = {
	autoAdvanceAfterOptions: PropTypes.array.isRequired,
	updateMeta: PropTypes.func.isRequired,
	meta: PropTypes.shape( {
		amp_story_auto_advance_after: PropTypes.string,
		amp_story_auto_advance_after_duration: PropTypes.number,
	} ),
};

const EnhancedMetaFields = compose(
	withSelect( ( select ) =&gt; {
		const { getEditedPostAttribute } = select( 'core/editor' );
		const { getSettings } = select( 'amp/story' );
		const { storySettings } = getSettings();
		const { autoAdvanceAfterOptions } = storySettings || {};

		return {
			meta: getEditedPostAttribute( 'meta' ),
			autoAdvanceAfterOptions,
		};
	} ),
	withDispatch( ( dispatch, { meta } ) =&gt; {
		const { editPost } = dispatch( 'core/editor' );
		return {
			updateMeta( newMeta ) {
				editPost( {
					meta: {