Skip to content

Commit 8784723

Browse files
committed
Merge branch 'custom-ordering-not-respected' of Arnei/opencast-admin-interface into r/19.x
Pull request #1558 Fixes #1480 Fix custom ordering in metadata
2 parents 6604399 + de3ba58 commit 8784723

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

src/components/shared/DropDown.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
dropDownStyle,
66
} from "../../utils/componentStyles";
77
import { GroupBase, MenuListProps, Props, SelectInstance } from "react-select";
8-
import { isJson } from "../../utils/utils";
98
import { ParseKeys } from "i18next";
109
import { FixedSizeList, ListChildComponentProps } from "react-window";
1110
import AsyncSelect from "react-select/async";
@@ -102,29 +101,23 @@ const DropDown = <T, >({
102101
unformattedOptions.push({
103102
value: "",
104103
label: `-- ${t("SELECT_NO_OPTION_SELECTED")} --`,
104+
order: 0,
105105
});
106106
}
107107

108108
// Sort
109109
/**
110-
* This is used to determine whether any entry of the passed `unformattedOptions`
110+
* This is used to determine whether every entry of the passed `unformattedOptions`
111111
* contains an `order` field, indicating that a custom ordering for that list
112112
* exists and the list therefore should not be ordered alphabetically.
113113
*/
114114
const hasCustomOrder = unformattedOptions.every(item => {
115-
if (!isJson(item.label)) {
116-
return false;
117-
}
118-
// TODO: Handle JSON parsing errors
119-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
120-
const parsed = JSON.parse(item.label);
121-
return parsed && typeof parsed === "object" && "order" in parsed;
115+
return item.order !== undefined;
122116
});
123117

124118
if (hasCustomOrder) {
125119
// Apply custom ordering.
126-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
127-
unformattedOptions.sort((a, b) => JSON.parse(a.label).order - JSON.parse(b.label).order);
120+
unformattedOptions.sort((a, b) => a.order! - b.order!);
128121
} else {
129122
// Apply alphabetical ordering.
130123
unformattedOptions.sort((a, b) => a.label.localeCompare(b.label));

0 commit comments

Comments
 (0)