Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dashboard Edit View Tab Headers Hidden when Dashboard Name is Long #19472

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 @@ -18,7 +18,7 @@
*/
/* eslint-env browser */
import cx from 'classnames';
import React, { FC, useCallback, useMemo } from 'react';
import React, { FC, useCallback, useEffect, useState, useMemo } from 'react';
import { JsonObject, styled, css, t } from '@superset-ui/core';
import { Global } from '@emotion/react';
import { useDispatch, useSelector } from 'react-redux';
Expand Down Expand Up @@ -56,10 +56,8 @@ import {
CLOSED_FILTER_BAR_WIDTH,
FILTER_BAR_HEADER_HEIGHT,
FILTER_BAR_TABS_HEIGHT,
HEADER_HEIGHT,
MAIN_HEADER_HEIGHT,
OPEN_FILTER_BAR_WIDTH,
TABS_HEIGHT,
} from 'src/dashboard/constants';
import { shouldFocusTabs, getRootLevelTabsComponent } from './utils';
import DashboardContainer from './DashboardContainer';
Expand Down Expand Up @@ -249,6 +247,7 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
[dispatch],
);

const headerRef = React.useRef<HTMLDivElement>(null);
const dashboardRoot = dashboardLayout[DASHBOARD_ROOT_ID];
const rootChildId = dashboardRoot?.children[0];
const topLevelTabs =
Expand All @@ -261,10 +260,26 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
uiConfig.hideTitle ||
standaloneMode === DashboardStandaloneMode.HIDE_NAV_AND_TITLE ||
isReport;
const [barTopOffset, setBarTopOffset] = useState(0);

const barTopOffset =
(hideDashboardHeader ? 0 : HEADER_HEIGHT) +
(topLevelTabs ? TABS_HEIGHT : 0);
useEffect(() => {
setBarTopOffset(headerRef.current?.getBoundingClientRect()?.height || 0);

let observer: ResizeObserver;
if (typeof global.ResizeObserver !== 'undefined' && headerRef.current) {
observer = new ResizeObserver(entries => {
setBarTopOffset(
current => entries?.[0]?.contentRect?.height || current,
);
});

observer.observe(headerRef.current);
}

return () => {
observer?.disconnect();
};
}, []);
Comment on lines +265 to +282
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice solution!


const {
showDashboard,
Expand Down Expand Up @@ -361,7 +376,7 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
</StickyPanel>
</FiltersPanel>
)}
<StyledHeader>
<StyledHeader ref={headerRef}>
{/* @ts-ignore */}
<DragDroppable
data-test="top-level-tabs"
Expand Down
2 changes: 0 additions & 2 deletions superset-frontend/src/dashboard/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export const PLACEHOLDER_DATASOURCE: Datasource = {
};

export const MAIN_HEADER_HEIGHT = 53;
export const TABS_HEIGHT = 50;
export const HEADER_HEIGHT = 72;
export const CLOSED_FILTER_BAR_WIDTH = 32;
export const OPEN_FILTER_BAR_WIDTH = 260;
export const FILTER_BAR_HEADER_HEIGHT = 80;
Expand Down