Skip to content

Commit 2ede8d7

Browse files
authored
ref(ts): Convert utils/convertFromSelect2Choices to typescript (#21005)
1 parent 2a8192b commit 2ede8d7

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/sentry/static/sentry/app/utils/convertFromSelect2Choices.jsx

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {SelectValue} from 'app/types';
2+
3+
type Choices = Array<string | [value: string, label: string]>;
4+
5+
/**
6+
* Converts arg from a `select2` choices array to a `react-select` `options` array
7+
*/
8+
const convertFromSelect2Choices = (choices: Choices): SelectValue<any>[] | null => {
9+
// TODO(ts): This is to make sure that this function is backwards compatible, ideally,
10+
// this function only accepts arrays
11+
if (!Array.isArray(choices)) {
12+
return null;
13+
}
14+
15+
// Accepts an array of strings or an array of tuples
16+
return choices.map(choice =>
17+
Array.isArray(choice)
18+
? {value: choice[0], label: choice[1]}
19+
: {value: choice, label: choice}
20+
);
21+
};
22+
23+
export default convertFromSelect2Choices;

0 commit comments

Comments
 (0)