forked from influxdata/chronograf
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
SideNav.js
196 lines (185 loc) · 5.1 KB
/
SideNav.js
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
import React from 'react'
import PropTypes from 'prop-types'
import {withRouter, Link} from 'react-router'
import {connect} from 'react-redux'
import Authorized, {ADMIN_ROLE} from 'src/auth/Authorized'
import UserNavBlock from 'src/side_nav/components/UserNavBlock'
import {
NavBar,
NavBlock,
NavHeader,
NavListItem,
} from 'src/side_nav/components/NavItems'
import {DEFAULT_HOME_PAGE} from 'shared/constants'
const {arrayOf, bool, shape, string} = PropTypes
const SideNav = React.createClass({
propTypes: {
params: shape({
sourceID: string.isRequired,
}).isRequired,
location: shape({
pathname: string.isRequired,
}).isRequired,
isHidden: bool.isRequired,
isUsingAuth: bool,
logoutLink: string,
links: shape({
me: string,
external: shape({
custom: arrayOf(
shape({
name: string.isRequired,
url: string.isRequired,
})
),
}),
}),
me: shape({
currentOrganization: shape({
id: string.isRequired,
name: string.isRequired,
}),
name: string,
organizations: arrayOf(
shape({
id: string.isRequired,
name: string.isRequired,
})
),
roles: arrayOf(
shape({
id: string,
name: string,
})
),
}),
},
render() {
const {
params: {sourceID},
location: {pathname: location},
isHidden,
isUsingAuth,
logoutLink,
links,
me,
} = this.props
const sourcePrefix = `/sources/${sourceID}`
const dataExplorerLink = `${sourcePrefix}/chronograf/data-explorer`
const isDefaultPage = location.split('/').includes(DEFAULT_HOME_PAGE)
return isHidden ? null : (
<NavBar location={location}>
<div
className={isDefaultPage ? 'sidebar--item active' : 'sidebar--item'}
>
<Link
to={`${sourcePrefix}/${DEFAULT_HOME_PAGE}`}
className="sidebar--square sidebar--logo"
>
<span className="sidebar--icon icon cubo-uniform" />
</Link>
</div>
<NavBlock
icon="cubo-node"
link={`${sourcePrefix}/hosts`}
location={location}
>
<NavHeader link={`${sourcePrefix}/hosts`} title="Host List" />
</NavBlock>
<NavBlock icon="graphline" link={dataExplorerLink} location={location}>
<NavHeader link={dataExplorerLink} title="Data Explorer" />
</NavBlock>
<NavBlock
icon="dash-h"
link={`${sourcePrefix}/dashboards`}
location={location}
>
<NavHeader link={`${sourcePrefix}/dashboards`} title={'Dashboards'} />
</NavBlock>
<NavBlock
matcher="alerts"
icon="alert-triangle"
link={`${sourcePrefix}/alert-rules`}
location={location}
>
<NavHeader link={`${sourcePrefix}/alert-rules`} title="Alerting" />
<NavListItem link={`${sourcePrefix}/alert-rules`}>
Manage Tasks
</NavListItem>
<NavListItem link={`${sourcePrefix}/alerts`}>
Alert History
</NavListItem>
</NavBlock>
<NavBlock
icon="loudml-bold"
link={`${sourcePrefix}/loudml`}
location={location}
>
<NavHeader link={`${sourcePrefix}/loudml`} title={'Loud ML'} />
</NavBlock>
<Authorized
requiredRole={ADMIN_ROLE}
replaceWithIfNotUsingAuth={
<NavBlock
icon="crown2"
link={`${sourcePrefix}/admin-influxdb`}
location={location}
>
<NavHeader
link={`${sourcePrefix}/admin-influxdb`}
title="InfluxDB Admin"
/>
</NavBlock>
}
>
<NavBlock
icon="crown2"
link={`${sourcePrefix}/admin-chronograf`}
location={location}
>
<NavHeader
link={`${sourcePrefix}/admin-chronograf`}
title="Admin"
/>
<NavListItem link={`${sourcePrefix}/admin-chronograf`}>
Chronograf
</NavListItem>
<NavListItem link={`${sourcePrefix}/admin-influxdb`}>
InfluxDB
</NavListItem>
</NavBlock>
</Authorized>
<NavBlock
icon="cog-thick"
link={`${sourcePrefix}/manage-sources`}
location={location}
>
<NavHeader
link={`${sourcePrefix}/manage-sources`}
title="Configuration"
/>
</NavBlock>
{isUsingAuth ? (
<UserNavBlock
logoutLink={logoutLink}
links={links}
me={me}
sourcePrefix={sourcePrefix}
/>
) : null}
</NavBar>
)
},
})
const mapStateToProps = ({
auth: {isUsingAuth, logoutLink, me},
app: {ephemeral: {inPresentationMode}},
links,
}) => ({
isHidden: inPresentationMode,
isUsingAuth,
logoutLink,
links,
me,
})
export default connect(mapStateToProps)(withRouter(SideNav))