Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ToolSelectorNarrow: FC<ToolSelectorNarrowProps> = (props: ToolSelectorNarr
const toolPath: string = getPathFromRoute(toolRoute)

const baseClass: string = 'tool-selector-narrow'
const isActive: boolean = isActiveRoute(useLocation().pathname, toolPath)
const isActive: boolean = isActiveRoute(useLocation().pathname, toolRoute)
const activeIndicaterClass: string = `${baseClass}-${isActive ? '' : 'in'}active`
const hasChildren: boolean = !!toolRoute.children.some(child => !!child.route && !isParamRoute(child.route))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ToolSelectorWide: FC<ToolSelectorWideProps> = (props: ToolSelectorWideProp
const toolRoute: PlatformRoute = props.route
const toolPath: string = getPathFromRoute(toolRoute)

const isActive: boolean = isActiveRoute(activePath, toolPath)
const isActive: boolean = isActiveRoute(activePath, toolRoute)

const activeIndicatorClass: string = `tool-selector-wide-${isActive ? '' : 'in'}active`

Expand Down
1 change: 1 addition & 0 deletions src-ts/lib/route-provider/platform-route.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC, SVGProps } from 'react'

export interface PlatformRoute {
alternativePaths?: Array<string>
children?: Array<PlatformRoute>
disabled?: boolean
element: JSX.Element
Expand Down
2 changes: 1 addition & 1 deletion src-ts/lib/route-provider/route-context-data.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface RouteContextData {
getPath: (routeTitle: string) => string
getPathFromRoute: (route: PlatformRoute) => string
getRouteElement: (route: PlatformRoute) => JSX.Element
isActiveRoute: (activePath: string, pathName: string, rootPath?: string) => boolean
isActiveRoute: (activePath: string, toolRoute: PlatformRoute) => boolean
isRootRoute: (activePath: string) => boolean
rootLoggedInRoute: string
rootLoggedOutRoute: string
Expand Down
27 changes: 6 additions & 21 deletions src-ts/lib/route-provider/route.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
getPath,
getPathFromRoute,
getRouteElement,
isActiveRoute: isActiveRoute(props.rootLoggedIn, props.rootLoggedOut),
isActiveRoute,
isRootRoute: isRootRoute(props.rootLoggedIn, props.rootLoggedOut),
rootLoggedInRoute: props.rootLoggedIn,
rootLoggedOutRoute: props.rootLoggedOut,
Expand Down Expand Up @@ -111,26 +111,11 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
)
}

function isActivePath(activePath: string, pathName: string, rootPath?: string): boolean {
return activePath?.startsWith(pathName)
&& (pathName !== rootPath || activePath === rootPath)
}

function isActiveRoute(rootLoggedIn: string, rootLoggedOut: string):
(activePath: string, pathName: string, rootPath?: string) => boolean {

return (activePath: string, pathName: string, rootPath?: string) => {

let isActive: boolean = isActivePath(activePath, pathName, rootPath)

// if this is the root logged in route,
// also check the root logged out route
if (!isActive && pathName.startsWith(rootLoggedIn)) {
isActive = isActivePath(activePath, rootLoggedOut)
}

return isActive
}
function isActiveRoute(activePath: string, toolRoute: PlatformRoute): boolean {
return !!(
activePath?.startsWith(toolRoute.route)
|| toolRoute.alternativePaths?.some(path => activePath?.startsWith(path))
)
}

function isRootRoute(rootLoggedIn: string, rootLoggedOut: string):
Expand Down
1 change: 1 addition & 0 deletions src-ts/tools/work/work.routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const workRoutes: Array<PlatformRoute> = [
title: 'Logged Out Landing',
},
{
alternativePaths: [selfServiceRootRoute],
children: [
{
element: <WorkTable />,
Expand Down