/** * External dependencies */ import React from 'react'; import classNames from 'classnames'; /** * WordPress dependencies */ const { __, sprintf } = wp.i18n; /** * Internal dependencies */ import './wizard.scss'; import Box from '../../components/sui-box'; import { getLink } from '../../../js/utils/helpers'; import Icon from '../../components/sui-icon'; import ProgressBar from '../../components/sui-progress'; import Tag from '../../components/sui-tag'; import MinifySetupWizard from '../../../js/scanners/MinifySetupWizard'; import Toggle from '../../components/sui-toggle'; import SettingsRow from '../../components/sui-box-settings/row'; import Button from '../../components/sui-button'; import Tabs from '../../components/sui-tabs'; import Tooltip from '../../components/sui-tooltip'; import {createInterpolateElement} from "@wordpress/element"; /** * Wizard module, extends React.Component. * * @since 3.3.1 */ export default class Wizard extends React.Component { /** * Component constructor. * * @param {Object} props */ constructor( props ) { super( props ); this.state = { steps: { 1: __( 'Getting Started', 'wphb' ), 2: __( 'Asset Optimization', 'wphb' ), 3: __( 'Uptime', 'wphb' ), 4: __( 'Page Caching', 'wphb' ), 5: __( 'Advanced Tools', 'wphb' ), 6: __( 'Finish', 'wphb' ) }, scanning: false, skip: { advCacheFile: false, fastCGI: false } }; this.continueToNextStep = this.continueToNextStep.bind( this ); } /** * Run actions on component update. * * @param {Object} prevProps * @param {Object} prevState */ componentDidUpdate( prevProps, prevState ) { if ( 1 === this.props.step && this.props.showConflicts ) { if ( this.props.step === prevProps.step && this.props.showConflicts === prevProps.showConflicts ) { return; // Nothing changed after re-checking status. } // We need to save our state, so we don't show extra stuff on next step. this.setState( { skip: { advCacheFile: ! this.props.issues.advCacheFile, fastCGI: ! this.props.issues.fastCGI } } ); jQuery( '.sui-box-header' ).on( 'click', this.toggleContent ); } if ( 2 === this.props.step && this.props.settings.aoEnable ) { if ( true === this.state.scanning && this.state.scanning !== prevState.scanning ) { const scanner = new MinifySetupWizard( this.props.minifySteps, 0 ); scanner.start(); } } if ( 3 <= this.props.step && this.props.step !== prevProps.step ) { this.setState( { scanning: false } ); } } /** * Show/hide content block with issues. * * @param {Object} e */ toggleContent( e ) { e.currentTarget.parentNode.classList.toggle( 'open' ); } /** * Get navigation. * * @return {JSX.Element} Side navigation */ getNavigation() { const mobileSteps = Object.entries( this.state.steps ).map( ( step, key ) => { if ( 6 === key ) { return null; } const x1 = key * 20; const x2 = step[ 0 ] * 20; const stroke = this.props.step <= step[ 0 ] ? '#D8D8D8' : '#1ABC9C'; return ; } ); const steps = Object.entries( this.state.steps ).map( ( step, key ) => { if ( 6 === key ) { return null; } const classes = classNames( { current: parseInt( step[ 0 ] ) === this.props.step, done: parseInt( step[ 0 ] ) < this.props.step, disabled: 3 === parseInt( step[ 0 ] ) && ! this.props.hasUptime, } ); return (
  • { 'done' !== classes && { step[ 0 ] } } { 'done' === classes && } { step[ 1 ] } { 3 === parseInt( step[ 0 ] ) && ! this.props.hasUptime && }
  • { 5 > key && }
    ); } ); return (
    ); } /** * Wizard header. * * @return {JSX.Element} Header block */ getHeader() { let title = this.state.steps[ this.props.step ]; let name = this.state.steps[ this.props.step ].replace( /\s+/g, '-' ).toLowerCase(); if ( 1 === this.props.step && this.props.showConflicts ) { name = ! this.props.issues.advCacheFile && ! this.props.issues.fastCGI ? 'success' : 'failed'; title = __( 'Plugin Conflict', 'wphb' ); } else if ( 6 === this.props.step ) { name = 'success'; title = __( 'Wizard Completed!', 'wphb' ); } return ( { { __( 'Hummingbird Setup', 'wphb' ) }

    { title }

    ); } /** * Plugins compatibility content. * * @return {JSX.Element} Content block. */ getCompatPluginsContent() { if ( ! this.props.showConflicts || this.state.skip.advCacheFile ) { return null; } let title = __( 'No other caching plugin is detected', 'wphb' ); let icon = 'check-tick sui-success'; let description = (

    { __( 'No other caching plugin is detected. You can proceed with the setup.', 'wphb' ) }

    ); if ( this.props.issues.advCacheFile ) { title = __( 'Another caching plugin is detected', 'wphb' ); icon = 'warning-alert sui-error'; const message = createInterpolateElement( __('Hummingbird has detected an advanced-cache.php file in your site’s wp-content directory. Manage your plugins and disable any other active caching plugins to ensure Hummingbird’s page caching works properly.', 'wphb'), { a: } ); description = (

    {message}

    { __( 'If no other caching plugins are active, the advanced-cache.php may have been left by a previously used caching plugin. You can remove the file from the wp-content directory, or remove it via your file manager or FTP.', 'wphb' ) }

    ); } return (