Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,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;
Expand Down Expand Up @@ -426,6 +426,9 @@ const DashboardBuilder = () => {
isReport;

const [barTopOffset, setBarTopOffset] = useState(0);
const [currentFilterBarWidth, setCurrentFilterBarWidth] = useState(
CLOSED_FILTER_BAR_WIDTH,
);

useEffect(() => {
setBarTopOffset(headerRef.current?.getBoundingClientRect()?.height || 0);
Expand Down Expand Up @@ -523,6 +526,7 @@ const DashboardBuilder = () => {
shouldFocus={shouldFocusTabs}
menuItems={[
<IconButton
key="collapse-tabs"
icon={<Icons.FallOutlined iconSize="xl" />}
label={t('Collapse tab content')}
onClick={handleDeleteTopLevelTabs}
Expand Down Expand Up @@ -566,6 +570,9 @@ const DashboardBuilder = () => {
const filterBarWidth = dashboardFiltersOpen
? adjustedWidth
: CLOSED_FILTER_BAR_WIDTH;
if (filterBarWidth !== currentFilterBarWidth) {
setCurrentFilterBarWidth(filterBarWidth);
}
return (
<FiltersPanel
width={filterBarWidth}
Expand Down Expand Up @@ -598,23 +605,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"
Expand Down
Loading