diff --git a/assets/js/sync-ui/apps/sync.js b/assets/js/sync-ui/apps/sync.js index 06fb401b17..c221f5283a 100644 --- a/assets/js/sync-ui/apps/sync.js +++ b/assets/js/sync-ui/apps/sync.js @@ -27,7 +27,8 @@ import { useSyncSettings } from '../provider'; */ export default () => { const { createNotice } = useSettingsScreen(); - const { isComplete, isEpio, isSyncing, logMessage, startSync, syncHistory } = useSync(); + const { isComplete, isEpio, isSyncing, logMessage, startSync, syncHistory, syncTrigger } = + useSync(); const { autoIndex } = useSyncSettings(); /** @@ -46,13 +47,13 @@ export default () => { */ const onInit = () => { if (autoIndex) { - startSync({ put_mapping: true }); + startSync({ put_mapping: true, trigger: syncTrigger }); logMessage(__('Starting delete and sync…', 'elasticpress'), 'info'); } }; useEffect(onComplete, [createNotice, isComplete]); - useEffect(onInit, [autoIndex, logMessage, startSync]); + useEffect(onInit, [autoIndex, logMessage, startSync, syncTrigger]); return ( <> diff --git a/assets/js/sync-ui/components/controls.js b/assets/js/sync-ui/components/controls.js index fd5692d90f..c8890dcdf4 100644 --- a/assets/js/sync-ui/components/controls.js +++ b/assets/js/sync-ui/components/controls.js @@ -69,7 +69,7 @@ export default () => { const { put_mapping } = args; const putMapping = syncHistory.length ? put_mapping : true; - const syncArgs = { ...args, put_mapping: putMapping }; + const syncArgs = { ...args, put_mapping: putMapping, trigger: 'manual' }; startSync(syncArgs); logMessage(__('Starting sync…', 'elasticpress'), 'info'); diff --git a/assets/js/sync-ui/components/previous-sync.js b/assets/js/sync-ui/components/previous-sync.js index 94c4031451..aa9f89e4d1 100644 --- a/assets/js/sync-ui/components/previous-sync.js +++ b/assets/js/sync-ui/components/previous-sync.js @@ -71,10 +71,16 @@ export default ({ failures, method, stateDatetime, status, trigger }) => { } switch (trigger) { + case 'features': + return __('Automatic sync after settings change.', 'elasticpress'); + case 'install': + return __('Automatic sync after installation.', 'elasticpress'); case 'manual': - default: { return __('Manual sync from Sync Settings.', 'elasticpress'); - } + case 'upgrade': + return __('Automatic sync after plugin update.', 'elasticpress'); + default: + return null; } }, [method, trigger]); @@ -101,7 +107,16 @@ export default ({ failures, method, stateDatetime, status, trigger }) => { >
- {when} — {why} + {why + ? sprintf( + /* translators: %1$s Sync date and time. %2%s sync trigger. */ __( + '%1$s — %2$s', + 'elasticpress', + ), + when, + why, + ) + : when}
{how}
diff --git a/assets/js/sync-ui/components/progress.js b/assets/js/sync-ui/components/progress.js index 6c1a88a559..ed0aed74d8 100644 --- a/assets/js/sync-ui/components/progress.js +++ b/assets/js/sync-ui/components/progress.js @@ -7,9 +7,9 @@ import classnames from 'classnames'; * WordPress dependencies. */ import { Icon } from '@wordpress/components'; -import { useMemo, WPElement } from '@wordpress/element'; +import { createInterpolateElement, useMemo, WPElement } from '@wordpress/element'; import { dateI18n } from '@wordpress/date'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { update } from '@wordpress/icons'; /** @@ -23,8 +23,16 @@ import { useSync } from '../../sync'; * @returns {WPElement} Component. */ export default () => { - const { isCli, isComplete, isFailed, isPaused, itemsProcessed, itemsTotal, syncStartDateTime } = - useSync(); + const { + isCli, + isComplete, + isFailed, + isPaused, + itemsProcessed, + itemsTotal, + syncStartDateTime, + syncTrigger, + } = useSync(); /** * Sync progress label. @@ -59,6 +67,43 @@ export default () => { const now = itemsTotal ? Math.floor((itemsProcessed / itemsTotal) * 100) : 100; + const why = useMemo(() => { + if (isCli) { + /* translators: %1$s Sync start date and time. */ + return __('Started manually from WP CLI at .', 'elasticpress'); + } + + switch (syncTrigger) { + case 'features': + /* translators: %1$s Sync start date and time. */ + return __( + 'Started automatically after a change to feature settings at .', + 'elasticpress', + ); + case 'install': + /* translators: %1$s Sync start date and time. */ + return __( + 'Started automatically after installing the ElasticPress plugin at .', + 'elasticpress', + ); + case 'manual': + /* translators: %1$s Sync start date and time. */ + return __( + 'Started manually from the Sync page at .', + 'elasticpress', + ); + case 'upgrade': + /* translators: %1$s Sync start date and time. */ + return __( + 'Started automatically after updating the ElasticPress plugin at .', + 'elasticpress', + ); + default: + /* translators: %1$s Sync start date and time. */ + return __('Started on .', 'elasticpress'); + } + }, [isCli, syncTrigger]); + return (
{
{label} - {syncStartDateTime ? ( - <> - {__('Started on', 'elasticpress')}{' '} - - - ) : null} + {syncStartDateTime + ? createInterpolateElement( + sprintf(why, dateI18n('g:ia l F jS, Y', syncStartDateTime)), + { + time:
( {children}; diff --git a/includes/classes/AdminNotices.php b/includes/classes/AdminNotices.php index 4c1767fafd..945cbcf269 100644 --- a/includes/classes/AdminNotices.php +++ b/includes/classes/AdminNotices.php @@ -182,9 +182,9 @@ protected function process_auto_activate_sync_notice() { } if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' ); + $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync=features' ); } else { - $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync' ); + $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync=features' ); } $feature = Features::factory()->get_registered_feature( $auto_activate_sync ); @@ -257,9 +257,9 @@ protected function process_upgrade_sync_notice() { } if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' ); + $url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync=upgrade' ); } else { - $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync' ); + $url = admin_url( 'admin.php?page=elasticpress-sync&do_sync=upgrade' ); } if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) { diff --git a/includes/classes/IndexHelper.php b/includes/classes/IndexHelper.php index af8ad6beb8..ea7f01d44e 100644 --- a/includes/classes/IndexHelper.php +++ b/includes/classes/IndexHelper.php @@ -144,7 +144,7 @@ protected function build_index_meta() { 'start_date_time' => $start_date_time ? $start_date_time->format( DATE_ATOM ) : false, 'starting_indices' => $starting_indices, 'messages_queue' => [], - 'trigger' => 'manual', + 'trigger' => ! empty( $this->args['trigger'] ) ? sanitize_text_field( $this->args['trigger'] ) : null, 'totals' => [ 'total' => 0, 'synced' => 0, diff --git a/includes/classes/REST/Sync.php b/includes/classes/REST/Sync.php index 62723bfee4..e57726faa7 100644 --- a/includes/classes/REST/Sync.php +++ b/includes/classes/REST/Sync.php @@ -102,6 +102,10 @@ public function get_args() { 'type' => 'boolean', 'required' => false, ], + 'trigger' => [ + 'enum' => [ 'features', 'install', 'manual', 'upgrade' ], + 'required' => false, + ], 'upper_limit_object_id' => [ 'description' => __( 'End of object ID range to sync.', 'elasticpress' ), 'type' => 'integer', diff --git a/includes/classes/Screen/Sync.php b/includes/classes/Screen/Sync.php index e14c786a4d..c2fc69f7e3 100644 --- a/includes/classes/Screen/Sync.php +++ b/includes/classes/Screen/Sync.php @@ -82,6 +82,7 @@ public function admin_enqueue_scripts() { 'nonce' => wp_create_nonce( 'wp_rest' ), 'postTypes' => array_map( fn( $post_type ) => [ $post_type, get_post_type_object( $post_type )->labels->name ], $post_types ), 'syncHistory' => $sync_history, + 'syncTrigger' => ! empty( $_GET['do_sync'] ) ? sanitize_text_field( wp_unslash( $_GET['do_sync'] ) ) : null, // phpcs:ignore WordPress.Security.NonceVerification.Recommended ]; wp_localize_script( 'ep_sync_scripts', 'epDash', $data ); diff --git a/includes/partials/install-page.php b/includes/partials/install-page.php index f92e094fc1..8808db66a0 100644 --- a/includes/partials/install-page.php +++ b/includes/partials/install-page.php @@ -12,11 +12,11 @@ if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { $setup_url = admin_url( 'network/admin.php?page=elasticpress-settings' ); - $sync_url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' ); + $sync_url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync=install' ); $dashboard_url = admin_url( 'network/admin.php?page=elasticpress' ); } else { $setup_url = admin_url( 'admin.php?page=elasticpress-settings' ); - $sync_url = admin_url( 'admin.php?page=elasticpress-sync&do_sync' ); + $sync_url = admin_url( 'admin.php?page=elasticpress-sync&do_sync=install' ); $dashboard_url = admin_url( 'admin.php?page=elasticpress' ); } diff --git a/tests/cypress/integration/features/woocommerce.cy.js b/tests/cypress/integration/features/woocommerce.cy.js index 6a4d971a89..59679dad87 100644 --- a/tests/cypress/integration/features/woocommerce.cy.js +++ b/tests/cypress/integration/features/woocommerce.cy.js @@ -336,12 +336,18 @@ describe('WooCommerce Feature', { tags: '@slow' }, () => { */ cy.contains('button', 'WooCommerce').click(); + cy.contains('label', 'Show suggestions') + .closest('.components-base-control') + .find('input') + .as('showSuggestionsCheck'); + if (!isEpIo) { - cy.get('.components-radio-control__input').first().should('be.disabled'); + cy.get('@showSuggestionsCheck').should('be.disabled'); return; } - cy.get('.components-radio-control__input').first().click(); + cy.get('@showSuggestionsCheck').check(); + cy.contains('button', 'Save and sync now').click(); cy.wait('@apiRequest');