From de8422968b97f2609f80a0a3c4a92ab0e4fcf558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Dombya?= <135591453+hervedombya@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:41:07 +0200 Subject: [PATCH] ARTESCA-13612 // Add listener to custom event in NavbarUC --- .../src/navbar/NavbarUpdaterComponents.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/shell-ui/src/navbar/NavbarUpdaterComponents.tsx b/shell-ui/src/navbar/NavbarUpdaterComponents.tsx index f77279b816..5340fab960 100644 --- a/shell-ui/src/navbar/NavbarUpdaterComponents.tsx +++ b/shell-ui/src/navbar/NavbarUpdaterComponents.tsx @@ -1,6 +1,6 @@ import { SolutionUI } from '@scality/module-federation'; import { FederatedComponent } from '@scality/module-federation'; -import { Fragment } from 'react'; +import { Fragment, useEffect } from 'react'; import { ErrorBoundary } from 'react-error-boundary'; import { useAuth } from '../auth/AuthProvider'; import { useFirstTimeLogin } from '../auth/FirstTimeLoginProvider'; @@ -9,6 +9,7 @@ import { useConfigRetriever } from '../initFederation/ConfigurationProviders'; import { useDeployedApps } from '../initFederation/UIListProvider'; import { useNotificationCenter } from '../useNotificationCenter'; import { useNavbar } from './navbarHooks'; +import { useShellHistory } from '../initFederation/ShellHistoryProvider'; export const NavbarUpdaterComponents = () => { const deployedApps = useDeployedApps(); @@ -36,6 +37,23 @@ export const NavbarUpdaterComponents = () => { .filter((appBuildConfig) => !!appBuildConfig); const { firstTimeLogin } = useFirstTimeLogin(); const { userData } = useAuth(); + const history = useShellHistory(); + + useEffect(() => { + const handleDownloadUploadEvent = (event: CustomEvent) => { + history.push(event.detail); + }; + + window.addEventListener('downloadUploadEvent', handleDownloadUploadEvent); + + return () => { + window.removeEventListener( + 'downloadUploadEvent', + handleDownloadUploadEvent, + ); + }; + }, []); + return ( <> {componentsToFederate.map((component, index) => {