diff --git a/bootstrap.php b/bootstrap.php index 529de170..a47e7223 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -144,7 +144,6 @@ function() { // Required files require HOSTGATOR_PLUGIN_DIR . '/inc/Admin.php'; -require HOSTGATOR_PLUGIN_DIR . '/inc/AdminBar.php'; require HOSTGATOR_PLUGIN_DIR . '/inc/base.php'; require HOSTGATOR_PLUGIN_DIR . '/inc/jetpack.php'; require HOSTGATOR_PLUGIN_DIR . '/inc/LoginRedirect.php'; @@ -159,5 +158,3 @@ function() { if ( is_admin() ) { new Admin(); } - -AdminBar::init(); diff --git a/composer.json b/composer.json index faf10cea..62259423 100644 --- a/composer.json +++ b/composer.json @@ -70,6 +70,7 @@ "newfold-labs/wp-module-deactivation": "^1.0.4", "newfold-labs/wp-module-ecommerce": "^1.3.19", "newfold-labs/wp-module-global-ctb": "^1.0.9", + "newfold-labs/wp-module-help-center": "^1.0.22", "newfold-labs/wp-module-loader": "^1.0.10", "newfold-labs/wp-module-marketplace": "^2.2.0", "newfold-labs/wp-module-notifications": "^1.1.6", diff --git a/composer.lock b/composer.lock index 7c6cc3e6..61394cd8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5622b9429744d4dcd5555fddc7a5dff9", + "content-hash": "96407a6a211a4a2e88102f7f2102b0f0", "packages": [ { "name": "doctrine/inflector", @@ -190,6 +190,51 @@ }, "time": "2022-08-26T17:23:54+00:00" }, + { + "name": "newfold-labs/wp-module-ai", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/newfold-labs/wp-module-ai.git", + "reference": "17e48833284ef04113abc42fc2bb773a8124aef3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/newfold-labs/wp-module-ai/zipball/17e48833284ef04113abc42fc2bb773a8124aef3", + "reference": "17e48833284ef04113abc42fc2bb773a8124aef3", + "shasum": "" + }, + "require": { + "newfold-labs/wp-module-data": "^2.3.1" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "NewfoldLabs\\WP\\Module\\AI\\": "includes" + }, + "files": [ + "bootstrap.php" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Micah Wood", + "email": "micah@bluehost.com" + } + ], + "description": "A module for providing artificial intelligence capabilities.", + "support": { + "source": "https://github.com/newfold-labs/wp-module-ai/tree/1.0.9", + "issues": "https://github.com/newfold-labs/wp-module-ai/issues" + }, + "time": "2023-12-18T14:53:40+00:00" + }, { "name": "newfold-labs/wp-module-coming-soon", "version": "1.1.14", @@ -462,6 +507,52 @@ }, "time": "2023-11-03T15:59:01+00:00" }, + { + "name": "newfold-labs/wp-module-help-center", + "version": "1.0.22", + "source": { + "type": "git", + "url": "https://github.com/newfold-labs/wp-module-help-center.git", + "reference": "43a61428a420a91066e39c6a8491f0efcae73d26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/newfold-labs/wp-module-help-center/zipball/43a61428a420a91066e39c6a8491f0efcae73d26", + "reference": "43a61428a420a91066e39c6a8491f0efcae73d26", + "shasum": "" + }, + "require": { + "newfold-labs/wp-module-ai": "^1.0.3", + "newfold-labs/wp-module-data": "^2.3.4" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "@stable" + }, + "type": "library", + "autoload": { + "psr-4": { + "NewfoldLabs\\WP\\Module\\HelpCenter\\": "includes" + }, + "files": [ + "bootstrap.php" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Faizaan Mohammed", + "email": "faizaan.md@newfold.com" + } + ], + "description": "HelpCenter", + "support": { + "source": "https://github.com/newfold-labs/wp-module-help-center/tree/1.0.22", + "issues": "https://github.com/newfold-labs/wp-module-help-center/issues" + }, + "time": "2024-01-12T17:29:18+00:00" + }, { "name": "newfold-labs/wp-module-install-checker", "version": "1.0.2", @@ -2668,4 +2759,4 @@ "php": "7.1.0" }, "plugin-api-version": "2.6.0" -} +} \ No newline at end of file diff --git a/inc/Admin.php b/inc/Admin.php index 2f9d242e..6e7cf976 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -190,18 +190,21 @@ public static function page() { $snappy, 0 ); - - foreach ( self::subpages() as $route => $title ) { - \add_submenu_page( - 'hostgator', - $title, - $title, - 'manage_options', - $route, - array( __CLASS__, 'render' ) - ); + + // If we're outside of App, add subpages to App menu + if ( false === ( isset( $_GET['page'] ) && strpos( filter_input( INPUT_GET, 'page', FILTER_UNSAFE_RAW ), 'hostgator' ) >= 0 ) ) { // phpcs:ignore + foreach ( self::subpages() as $route => $title ) { + \add_submenu_page( + 'hostgator', + $title, + $title, + 'manage_options', + $route, + array( __CLASS__, 'render' ) + ); + } + } } - } /** * Render DOM element for React to load onto. diff --git a/inc/AdminBar.php b/inc/AdminBar.php deleted file mode 100644 index 4065cb35..00000000 --- a/inc/AdminBar.php +++ /dev/null @@ -1,44 +0,0 @@ -add_menu( - array( - 'id' => 'hostgator-support', - 'title' => __( 'Need help?', 'wp-plugin-hostgator' ), - 'href' => admin_url( 'admin.php?page=hostgator#/help' ), - 'meta' => array( - 'title' => esc_attr__( 'We\'re here for you!', 'wp-plugin-hostgator' ), - ), - ) - ); - } - -} diff --git a/src/app/components/app-nav/index.js b/src/app/components/app-nav/index.js index 1dfe05c1..471f0083 100644 --- a/src/app/components/app-nav/index.js +++ b/src/app/components/app-nav/index.js @@ -4,6 +4,7 @@ import { Modal, SidebarNavigation } from "@newfold/ui-component-library" import { NavLink, useLocation } from 'react-router-dom'; import Logo from "./logo"; import { topRoutes, utilityRoutes } from "../../data/routes"; +import { handleHelpLinksClick } from '../../util/helpers'; import { Bars3Icon } from "@heroicons/react/24/outline"; @@ -188,6 +189,7 @@ export const MobileNav = () => { export const AppNav = () => { const isLargeViewport = useViewportMatch('medium'); + handleHelpLinksClick(); return ( <> diff --git a/src/app/data/routes.js b/src/app/data/routes.js index 838a232a..5188d022 100644 --- a/src/app/data/routes.js +++ b/src/app/data/routes.js @@ -19,7 +19,12 @@ import Help from '../pages/help'; import Store from '../pages/ecommerce/page'; import { getMarketplaceSubnavRoutes } from '../../../vendor/newfold-labs/wp-module-marketplace/components/marketplaceSubnav'; -const addPartialMatch = (prefix, path) => prefix === path ? `${prefix}/*` : path; +const addPartialMatch = (prefix, path) => prefix === path ? `${prefix}/*` : path; + +const HelpCenterAI = ( e ) => { + e.preventDefault(); + window.newfoldEmbeddedHelp.toggleNFDLaunchedEmbeddedHelp(); +}; export const AppRoutes = () => { return ( @@ -124,6 +129,9 @@ export const routes = [ title: __('Help', 'wp-plugin-hostgator'), Component: Help, Icon: QuestionMarkCircleIcon, + action: NewfoldRuntime.hasCapability( 'canAccessHelpCenter' ) + ? HelpCenterAI + : false, }, ]; diff --git a/src/app/index.js b/src/app/index.js index 00df28fc..b4229e36 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -14,7 +14,6 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { useEffect } from 'react'; import { ErrorBoundary } from 'react-error-boundary'; import { store as noticesStore } from '@wordpress/notices'; -import { setActiveSubnav } from './util/helpers'; import { kebabCase, filter } from 'lodash'; import { AppNav } from './components/app-nav'; import { SiteInfoBar } from './components/site-info'; @@ -52,7 +51,6 @@ const handlePageLoad = () => { const location = useLocation(); const routeContents = document.querySelector('.hgwp-app-body-inner'); useEffect(() => { - setActiveSubnav(location.pathname); window.scrollTo(0, 0); if (routeContents) { routeContents.focus({ preventScroll: true }); diff --git a/src/app/pages/help/index.js b/src/app/pages/help/index.js index c26b8902..a34913d8 100644 --- a/src/app/pages/help/index.js +++ b/src/app/pages/help/index.js @@ -1,5 +1,9 @@ import help from '../../data/help'; -import { getLinkPerRegion, supportsLinkPerRegion } from '../../util/helpers'; +import { + getLinkPerRegion, + supportsLinkPerRegion, + handleHelpLinksClick +} from '../../util/helpers'; import { Button, Card, @@ -36,6 +40,7 @@ const HelpCard = ({ item }) => { } const Help = () => { + handleHelpLinksClick(); const renderHelpCards = () => { const helpItems = help; diff --git a/src/app/util/helpers.js b/src/app/util/helpers.js index 51ca7126..fecca71d 100644 --- a/src/app/util/helpers.js +++ b/src/app/util/helpers.js @@ -5,50 +5,6 @@ import { NewfoldRuntime } from "@newfold-labs/wp-module-runtime"; import region from '../data/region'; let lastNoticeId; -const HG_NAV = document.querySelector('#toplevel_page_hostgator .wp-submenu'); -/** - * Set active nav in wp admin sub pages. - * - * @param path - */ -export const setActiveSubnav = (path) => { - if (HG_NAV) { - const HG_NAV_LIS = HG_NAV.children; - if (HG_NAV_LIS) { - for (let i = 0; i < HG_NAV_LIS.length; i++) { - // get all children li elements - const link = HG_NAV_LIS[i].children[0]; - if (link) { - const href = link.getAttribute('href'); - // check each child a href for match with path - if ( - href.endsWith(path) || // match - (path.includes('/marketplace/') && - href.endsWith('marketplace')) || - (path === '/' && href.endsWith('home')) - ) { - // highlight home subnav for root page - // update li class when match - HG_NAV_LIS[i].classList.add('current'); - } else { - HG_NAV_LIS[i].classList.remove('current'); - } - // highlight our home nav for root level access - const HG_HOME_NAV = document.querySelector( - '.hgwp-nav a[href="#/home"]' - ); - if (HG_HOME_NAV) { - if (path === '/' || path === '/home') { - HG_HOME_NAV.classList.add('active'); - } else { - HG_HOME_NAV.classList.remove('active'); - } - } - } - } - } - } -}; /** * Wrapper method to dispatch snackbar notice @@ -227,3 +183,32 @@ export const supportsLinkPerRegion = (link_name = 'main') => { params.utm_medium = 'hostgator_plugin'; return addQueryArgs(url, params); }; + +/** + * Handles help center links click, will open help center slide if user has access + * or navigate to help page if user doesn't have access + */ +export const handleHelpLinksClick = () => { + if ( + NewfoldRuntime.hasCapability( 'canAccessHelpCenter' ) && + window.newfoldEmbeddedHelp && + ! window.newfoldEmbeddedHelp.hasListeners + ) { + // add listener to all help links + const helpLinks = document.querySelectorAll( '[href*="#/help"]' ); + if ( helpLinks ) { + helpLinks.forEach( ( el ) => + el.addEventListener( 'click', ( e ) => { + e.preventDefault(); + window.newfoldEmbeddedHelp.toggleNFDLaunchedEmbeddedHelp(); + } ) + ); + window.newfoldEmbeddedHelp.hasListeners = true; + } + + // if on help page already, open help center + if( window.location.hash === '#/help') { + window.newfoldEmbeddedHelp.toggleNFDLaunchedEmbeddedHelp(); + } + } +}; diff --git a/tests/cypress/integration/navigation.cy.js b/tests/cypress/integration/navigation.cy.js index 8c3b018f..2a8090ae 100644 --- a/tests/cypress/integration/navigation.cy.js +++ b/tests/cypress/integration/navigation.cy.js @@ -8,21 +8,17 @@ describe('Navigation', function () { }); + it( "Admin submenu shouldn't exist inside app", () => { + cy.get( '#adminmenu #toplevel_page_hostgator ul.wp-submenu' ).should( + 'not.exist' + ); + } ); + it('Logo Links to home', () => { cy.get('.hgwp-logo-wrap').click(); cy.wait(500); cy.hash().should('eq', '#/home'); }); - - it('Admin Subnav properly highlights', () => { - cy - .get('#adminmenu #toplevel_page_hostgator') - .should('have.class', 'wp-has-current-submenu'); - cy - .get('#adminmenu #toplevel_page_hostgator ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /home/); - }); // test main nav it('Main nav links properly navigates', () => { @@ -35,10 +31,6 @@ describe('Navigation', function () { cy .get('.hgwp-app-navitem-Marketplace') .should('have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_hostgator ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy.get('.hgwp-app-navitem-Performance').click(); cy.wait(500); @@ -49,18 +41,10 @@ describe('Navigation', function () { cy .get('.hgwp-app-navitem-Marketplace') .should('not.have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_hostgator ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /performance/); cy.get('.hgwp-app-navitem-Settings').click(); cy.wait(500); cy.hash().should('eq', '#/settings'); - cy - .get('#adminmenu #toplevel_page_hostgator ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /settings/); }); it('Subnav links properly navigates', () => { @@ -75,10 +59,6 @@ describe('Navigation', function () { cy .get('.hgwp-app-navitem-Marketplace') .should('have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_hostgator ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy.get('.hgwp-app-subnavitem-Services').click(); cy.wait(500); @@ -86,10 +66,6 @@ describe('Navigation', function () { cy .get('.hgwp-app-subnavitem-Services') .should('have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_hostgator ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy .get('.hgwp-app-navitem-Marketplace') .should('have.class', 'active'); @@ -104,10 +80,6 @@ describe('Navigation', function () { cy .get('.hgwp-app-subnavitem-Services') .should('not.have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_hostgator ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy .get('.hgwp-app-navitem-Marketplace') .should('have.class', 'active');