Skip to content

Commit 1e67deb

Browse files
authored
Core 1264 port default layout part 1 (#2783)
* CORE-1264: Port default layouts, part 1 [CORE-1264] * Remove welcome * Quiet more tests * Cover the piTracker call * Coverage of default/shared * Handle missing/disabled localStorage
1 parent 5155545 commit 1e67deb

32 files changed

+474
-298
lines changed

src/app/layouts/default/default.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import useMainClassContext, {
99
} from '~/contexts/main-class';
1010
import useLanguageContext from '~/contexts/language';
1111
import ReactModal from 'react-modal';
12-
import Welcome from './welcome/welcome';
1312
import TakeoverDialog from './takeover-dialog/takeover-dialog';
1413
import cn from 'classnames';
1514
import './default.scss';
@@ -53,7 +52,6 @@ function Main({children}: React.PropsWithChildren<object>) {
5352
ref={ref}
5453
tabIndex={-1}
5554
>
56-
<Welcome />
5755
<TakeoverDialog />
5856
{children}
5957
</div>

src/app/layouts/default/footer/copyright.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ type Props = {
77
}
88

99
export default function Copyright({copyright, apStatement}: Props) {
10-
const updatedCopyright = copyright
11-
? copyright.replace(/-\d+/, `-${new Date().getFullYear()}`)
12-
: copyright;
10+
const updatedCopyright = copyright?.replace(/-\d+/, `-${new Date().getFullYear()}`);
1311

1412
return (
1513
<React.Fragment>

src/app/layouts/default/header/header.js renamed to src/app/layouts/default/header/header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import JITLoad from '~/helpers/jit-load';
2+
import StickyNote from './sticky-note/sticky-note';
33
import {useStickyData} from '../shared';
44
import Menus from './menus/menus';
55
import './header.scss';
@@ -9,7 +9,7 @@ export default function Header() {
99

1010
return (
1111
<div className="page-header">
12-
<JITLoad importFn={() => import('./sticky-note/sticky-note.js')} stickyData={stickyData} />
12+
<StickyNote stickyData={stickyData} />
1313
<Menus />
1414
</div>
1515
);

src/app/layouts/default/header/menus/dropdown-context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {useState} from 'react';
33

44
function useContextValue({prefix} = {prefix: 'menulabel'}) {
55
const [activeDropdown, setActiveDropdown] = useState<
6-
React.MutableRefObject<HTMLAnchorElement> | Record<string, never>
6+
React.MutableRefObject<HTMLAnchorElement | null> | Record<string, never>
77
>({});
88
const [submenuLabel, setSubmenuLabel] = useState<string>();
99

src/app/layouts/default/header/menus/menu-expander/menu-expander.js renamed to src/app/layouts/default/header/menus/menu-expander/menu-expander.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,43 @@ import {useLocation} from 'react-router-dom';
44
import {treatSpaceOrEnterAsClick} from '~/helpers/events';
55
import './menu-expander.scss';
66

7-
function useCloseOnLocationChange(onClick, active) {
7+
function useCloseOnLocationChange(toggleActive: (v?: boolean) => void, active: boolean) {
88
const location = useLocation();
99
const {setActiveDropdown} = useDropdownContext();
10-
const activeRef = React.useRef();
10+
const activeRef = React.useRef<boolean>();
1111

1212
activeRef.current = active;
1313

1414
React.useEffect(() => {
1515
if (activeRef.current) {
16-
onClick({});
16+
toggleActive(false);
1717
setActiveDropdown({});
1818
}
19-
}, [location, onClick, setActiveDropdown]);
19+
}, [location, toggleActive, setActiveDropdown]);
2020
}
2121

22-
export default function MenuExpander({active, onClick, ...props}) {
22+
type MenuExpanderProps = {
23+
active: boolean;
24+
toggleActive: (v?: boolean) => void;
25+
} & React.ButtonHTMLAttributes<HTMLButtonElement>;
26+
27+
export default function MenuExpander({active, toggleActive, ...props}: MenuExpanderProps) {
2328
const onClickAndBlur = React.useCallback(
24-
(event) => {
25-
onClick(event);
29+
(event: React.MouseEvent<HTMLButtonElement>) => {
30+
toggleActive();
2631
event.currentTarget.blur();
2732
},
28-
[onClick]
33+
[toggleActive]
2934
);
3035

31-
useCloseOnLocationChange(onClick, active);
36+
useCloseOnLocationChange(toggleActive, active);
3237

3338
return (
3439
<button
3540
type="button"
3641
className="expand"
3742
aria-haspopup="true" aria-label="Toggle Meta Navigation Menu"
38-
tabIndex="0"
43+
tabIndex={0}
3944
onClick={onClickAndBlur}
4045
onKeyDown={treatSpaceOrEnterAsClick}
4146
{...props}

src/app/layouts/default/header/menus/menus.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@ import { treatSpaceOrEnterAsClick } from '~/helpers/events';
1212

1313
export default function Menus() {
1414
const ref = React.useRef<HTMLDivElement>(null);
15-
const [active, toggle] = useToggle();
16-
const expandMenu = React.useCallback(() => toggle(), [toggle]);
15+
const [active, toggleActive] = useToggle();
1716
const clickOverlay = React.useCallback(
1817
(event: React.MouseEvent) => {
1918
if (event.currentTarget === event.target) {
20-
expandMenu();
19+
toggleActive(false);
2120
}
2221
},
23-
[expandMenu]
22+
[toggleActive]
2423
);
2524
const closeOnEsc = React.useCallback(
2625
(event: React.KeyboardEvent) => {
27-
if (active && event.key === 'Escape') {
28-
expandMenu();
26+
if (event.key === 'Escape') {
27+
toggleActive(false);
2928
}
3029
},
31-
[active, expandMenu]
30+
[toggleActive]
3231
);
3332

3433
React.useEffect(() => {
@@ -66,7 +65,7 @@ export default function Menus() {
6665
<Logo />
6766
<MenuExpander
6867
active={active}
69-
onClick={expandMenu}
68+
toggleActive={toggleActive}
7069
aria-controls='menu-popover'
7170
aria-expanded={active}
7271
/>

src/app/layouts/default/header/sticky-note/sticky-note.js renamed to src/app/layouts/default/header/sticky-note/sticky-note.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ import RawHTML from '~/components/jsx-helpers/raw-html';
33
import {usePutAway} from '../../shared';
44
import './sticky-note.scss';
55

6-
export default function StickyNote({stickyData}) {
6+
export type StickyNoteProps = {
7+
stickyData: {
8+
mode: 'emergency';
9+
emergency_content: string;
10+
} | object | null;
11+
};
12+
13+
export default function StickyNote({stickyData}: StickyNoteProps) {
714
const [closed, PutAway] = usePutAway();
815

9-
if (!stickyData || closed || stickyData.mode !== 'emergency') {
16+
if (!stickyData || closed || !('emergency_content' in stickyData)) {
1017
return null;
1118
}
1219

src/app/layouts/default/lower-sticky-note/lsn-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import cn from 'classnames';
77
import './lower-sticky-note.scss';
88

99
type BannerInfo = {
10-
html_message: string;
10+
html_message?: string;
1111
link_url: string;
1212
link_text: string;
1313
banner_thumbnail?: string;

0 commit comments

Comments
 (0)