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

Commit 90ca8a7

Browse files
authored
Replace 'isPreview' with 'isEditor' when it refers to the editor (#1276)
* Replace 'isPreview' with 'isEditor' in several places * Explicitly set props to true * Add missing propTypes
1 parent 6c3967e commit 90ca8a7

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

assets/js/blocks/active-filters/block.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n';
55
import { useQueryStateByKey } from '@woocommerce/base-hooks';
66
import { useMemo, Fragment } from '@wordpress/element';
77
import classnames from 'classnames';
8+
import PropTypes from 'prop-types';
89

910
/**
1011
* Internal dependencies
@@ -19,7 +20,7 @@ import ActiveAttributeFilters from './active-attribute-filters';
1920
*/
2021
const ActiveFiltersBlock = ( {
2122
attributes: blockAttributes,
22-
isPreview = false,
23+
isEditor = false,
2324
} ) => {
2425
const [ productAttributes, setProductAttributes ] = useQueryStateByKey(
2526
'attributes',
@@ -65,7 +66,7 @@ const ActiveFiltersBlock = ( {
6566
);
6667
};
6768

68-
if ( ! hasFilters() && ! isPreview ) {
69+
if ( ! hasFilters() && ! isEditor ) {
6970
return null;
7071
}
7172

@@ -77,12 +78,12 @@ const ActiveFiltersBlock = ( {
7778

7879
return (
7980
<Fragment>
80-
{ ! isPreview && blockAttributes.heading && (
81+
{ ! isEditor && blockAttributes.heading && (
8182
<TagName>{ blockAttributes.heading }</TagName>
8283
) }
8384
<div className="wc-block-active-filters">
8485
<ul className={ listClasses }>
85-
{ isPreview ? (
86+
{ isEditor ? (
8687
<Fragment>
8788
{ renderRemovableListItem(
8889
__( 'Size', 'woo-gutenberg-products-block' ),
@@ -115,4 +116,15 @@ const ActiveFiltersBlock = ( {
115116
);
116117
};
117118

119+
ActiveFiltersBlock.propTypes = {
120+
/**
121+
* The attributes for this block.
122+
*/
123+
attributes: PropTypes.object.isRequired,
124+
/**
125+
* Whether it's in the editor or frontend display.
126+
*/
127+
isEditor: PropTypes.bool,
128+
};
129+
118130
export default ActiveFiltersBlock;

assets/js/blocks/active-filters/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const Edit = ( { attributes, setAttributes } ) => {
8282
onChange={ ( value ) => setAttributes( { heading: value } ) }
8383
/>
8484
<Disabled>
85-
<Block attributes={ attributes } isPreview />
85+
<Block attributes={ attributes } isEditor={ true } />
8686
</Disabled>
8787
</div>
8888
);

assets/js/blocks/price-filter/block.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { Fragment, useCallback, useState, useEffect } from '@wordpress/element';
1010
import PriceSlider from '@woocommerce/base-components/price-slider';
1111
import { CURRENCY } from '@woocommerce/settings';
1212
import { useDebouncedCallback } from 'use-debounce';
13+
import PropTypes from 'prop-types';
1314

1415
/**
1516
* Component displaying a price filter.
1617
*/
17-
const PriceFilterBlock = ( { attributes, isPreview = false } ) => {
18+
const PriceFilterBlock = ( { attributes, isEditor = false } ) => {
1819
const [ minPriceQuery, setMinPriceQuery ] = useQueryStateByKey(
1920
'min_price'
2021
);
@@ -103,7 +104,7 @@ const PriceFilterBlock = ( { attributes, isPreview = false } ) => {
103104

104105
return (
105106
<Fragment>
106-
{ ! isPreview && attributes.heading && (
107+
{ ! isEditor && attributes.heading && (
107108
<TagName>{ attributes.heading }</TagName>
108109
) }
109110
<div className="wc-block-price-slider">
@@ -126,4 +127,15 @@ const PriceFilterBlock = ( { attributes, isPreview = false } ) => {
126127
);
127128
};
128129

130+
PriceFilterBlock.propTypes = {
131+
/**
132+
* The attributes for this block.
133+
*/
134+
attributes: PropTypes.object.isRequired,
135+
/**
136+
* Whether it's in the editor or frontend display.
137+
*/
138+
isEditor: PropTypes.bool,
139+
};
140+
129141
export default PriceFilterBlock;

assets/js/blocks/price-filter/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export default function( { attributes, setAttributes } ) {
167167
}
168168
/>
169169
<Disabled>
170-
<Block attributes={ attributes } isPreview />
170+
<Block attributes={ attributes } isEditor={ true } />
171171
</Disabled>
172172
</div>
173173
) }

assets/js/blocks/product-search/block.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class ProductSearchBlock extends Component {
152152
}
153153

154154
render() {
155-
if ( this.props.isPreview ) {
155+
if ( this.props.isEditor ) {
156156
return this.renderEdit();
157157
}
158158

@@ -170,9 +170,9 @@ ProductSearchBlock.propTypes = {
170170
*/
171171
instanceId: PropTypes.number,
172172
/**
173-
* Whether this is the block preview or frontend display.
173+
* Whether it's in the editor or frontend display.
174174
*/
175-
isPreview: PropTypes.bool,
175+
isEditor: PropTypes.bool,
176176
/**
177177
* A callback to update attributes.
178178
*/

assets/js/blocks/product-search/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ registerBlockType( 'woocommerce/product-search', {
113113
/>
114114
</PanelBody>
115115
</InspectorControls>
116-
<Block { ...props } isPreview />
116+
<Block { ...props } isEditor={ true } />
117117
</Fragment>
118118
);
119119
},

0 commit comments

Comments
 (0)