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

Keep alignment of custom search results action icons #4020

Merged
merged 10 commits into from
Dec 4, 2024
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
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
Loading