Skip to content

Commit 6e1e701

Browse files
authored
feat(Preview): add rows count and truncated flag (#1715)
1 parent eba72a0 commit 6e1e701

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/containers/Tenant/Query/Preview/Preview.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
@use '../../../../styles/mixins.scss';
1+
@import '../../../../styles/mixins.scss';
22

33
.kv-preview {
44
height: 100%;
5-
@include mixins.flex-container();
6-
@include mixins.query-data-table();
7-
5+
@include flex-container();
6+
@include query-data-table();
87
&__header {
98
position: sticky;
109
top: 0;
1110

1211
display: flex;
12+
flex-shrink: 0;
1313
justify-content: space-between;
1414
align-items: center;
1515

@@ -22,17 +22,18 @@
2222

2323
&__title {
2424
display: flex;
25+
gap: var(--g-spacing-1);
2526
}
2627

2728
&__table-name {
28-
margin-left: 4px;
29+
margin-left: var(--g-spacing-1);
2930

3031
color: var(--g-color-text-complementary);
3132
}
3233

3334
&__controls-left {
3435
display: flex;
35-
gap: 5px;
36+
gap: var(--g-spacing-1);
3637
}
3738
&__message-container {
3839
padding: 15px 20px;

src/containers/Tenant/Query/Preview/Preview.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Xmark} from '@gravity-ui/icons';
2-
import {Button, Icon, Loader} from '@gravity-ui/uikit';
2+
import {Button, Icon, Loader, Text} from '@gravity-ui/uikit';
33

44
import EnableFullscreenButton from '../../../../components/EnableFullscreenButton/EnableFullscreenButton';
55
import Fullscreen from '../../../../components/Fullscreen/Fullscreen';
@@ -28,9 +28,14 @@ export const Preview = ({database, path, type}: PreviewProps) => {
2828

2929
const isPreviewAvailable = isTableType(type);
3030

31-
const query = `select * from \`${path}\` limit 32`;
31+
const query = `select * from \`${path}\` limit 101`;
3232
const {currentData, isFetching, error} = previewApi.useSendQueryQuery(
33-
{database, query, action: isExternalTableType(type) ? 'execute-query' : 'execute-scan'},
33+
{
34+
database,
35+
query,
36+
action: isExternalTableType(type) ? 'execute-query' : 'execute-scan',
37+
limitRows: 100,
38+
},
3439
{
3540
skip: !isPreviewAvailable,
3641
refetchOnMountOrArgChange: true,
@@ -47,7 +52,12 @@ export const Preview = ({database, path, type}: PreviewProps) => {
4752
return (
4853
<div className={b('header')}>
4954
<div className={b('title')}>
50-
{i18n('preview.title')} <div className={b('table-name')}>{path}</div>
55+
{i18n('preview.title')}
56+
<Text color="secondary" variant="body-2">
57+
{data.truncated ? `${i18n('preview.truncated')} ` : ''}(
58+
{data.result?.length ?? 0})
59+
</Text>
60+
<div className={b('table-name')}>{path}</div>
5161
</div>
5262
<div className={b('controls-left')}>
5363
<EnableFullscreenButton disabled={Boolean(error)} />

src/containers/Tenant/Query/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"preview.title": "Preview",
1818
"preview.not-available": "Preview is not available",
1919
"preview.close": "Close preview",
20+
"preview.truncated": "truncated",
2021

2122
"method-description.script": "For YQL-scripts combining DDL and DML.\nAPI call: schema.scripting",
2223
"method-description.scan": "Read-only queries, potentially reading a lot of data.\nAPI call: table.ExecuteScan",

src/store/reducers/preview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ interface SendQueryParams {
77
query?: string;
88
database?: string;
99
action?: ExecuteActions;
10+
limitRows?: number;
1011
}
1112

1213
export const previewApi = api.injectEndpoints({
1314
endpoints: (build) => ({
1415
sendQuery: build.query({
15-
queryFn: async ({query, database, action}: SendQueryParams, {signal}) => {
16+
queryFn: async ({query, database, action, limitRows}: SendQueryParams, {signal}) => {
1617
try {
1718
const response = await window.api.sendQuery(
18-
{query, database, action},
19+
{query, database, action, limit_rows: limitRows},
1920
{signal, withRetries: true},
2021
);
2122

0 commit comments

Comments
 (0)