Skip to content

Commit

Permalink
Merge pull request #4018 from 10up/fix/issue-3983
Browse files Browse the repository at this point in the history
Refactor logic of custom search pointers
  • Loading branch information
felipeelia authored Nov 27, 2024
2 parents 023712b + e63f80d commit 51d6e46
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions assets/js/ordering/pointers.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,16 @@ export class Pointers extends Component {
const { title, defaultResults } = this.state;
let merged = defaultResults[title].slice();

const setIds = {};
merged.forEach((item) => {
setIds[item.ID] = item;
});

pointers = pointers.sort((a, b) => {
return a.order > b.order ? 1 : -1;
});
const pointersIds = pointers.map((pointer) => pointer.ID);

pointers.forEach((pointer) => {
// Remove the original if a duplicate
if (setIds[pointer.ID]) {
delete merged[merged.indexOf(setIds[pointer.ID])];
merged = merged.filter((item) => item);
}
// Remove all custom pointers from the default results
merged = merged.filter((item) => pointersIds.indexOf(item.ID) === -1);

// Insert into proper location
// Insert pointers into their proper location
pointers.forEach((pointer) => {
merged.splice(parseInt(pointer.order, 10) - 1, 0, pointer);
});

Expand Down

0 comments on commit 51d6e46

Please sign in to comment.