balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

index.js (3032B)


      1 import {Tooltip} from '@wordpress/components';
      2 import * as Icons from '~redux-templates/icons'
      3 import './style.scss'
      4 const {__} = wp.i18n;
      5 
      6 export default function DependentPlugins (props) {
      7     const {data, showDependencyBlock} = props;
      8     const {id} = data;
      9 
     10     const isMissingPlugin = (plugin) => {
     11         return ((data.proDependenciesMissing && data.proDependenciesMissing.indexOf(plugin) >=0)
     12             || (data.installDependenciesMissing && data.installDependenciesMissing.indexOf(plugin) >=0))
     13     }
     14 
     15     if (showDependencyBlock) {
     16 	    let index = data.dependencies.indexOf('core');
     17 	    if ( index > -1 ) {
     18 		    data.dependencies.splice(index, 1);
     19 		    data.dependencies.push( 'core' );
     20 	    }
     21 	    return (
     22 		    <div className="redux-templates-button-display-dependencies">
     23 			    { data.dependencies &&
     24 			    data.dependencies.map(plugin => {
     25 			    	let pluginInstance = null;
     26 				    const plugin_name = plugin.replace('-pro', '').replace('-premium', '').replace(/\W/g, '').toLowerCase();
     27 			    	if ( 'core' == plugin ) {
     28 					    pluginInstance = {
     29 					    	name: 'WordPress Native'
     30 					    }
     31 				    } else {
     32 					    pluginInstance = redux_templates.supported_plugins[plugin];
     33 				    }
     34 					if ( !pluginInstance ) {
     35 						pluginInstance = redux_templates.supported_plugins[plugin.replace('-pro', '').replace('-premium', '')];
     36 					}
     37 
     38 				    // We don't want two of the same icons showing up.
     39 				    if ( ! plugin.includes('-pro') && ! plugin.includes('-premium') ) {
     40 					    if ( data.dependencies.includes(plugin + '-pro') || data.dependencies.includes( plugin + '-premium' ) ) {
     41 						    return;
     42 					    }
     43 				    }
     44 				    if (!pluginInstance) {
     45 					    console.log( 'Missing plugin details for '+ plugin+' - ' + plugin.replace('-pro', '').replace('-premium', '') );
     46 					    console.log( redux_templates.supported_plugins );
     47 					    return;
     48 				    }
     49 				    if ( 'redux' === plugin_name ) {
     50 					    return;
     51 				    }
     52 				    const IconComponent = Icons[plugin_name];
     53 				    if (IconComponent && pluginInstance) {
     54 					    return (
     55 						    <Tooltip text={(isMissingPlugin(plugin) && 'core' !== plugin ? pluginInstance.name+ ' ( '+__('Not Installed', redux_templates.i18n)+' )' : pluginInstance.name)} position="bottom center" key={id + plugin}>
     56                                     <span className={isMissingPlugin(plugin) && 'core' !== plugin ? 'missing-dependency' : ''}>
     57                                         <IconComponent/>
     58                                     </span>
     59 						    </Tooltip>
     60 					    );
     61 				    } else if ( 'shareablockcom' !== plugin_name && 'gutenberghubcom' !== plugin_name ) {
     62 					    console.log('Need icon for ' + plugin_name);
     63 				    }
     64 
     65 			    })
     66 			    }
     67 			    { data.dependencies['core'] &&
     68 			    <Tooltip text={__('WordPress Core', redux_templates.i18n)} position="bottom center" key={id + 'core'}>
     69 				            <span>
     70 				            <IconComponent/>
     71 				            </span>
     72 			    </Tooltip>
     73 
     74 			    }
     75 		    </div>
     76 	    );
     77     }
     78 
     79     return null;
     80 }