Skip to content

Commit

Permalink
Refactor logic of custom search pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Nov 26, 2024
1 parent 2fee5e2 commit 8a847a8
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 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 Expand Up @@ -426,7 +419,9 @@ export class Pointers extends Component {
CR
</span>
)}
<strong className="title">{title}</strong>
<strong className="title">
{item.order} {title}
</strong>
<div className="pointer-actions">
<span
className="dashicons dashicons-menu handle"
Expand Down

0 comments on commit 8a847a8

Please sign in to comment.