Skip to content

Commit

Permalink
Remove pointers that are not part of the initial set of posts
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Nov 27, 2024
1 parent fa72264 commit a6433d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
4 changes: 4 additions & 0 deletions 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 Down
27 changes: 17 additions & 10 deletions assets/js/ordering/pointers.js
Original file line number Diff line number Diff line change
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 @@ -289,6 +292,7 @@ export class Pointers extends Component {
defaultResults,
title,
pointers,
removedPointers,
searchText,
searchResults: searchResultsFromState,
} = this.state;
Expand Down Expand Up @@ -348,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 @@ -357,15 +363,14 @@ 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
? __('Return to original position', 'elasticpress')
: __(
'Remove custom result from results list',
'elasticpress',
);
const tooltipText =
itemType === 'reordered'
? __('Return to original position', 'elasticpress')
: __(
'Remove custom result from results list',
'elasticpress',
);

return (
<Fragment key={item.ID}>
Expand Down Expand Up @@ -402,7 +407,9 @@ export class Pointers extends Component {
>
{(provided2) => (
<div
className={`pointer ${draggableIndex}`}
className={`pointer ${draggableIndex} ${
isRemoved ? 'removed' : ''
}`}
ref={provided2.innerRef}
{...provided2.draggableProps}
>
Expand Down

0 comments on commit a6433d2

Please sign in to comment.