Skip to content

Commit

Permalink
Merge branch 'develop' into feature/3853-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter authored Dec 5, 2024
2 parents c61fa80 + 7a2bcf4 commit 14d1b30
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 291 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
key: npm-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-${{ env.NODE_VERSION }}-
- name: Prepare composer cache
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -131,7 +130,6 @@ jobs:
key: npm-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-${{ env.NODE_VERSION }}-
- name: Prepare composer cache
uses: actions/cache@v4
with:
Expand Down
6 changes: 5 additions & 1 deletion assets/css/ordering.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
color: #0073aa;
}

& .removed .title {
color: #999;
}

& .pointer-actions {
float: right;

Expand All @@ -65,7 +69,7 @@
}

& .delete-pointer {
margin-left: 10px;
margin-right: 10px;
}
}

Expand Down
6 changes: 3 additions & 3 deletions assets/js/instant-results/components/common/result.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies.
*/
import { React, WPElement } from '@wordpress/element';
import { Component, FunctionComponent, WPElement } from '@wordpress/element';
import { applyFilters } from '@wordpress/hooks';

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ const Result = ({ averageRating = 0, date, excerpt, priceHtml, thumbnail, title,
* @filter ep.InstantResults.Result
* @since 4.4.0
*
* @param {React.Component|React.FunctionComponent} Result Result component.
* @returns {React.Component|React.FunctionComponent} Result component.
* @param {Component|FunctionComponent} Result Result component.
* @returns {Component|FunctionComponent} Result component.
*/
export default applyFilters('ep.InstantResults.Result', Result);
60 changes: 30 additions & 30 deletions assets/js/ordering/pointers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies.
*/
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';

/**
* WordPress dependencies.
Expand Down Expand Up @@ -63,6 +63,7 @@ export class Pointers extends Component {
defaultResults: {},
searchText: '',
searchResults: {},
removedPointers: [],
};
}

Expand Down Expand Up @@ -101,9 +102,11 @@ export class Pointers extends Component {

removePointer = (pointer) => {
let { pointers } = this.state;
const { removedPointers } = this.state;

delete pointers[pointers.indexOf(pointer)];
pointers = pointers.filter((item) => item !== null);
removedPointers.push(pointer.ID);

this.setState({ pointers });
};
Expand All @@ -116,7 +119,7 @@ export class Pointers extends Component {
pointers = pointers.sort((a, b) => {
return a.order > b.order ? 1 : -1;
});
const pointersIds = pointers.map((pointer) => pointer.ID);
const pointersIds = pluck(pointers, 'ID');

// Remove all custom pointers from the default results
merged = merged.filter((item) => pointersIds.indexOf(item.ID) === -1);
Expand Down Expand Up @@ -183,6 +186,7 @@ export class Pointers extends Component {
pointers.push({
ID: id,
order: position,
type: 'custom-result',
});

this.setState({ pointers });
Expand Down Expand Up @@ -220,17 +224,12 @@ export class Pointers extends Component {
const pointers = [];

items.forEach((item, index) => {
if (item.order) {
// Reordering an existing pointer
pointers.push({
ID: item.ID,
order: index + 1,
});
} else if (item.ID === result.draggableId) {
// Adding a default post to the pointers array
// Reordering an existing pointer or adding a default post to the pointers array
if (item.order || item.ID === result.draggableId) {
pointers.push({
ID: item.ID,
order: index + 1,
type: item?.type || 'reordered',
});
}
});
Expand Down Expand Up @@ -293,6 +292,7 @@ export class Pointers extends Component {
defaultResults,
title,
pointers,
removedPointers,
searchText,
searchResults: searchResultsFromState,
} = this.state;
Expand Down Expand Up @@ -352,6 +352,8 @@ export class Pointers extends Component {
? index + 1
: index;

const isRemoved = removedPointers.includes(item.ID);

let { title } = item;
if (undefined === title) {
title =
Expand All @@ -361,10 +363,9 @@ export class Pointers extends Component {
}

// Determine if this result is part of default search results or not
const isDefaultResult =
undefined !== defaultResultsById[item.ID];
const itemType = item?.type || 'reordered';
const tooltipText =
isDefaultResult === true
itemType === 'reordered'
? __('Return to original position', 'elasticpress')
: __(
'Remove custom result from results list',
Expand Down Expand Up @@ -401,34 +402,25 @@ export class Pointers extends Component {

<Draggable
key={item.ID}
draggableId={item.ID}
draggableId={String(item.ID)}
index={draggableIndex}
>
{(provided2) => (
<div
className={`pointer ${draggableIndex}`}
className={`pointer ${draggableIndex} ${
isRemoved ? 'removed' : ''
}`}
ref={provided2.innerRef}
{...provided2.draggableProps}
>
{item.order && isDefaultResult === true && (
{item.order && itemType === 'reordered' && (
<span className="pointer-type">RD</span>
)}
{item.order &&
isDefaultResult === false && (
<span className="pointer-type">
CR
</span>
)}
{item.order && itemType !== 'reordered' && (
<span className="pointer-type">CR</span>
)}
<strong className="title">{title}</strong>
<div className="pointer-actions">
<span
className="dashicons dashicons-menu handle"
{...provided2.dragHandleProps}
title={__(
'Drag post up or down to reposition',
'elasticpress',
)}
/>
{item.order && (
<span
role="button"
Expand All @@ -449,6 +441,14 @@ export class Pointers extends Component {
</span>
</span>
)}
<span
className="dashicons dashicons-menu handle"
{...provided2.dragHandleProps}
title={__(
'Drag post up or down to reposition',
'elasticpress',
)}
/>
</div>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ protected function add_query_log( $query ) {
* @hook ep_disable_query_logging
* @param {bool} Whether to log to the queries property. Defaults to false.
* @return {bool} New value
* @since 5.2.0
* @since 5.1.4
*/
$disable_query_logging = apply_filters( 'ep_disable_query_logging', false );

Expand Down
2 changes: 1 addition & 1 deletion includes/classes/Feature/Facets/Facets.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public function get_selected() {
* Filter selected filters.
*
* @hook ep_facet_selected_filters
* @since 5.2.0
* @since 5.1.4
* @param {array} $filters Current filters
* @return {array} New filters
*/
Expand Down
49 changes: 49 additions & 0 deletions includes/classes/Feature/ProtectedContent/ProtectedContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function setup() {
add_filter( 'ep_admin_wp_query_integration', '__return_true' );
add_action( 'pre_get_posts', [ $this, 'integrate' ] );
add_filter( 'ep_post_query_db_args', [ $this, 'query_password_protected_posts' ] );
add_filter( 'ep_set_sort', [ $this, 'maybe_change_sort' ] );
}

if ( Features::factory()->get_registered_feature( 'comments' )->is_active() ) {
Expand Down Expand Up @@ -427,4 +428,52 @@ public function requirements_status() {
public function sync_password_protected( $new_skip, bool $skip ) : bool {
return $skip;
}

/**
* Maybe change the sort order for the WP Dashboard.
*
* If the admin user has enabled the setting to use the default WordPress sort order,
* we will change the sort order to (somewhat) match the default WP behavior.
*
* @since 5.1.4
*
* @param array $default_sort The previous value of the `ep_set_sort` filter
* @return array
*/
public function maybe_change_sort( $default_sort ) {
if ( ! function_exists( '\get_current_screen' ) ) {
return $default_sort;
}

$screen = get_current_screen();
if ( 'edit' !== $screen->base ) {
return $default_sort;
}

if ( ! $this->get_setting( 'use_default_wp_sort' ) ) {
return $default_sort;
}

return [
[ 'post_date' => [ 'order' => 'desc' ] ],
[ 'post_title.sortable' => [ 'order' => 'asc' ] ],
];
}

/**
* Set the `settings_schema` attribute
*
* @since 5.1.4
*/
protected function set_settings_schema() {
$this->settings_schema = [
[
'default' => '0',
'key' => 'use_default_wp_sort',
'help' => __( 'Enable to use WordPress default sort for searches inside the WP Dashboard.', 'elasticpress' ),
'label' => __( 'Use default WordPress sort on the WP Dashboard', 'elasticpress' ),
'type' => 'checkbox',
],
];
}
}
3 changes: 2 additions & 1 deletion includes/classes/Feature/Search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ public function enqueue_block_editor_assets() {
* @param WP_Query $query WP Query object
*/
public function exclude_posts_from_search( $filters, $args, $query ) {
$bypass_exclusion_from_search = is_admin() || ! $query->is_search();
$bypass_exclusion_from_search = ( is_admin() && ! wp_doing_ajax() ) || ! $query->is_search();

/**
* Filter whether the exclusion from the "exclude from search" checkbox should be applied
*
Expand Down
1 change: 1 addition & 0 deletions includes/classes/Feature/SearchOrdering/SearchOrdering.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ public function save_post( $post_id, $post ) {
$final_order_data[] = [
'ID' => intval( $order_data['ID'] ),
'order' => intval( $order_data['order'] ),
'type' => ! empty( $order_data['type'] ) ? sanitize_text_field( $order_data['type'] ) : 'reordered',
];
} else {
$previous_post_ids[ intval( $order_data['ID'] ) ] = true;
Expand Down
Loading

0 comments on commit 14d1b30

Please sign in to comment.