Skip to content

Commit

Permalink
fix(basename): basename for workspaces is calculated incorrectly (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
karelhala authored Nov 12, 2024
1 parent c1847b9 commit 113a38e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Routing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Suspense fallback={<AppPlaceholder />}>
<QuickstartsTestButtons />
<RouterRoutes>
{renderedRoutes}
{/* Catch all unmatched routes */}
<RouterRoute path="*" element={<Navigate to={mergeToBasename(pathnames.users.link)} />} />
<RouterRoute path="*" element={<Navigate to={mergeToBasename(pathnames.users.link, defaultBasename)} />} />
</RouterRoutes>
</Suspense>
);
Expand Down
15 changes: 10 additions & 5 deletions src/presentational-components/shared/AppLink.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -17,11 +18,15 @@ export const mergeToBasename = (to: To, basename = '/iam/user-access') => {
};
};

const AppLink: React.FC<AppLinkProps> = React.forwardRef((props: AppLinkProps, ref: LegacyRef<HTMLSpanElement>) => (
<span ref={ref}>
<Link {...props} to={mergeToBasename(props.to, props.linkBasename)} />
</span>
));
const AppLink: React.FC<AppLinkProps> = React.forwardRef((props: AppLinkProps, ref: LegacyRef<HTMLSpanElement>) => {
const { getBundle, getApp } = useChrome();
const defaultBasename = `/${getBundle()}/${getApp()}`;
return (
<span ref={ref}>
<Link {...props} to={mergeToBasename(props.to, props.linkBasename || defaultBasename)} />
</span>
);
});

AppLink.displayName = 'AppLink';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const useChrome = () => ({
isProd: () => true,
getEnvironment: () => undefined,
auth: { getUser: () => undefined },
getBundle: () => 'iam',
getApp: () => 'user-access',
});

module.exports = useChrome;
Expand Down

0 comments on commit 113a38e

Please sign in to comment.