Skip to content

Commit 169aa50

Browse files
authored
Merge pull request #368 from topcoder-platform/PROD-2014_nav-fixes
PROD-2014 fix tools nav so that it can support new tools -> PROD-1516_work-filter
2 parents 0d4d82b + eab855b commit 169aa50

File tree

6 files changed

+58
-29
lines changed

6 files changed

+58
-29
lines changed

src-ts/header/tool-selectors/tool-selectors-narrow/tool-selector-narrow/ToolSelectorNarrow.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import classNames from 'classnames'
2-
import { FC } from 'react'
2+
import { FC, useContext } from 'react'
33
import { Link, useLocation } from 'react-router-dom'
44

5-
import { IconOutline, PlatformRoute, routeIsActive } from '../../../../lib'
5+
import { IconOutline, PlatformRoute, routeContext, RouteContextData, routeIsActive } from '../../../../lib'
66

77
import styles from './ToolSelectorNarrow.module.scss'
88

@@ -14,22 +14,23 @@ const isParamRoute: (route: string) => boolean = (route: string) => !!route.matc
1414

1515
const ToolSelectorNarrow: FC<ToolSelectorNarrowProps> = (props: ToolSelectorNarrowProps) => {
1616

17-
const route: PlatformRoute = props.route
18-
const path: string = props.route.route
17+
const { getPathFromRoute }: RouteContextData = useContext(routeContext)
18+
const toolRoute: PlatformRoute = props.route
19+
const toolPath: string = getPathFromRoute(toolRoute)
1920

2021
const baseClass: string = 'tool-selector-narrow'
21-
const isActive: boolean = routeIsActive(useLocation().pathname, path)
22+
const isActive: boolean = routeIsActive(useLocation().pathname, toolPath)
2223
const activeIndicaterClass: string = `${baseClass}-${isActive ? '' : 'in'}active`
23-
const hasChildren: boolean = !!route.children.some(child => !!child.route && !isParamRoute(child.route))
24+
const hasChildren: boolean = !!toolRoute.children.some(child => !!child.route && !isParamRoute(child.route))
2425

2526
return (
2627
<div className={styles[baseClass]}>
2728
<Link
2829
className={classNames(styles[`${baseClass}-link`], styles[activeIndicaterClass])}
29-
key={path}
30-
to={path}
30+
key={toolPath}
31+
to={toolPath}
3132
>
32-
{route.title}
33+
{toolRoute.title}
3334
{hasChildren && <IconOutline.ChevronRightIcon />}
3435
</Link>
3536
</div>

src-ts/header/tool-selectors/tool-selectors-wide/tool-selector-wide/ToolSelectorWide.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import classNames from 'classnames'
22
import { FC, useContext } from 'react'
33
import { Link, useLocation } from 'react-router-dom'
44

5-
import { ToolTitle } from '../../../../config'
6-
import { PlatformRoute, routeContext, RouteContextData, routeIsActive, routeIsHome } from '../../../../lib'
5+
import {
6+
PlatformRoute,
7+
routeContext,
8+
RouteContextData,
9+
routeIsActive,
10+
routeIsHome,
11+
} from '../../../../lib'
712
import '../../../../lib/styles/index.scss'
813

914
import styles from './ToolSelectorWide.module.scss'
@@ -14,15 +19,17 @@ interface ToolSelectorWideProps {
1419

1520
const ToolSelectorWide: FC<ToolSelectorWideProps> = (props: ToolSelectorWideProps) => {
1621

17-
const { getPath, getPathFromRoute }: RouteContextData = useContext(routeContext)
18-
const currentPath: string = useLocation().pathname
22+
const { getPathFromRoute }: RouteContextData = useContext(routeContext)
23+
const activePath: string = useLocation().pathname
24+
const toolRoute: PlatformRoute = props.route
25+
const toolPath: string = getPathFromRoute(toolRoute)
26+
27+
const isActive: boolean = routeIsActive(activePath, toolPath)
1928

20-
// for now, the work tool should be active for all pages except the account
21-
const isActive: boolean = !routeIsActive(currentPath, getPath(ToolTitle.settings))
2229
const activeIndicatorClass: string = `tool-selector-wide-${isActive ? '' : 'in'}active`
2330

2431
// the tool link should be usable for all active routes except the home page
25-
const isLink: boolean = isActive && !routeIsHome(currentPath)
32+
const isLink: boolean = isActive && !routeIsHome(activePath)
2633

2734
return (
2835
<div className={classNames(
@@ -33,9 +40,9 @@ const ToolSelectorWide: FC<ToolSelectorWideProps> = (props: ToolSelectorWideProp
3340
<Link
3441
className='large-tab'
3542
tabIndex={-1}
36-
to={getPathFromRoute(props.route)}
43+
to={toolPath}
3744
>
38-
{props.route.title}
45+
{toolRoute.title}
3946
</Link>
4047
<div className={styles['active-indicator']}></div>
4148
</div>

src-ts/lib/functions/authentication-functions/authentication-url.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { EnvironmentConfig } from '../../../config'
2+
import { routeSelfServiceRoot } from '../../route-provider'
23

34
export const authentication: string = EnvironmentConfig.URL.ACCOUNTS_APP_CONNECTOR
45

56
export function login(fallback: string): string {
67
return `${authentication}?retUrl=${encodeURIComponent(window.location.href.match(/[^?]*/)?.[0] || fallback)}`
78
}
89

9-
export const logout: string = `${authentication}?logout=true&retUrl=${encodeURIComponent('https://' + window.location.host)}/self-service`
10+
export const logout: string = `${authentication}?logout=true&retUrl=${encodeURIComponent('https://' + window.location.host)}${routeSelfServiceRoot}`
1011

1112
export function signup(fallback: string): string {
1213
return `${login(fallback)}&regSource=tcBusiness&mode=signUp`
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
export const routeRoot: string = '/work/dashboard'
2+
export const routeSelfServiceRoot: string = '/self-service'
3+
export const routeSelfServiceStart: string = `${routeSelfServiceRoot}/wizard`
24

35
export function routeIsActive(activePath: string, pathName: string, rootPath?: string): boolean {
4-
return activePath?.startsWith(pathName)
5-
&& (pathName !== rootPath || activePath === rootPath)
6+
let isActive: boolean = isActivePath(activePath, pathName, rootPath)
7+
8+
// temporarilily, if the path we're testing against is the work tool
9+
// also check if the current path is self-service
10+
if (!isActive && pathName.startsWith(routeRoot)) {
11+
isActive = isActivePath(activePath, routeSelfServiceRoot)
12+
}
13+
14+
return isActive
615
}
716

817
export function routeIsHome(activePath: string): boolean {
918
// TODO: make the alternate home route configurable
10-
return [routeRoot, '/self-service'].some(route => activePath === route)
19+
return [routeRoot, routeSelfServiceRoot].some(route => activePath === route)
20+
}
21+
22+
export function routeWorkDetails(workId: string): string {
23+
return `${routeSelfServiceRoot}/work-items/${workId}`
24+
}
25+
26+
function isActivePath(activePath: string, pathName: string, rootPath?: string): boolean {
27+
return activePath?.startsWith(pathName)
28+
&& (pathName !== rootPath || activePath === rootPath)
1129
}

src-ts/tools/work/Work.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
ProfileContextData,
1616
routeContext,
1717
RouteContextData,
18+
routeSelfServiceRoot,
19+
routeSelfServiceStart,
1820
WorkProvider,
1921
} from '../../lib'
2022

@@ -36,15 +38,15 @@ const Work: FC<{}> = () => {
3638
}
3739

3840
// if the profile is initialized, go to the self-service login
39-
return <Navigate to='/self-service' />
41+
return <Navigate to={routeSelfServiceRoot} />
4042
}
4143

4244
function startWork(): void {
4345
clearCachedChallengeId()
4446
clearAutoSavedForm()
4547
dispatch(resetIntakeForm(true))
4648
// TODO: add the start work page to the route provider context
47-
navigate('/self-service/wizard')
49+
navigate(routeSelfServiceStart)
4850
}
4951

5052
const buttonConfig: ButtonProps = {

src-ts/tools/work/work-table/WorkTable.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { cacheChallengeId } from '../../../../src/autoSaveBeforeLogin' // TODO:
55
import {
66
LoadingSpinner,
77
routeRoot,
8+
routeSelfServiceStart,
9+
routeWorkDetails,
810
Table,
911
TableColumn,
1012
TabsNavbar,
@@ -68,7 +70,6 @@ const WorkTable: FC<{}> = () => {
6870
setColumns(filteredColumns)
6971
}, [
7072
initialized,
71-
work,
7273
workStatusFilter,
7374
])
7475

@@ -93,8 +94,8 @@ const WorkTable: FC<{}> = () => {
9394

9495
// TODO: get these routes from an object/function that's not hard-coded
9596
const url: string = isDraft
96-
? '/self-service/wizard'
97-
: `/self-service/work-items/${selectedWork.id}`
97+
? routeSelfServiceStart
98+
: routeWorkDetails(selectedWork.id)
9899

99100
navigate(url)
100101
}
@@ -162,8 +163,7 @@ function initializeStatusGroups(
162163
setTabs: Dispatch<SetStateAction<ReadonlyArray<TabsNavItem>>>
163164
): void {
164165

165-
// if we're not initialized or we already have status groups,
166-
// nothing else to do
166+
// if we're not initialized, nothing else to do
167167
if (!initialized) {
168168
return
169169
}

0 commit comments

Comments
 (0)