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

Display a notice that content will be reindexed when enabling a feature that requires it #2524

Merged
merged 3 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Only display notice when enabling a feature.
  • Loading branch information
JakePT authored and felipeelia committed Dec 15, 2021
commit 7d8f2323668c299b0e3c368ca08b2fc5a3a132d3
11 changes: 6 additions & 5 deletions assets/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ $features.on('click', '.save-settings', function (event) {
}
});

const requiresConfirmation = requiresReindex && wasActive !== settings.active;
const requiresConfirmation = requiresReindex && wasActive === '0' && settings.active === '1';

if (requiresConfirmation) {
// eslint-disable-next-line no-alert
const isConfirmed = window.confirm(
__(
'Toggling this feature will begin re-indexing your content. Do you wish to proceed?',
'Enabling this feature will begin re-indexing your content. Do you wish to proceed?',
'elasticpress',
),
);
Expand Down Expand Up @@ -103,6 +103,9 @@ $features.on('click', '.save-settings', function (event) {
}

event.target.dataset.wasActive = settings.active;
event.target
.closest('.settings')
.querySelector('.js-toggle-feature').dataset.wasActive = settings.active;

if (response.data.reindex) {
syncStatus = 'initialsync';
Expand Down Expand Up @@ -602,11 +605,9 @@ $features.on('change', '.js-toggle-feature', function (event) {
const { value } = event.target;
const { requiresReindex, wasActive } = event.currentTarget.dataset;

if (requiresReindex && wasActive !== value) {
if (requiresReindex && wasActive === '0' && value === '1') {
container.style.display = 'block';
} else {
container.style.display = null;
}

event.currentTarget.dataset.requiresReindex = value;
});
2 changes: 1 addition & 1 deletion dist/js/dashboard-script.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion includes/classes/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function output_settings_box() {

<?php if ( $this->requires_install_reindex ) : ?>
<div class="requirements-status-notice requirements-status-notice--reindex" role="status">
<?php esc_html_e( 'Toggling this feature will require re-indexing your content.', 'elasticpress'); ?>
<?php esc_html_e( 'Enabling this feature will require re-indexing your content.', 'elasticpress'); ?>
</div>
<?php endif; ?>

Expand Down