Skip to content

Commit

Permalink
Merge pull request #3708 from 10up/feature/feature-settings-ui
Browse files Browse the repository at this point in the history
Use toggle type for active feature control.
  • Loading branch information
felipeelia authored Oct 18, 2023
2 parents 1986da6 + 1370930 commit e2e0d4f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 54 deletions.
4 changes: 2 additions & 2 deletions includes/classes/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ public function get_settings_schema() {
$req_status = $this->requirements_status();

$active = [
'default' => 0 === $req_status->code,
'default' => false,
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => $this->requires_install_reindex,
'type' => 'checkbox',
'type' => 'toggle',
];

$settings_schema = [
Expand Down
9 changes: 4 additions & 5 deletions includes/classes/Feature/Autosuggest/Autosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ protected function maybe_add_epio_settings_schema() {
$status_report_link = defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ? network_admin_url( 'admin.php?page=elasticpress-status-report' ) : admin_url( 'admin.php?page=elasticpress-status-report' );

$this->settings_schema[] = [
'default' => sprintf(
'key' => 'epio',
'label' => sprintf(
/* translators: 1: <a> tag (ElasticPress.io); 2. </a>; 3: <a> tag (KB article); 4. </a>; 5: <a> tag (Site Health Debug Section); 6. </a>; */
__( 'You are directly connected to %1$sElasticPress.io%2$s, ensuring the most performant Autosuggest experience. %3$sLearn more about what this means%4$s or %5$sclick here for debug information%6$s.', 'elasticpress' ),
'<a href="' . esc_url( $epio_link ) . '">',
Expand All @@ -883,9 +884,7 @@ protected function maybe_add_epio_settings_schema() {
'<a href="' . esc_url( $status_report_link ) . '">',
'</a>'
),
'key' => 'epio',
'label' => __( 'Connection', 'elasticpress' ),
'type' => 'markup',
'type' => 'markup',
];
}

Expand Down Expand Up @@ -919,7 +918,7 @@ protected function set_settings_schema() {
$set_in_wp_config = defined( 'EP_AUTOSUGGEST_ENDPOINT' ) && EP_AUTOSUGGEST_ENDPOINT;

$this->settings_schema[] = [
'readonly' => $set_in_wp_config,
'disabled' => $set_in_wp_config,
'help' => $set_in_wp_config ? __( 'This address will be exposed to the public.', 'elasticpress' ) : '',
'key' => 'endpoint_url',
'label' => __( 'Endpoint URL', 'elasticpress' ),
Expand Down
4 changes: 2 additions & 2 deletions includes/classes/Feature/DidYouMean/DidYouMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct() {
$this->available_during_installation = true;

$this->default_settings = [
'search_behavior' => false,
'search_behavior' => '0',
];

$this->set_settings_schema();
Expand Down Expand Up @@ -426,7 +426,7 @@ public function the_output( $query = null ) {
protected function set_settings_schema() {
$this->settings_schema = [
[
'default' => false,
'default' => '0',
'key' => 'search_behavior',
'label' => __( 'Search behavior when no result is found', 'elasticpress' ),
'options' => [
Expand Down
24 changes: 7 additions & 17 deletions includes/classes/Feature/InstantResults/InstantResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct() {

$this->default_settings = [
'highlight_tag' => 'mark',
'facets' => 'post_type,category,post_tag',
'facets' => 'post_type,tax-category,tax-post_tag',
'match_type' => 'all',
'term_count' => '1',
'per_page' => get_option( 'posts_per_page', 6 ),
Expand Down Expand Up @@ -954,6 +954,7 @@ public function get_facets_for_admin() {
foreach ( $available_facets as $key => $facet ) {
$facets[ $key ] = array(
'label' => $facet['labels']['admin'],
'value' => $key,
);
}

Expand Down Expand Up @@ -1059,6 +1060,8 @@ public function get_title() : string {
* @since 5.0.0
*/
protected function set_settings_schema() {
$facets = $this->get_facets_for_admin();

$this->settings_schema = [
[
'default' => 'mark',
Expand Down Expand Up @@ -1094,23 +1097,10 @@ protected function set_settings_schema() {
'type' => 'select',
],
[
'default' => 'post_type,category,post_tag',
'default' => 'post_type,tax-category,tax-post_tag',
'key' => 'facets',
'label' => __( 'Filters', 'elasticpress' ),
'options' => [
[
'label' => 'post_type',
'value' => 'post_type',
],
[
'label' => 'category',
'value' => 'category',
],
[
'label' => 'post_tag',
'value' => 'post_tag',
],
],
'options' => array_values( $facets ),
'type' => 'multiple',
],
[
Expand Down Expand Up @@ -1153,7 +1143,7 @@ protected function set_settings_schema() {
'type' => 'hidden',
],
[
'default' => '',
'default' => '0',
'key' => 'search_behavior',
'label' => __( 'Search behavior when no result is found', 'elasticpress' ),
'options' => [
Expand Down
13 changes: 0 additions & 13 deletions includes/classes/Feature/Search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,19 +922,6 @@ protected function set_settings_schema() {
],
'type' => 'radio',
],
[
'default' => '.ep-autosuggest',
'help' => __( 'Input additional selectors where you would like to include autosuggest separated by a comma. Example: .custom-selector, #custom-id, input[type="text"]', 'elasticpress' ),
'key' => 'autosuggest_selector',
'label' => __( 'Autosuggest Selector', 'elasticpress' ),
'type' => 'text',
],
[
'key' => 'trigger_ga_event',
'help' => __( 'When enabled, a gtag tracking event is fired when an autosuggest result is clicked.', 'elasticpress' ),
'label' => __( 'Google Analytics Events', 'elasticpress' ),
'type' => 'checkbox',
],
[
'default' => 'simple',
'key' => 'synonyms_editor_mode',
Expand Down
7 changes: 3 additions & 4 deletions includes/classes/REST/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ public function get_args() {
case 'radio':
$property['enum'] = array_map( fn( $o ) => $o['value'], $schema['options'] );
break;
case 'multiple':
$property['type'] = 'string';
break;
case 'checkbox':
case 'toggle':
$property['type'] = 'boolean';
break;
case 'checkbox':
case 'multiple':
default:
$property['type'] = 'string';
break;
Expand Down
5 changes: 1 addition & 4 deletions tests/cypress/integration/features/instant-results.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ describe('Instant Results Feature', { tags: '@slow' }, () => {
cy.intercept('**/wp-admin/admin-ajax.php*').as('ajaxRequest');
cy.visitAdminPage('admin.php?page=elasticpress');
cy.get('.ep-feature-instant-results .settings-button').click();
cy.get('.ep-feature-instant-results .components-form-token-field__input').type(
'cat{downArrow}{enter}',
);
cy.get('.ep-feature-instant-results .components-form-token-field__input').type(
'prod{downArrow}{enter}{esc}',
);
Expand Down Expand Up @@ -239,7 +236,7 @@ describe('Instant Results Feature', { tags: '@slow' }, () => {
cy.intercept('/wp-admin/admin-ajax.php*').as('ajaxRequest');
cy.get('.ep-feature-instant-results .settings-button').click();
cy.get('.ep-feature-instant-results .components-form-token-field__input').type(
'{backspace}{backspace}price{downArrow}{enter}{esc}',
'{backspace}{backspace}{backspace}price{downArrow}{enter}{esc}',
);
cy.get('.ep-feature-instant-results .button-primary').click();
cy.wait('@ajaxRequest');
Expand Down
10 changes: 5 additions & 5 deletions tests/php/TestFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function() {
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => false,
'type' => 'checkbox',
'type' => 'toggle',
],
],
];
Expand Down Expand Up @@ -79,11 +79,11 @@ public function test_get_settings_schema() {
$this->assertSame(
[
[
'default' => true,
'default' => false,
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => false,
'type' => 'checkbox',
'type' => 'toggle',
],
[ 'key' => 'test_1' ],
[ 'key' => 'test_2' ],
Expand Down Expand Up @@ -113,11 +113,11 @@ public function test_ep_feature_settings_schema_filter() {
$this->assertSame(
[
[
'default' => true,
'default' => false,
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => false,
'type' => 'checkbox',
'type' => 'toggle',
],
[ 'key' => 'new_field' ],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/php/features/TestDidYouMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testConstruct() {
$this->assertTrue( $instance->requires_install_reindex );
$this->assertTrue( $instance->available_during_installation );
$this->assertTrue( $instance->is_visible() );
$this->assertSame( [ 'search_behavior' => false ], $instance->default_settings );
$this->assertSame( [ 'search_behavior' => '0' ], $instance->default_settings );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/php/features/TestSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function test_get_settings_schema() {

$settings_keys = wp_list_pluck( $settings_schema, 'key' );

$expected = [ 'active', 'decaying_enabled', 'highlight_enabled', 'highlight_tag', 'highlight_excerpt', 'autosuggest_selector', 'trigger_ga_event', 'synonyms_editor_mode' ];
$expected = [ 'active', 'decaying_enabled', 'highlight_enabled', 'highlight_tag', 'highlight_excerpt', 'synonyms_editor_mode' ];
if ( ! is_multisite() ) {
$expected[] = 'additional_links';
}
Expand Down

0 comments on commit e2e0d4f

Please sign in to comment.