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

Reorganise Columns controls and fix undefined problem in Product Collection settings #11937

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@ const ColumnsControl = ( props: DisplayLayoutToolbarProps ) => {
return showColumnsControl ? (
<>
<ToolsPanelItem
label={ columnsLabel }
hasValue={ () =>
defaultLayout?.shrinkColumns !== shrinkColumns
defaultLayout?.columns !== columns ||
defaultLayout?.type !== type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the "defaultLayout?.type !== type" condition is necessary. In my view, "defaultLayout?.columns !== columns" should suffice. no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I applied your suggestion!

}
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
Loading