From b9bd2a4622c62c957cc1e496881af342eead110e Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Fri, 24 Jun 2022 18:17:25 +1000 Subject: [PATCH 1/4] Show a single sync option for the initial sync. --- assets/js/sync/components/sync-page.js | 192 +++++++----------------- assets/js/sync/components/sync/panel.js | 151 +++++++++++++++++++ assets/js/sync/index.js | 26 +++- 3 files changed, 222 insertions(+), 147 deletions(-) create mode 100644 assets/js/sync/components/sync/panel.js diff --git a/assets/js/sync/components/sync-page.js b/assets/js/sync/components/sync-page.js index 45507f374d..2e4bfb26a1 100644 --- a/assets/js/sync/components/sync-page.js +++ b/assets/js/sync/components/sync-page.js @@ -1,18 +1,13 @@ /** * WordPress dependencies. */ -import { Button, Icon, Panel, PanelBody } from '@wordpress/components'; import { WPElement } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; -import { warning } from '@wordpress/icons'; +import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies. */ -import SyncControls from './sync/controls'; -import SyncLog from './sync/log'; -import SyncProgress from './sync/progress'; -import SyncStatus from './sync/status'; +import SyncPanel from './sync/panel'; /** * Sync page component. @@ -21,6 +16,7 @@ import SyncStatus from './sync/status'; * @param {boolean} props.isCli If sync is a CLI sync. * @param {boolean} props.isComplete If sync is complete. * @param {boolean} props.isDeleting If sync is a delete and sync. + * @param {boolean} props.isEpio If ElasticPress is using ElasticPress.io. * @param {boolean} props.isPaused If sync is paused. * @param {boolean} props.isSyncing If sync is running. * @param {number} props.itemsProcessed Number of items processed. @@ -36,147 +32,61 @@ import SyncStatus from './sync/status'; * @param {string} props.syncStartDateTime Date and time of current sync in ISO 8601. * @returns {WPElement} Sync page component. */ -export default ({ - isCli, - isComplete, - isDeleting, - isPaused, - isSyncing, - itemsProcessed, - itemsTotal, - lastSyncDateTime, - lastSyncFailed, - log, - onDelete, - onPause, - onResume, - onStop, - onSync, - syncStartDateTime, -}) => { +export default ({ isCli, isComplete, isDeleting, isEpio, isSyncing, log, ...props }) => { + const isInitialSync = props.lastSyncDateTime === null; + return ( <>

{__('Sync Settings', 'elasticpress')}

- - -
-

- {__( + - - {lastSyncDateTime ? ( - <> -

- {__('Last Sync', 'elasticpress')} -

- - - ) : null} -
- -
- -
- - {!isDeleting && (isSyncing || isComplete) ? ( -
- -
- ) : null} + ) + } + isComplete={isComplete} + isDisabled={(isSyncing && isDeleting) || (isSyncing && isCli)} + isSyncing={isSyncing && !isDeleting} + logMessages={log.filter((m) => !m.isDeleting)} + showLastSync + showProgress={!isDeleting && (isSyncing || isComplete)} + showSync + {...props} + /> -
- !m.isDeleting)} /> -
-
-
- -

{__('Delete All Data and Sync', 'elasticpress')}

- - - -
-

- {__( - 'If you are still having issues with your search results, you may need to do a completely fresh sync.', - 'elasticpress', - )} -

- -

- -

-
- -
- -
- - {isDeleting && (isSyncing || isComplete) ? ( -
- -
- ) : null} - -
- m.isDeleting)} /> -
- -
-

- - {__( - 'All indexed data on ElasticPress will be deleted without affecting anything on your WordPress website. This may take a few hours depending on the amount of content that needs to be synced and indexed. While this is happening, searches will use the default WordPress results', - 'elasticpress', - )} -

