Software: Apache. PHP/7.3.33 uname -a: Linux acloudg.aryanict.com 4.18.0-513.9.1.lve.el8.x86_64 #1 SMP Mon Dec 4 15:01:22 UTC uid=1095(katebhospital) gid=1098(katebhospital) groups=1098(katebhospital) Safe-mode: OFF (not secure) /var/softaculous/sitepad/editor/site-data/plugins/kkart-pro/packages/kkart-blocks/assets/js/utils/ drwxr-xr-x |
Viewing file: Select action/file-type: /** * External dependencies */ import { sortBy, map } from 'lodash'; /** * Given a query object, removes an attribute filter by a single slug. * * @param {Array} query Current query object. * @param {Function} setQuery Callback to update the current query object. * @param {Object} attribute An attribute object. * @param {string} slug Term slug to remove. */ export const removeAttributeFilterBySlug = ( query = [], setQuery = () => {}, attribute, slug = '' ) => { // Get current filter for provided attribute. const foundQuery = query.filter( ( item ) => item.attribute === attribute.taxonomy ); const currentQuery = foundQuery.length ? foundQuery[ 0 ] : null; if ( ! currentQuery || ! currentQuery.slug || ! Array.isArray( currentQuery.slug ) || ! currentQuery.slug.includes( slug ) ) { return; } const newSlugs = currentQuery.slug.filter( ( item ) => item !== slug ); // Remove current attribute filter from query. const returnQuery = query.filter( ( item ) => item.attribute !== attribute.taxonomy ); // Add a new query for selected terms, if provided. if ( newSlugs.length > 0 ) { currentQuery.slug = newSlugs.sort(); returnQuery.push( currentQuery ); } setQuery( sortBy( returnQuery, 'attribute' ) ); }; /** * Given a query object, sets the query up to filter by a given attribute and attribute terms. * * @param {Array} query Current query object. * @param {Function} setQuery Callback to update the current query object. * @param {Object} attribute An attribute object. * @param {Array} attributeTerms Array of term objects. * @param {string} operator Operator for the filter. Valid values: in, and. */ export const updateAttributeFilter = ( query = [], setQuery = () => {}, attribute, attributeTerms = [], operator = 'in' ) => { const returnQuery = query.filter( ( item ) => item.attribute !== attribute.taxonomy ); if ( attributeTerms.length === 0 ) { setQuery( returnQuery ); } else { returnQuery.push( { attribute: attribute.taxonomy, operator, slug: map( attributeTerms, 'slug' ).sort(), } ); setQuery( sortBy( returnQuery, 'attribute' ) ); } }; |
:: Command execute :: | |
--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0039 ]-- |