| 1 |
const { __ } = wp.i18n; |
| 2 |
const { |
| 3 |
Button, |
| 4 |
PanelBody, |
| 5 |
TextareaControl, |
| 6 |
} = wp.components; |
| 7 |
|
| 8 |
export default { |
| 9 |
dynamicObjectToString( obj, glue = ' ' ) { |
| 10 |
let dynamic = []; |
| 11 |
for ( let key of Object.keys( obj ) ) { |
| 12 |
if ( key ) { |
| 13 |
const value = obj[ key ]; |
| 14 |
|
| 15 |
if ( value ) { |
| 16 |
dynamic.push( `${key}="${ value }"` ); |
| 17 |
} |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
return dynamic.join( glue ); |
| 22 |
}, |
| 23 |
dynamicSidebar( attributes, setAttributes, type = 'grid' ) { |
| 24 |
return ( |
| 25 |
<PanelBody title={ 'grid' === type ? __( 'Dynamic Filters' ) : __( 'Default Filter Selections' ) }> |
| 26 |
<p> |
| 27 |
{ |
| 28 |
! wpupg_admin.addons.premium |
| 29 |
&& |
| 30 |
<span style={ { color: 'darkred' } }>This feature is only available in WP Ultimate Post Grid Premium.<br/></span> |
| 31 |
} |
| 32 |
{ |
| 33 |
'grid' === type |
| 34 |
? |
| 35 |
<a href="https://help.bootstrapped.ventures/article/238-limit-items-dynamically" target="_blank">Learn More</a> |
| 36 |
: |
| 37 |
<a href="https://help.bootstrapped.ventures/article/247-default-filter-selections" target="_blank">Learn More</a> |
| 38 |
} |
| 39 |
</p> |
| 40 |
<TextareaControl |
| 41 |
value={ attributes.dynamic } |
| 42 |
onChange={( value ) => { |
| 43 |
// Clean up. |
| 44 |
value = value.replace( '\n', ' ' ); |
| 45 |
value = value.replace( '\r', ' ' ); |
| 46 |
value = value.replace( ' ', ' ' ); |
| 47 |
|
| 48 |
setAttributes({ |
| 49 |
dynamic: value, |
| 50 |
}); |
| 51 |
}} |
| 52 |
/> |
| 53 |
</PanelBody> |
| 54 |
) |
| 55 |
} |
| 56 |
}; |
| 57 |
|