Skip to content

Commit 4a75277

Browse files
committed
fix: code snippets
1 parent 216c645 commit 4a75277

File tree

14 files changed

+99
-107
lines changed

14 files changed

+99
-107
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.snippet {
2+
&__content {
3+
border: 1px solid var(--g-color-line-generic);
4+
5+
overflow: auto;
6+
7+
* {
8+
cursor: pointer !important;
9+
}
10+
}
11+
}

src/components/Snippet/Snippet.tsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react';
2+
3+
import {useThemeValue} from '@gravity-ui/uikit';
4+
import type {editor} from 'monaco-editor';
5+
import 'monaco-yql-languages/build/monaco.contribution';
6+
import MonacoEditor from 'react-monaco-editor';
7+
8+
import {cn} from '../../utils/cn';
9+
import {YQL_LANGUAGE_ID} from '../../utils/monaco/constants';
10+
11+
import './Snippet.scss';
12+
13+
const block = cn('snippet');
14+
const SNIPPET_LENGTH = 7;
15+
16+
export interface SnippetProps {
17+
className?: string;
18+
children: string;
19+
language?: string;
20+
}
21+
22+
export const Snippet = ({
23+
className,
24+
children,
25+
language = YQL_LANGUAGE_ID,
26+
}: SnippetProps): JSX.Element => {
27+
const themeValue = useThemeValue();
28+
const theme = `vs-${themeValue}`;
29+
30+
const editorOptions = React.useMemo<editor.IStandaloneEditorConstructionOptions>(
31+
() => ({
32+
readOnly: true,
33+
minimap: {enabled: false},
34+
scrollBeyondLastLine: false,
35+
lineNumbers: 'off' as const,
36+
scrollbar: {
37+
vertical: 'visible',
38+
horizontal: 'visible',
39+
verticalScrollbarSize: 8,
40+
horizontalScrollbarSize: 8,
41+
alwaysConsumeMouseWheel: false,
42+
},
43+
renderLineHighlight: 'none' as const,
44+
overviewRulerLanes: 0,
45+
hideCursorInOverviewRuler: true,
46+
overviewRulerBorder: false,
47+
lineDecorationsWidth: 0,
48+
contextmenu: false,
49+
fontSize: 13,
50+
lineHeight: 20,
51+
domReadOnly: true,
52+
}),
53+
[],
54+
);
55+
56+
return (
57+
<div className={block(null, className)}>
58+
<div className={block('content')}>
59+
<MonacoEditor
60+
language={language}
61+
theme={theme}
62+
value={children}
63+
height={SNIPPET_LENGTH * 20}
64+
options={editorOptions}
65+
/>
66+
</div>
67+
</div>
68+
);
69+
};

src/components/SqlHighlighter/SqlHighlighter.scss

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

src/components/SqlHighlighter/SqlHighlighter.tsx

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
1-
import React from 'react';
2-
31
import {cn} from '../../utils/cn';
42
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
5-
import {SqlHighlighter} from '../SqlHighlighter/SqlHighlighter';
3+
import {Snippet} from '../Snippet/Snippet';
64

75
import './TruncatedQuery.scss';
86

97
const b = cn('kv-truncated-query');
108

119
interface TruncatedQueryProps {
1210
value?: string;
13-
maxQueryHeight?: number;
1411
}
1512

