-
Notifications
You must be signed in to change notification settings - Fork 87
/
SupportBundleAnalysis.jsx
300 lines (280 loc) · 13.7 KB
/
SupportBundleAnalysis.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import * as React from "react";
import { withRouter, Switch, Route, Link } from "react-router-dom";
import dayjs from "dayjs";
import Modal from "react-modal";
import Loader from "../shared/Loader";
import AnalyzerInsights from "./AnalyzerInsights";
import AnalyzerFileTree from "./AnalyzerFileTree";
import AnalyzerRedactorReport from "./AnalyzerRedactorReport";
import PodAnalyzerDetails from "./PodAnalyzerDetails";
import ErrorModal from "../modals/ErrorModal";
import { Utilities } from "../../utilities/utilities";
import "../../scss/components/troubleshoot/SupportBundleAnalysis.scss";
import download from "downloadjs";
export class SupportBundleAnalysis extends React.Component {
constructor(props) {
super();
this.state = {
activeTab: props.location.pathname.indexOf("/contents") !== -1 ? "fileTree" : location.pathname.indexOf("/redactor") !== -1 ? "redactorReport" : "bundleAnalysis",
filterTiles: "0",
downloadingBundle: false,
bundle: null,
loading: false,
downloadBundleErrMsg: "",
getSupportBundleErrMsg: "",
sendingBundle: false,
sendingBundleErrMsg: "",
displayErrorModal: false,
showPodAnalyzerDetailsModal: false,
};
}
togglePodDetailsModal = (selectedPod) => {
this.setState({ showPodAnalyzerDetailsModal: !this.state.showPodAnalyzerDetailsModal, selectedPod });
}
sendBundleToVendor = async () => {
this.setState({ sendingBundle: true, sendingBundleErrMsg: "", downloadBundleErrMsg: "" });
fetch(`${window.env.API_ENDPOINT}/troubleshoot/app/${this.props.match.params.slug}/supportbundle/${this.props.match.params.bundleSlug}/share`, {
method: "POST",
headers: {
"Authorization": Utilities.getToken(),
}
})
.then(async (result) => {
if (!result.ok) {
const text = await result.text();
let msg = `Unable to send bundle to vendor: Status ${result.status}, please try again.`;
if (text) {
msg = `Unable to send bundle to vendor: ${text}`;
}
this.setState({ sendingBundle: false, sendingBundleErrMsg: msg });
return;
}
await this.getSupportBundle();
this.setState({ sendingBundle: false, sendingBundleErrMsg: "" });
})
.catch(err => {
console.log(err);
this.setState({ sendingBundle: false, sendingBundleErrMsg: err ? `Unable to send bundle to vendor: ${err.message}` : "Something went wrong, please try again." });
})
}
downloadBundle = async (bundle) => {
this.setState({ downloadingBundle: true, downloadBundleErrMsg: "", sendingBundleErrMsg: "" });
fetch(`${window.env.API_ENDPOINT}/troubleshoot/supportbundle/${bundle.id}/download`, {
method: "GET",
headers: {
"Authorization": Utilities.getToken(),
}
})
.then(async (result) => {
if (!result.ok) {
this.setState({ downloadingBundle: false, downloadBundleErrMsg: `Unable to download bundle: Status ${result.status}, please try again.` });
return;
}
let filename = "";
const disposition = result.headers.get("Content-Disposition");
if (disposition) {
filename = disposition.split("filename=")[1];
} else {
const createdAt = dayjs(bundle.createdAt).format("YYYY-MM-DDTHH_mm_ss");
filename = `supportbundle-${createdAt}.tar.gz`;
}
const blob = await result.blob();
download(blob, filename, "application/gzip");
this.setState({ downloadingBundle: false, downloadBundleErrMsg: "" });
})
.catch(err => {
console.log(err);
this.setState({ downloadingBundle: false, downloadBundleErrMsg: err ? `Unable to download bundle: ${err.message}` : "Something went wrong, please try again." });
})
}
getSupportBundle = async () => {
this.setState({ loading: true, getSupportBundleErrMsg: "", displayErrorModal: false });
fetch(`${window.env.API_ENDPOINT}/troubleshoot/supportbundle/${this.props.match.params.bundleSlug}`, {
headers: {
"Content-Type": "application/json",
"Authorization": Utilities.getToken(),
},
method: "GET",
})
.then(async (res) => {
if (!res.ok) {
this.setState({
loading: false,
getSupportBundleErrMsg: `Unexpected status code: ${res.status}`,
displayErrorModal: true
});
return;
}
const bundle = await res.json();
this.setState({
bundle: bundle,
loading: false,
getSupportBundleErrMsg: "",
displayErrorModal: false
});
})
.catch((err) => {
console.log(err);
this.setState({
loading: false,
getSupportBundleErrMsg: err ? err.message : "Something went wrong, please try again.",
displayErrorModal: true
});
});
}
toggleErrorModal = () => {
this.setState({ displayErrorModal: !this.state.displayErrorModal });
}
toggleAnalysisAction = (active) => {
this.setState({
activeTab: active,
});
}
componentDidMount() {
this.getSupportBundle();
}
componentDidUpdate = (lastProps) => {
const { location } = this.props;
if (location !== lastProps.location) {
this.setState({
activeTab: location.pathname.indexOf("/contents") !== -1 ? "fileTree" : location.pathname.indexOf("/redactor") !== -1 ? "redactorReport" : "bundleAnalysis"
});
}
}
render() {
const { watch } = this.props;
const { bundle, loading, getSupportBundleErrMsg } = this.state;
if (loading) {
return (
<div className="flex-column flex1 justifyContent--center alignItems--center">
<Loader size="60" />
</div>
)
}
const insightsUrl = `/app/:slug/troubleshoot/analyze/:bundleSlug`;
const fileTreeUrl = `/app/:slug/troubleshoot/analyze/:bundleSlug/contents/*`;
const redactorUrl = `/app/:slug/troubleshoot/analyze/:bundleSlug/redactor/report`;
const showSendSupportBundleBtn = watch.isSupportBundleUploadSupported && !watch.isAirgap;
return (
<div className="container u-marginTop--20 u-paddingBottom--30 flex1 flex-column">
<div className="flex1 flex-column">
{bundle &&
<div className="flex1 flex-column">
<div className="u-position--relative flex-auto u-marginBottom--20 flex justifyContent--spaceBetween">
<div className="flex flex1 u-marginTop--10 u-marginBottom--10">
<div className="flex-column flex1">
<div className="u-fontSize--small u-fontWeight--medium u-textColor--bodyCopy u-marginBottom--20">
<Link to={`/app/${this.props.watch.slug}/troubleshoot`} className="replicated-link u-marginRight--5">Support bundles</Link> > <span className="u-marginLeft--5">{dayjs(bundle.createdAt).format("MMMM D, YYYY")}</span>
</div>
<div className="flex flex1 justifyContent--spaceBetween">
<div className="flex flex-column">
<h2 className="u-fontSize--header2 u-fontWeight--bold u-textColor--primary flex alignContent--center alignItems--center">Support bundle analysis</h2>
</div>
</div>
<div className="upload-date-container flex u-marginTop--5 alignItems--center">
<div className="flex alignSelf--center">
<p className="flex u-fontSize--normal u-textColor--bodyCopy u-fontWeight--medium">Collected on <span className="u-fontWeight--bold u-marginLeft--5">{dayjs(bundle.createdAt).format("MMMM D, YYYY @ h:mm a")}</span></p>
</div>
</div>
</div>
<div className="flex flex-auto alignItems--center justifyContent--flexEnd">
{this.state.downloadBundleErrMsg && <p className="u-textColor--error u-fontSize--normal u-fontWeight--medium u-lineHeight--normal u-marginRight--10">{this.state.downloadBundleErrMsg}</p>}
{this.state.sendingBundleErrMsg && <p className="u-textColor--error u-fontSize--normal u-fontWeight--medium u-lineHeight--normal u-marginRight--10">{this.state.sendingBundleErrMsg}</p>}
{showSendSupportBundleBtn && (
this.state.sendingBundle
? <Loader className="u-marginRight--10" size="30" />
: !bundle.sharedAt
? <button className="btn primary lightBlue u-marginRight--10" onClick={this.sendBundleToVendor}>Send bundle to vendor</button>
: <div className="sentToVendorWrapper flex alignItems--flexEnd u-paddingLeft--10 u-paddingRight--10 u-marginRight--10">
<span style={{ marginRight: 7 }} className="icon send-icon" />
<span className="u-fontWeight--bold u-fontSize--small u-color--mutedteal">Sent to vendor on {Utilities.dateFormat(bundle.sharedAt, "MM/DD/YYYY")}</span>
</div>
)}
{this.state.downloadingBundle ?
<Loader size="30" /> :
<button className={`btn ${showSendSupportBundleBtn ? "secondary blue" : "primary lightBlue"}`} onClick={() => this.downloadBundle(bundle)}> Download bundle </button>
}
</div>
</div>
</div>
{watch.licenseType === "community" &&
<div className="flex">
<div className="CommunityLicenseBundle--wrapper flex flex1 alignItems--center">
<div className="flex flex-auto">
<span className="icon communityIcon"></span>
</div>
<div className="flex1 flex-column u-marginLeft--10">
<p className="u-textColor--accent u-fontSize--large u-fontWeight--bold u-lineHeight--medium u-marginBottom--5"> This bundle was uploaded by a customer under a Community license type. </p>
<p className="u-textColor--info u-fontSize--normal u-lineHeight--medium"> Customers with Community licenses are using the free, Community-Supported version of Nomad Enterprise. </p>
</div>
</div>
</div>}
<div className="flex-column flex1">
<div className="SupportBundleTabs--wrapper flex1 flex-column">
<div className="tab-items flex">
<Link to={`/app/${watch.slug}/troubleshoot/analyze/${bundle.slug}`} className={`${this.state.activeTab === "bundleAnalysis" ? "is-active" : ""} tab-item blue`} onClick={() => this.toggleAnalysisAction("bundleAnalysis")}>Analysis overview</Link>
<Link to={`/app/${watch.slug}/troubleshoot/analyze/${bundle.slug}/contents/`} className={`${this.state.activeTab === "fileTree" ? "is-active" : ""} tab-item blue`} onClick={() => this.toggleAnalysisAction("fileTree")}>File inspector</Link>
<Link to={`/app/${watch.slug}/troubleshoot/analyze/${bundle.slug}/redactor/report`} className={`${this.state.activeTab === "redactorReport" ? "is-active" : ""} tab-item blue`} onClick={() => this.toggleAnalysisAction("redactorReport")}>Redactor report</Link>
</div>
<div className="flex-column flex1 action-content">
<Switch>
<Route exact path={insightsUrl} render={() =>
<AnalyzerInsights
status={bundle.status}
refetchSupportBundle={this.getSupportBundle}
insights={bundle.analysis?.insights}
openPodDetailsModal={this.togglePodDetailsModal}
/>
} />
<Route exact path={fileTreeUrl} render={() =>
<AnalyzerFileTree
watchSlug={watch.slug}
bundle={bundle}
downloadBundle={() => this.downloadBundle(bundle)}
/>
} />
<Route exact path={redactorUrl} render={() =>
<AnalyzerRedactorReport
watchSlug={watch.slug}
bundle={bundle}
/>
} />
</Switch>
</div>
</div>
</div>
</div>
}
</div>
{getSupportBundleErrMsg &&
<ErrorModal
errorModal={this.state.displayErrorModal}
toggleErrorModal={this.toggleErrorModal}
errMsg={getSupportBundleErrMsg}
tryAgain={this.getSupportBundle}
err="Failed to get bundle"
loading={this.state.loading}
appSlug={this.props.match.params.slug}
/>}
{this.state.showPodAnalyzerDetailsModal &&
<Modal
isOpen={true}
shouldReturnFocusAfterClose={false}
onRequestClose={() => this.togglePodDetailsModal({})}
ariaHideApp={false}
contentLabel="Modal"
className="Modal PodAnalyzerDetailsModal LargeSize"
>
<div className="Modal-body">
<PodAnalyzerDetails bundleId={bundle.id} pod={this.state.selectedPod} />
<div className="u-marginTop--10">
<button type="button" className="btn primary blue" onClick={() => this.togglePodDetailsModal({})}>Ok, got it!</button>
</div>
</div>
</Modal>
}
</div>
);
}
}
export default withRouter(SupportBundleAnalysis);