-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathDataFlowPaths.tsx
More file actions
76 lines (65 loc) · 2.03 KB
/
DataFlowPaths.tsx
File metadata and controls
76 lines (65 loc) · 2.03 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as React from "react";
import styled from "styled-components";
import { useState } from "react";
import { useTelemetryOnChange } from "../common/telemetry";
import { CodeFlowsDropdown } from "../common/CodePaths/CodeFlowsDropdown";
import { SectionTitle, VerticalSpace } from "../common";
import { CodePath } from "../common/CodePaths/CodePath";
import { DataFlowPaths as DataFlowPathsDomainModel } from "../../variant-analysis/shared/data-flow-paths";
const PathsContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
`;
const PathDetailsContainer = styled.div`
padding: 0;
border: 0;
`;
const PathDropdownContainer = styled.div`
flex-grow: 1;
padding: 0 0 0 0.2em;
border: none;
`;
export type DataFlowPathsProps = {
dataFlowPaths: DataFlowPathsDomainModel;
};
export const DataFlowPaths = ({
dataFlowPaths,
}: {
dataFlowPaths: DataFlowPathsDomainModel;
}): JSX.Element => {
const [selectedCodeFlow, setSelectedCodeFlow] = useState(
dataFlowPaths.codeFlows[0],
);
useTelemetryOnChange(selectedCodeFlow, "code-flow-selected");
const { codeFlows, ruleDescription, message, severity } = dataFlowPaths;
React.useEffect(() => {
// Make sure to update the selected code flow if the data flow paths change
setSelectedCodeFlow(dataFlowPaths.codeFlows[0]);
}, [dataFlowPaths]);
return (
<>
<VerticalSpace size={2} />
<SectionTitle>{ruleDescription}</SectionTitle>
<VerticalSpace size={2} />
<PathsContainer>
<PathDetailsContainer>
{codeFlows.length} paths available:{" "}
{selectedCodeFlow?.threadFlows.length} steps in
</PathDetailsContainer>
<PathDropdownContainer>
<CodeFlowsDropdown
codeFlows={codeFlows}
setSelectedCodeFlow={setSelectedCodeFlow}
/>
</PathDropdownContainer>
</PathsContainer>
<VerticalSpace size={2} />
<CodePath
codeFlow={selectedCodeFlow}
severity={severity}
message={message}
/>
</>
);
};