fix(superset-frontend): Fixes for broken functionality when an application root is defined (#36058)

This commit is contained in:
Martyn Gigg
2026-01-23 22:13:48 +00:00
committed by GitHub
parent d54e227e25
commit e4f649e49c
9 changed files with 128 additions and 69 deletions

View File

@@ -22,6 +22,7 @@ import { render, screen, userEvent } from 'spec/helpers/testing-library';
import setupCodeOverrides from 'src/setup/setupCodeOverrides';
import { getExtensionsRegistry } from '@superset-ui/core';
import { Menu } from './Menu';
import * as getBootstrapData from 'src/utils/getBootstrapData';
const dropdownItems = [
{
@@ -238,6 +239,10 @@ const notanonProps = {
};
const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');
const staticAssetsPrefixMock = jest.spyOn(
getBootstrapData,
'staticAssetsPrefix',
);
fetchMock.get(
'glob:*api/v1/database/?q=(filters:!((col:allow_file_upload,opr:upload_is_enabled,value:!t)))',
@@ -247,6 +252,8 @@ fetchMock.get(
beforeEach(() => {
// setup a DOM element as a render target
useSelectorMock.mockClear();
// By default use empty static assets prefix
staticAssetsPrefixMock.mockReturnValue('');
});
test('should render', async () => {
@@ -272,23 +279,27 @@ test('should render the navigation', async () => {
expect(await screen.findByRole('navigation')).toBeInTheDocument();
});
test('should render the brand', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
brand: { alt, icon },
},
} = mockedProps;
render(<Menu {...mockedProps} />, {
useRedux: true,
useQueryParams: true,
useRouter: true,
useTheme: true,
});
expect(await screen.findByAltText(alt)).toBeInTheDocument();
const image = screen.getByAltText(alt);
expect(image).toHaveAttribute('src', icon);
});
test.each(['', '/myapp'])(
'should render the brand, including app_root "%s"',
async app_root => {
staticAssetsPrefixMock.mockReturnValue(app_root);
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
data: {
brand: { alt, icon },
},
} = mockedProps;
render(<Menu {...mockedProps} />, {
useRedux: true,
useQueryParams: true,
useRouter: true,
useTheme: true,
});
expect(await screen.findByAltText(alt)).toBeInTheDocument();
const image = screen.getByAltText(alt);
expect(image).toHaveAttribute('src', `${app_root}${icon}`);
},
);
test('should render the environment tag', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });

View File

@@ -18,6 +18,8 @@
*/
import { useState, useEffect } from 'react';
import { styled, css, useTheme } from '@apache-superset/core/ui';
import { ensureStaticPrefix } from 'src/utils/assetUrl';
import { ensureAppRoot } from 'src/utils/pathUtils';
import { getUrlParam } from 'src/utils/urlUtils';
import { MainNav, MenuItem } from '@superset-ui/core/components/Menu';
import { Tooltip, Grid, Row, Col, Image } from '@superset-ui/core/components';
@@ -287,10 +289,10 @@ export function Menu({
if (theme.brandLogoUrl) {
link = (
<StyledBrandWrapper margin={theme.brandLogoMargin}>
<StyledBrandLink href={theme.brandLogoHref}>
<StyledBrandLink href={ensureAppRoot(theme.brandLogoHref)}>
<StyledImage
preview={false}
src={theme.brandLogoUrl}
src={ensureStaticPrefix(theme.brandLogoUrl)}
alt={theme.brandLogoAlt || 'Apache Superset'}
height={theme.brandLogoHeight}
/>
@@ -303,17 +305,25 @@ export function Menu({
// Kept as is for backwards compatibility with the old theme system / superset_config.py
link = (
<GenericLink className="navbar-brand" to={brand.path}>
<StyledImage preview={false} src={brand.icon} alt={brand.alt} />
<StyledImage
preview={false}
src={ensureStaticPrefix(brand.icon)}
alt={brand.alt}
/>
</GenericLink>
);
} else {
link = (
<Typography.Link
className="navbar-brand"
href={brand.path}
href={ensureAppRoot(brand.path)}
tabIndex={-1}
>
<StyledImage preview={false} src={brand.icon} alt={brand.alt} />
<StyledImage
preview={false}
src={ensureStaticPrefix(brand.icon)}
alt={brand.alt}
/>
</Typography.Link>
);
}

View File

@@ -483,7 +483,7 @@ const RightMenu = ({
userItems.push({
key: 'info',
label: (
<Typography.Link href={navbarRight.user_info_url}>
<Typography.Link href={ensureAppRoot(navbarRight.user_info_url)}>
{t('Info')}
</Typography.Link>
),