-
Notifications
You must be signed in to change notification settings - Fork 87
/
AnalyzerInsights.jsx
156 lines (144 loc) · 7.17 KB
/
AnalyzerInsights.jsx
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import * as React from "react";
import Loader from "../shared/Loader";
import isEmpty from "lodash/isEmpty";
import filter from "lodash/filter";
import MarkdownRenderer from "@src/components/shared/MarkdownRenderer";
import { sortAnalyzers, parseIconUri } from "../../utilities/utilities";
export class AnalyzerInsights extends React.Component {
constructor(props) {
super(props);
this.state = {
insights: [],
analyzing: false,
filterTiles: false,
};
}
componentDidUpdate(lastProps) {
if (this.props.insights !== lastProps.insights && this.props.insights) {
const hasProblems = this.props.insights.some(i => i.severity === "warn" || i.severity === "error");
this.handleFilterTiles(hasProblems);
}
if (this.props.insights) {
clearInterval(this.interval);
}
}
componentDidMount() {
if (this.props.insights) {
const hasProblems = this.props.insights.some(i => i.severity === "warn" || i.severity === "error");
this.handleFilterTiles(hasProblems);
}
this.checkBundleStatus();
}
checkBundleStatus = () => {
const { status, refetchSupportBundle, insights } = this.props;
if (status === "uploaded" || status === "analyzing") {
// Check if the bundle is ready only if the user is on the page
if (!insights) {
this.interval = setInterval(refetchSupportBundle, 2000);
} else {
clearInterval(this.interval);
}
}
}
componentWillUnmount() {
clearInterval(this.interval);
}
handleFilterTiles = (checked) => {
let insights = sortAnalyzers(this.props.insights);
if (checked) {
insights = filter(insights, i => i.severity === "error" || i.severity === "warn");
}
this.setState({
filterTiles: checked,
insights
});
}
render() {
const { insights, status } = this.props;
const { filterTiles } = this.state;
const filteredInsights = this.state.insights;
let noInsightsNode;
if (isEmpty(insights)) {
if (status === "uploaded" || status === "analyzing") {
noInsightsNode = (
<div className="flex-column flex1 justifyContent--center alignItems--center u-textAlign--center u-lineHeight--normal u-textColor--bodyCopy">
<Loader size="40" />
<p className="u-textColor--primary u-fontSize--normal u-fontWeight--bold">We are still analyzing this Support Bundle</p>
<p className="u-fontSize--small u-fontWeight--regular u-marginTop--10">This can tak up to a minute, you can refresh the page to see if your analysis is ready.</p>
</div>
)
} else {
noInsightsNode = (
<div className="flex-column flex1 justifyContent--center alignItems--center u-textAlign--center u-lineHeight--normal u-textColor--bodyCopy">
<p className="u-textColor--primary u-fontSize--normal u-fontWeight--bold">We were unable to surface any insights for this Support Bundle</p>
<p className="u-fontSize--small u-fontWeight--regular u-marginTop--10">It's possible that the file that was uploaded was not a Replicated Support Bundle,<br />or that collection of OS or Docker stats was not enabled in your spec.</p>
<p className="u-fontSize--small u-fontWeight--regular u-marginTop--10">We're adding new bundle analyzers all the time, so check back soon.</p>
</div>
)
}
}
return (
<div className="flex flex1">
{isEmpty(insights)
? noInsightsNode :
<div className="flex-column flex1">
<div className="flex-auto">
<div className="u-position--relative flex u-marginBottom--20 u-paddingLeft--10 u-paddingRight--10">
<input
type="checkbox"
className="filter-tiles-checkbox"
id="filterTiles"
checked={filterTiles}
onChange={(e) => { this.handleFilterTiles(e.target.checked) }}
/>
<label htmlFor="filterTiles" className="flex1 u-width--full u-position--relative u-marginLeft--5 u-cursor--pointer">
<div className="flex-column">
<span className="u-fontWeight--medium u-textColor--primary u-fontSize--normal u-marginBottom--5 u-lineHeight--normal u-userSelect--none">Only show errors and warnings</span>
</div>
</label>
</div>
</div>
{isEmpty(filteredInsights) ?
<div className="flex-column flex1 justifyContent--center alignItems--center u-textAlign--center u-lineHeight--normal u-textColor--bodyCopy">
<p className="u-textColor--primary u-fontSize--normal u-fontWeight--bold">There were no errors or warnings found.</p>
<p className="u-fontSize--small u-fontWeight--regular u-marginTop--10">Turn off "Only show errors and warnings" to see informational analyzers that we were able to surface.</p>
</div>
:
<div className="flex-column flex1 u-overflow--auto">
<div className="flex flex-auto flexWrap--wrap">
{filteredInsights && filteredInsights.map((tile, i) => {
let iconObj;
if (tile.icon) {
iconObj = parseIconUri(tile.icon);
}
return (
<div key={i} className="insight-tile-wrapper flex-column">
<div className={`insight-tile flex-auto u-textAlign--center flex-verticalCenter flex-column ${tile.severity}`}>
<div className="flex justifyContent--center u-marginBottom--10">
{tile.icon ?
<span className="tile-icon" style={{ backgroundImage: `url(${iconObj.uri})`, width: `${iconObj.dimensions?.w}px`, height: `${iconObj.dimensions?.h}px` }}></span>
: tile.icon_key ?
<span className={`icon analysis-${tile.icon_key} tile-icon`}></span>
:
<span className={`icon analysis tile-icon`}></span>
}
</div>
<p className={tile.severity === "debug" ? "u-textColor--bodyCopy u-fontSize--normal u-fontWeight--bold" : "u-textColor--primary u-fontSize--normal u-fontWeight--bold"}>{tile.primary}</p>
<MarkdownRenderer id={`markdown-wrapper-${i}`} className={tile.severity === "debug" ? "u-textColor--bodyCopy u-fontSize--smaller u-fontWeight--medium u-marginTop--5" : "u-textColor--accent u-fontSize--smaller u-fontWeight--medium u-marginTop--5"}>
{tile.detail}
</MarkdownRenderer>
{tile?.involvedObject?.kind === "Pod" && <div><span className="replicated-link u-fontSize--small u-marginTop--5" onClick={() => this.props.openPodDetailsModal(tile?.involvedObject)}>See details</span></div>}
</div>
</div>
)
})}
</div>
</div>
}
</div>
}
</div>
);
}
}
export default AnalyzerInsights;