Skip to content

Commit

Permalink
IBX-9322: ezobjectrelationlist field allows selecting the same conten…
Browse files Browse the repository at this point in the history
…t multiple times
  • Loading branch information
lucasOsti committed Dec 13, 2024
1 parent 843ac71 commit 1c5593e
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,20 @@
sourceInput.dispatchEvent(new CustomEvent(EVENT_CUSTOM));
};
const onConfirm = (items) => {
items = excludeDuplicatedItems(items);
const itemsWithoutDuplicate = excludeDuplicatedItems(items);

renderRows(items);
renderRows(itemsWithoutDuplicate);
attachRowsEventHandlers();

selectedItems = [...selectedItems, ...items.map((item) => item.ContentInfo.Content._id)];
selectedItems = [...selectedItems, ...itemsWithoutDuplicate.map((item) => item.ContentInfo.Content._id)];

updateInputValue(selectedItems);
closeUDW();
updateFieldState();
updateAddBtnState();
relationsTable.dispatchEvent(new CustomEvent('ibexa-refresh-main-table-checkbox'));
};

const openUDW = (event) => {
event.preventDefault();

Expand Down Expand Up @@ -157,11 +158,7 @@
}),
);
};
const excludeDuplicatedItems = (items) => {
selectedItemsMap = items.reduce((total, item) => ({ ...total, [item.ContentInfo.Content._id]: item }), selectedItemsMap);

return items.filter((item) => selectedItemsMap[item.ContentInfo.Content._id]);
};
const excludeDuplicatedItems = (items) => items.filter((item) => !selectedItems.includes(item.ContentInfo.Content._id));
const renderRow = (item, index) => {
const { escapeHTML } = ibexa.helpers.text;
const { formatShortDateTime } = ibexa.helpers.timezone;
Expand Down Expand Up @@ -304,7 +301,6 @@
updateInputValue(selectedItems);
};
let selectedItems = [...fieldContainer.querySelectorAll(SELECTOR_ROW)].map((row) => parseInt(row.dataset.contentId, 10));
let selectedItemsMap = selectedItems.reduce((total, item) => ({ ...total, [item]: item }), {});

updateAddBtnState();
attachRowsEventHandlers();
Expand Down

0 comments on commit 1c5593e

Please sign in to comment.