|
5 | 5 | dropDownStyle, |
6 | 6 | } from "../../utils/componentStyles"; |
7 | 7 | import { GroupBase, MenuListProps, Props, SelectInstance } from "react-select"; |
8 | | -import { isJson } from "../../utils/utils"; |
9 | 8 | import { ParseKeys } from "i18next"; |
10 | 9 | import { FixedSizeList, ListChildComponentProps } from "react-window"; |
11 | 10 | import AsyncSelect from "react-select/async"; |
@@ -102,29 +101,23 @@ const DropDown = <T, >({ |
102 | 101 | unformattedOptions.push({ |
103 | 102 | value: "", |
104 | 103 | label: `-- ${t("SELECT_NO_OPTION_SELECTED")} --`, |
| 104 | + order: 0, |
105 | 105 | }); |
106 | 106 | } |
107 | 107 |
|
108 | 108 | // Sort |
109 | 109 | /** |
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` |
111 | 111 | * contains an `order` field, indicating that a custom ordering for that list |
112 | 112 | * exists and the list therefore should not be ordered alphabetically. |
113 | 113 | */ |
114 | 114 | 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; |
122 | 116 | }); |
123 | 117 |
|
124 | 118 | if (hasCustomOrder) { |
125 | 119 | // 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!); |
128 | 121 | } else { |
129 | 122 | // Apply alphabetical ordering. |
130 | 123 | unformattedOptions.sort((a, b) => a.label.localeCompare(b.label)); |
|
0 commit comments