From 113a38e4d3475e79252a0e931c203056d6e77359 Mon Sep 17 00:00:00 2001 From: Karel Hala Date: Tue, 12 Nov 2024 14:57:35 +0100 Subject: [PATCH] fix(basename): basename for workspaces is calculated incorrectly (#1699) --- src/Routing.tsx | 5 ++++- src/presentational-components/shared/AppLink.tsx | 15 ++++++++++----- .../frontend-components/useChrome/index.js | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Routing.tsx b/src/Routing.tsx index 9ceadb129..7fa536c84 100644 --- a/src/Routing.tsx +++ b/src/Routing.tsx @@ -284,13 +284,16 @@ const Routing = () => { const routes = getRoutes({ enableServiceAccounts, isITLess, isWorkspacesFlag }); const renderedRoutes = useMemo(() => renderRoutes(routes as never), [routes]); + + const { getBundle, getApp } = useChrome(); + const defaultBasename = `/${getBundle()}/${getApp()}`; return ( }> {renderedRoutes} {/* Catch all unmatched routes */} - } /> + } /> ); diff --git a/src/presentational-components/shared/AppLink.tsx b/src/presentational-components/shared/AppLink.tsx index 2f54cec78..f335667da 100644 --- a/src/presentational-components/shared/AppLink.tsx +++ b/src/presentational-components/shared/AppLink.tsx @@ -1,3 +1,4 @@ +import useChrome from '@redhat-cloud-services/frontend-components/useChrome'; import React, { LegacyRef } from 'react'; import { Link, LinkProps, To } from 'react-router-dom'; @@ -17,11 +18,15 @@ export const mergeToBasename = (to: To, basename = '/iam/user-access') => { }; }; -const AppLink: React.FC = React.forwardRef((props: AppLinkProps, ref: LegacyRef) => ( - - - -)); +const AppLink: React.FC = React.forwardRef((props: AppLinkProps, ref: LegacyRef) => { + const { getBundle, getApp } = useChrome(); + const defaultBasename = `/${getBundle()}/${getApp()}`; + return ( + + + + ); +}); AppLink.displayName = 'AppLink'; diff --git a/src/test/__mocks__/@redhat-cloud-services/frontend-components/useChrome/index.js b/src/test/__mocks__/@redhat-cloud-services/frontend-components/useChrome/index.js index 669441c3c..2d1a42495 100644 --- a/src/test/__mocks__/@redhat-cloud-services/frontend-components/useChrome/index.js +++ b/src/test/__mocks__/@redhat-cloud-services/frontend-components/useChrome/index.js @@ -5,6 +5,8 @@ const useChrome = () => ({ isProd: () => true, getEnvironment: () => undefined, auth: { getUser: () => undefined }, + getBundle: () => 'iam', + getApp: () => 'user-access', }); module.exports = useChrome;