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

Product Collection: Add new flow for adding Product Collection block #10952

Closed
wants to merge 113 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
9584744
Move default Product Collection template to constants
kmanijak Sep 14, 2023
815cbc0
Move Product Collection editor related code to edit directory and dis…
kmanijak Sep 14, 2023
fe7f5dc
Use Pattern Selection Modal for both: initial state and later
kmanijak Sep 14, 2023
8565738
Rename components files to follow the naming convention
kmanijak Sep 15, 2023
e5a0313
Use default query when choosing pattern for first time
kmanijak Sep 15, 2023
fbeb508
Handle the initial inherit attribute value
kmanijak Sep 15, 2023
5decf65
Provide initial example collection
kmanijak Sep 15, 2023
104bf1f
Add isActive function to collections registration
kmanijak Sep 15, 2023
8fb526f
Treat collections as patterns and display them in inserter
kmanijak Sep 15, 2023
b663694
Add README.md
kmanijak Sep 15, 2023
8fa4dd6
Add logic to include default Product Collection block
kmanijak Sep 15, 2023
feddf81
Improve the README.md
kmanijak Sep 15, 2023
2d1b558
Improve the README.md
kmanijak Sep 15, 2023
6cec5e0
Preserve the collection attribute
kmanijak Sep 15, 2023
1ac3c57
Fix typo and update placeholder instruction in product-collection
imanish003 Sep 19, 2023
76a88a5
Refactor Product Collection block and update New Arrivals collection
imanish003 Sep 19, 2023
6ee03ae
Refactor: Rename QueryEditComponentProps to ProductCollectionEditComp…
imanish003 Sep 19, 2023
815e6e6
Minor improvements
imanish003 Sep 19, 2023
6ab7b6a
Refactor: Rename QueryPlaceholder component and update imports and co…
imanish003 Sep 19, 2023
9768354
Refactor: Use block.json properties and enhance pattern selection modal
imanish003 Sep 20, 2023
8554ed6
Resolve conflicts
imanish003 Sep 21, 2023
1c97714
Resolve conflicts
imanish003 Sep 21, 2023
ef16e22
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
imanish003 Sep 21, 2023
49a5a8f
Minor improvement
imanish003 Sep 21, 2023
e72a104
Update modal title and placeholder button text
imanish003 Sep 22, 2023
3df3e3f
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Oct 6, 2023
af4c3fd
Remove unnecessary todo
kmanijak Oct 6, 2023
8bce89e
Add subtitle to Pattern Chooser modal
kmanijak Oct 6, 2023
38bdcda
Add styles to Pattern Chooser modal
kmanijak Oct 6, 2023
174515a
Increase the gap between Product Collection selection modal subtitle …
kmanijak Oct 6, 2023
0b57b89
Add the padding top between Product Collection selection modal previe…
kmanijak Oct 6, 2023
6aa5175
Adjust Product Collection tests to the new flow
kmanijak Oct 6, 2023
1b8bb2f
Adjust Product Collection tests to the new flow
kmanijak Oct 6, 2023
ddae428
Avoid collection items in pattern chooser break between columns
kmanijak Oct 6, 2023
2c1a477
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
imanish003 Oct 11, 2023
9d841f2
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Oct 17, 2023
264e82e
Hide New Arrivals collection from inserter and add keywords
kmanijak Oct 17, 2023
a37a9ba
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Oct 19, 2023
5d54dcb
Rename with containing Pattern Selection Modal as it changes its purp…
kmanijak Oct 23, 2023
8fc1a97
Separate collections and patterns
kmanijak Oct 23, 2023
87b7f14
Simplify New Arrivals structure to just Product Collection block
kmanijak Oct 23, 2023
a9b2312
Add second variation for easier dfevelopment
kmanijak Oct 23, 2023
18956d4
Add mechanism of choosing particular collection
kmanijak Oct 23, 2023
149fee7
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Oct 26, 2023
ef75cc3
Temporary
kmanijak Oct 26, 2023
4e78a83
Add patterns section to Collection Chooser modal
kmanijak Oct 30, 2023
c112964
Cleanup
kmanijak Oct 30, 2023
5771518
Initiate adding Default Query Collection
kmanijak Oct 30, 2023
fa46395
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Nov 8, 2023
c98525d
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Nov 9, 2023
9769b17
Style the Collection buttons and arranmge them in grid
kmanijak Nov 9, 2023
9e58e9a
Change margins of Collection button section
kmanijak Nov 9, 2023
71e185b
Add Best Sellers collection
kmanijak Nov 9, 2023
2009efd
Add Featured collection
kmanijak Nov 9, 2023
ad52a49
Add On Sale collection
kmanijak Nov 9, 2023
10360a1
Remove Top Sellers collection
kmanijak Nov 9, 2023
f2e27fe
Add Top Rated collection
kmanijak Nov 9, 2023
07f824d
Remove fake default query collection
kmanijak Nov 9, 2023
8dee843
Register all the new collections
kmanijak Nov 9, 2023
b633f96
Fix incorrect import
kmanijak Nov 9, 2023
3248853
Add logic to choose highlighted collection
kmanijak Nov 9, 2023
d37c041
Improve Collection buttons styling
kmanijak Nov 9, 2023
8d6abb6
Improve Pattern Chooser styling
kmanijak Nov 9, 2023
2faeccd
Add styles to Modal buttons
kmanijak Nov 9, 2023
92bad6f
Merge Collections and Patterns
kmanijak Nov 9, 2023
d0346a5
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Nov 14, 2023
b64502f
Remove Pattern Chooser - visual part
kmanijak Nov 14, 2023
10c0fe0
Remove the logic related to pattern
kmanijak Nov 14, 2023
dc9b4df
Add visual improvements to the smaller modal
kmanijak Nov 14, 2023
5bb7d02
Make Collection Chooser look fine on mobile
kmanijak Nov 14, 2023
b26c6d6
Simplify Default Query case
kmanijak Nov 14, 2023
b8b34b2
Change the default setting of Collections
kmanijak Nov 14, 2023
25c068e
Add headings to collections
kmanijak Nov 14, 2023
590a762
Add translations to the collections titles and descriptions
kmanijak Nov 14, 2023
f6b00a6
Fix TS errors by forcing type from wordpress/blocks
kmanijak Nov 14, 2023
42b56d3
Improve typing
kmanijak Nov 14, 2023
c2f0288
Rename the file to better reflect its purpose
kmanijak Nov 14, 2023
bed592f
Add frameLocator to tests
kmanijak Nov 15, 2023
3178339
Fix the Product Collection E2E tests
kmanijak Nov 15, 2023
badf4aa
Fixed E2E tests of Product Collection
kmanijak Nov 16, 2023
9837826
Additional fix to tests
kmanijak Nov 16, 2023
36e1f97
E2E try
kmanijak Nov 16, 2023
b7c094c
Fix existing Product Collection E2E tests
kmanijak Nov 16, 2023
bba6845
Adjust test to collection
kmanijak Nov 16, 2023
5c52a3c
Add E2E tests to Collections
kmanijak Nov 17, 2023
2c855fb
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Nov 17, 2023
9712641
Enable shrinking columns by default
kmanijak Nov 17, 2023
b0804ca
Change Default Query collection name to All products to better repres…
kmanijak Nov 17, 2023
ff42e8c
Adjust test about responsiveness after enabling shrinking columns
kmanijak Nov 17, 2023
6cd4496
Revert enabling shrink columns so it's added in separate PR
kmanijak Nov 17, 2023
4661e48
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Nov 17, 2023
048a45c
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Nov 23, 2023
a2c0cba
Improvements after merge
kmanijak Nov 23, 2023
037410f
Enable shrink columns to fit by default in Collections
kmanijak Nov 23, 2023
0503847
Hide Inherit query from template for Collections
kmanijak Nov 23, 2023
b846a54
Tweak the order of Collections
kmanijak Nov 23, 2023
bef9462
Fix Modal styles on Firefox
kmanijak Nov 23, 2023
41df492
Update order and copy for Collections
kmanijak Nov 23, 2023
838770d
Bring back the file removed by accident
kmanijak Nov 24, 2023
7509e5e
Bring back Display controls in Product Collection Toolbar
kmanijak Nov 24, 2023
677d1e7
Update tests to reflect copy changes
kmanijak Nov 24, 2023
3fe5e9b
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Nov 29, 2023
c9446ef
Update the copy of Product Collection chooser modal
kmanijak Nov 29, 2023
78dacf2
Move defaultQuery to collections directory so the name property can b…
kmanijak Nov 29, 2023
2b482fc
Update collection description in locator in E2E test
kmanijak Dec 1, 2023
e609230
Update Collection tests so they are based on displayed products and n…
kmanijak Dec 1, 2023
8f3fbc1
Merge branch 'trunk' into add/10822-new-flow-for-product-collection
kmanijak Dec 6, 2023
b622b61
Fix incorrect conflict resolution
kmanijak Dec 6, 2023
aca352b
Revert unexpected composer.lock changes
kmanijak Dec 6, 2023
1ffe028
Revert lines swap
kmanijak Dec 6, 2023
692e49b
Move the Collections buttons to Product Collection Placeholder
kmanijak Dec 7, 2023
79936bc
Adjust tests to the new flow (no modal)
kmanijak Dec 7, 2023
ab897f1
Fix styling of the placeholder
kmanijak Dec 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/js/blocks/product-collection/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"convertedFromProducts": {
"type": "boolean",
"default": false
},
"collection": {
"type": "string"
}
},
"providesContext": {
Expand Down
32 changes: 32 additions & 0 deletions assets/js/blocks/product-collection/collections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Product Collection - Collections

Collections are a variations of Product Collection block with the predefined attributes which includes:

- UI aspect - you can define layout, number of columns etc.
- Query - specify the filters and sorting of the products
- Inner blocks structure - define the Product Template structure

## Interface

Collections are in fact Variations and they are registered via Variation API. Hence they should follow the BlockVariation type, providing at least:

```typescript
{
name: string;
title: string,
icon: Icon,
description: string,
attributes: ProductCollectionAttributes,
innerBlocks: InnerBlockTemplate[],
isActive?:
(blockAttrs: BlockAttributes, variationAttributes: BlockAttributes) => boolean,
}
```

Please be aware you can specify `isActive` function, but if not, the default one will compare the variation's `name` with `attributes.collection` value.

As an example please follow `./new-arrivals.tsx`.

## Registering Collection

To register collection import it in `./index.ts` file and add to the `collections` array.
65 changes: 65 additions & 0 deletions assets/js/blocks/product-collection/collections/best-sellers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* External dependencies
*/
import type { InnerBlockTemplate, BlockIcon } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { Icon, chartBar } from '@wordpress/icons';

/**
* Internal dependencies
*/
import {
DEFAULT_ATTRIBUTES,
INNER_BLOCKS_PRODUCT_TEMPLATE,
} from '../constants';

const collection = {
name: 'woocommerce-blocks/product-collection/best-sellers',
title: __( 'Best Sellers', 'woo-gutenberg-products-block' ),
icon: ( <Icon icon={ chartBar } /> ) as BlockIcon,
description: __(
'Recommend your best-selling products.',
'woo-gutenberg-products-block'
),
keywords: [ 'best selling' ],
scope: [],
};

const attributes = {
...DEFAULT_ATTRIBUTES,
displayLayout: {
type: 'flex',
columns: 5,
shrinkColumns: true,
},
query: {
...DEFAULT_ATTRIBUTES.query,
inherit: false,
orderBy: 'popularity',
order: 'desc',
perPage: 5,
pages: 1,
},
collection: collection.name,
};

const heading: InnerBlockTemplate = [
'core/heading',
{
textAlign: 'center',
level: 2,
content: __( 'Best selling products', 'woo-gutenberg-products-block' ),
style: { spacing: { margin: { bottom: '1rem' } } },
},
];

const innerBlocks: InnerBlockTemplate[] = [
heading,
INNER_BLOCKS_PRODUCT_TEMPLATE,
];

export default {
...collection,
attributes,
innerBlocks,
};
68 changes: 68 additions & 0 deletions assets/js/blocks/product-collection/collections/featured.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* External dependencies
*/
import type {
BlockAttributes,
InnerBlockTemplate,
BlockIcon,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { Icon, starFilled } from '@wordpress/icons';

/**
* Internal dependencies
*/
import {
DEFAULT_ATTRIBUTES,
INNER_BLOCKS_PRODUCT_TEMPLATE,
} from '../constants';

const collection = {
name: 'woocommerce-blocks/product-collection/featured',
title: __( 'Featured', 'woo-gutenberg-products-block' ),
icon: ( <Icon icon={ starFilled } /> ) as BlockIcon,
description: __(
'Showcase your featured products.',
'woo-gutenberg-products-block'
),
keywords: [],
scope: [],
};

const attributes = {
...DEFAULT_ATTRIBUTES,
displayLayout: {
type: 'flex',
columns: 5,
shrinkColumns: true,
},
query: {
...DEFAULT_ATTRIBUTES.query,
inherit: false,
featured: true,
perPage: 5,
pages: 1,
},
collection: collection.name,
};

const heading: [ string, BlockAttributes?, InnerBlockTemplate[]? ] = [
'core/heading',
{
textAlign: 'center',
level: 2,
content: __( 'Featured products', 'woo-gutenberg-products-block' ),
style: { spacing: { margin: { bottom: '1rem' } } },
},
];

const innerBlocks: InnerBlockTemplate[] = [
heading,
INNER_BLOCKS_PRODUCT_TEMPLATE,
];

export default {
...collection,
attributes,
innerBlocks,
};
53 changes: 53 additions & 0 deletions assets/js/blocks/product-collection/collections/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* External dependencies
*/
import {
type BlockVariation,
registerBlockVariation,
BlockAttributes,
} from '@wordpress/blocks';
import { Icon, loop } from '@wordpress/icons';

/**
* Internal dependencies
*/
import blockJson from '../block.json';
import newArrivals from './new-arrivals';
import topRated from './top-rated';
import bestSellers from './best-sellers';
import onSale from './on-sale';
import featured from './featured';

export const defaultQuery = {
name: 'woocommerce-blocks/product-collection/default-query',
title: 'All Products',
icon: <Icon icon={ loop } />,
description:
'Display all products. Results may be limited by the current template context.',
};

const collections: BlockVariation[] = [
featured,
topRated,
onSale,
bestSellers,
newArrivals,
];

const registerCollections = () => {
collections.forEach( ( collection ) => {
const isActive = (
blockAttrs: BlockAttributes,
variationAttributes: BlockAttributes
) => {
return blockAttrs.collection === variationAttributes.collection;
};

registerBlockVariation( blockJson.name, {
isActive,
...collection,
} );
} );
};

export default registerCollections;
69 changes: 69 additions & 0 deletions assets/js/blocks/product-collection/collections/new-arrivals.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* External dependencies
*/
import type {
BlockAttributes,
InnerBlockTemplate,
BlockIcon,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { Icon, calendar } from '@wordpress/icons';

/**
* Internal dependencies
*/
import {
DEFAULT_ATTRIBUTES,
INNER_BLOCKS_PRODUCT_TEMPLATE,
} from '../constants';

const collection = {
name: 'woocommerce-blocks/product-collection/new-arrivals',
title: __( 'New Arrivals', 'woo-gutenberg-products-block' ),
icon: ( <Icon icon={ calendar } /> ) as BlockIcon,
description: __(
'Recommend your newest products.',
'woo-gutenberg-products-block'
),
keywords: [ 'newest products' ],
scope: [],
};

const attributes = {
...DEFAULT_ATTRIBUTES,
displayLayout: {
type: 'flex',
columns: 5,
shrinkColumns: true,
},
query: {
...DEFAULT_ATTRIBUTES.query,
inherit: false,
orderBy: 'date',
order: 'desc',
perPage: 5,
pages: 1,
},
collection: collection.name,
};

const heading: [ string, BlockAttributes?, InnerBlockTemplate[]? ] = [
'core/heading',
{
textAlign: 'center',
level: 2,
content: __( 'New arrivals', 'woo-gutenberg-products-block' ),
style: { spacing: { margin: { bottom: '1rem' } } },
},
];

const innerBlocks: InnerBlockTemplate[] = [
heading,
INNER_BLOCKS_PRODUCT_TEMPLATE,
];

export default {
...collection,
attributes,
innerBlocks,
};
68 changes: 68 additions & 0 deletions assets/js/blocks/product-collection/collections/on-sale.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* External dependencies
*/
import type {
BlockAttributes,
InnerBlockTemplate,
BlockIcon,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { Icon, percent } from '@wordpress/icons';

/**
* Internal dependencies
*/
import {
DEFAULT_ATTRIBUTES,
INNER_BLOCKS_PRODUCT_TEMPLATE,
} from '../constants';

const collection = {
name: 'woocommerce-blocks/product-collection/on-sale',
title: __( 'On Sale', 'woo-gutenberg-products-block' ),
icon: ( <Icon icon={ percent } /> ) as BlockIcon,
description: __(
'Highlight products that are currently on sale.',
'woo-gutenberg-products-block'
),
keywords: [],
scope: [],
};

const attributes = {
...DEFAULT_ATTRIBUTES,
displayLayout: {
type: 'flex',
columns: 5,
shrinkColumns: true,
},
query: {
...DEFAULT_ATTRIBUTES.query,
inherit: false,
woocommerceOnSale: true,
perPage: 5,
pages: 1,
},
collection: collection.name,
};

const heading: [ string, BlockAttributes?, InnerBlockTemplate[]? ] = [
'core/heading',
{
textAlign: 'center',
level: 2,
content: __( 'On sale products', 'woo-gutenberg-products-block' ),
style: { spacing: { margin: { bottom: '1rem' } } },
},
];

const innerBlocks: InnerBlockTemplate[] = [
heading,
INNER_BLOCKS_PRODUCT_TEMPLATE,
];

export default {
...collection,
attributes,
innerBlocks,
};