fix: fix tabs overflow in dashboards (#35984)

This commit is contained in:
Levis Mbote
2025-11-12 19:35:29 +03:00
committed by GitHub
parent a45c0528da
commit bb2e2a5ed6
2 changed files with 111 additions and 18 deletions

View File

@@ -275,6 +275,85 @@ describe('DashboardBuilder', () => {
expect(filterbar).toHaveStyleRule('width', `${expectedValue}px`);
});
test('should set header max width based on open filter bar width', () => {
const expectedValue = 320;
const setter = jest.fn();
(useStoredSidebarWidth as jest.Mock).mockImplementation(() => [
expectedValue,
setter,
]);
const nativeFiltersSpy = jest
.spyOn(useNativeFiltersModule, 'useNativeFilters')
.mockReturnValue({
showDashboard: true,
missingInitialFilters: [],
dashboardFiltersOpen: true,
toggleDashboardFiltersOpen: jest.fn(),
nativeFiltersEnabled: true,
});
const { getByTestId } = setup();
expect(getByTestId('dashboard-header-wrapper')).toHaveStyleRule(
'max-width',
`calc(100vw - ${expectedValue}px)`,
);
nativeFiltersSpy.mockRestore();
});
test('should use closed filter bar width when the panel is collapsed', () => {
const setter = jest.fn();
(useStoredSidebarWidth as jest.Mock).mockImplementation(() => [
OPEN_FILTER_BAR_WIDTH,
setter,
]);
const nativeFiltersSpy = jest
.spyOn(useNativeFiltersModule, 'useNativeFilters')
.mockReturnValue({
showDashboard: true,
missingInitialFilters: [],
dashboardFiltersOpen: false,
toggleDashboardFiltersOpen: jest.fn(),
nativeFiltersEnabled: true,
});
const { getByTestId } = setup();
expect(getByTestId('dashboard-header-wrapper')).toHaveStyleRule(
'max-width',
`calc(100vw - ${CLOSED_FILTER_BAR_WIDTH}px)`,
);
nativeFiltersSpy.mockRestore();
});
test('should not constrain header width when filter bar is hidden', () => {
const setter = jest.fn();
(useStoredSidebarWidth as jest.Mock).mockImplementation(() => [
OPEN_FILTER_BAR_WIDTH,
setter,
]);
const nativeFiltersSpy = jest
.spyOn(useNativeFiltersModule, 'useNativeFilters')
.mockReturnValue({
showDashboard: true,
missingInitialFilters: [],
dashboardFiltersOpen: true,
toggleDashboardFiltersOpen: jest.fn(),
nativeFiltersEnabled: false,
});
const { getByTestId } = setup();
expect(getByTestId('dashboard-header-wrapper')).toHaveStyleRule(
'max-width',
'calc(100vw - 0px)',
);
nativeFiltersSpy.mockRestore();
});
test('filter panel state when featureflag is true', () => {
window.featureFlags = {
[FeatureFlag.FilterBarClosedByDefault]: true,

View File

@@ -89,14 +89,14 @@ const StickyPanel = styled.div<{ width: number }>`
`;
// @z-index-above-dashboard-popovers (99) + 1 = 100
const StyledHeader = styled.div`
${({ theme }) => css`
const StyledHeader = styled.div<{ filterBarWidth: number }>`
${({ theme, filterBarWidth }) => css`
grid-column: 2;
grid-row: 1;
position: sticky;
top: 0;
z-index: 99;
max-width: 100vw;
max-width: calc(100vw - ${filterBarWidth}px);
.empty-droptarget:before {
position: absolute;
@@ -419,6 +419,9 @@ const DashboardBuilder = () => {
isReport;
const [barTopOffset, setBarTopOffset] = useState(0);
const [currentFilterBarWidth, setCurrentFilterBarWidth] = useState(
CLOSED_FILTER_BAR_WIDTH,
);
useEffect(() => {
setBarTopOffset(headerRef.current?.getBoundingClientRect()?.height || 0);
@@ -516,6 +519,7 @@ const DashboardBuilder = () => {
shouldFocus={shouldFocusTabs}
menuItems={[
<IconButton
key="collapse-tabs"
icon={<Icons.FallOutlined iconSize="xl" />}
label={t('Collapse tab content')}
onClick={handleDeleteTopLevelTabs}
@@ -559,6 +563,9 @@ const DashboardBuilder = () => {
const filterBarWidth = dashboardFiltersOpen
? adjustedWidth
: CLOSED_FILTER_BAR_WIDTH;
if (filterBarWidth !== currentFilterBarWidth) {
setCurrentFilterBarWidth(filterBarWidth);
}
return (
<FiltersPanel
width={filterBarWidth}
@@ -591,23 +598,30 @@ const DashboardBuilder = () => {
],
);
const isVerticalFilterBarVisible =
showFilterBar && filterBarOrientation === FilterBarOrientation.Vertical;
const headerFilterBarWidth = isVerticalFilterBarVisible
? currentFilterBarWidth
: 0;
return (
<DashboardWrapper>
{showFilterBar &&
filterBarOrientation === FilterBarOrientation.Vertical && (
<>
<ResizableSidebar
id={`dashboard:${dashboardId}`}
enable={dashboardFiltersOpen}
minWidth={OPEN_FILTER_BAR_WIDTH}
maxWidth={OPEN_FILTER_BAR_MAX_WIDTH}
initialWidth={OPEN_FILTER_BAR_WIDTH}
>
{renderChild}
</ResizableSidebar>
</>
)}
<StyledHeader ref={headerRef}>
{isVerticalFilterBarVisible && (
<ResizableSidebar
id={`dashboard:${dashboardId}`}
enable={dashboardFiltersOpen}
minWidth={OPEN_FILTER_BAR_WIDTH}
maxWidth={OPEN_FILTER_BAR_MAX_WIDTH}
initialWidth={OPEN_FILTER_BAR_WIDTH}
>
{renderChild}
</ResizableSidebar>
)}
<StyledHeader
data-test="dashboard-header-wrapper"
ref={headerRef}
filterBarWidth={headerFilterBarWidth}
>
{/* @ts-ignore */}
<Droppable
data-test="top-level-tabs"