Skip to content

Commit 24bd508

Browse files
authored
Merge pull request #171 from topcoder-platform/nav-hotfix-thrive-link
Nav hotfix thrive link
2 parents 832e036 + 0694e6f commit 24bd508

File tree

5 files changed

+21
-52
lines changed

5 files changed

+21
-52
lines changed

dist/dev/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/prod/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/TopNav/SubNav.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const SubNav = ({
1212
isSecondaryMenu,
1313
isResize,
1414
activeChildId,
15+
exact,
1516
showIndicator,
1617
indicatorX,
1718
createHandleClickItem,
@@ -23,7 +24,11 @@ const SubNav = ({
2324
const to = _.isEmpty(level3.link) ? level3.href : level3.link
2425
return (
2526
<Link
26-
className={cn(styles.secondaryNavItem, level3.id === activeChildId && styles.secondaryNavItemOpen)}
27+
className={cn(
28+
styles.secondaryNavItem,
29+
level3.id === activeChildId && styles.secondaryNavItemOpen,
30+
(level3.id === activeChildId && exact) && styles.secondaryNavItemActive
31+
)}
2732
key={`level3-${i}`}
2833
to={to}
2934
onClick={!level3.openNewTab && createHandleClickItem(level3.id)}
@@ -44,6 +49,7 @@ SubNav.propTypes = {
4449
isResize: PropTypes.bool,
4550
isSecondaryMenu: PropTypes.bool,
4651
activeChildId: PropTypes.any,
52+
exact: PropTypes.bool,
4753
showIndicator: PropTypes.bool,
4854
indicatorX: PropTypes.number,
4955
createHandleClickItem: PropTypes.func,

src/components/TopNav/SubNav.module.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
}
7171
&.secondaryNavItemOpen {
7272
@include Roboto-Bold;
73+
}
74+
&.secondaryNavItemActive {
7375
@include not-clickable;
7476
}
7577
}

src/components/TopNav/index.js

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const TopNav = ({
9090
const [activeLevel1Id, setActiveLevel1Id] = useState()
9191
const [activeLevel2Id, setActiveLevel2Id] = useState()
9292
const [activeLevel3Id, setActiveLevel3Id] = useState()
93+
const [level3Exact, setLevel3Exact] = useState(false)
9394
const [isResize, setResize] = useState(false)
9495
const [showLevel3, setShowLevel3] = useState(false)
9596
const [forceHideLevel3, setforceHideLevel3] = useState(false)
@@ -249,46 +250,6 @@ const TopNav = ({
249250
}
250251
}, [activeLevel1Id, activeLevel2Id, path])
251252

252-
const isLevel3ExactPath = (menuWithId_, path_) => {
253-
let found = { exact: false }
254-
255-
// If haven't a path just return
256-
if (!path_) return found
257-
258-
menuWithId_.forEach(level1 => {
259-
level1.subMenu && level1.subMenu.forEach(level2 => {
260-
level2.subMenu && level2.subMenu.forEach(level3 => {
261-
if (level3.href && path_.indexOf(level3.href) > -1) {
262-
if (found.exact) {
263-
if (level3.href === path_) found = { exact: true }
264-
} else {
265-
found = { exact: path_.endsWith(level3.href) }
266-
}
267-
}
268-
})
269-
})
270-
level1.secondaryMenu && level1.secondaryMenu.forEach(level3 => {
271-
if (level3.href) {
272-
// Check if path have parameters
273-
const href = level3.href.indexOf('?') > -1 ? level3.href.split('?')[0] : level3.href
274-
if (path_.indexOf(href) > -1) found = { exact: path_.endsWith(href) }
275-
}
276-
})
277-
})
278-
return found
279-
}
280-
281-
useEffect(() => {
282-
if (!path || !menuWithId) return
283-
// check if current path is an exact matches with level3 href
284-
const { exact } = isLevel3ExactPath(menuWithId, path)
285-
if (!exact) {
286-
setActiveLevel3Id(undefined)
287-
setIconSelectPos(undefined)
288-
setShowIconSelect(false)
289-
}
290-
}, [activeLevel3Id])
291-
292253
const createHandleClickLevel3 = menuId => () => {
293254
setActiveLevel3Id(menuId)
294255
setIconSelectPos(menuId)
@@ -445,20 +406,19 @@ const TopNav = ({
445406
if (level2.href && path_.indexOf(level2.href) > -1) found = { m1: level1.id, m2: level2.id }
446407
level2.subMenu && level2.subMenu.forEach(level3 => {
447408
if (level3.href && path_.indexOf(level3.href) > -1) {
448-
if (found.m3) {
449-
if (level3.href === path_) found = { m1: level1.id, m2: level2.id, m3: level3.id }
450-
} else {
409+
if (level3.href && level3.href === path_) {
410+
found = { m1: level1.id, m2: level2.id, m3: level3.id }
411+
setLevel3Exact(true)
412+
} else if (!found.m3) {
451413
found = { m1: level1.id, m2: level2.id, m3: level3.id }
452414
}
453415
if (!activeLevel3Id && level3.collapsed) setforceHideLevel3(true)
454416
}
455417
})
456418
})
457419
level1.secondaryMenu && level1.secondaryMenu.forEach(level3 => {
458-
if (level3.href) {
459-
// Check if path have parameters
460-
const href = level3.href.indexOf('?') > -1 ? level3.href.split('?')[0] : level3.href
461-
if (path_.indexOf(href) > -1) found = { m1: level1.id, m3: level3.id }
420+
if (level3.href && level3.href === path_) {
421+
found = { m1: level1.id, m3: level3.id }
462422
}
463423
})
464424
})
@@ -578,6 +538,7 @@ const TopNav = ({
578538
isResize={isResize}
579539
isSecondaryMenu={!activeMenu2}
580540
activeChildId={activeLevel3Id}
541+
exact={level3Exact}
581542
showIndicator={showIconSelect}
582543
indicatorX={iconSelectX}
583544
createHandleClickItem={createHandleClickLevel3}

0 commit comments

Comments
 (0)