Adds orderBy and orderByMetaKey attrs to items list block. #735.

This commit is contained in:
mateuswetah 2022-11-24 12:25:55 -03:00
parent 4f2242e262
commit 49354a7d68
6 changed files with 34 additions and 9 deletions

View File

@ -102,6 +102,10 @@
"type": "string",
"default": "date"
},
"orderByMetaKey": {
"type": "string",
"default": ""
},
"blockId": {
"type": "string",
"default": ""

View File

@ -1,7 +1,7 @@
const { useBlockProps } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor );
export default [
/* Deprecated on 0.19.3 due to the introduction of orderBy */
/* Deprecated on 0.19.3 due to the introduction of orderBy and orderByMetaKey */
{
attributes: {
"content": {

View File

@ -32,6 +32,7 @@ export default function({ attributes, setAttributes, className, isSelected, clie
maxItemsNumber,
order,
orderBy,
orderByMetaKey,
searchString,
selectedItems,
isLoading,
@ -303,25 +304,35 @@ export default function({ attributes, setAttributes, className, isSelected, clie
}
// Set up sorting order
if (order != '' && showSearchBar)
queryObject.order = order;
else if (queryObject.order != '')
if (queryObject.order != '' && !showSearchBar)
setAttributes({ order: queryObject.order });
else if (order != '')
queryObject.order = order;
else {
queryObject.order = 'asc';
setAttributes({ order: 'asc' });
}
// Set up sorting order
if (orderBy != '')
queryObject.orderby = orderBy;
else if (queryObject.orderby != '')
// Set up sorting orderby
if (queryObject.orderby != '')
setAttributes({ orderBy: queryObject.orderby });
else if (orderBy != 'date')
queryObject.orderby = orderBy;
else {
queryObject.orderby = 'date';
setAttributes({ orderBy: 'date' });
}
// Set up sorting metakey (used by some orderby)
if (queryObject.metakey != '')
setAttributes({ orderByMetaKey: queryObject.metakey });
else if (orderByMetaKey != '')
queryObject.metakey = orderByMetaKey;
else {
queryObject.metakey = '';
setAttributes({ orderByMetaKey: '' });
}
// Set up search string
if (searchString != undefined)
queryObject.search = searchString;

View File

@ -15,6 +15,7 @@ export default function({ attributes, className }) {
maxItemsNumber,
order,
orderBy,
orderByMetaKey,
showSearchBar,
showCollectionHeader,
showCollectionLabel,
@ -58,6 +59,7 @@ export default function({ attributes, className }) {
max-items-number={ maxItemsNumber }
order={ order }
orderBy={ orderBy }
orderByMetaKey={ orderByMetaKey }
tainacan-api-root={ tainacan_blocks.root }
tainacan-base-url={ tainacan_blocks.base_url }
id={ 'wp-block-tainacan-dynamic-items-list_' + blockId }>

View File

@ -45,6 +45,7 @@ export default (element) => {
imageSize: 'tainacan-medium',
order: 'asc',
orderBy: 'date',
orderByMetaKey: '',
showSearchBar: false,
showCollectionHeader: false,
showCollectionLabel: false,
@ -77,6 +78,7 @@ export default (element) => {
maxItemsNumber: this.maxItemsNumber,
order: this.order,
orderBy: this.orderBy,
orderByMetaKey: this.orderByMetaKey,
showSearchBar: this.showSearchBar,
showCollectionHeader: this.showCollectionHeader,
showCollectionLabel: this.showCollectionLabel,
@ -110,6 +112,7 @@ export default (element) => {
this.maxItemsNumber = this.$el.attributes['max-items-number'] != undefined ? this.$el.attributes['max-items-number'].value : undefined;
this.order = this.$el.attributes['order'] != undefined ? this.$el.attributes['order'].value : undefined;
this.orderBy = this.$el.attributes['order-by'] != undefined ? this.$el.attributes['order-by'].value : undefined;
this.orderByMetaKey = this.$el.attributes['order-by-meta-key'] != undefined ? this.$el.attributes['order-by-meta-key'].value : undefined;
this.showSearchBar = this.$el.attributes['show-search-bar'] != undefined ? this.$el.attributes['show-search-bar'].value == 'true' : false;
this.showCollectionHeader = this.$el.attributes['show-collection-header'] != undefined ? this.$el.attributes['show-collection-header'].value == 'true' : false;
this.showCollectionLabel = this.$el.attributes['show-collection-label'] != undefined ? this.$el.attributes['show-collection-label'].value == 'true' : false;

View File

@ -300,6 +300,7 @@ export default {
imageSize: String,
order: String,
orderBy: String,
orderByMetaKey: String,
showSearchBar: Boolean,
showCollectionHeader: Boolean,
showCollectionLabel: Boolean,
@ -419,6 +420,10 @@ export default {
// Set up orderBy
if (this.orderBy != undefined)
queryObject.orderby = this.orderBy;
// Set up orderByMetaKey
if (this.orderByMetaKey != undefined)
queryObject.metakey = this.orderByMetaKey;
// Set up search string
if (this.searchString != undefined)