Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display view query text #1761

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const config: PlaywrightTestConfig = {
: {
command: 'npm run dev',
port: 3000,
reuseExistingServer: true,
},
use: {
baseURL: baseUrl || 'http://localhost:3000/',
Expand Down
9 changes: 9 additions & 0 deletions src/components/Snippet/Snippet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.snippet {
&__content {
border: 1px solid var(--g-color-line-generic);

* {
cursor: pointer !important;
}
}
}
70 changes: 70 additions & 0 deletions src/components/Snippet/Snippet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from 'react';

import {useThemeValue} from '@gravity-ui/uikit';
import type {editor} from 'monaco-editor';
import 'monaco-yql-languages/build/monaco.contribution';
import MonacoEditor from 'react-monaco-editor';

import {cn} from '../../utils/cn';
import {YQL_LANGUAGE_ID} from '../../utils/monaco/constants';

import './Snippet.scss';

const block = cn('snippet');
const SNIPPET_LENGTH = 7;

export interface SnippetProps {
className?: string;
children: string;
language?: string;
}

export const Snippet = ({
className,
children,
language = YQL_LANGUAGE_ID,
}: SnippetProps): JSX.Element => {
Copy link
Contributor

Choose a reason for hiding this comment

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

for now we don't specify returning type. It seems we should always do (and add linter rule for this), or always don't...

const themeValue = useThemeValue();
const theme = `vs-${themeValue}`;

const editorOptions = React.useMemo<editor.IStandaloneEditorConstructionOptions>(
Copy link
Contributor

Choose a reason for hiding this comment

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

It's all constant options, let's move them outside from component.

() => ({
readOnly: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to make editor totally not interactive?
Screen Recording 2024-12-20 at 09 54 35

minimap: {enabled: false},
scrollBeyondLastLine: false,
lineNumbers: 'off' as const,
scrollbar: {
vertical: 'visible',
horizontal: 'visible',
verticalScrollbarSize: 8,
horizontalScrollbarSize: 8,
alwaysConsumeMouseWheel: false,
},
renderLineHighlight: 'none' as const,
overviewRulerLanes: 0,
hideCursorInOverviewRuler: true,
overviewRulerBorder: false,
lineDecorationsWidth: 0,
contextmenu: false,
fontSize: 13,
lineHeight: 20,
domReadOnly: true,
automaticLayout: true,
}),
[],
);

return (
<div className={block(null, className)}>
<div className={block('content')}>
<MonacoEditor
language={language}
theme={theme}
value={children}
height={SNIPPET_LENGTH * 20}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make a variable height with maximum SNIPPET_LENGTH * 20

For example, here such height looks redundant.
Screenshot 2024-12-20 at 10 07 00

options={editorOptions}
/>
</div>
</div>
);
};
29 changes: 8 additions & 21 deletions src/components/TruncatedQuery/TruncatedQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
import React from 'react';

import {cn} from '../../utils/cn';
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
import {Snippet} from '../Snippet/Snippet';

import './TruncatedQuery.scss';

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

interface TruncatedQueryProps {
value?: string;
maxQueryHeight?: number;
}

export const TruncatedQuery = ({value = '', maxQueryHeight = 6}: TruncatedQueryProps) => {
const lines = value.split('\n');
const truncated = lines.length > maxQueryHeight;

if (truncated) {
const content = lines.slice(0, maxQueryHeight).join('\n');
const message =
'\n...\nThe request was truncated. Click on the line to show the full query on the query tab';
return (
<React.Fragment>
<span className={b()}>{content}</span>
<span className={b('message', {color: 'secondary'})}>{message}</span>
</React.Fragment>
);
}
return <React.Fragment>{value}</React.Fragment>;
export const TruncatedQuery = ({value = ''}: TruncatedQueryProps) => {
return <Snippet>{value}</Snippet>;
Copy link
Contributor

Choose a reason for hiding this comment

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

For now it's not truncated. Let's rename component

};

interface OneLineQueryWithPopoverProps {
Expand All @@ -36,8 +20,11 @@ interface OneLineQueryWithPopoverProps {

export const OneLineQueryWithPopover = ({value = ''}: OneLineQueryWithPopoverProps) => {
return (
<CellWithPopover contentClassName={b('popover-content')} content={value}>
{value}
<CellWithPopover
contentClassName={b('popover-content')}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that popover is now redundant, because we don't truncate query any more.

content={<Snippet>{value}</Snippet>}
>
<Snippet>{value}</Snippet>
</CellWithPopover>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {cn} from '../../../../../utils/cn';
import {formatDateTime, formatNumber} from '../../../../../utils/dataFormatters/dataFormatters';
import {generateHash} from '../../../../../utils/generateHash';
import {formatToMs, parseUsToMs} from '../../../../../utils/timeParsers';
import {MAX_QUERY_HEIGHT} from '../../../utils/constants';

import {
TOP_QUERIES_COLUMNS_IDS,
Expand Down Expand Up @@ -38,7 +37,7 @@ const queryTextColumn: Column<KeyValueRow> = {
sortAccessor: (row) => Number(row.CPUTimeUs),
render: ({row}) => (
<div className={b('query')}>
<TruncatedQuery value={row.QueryText?.toString()} maxQueryHeight={MAX_QUERY_HEIGHT} />
<TruncatedQuery value={row.QueryText?.toString()} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot 2024-12-20 at 10 00 03

</div>
),
sortable: false,
Expand Down
5 changes: 5 additions & 0 deletions src/containers/Tenant/Info/View/View.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.view {
&__snippet-container {
width: 650px;
}
}
15 changes: 9 additions & 6 deletions src/containers/Tenant/Info/View/View.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import type {DefinitionListItem} from '@gravity-ui/components';
import {Text} from '@gravity-ui/uikit';

import {Snippet} from '../../../../components/Snippet/Snippet';
import {YDBDefinitionList} from '../../../../components/YDBDefinitionList/YDBDefinitionList';
import type {TEvDescribeSchemeResult} from '../../../../types/api/schema';
import {cn} from '../../../../utils/cn';
import {getEntityName} from '../../utils';
import i18n from '../i18n';

import './View.scss';

const b = cn('view');

const prepareViewItems = (data: TEvDescribeSchemeResult): DefinitionListItem[] => {
const queryText = data.PathDescription?.ViewDescription?.QueryText;

return [
{
name: i18n('view.query-text'),
copyText: queryText,
content: (
<Text variant="code-2" wordBreak="break-word">
{queryText}
</Text>
),
content: queryText ? (
<Snippet className={b('snippet-container')}>{queryText}</Snippet>
) : null,
},
];
};
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Tenant/Query/QueriesHistory/QueriesHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {formatDateTime} from '../../../../utils/dataFormatters/dataFormatters';
import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
import {useChangeInputWithConfirmation} from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation';
import {formatToMs, parseUsToMs} from '../../../../utils/timeParsers';
import {MAX_QUERY_HEIGHT, QUERY_TABLE_SETTINGS} from '../../utils/constants';
import {QUERY_TABLE_SETTINGS} from '../../utils/constants';
import i18n from '../i18n';

import './QueriesHistory.scss';
Expand Down Expand Up @@ -55,7 +55,7 @@ function QueriesHistory({changeUserInput}: QueriesHistoryProps) {
render: ({row}) => {
return (
<div className={b('query')}>
<TruncatedQuery value={row.queryText} maxQueryHeight={MAX_QUERY_HEIGHT} />
<TruncatedQuery value={row.queryText} />
</div>
);
},
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
} from '../../../../utils/hooks';
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
import {useLastQueryExecutionSettings} from '../../../../utils/hooks/useLastQueryExecutionSettings';
import {YQL_LANGUAGE_ID} from '../../../../utils/monaco/constats';
import {YQL_LANGUAGE_ID} from '../../../../utils/monaco/constants';
import {QUERY_ACTIONS} from '../../../../utils/query';
import type {InitialPaneState} from '../../utils/paneVisibilityToggleHelpers';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MonacoEditor from 'react-monaco-editor';

import {cn} from '../../../../../../utils/cn';
import {S_EXPRESSION_LANGUAGE_ID} from '../../../../../../utils/monaco/constats';
import {S_EXPRESSION_LANGUAGE_ID} from '../../../../../../utils/monaco/constants';

import './Ast.scss';

Expand Down
5 changes: 3 additions & 2 deletions src/containers/Tenant/Query/SavedQueries/SavedQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {SavedQuery} from '../../../../types/store/query';
import {cn} from '../../../../utils/cn';
import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
import {useChangeInputWithConfirmation} from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation';
import {MAX_QUERY_HEIGHT, QUERY_TABLE_SETTINGS} from '../../utils/constants';
import {QUERY_TABLE_SETTINGS} from '../../utils/constants';
import i18n from '../i18n';
import {useSavedQueries} from '../utils/useSavedQueries';

Expand Down Expand Up @@ -125,7 +125,7 @@ export const SavedQueries = ({changeUserInput}: SavedQueriesProps) => {
render: ({row: query}) => (
<div className={b('query')}>
<div className={b('query-body')}>
<TruncatedQuery value={query.body} maxQueryHeight={MAX_QUERY_HEIGHT} />
<TruncatedQuery value={query.body} />
</div>
<span className={b('controls')}>
<Button view="flat-secondary">
Expand All @@ -139,6 +139,7 @@ export const SavedQueries = ({changeUserInput}: SavedQueriesProps) => {
),
sortable: false,
resizeMinWidth: 650,
width: 650,
},
];

Expand Down
2 changes: 0 additions & 2 deletions src/containers/Tenant/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type {Settings} from '@gravity-ui/react-data-table';

import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';

export const MAX_QUERY_HEIGHT = 6;

export const QUERY_TABLE_SETTINGS: Settings = {
...DEFAULT_TABLE_SETTINGS,
dynamicRenderType: 'variable',
Expand Down
4 changes: 4 additions & 0 deletions src/utils/monaco/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {LANGUAGE_ID} from 'monaco-yql-languages/build/yql/yql.contribution';

export const S_EXPRESSION_LANGUAGE_ID = 's-expression';
export const YQL_LANGUAGE_ID = LANGUAGE_ID;
2 changes: 0 additions & 2 deletions src/utils/monaco/constats.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tests/suites/tenant/queryHistory/queryHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.describe('Query History', () => {

// Check if the query appears in the history
const historyTable = page.locator('.ydb-queries-history table');
await expect(historyTable.locator(`text="${testQuery}"`)).toBeVisible({
await expect(historyTable.locator('.sql-highlighter', {hasText: testQuery})).toBeVisible({
timeout: VISIBILITY_TIMEOUT,
});
});
Expand Down Expand Up @@ -85,6 +85,6 @@ test.describe('Query History', () => {

// Check if the query appears in the history
const historyTable = page.locator('.ydb-queries-history table');
await expect(historyTable.locator(`text="${testQuery}"`)).toBeVisible();
await expect(historyTable.locator('.sql-highlighter', {hasText: testQuery})).toBeVisible();
});
});
Loading