Skip to content

Commit e6104b2

Browse files
authored
Block: OpenTable: Add a warning if width is set to anything other than wide or full if style is wide (#15323)
1 parent 4e74ee9 commit e6104b2

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

extensions/blocks/opentable/edit.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from '@wordpress/components';
2020
import { __, sprintf } from '@wordpress/i18n';
2121
import { getBlockDefaultClassName } from '@wordpress/blocks';
22+
import { useEffect } from '@wordpress/element';
2223

2324
/**
2425
* Internal dependencies
@@ -55,7 +56,29 @@ function OpenTableEdit( {
5556
setAttributes( validatedAttributes );
5657
}
5758

58-
const { align, rid, style, iframe, domain, lang, newtab } = attributes;
59+
const { align, rid, style, iframe, domain, lang, newtab, __isBlockPreview } = attributes;
60+
const isPlaceholder = isEmpty( rid );
61+
62+
useEffect( () => {
63+
noticeOperations.removeAllNotices();
64+
if (
65+
! isPlaceholder &&
66+
! __isBlockPreview &&
67+
'wide' === style &&
68+
'wide' !== align &&
69+
'full' !== align
70+
) {
71+
const content = (
72+
<>
73+
{ __(
74+
'With the OpenTable block you may encounter display issues if you use its "wide" style with anything other than "wide" or "full" alignment. The wide display style may also not work well on smaller screens.',
75+
'jetpack'
76+
) }
77+
</>
78+
);
79+
noticeOperations.createNotice( { status: 'warning', content } );
80+
}
81+
}, [ __isBlockPreview, align, isPlaceholder, noticeOperations, rid, style ] );
5982

6083
const parseEmbedCode = embedCode => {
6184
const newAttributes = getAttributesFromEmbedCode( embedCode );
@@ -197,17 +220,20 @@ function OpenTableEdit( {
197220
);
198221

199222
const editClasses = classnames( className, {
200-
[ `${ defaultClassName }-theme-${ style }` ]: ! isEmpty( rid ) && styleValues.includes( style ),
201-
'is-placeholder': isEmpty( rid ),
223+
[ `${ defaultClassName }-theme-${ style }` ]: ! isPlaceholder && styleValues.includes( style ),
224+
'is-placeholder': isPlaceholder,
202225
'is-multi': 'multi' === getTypeAndTheme( style )[ 0 ],
203226
[ `align${ align }` ]: align,
204227
} );
205228

206229
return (
207-
<div className={ editClasses }>
208-
{ ! isEmpty( rid ) && inspectorControls }
209-
{ ! isEmpty( rid ) ? blockPreview() : blockPlaceholder }
210-
</div>
230+
<>
231+
{ noticeUI }
232+
<div className={ editClasses }>
233+
{ ! isPlaceholder && inspectorControls }
234+
{ ! isPlaceholder ? blockPreview() : blockPlaceholder }
235+
</div>
236+
</>
211237
);
212238
}
213239

extensions/blocks/opentable/editor.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@
107107
}
108108
}
109109

110+
.wp-block[data-type="jetpack/opentable"] {
111+
.components-notice__content {
112+
text-align: left;
113+
}
114+
}
115+
110116
.components-toggle-control.is-opentable {
111117
padding-top: 6px;
112118
}

0 commit comments

Comments
 (0)