Skip to content
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

Social Links: Add filter to services data to enable extendibility #30749

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { keyboardReturn } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { getIconBySite, getNameBySite } from './social-list';
import { useServiceIcon, useServiceName } from './social-list';

const SocialLinkURLPopover = ( {
url,
Expand Down Expand Up @@ -77,8 +77,8 @@ const SocialLinkEdit = ( {
} );

const ref = useRef();
const IconComponent = getIconBySite( service );
const socialLinkName = getNameBySite( service );
const IconComponent = useServiceIcon( service );
const socialLinkName = useServiceName( service );
const blockProps = useBlockProps( {
className: classes,
style: {
Expand Down
14 changes: 5 additions & 9 deletions packages/block-library/src/social-link/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import {
} from '@wordpress/components';
import { compose, usePreferredColorSchemeStyle } from '@wordpress/compose';
import { __, sprintf } from '@wordpress/i18n';
import { link, Icon } from '@wordpress/icons';
import { link } from '@wordpress/icons';
import { withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { getIconBySite, getNameBySite } from './social-list';
import { useServiceIcon, useServiceName } from './social-list';
import styles from './editor.scss';

const ANIMATION_DELAY = 300;
Expand Down Expand Up @@ -65,8 +65,8 @@ const SocialLinkEdit = ( {

const animatedValue = useRef( new Animated.Value( 0 ) ).current;

const IconComponent = getIconBySite( service )();
const socialLinkName = getNameBySite( service );
const IconComponent = useServiceIcon( service );
const socialLinkName = useServiceName( service );

// When new social icon is added link sheet is opened automatically
useEffect( () => {
Expand Down Expand Up @@ -192,11 +192,7 @@ const SocialLinkEdit = ( {
<Animated.View
style={ [ styles.iconContainer, { backgroundColor } ] }
>
<Icon
animated
icon={ IconComponent }
style={ { stroke, color } }
/>
<IconComponent animated style={ { stroke, color } } />
</Animated.View>
</TouchableWithoutFeedback>
</View>
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/social-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ function block_core_social_link_services( $service = '', $field = '' ) {
),
);

$services_data = apply_filters( 'block_editor_social_link_services', $services_data );

mkaz marked this conversation as resolved.
Show resolved Hide resolved
if ( ! empty( $service )
&& ! empty( $field )
&& isset( $services_data[ $service ] )
Expand Down
15 changes: 12 additions & 3 deletions packages/block-library/src/social-link/social-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { find } from 'lodash';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import variations from './variations';
import { ChainIcon } from './icons';

/**
Expand All @@ -21,7 +22,11 @@ import { ChainIcon } from './icons';
*
* @return {WPComponent} Icon component for social service.
*/
export const getIconBySite = ( name ) => {
export const useServiceIcon = ( name ) => {
const variations = useSelect( ( select ) => {
const { getBlockVariations } = select( blocksStore );
return getBlockVariations( 'core/social-link', 'block' );
} );
const variation = find( variations, { name } );
return variation ? variation.icon : ChainIcon;
};
Expand All @@ -33,7 +38,11 @@ export const getIconBySite = ( name ) => {
*
* @return {string} Display name for social service
*/
export const getNameBySite = ( name ) => {
export const useServiceName = ( name ) => {
const variations = useSelect( ( select ) => {
const { getBlockVariations } = select( blocksStore );
return getBlockVariations( 'core/social-link', 'block' );
} );
const variation = find( variations, { name } );
return variation ? variation.title : __( 'Social Icon' );
};