From 91cbdd48c8c8ac99b7c1c4cbfd62b97bf21bfd95 Mon Sep 17 00:00:00 2001 From: Alec M Date: Tue, 21 Nov 2023 12:49:16 -0500 Subject: [PATCH 1/3] CRDCDH-621 Restore current URL on login --- .../Header/HeaderTabletAndMobile.tsx | 33 ++++++++++++------- .../Header/components/NavbarDesktop.tsx | 20 ++++++++--- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/components/Header/HeaderTabletAndMobile.tsx b/src/components/Header/HeaderTabletAndMobile.tsx index 3b391a45..fb5102a0 100644 --- a/src/components/Header/HeaderTabletAndMobile.tsx +++ b/src/components/Header/HeaderTabletAndMobile.tsx @@ -1,5 +1,5 @@ -import React, { useState } from 'react'; -import { NavLink, Link, useNavigate } from 'react-router-dom'; +import React, { useEffect, useState } from 'react'; +import { NavLink, Link, useNavigate, useLocation } from 'react-router-dom'; import styled from 'styled-components'; import Logo from "./components/LogoMobile"; import menuClearIcon from '../../assets/header/Menu_Cancel_Icon.svg'; @@ -148,7 +148,7 @@ const MenuArea = styled.div` .clickable { cursor: pointer; } - + .action { cursor: pointer; } @@ -169,10 +169,12 @@ const Header = () => { const navbarMobileList: NavbarMobileList = navMobileListHookResult[0]; const setNavbarMobileList = navMobileListHookResult[1]; const [showLogoutAlert, setShowLogoutAlert] = useState(false); + const [restorePath, setRestorePath] = useState(null); const authData = useAuthContext(); const displayName = authData?.user?.firstName || "N/A"; const navigate = useNavigate(); + const location = useLocation(); const handleLogout = async () => { const logoutStatus = await authData.logout(); @@ -228,6 +230,15 @@ const Header = () => { setNavbarMobileList(navbarSublists[clickTitle]); }; + useEffect(() => { + if (!location?.pathname || location?.pathname === "/") { + setRestorePath(null); + return; + } + + setRestorePath(location?.pathname); + }, [location]); + return ( <> @@ -393,15 +404,13 @@ const Header = () => { > {displayName} - ) - : ( - -
{ if (e.key === "Enter") { setNavMobileDisplay('none'); } }} onClick={() => setNavMobileDisplay('none')}> - Login -
- - - )) : null} + ) : ( + +
{ if (e.key === "Enter") { setNavMobileDisplay('none'); } }} onClick={() => setNavMobileDisplay('none')}> + Login +
+ + )) : null}
{ const clickableTitle = clickableObject.map((item) => item.name); const navigate = useNavigate(); const authData = useAuthContext(); + const location = useLocation(); const displayName = authData?.user?.firstName?.toUpperCase() || "N/A"; const [showLogoutAlert, setShowLogoutAlert] = useState(false); + const [restorePath, setRestorePath] = useState(null); + clickableTitle.push(displayName); useOutsideAlerter(dropdownSelection, nameDropdownSelection); @@ -430,6 +433,16 @@ const NavBar = () => { useEffect(() => { setClickedTitle(""); }, []); + + useEffect(() => { + if (!location?.pathname || location?.pathname === "/") { + setRestorePath(null); + return; + } + + setRestorePath(location?.pathname); + }, [location]); + return (
- ) - : ( - + ) : ( + Login )} From c8a5d6e0252158ba29bf4f2df6c6ccc4494a3ba7 Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Wed, 22 Nov 2023 14:39:00 -0500 Subject: [PATCH 2/3] change mobile header to item so it's a link --- src/config/globalHeaderData.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/globalHeaderData.tsx b/src/config/globalHeaderData.tsx index edf15c40..0b66f21d 100644 --- a/src/config/globalHeaderData.tsx +++ b/src/config/globalHeaderData.tsx @@ -55,6 +55,6 @@ export const navbarSublists = { name: `${dc.name} Model`, link: `/model-navigator/${dc.name}`, text: '', - className: 'navMobileSubTitle', + className: 'navMobileSubItem', })), }; From d98b43b019bcd61d8ac2f0cd577626bf59ba5351 Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Wed, 22 Nov 2023 14:40:24 -0500 Subject: [PATCH 3/3] add documentation in comment --- src/config/globalHeaderData.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/config/globalHeaderData.tsx b/src/config/globalHeaderData.tsx index 0b66f21d..97e13f59 100644 --- a/src/config/globalHeaderData.tsx +++ b/src/config/globalHeaderData.tsx @@ -51,6 +51,8 @@ export const navbarSublists = { // className: 'navMobileSubTitle', // }, // ], + // + // To make it a link, the className has to be navMobileSubItem "Model Navigator": DataCommons.map((dc) => ({ name: `${dc.name} Model`, link: `/model-navigator/${dc.name}`,