Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails…
Browse files Browse the repository at this point in the history
… position bug when initially adding the Product Gallery block
  • Loading branch information
danieldudzic committed Jul 29, 2023
1 parent a2171c0 commit 54d195b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions assets/js/blocks/product-gallery/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ export const Edit = ( {
}: BlockEditProps< BlockAttributes > ) => {
const blockProps = useBlockProps();

// Update the Group block type when the thumbnailsPosition attribute changes.
updateGroupBlockType( attributes, clientId );

useEffect( () => {
setAttributes( {
...attributes,
productGalleryClientId: clientId,
} );
// Update the Group block type when the thumbnailsPosition attribute changes.
updateGroupBlockType( attributes, clientId );
// Move the Thumbnails block to the correct above or below the Large Image based on the thumbnailsPosition attribute.
moveInnerBlocksToPosition( attributes, clientId );
}, [ setAttributes, attributes, clientId ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ import { ThumbnailsPosition } from '../constants';
import type { ThumbnailsSettingProps } from '../../../types';

const positionHelp: Record< ThumbnailsPosition, string > = {
[ ThumbnailsPosition.Off ]: __(
[ ThumbnailsPosition.OFF ]: __(
'No thumbnails will be displayed.',
'woo-gutenberg-products-block'
),
[ ThumbnailsPosition.Left ]: __(
[ ThumbnailsPosition.LEFT ]: __(
'A strip of small images will appear to the left of the main gallery image.',
'woo-gutenberg-products-block'
),
[ ThumbnailsPosition.Bottom ]: __(
[ ThumbnailsPosition.BOTTOM ]: __(
'A strip of small images will appear below the main gallery image.',
'woo-gutenberg-products-block'
),
[ ThumbnailsPosition.Right ]: __(
[ ThumbnailsPosition.RIGHT ]: __(
'A strip of small images will appear to the right of the main gallery image.',
'woo-gutenberg-products-block'
),
Expand Down Expand Up @@ -81,17 +81,17 @@ export const BlockSettings = ( { context }: ThumbnailsSettingProps ) => {
}
>
<ToggleGroupControlOption
value={ ThumbnailsPosition.Off }
value={ ThumbnailsPosition.OFF }
label={ __( 'Off', 'woo-gutenberg-products-block' ) }
/>
<ToggleGroupControlOption
value={ ThumbnailsPosition.Left }
value={ ThumbnailsPosition.LEFT }
label={
<Icon size={ 32 } icon={ thumbnailsPositionLeft } />
}
/>
<ToggleGroupControlOption
value={ ThumbnailsPosition.Bottom }
value={ ThumbnailsPosition.BOTTOM }
label={
<Icon
size={ 32 }
Expand All @@ -100,7 +100,7 @@ export const BlockSettings = ( { context }: ThumbnailsSettingProps ) => {
}
/>
<ToggleGroupControlOption
value={ ThumbnailsPosition.Right }
value={ ThumbnailsPosition.RIGHT }
label={
<Icon
size={ 32 }
Expand All @@ -109,7 +109,7 @@ export const BlockSettings = ( { context }: ThumbnailsSettingProps ) => {
}
/>
</ToggleGroupControl>
{ context.thumbnailsPosition !== ThumbnailsPosition.Off && (
{ context.thumbnailsPosition !== ThumbnailsPosition.OFF && (
<RangeControl
label={ __(
'Number of Thumbnails',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum ThumbnailsPosition {
'Off' = 'off',
'Left' = 'left',
'Bottom' = 'bottom',
'Right' = 'right',
OFF = 'off',
LEFT = 'left',
BOTTOM = 'bottom',
RIGHT = 'right',
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Edit = ( {
const Placeholder = () => {
return (
<>
{ context.thumbnailsPosition !== ThumbnailsPosition.Off && (
{ context.thumbnailsPosition !== ThumbnailsPosition.OFF && (
<div className="wc-block-editor-product-gallery-thumbnails">
{ [
...Array(
Expand Down

0 comments on commit 54d195b

Please sign in to comment.