Skip to content

PROD-3115 Integrate Universal Nav -> dev #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0fd1610
PROD-3232 #comment This commit adds the uni nav snippet and does a li…
brooketopcoder Nov 18, 2022
d3cfb58
PROD-3232 #comment This commit removes the obsolete header code #time…
brooketopcoder Nov 18, 2022
a16cacd
Merge branch 'dev' into PROD-3115_uni-nav
brooketopcoder Nov 18, 2022
edcc130
Merge branch 'PROD-3115_uni-nav' into PROD-3232_integrate-nav
brooketopcoder Nov 18, 2022
d5b83fa
PROD-3233 #comment This commit sets the tool name based on the curren…
brooketopcoder Nov 18, 2022
8cba9e3
PROD-3232 #comment This commit moves the call to initalize the uni na…
brooketopcoder Nov 21, 2022
1f6f094
Merge pull request #421 from topcoder-platform/PROD-3232_integrate-nav
brooketopcoder Nov 21, 2022
ef495ae
Merge pull request #422 from topcoder-platform/PROD-3233_dynamic-tool
brooketopcoder Nov 21, 2022
1ddbfd3
PROD-3234 #comment This commit cleans up some obsolete code. It adds …
brooketopcoder Nov 21, 2022
6da0e30
PROD-3246 #comment This commit updates the profile and tool info afte…
brooketopcoder Nov 21, 2022
ae88227
Merge pull request #423 from topcoder-platform/PROD-3234_dev-center
brooketopcoder Nov 21, 2022
20600a2
Merge branch 'PROD-3246_update-user' into PROD-3245_work
brooketopcoder Nov 21, 2022
f6cdd2c
PROD-3245 #comment This commit adds the universal footer and removes …
brooketopcoder Nov 21, 2022
2450490
Merge pull request #424 from topcoder-platform/PROD-3246_update-user
brooketopcoder Nov 22, 2022
0d5c360
PROD-3115 #comment This commit attempts to implement the navigation h…
brooketopcoder Nov 22, 2022
16d90cf
PROD-3115 #comment This commit waits to initialize the nav when the p…
brooketopcoder Nov 22, 2022
c58ab13
PROD-3115 #comment This commit fixes invalid configuration. #time 30m
brooketopcoder Nov 22, 2022
4203971
Merge branch 'PROD-3115_handle-navigation' into PROD-3245_work
brooketopcoder Nov 22, 2022
757803d
PROD-3115 fix for nav changing #time 15m
brooketopcoder Nov 22, 2022
c3d60e2
Merge branch 'PROD-3115_handle-navigation' into PROD-3245_work
brooketopcoder Nov 22, 2022
6425c9f
PROD-3245 #comment This commit removes the customer- and member-speci…
brooketopcoder Nov 23, 2022
5a88174
Merge pull request #425 from topcoder-platform/PROD-3115_handle-navig…
brooketopcoder Nov 23, 2022
d092cec
clean-up
brooketopcoder Nov 23, 2022
b158852
Merge pull request #427 from topcoder-platform/PROD-3245_work
brooketopcoder Nov 23, 2022
784667b
PROD-3245 #comment This commit adds a header-specific readme and upda…
brooketopcoder Nov 23, 2022
78a110f
PROD-3245 - add universal-navigation as npm dependency, fix typings i…
vas3a Nov 25, 2022
3344896
update universal-navigation
vas3a Nov 25, 2022
2dae369
PROD-3257 #comment This commit changes the path to the uni nav script…
brooketopcoder Nov 28, 2022
4b503f6
Merge pull request #428 from topcoder-platform/PROD-3257_readme
brooketopcoder Nov 28, 2022
9b89ea5
PROD-3245 clean up
brooketopcoder Nov 28, 2022
3e22ba6
PROD-3245 #comment This commit updates the uni nav types and the asso…
brooketopcoder Nov 28, 2022
1ad8688
PROD-3245 clean up
brooketopcoder Nov 28, 2022
8e0abfd
Merge pull request #429 from topcoder-platform/PROD-3245_uni-nav-types
brooketopcoder Nov 28, 2022
be1dd6b
PROD-3115 #comment This commit updates the version of the uni nav typ…
brooketopcoder Nov 29, 2022
a471b12
Merge branch 'dev' into PROD-3115_uni-nav
brooketopcoder Dec 7, 2022
2b2ded6
Merge branch 'dev' into PROD-3115_uni-nav
brooketopcoder Dec 9, 2022
c46c1a0
PROD-3115 #comment This commit updates the uni nav user and fixes bug…
brooketopcoder Dec 9, 2022
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"swr": "^1.3.0",
"tc-auth-lib": "topcoder-platform/tc-auth-lib#1.0.26",
"typescript": "^4.8.4",
"universal-navigation": "https://github.com/topcoder-platform/universal-navigation",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src-ts/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module.exports = {
11
],
'import/extensions': 'off',
'import/no-named-default': 'off',
'import/prefer-default-export': 'off',
'indent': [
2,
Expand Down Expand Up @@ -105,6 +106,7 @@ module.exports = {
120,
],
'no-extra-boolean-cast': 'off',
'no-nested-ternary': 'off',
'no-null/no-null': 'error',
'no-param-reassign': [
'error',
Expand Down
13 changes: 1 addition & 12 deletions src-ts/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, FC, ReactElement, SetStateAction, useContext, useEffect, useState } from 'react'
import { FC, ReactElement, useContext } from 'react'
import { Routes } from 'react-router-dom'
import { toast, ToastContainer } from 'react-toastify'

Expand All @@ -7,22 +7,11 @@ import { routeContext, RouteContextData } from './lib'

const App: FC<{}> = () => {

const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
const { allRoutes, getRouteElement }: RouteContextData = useContext(routeContext)

const routeElements: Array<ReactElement> = allRoutes
.map(route => getRouteElement(route))

useEffect(() => {
setReady(true)
}, [])

useEffect(() => {
if (ready) {
document.getElementById('root')?.classList.add('app-ready')
}
}, [ready])

return (
<>
<Header />
Expand Down
9 changes: 7 additions & 2 deletions src-ts/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export enum ToolTitle {
learn = 'Learn',
dev = 'Dev Center',
game = 'Gamification Admin',
settings = 'Account Settings',
work = 'Work',
support = 'Support',
tca = 'Topcoder Academy',
work = 'Self-Service Challenges',
}

export const PageSubheaderPortalId: string = 'page-subheader-portal-el'
7 changes: 5 additions & 2 deletions src-ts/config/environments/environment.default.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const EnvironmentConfigDefault: EnvironmentConfigModel = {
V3: 'https://api.topcoder-dev.com/v3',
V5: 'https://api.topcoder-dev.com/v5',
},
AUTH: {
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder-dev.com',
},
ENV: 'default',
LOGGING: {
PUBLIC_TOKEN: 'puba0825671e469d16f940c5a30dc738f11',
Expand Down Expand Up @@ -41,7 +44,7 @@ export const EnvironmentConfigDefault: EnvironmentConfigModel = {
USER_PROFILE: `${COMMUNITY_WEBSITE}/members`,
WP_CONTENT: `${COMMUNITY_WEBSITE}/wp-content`,
},
URL: {
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder-dev.com',
UNIVERSAL_NAV: {
URL: 'https://uni-nav.topcoder-dev.com/v1/tc-universal-nav.js',
},
}
7 changes: 5 additions & 2 deletions src-ts/config/environments/environment.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const EnvironmentConfigProd: EnvironmentConfigModel = {
V3: 'https://api.topcoder.com/v3',
V5: 'https://api.topcoder.com/v5',
},
AUTH: {
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder.com',
},
DISABLED_TOOLS: [],
ENV: 'prod',
SPRIG: {
Expand All @@ -39,7 +42,7 @@ export const EnvironmentConfigProd: EnvironmentConfigModel = {
USER_PROFILE: `${COMMUNITY_WEBSITE}/members`,
WP_CONTENT: `${COMMUNITY_WEBSITE}/wp-content`,
},
URL: {
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder.com',
UNIVERSAL_NAV: {
URL: 'https://uni-nav.topcoder.com/v1/tc-universal-nav.js',
},
}
31 changes: 0 additions & 31 deletions src-ts/header/Header.module.scss

This file was deleted.

152 changes: 134 additions & 18 deletions src-ts/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,136 @@
import { FC } from 'react'

import { Logo } from './logo'
import { ToolSelectors } from './tool-selectors'
import { UtilitySelectors } from './utility-selectors'
import styles from './Header.module.scss'

const Header: FC<{}> = () => (
<div className={styles['header-wrap']}>
<header className={styles.header}>
<ToolSelectors isWide={false} />
<Logo />
<ToolSelectors isWide />
<UtilitySelectors />
</header>
<div id='page-subheader-portal-el' className={styles.subheader} />
</div>
)
import {
Dispatch,
FC,
MutableRefObject,
SetStateAction,
useCallback,
useContext,
useEffect,
useRef,
useState,
} from 'react'
import { NavigateFunction, useNavigate } from 'react-router-dom'
import { type TcUniNavFn } from 'universal-navigation'
import classNames from 'classnames'

import { EnvironmentConfig, PageSubheaderPortalId } from '../config'
import {
authUrlLogin,
authUrlLogout,
authUrlSignup,
LoadingSpinner,
profileContext,
ProfileContextData,
routeContext,
RouteContextData,
} from '../lib'

import UniNavSnippet from './universal-nav-snippet'

declare let tcUniNav: TcUniNavFn
UniNavSnippet(EnvironmentConfig.UNIVERSAL_NAV.URL)

interface NavigationRequest {
label: string
path: string
}

const Header: FC = () => {

const { activeToolName, activeToolRoute }: RouteContextData = useContext(routeContext)
const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext)
const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
const headerInit: MutableRefObject<boolean> = useRef(false)
const navElementId: string = 'main-nav-el'
const navigate: NavigateFunction = useNavigate()

const navigationHandler: (request: NavigationRequest) => void
= useCallback((request: NavigationRequest) => {

try {
// strip the domain and navigate to the path
navigate(new URL(request.path).pathname)
} catch (error) {
// if we couldn't navigate to the path, just go to the route of the currently active tool
navigate(new URL(activeToolRoute || '/').pathname)
}

}, [
activeToolRoute,
navigate,
])

useEffect(() => {

if (headerInit.current || !profileReady) {
return
}

headerInit.current = true

tcUniNav(
'init',
navElementId,
{
handleNavigation: navigationHandler,
onReady() {
setReady(true)
document.getElementById('root')?.classList.add('app-ready')
},
signIn() { window.location.href = authUrlLogin() },
signOut() { window.location.href = authUrlLogout },
signUp() { window.location.href = authUrlSignup() },
toolName: activeToolName,
toolRoot: activeToolRoute,
type: 'tool',
user: profile ? {
email: profile.email,
firstName: profile.firstName,
handle: profile.handle,
lastName: profile.lastName,
photoUrl: profile.photoURL,
userId: profile.userId,
} : undefined,
},
)
}, [
activeToolName,
activeToolRoute,
navigationHandler,
profile,
profileReady,
])

useEffect(() => {

if (!profileReady) {
return
}

tcUniNav(
'update',
navElementId,
{
toolName: activeToolName,
toolRoot: activeToolRoute,
},
)
}, [
activeToolName,
activeToolRoute,
profileReady,
])

return (
<>
<LoadingSpinner hide={ready} />
<div id={navElementId} />
<div
id={PageSubheaderPortalId}
className={classNames('full-width-relative')}
/>
</>
)
}

export default Header
28 changes: 28 additions & 0 deletions src-ts/header/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Topcoder Universal Navigation

The Platform UI project uses the Topcoder Universal navigation ([README](https://github.com/topcoder-platform/universal-navigation)).

## Uni-nav Versions

The Uni-nav is a hosted JS library. There are currently dev and prod versions of the library located at:

https://uni-nav.topcoder.com/v1/tc-universal-nav.js

https://uni-nav.topcoder-dev.com/v1/tc-universal-nav.js

The URL is set at build time with the [Global Config](../lib/global-config.model.ts) `UNIVERSAL_NAV.URL` property.

>See the [Local Environment Setup](../../README.md#local-environment-setup) section of the main README for instructions on how to set your environment configuration.

>See the [Uni-Nav Version README](https://github.com/topcoder-platform/universal-navigation#versioning) for more information about versioning.

## Uni-nav Initialization

The Header uses the `tcUniNav` method to initialize the nav with:

- active tool name
- active tool root route
- current user, if logged in
- action handler callbacks (e.g. navigation, log in, log out, sign up)

Because the Platform UI hosts multiple tools, each time the user navigates to a new tool, the Header updates the uni-nav w/the active tool info.
33 changes: 0 additions & 33 deletions src-ts/header/logo/Logo.module.scss

This file was deleted.

33 changes: 0 additions & 33 deletions src-ts/header/logo/Logo.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src-ts/header/logo/index.ts

This file was deleted.

Loading