-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigationNew
More file actions
401 lines (368 loc) · 17.8 KB
/
Copy pathNavigationNew
File metadata and controls
401 lines (368 loc) · 17.8 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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
import React, { useEffect, useState } from 'react';
import { styled } from '@mui/system';
import { Drawer, List, ListItem, Tooltip } from '@mui/material';
import { Link, useLocation } from 'react-router-dom';
import { IsSuperUser } from "../../util/security";
import "../layout-styles.css";
import 'remixicon/fonts/remixicon.css'
import properties from "../../properties/properties";
import InvokeApi from "../../util/apiInvoker";
import GenerateURL, { GenerateSearchURL } from "../../util/APIUrlProvider";
import { useMatch } from 'react-router-dom';
const tenentKey = properties.tenent;
const navigationJson = [
{ label: "Maturity Insights", url: '/maturity-overview/Dora%20Metrics', subOptions: [], icon: 'ri-bar-chart-fill' },
{
label: "Velocity Insights", url: '/velocity-insights/build', icon: 'ri-pie-chart-2-line',
subOptions: [{ label: 'Build Velocity', url: '/velocity-insights/build' }, { label: 'Deploy Velocity', url: '/velocity-insights/deploy' }],
},
{
label: "Developers Insights", url: '/developer-insights', subOptions: [], icon: 'ri-code-s-slash-fill'
},
{
label: "Manage User", url: '/manage-users/users', subOptions: [{ label: 'Users', url: '/manage-users/users' },
{ label: 'Upload Users', url: '/manage-users/upload-users' }], icon: 'ri-user-settings-line'
},
{
label: "Release Compliance", url: '/release-compliance', subOptions: [], icon: 'ri-code-s-slash-fill'
},
]
const NAV_WIDTH = 86; // px — must match insights-nav width
const NavigationNew = ({ isSubOptionActive, setIsSubOptionActive, ...props }) => {
const open = props.open;
const location = useLocation();
const pathName = location?.pathname;
const match = location?.pathname;
const [subOptions, setSubOptions] = useState([]);
const [navigation, setNavigation] = useState(navigationJson);
const [subOptionTitle, setSubOptionTitle] = useState(null);
const [settingsSubOption, setSettingsSubOption] = useState(false);
// controls the floating overlay drawer
const [subDrawerOpen, setSubDrawerOpen] = useState(false);
const checkPath = (target, currentpath) => {
const firstPath = currentpath.split('/');
const targetFirstPath = target.split('/');
return firstPath[1] === targetFirstPath[1];
};
function normalizePath(path) {
return path.replace(/\/+$/, '');
}
// ── derive sub-options whenever path changes ───────────────────────────────
useEffect(() => {
let derivedSubOptions = [];
let title = 'Insights';
navigation?.forEach(navItem => {
if (checkPath(navItem.url, pathName) && navItem?.subOptions?.length > 0) {
derivedSubOptions = navItem.subOptions;
title = navItem?.label;
if (location.search !== '') {
derivedSubOptions = derivedSubOptions.map(item => {
let urlPathArray = item?.url.split('?');
if (urlPathArray?.length === 1)
item.url = normalizePath(item.url) + '/' + location.search;
return item;
});
} else {
derivedSubOptions = derivedSubOptions.map(item => {
item.url = item.url.split('?')[0];
return item;
});
}
}
});
if (derivedSubOptions?.length > 0) {
setSubOptions(derivedSubOptions);
setIsSubOptionActive(true);
setSubOptionTitle(title);
setSettingsSubOption(false);
setSubDrawerOpen(true);
} else {
setSubOptions([]);
setIsSubOptionActive(false);
setSubOptionTitle(null);
setSubDrawerOpen(false);
}
}, [pathName, navigation]);
// ── fetch maturity metric groups ──────────────────────────────────────────
useEffect(() => {
fetchData();
}, []);
const fetchData = () => {
let requestInfo = {
endPoint: GenerateURL({}, properties.api.maturityInsightsGroups),
httpMethod: "GET",
httpHeaders: { "Content-Type": "application/json" }
};
InvokeApi(requestInfo, (response) => {
const options = Array.isArray(response)
? response.map(group => ({
label: group.name,
url: `/maturity-overview/${encodeURIComponent(group.name)}`
}))
: [];
const navigations = [...navigation];
navigations[0].subOptions = options;
setNavigation(navigations);
}, () => { });
};
const checkSubOptionsSelection = (url) => {
if (location.search !== '') {
const path1 = normalizePath(pathName + location.search);
const path2 = normalizePath(url);
return path1 === path2;
}
return decodeURIComponent(pathName) === normalizePath(url);
};
const handleNavClick = (navItem, e) => {
if (navItem?.subOptions?.length > 0 && checkPath(navItem.url, pathName)) {
e.preventDefault();
setSubDrawerOpen(true);
}
};
const ontoggleState = () => {
setSettingsSubOption(false);
setSubOptions([]);
setIsSubOptionActive(false);
setSubOptionTitle(null);
setSubDrawerOpen(false);
};
const handleSettingsClick = () => {
setSettingsSubOption(true);
setSubDrawerOpen(true);
setIsSubOptionActive(false);
};
const handleSubDrawerClose = () => {
setSubDrawerOpen(false);
};
// ── sub-options panel content ─────────────────────────────────────────────
const SubOptionsContent = () => (
<SubOptionsPanel>
{/* close button */}
<button
onClick={handleSubDrawerClose}
style={{
position: 'absolute',
top: 12,
right: 10,
background: 'none',
border: 'none',
cursor: 'pointer',
color: '#8598a7',
fontSize: 18,
lineHeight: 1,
padding: '2px 4px',
borderRadius: 4,
}}
title="Close"
>
<i className="ri-close-line" />
</button>
<div className="sub-title">
{settingsSubOption ? 'Settings' : subOptionTitle}
</div>
{settingsSubOption ? (
<>
<Link to="/maturity-configuration">
<div className={checkSubOptionsSelection("/maturity-configuration") ? 'sub-options-selected d-flex align-center' : 'sub-options d-flex align-center'}>
<span>Maturity Configuration</span>
</div>
</Link>
<Link to="#">
<div className="sub-options d-flex align-center"><span>Manage Account</span></div>
</Link>
<Link to="#">
<div className="sub-options d-flex align-center"><span>Help & Support</span></div>
</Link>
</>
) : (
subOptions?.map((item, index) => (
<Link to={item.url} key={index}>
<div className={checkSubOptionsSelection(item.url) ? 'sub-options-selected d-flex align-center' : 'sub-options d-flex align-center'}>
<span>{item.label}</span>
</div>
</Link>
))
)}
</SubOptionsPanel>
);
const authData = JSON.parse(localStorage.getItem('authData') || '{}');
const isSuperuser = authData.userDetails?.is_superuser || false;
return (
<>
{/* ── primary permanent nav ─────────────────────────────────────── */}
<Drawer anchor="left" variant="permanent" open={open}>
<Root style={{ height: '100%' }}>
<div className="insights-nav">
<List className="root side-nav">
<Link to="/maturity-overview/OWASP%20Java">
<div className="d-flex align-center justify-center" style={{ padding: "12px 8px" }}>
<img src="/images/buildpiper_updated_logo.png" style={{ height: "40px", width: "72px" }} />
</div>
</Link>
<div className="main_menu">
{navigation?.map((navItem, index) => {
if (navItem.label === "Manage User" && !isSuperuser) {
return (
<Tooltip title="You don't have permission to access to this section" placement="right" key={index}>
<div style={{ display: 'flex', flexDirection: 'column', backgroundColor: checkPath(navItem.url, match) && '#1C3854', padding: "12px 8px" }} className="main-menu hover-effect">
<span style={{ color: checkPath(navItem.url, match) ? '#0086FF' : '#fff' }} className={`${navItem.icon} font-18`}></span>
<div style={{
fontSize: '11px',
fontWeight: '500',
lineHeight: "13.41px",
textAlign: 'center',
color: '#fff'
}}>
{navItem.label}
</div>
</div>
</Tooltip>
);
}
return (
<Link to={navItem.url} key={index} onClick={(e) => handleNavClick(navItem, e)}>
<div
style={{
display: 'flex',
flexDirection: 'column',
backgroundColor: checkPath(navItem.url, match) ? '#1C3854' : undefined,
padding: "12px 8px"
}}
className="main-menu hover-effect"
>
<span style={{ color: checkPath(navItem.url, match) ? '#0086FF' : '#fff' }} className={`${navItem.icon} font-18`} />
<div style={{ fontSize: '11px', fontWeight: '500', lineHeight: "13.41px", textAlign: 'center', color: '#fff' }}>
{navItem.label}
</div>
</div>
</Link>
)
}
)}
{properties.bp_url && (
<a href={properties.bp_url}>
<div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', height: "75px" }} className="main-menu hover-effect">
<img src="/images/logos/bp-white.png" width={35} height={18} alt="buildpiper" />
<div style={{ width: "56px", fontSize: '11px', fontWeight: '500', lineHeight: "13.41px", textAlign: 'center', color: "#fff", marginTop: '8px' }}>
Buildpiper
</div>
</div>
</a>
)}
</div>
</List>
<div>
<div className="d-flex align-center justify-center" style={{ marginBottom: "20px" }}>
<Link to="/initiateLogOut">
<span style={{ color: "#fff" }} className="ri-logout-circle-line font-20" />
</Link>
</div>
<div className="d-flex align-center justify-center" style={{ marginBottom: "70px" }}>
{
isSuperuser ?
<Link to={"/maturity-configuration"} onClick={ontoggleState} className='btn btn-transparent'>
<span style={{ color: "#fff" }} className="ri-settings-4-line font-20"></span>
</Link>
:
<Tooltip title="You don't have permission to access to this section" placement="right">
<span style={{ color: "#fafafa", cursor: "pointer" }} className="ri-settings-4-line font-20"></span>
</Tooltip>
}
</div>
</div>
</div>
</Root>
</Drawer>
{/* ── floating sub-options overlay — does NOT push dashboard width ─ */}
<Drawer
anchor="left"
variant="temporary"
open={subDrawerOpen}
onClose={handleSubDrawerClose}
disableEnforceFocus // keep main nav usable
disableScrollLock // don't lock page scroll
BackdropProps={{
style: { background: 'transparent' } // ← add this
}}
ModalProps={{
keepMounted: true,
}}
PaperProps={{
style: {
pointerEvents: 'auto',
left: NAV_WIDTH, // sit flush against the right edge of the nav
width: 205,
boxShadow: '4px 0 16px rgba(0,0,0,0.15)',
border: 'none',
top: 0,
height: '100%',
position: 'fixed',
}
}}
>
<SubOptionsContent />
</Drawer>
</>
);
};
export default NavigationNew;
export const drawerWidth = 90;
// ── styled components ─────────────────────────────────────────────────────────
const SubOptionsPanel = styled('div')({
position: 'relative',
background: '#fff',
width: '205px',
height: '100%',
padding: '20px 16px',
paddingTop: '44px', // room for close button
"& a": {
'& span': { fontSize: "12px", fontWeight: '600', color: '#787878' },
'&:hover': { '& span': { color: '#505050' } },
},
'& .sub-options': {
width: '100%', height: '39px', padding: '12px', borderRadius: '6px',
marginBottom: '2px',
'&:hover': { background: '#F4F4F4' }
},
'& .sub-options-selected': {
width: '100%', height: '39px', padding: '12px', borderRadius: '6px',
background: '#F4F4F4', border: '1px solid #E6E6E6', marginBottom: '2px',
},
'& .sub-title': {
fontSize: '14px', fontWeight: '600', lineHeight: '17.07px',
color: '#000', marginBottom: '20px'
},
});
const Root = styled('div')({
display: 'flex',
'& .insights-nav': {
background: '#134E9C',
width: '86px',
display: 'flex',
justifyContent: 'space-between',
flexDirection: 'column',
'& .btn-transparent': {
'&:hover': { backgroundColor: '#093267!important', color: '#fff' }
}
},
"& .main_menu": {
"& .main-menu": {
display: "flex", alignItems: "center",
backgroundColor: "#134E9C", border: "none", width: "100%"
},
"& .hover-effect": {
borderLeft: "0", borderRight: "0", borderImageSlice: "1",
transition: "background-color 0.3s ease-in-out",
"&:hover": { backgroundColor: "#1C3854" },
},
"& .main-menu>div": { display: "flex", alignItems: "center" },
"& .main-menu-icon": { width: "24px", height: "24px", marginLeft: "10px" },
"& .main-menu-name": {
fontFamily: "Montserrat", fontSize: "14px", fontWeight: "400",
lineHeight: "17px", letterSpacing: "0em", textAlign: "left",
marginLeft: "10px", color: "#ffffff"
},
"& .selected-border": { borderLeft: "4px solid #0086FF" },
"& .selected-shadow": { background: "linear-gradient(.25turn, #0086FF, 1%, #134E9C)" },
},
});