Skip to content

TCA-838 Uni Nav Release - 2022-12-19 -> master #448

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 64 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 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
bc73636
TCA-787 complete a certification shortcut
kkartunov Dec 8, 2022
df67f69
TCA-790 Delay all calls to the survey so they don't close when the us…
brooketopcoder Dec 9, 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
a3be4d0
TCA-790 - use localstorage flag for showing survey
vas3a Dec 9, 2022
caf8e3b
add missing hook deps
vas3a Dec 9, 2022
af3fa18
Merge pull request #437 from topcoder-platform/PROD-3115_uni-nav
brooketopcoder Dec 10, 2022
970815c
Move name of survey in learn-config, move storage hook in learn-lib
vas3a Dec 12, 2022
88a91fb
TC layout: fix for layout height
vas3a Dec 12, 2022
bc91e20
Merge pull request #438 from topcoder-platform/TCA-790_assessments_flags
brooketopcoder Dec 13, 2022
81ba885
Merge pull request #436 from topcoder-platform/TCA-790_assessments
brooketopcoder Dec 13, 2022
b559109
Merge pull request #439 from topcoder-platform/TC-layout-height-fix
vas3a Dec 13, 2022
c1a10d5
PROD-3372 rename self service title
vas3a Dec 13, 2022
aa63b57
Merge pull request #441 from topcoder-platform/PROD-3372_rename-self-…
vas3a Dec 13, 2022
3cfefba
TCA-830 #comment Removes the loading spinner from the home page #time…
brooketopcoder Dec 13, 2022
a0ea303
Merge pull request #442 from topcoder-platform/TCA-830_double-loading
brooketopcoder Dec 13, 2022
97e142f
Code review fixes
kkartunov Dec 14, 2022
bc48e98
use string props
kkartunov Dec 14, 2022
932f0d3
Merge branch 'dev' into TCA-787
kkartunov Dec 14, 2022
812782a
Merge branch 'TCA-832_release' into dev
brooketopcoder Dec 14, 2022
9427358
Merge pull request #434 from topcoder-platform/TCA-787
brooketopcoder Dec 16, 2022
843acd7
TCA-834 - updates code for uni-nav integration, cleans up·css for pag…
vas3a Dec 19, 2022
04c3e47
Merge pull request #447 from topcoder-platform/TCA-834_fix-uninav-loa…
brooketopcoder Dec 19, 2022
df21e6d
TCA-790 Remove obsolete code
brooketopcoder Dec 19, 2022
0340eef
Merge pull request #449 from topcoder-platform/TCA-790_survey
brooketopcoder Dec 19, 2022
91b9af0
TCA-790 Remove more obsolete code
brooketopcoder Dec 19, 2022
38fb652
Merge pull request #450 from topcoder-platform/TCA-790_survey
brooketopcoder Dec 19, 2022
4c150d4
TCA-790 Remove Obsolete Code
brooketopcoder Dec 19, 2022
fe8e600
Merge pull request #451 from topcoder-platform/TCA-790_survey
brooketopcoder Dec 19, 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.

173 changes: 155 additions & 18 deletions src-ts/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,157 @@
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,
useMemo,
useRef,
useState,
} from 'react'
import { NavigateFunction, useNavigate } from 'react-router-dom'
import type { AuthUser as NavAuthUser, TcUniNavFn } from 'universal-navigation'
import classNames from 'classnames'

import { EnvironmentConfig, PageSubheaderPortalId } from '../config'
import {
authUrlLogin,
authUrlLogout,
authUrlSignup,
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()

// userinfo will be an empty object until profileReady=true
// userinfo will be {user: undefined} if user is logged out
// userinfo will have all user's details when user is logged in
const userInfo: {} | undefined | NavAuthUser = useMemo(() => (
!profileReady ? {} : ({
user: profile ? {
email: profile.email,
firstName: profile.firstName,
handle: profile.handle,
lastName: profile.lastName,
photoUrl: profile.photoURL,
userId: profile.userId,
} : undefined,
})
), [profile, profileReady])

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,
])

// initialize uni-nav elements
useEffect(() => {

if (headerInit.current) {
return
}

headerInit.current = true

tcUniNav(
'init',
navElementId,
{
handleNavigation: navigationHandler,
onReady() { setReady(true) },
signIn() { window.location.href = authUrlLogin() },
signOut() { window.location.href = authUrlLogout },
signUp() { window.location.href = authUrlSignup() },
toolName: activeToolName,
toolRoot: activeToolRoute,
type: 'tool',
...userInfo,
},
)
}, [
activeToolName,
activeToolRoute,
navigationHandler,
userInfo,
profileReady,
])

// update uni-nav's tool details
useEffect(() => {

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

// update uni-nav's user/auth details
useEffect(() => {

if (!profileReady) {
return
}

tcUniNav(
'update',
navElementId,
{
...userInfo,
},
)
}, [
profileReady,
userInfo,
])

return (
<>
<div id={navElementId} />
<div
id={PageSubheaderPortalId}
className={classNames('full-width-relative', !ready && 'hidden')}
/>
</>
)
}

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.

Loading