diff --git a/.github/workflows/brand-plugin-test.yml b/.github/workflows/brand-plugin-test.yml
index f31d801..326ac8a 100644
--- a/.github/workflows/brand-plugin-test.yml
+++ b/.github/workflows/brand-plugin-test.yml
@@ -31,6 +31,7 @@ jobs:
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'bluehost/bluehost-wordpress-plugin'
+ plugin-branch: 'add/app-nav-notifications'
secrets: inherit
hostgator:
diff --git a/assets/js/components/notifications/index.js b/assets/js/components/notifications/index.js
index a0dfe5c..6d6c0fd 100644
--- a/assets/js/components/notifications/index.js
+++ b/assets/js/components/notifications/index.js
@@ -37,15 +37,15 @@ const Notifications = ({methods, constants, ...props}) => {
)
}).then( ( response ) => {
setAllNotifications(response);
- });
- }, [] );
+ });
+ }, [] );
// on update notifications, context or page calculate active notifications
methods.useEffect(() => {
setActiveNotifications(
filterNotifications(allNotifications)
);
- }, [allNotifications, constants.page]);
+ }, [allNotifications, constants.page]);
/**
* Wrapper method to filter notifications
@@ -73,7 +73,7 @@ const Notifications = ({methods, constants, ...props}) => {
* @returns Array of filtered notifications - removes expired notifications
*/
const filterByExpiry = (notifications) => {
- const now = Date.now();
+ const now = Math.round(Date.now() / 1000);
// console.log( 'Now: ' + now );
// filter out expired notifications
return methods.filter(notifications,
@@ -150,19 +150,33 @@ const Notifications = ({methods, constants, ...props}) => {
);
}
- return (
-
- {activeNotifications.map(notification => (
+ if (`${window.NewfoldRuntime.plugin.brand}-app-nav` === constants.context && activeNotifications.length > 0) {
+ return (
+
- ))}
-
- )
+
+ );
+ } else {
+ return (
+
+ {activeNotifications.map(notification => (
+
+ ))}
+
+ );
+ }
};
diff --git a/includes/Notification.php b/includes/Notification.php
index debdaf5..5cf9caa 100644
--- a/includes/Notification.php
+++ b/includes/Notification.php
@@ -121,6 +121,7 @@ public function shouldShow( $context, array $contextData ) {
}
case container()->plugin()->id . '-plugin':
+ case container()->plugin()->id . '-app-nav':
// The current page
$current_page = Arr::get( $contextData, 'page' );
diff --git a/includes/NotificationsApi.php b/includes/NotificationsApi.php
index 12f5d2c..c61af6e 100644
--- a/includes/NotificationsApi.php
+++ b/includes/NotificationsApi.php
@@ -52,6 +52,7 @@ function ( Notification $notification ) {
'validate_callback' => function ( $value ) {
return is_string( $value ) && in_array( $value, array(
container()->plugin()->id . '-plugin',
+ container()->plugin()->id . '-app-nav',
'wp-admin-notice',
'wp-admin-prime'
), true );
@@ -61,7 +62,7 @@ function ( Notification $notification ) {
'required' => false,
'validate_callback' => function ( $value, \WP_REST_Request $request ) {
$context = $request->get_param( 'context' );
- if ( container()->plugin()->id . '-plugin' === $context || 'wp-admin-notice' === $context ) {
+ if ( container()->plugin()->id . '-plugin' === $context || container()->plugin()->id . '-app-nav' === $context || 'wp-admin-notice' === $context ) {
return is_string( $value );
}
diff --git a/tests/cypress/integration/notifications.cy.js b/tests/cypress/integration/notifications.cy.js
index aaaaec5..8674bd4 100644
--- a/tests/cypress/integration/notifications.cy.js
+++ b/tests/cypress/integration/notifications.cy.js
@@ -8,7 +8,7 @@ const notifications = [
pages: '#/settings',
},
],
- expiration: 2748863456503,
+ expiration: 2748820256,
content:
'Notice should only display on plugin app settings page
',
},
@@ -20,7 +20,7 @@ const notifications = [
pages: [ '#/home/onboarding', '#/home' ],
},
],
- expiration: 2749860279240,
+ expiration: 2749860279,
content:
'Here is a plugin notice it should display on home and onboarding screens only!
',
},
@@ -32,7 +32,7 @@ const notifications = [
pages: [ '#/marketplace' ],
},
],
- expiration: 2749860279240,
+ expiration: 2749860279,
content:
'Here is a plugin notice it should display on marketplace themes screen only!
',
},
@@ -48,10 +48,22 @@ const notifications = [
pages: 'all',
},
],
- expiration: 2749860279240,
+ expiration: 2749860279,
content:
'Here is a notice it should display everywhere in the app and in wp-admin!
',
},
+ {
+ id: 'test-5',
+ locations: [
+ {
+ context: Cypress.env( 'pluginId' ) + '-app-nav',
+ pages: 'all',
+ },
+ ],
+ expiration: 2749860279,
+ content:
+ 'Notice should display in the app side nav
',
+ },
{
id: 'test-expired',
locations: [
@@ -60,7 +72,7 @@ const notifications = [
pages: 'all',
},
],
- expiration: 1649860279240,
+ expiration: 1649817079,
content:
'Here is an expired notice it should never display anywhere even though it has location `all`
',
},
@@ -70,7 +82,7 @@ describe( 'Notifications', () => {
const appClass = '.' + Cypress.env( 'appId' );
before( () => {
- cy.exec( 'npx wp-env run cli wp transient delete newfold_notifications' );
+ cy.exec( 'npx wp-env run cli wp transient delete newfold_notifications', {failOnNonZeroExit: false} );
cy.visit( '/wp-admin/index.php' );
cy.intercept(
{
@@ -131,6 +143,18 @@ describe( 'Notifications', () => {
).contains( 'display on plugin app settings page' );
} );
+ // notification renders on the side nav
+ it( 'Test notification displays in app side nav', () => {
+ cy.get( '.newfold-nav-notifications-wrapper #notification-test-5' )
+ .should( 'be.visible' )
+ .should( 'have.attr', 'data-id' )
+ .and( 'equal', 'test-5' );
+
+ cy.get(
+ '.newfold-nav-notifications-wrapper #notification-test-5'
+ ).contains( 'display in the app side nav' );
+ } );
+
// expired notification should not show
it( 'Test expired notification does not display in plugin app', () => {
cy.get(