Skip to content

Commit 01d2cad

Browse files
fix (migration): do not re-migrate button gradient color if it's already migrated before. 2nd take
1 parent 8374933 commit 01d2cad

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/block-components/button/deprecated.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ export const deprecateButtonGradientColor = {
3232
return getAttribute( 'backgroundColorType' ) === 'gradient' && getAttribute( 'backgroundColor2' )
3333
},
3434
migrate: attrNameTemplate => attributes => {
35-
// Do not migrate if the attributes are not eligible.
36-
if ( ! deprecateButtonGradientColor.isEligible( attrNameTemplate )( attributes ) ) {
37-
return attributes
38-
}
39-
4035
const getAttrName = getAttrNameFunction( attrNameTemplate )
4136
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
4237

@@ -59,13 +54,21 @@ export const deprecateButtonGradientColor = {
5954
const color2ParentHover = getAttribute( 'backgroundColor2ParentHover' ) || color1ParentHover
6055
const gradientDirectionParentHover = getAttribute( 'backgroundGradientDirectionParentHover' ) || getAttribute( 'backgroundGradientDirectionParentHover' ) === 0 ? getAttribute( 'backgroundGradientDirectionParentHover' ) : 90
6156

62-
if ( color1 && color2 ) {
57+
const isColor1Gradient = color1 && color1.includes( 'linear-gradient' )
58+
const isColor2Gradient = color2 && color2.includes( 'linear-gradient' )
59+
if ( color1 && color2 && ! isColor1Gradient && ! isColor2Gradient ) {
6360
newAttributes[ getAttrName( 'backgroundColor' ) ] = `linear-gradient(${ gradientDirection }deg, ${ color1 } 0%, ${ color2 } 100%)`
6461
}
65-
if ( color1Hover && color2Hover ) {
62+
63+
const isColor1HoverGradient = color1Hover && color1Hover.includes( 'linear-gradient' )
64+
const isColor2HoverGradient = color2Hover && color2Hover.includes( 'linear-gradient' )
65+
if ( color1Hover && color2Hover && ! isColor1HoverGradient && ! isColor2HoverGradient ) {
6666
newAttributes[ getAttrName( 'backgroundColorHover' ) ] = `linear-gradient(${ gradientDirectionHover }deg, ${ color1Hover } 0%, ${ color2Hover } 100%)`
6767
}
68-
if ( color1ParentHover && color2ParentHover ) {
68+
69+
const isColor1ParentHoverGradient = color1ParentHover && color1ParentHover.includes( 'linear-gradient' )
70+
const isColor2ParentHoverGradient = color2ParentHover && color2ParentHover.includes( 'linear-gradient' )
71+
if ( color1ParentHover && color2ParentHover && ! isColor1ParentHoverGradient && ! isColor2ParentHoverGradient ) {
6972
newAttributes[ getAttrName( 'backgroundColorParentHover' ) ] = `linear-gradient(${ gradientDirectionParentHover }deg, ${ color1ParentHover } 0%, ${ color2ParentHover } 100%)`
7073
}
7174
}

0 commit comments

Comments
 (0)