Skip to content

Commit 135a63a

Browse files
committed
fix: use query params
1 parent 642ea32 commit 135a63a

File tree

18 files changed

+564
-138
lines changed

18 files changed

+564
-138
lines changed

src/assets/icons/cry-cat.svg

Lines changed: 14 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.ydb-drawer-wrapper {
2+
&__item {
3+
z-index: 4;
4+
height: 100%;
5+
}
6+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import React from 'react';
2+
3+
import {Drawer, DrawerItem} from '@gravity-ui/navigation';
4+
5+
import {cn} from '../../utils/cn';
6+
7+
const DEFAULT_DRAWER_WIDTH = 600;
8+
const DRAWER_WIDTH_KEY = 'drawer-width';
9+
const b = cn('ydb-drawer-wrapper');
10+
11+
import './DrawerWrapper.scss';
12+
13+
interface DrawerContentWrapperProps {
14+
isVisible: boolean;
15+
onClose: () => void;
16+
children: React.ReactNode;
17+
drawerId?: string;
18+
storageKey?: string;
19+
defaultWidth?: number;
20+
direction?: 'left' | 'right';
21+
className?: string;
22+
detectClickOutside?: boolean;
23+
}
24+
25+
export const DrawerContentWrapper = ({
26+
isVisible,
27+
onClose,
28+
children,
29+
drawerId = 'drawer',
30+
storageKey = DRAWER_WIDTH_KEY,
31+
defaultWidth = DEFAULT_DRAWER_WIDTH,
32+
direction = 'right',
33+
className,
34+
detectClickOutside = false,
35+
}: DrawerContentWrapperProps) => {
36+
const [drawerWidth, setDrawerWidth] = React.useState(() => {
37+
const savedWidth = localStorage.getItem(storageKey);
38+
return savedWidth ? Number(savedWidth) : defaultWidth;
39+
});
40+
41+
const drawerRef = React.useRef<HTMLDivElement>(null);
42+
43+
React.useEffect(() => {
44+
if (!detectClickOutside) {
45+
return undefined;
46+
}
47+
48+
const handleClickOutside = (event: MouseEvent) => {
49+
if (
50+
isVisible &&
51+
drawerRef.current &&
52+
!drawerRef.current.contains(event.target as Node)
53+
) {
54+
onClose();
55+
}
56+
};
57+
58+
document.addEventListener('mousedown', handleClickOutside);
59+
return () => {
60+
document.removeEventListener('mousedown', handleClickOutside);
61+
};
62+
}, [isVisible, onClose, detectClickOutside]);
63+
64+
const handleResizeDrawer = (width: number) => {
65+
setDrawerWidth(width);
66+
localStorage.setItem(storageKey, width.toString());
67+
};
68+
69+
return (
70+
<Drawer
71+
onEscape={onClose}
72+
onVeilClick={onClose}
73+
hideVeil
74+
className={b('container', className)}
75+
>
76+
<DrawerItem
77+
id={drawerId}
78+
visible={isVisible}
79+
resizable
80+
width={drawerWidth}
81+
onResize={handleResizeDrawer}
82+
direction={direction}
83+
className={b('item')}
84+
ref={detectClickOutside ? drawerRef : undefined}
85+
>
86+
{children}
87+
</DrawerItem>
88+
</Drawer>
89+
);
90+
};
91+
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+
}
104+
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+
return (
118+
<React.Fragment>
119+
{children}
120+
<DrawerContentWrapper
121+
isVisible={isDrawerVisible}
122+
onClose={onCloseDrawer}
123+
drawerId={drawerId}
124+
storageKey={storageKey}
125+
defaultWidth={defaultWidth}
126+
direction={direction}
127+
className={className}
128+
detectClickOutside={detectClickOutside}
129+
>
130+
{renderDrawerContent()}
131+
</DrawerContentWrapper>
132+
</React.Fragment>
133+
);
134+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {DrawerWrapper, DrawerContentWrapper} from './DrawerWrapper';

src/containers/Tenant/Diagnostics/Diagnostics.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
position: relative;
3939

4040
overflow: hidden;
41+
42+
height: 100%;
4143
}
4244

4345
&__page-wrapper {

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

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react';
2+
3+
import {Button, Icon, Text} from '@gravity-ui/uikit';
4+
import {useHistory, useLocation} from 'react-router-dom';
5+
6+
import {parseQuery} from '../../../../routes';
7+
import {changeUserInput, setIsDirty} from '../../../../store/reducers/query/query';
8+
import {
9+
TENANT_PAGE,
10+
TENANT_PAGES_IDS,
11+
TENANT_QUERY_TABS_ID,
12+
} from '../../../../store/reducers/tenant/constants';
13+
import type {KeyValueRow} from '../../../../types/api/query';
14+
import {cn} from '../../../../utils/cn';
15+
import {useTypedDispatch} from '../../../../utils/hooks';
16+
import {TenantTabsGroups, getTenantPath} from '../../TenantPages';
17+
18+
import {QueryDetails} from './QueryDetails';
19+
import i18n from './i18n';
20+
import {createQueryInfoItems} from './utils';
21+
22+
import CryCatIcon from '../../../../assets/icons/cry-cat.svg';
23+
24+
const b = cn('kv-top-queries');
25+
26+
interface QueryDetailsDrawerContentProps {
27+
row: KeyValueRow | null;
28+
onClose: () => void;
29+
}
30+
31+
export const QueryDetailsDrawerContent = ({row, onClose}: QueryDetailsDrawerContentProps) => {
32+
const dispatch = useTypedDispatch();
33+
const location = useLocation();
34+
const history = useHistory();
35+
36+
const handleOpenInEditor = React.useCallback(() => {
37+
if (row) {
38+
const input = row.QueryText as string;
39+
dispatch(changeUserInput({input}));
40+
dispatch(setIsDirty(false));
41+
42+
const queryParams = parseQuery(location);
43+
44+
const queryPath = getTenantPath({
45+
...queryParams,
46+
[TENANT_PAGE]: TENANT_PAGES_IDS.query,
47+
[TenantTabsGroups.queryTab]: TENANT_QUERY_TABS_ID.newQuery,
48+
});
49+
50+
history.push(queryPath);
51+
}
52+
}, [dispatch, history, location, row]);
53+
54+
if (row) {
55+
return (
56+
<QueryDetails
57+
queryText={row.QueryText as string}
58+
infoItems={createQueryInfoItems(row)}
59+
onClose={onClose}
60+
onOpenInEditor={handleOpenInEditor}
61+
/>
62+
);
63+
}
64+
65+
return (
66+
<div className={b('not-found-container')}>
67+
<Icon data={CryCatIcon} size={100} />
68+
<Text variant="subheader-2" className={b('not-found-title')}>
69+
{i18n('query-details.not-found.title')}
70+
</Text>
71+
<Text variant="body-1" color="complementary" className={b('not-found-description')}>
72+
{i18n('query-details.not-found.description')}
73+
</Text>
74+
<Button size="m" view="normal" className={b('not-found-close')} onClick={onClose}>
75+
{i18n('query-details.close')}
76+
</Button>
77+
</div>
78+
);
79+
};

0 commit comments

Comments
 (0)