Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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,
);
Comment thread
LevisNgigi marked this conversation as resolved.
Comment thread
LevisNgigi marked this conversation as resolved.

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,7 @@ const DashboardBuilder = () => {
const filterBarWidth = dashboardFiltersOpen
? adjustedWidth
: CLOSED_FILTER_BAR_WIDTH;
setCurrentFilterBarWidth(filterBarWidth);
Comment thread
LevisNgigi marked this conversation as resolved.
Outdated
return (
<FiltersPanel
width={filterBarWidth}
Expand Down Expand Up @@ -614,7 +619,16 @@ const DashboardBuilder = () => {
</ResizableSidebar>
</>
)}
<StyledHeader ref={headerRef}>
<StyledHeader
data-test="dashboard-header-wrapper"
ref={headerRef}
filterBarWidth={
showFilterBar &&
filterBarOrientation === FilterBarOrientation.Vertical
? currentFilterBarWidth
: 0
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const filterBarWidth = useMemo(() => {
if (showFilterBar && filterBarOrientation === FilterBarOrientation.Vertical) {
return currentFilterBarWidth;
}
return 0;
}, [showFilterBar, filterBarOrientation, currentFilterBarWidth]);

Can we use variable like this outside and pass it here rather than putting ternary conditions here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

I might be missing something, but I don’t see this modification in the code.

Could you please double-check?

>
{/* @ts-ignore */}
<Droppable
data-test="top-level-tabs"
Expand Down
Loading