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

Commit

Permalink
Reorganise Columns controls and fix undefined problem in Product Coll…
Browse files Browse the repository at this point in the history
…ection settings (#11937)

* Reorganise Columns controls and fix undefined problem in Product Collection settings

* Remove type condition in hasValue of Columns control

* Adjust the E2E tests locator to new changes
  • Loading branch information
kmanijak authored Nov 28, 2023
1 parent 5634c76 commit 906b9a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ import {
import { DisplayLayoutToolbarProps } from '../types';
import { getDefaultDisplayLayout } from '../constants';

const toggleLabel = __(
'Shrink columns to fit',
'woo-gutenberg-products-block'
);

const columnsLabel = __( 'Columns', 'woo-gutenberg-products-block' );
const toggleLabel = __( 'Responsive', 'woo-gutenberg-products-block' );
const toggleHelp = __(
'Reduce the number of columns to better fit smaller screens and spaces.',
'Automatically adjust the number of columns to better fit smaller screens.',
'woo-gutenberg-products-block'
);

const getColumnsLabel = ( shrinkColumns: boolean ) =>
shrinkColumns
? __( 'Max Columns', 'woo-gutenberg-products-block' )
: __( 'Columns', 'woo-gutenberg-products-block' );

const ColumnsControl = ( props: DisplayLayoutToolbarProps ) => {
const { type, columns, shrinkColumns } = props.displayLayout;
const showColumnsControl = type === 'flex';
Expand Down Expand Up @@ -63,33 +55,32 @@ const ColumnsControl = ( props: DisplayLayoutToolbarProps ) => {
return showColumnsControl ? (
<>
<ToolsPanelItem
hasValue={ () =>
defaultLayout?.shrinkColumns !== shrinkColumns
}
label={ columnsLabel }
hasValue={ () => defaultLayout?.columns !== columns }
isShownByDefault
onDeselect={ onPanelDeselect }
>
<ToggleControl
checked={ !! shrinkColumns }
label={ toggleLabel }
help={ toggleHelp }
onChange={ onShrinkColumnsToggleChange }
<RangeControl
label={ columnsLabel }
onChange={ onColumnsChange }
value={ columns }
min={ 2 }
max={ Math.max( 6, columns ) }
/>
</ToolsPanelItem>
<ToolsPanelItem
label={ toggleLabel }
hasValue={ () =>
defaultLayout?.columns !== columns ||
defaultLayout?.type !== type
defaultLayout?.shrinkColumns !== shrinkColumns
}
isShownByDefault
onDeselect={ onPanelDeselect }
>
<RangeControl
label={ getColumnsLabel( !! shrinkColumns ) }
onChange={ onColumnsChange }
value={ columns }
min={ 2 }
max={ Math.max( 6, columns ) }
<ToggleControl
checked={ !! shrinkColumns }
label={ toggleLabel }
help={ toggleHelp }
onChange={ onShrinkColumnsToggleChange }
/>
</ToolsPanelItem>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SELECTORS = {
onSaleControlLabel: 'Show only products on sale',
inheritQueryFromTemplateControl:
'.wc-block-product-collection__inherit-query-control',
shrinkColumnsToFit: 'Shrink columns to fit',
shrinkColumnsToFit: 'Responsive',
productSearchLabel: 'Search',
productSearchButton: '.wp-block-search__button wp-element-button',
};
Expand Down

0 comments on commit 906b9a5

Please sign in to comment.