-
-
-
+ {!isInitialSync ? ( + m.isDeleting)} + showDelete + showProgress={isDeleting && (isSyncing || isComplete)} + warningMessage={__( + 'All indexed data on ElasticPress will be deleted without affecting anything on your WordPress website. This may take a few hours depending on the amount of content that needs to be synced and indexed. While this is happening, searches will use the default WordPress results', + 'elasticpress', + )} + {...props} + /> + ) : null} ); }; diff --git a/assets/js/sync/components/sync/panel.js b/assets/js/sync/components/sync/panel.js new file mode 100644 index 0000000000..dc83f4e600 --- /dev/null +++ b/assets/js/sync/components/sync/panel.js @@ -0,0 +1,151 @@ +/** + * WordPress dependencies. + */ +import { Button, Icon, Panel, PanelBody } from '@wordpress/components'; +import { WPElement } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { warning } from '@wordpress/icons'; + +/** + * Internal dependencies. + */ +import SyncControls from './controls'; +import SyncLog from './log'; +import SyncProgress from './progress'; +import SyncStatus from './status'; + +/** + * Sync page component. + * + * @param {object} props Component props. + * @param {string} props.heading Panel heading. + * @param {string} props.introduction Panel introduction. + * @param {boolean} props.isCli If sync is a CLI sync. + * @param {boolean} props.isComplete If sync is complete. + * @param {boolean} props.isDisabled If controls are disabled. + * @param {boolean} props.isPaused If sync is paused. + * @param {boolean} props.isSyncing If sync is running. + * @param {number} props.itemsProcessed Number of items processed. + * @param {number} props.itemsTotal Number of items to process. + * @param {string} props.lastSyncDateTime Date and time of last sync in ISO-8601. + * @param {boolean} props.lastSyncFailed If the last sync had failures. + * @param {object[]} props.logMessages Log messages. + * @param {Function} props.onDelete Callback for clicking delete and sync. + * @param {Function} props.onPause Callback for clicking pause. + * @param {Function} props.onResume Callback for clicking resume. + * @param {Function} props.onStop Callback for clicking stop. + * @param {Function} props.onSync Callback for clicking sync. + * @param {string} props.syncStartDateTime Date and time of current sync in ISO 8601. + * @param {boolean} props.showLastSync Whether to show the last sync details. + * @param {boolean} props.showDelete Whether to show the delete button. + * @param {boolean} props.showProgress Whether to show the progress bar. + * @param {boolean} props.showSync Whether to show the sync button. + * @param {string} props.warningMessage Warning message. + * @returns {WPElement} Sync page component. + */ +export default ({ + heading, + introduction, + isCli, + isComplete, + isDisabled, + isPaused, + isSyncing, + itemsProcessed, + itemsTotal, + lastSyncDateTime, + lastSyncFailed, + logMessages, + onDelete, + onPause, + onResume, + onStop, + onSync, + showDelete, + showLastSync, + showProgress, + showSync, + syncStartDateTime, + warningMessage, +}) => { + return ( + <> + {heading ?

{heading}

: null} + + + +
+ {introduction ? ( +

{introduction}

+ ) : null} + + {showLastSync && lastSyncDateTime ? ( + <> +

+ {__('Last Sync', 'elasticpress')} +

+ + + ) : null} + + {showDelete ? ( +

+ +

+ ) : null} +
+ +
+ +
+ + {showProgress ? ( +
+ +
+ ) : null} + +
+ +
+ + {warningMessage ? ( +
+

+ + {warningMessage} +

+
+ ) : null} +
+
+ + ); +}; diff --git a/assets/js/sync/index.js b/assets/js/sync/index.js index 194bb2bb48..879b00a620 100644 --- a/assets/js/sync/index.js +++ b/assets/js/sync/index.js @@ -103,6 +103,11 @@ const App = () => { lastSyncDateTime: indexTotals.end_date_time, lastSyncFailed: indexTotals.failed > 0, }); + + /** + * Hide the "just need to sync" notice, if it's present. + */ + document.querySelector('[data-ep-notice="no_sync"]')?.remove(); }, [], ); @@ -175,10 +180,12 @@ const App = () => { * @returns {void} */ (indexMeta) => { + const isInitialSync = stateRef.current.lastSyncDateTime === null; + updateState({ isCli: indexMeta.method === 'cli', isComplete: false, - isDeleting: indexMeta.put_mapping, + isDeleting: isInitialSync ? false : indexMeta.put_mapping, isSyncing: true, itemsProcessed: getItemsProcessedFromIndexMeta(indexMeta), itemsTotal: getItemsTotalFromIndexMeta(indexMeta), @@ -333,23 +340,29 @@ const App = () => { * @returns {void} */ () => { + const { isDeleting, lastSyncDateTime } = stateRef.current; + const isInitialSync = lastSyncDateTime === null; + updateState({ isComplete: false, isPaused: false, isSyncing: true }); - doIndex(stateRef.current.isDeleting); + doIndex(isInitialSync ? true : isDeleting); }, [doIndex], ); const startSync = useCallback( /** - * Stop syncing. + * Start syncing. * * @param {boolean} isDeleting Whether to delete and sync. * @returns {void} */ (isDeleting) => { + const { lastSyncDateTime } = stateRef.current; + const isInitialSync = lastSyncDateTime === null; + updateState({ isComplete: false, isDeleting, isPaused: false, isSyncing: true }); updateState({ itemsProcessed: 0, syncStartDateTime: Date.now() }); - doIndex(isDeleting); + doIndex(isInitialSync ? true : isDeleting); }, [doIndex], ); @@ -440,8 +453,8 @@ const App = () => { * Start an initial index. */ if (autoIndex) { - startSync(true); - logMessage(__('Starting delete and sync…', 'elasticpress'), 'info'); + startSync(false); + logMessage(__('Starting sync…', 'elasticpress'), 'info'); } }; @@ -455,6 +468,7 @@ const App = () => { */ return ( Date: Tue, 9 Aug 2022 21:21:22 +1000 Subject: [PATCH 2/4] Add a test for the initial sync. --- .../integration/dashboard-sync.spec.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/cypress/integration/dashboard-sync.spec.js b/tests/cypress/integration/dashboard-sync.spec.js index f946764a65..d3435eac69 100644 --- a/tests/cypress/integration/dashboard-sync.spec.js +++ b/tests/cypress/integration/dashboard-sync.spec.js @@ -35,6 +35,51 @@ describe('Dashboard Sync', () => { } }); + it('There should only be a single sync option for the initial sync', () => { + /** + * Reset settings and skip install. + */ + cy.wpCli('elasticpress settings-reset --yes'); + cy.visitAdminPage('admin.php?page=elasticpress'); + cy.get('.setup-message a').contains('Skip Install').click(); + + /** + * If a sync has not been performed the sync page should only show a + * single sync panel. + */ + cy.visitAdminPage('admin.php?page=elasticpress-sync'); + cy.get('.ep-sync-panel') + .should('have.length', 1) + .as('syncPanel') + .should('contain.text', 'Run a sync to index your existing content in Elasticsearch.'); + + /** + * Perform an initial sync. + */ + cy.get('@syncPanel').find('.ep-sync-button').click(); + cy.get('.ep-sync-progress__details', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync complete'); + + /** + * The sync log should indicate that mapping was sent. + */ + cy.get('@syncPanel').find('.components-form-toggle').click(); + cy.get('@syncPanel').find('.ep-sync-messages').should('contain.text', 'Mapping sent'); + + /** + * After the initial sync is complete there should be 2 sync panels + * and the second should contain the delete & sync option. + */ + cy.get('.ep-sync-panel') + .should('have.length', 2) + .last() + .should( + 'contain.text', + 'If you are still having issues with your search results, you may need to do a completely fresh sync.', + ); + }); + it('Can index content and see indexes names in the Health Screen', () => { cy.visitAdminPage('admin.php?page=elasticpress-sync'); cy.get('.ep-sync-button--delete').click(); From bb9927d49e03e813886c5b7834ad34fc83a631d7 Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Tue, 9 Aug 2022 22:17:38 +1000 Subject: [PATCH 3/4] Fix expected message in test. --- tests/cypress/integration/dashboard-sync.spec.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/cypress/integration/dashboard-sync.spec.js b/tests/cypress/integration/dashboard-sync.spec.js index d3435eac69..c6920acbba 100644 --- a/tests/cypress/integration/dashboard-sync.spec.js +++ b/tests/cypress/integration/dashboard-sync.spec.js @@ -35,7 +35,7 @@ describe('Dashboard Sync', () => { } }); - it('There should only be a single sync option for the initial sync', () => { + it('Should only display a single sync option for the initial sync', () => { /** * Reset settings and skip install. */ @@ -51,7 +51,7 @@ describe('Dashboard Sync', () => { cy.get('.ep-sync-panel') .should('have.length', 1) .as('syncPanel') - .should('contain.text', 'Run a sync to index your existing content in Elasticsearch.'); + .should('contain.text', 'Run a sync to index your existing content'); /** * Perform an initial sync. @@ -74,10 +74,7 @@ describe('Dashboard Sync', () => { cy.get('.ep-sync-panel') .should('have.length', 2) .last() - .should( - 'contain.text', - 'If you are still having issues with your search results, you may need to do a completely fresh sync.', - ); + .should('contain.text', 'If you are still having issues with your search results'); }); it('Can index content and see indexes names in the Health Screen', () => { From fe591d88aead3d700b1ae5b58a3e301fbf2b6d0e Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Wed, 10 Aug 2022 19:53:10 +1000 Subject: [PATCH 4/4] Fix tests of install skipping the setup step. --- .../cypress/wordpress-files/test-plugins/fake-new-activation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cypress/wordpress-files/test-plugins/fake-new-activation.php b/tests/cypress/wordpress-files/test-plugins/fake-new-activation.php index 81941d6562..05935dc82e 100644 --- a/tests/cypress/wordpress-files/test-plugins/fake-new-activation.php +++ b/tests/cypress/wordpress-files/test-plugins/fake-new-activation.php @@ -8,3 +8,4 @@ */ add_filter( 'pre_option_ep_last_sync', '__return_empty_array' ); +add_filter( 'option_ep_skip_install', '__return_false' );