Skip to content

Commit

Permalink
Block Library: Remove client side variation fallbacks (#42180)
Browse files Browse the repository at this point in the history
* Block Library: Remove client side variation fallbacks

* Remove fallback test
  • Loading branch information
Mamaduka authored Jul 7, 2022
1 parent c74e1e8 commit 0e4747d
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 246 deletions.
65 changes: 0 additions & 65 deletions packages/block-library/src/navigation-link/fallback-variations.js

This file was deleted.

14 changes: 0 additions & 14 deletions packages/block-library/src/navigation-link/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import {
customPostType,
} from '@wordpress/icons';

/**
* Internal dependencies
*/
import fallbackVariations from './fallback-variations';

function getIcon( variationName ) {
switch ( variationName ) {
case 'post':
Expand All @@ -34,15 +29,6 @@ export function enhanceNavigationLinkVariations( settings, name ) {
return settings;
}

// Fallback handling may be deleted after supported WP ranges understand the `variations`
// property when passed to register_block_type in index.php.
if ( ! settings.variations ) {
return {
...settings,
variations: fallbackVariations,
};
}

// Otherwise decorate server passed variations with an icon and isActive function.
if ( settings.variations ) {
const isActive = ( blockAttributes, variationAttributes ) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,98 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`hooks enhanceNavigationLinkVariations adds fallback variations when variations are missing 1`] = `
Object {
"name": "core/navigation-link",
"one": "one",
"three": "three",
"two": "two",
"variations": Array [
Object {
"attributes": Object {},
"description": "A link to a custom URL.",
"isActive": [Function],
"isDefault": true,
"name": "link",
"title": "Custom Link",
},
Object {
"attributes": Object {
"kind": "post-type",
"type": "post",
},
"description": "A link to a post.",
"icon": <SVG
viewBox="0 0 24 24"
xmlns="https://www.w3.org/2000/svg"
>
<Path
d="M4 20h16v-1.5H4V20zm0-4.8h16v-1.5H4v1.5zm0-6.4v1.5h16V8.8H4zM16 4H4v1.5h12V4z"
/>
</SVG>,
"isActive": [Function],
"name": "post",
"title": "Post Link",
},
Object {
"attributes": Object {
"kind": "post-type",
"type": "page",
},
"description": "A link to a page.",
"icon": <SVG
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<Path
d="M7 5.5h10a.5.5 0 01.5.5v12a.5.5 0 01-.5.5H7a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM17 4H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V6a2 2 0 00-2-2zm-1 3.75H8v1.5h8v-1.5zM8 11h8v1.5H8V11zm6 3.25H8v1.5h6v-1.5z"
/>
</SVG>,
"isActive": [Function],
"name": "page",
"title": "Page Link",
},
Object {
"attributes": Object {
"kind": "taxonomy",
"type": "category",
},
"description": "A link to a category.",
"icon": <SVG
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<Path
clipRule="evenodd"
d="M6 5.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm11-.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5h-3a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM13 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2h-3a2 2 0 01-2-2V6zm5 8.5h-3a.5.5 0 00-.5.5v3a.5.5 0 00.5.5h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5zM15 13a2 2 0 00-2 2v3a2 2 0 002 2h3a2 2 0 002-2v-3a2 2 0 00-2-2h-3zm-9 1.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5zM4 15a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2v-3z"
fillRule="evenodd"
/>
</SVG>,
"isActive": [Function],
"name": "category",
"title": "Category Link",
},
Object {
"attributes": Object {
"kind": "taxonomy",
"type": "tag",
},
"description": "A link to a tag.",
"icon": <SVG
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<Path
d="M20.1 11.2l-6.7-6.7c-.1-.1-.3-.2-.5-.2H5c-.4-.1-.8.3-.8.7v7.8c0 .2.1.4.2.5l6.7 6.7c.2.2.5.4.7.5s.6.2.9.2c.3 0 .6-.1.9-.2.3-.1.5-.3.8-.5l5.6-5.6c.4-.4.7-1 .7-1.6.1-.6-.2-1.2-.6-1.6zM19 13.4L13.4 19c-.1.1-.2.1-.3.2-.2.1-.4.1-.6 0-.1 0-.2-.1-.3-.2l-6.5-6.5V5.8h6.8l6.5 6.5c.2.2.2.4.2.6 0 .1 0 .3-.2.5zM9 8c-.6 0-1 .4-1 1s.4 1 1 1 1-.4 1-1-.4-1-1-1z"
/>
</SVG>,
"isActive": [Function],
"name": "tag",
"title": "Tag Link",
},
],
}
`;

exports[`hooks enhanceNavigationLinkVariations enhances variations with icon and isActive functions 1`] = `
Object {
"extraProp": "extraProp",
Expand Down
12 changes: 0 additions & 12 deletions packages/block-library/src/navigation-link/test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ describe( 'hooks', () => {
three: 'three',
} );
} );
it( 'adds fallback variations when variations are missing', () => {
const updatedSettings = enhanceNavigationLinkVariations(
{
name: 'core/navigation-link',
one: 'one',
two: 'two',
three: 'three',
},
'core/navigation-link'
);
expect( updatedSettings ).toMatchSnapshot();
} );
it( 'enhances variations with icon and isActive functions', () => {
const updatedSettings = enhanceNavigationLinkVariations(
{
Expand Down
51 changes: 0 additions & 51 deletions packages/block-library/src/template-part/fallback-variations.js

This file was deleted.

11 changes: 0 additions & 11 deletions packages/block-library/src/template-part/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import {
symbolFilled as symbolFilledIcon,
} from '@wordpress/icons';

/**
* Internal dependencies
*/
import fallbackVariations from './fallback-variations';

function getTemplatePartIcon( iconName ) {
if ( 'header' === iconName ) {
return headerIcon;
Expand All @@ -31,12 +26,6 @@ export function enhanceTemplatePartVariations( settings, name ) {
return settings;
}

// WordPress versions pre-5.8 do not support server side variation registration.
// So we must register the fallback variations until those versions are no longer supported.
if ( ! ( settings.variations && settings.variations.length ) ) {
return { ...settings, variations: fallbackVariations };
}

if ( settings.variations ) {
const isActive = ( blockAttributes, variationAttributes ) => {
const { area, theme, slug } = blockAttributes;
Expand Down

0 comments on commit 0e4747d

Please sign in to comment.