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

Feature/1932 #2491

Merged
merged 4 commits into from
Dec 6, 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
Next Next commit
Display confirmation message when toggling features that require rein…
…dex.
  • Loading branch information
JakePT committed Dec 6, 2021
commit 9d59f58ae16440e6034e115658d29ed3258fbfa5
5 changes: 5 additions & 0 deletions assets/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ h2.ep-list-features {
border-left: 4px solid var(--statusOk);
margin-bottom: 10px;
padding: 8px 12px;

&.requirements-status-notice--reindex {
border-color: var(--statusWarning);
display: none; /* Controlled by JavaScript. */
}
}

.ep-feature .settings .action-wrap {
Expand Down
39 changes: 38 additions & 1 deletion assets/js/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable camelcase, no-use-before-define */
import { __ } from '@wordpress/i18n';

const { ajaxurl, epDash } = window;

const $features = jQuery(document.getElementsByClassName('ep-features'));
Expand Down Expand Up @@ -27,7 +29,7 @@ $features.on('click', '.save-settings', function (event) {
return;
}

const feature = event.target.getAttribute('data-feature');
const { feature, requiresReindex, wasActive } = event.target.dataset;
const $feature = $features.find(`.ep-feature-${feature}`);
const settings = {};
const $settings = $feature.find('.setting-field');
Expand All @@ -47,6 +49,22 @@ $features.on('click', '.save-settings', function (event) {
}
});

const requiresConfirmation = requiresReindex && wasActive !== settings.active;

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?',
'elasticpress',
),
);

if (!isConfirmed) {
return;
}
}

$feature.addClass('saving');

jQuery
Expand All @@ -70,6 +88,8 @@ $features.on('click', '.save-settings', function (event) {
$feature.removeClass('feature-active');
}

event.target.dataset.wasActive = settings.active;

if (response.data.reindex) {
window.location = epDash.sync_url;

Expand Down Expand Up @@ -137,3 +157,20 @@ $epCredentialsTab.on('click', (e) => {
$epCredentialsAdditionalFields.attr('aria-hidden', 'true');
}
});

$features.on('change', '.js-toggle-feature', function (event) {
const container = event.currentTarget
.closest('.settings')
.querySelector('.requirements-status-notice--reindex');

const { value } = event.target;
const { requiresReindex, wasActive } = event.currentTarget.dataset;

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

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/dashboard-script.min.js

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions includes/classes/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,16 @@ public function output_settings_box() {
<?php endforeach; ?>
<?php endif; ?>

<?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'); ?>
</div>
<?php endif; ?>

<h3><?php esc_html_e( 'Settings', 'elasticpress' ); ?></h3>

<div class="feature-fields">
<div class="field js-toggle-feature" data-feature="<?php echo esc_attr( $this->slug ); ?>">
<div class="field js-toggle-feature" data-feature="<?php echo esc_attr( $this->slug ); ?>" data-requires-reindex="<?php echo $this->requires_install_reindex ? '1' : '0'; ?>" data-was-active="<?php echo $this->is_active() ? '1' : '0'; ?>">
<div class="field-name status"><?php esc_html_e( 'Status', 'elasticpress' ); ?></div>
<div class="input-wrap <?php if ( 2 === $requirements_status->code ) : ?>disabled<?php endif; ?>">
<label for="feature_active_<?php echo esc_attr( $this->slug ); ?>_enabled"><input name="feature_active_<?php echo esc_attr( $this->slug ); ?>" id="feature_active_<?php echo esc_attr( $this->slug ); ?>_enabled" data-field-name="active" class="setting-field" <?php if ( 2 === $requirements_status->code ) : ?>disabled<?php endif; ?> type="radio" <?php if ( $this->is_active() ) : ?>checked<?php endif; ?> value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?></label><br>
Expand All @@ -288,7 +294,13 @@ public function output_settings_box() {
<?php esc_html_e( 'Setting adjustments to this feature require a re-sync. Use WP-CLI.', 'elasticpress' ); ?>
</span>

<a data-feature="<?php echo esc_attr( $this->slug ); ?>" class="<?php if ( 2 === $requirements_status->code || ( $this->requires_install_reindex && defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) ) : ?>disabled<?php endif; ?> button button-primary save-settings"><?php esc_html_e( 'Save', 'elasticpress' ); ?></a>
<a
data-feature="<?php echo esc_attr( $this->slug ); ?>"
data-requires-reindex="<?php echo $this->requires_install_reindex ? '1' : '0'; ?>"
data-was-active="<?php echo $this->is_active() ? '1' : '0'; ?>"
class="<?php if ( 2 === $requirements_status->code || ( $this->requires_install_reindex && defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) ) : ?>disabled<?php endif; ?> button button-primary save-settings">
<?php esc_html_e( 'Save', 'elasticpress' ); ?>
</a>
</div>
<?php
}
Expand Down