Skip to content

Commit b7e6780

Browse files
committed
fix: better code
1 parent c1ed814 commit b7e6780

File tree

8 files changed

+86
-80
lines changed

8 files changed

+86
-80
lines changed

src/containers/Drawer/Drawer.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.ydb-drawer {
2+
&__drawer-container {
3+
position: relative;
4+
overflow: hidden;
5+
height: 100%;
6+
}
7+
8+
&__item {
9+
z-index: 4;
10+
height: 100%;
11+
}
12+
}
Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
import React from 'react';
22

3-
import {Drawer, DrawerItem} from '@gravity-ui/navigation';
3+
import {DrawerItem, Drawer as GravityDrawer} from '@gravity-ui/navigation';
44

55
import {cn} from '../../utils/cn';
66

77
const DEFAULT_DRAWER_WIDTH = 600;
88
const DRAWER_WIDTH_KEY = 'drawer-width';
9-
const b = cn('ydb-drawer-wrapper');
9+
const b = cn('ydb-drawer');
1010

11-
import './DrawerWrapper.scss';
11+
import './Drawer.scss';
1212

13-
interface DrawerContentWrapperProps {
13+
interface ContainerProps {
14+
children: React.ReactNode;
15+
className?: string;
16+
}
17+
18+
interface WrapperProps {
19+
children: React.ReactNode;
20+
renderDrawerContent: () => React.ReactNode;
21+
isDrawerVisible: boolean;
22+
onCloseDrawer: () => void;
23+
drawerId?: string;
24+
storageKey?: string;
25+
defaultWidth?: number;
26+
direction?: 'left' | 'right';
27+
className?: string;
28+
detectClickOutside?: boolean;
29+
}
30+
31+
interface ContentWrapperProps {
1432
isVisible: boolean;
1533
onClose: () => void;
1634
children: React.ReactNode;
@@ -22,7 +40,7 @@ interface DrawerContentWrapperProps {
2240
detectClickOutside?: boolean;
2341
}
2442

25-
export const DrawerContentWrapper = ({
43+
const ContentWrapper = ({
2644
isVisible,
2745
onClose,
2846
children,
@@ -32,7 +50,7 @@ export const DrawerContentWrapper = ({
3250
direction = 'right',
3351
className,
3452
detectClickOutside = false,
35-
}: DrawerContentWrapperProps) => {
53+
}: ContentWrapperProps) => {
3654
const [drawerWidth, setDrawerWidth] = React.useState(() => {
3755
const savedWidth = localStorage.getItem(storageKey);
3856
return savedWidth ? Number(savedWidth) : defaultWidth;
@@ -67,7 +85,7 @@ export const DrawerContentWrapper = ({
6785
};
6886

6987
return (
70-
<Drawer
88+
<GravityDrawer
7189
onEscape={onClose}
7290
onVeilClick={onClose}
7391
hideVeil
@@ -85,55 +103,48 @@ export const DrawerContentWrapper = ({
85103
>
86104
{children}
87105
</DrawerItem>
88-
</Drawer>
106+
</GravityDrawer>
89107
);
90108
};
91109

92-
interface DrawerWrapperProps {
93-
children: React.ReactNode;
94-
renderDrawerContent: () => React.ReactNode;
95-
isDrawerVisible: boolean;
96-
onCloseDrawer: () => void;
97-
drawerId?: string;
98-
storageKey?: string;
99-
defaultWidth?: number;
100-
direction?: 'left' | 'right';
101-
className?: string;
102-
detectClickOutside?: boolean;
103-
}
110+
export const Drawer = {
111+
Container: ({children, className}: ContainerProps) => {
112+
return <div className={b('drawer-container', className)}>{children}</div>;
113+
},
104114

105-
export const DrawerWrapper = ({
106-
children,
107-
renderDrawerContent,
108-
isDrawerVisible,
109-
onCloseDrawer,
110-
drawerId,
111-
storageKey,
112-
defaultWidth,
113-
direction,
114-
className,
115-
detectClickOutside,
116-
}: DrawerWrapperProps) => {
117-
React.useEffect(() => {
118-
return () => {
119-
onCloseDrawer();
120-
};
121-
}, [onCloseDrawer]);
122-
return (
123-
<React.Fragment>
124-
{children}
125-
<DrawerContentWrapper
126-
isVisible={isDrawerVisible}
127-
onClose={onCloseDrawer}
128-
drawerId={drawerId}
129-
storageKey={storageKey}
130-
defaultWidth={defaultWidth}
131-
direction={direction}
132-
className={className}
133-
detectClickOutside={detectClickOutside}
134-
>
135-
{renderDrawerContent()}
136-
</DrawerContentWrapper>
137-
</React.Fragment>
138-
);
115+
Wrapper: ({
116+
children,
117+
renderDrawerContent,
118+
isDrawerVisible,
119+
onCloseDrawer,
120+
drawerId,
121+
storageKey,
122+
defaultWidth,
123+
direction,
124+
className,
125+
detectClickOutside,
126+
}: WrapperProps) => {
127+
React.useEffect(() => {
128+
return () => {
129+
onCloseDrawer();
130+
};
131+
}, [onCloseDrawer]);
132+
return (
133+
<React.Fragment>
134+
{children}
135+
<ContentWrapper
136+
isVisible={isDrawerVisible}
137+
onClose={onCloseDrawer}
138+
drawerId={drawerId}
139+
storageKey={storageKey}
140+
defaultWidth={defaultWidth}
141+
direction={direction}
142+
className={className}
143+
detectClickOutside={detectClickOutside}
144+
>
145+
{renderDrawerContent()}
146+
</ContentWrapper>
147+
</React.Fragment>
148+
);
149+
},
139150
};

src/containers/DrawerWrapper/DrawerWrapper.scss

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/containers/DrawerWrapper/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/containers/Tenant/Diagnostics/Diagnostics.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
}
3535
}
3636

37-
&__drawer-container {
38-
position: relative;
39-
40-
overflow: hidden;
41-
42-
height: 100%;
43-
}
44-
4537
&__page-wrapper {
4638
overflow: auto;
4739
flex-grow: 1;

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../../types/
1313
import type {EPathType} from '../../../types/api/schema';
1414
import {cn} from '../../../utils/cn';
1515
import {useTypedDispatch, useTypedSelector} from '../../../utils/hooks';
16+
import {Drawer} from '../../Drawer/Drawer';
1617
import {Heatmap} from '../../Heatmap';
1718
import {Nodes} from '../../Nodes/Nodes';
1819
import {Operations} from '../../Operations';
@@ -194,11 +195,11 @@ function Diagnostics(props: DiagnosticsProps) {
194195
</Helmet>
195196
) : null}
196197
{renderTabs()}
197-
<div className={b('drawer-container')}>
198+
<Drawer.Container>
198199
<div className={b('page-wrapper')} ref={containerRef}>
199200
{renderTabContent()}
200201
</div>
201-
</div>
202+
</Drawer.Container>
202203
</div>
203204
);
204205
}

src/containers/Tenant/Diagnostics/TopQueries/RunningQueriesData.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import {ResponseError} from '../../../../components/Errors/ResponseError';
77
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
88
import {Search} from '../../../../components/Search';
99
import {TableWithControlsLayout} from '../../../../components/TableWithControlsLayout/TableWithControlsLayout';
10-
import {DrawerWrapper} from '../../../../containers/DrawerWrapper';
1110
import {topQueriesApi} from '../../../../store/reducers/executeTopQueries/executeTopQueries';
1211
import type {KeyValueRow} from '../../../../types/api/query';
1312
import {cn} from '../../../../utils/cn';
1413
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
1514
import {useSelectedColumns} from '../../../../utils/hooks/useSelectedColumns';
1615
import {parseQueryErrorToString} from '../../../../utils/query';
16+
import {Drawer} from '../../../Drawer/Drawer';
1717

1818
import {QueryDetailsDrawerContent} from './QueryDetailsDrawerContent';
1919
import {getRunningQueriesColumns} from './columns/columns';
@@ -100,15 +100,14 @@ export const RunningQueriesData = ({
100100
);
101101

102102
return (
103-
<DrawerWrapper
103+
<Drawer.Wrapper
104104
isDrawerVisible={isDrawerVisible}
105105
onCloseDrawer={handleCloseDetails}
106106
renderDrawerContent={renderDrawerContent}
107107
drawerId="running-query-details"
108108
storageKey="running-queries-drawer-width"
109109
defaultWidth={600}
110110
detectClickOutside
111-
className={b('drawer-container')}
112111
>
113112
<TableWithControlsLayout>
114113
<TableWithControlsLayout.Controls>
@@ -144,6 +143,6 @@ export const RunningQueriesData = ({
144143
/>
145144
</TableWithControlsLayout.Table>
146145
</TableWithControlsLayout>
147-
</DrawerWrapper>
146+
</Drawer.Wrapper>
148147
);
149148
};

src/containers/Tenant/Diagnostics/TopQueries/TopQueriesData.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import {ResponseError} from '../../../../components/Errors/ResponseError';
1010
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
1111
import {Search} from '../../../../components/Search';
1212
import {TableWithControlsLayout} from '../../../../components/TableWithControlsLayout/TableWithControlsLayout';
13-
import {DrawerWrapper} from '../../../../containers/DrawerWrapper';
1413
import {topQueriesApi} from '../../../../store/reducers/executeTopQueries/executeTopQueries';
1514
import type {TimeFrame} from '../../../../store/reducers/executeTopQueries/types';
1615
import type {KeyValueRow} from '../../../../types/api/query';
1716
import {cn} from '../../../../utils/cn';
1817
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
1918
import {useSelectedColumns} from '../../../../utils/hooks/useSelectedColumns';
2019
import {parseQueryErrorToString} from '../../../../utils/query';
20+
import {Drawer} from '../../../Drawer/Drawer';
2121

2222
import {QueryDetailsDrawerContent} from './QueryDetailsDrawerContent';
2323
import {getTopQueriesColumns} from './columns/columns';
@@ -128,15 +128,14 @@ export const TopQueriesData = ({
128128
);
129129

130130
return (
131-
<DrawerWrapper
131+
<Drawer.Wrapper
132132
isDrawerVisible={isDrawerVisible}
133133
onCloseDrawer={handleCloseDetails}
134134
renderDrawerContent={renderDrawerContent}
135135
drawerId="query-details"
136136
storageKey="kv-top-queries-drawer-width"
137137
defaultWidth={600}
138138
detectClickOutside
139-
className={b('drawer-container')}
140139
>
141140
<TableWithControlsLayout>
142141
<TableWithControlsLayout.Controls>
@@ -183,6 +182,6 @@ export const TopQueriesData = ({
183182
/>
184183
</TableWithControlsLayout.Table>
185184
</TableWithControlsLayout>
186-
</DrawerWrapper>
185+
</Drawer.Wrapper>
187186
);
188187
};

0 commit comments

Comments
 (0)