-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathCodeFlowsDropdown.tsx
More file actions
49 lines (43 loc) · 1.38 KB
/
CodeFlowsDropdown.tsx
File metadata and controls
49 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type { SetStateAction } from "react";
import { useCallback } from "react";
import {
VscodeOption,
VscodeSingleSelect,
} from "@vscode-elements/react-elements";
import type { CodeFlow } from "../../../variant-analysis/shared/analysis-result";
const getCodeFlowName = (codeFlow: CodeFlow) => {
const filePath =
codeFlow.threadFlows[codeFlow.threadFlows.length - 1].fileLink.filePath;
return filePath.substring(filePath.lastIndexOf("/") + 1);
};
type CodeFlowsDropdownProps = {
codeFlows: CodeFlow[];
selectedCodeFlow: CodeFlow;
setSelectedCodeFlow: (value: SetStateAction<CodeFlow>) => void;
};
export const CodeFlowsDropdown = ({
codeFlows,
selectedCodeFlow,
setSelectedCodeFlow,
}: CodeFlowsDropdownProps) => {
const handleChange = useCallback(
(e: Event) => {
const selectedOption = e.target as HTMLSelectElement;
const selectedIndex = parseInt(selectedOption.value);
setSelectedCodeFlow(codeFlows[selectedIndex]);
},
[setSelectedCodeFlow, codeFlows],
);
const value = codeFlows
.findIndex((codeFlow) => selectedCodeFlow === codeFlow)
.toString();
return (
<VscodeSingleSelect value={value} onChange={handleChange}>
{codeFlows.map((codeFlow, index) => (
<VscodeOption key={index} value={index.toString()}>
{getCodeFlowName(codeFlow)}
</VscodeOption>
))}
</VscodeSingleSelect>
);
};