-
Notifications
You must be signed in to change notification settings - Fork 219
Convert filter blocks to inner blocks #6978
Changes from 32 commits
0580f81
6ea437e
a81be07
8b6cb7c
5a52b47
6593c13
b95a157
a88647f
225c0fa
4c6f1f0
49236d8
37e78a8
b5e039e
b2754c7
82889ff
3ba7237
3d02766
83b7fee
00e94f1
e423340
c3b9c67
e14fe84
bb6973a
42ac2b4
1cc05c6
0eb484c
deedc4a
7e6b2ea
d1b4512
311b512
0d17886
0827141
69cea5b
6731264
81bbadb
4e42ac4
d5ae52b
c0984ac
ce3ed78
5305611
29542e1
a903151
e1f0f33
b3d4d56
a44ad73
e1a9901
959c8b5
5bb547a
ddfc5d7
ef0b035
a44513a
4e41b0a
f0b9ebc
dd70a77
941f1af
2a9d2ee
b538432
6a1e87d
4845321
e861133
2660784
2e7344c
4686e91
6f49f57
c2c25c9
4e91226
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ import { Icon, category, external } from '@wordpress/icons'; | |
import { SearchListControl } from '@woocommerce/editor-components/search-list-control'; | ||
import { sortBy } from 'lodash'; | ||
import { getAdminLink, getSetting } from '@woocommerce/settings'; | ||
import HeadingToolbar from '@woocommerce/editor-components/heading-toolbar'; | ||
import BlockTitle from '@woocommerce/editor-components/block-title'; | ||
import classnames from 'classnames'; | ||
import { SearchListItemsType } from '@woocommerce/editor-components/search-list-control/types'; | ||
|
@@ -37,10 +36,16 @@ import { | |
import Block from './block'; | ||
import './editor.scss'; | ||
import type { EditProps } from './types'; | ||
import { UpgradeToolbarButton } from '../filter-wrapper/upgrade'; | ||
|
||
const ATTRIBUTES = getSetting< AttributeSetting[] >( 'attributes', [] ); | ||
|
||
const Edit = ( { attributes, setAttributes, debouncedSpeak }: EditProps ) => { | ||
const Edit = ( { | ||
attributes, | ||
setAttributes, | ||
debouncedSpeak, | ||
clientId, | ||
}: EditProps ) => { | ||
const { | ||
attributeId, | ||
className, | ||
|
@@ -91,15 +96,15 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak }: EditProps ) => { | |
return; | ||
} | ||
|
||
const attributeName = productAttribute.attribute_label; | ||
// const attributeName = productAttribute.attribute_label; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we should remove this commented code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will do that eventually. I'm leaving it here while working on the dynamic title. For the attribute filter block, the block title is updated automatically after store admins selected an attribute. We're losing this feature on this PR. I will look at this again before other higher priority parts are addressed (E2E test, block upgrade) |
||
|
||
setAttributes( { | ||
attributeId: selectedId as number, | ||
heading: sprintf( | ||
/* translators: %s attribute name. */ | ||
__( 'Filter by %s', 'woo-gutenberg-products-block' ), | ||
attributeName | ||
), | ||
// heading: sprintf( | ||
// /* translators: %s attribute name. */ | ||
// __( 'Filter by %s', 'woo-gutenberg-products-block' ), | ||
// attributeName | ||
// ), | ||
} ); | ||
}; | ||
|
||
|
@@ -183,21 +188,6 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak }: EditProps ) => { | |
} ) | ||
} | ||
/> | ||
<p> | ||
{ __( | ||
'Heading Level', | ||
'woo-gutenberg-products-block' | ||
) } | ||
</p> | ||
<HeadingToolbar | ||
isCollapsed={ false } | ||
minLevel={ 2 } | ||
maxLevel={ 7 } | ||
selectedLevel={ headingLevel } | ||
onChange={ ( newLevel: number ) => | ||
setAttributes( { headingLevel: newLevel } ) | ||
} | ||
/> | ||
<ToggleGroupControl | ||
label={ __( | ||
'Allow selecting multiple options?', | ||
|
@@ -412,6 +402,12 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak }: EditProps ) => { | |
<div { ...blockProps }> | ||
{ getBlockControls() } | ||
{ getInspectorControls() } | ||
<UpgradeToolbarButton | ||
clientId={ clientId } | ||
attributes={ attributes } | ||
setAttributes={ setAttributes } | ||
filterType="attribute-filter" | ||
/> | ||
{ isEditing ? ( | ||
renderEditMode() | ||
) : ( | ||
|
@@ -421,14 +417,16 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak }: EditProps ) => { | |
'wc-block-attribute-filter' | ||
) } | ||
> | ||
<BlockTitle | ||
className="wc-block-attribute-filter__title" | ||
headingLevel={ headingLevel } | ||
heading={ heading } | ||
onChange={ ( value: string ) => | ||
setAttributes( { heading: value } ) | ||
} | ||
/> | ||
{ heading && ( | ||
<BlockTitle | ||
className="wc-block-attribute-filter__title" | ||
headingLevel={ headingLevel } | ||
heading={ heading } | ||
onChange={ ( value: string ) => | ||
setAttributes( { heading: value } ) | ||
} | ||
/> | ||
) } | ||
<Disabled> | ||
<Block attributes={ attributes } isEditor /> | ||
</Disabled> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
import { parseAttributes } from './utils'; | ||
|
||
const InnerBlockWrapper = ( props: Record< string, unknown > ) => { | ||
return <Block isEditor={ false } attributes={ parseAttributes( props ) } />; | ||
}; | ||
|
||
export default InnerBlockWrapper; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "woocommerce/filter-wrapper", | ||
"version": "1.0.0", | ||
"title": "Active Product Filters", | ||
"description": "Show the currently active product filters. Works in combination with other filters blocks.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's probably better to register the Active Product Filters as a variation too, but we need to hide the main filter wrapper block. |
||
"category": "woocommerce", | ||
"keywords": [ "WooCommerce" ], | ||
"attributes": { | ||
"filterType": { | ||
"type": "string", | ||
"default": "active-filters" | ||
} | ||
}, | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2, | ||
"$schema": "https://schemas.wp.org/trunk/block.json" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're losing the ability to limit the number of Active Filters, Price Filter, and Stock Filter blocks on a page.