Skip to content

Commit

Permalink
Merge pull request #40 from entando/ENG-4088
Browse files Browse the repository at this point in the history
ENG-4088 Use session storage instead of query params for menu_open data
  • Loading branch information
Dv92 authored Sep 13, 2022
2 parents 365d486 + c0802af commit 39828fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 15 additions & 4 deletions microfrontends/app-builder-menu/src/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { MfeConfig } from '../types/globals';
import { GlobalStyle } from '../styles/globalStyles';
import { DEFAULT_LOCALE } from '../content';
import { getPBCNav } from '../api/getPBCNav';
import { useQueryParams } from '../hooks/common';

interface Props {
config: MfeConfig;
Expand All @@ -37,8 +36,7 @@ export function Menu(props: Props) {

const [dynamicMenuItems, setDynamicMenuItems] = useState<MenuItem[]>([]);

const queryParams = useQueryParams();
const { menu_open } = queryParams || {};
const menuOpen = sessionStorage.getItem('menu_open') || '';

const { lang } = window.entando?.globals || {};
const locale = lang || DEFAULT_LOCALE;
Expand All @@ -54,6 +52,19 @@ export function Menu(props: Props) {
if (config) {
request();
}

const removeMenuOpenSession = () => {
sessionStorage.removeItem('menu_open');
};

if (menuOpen) {
window.addEventListener('beforeunload', removeMenuOpenSession);

return () => {
removeMenuOpenSession();
window.removeEventListener('beforeunload', removeMenuOpenSession);
};
}
}, []);

return (
Expand All @@ -71,7 +82,7 @@ export function Menu(props: Props) {
<MenuUI
config={config}
dynamicMenuItems={dynamicMenuItems}
openDefaultSubmenuId={menu_open}
openDefaultSubmenuId={menuOpen}
/>
</>
)}
Expand Down
5 changes: 0 additions & 5 deletions microfrontends/app-builder-menu/src/hooks/common.ts

This file was deleted.

0 comments on commit 39828fa

Please sign in to comment.