16-
export const TruncatedQuery = ({value = '', maxQueryHeight = 6}: TruncatedQueryProps) => {
17-
const lines = value.split('\n');
18-
const truncated = lines.length > maxQueryHeight;
19-
20-
if (truncated) {
21-
const content = lines.slice(0, maxQueryHeight).join('\n');
22-
const message =
23-
'\n...\nThe request was truncated. Click on the line to show the full query on the query tab';
24-
return (
25-
<React.Fragment>
26-
<SqlHighlighter className={b()}>{content}</SqlHighlighter>
27-
<span className={b('message', {color: 'secondary'})}>{message}</span>
28-
</React.Fragment>
29-
);
30-
}
31-
return <SqlHighlighter>{value}</SqlHighlighter>;
13+
export const TruncatedQuery = ({value = ''}: TruncatedQueryProps) => {
14+
return <Snippet>{value}</Snippet>;
3215
};
3316

3417
interface OneLineQueryWithPopoverProps {
@@ -39,9 +22,9 @@ export const OneLineQueryWithPopover = ({value = ''}: OneLineQueryWithPopoverPro
3922
return (
4023
<CellWithPopover
4124
contentClassName={b('popover-content')}
42-
content={<SqlHighlighter>{value}</SqlHighlighter>}
25+
content={<Snippet>{value}</Snippet>}
4326
>
44-
<SqlHighlighter>{value}</SqlHighlighter>
27+
<Snippet>{value}</Snippet>
4528
</CellWithPopover>
4629
);
4730
};

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {cn} from '../../../../../utils/cn';
1010
import {formatDateTime, formatNumber} from '../../../../../utils/dataFormatters/dataFormatters';
1111
import {generateHash} from '../../../../../utils/generateHash';
1212
import {formatToMs, parseUsToMs} from '../../../../../utils/timeParsers';
13-
import {MAX_QUERY_HEIGHT} from '../../../utils/constants';
1413

1514
import {
1615
TOP_QUERIES_COLUMNS_IDS,
@@ -38,7 +37,7 @@ const queryTextColumn: Column<KeyValueRow> = {
3837
sortAccessor: (row) => Number(row.CPUTimeUs),
3938
render: ({row}) => (
4039
<div className={b('query')}>
41-
<TruncatedQuery value={row.QueryText?.toString()} maxQueryHeight={MAX_QUERY_HEIGHT} />
40+
<TruncatedQuery value={row.QueryText?.toString()} />
4241
</div>
4342
),
4443
sortable: false,

src/containers/Tenant/Info/View/View.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {DefinitionListItem} from '@gravity-ui/components';
22

3-
import {SqlHighlighter} from '../../../../components/SqlHighlighter/SqlHighlighter';
3+
import {Snippet} from '../../../../components/Snippet/Snippet';
44
import {YDBDefinitionList} from '../../../../components/YDBDefinitionList/YDBDefinitionList';
55
import type {TEvDescribeSchemeResult} from '../../../../types/api/schema';
66
import {getEntityName} from '../../utils';
@@ -13,7 +13,7 @@ const prepareViewItems = (data: TEvDescribeSchemeResult): DefinitionListItem[] =
1313
{
1414
name: i18n('view.query-text'),
1515
copyText: queryText,
16-
content: queryText ? <SqlHighlighter>{queryText}</SqlHighlighter> : null,
16+
content: queryText ? <Snippet>{queryText}</Snippet> : null,
1717
},
1818
];
1919
};

src/containers/Tenant/Query/QueriesHistory/QueriesHistory.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {formatDateTime} from '../../../../utils/dataFormatters/dataFormatters';
1717
import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
1818
import {useChangeInputWithConfirmation} from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation';
1919
import {formatToMs, parseUsToMs} from '../../../../utils/timeParsers';
20-
import {MAX_QUERY_HEIGHT, QUERY_TABLE_SETTINGS} from '../../utils/constants';
20+
import {QUERY_TABLE_SETTINGS} from '../../utils/constants';
2121
import i18n from '../i18n';
2222

2323
import './QueriesHistory.scss';
@@ -55,7 +55,7 @@ function QueriesHistory({changeUserInput}: QueriesHistoryProps) {
5555
render: ({row}) => {
5656
return (
5757
<div className={b('query')}>
58-
<TruncatedQuery value={row.queryText} maxQueryHeight={MAX_QUERY_HEIGHT} />
58+
<TruncatedQuery value={row.queryText} />
5959
</div>
6060
);
6161
},

src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
} from '../../../../utils/hooks';
4242
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
4343
import {useLastQueryExecutionSettings} from '../../../../utils/hooks/useLastQueryExecutionSettings';
44-
import {YQL_LANGUAGE_ID} from '../../../../utils/monaco/constats';
44+
import {YQL_LANGUAGE_ID} from '../../../../utils/monaco/constants';
4545
import {QUERY_ACTIONS} from '../../../../utils/query';
4646
import type {InitialPaneState} from '../../utils/paneVisibilityToggleHelpers';
4747
import {

src/containers/Tenant/Query/QueryResult/components/Ast/Ast.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import MonacoEditor from 'react-monaco-editor';
22

33
import {cn} from '../../../../../../utils/cn';
4-
import {S_EXPRESSION_LANGUAGE_ID} from '../../../../../../utils/monaco/constats';
4+
import {S_EXPRESSION_LANGUAGE_ID} from '../../../../../../utils/monaco/constants';
55

66
import './Ast.scss';
77

0 commit comments

Comments
 (0)