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

2896: make it work with both id and @id #260

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- [#260](https://github.com/os2display/display-admin-client/pull/260)
- Bug in multiselect, fixed by removing duplicates by key both `@id`and `id`

- [#259](https://github.com/os2display/display-admin-client/pull/259)
- Add saving of playlists/groups with screen (as opposed to _after_)
- Clean up `screen-manager.jsx`
Expand Down
26 changes: 18 additions & 8 deletions src/components/util/forms/multiselect-dropdown/multi-dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import "./multi-dropdown.scss";
* @param {Array} props.selected - The selected options
* @param {string} props.name - The id of the form element
* @param {boolean} props.isLoading - Whether the component is loading.
* @param {string | null} props.noSelectedString - The label for when there is nothing selected.
* @param {string | null} props.noSelectedString - The label for when there is
* nothing selected.
* @param {string} props.errorText - The string to display on error.
* @param {string} props.label - The input label
* @param {string | null} props.helpText - Help text for the dropdown.
Expand Down Expand Up @@ -122,13 +123,22 @@ function MultiSelectComponent({
const addOrRemoveNewEntryToSelected = (multiselectData) => {
let selectedOptions = [];
const idsOfSelectedEntries = multiselectData.map(({ value }) => value);

selectedOptions = removeDuplicatesByKey(
[...selected, ...options].filter((option) =>
idsOfSelectedEntries.includes(option["@id"] || option.id)
),
"@id"
);
const selectedAndOptions = [...selected, ...options];
if ("@id" in selectedAndOptions[0]) {
selectedOptions = removeDuplicatesByKey(
selectedAndOptions.filter((option) =>
idsOfSelectedEntries.includes(option["@id"])
),
"@id"
);
} else {
selectedOptions = removeDuplicatesByKey(
selectedAndOptions.filter(({ id }) =>
idsOfSelectedEntries.includes(id)
),
"id"
);
}

if (singleSelect) {
selectedOptions = [selectedOptions[selectedOptions.length - 1]];
Expand Down
Loading