Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
16 changes: 11 additions & 5 deletions src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import {useDrawerContext} from './DrawerContext';

import './Drawer.scss';

const DEFAULT_DRAWER_WIDTH_PERCENTS = 60;
const DEFAULT_DRAWER_WIDTH = 600;
const DRAWER_WIDTH_KEY = 'drawer-width';
const b = cn('ydb-drawer');

import './Drawer.scss';

type DrawerEvent = MouseEvent & {
_capturedInsideDrawer?: boolean;
};
Expand Down Expand Up @@ -100,7 +100,7 @@
};

const handleClickInsideDrawer = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
(event.nativeEvent as DrawerEvent)._capturedInsideDrawer = true;

Check warning on line 103 in src/components/Drawer/Drawer.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'event'
};

return (
Expand Down Expand Up @@ -129,10 +129,16 @@
);
};

export enum DrawerControlType {
CLOSE = 'close',
COPY_LINK = 'copyLink',
CUSTOM = 'custom',
}

type DrawerControl =
| {type: 'close'}
| {type: 'copyLink'; link: string}
| {type: 'custom'; node: React.ReactNode; key: string};
| {type: DrawerControlType.CLOSE}
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you decide to use enum here? String has same type protection, but you should not import enum in any place you want to use drawer controls.

| {type: DrawerControlType.COPY_LINK; link: string}
| {type: DrawerControlType.CUSTOM; node: React.ReactNode; key: string};

interface DrawerPaneProps {
children: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {Button, Icon, Text} from '@gravity-ui/uikit';

import {cn} from '../../../../../utils/cn';
import i18n from '../i18n';

import CryCatIcon from '../../../../../assets/icons/cry-cat.svg';

const b = cn('kv-top-queries');

interface NotFoundContainerProps {
onClose: () => void;
}

export const NotFoundContainer = ({onClose}: NotFoundContainerProps) => {
return (
<div className={b('not-found-container')}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Flex?

<Icon data={CryCatIcon} size={100} />
<Text variant="subheader-2" className={b('not-found-title')}>
{i18n('query-details.not-found.title')}
</Text>
<Text variant="body-1" color="complementary" className={b('not-found-description')}>
{i18n('query-details.not-found.description')}
</Text>
<Button size="m" view="normal" className={b('not-found-close')} onClick={onClose}>
{i18n('query-details.close')}
</Button>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@import '../../../../../styles/mixins.scss';

.kv-query-details {
Copy link
Contributor

Choose a reason for hiding this comment

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

lets change prefix to ydb-

display: flex;
flex: 1;
flex-direction: column;

color: var(--g-color-text-primary);
background-color: var(--g-color-base-background-dark);

&__content {
overflow: auto;
flex: 1;

padding: var(--g-spacing-5) var(--g-spacing-4) var(--g-spacing-5) var(--g-spacing-4);
}

&__query-header {
display: flex;
justify-content: space-between;
align-items: center;

padding: var(--g-spacing-2) var(--g-spacing-3);

border-bottom: 1px solid var(--g-color-line-generic);
}

&__query-title {
font-size: 14px;
font-weight: 500;
}

&__query-content {
position: relative;

display: flex;
flex: 1;
flex-direction: column;

margin-top: var(--g-spacing-5);

border-radius: 4px;
background-color: var(--code-background-color);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {Code} from '@gravity-ui/icons';
import {Button, Flex, Icon} from '@gravity-ui/uikit';

import type {InfoViewerItem} from '../../../../../components/InfoViewer';
import {InfoViewer} from '../../../../../components/InfoViewer';
import {YDBSyntaxHighlighter} from '../../../../../components/SyntaxHighlighter/YDBSyntaxHighlighter';
import {cn} from '../../../../../utils/cn';
import i18n from '../i18n';

import './QueryDetails.scss';

const b = cn('kv-query-details');

interface QueryDetailsProps {
queryText: string;
infoItems: InfoViewerItem[];
onOpenInEditor: () => void;
}

export const QueryDetails = ({queryText, infoItems, onOpenInEditor}: QueryDetailsProps) => {
return (
<div className={b()}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Flex?

<Flex direction="column" className={b('content')}>
<InfoViewer info={infoItems} />

<div className={b('query-content')}>
<div className={b('query-header')}>
<div className={b('query-title')}>{i18n('query-details.query.title')}</div>
<Button
view="flat-secondary"
size="m"
onClick={onOpenInEditor}
className={b('editor-button')}
>
<Icon data={Code} size={16} />
{i18n('query-details.open-in-editor')}
</Button>
</div>
<YDBSyntaxHighlighter
language="yql"
text={queryText}
withClipboardButton={{alwaysVisible: true, withLabel: false}}
/>
</div>
</Flex>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';

import {useHistory, useLocation} from 'react-router-dom';

import {parseQuery} from '../../../../../routes';
import {changeUserInput, setIsDirty} from '../../../../../store/reducers/query/query';
import {
TENANT_PAGE,
TENANT_PAGES_IDS,
TENANT_QUERY_TABS_ID,
} from '../../../../../store/reducers/tenant/constants';
import type {KeyValueRow} from '../../../../../types/api/query';
import {useTypedDispatch} from '../../../../../utils/hooks';
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
import {createQueryInfoItems} from '../utils';

import {NotFoundContainer} from './NotFoundContainer';
import {QueryDetails} from './QueryDetails';

interface QueryDetailsDrawerContentProps {
row: KeyValueRow | null;
onClose: () => void;
}

export const QueryDetailsDrawerContent = ({row, onClose}: QueryDetailsDrawerContentProps) => {
const dispatch = useTypedDispatch();
const location = useLocation();
const history = useHistory();

const handleOpenInEditor = React.useCallback(() => {
if (row) {
const input = row.QueryText as string;
dispatch(changeUserInput({input}));
dispatch(setIsDirty(false));

const queryParams = parseQuery(location);

const queryPath = getTenantPath({
...queryParams,
[TENANT_PAGE]: TENANT_PAGES_IDS.query,
[TenantTabsGroups.queryTab]: TENANT_QUERY_TABS_ID.newQuery,
});

history.push(queryPath);
}
}, [dispatch, history, location, row]);

if (row) {
return (
<QueryDetails
queryText={row.QueryText as string}
infoItems={createQueryInfoItems(row)}
onOpenInEditor={handleOpenInEditor}
/>
);
}

return <NotFoundContainer onClose={onClose} />;
};
Loading
Loading