-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathModelAlertsResults.tsx
More file actions
134 lines (119 loc) · 3.54 KB
/
ModelAlertsResults.tsx
File metadata and controls
134 lines (119 loc) · 3.54 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { styled } from "styled-components";
import type { ModelAlerts } from "../../model-editor/model-alerts/model-alerts";
import { Codicon } from "../common";
import { useCallback, useEffect, useRef, useState } from "react";
import { formatDecimal } from "../../common/number";
import AnalysisAlertResult from "../variant-analysis/AnalysisAlertResult";
import { MethodName } from "../model-editor/MethodName";
import { ModelDetails } from "./ModelDetails";
import { vscode } from "../vscode-api";
import { createModeledMethodKey } from "../../model-editor/modeled-method";
import type { ModeledMethod } from "../../model-editor/modeled-method";
import { Link } from "../common/Link";
import { Badge } from "../common/Badge";
// This will ensure that these icons have a className which we can use in the TitleContainer
const ExpandCollapseCodicon = styled(Codicon)``;
const TitleContainer = styled.button`
display: flex;
gap: 0.5em;
align-items: center;
width: 100%;
color: var(--vscode-editor-foreground);
background-color: transparent;
border: none;
cursor: pointer;
&:disabled {
cursor: default;
${ExpandCollapseCodicon} {
color: var(--vscode-disabledForeground);
}
}
`;
const ModelTypeText = styled.span`
font-size: 0.85em;
color: var(--vscode-descriptionForeground);
`;
const ViewLink = styled(Link)`
white-space: nowrap;
padding: 0 0 0.25em 1em;
`;
const ModelDetailsContainer = styled.div`
padding-top: 10px;
`;
const AlertsContainer = styled.ul`
list-style-type: none;
margin: 1em 0 0;
padding: 0.5em 0 0 0;
`;
const Alert = styled.li`
margin-bottom: 1em;
background-color: var(--vscode-notifications-background);
`;
interface Props {
modelAlerts: ModelAlerts;
revealedModel: ModeledMethod | null;
}
export const ModelAlertsResults = ({
modelAlerts,
revealedModel,
}: Props): React.JSX.Element => {
const [isExpanded, setExpanded] = useState(true);
const viewInModelEditor = useCallback(
() =>
vscode.postMessage({
t: "revealInModelEditor",
method: modelAlerts.model,
}),
[modelAlerts.model],
);
const ref = useRef<HTMLElement | undefined>(undefined);
useEffect(() => {
if (
revealedModel &&
createModeledMethodKey(modelAlerts.model) ===
createModeledMethodKey(revealedModel)
) {
ref.current?.scrollIntoView({
behavior: "smooth",
block: "center",
});
}
}, [modelAlerts.model, revealedModel]);
return (
<div>
<TitleContainer onClick={() => setExpanded(!isExpanded)}>
{isExpanded && (
<ExpandCollapseCodicon name="chevron-down" label="Collapse" />
)}
{!isExpanded && (
<ExpandCollapseCodicon name="chevron-right" label="Expand" />
)}
<Badge>{formatDecimal(modelAlerts.alerts.length)}</Badge>
<MethodName {...modelAlerts.model}></MethodName>
<ModelTypeText>{modelAlerts.model.type}</ModelTypeText>
<ViewLink
onClick={(event: React.MouseEvent) => {
event.stopPropagation();
viewInModelEditor();
}}
>
View
</ViewLink>
</TitleContainer>
{isExpanded && (
<>
<ModelDetailsContainer>
<ModelDetails model={modelAlerts.model} />
</ModelDetailsContainer>
<AlertsContainer>
{modelAlerts.alerts.map((r, i) => (
<Alert key={i}>
<AnalysisAlertResult alert={r.alert} />
</Alert>
))}
</AlertsContainer>
</>
)}
</div>
);
};