Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect sync being triggered by URL parameter. #2939

Merged
merged 6 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions assets/js/sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ const App = () => {
(indexMeta) => {
const isInitialSync = stateRef.current.lastSyncDateTime === null;

/**
* We should not appear to be deleting if this is the first sync.
*/
const isDeleting = isInitialSync ? false : indexMeta.put_mapping;

updateState({
isCli: indexMeta.method === 'cli',
isComplete: false,
isDeleting: isInitialSync ? false : indexMeta.put_mapping,
isDeleting,
isSyncing: true,
itemsProcessed: getItemsProcessedFromIndexMeta(indexMeta),
itemsTotal: getItemsTotalFromIndexMeta(indexMeta),
Expand Down Expand Up @@ -287,13 +292,13 @@ const App = () => {

const doIndex = useCallback(
/**
* Start or continues a sync.
* Start or continue a sync.
*
* @param {boolean} isDeleting Whether to delete and sync.
* @param {boolean} putMapping Whether to send mapping.
* @returns {void}
*/
(isDeleting) => {
index(isDeleting)
(putMapping) => {
index(putMapping)
.then(updateSyncState)
.then(
/**
Expand All @@ -306,7 +311,7 @@ const App = () => {
if (method === 'cli') {
doIndexStatus();
} else {
doIndex(isDeleting);
doIndex(putMapping);
}
},
)
Expand Down Expand Up @@ -350,8 +355,14 @@ const App = () => {
const { isDeleting, lastSyncDateTime } = stateRef.current;
const isInitialSync = lastSyncDateTime === null;

/**
* Send mapping if we are deleting and syncing or if this is the
* first sync.
*/
const putMapping = isInitialSync || isDeleting;

updateState({ isComplete: false, isPaused: false, isSyncing: true });
doIndex(isInitialSync ? true : isDeleting);
doIndex(putMapping);
},
[doIndex],
);
Expand All @@ -360,16 +371,27 @@ const App = () => {
/**
* Start syncing.
*
* @param {boolean} isDeleting Whether to delete and sync.
* @param {boolean} deleteAndSync Whether to delete and sync.
* @returns {void}
*/
(isDeleting) => {
(deleteAndSync) => {
const { lastSyncDateTime } = stateRef.current;
const isInitialSync = lastSyncDateTime === null;

/**
* We should not appear to be deleting if this is the first sync.
*/
const isDeleting = isInitialSync ? false : deleteAndSync;

/**
* Send mapping if we are deleting and syncing or if this is the
* first sync.
*/
const putMapping = isInitialSync || deleteAndSync;

updateState({ isComplete: false, isDeleting, isPaused: false, isSyncing: true });
updateState({ itemsProcessed: 0, syncStartDateTime: Date.now() });
doIndex(isInitialSync ? true : isDeleting);
doIndex(putMapping);
},
[doIndex],
);
Expand Down Expand Up @@ -460,8 +482,8 @@ const App = () => {
* Start an initial index.
*/
if (autoIndex) {
startSync(false);
logMessage(__('Starting sync…', 'elasticpress'), 'info');
startSync(true);
logMessage(__('Starting delete and sync…', 'elasticpress'), 'info');
}
};

Expand Down
23 changes: 16 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions tests/cypress/integration/dashboard-sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ describe('Dashboard Sync', () => {
* 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.
* The sync log should indicate that the sync completed and that
* mapping was sent.
*/
cy.get('@syncPanel').find('.components-form-toggle').click();
cy.get('@syncPanel').find('.ep-sync-messages').should('contain.text', 'Mapping sent');
cy.get('@syncPanel')
.find('.ep-sync-messages', { timeout: Cypress.config('elasticPressIndexTimeout') })
.should('contain.text', 'Mapping sent')
.should('contain.text', 'Sync complete');

/**
* After the initial sync is complete there should be 2 sync panels
Expand Down
9 changes: 6 additions & 3 deletions tests/cypress/integration/features/protected-content.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ describe('Protected Content Feature', () => {
return true;
});

cy.get('.ep-sync-progress strong', {
timeout: Cypress.config('elasticPressIndexTimeout'),
}).should('contain.text', 'Sync complete');
cy.get('.ep-sync-panel').last().as('syncPanel');
cy.get('@syncPanel').find('.components-form-toggle').click();
cy.get('@syncPanel')
.find('.ep-sync-messages', { timeout: Cypress.config('elasticPressIndexTimeout') })
.should('contain.text', 'Mapping sent')
.should('contain.text', 'Sync complete');

cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'protected_content');
});
Expand Down
9 changes: 6 additions & 3 deletions tests/cypress/integration/features/woocommerce.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ describe('WooCommerce Feature', () => {
return true;
});

cy.get('.ep-sync-progress strong', {
timeout: Cypress.config('elasticPressIndexTimeout'),
}).should('contain.text', 'Sync complete');
cy.get('.ep-sync-panel').last().as('syncPanel');
cy.get('@syncPanel').find('.components-form-toggle').click();
cy.get('@syncPanel')
.find('.ep-sync-messages', { timeout: Cypress.config('elasticPressIndexTimeout') })
.should('contain.text', 'Mapping sent')
.should('contain.text', 'Sync complete');

cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'woocommerce');
});
Expand Down