Skip to content

Commit ce4754a

Browse files
QA from Coderabbit comments fixed
1 parent 32c64d2 commit ce4754a

File tree

11 files changed

+47
-27
lines changed

11 files changed

+47
-27
lines changed

src/components/guided-modal-tour/tours/blocks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export const blocks = {
7777
)
7878

7979
// Delete all blocks
80-
const allBlocks = select( 'core/block-editor' ).getBlocks()
81-
dispatch( 'core/block-editor' ).removeBlocks( allBlocks.map( block => block.clientId ) )
80+
// const allBlocks = select( 'core/block-editor' ).getBlocks()
81+
// dispatch( 'core/block-editor' ).removeBlocks( allBlocks.map( block => block.clientId ) )
8282

8383
// Insert our block
8484
dispatch( 'core/block-editor' ).insertBlocks( [ blockObject ], 0 )

src/components/guided-modal-tour/tours/design-library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const designLibrary = {
4242
postStep: () => {
4343
const el = document.querySelector( '.ugb-modal-design-library__enable-background input' )
4444
// If the input is not checked, click the button.
45-
if ( ! el.checked ) {
45+
if ( el && ! el.checked ) {
4646
el.click()
4747
}
4848
},

src/components/guided-modal-tour/tours/design-system.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const designSystem = {
8282
// Scroll this to the top.
8383
el.scrollTo( {
8484
top: 0,
85-
behavior: 'instant',
85+
behavior: 'auto',
8686
} )
8787
}
8888
},

src/components/style-guide/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export { default as StyleGuidePopover } from './popover'
2020

2121
// TODO: This is not yet finished
2222
const StyleGuide = props => {
23-
const { designSystem, contentRef = null } = props
23+
const { designSystem = {}, contentRef = null } = props
2424

2525
const {
26-
colors,
26+
colors = [],
2727
colorSchemes = DUMMY_COLOR_SCHEMES,
2828
typography = {
2929
desktop: [], tablet: [], mobile: [],
@@ -33,7 +33,8 @@ const StyleGuide = props => {
3333
previewClassNames = '',
3434
} = designSystem
3535

36-
const THEME_STYLES = wpGlobalStylesInlineCss.replaceAll( ':root', '&' ).replace( /[^\-](\bbody)/g, ( match, p1 ) => {
36+
const src = typeof wpGlobalStylesInlineCss === 'string' ? wpGlobalStylesInlineCss : ''
37+
const THEME_STYLES = src.replaceAll( ':root', '&' ).replace( /[^\-](\bbody)/g, ( match, p1 ) => {
3738
return match.replace( p1, '.ugb-style-guide__preview-root' )
3839
} )
3940

src/components/style-guide/popover.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const StyleGuidePopover = props => {
4747
className="ugb-style-guide-popover__close-button"
4848
variant="tertiary"
4949
onClick={ onClose }
50+
aria-label={ __( 'Close', i18n ) }
5051
>
5152
<Icon icon={ closeIcon } />
5253
</Button>
@@ -87,7 +88,7 @@ const ExportButton = props => {
8788
return (
8889
<Button
8990
className="ugb-style-guide__print-button"
90-
isSecondary
91+
variant="secondary"
9192
onClick={ handlePrint }
9293
icon={ <Icon icon={ downloadIcon } /> }
9394
isBusy={ isExporting }

src/components/style-guide/utils.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,16 @@ const ADDITIONAL_ATTRIBUTES = {
157157

158158
const INNER_BLOCK_CALLBACKS = {
159159
'stackable/team-member': innerBlocks => {
160-
innerBlocks[ 0 ].attributes.imageExternalUrl = `${ srcUrl }/${ profile }`
160+
if ( innerBlocks?.[ 0 ]?.attributes ) {
161+
innerBlocks[ 0 ].attributes.imageExternalUrl = `${ srcUrl }/${ profile }`
162+
}
161163

162164
return innerBlocks
163165
},
164166
'stackable/testimonial': innerBlocks => {
165-
innerBlocks[ 1 ].attributes.imageExternalUrl = `${ srcUrl }/${ profile }`
167+
if ( innerBlocks?.[ 1 ]?.attributes ) {
168+
innerBlocks[ 1 ].attributes.imageExternalUrl = `${ srcUrl }/${ profile }`
169+
}
166170

167171
return innerBlocks
168172
},
@@ -199,7 +203,8 @@ export const DefaultOutlineButton = ( {
199203
}
200204

201205
const getGeneratedCss = ( blocks, generateForInnerBlocks = false ) => {
202-
return blocks.map( block => {
206+
const list = Array.isArray( blocks ) ? blocks : []
207+
return list.map( block => {
203208
if ( ! block.attributes.uniqueId ) {
204209
block.attributes.uniqueId = createUniqueClass( block.clientId )
205210
}
@@ -220,7 +225,7 @@ const getGeneratedCss = ( blocks, generateForInnerBlocks = false ) => {
220225

221226
block.attributes.generatedCss = saveCss
222227

223-
if ( generateForInnerBlocks ) {
228+
if ( generateForInnerBlocks && Array.isArray( block.innerBlocks ) ) {
224229
block.innerBlocks = getGeneratedCss( block.innerBlocks, generateForInnerBlocks )
225230
}
226231

@@ -290,10 +295,12 @@ export const RenderBlock = props => {
290295
} = getSerializedBlock( propsToPass )
291296

292297
return (
293-
<RawHTML>
294-
{ cleanSerializedBlock( serialized, SERIALIZE_CALLBACKS[ blockName ], attributes ) }
295-
{ `<p>${ name }</p>` }
296-
</RawHTML>
298+
<>
299+
<RawHTML>
300+
{ cleanSerializedBlock( serialized, SERIALIZE_CALLBACKS[ blockName ], attributes ) }
301+
</RawHTML>
302+
<p>{ name }</p>
303+
</>
297304
)
298305
}
299306

src/hooks/use-design-system.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export const useDesignSystem = () => {
6969

7070
const buttonIconStyles = useMemo( () => {
7171
return renderGlobalBlockLayoutStyles( buttonsAndIcons, blockLayoutDefaults, NOOP, 'normal', null, null, true )?.replaceAll( ':root', '.ugb-style-guide__preview-root' ) || ''
72-
}, [ buttonsAndIcons ] )
72+
}, [ buttonsAndIcons, blockLayoutDefaults ] )
7373

7474
const spacingBorderStyles = useMemo( () => {
7575
return renderGlobalBlockLayoutStyles( spacingAndBorders, blockLayoutDefaults, NOOP, 'normal', null, null, true )?.replaceAll( ':root', '.ugb-style-guide__preview-root, .ugb-style-guide__preview' ) || ''
76-
}, [ spacingAndBorders ] )
76+
}, [ spacingAndBorders, blockLayoutDefaults ] )
7777

7878
const {
7979
getSortedColorSchemes,

src/plugins/global-settings/colors/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-colors', out
113113
<p className="components-base-control__help">
114114
{ __( 'Change your color palette for all your blocks across your site.', i18n ) }
115115
&nbsp;
116-
<a href="https://docs.wpstackable.com/article/362-how-to-use-global-colors?utm_source=wp-global-settings&utm_campaign=learnmore&utm_medium=gutenberg" target="_docs">
116+
<a href="https://docs.wpstackable.com/article/362-how-to-use-global-colors?utm_source=wp-global-settings&utm_campaign=learnmore&utm_medium=gutenberg" target="_docs" rel="noopener noreferrer">
117117
{ __( 'Learn more about Global Colors', i18n ) }
118118
</a>
119119
</p>

src/plugins/guided-modal-tour-trigger/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,29 @@ import { dispatch } from '@wordpress/data'
1010

1111
const TourTrigger = () => {
1212
useEffect( () => {
13-
// Check th
14-
const tourId = window?.location?.search?.includes( 'tour=' ) ? window?.location?.search?.split( 'tour=' )[ 1 ] : null
13+
// Check the GET parameter for the tour ID.
14+
const params = new URLSearchParams( window?.location?.search || '' )
15+
const tourId = params.get( 'tour' )
16+
const tids = []
17+
1518
switch ( tourId ) {
1619
case 'editor':
1720
// When the editor tour is to be shown, no need to do anything here.
1821
break
1922
case 'design-library':
2023
// When the design library tour is to be shown, simluate a click on the design library button.
21-
setTimeout( () => {
24+
tids.push( setTimeout( () => {
2225
document.querySelector( '.ugb-insert-library-button' )?.click()
23-
}, 500 )
26+
}, 500 ) )
2427
break
2528
case 'design-system':
2629
// When the design system tour is to be shown, open the sidebar
27-
setTimeout( () => {
30+
tids.push( setTimeout( () => {
2831
dispatch( 'core/edit-post' )?.openGeneralSidebar( 'stackable-global-settings/sidebar' ) // For Block Editor
29-
}, 500 )
32+
}, 500 ) )
3033
}
34+
35+
return () => tids.forEach( id => clearTimeout( id ) )
3136
}, [] )
3237

3338
return null

src/util/block-templates.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { i18n } from 'stackable'
22

3-
import { __, sprintf } from '@wordpress/i18n'
3+
import {
4+
__, _x, sprintf,
5+
} from '@wordpress/i18n'
46

57
export const LONG_TEXT = [
68
// Translators: This is placeholder text used in the style guide.
@@ -142,7 +144,7 @@ const TIMELINE_TEMPLATE = [
142144
left: 0,
143145
},
144146
}, [
145-
[ 'stackable/text', { text: __( 'Description for this block. Use this space for describing your block. Any text will do.', 'Content placeholder', i18n ) } ],
147+
[ 'stackable/text', { text: _x( 'Description for this block. Use this space for describing your block. Any text will do.', 'Content placeholder', i18n ) } ],
146148
] ],
147149
]
148150

0 commit comments

Comments
 (0)