This repository has been archived by the owner on May 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
KotsSidebarItem.jsx
58 lines (52 loc) · 1.87 KB
/
KotsSidebarItem.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
import React from "react";
import classNames from "classnames";
import { Link } from "react-router-dom";
export default function KotsSidebarItem(props) {
const { className, app } = props;
const { iconUri, name, slug } = app;
let downstreamPendingLengths = [];
app.downstreams?.map((w) => {
if (w.currentVersion) {
downstreamPendingLengths.push(w.pendingVersions?.length);
}
});
let versionsBehind;
if (downstreamPendingLengths?.length) {
versionsBehind = Math.max(...downstreamPendingLengths);
}
const isBehind = versionsBehind >= 2
? "2+"
: versionsBehind;
let versionsBehindText = "Up to date";
if (!app.downstreams?.length) {
versionsBehindText = "No downstreams found"
} else if (isBehind) {
versionsBehindText = `${isBehind} ${isBehind >= 2 || typeof isBehind === 'string' ? "versions" : "version"} behind`
}
return (
<div className={classNames('sidebar-link', className)}>
<Link
className="flex alignItems--center"
to={`/app/${slug}`}>
<span className="sidebar-link-icon" style={{ backgroundImage: `url(${iconUri})` }}></span>
<div className="flex-column">
<p className="u-color--tuna u-fontWeight--bold u-marginBottom--10">{name}</p>
<div className="flex alignItems--center">
<div className={classNames("icon", {
"checkmark-icon": !isBehind,
"exclamationMark--icon": isBehind,
"grayCircleMinus--icon": !app.downstreams?.length
})}
/>
<span className={classNames("u-marginLeft--5 u-fontSize--normal u-fontWeight--medium", {
"u-color--dustyGray": !isBehind,
"u-color--orange": isBehind
})}>
{versionsBehindText}
</span>
</div>
</div>
</Link>
</div>
);
}