Skip to content

Commit 9e18128

Browse files
fix(Fullscreen): fix overlay and root (#2817)
1 parent 4ddfc9e commit 9e18128

File tree

10 files changed

+62
-31
lines changed

10 files changed

+62
-31
lines changed

src/components/EnableFullscreenButton/EnableFullscreenButton.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ interface EnableFullscreenButtonProps {
1212
view?: ButtonView;
1313
}
1414

15-
function EnableFullscreenButton({disabled, view = 'flat-secondary'}: EnableFullscreenButtonProps) {
15+
export function EnableFullscreenButton({
16+
disabled,
17+
view = 'flat-secondary',
18+
}: EnableFullscreenButtonProps) {
1619
const dispatch = useTypedDispatch();
1720
const onEnableFullscreen = () => {
1821
dispatch(enableFullscreen());
@@ -25,5 +28,3 @@ function EnableFullscreenButton({disabled, view = 'flat-secondary'}: EnableFulls
2528
</ActionTooltip>
2629
);
2730
}
28-
29-
export default EnableFullscreenButton;

src/components/Fullscreen/Fullscreen.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
.ydb-fullscreen {
2+
--ydb-fullscreen-z-index: 1000;
3+
24
overflow: hidden;
35
flex-grow: 1;
46

57
&_fullscreen {
68
// should expand to fill the content area, keeping aside navigation visible
79
// counts on .gn-aside-header__content to have position: relative, it is set in App.scss
810
position: absolute;
9-
z-index: 10;
11+
z-index: var(--ydb-fullscreen-z-index);
1012
inset: 0;
1113

1214
background-color: var(--g-color-base-background);
1315
}
1416

1517
&__close-button {
1618
position: fixed;
17-
z-index: 11;
19+
z-index: calc(var(--ydb-fullscreen-z-index) + 1);
1820
top: 8px;
1921
right: 20px;
2022

src/components/Fullscreen/Fullscreen.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {cn} from '../../utils/cn';
77
import {useTypedDispatch, useTypedSelector} from '../../utils/hooks';
88
import {Portal} from '../Portal/Portal';
99

10+
import {useFullscreenContext} from './FullscreenContext';
11+
1012
import disableFullscreenIcon from '../../assets/icons/disableFullscreen.svg';
1113

1214
import './Fullscreen.scss';
@@ -18,11 +20,10 @@ interface FullscreenProps {
1820
className?: string;
1921
}
2022

21-
const fullscreenRoot = document.getElementById('fullscreen-root') ?? undefined;
22-
23-
function Fullscreen({children, className}: FullscreenProps) {
23+
export function Fullscreen({children, className}: FullscreenProps) {
2424
const isFullscreen = useTypedSelector((state) => state.fullscreen);
2525
const dispatch = useTypedDispatch();
26+
const fullscreenRootRef = useFullscreenContext();
2627

2728
const onDisableFullScreen = React.useCallback(() => {
2829
dispatch(disableFullscreen());
@@ -44,20 +45,20 @@ function Fullscreen({children, className}: FullscreenProps) {
4445
const [container, setContainer] = React.useState<HTMLDivElement | null>(null);
4546
React.useEffect(() => {
4647
const div = document.createElement('div');
47-
fullscreenRoot?.appendChild(div);
48+
fullscreenRootRef.current?.appendChild(div);
4849
div.style.display = 'contents';
4950
setContainer(div);
5051
return () => {
5152
setContainer(null);
5253
div.remove();
5354
};
54-
}, []);
55+
}, [fullscreenRootRef]);
5556

5657
const ref = React.useRef<HTMLDivElement>(null);
5758
React.useLayoutEffect(() => {
5859
if (container) {
5960
if (isFullscreen) {
60-
fullscreenRoot?.appendChild(container);
61+
fullscreenRootRef.current?.appendChild(container);
6162
} else {
6263
ref.current?.appendChild(container);
6364
}
@@ -67,7 +68,7 @@ function Fullscreen({children, className}: FullscreenProps) {
6768
window.dispatchEvent(new Event('resize'));
6869
});
6970
}
70-
}, [container, isFullscreen]);
71+
}, [container, fullscreenRootRef, isFullscreen]);
7172

7273
if (!container) {
7374
return null;
@@ -90,5 +91,3 @@ function Fullscreen({children, className}: FullscreenProps) {
9091
</div>
9192
);
9293
}
93-
94-
export default Fullscreen;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
3+
const FullscreenContext = React.createContext<React.RefObject<HTMLDivElement> | null>(null);
4+
5+
export function useFullscreenContext() {
6+
const context = React.useContext(FullscreenContext);
7+
if (!context) {
8+
throw new Error('useFullscreenContext must be used within a FullscreenProvider');
9+
}
10+
return context;
11+
}
12+
13+
export function FullscreenProvider({
14+
children,
15+
fullscreenRootRef,
16+
}: {
17+
children: React.ReactNode;
18+
fullscreenRootRef: React.RefObject<HTMLDivElement>;
19+
}) {
20+
return (
21+
<FullscreenContext.Provider value={fullscreenRootRef}>
22+
{children}
23+
</FullscreenContext.Provider>
24+
);
25+
}

src/containers/App/App.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {History} from 'history';
55
import {Helmet} from 'react-helmet-async';
66

77
import {componentsRegistry} from '../../components/ComponentsProvider/componentsRegistry';
8+
import {FullscreenProvider} from '../../components/Fullscreen/FullscreenContext';
89
import {useTypedSelector} from '../../utils/hooks';
910
import ReduxTooltip from '../ReduxTooltip/ReduxTooltip';
1011
import type {YDBEmbeddedUISettings} from '../UserSettings/settings';
@@ -47,19 +48,22 @@ function AppContent({
4748
}) {
4849
const {appTitle} = useAppTitle();
4950
const singleClusterMode = useTypedSelector((state) => state.singleClusterMode);
51+
const fullscreenRootRef = React.useRef<HTMLDivElement>(null);
5052

5153
return (
5254
<React.Fragment>
5355
<Helmet defaultTitle={appTitle} titleTemplate={`%s — ${appTitle}`} />
54-
<ContentWrapper>
55-
<NavigationWrapper
56-
singleClusterMode={singleClusterMode}
57-
userSettings={userSettings}
58-
>
59-
<Content singleClusterMode={singleClusterMode}>{children}</Content>
60-
<div id="fullscreen-root"></div>
61-
</NavigationWrapper>
62-
</ContentWrapper>
56+
<FullscreenProvider fullscreenRootRef={fullscreenRootRef}>
57+
<ContentWrapper>
58+
<NavigationWrapper
59+
singleClusterMode={singleClusterMode}
60+
userSettings={userSettings}
61+
>
62+
<Content singleClusterMode={singleClusterMode}>{children}</Content>
63+
<div ref={fullscreenRootRef}></div>
64+
</NavigationWrapper>
65+
</ContentWrapper>
66+
</FullscreenProvider>
6367
</React.Fragment>
6468
);
6569
}

src/containers/Tenant/Diagnostics/TopicData/TopicData.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {isNil} from 'lodash';
66

77
import {DrawerWrapper} from '../../../../components/Drawer';
88
import {EmptyFilter} from '../../../../components/EmptyFilter/EmptyFilter';
9-
import EnableFullscreenButton from '../../../../components/EnableFullscreenButton/EnableFullscreenButton';
9+
import {EnableFullscreenButton} from '../../../../components/EnableFullscreenButton/EnableFullscreenButton';
1010
import {PageError} from '../../../../components/Errors/PageError/PageError';
11-
import Fullscreen from '../../../../components/Fullscreen/Fullscreen';
11+
import {Fullscreen} from '../../../../components/Fullscreen/Fullscreen';
1212
import {
1313
DEFAULT_TABLE_ROW_HEIGHT,
1414
ResizeablePaginatedTable,

src/containers/Tenant/Healthcheck/Healthcheck.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import {Flex, Icon} from '@gravity-ui/uikit';
44

55
import {ResponseError} from '../../../components/Errors/ResponseError';
6-
import Fullscreen from '../../../components/Fullscreen/Fullscreen';
6+
import {Fullscreen} from '../../../components/Fullscreen/Fullscreen';
77
import {HealthcheckStatus} from '../../../components/HealthcheckStatus/HealthcheckStatus';
88
import {Illustration} from '../../../components/Illustration';
99
import {Loader} from '../../../components/Loader';

src/containers/Tenant/Query/Preview/components/PreviewView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import React from 'react';
33
import {Xmark} from '@gravity-ui/icons';
44
import {Button, Flex, Icon, Text} from '@gravity-ui/uikit';
55

6-
import EnableFullscreenButton from '../../../../../components/EnableFullscreenButton/EnableFullscreenButton';
7-
import Fullscreen from '../../../../../components/Fullscreen/Fullscreen';
6+
import {EnableFullscreenButton} from '../../../../../components/EnableFullscreenButton/EnableFullscreenButton';
7+
import {Fullscreen} from '../../../../../components/Fullscreen/Fullscreen';
88
import {LoaderWrapper} from '../../../../../components/LoaderWrapper/LoaderWrapper';
99
import {setShowPreview} from '../../../../../store/reducers/schema/schema';
1010
import {useTypedDispatch} from '../../../../../utils/hooks';

src/containers/Tenant/Query/QueryResult/QueryResultViewer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type {Settings} from '@gravity-ui/react-data-table';
55
import type {ControlGroupOption} from '@gravity-ui/uikit';
66
import {ClipboardButton, Flex, SegmentedRadioGroup, Text} from '@gravity-ui/uikit';
77

8-
import EnableFullscreenButton from '../../../../components/EnableFullscreenButton/EnableFullscreenButton';
9-
import Fullscreen from '../../../../components/Fullscreen/Fullscreen';
8+
import {EnableFullscreenButton} from '../../../../components/EnableFullscreenButton/EnableFullscreenButton';
9+
import {Fullscreen} from '../../../../components/Fullscreen/Fullscreen';
1010
import {Illustration} from '../../../../components/Illustration';
1111
import {LoaderWrapper} from '../../../../components/LoaderWrapper/LoaderWrapper';
1212
import {QueryExecutionStatus} from '../../../../components/QueryExecutionStatus';

src/containers/Tenant/TenantDrawerHealthcheck.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ArrowDownToLine} from '@gravity-ui/icons';
44
import {ActionTooltip, Button, Flex, Icon, Text} from '@gravity-ui/uikit';
55

66
import {DrawerWrapper} from '../../components/Drawer';
7-
import EnableFullscreenButton from '../../components/EnableFullscreenButton/EnableFullscreenButton';
7+
import {EnableFullscreenButton} from '../../components/EnableFullscreenButton/EnableFullscreenButton';
88
import {
99
selectAllHealthcheckInfo,
1010
selectCheckStatus,

0 commit comments

Comments
 (0)