Skip to content

Commit

Permalink
feat(Preview): add rows count and truncated flag (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raubzeug authored Nov 27, 2024
1 parent eba72a0 commit 6e1e701
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/containers/Tenant/Query/Preview/Preview.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@use '../../../../styles/mixins.scss';
@import '../../../../styles/mixins.scss';

.kv-preview {
height: 100%;
@include mixins.flex-container();
@include mixins.query-data-table();

@include flex-container();
@include query-data-table();
&__header {
position: sticky;
top: 0;

display: flex;
flex-shrink: 0;
justify-content: space-between;
align-items: center;

Expand All @@ -22,17 +22,18 @@

&__title {
display: flex;
gap: var(--g-spacing-1);
}

&__table-name {
margin-left: 4px;
margin-left: var(--g-spacing-1);

color: var(--g-color-text-complementary);
}

&__controls-left {
display: flex;
gap: 5px;
gap: var(--g-spacing-1);
}
&__message-container {
padding: 15px 20px;
Expand Down
18 changes: 14 additions & 4 deletions src/containers/Tenant/Query/Preview/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Xmark} from '@gravity-ui/icons';
import {Button, Icon, Loader} from '@gravity-ui/uikit';
import {Button, Icon, Loader, Text} from '@gravity-ui/uikit';

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

const isPreviewAvailable = isTableType(type);

const query = `select * from \`${path}\` limit 32`;
const query = `select * from \`${path}\` limit 101`;
const {currentData, isFetching, error} = previewApi.useSendQueryQuery(
{database, query, action: isExternalTableType(type) ? 'execute-query' : 'execute-scan'},
{
database,
query,
action: isExternalTableType(type) ? 'execute-query' : 'execute-scan',
limitRows: 100,
},
{
skip: !isPreviewAvailable,
refetchOnMountOrArgChange: true,
Expand All @@ -47,7 +52,12 @@ export const Preview = ({database, path, type}: PreviewProps) => {
return (
<div className={b('header')}>
<div className={b('title')}>
{i18n('preview.title')} <div className={b('table-name')}>{path}</div>
{i18n('preview.title')}
<Text color="secondary" variant="body-2">
{data.truncated ? `${i18n('preview.truncated')} ` : ''}(
{data.result?.length ?? 0})
</Text>
<div className={b('table-name')}>{path}</div>
</div>
<div className={b('controls-left')}>
<EnableFullscreenButton disabled={Boolean(error)} />
Expand Down
1 change: 1 addition & 0 deletions src/containers/Tenant/Query/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"preview.title": "Preview",
"preview.not-available": "Preview is not available",
"preview.close": "Close preview",
"preview.truncated": "truncated",

"method-description.script": "For YQL-scripts combining DDL and DML.\nAPI call: schema.scripting",
"method-description.scan": "Read-only queries, potentially reading a lot of data.\nAPI call: table.ExecuteScan",
Expand Down
5 changes: 3 additions & 2 deletions src/store/reducers/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ interface SendQueryParams {
query?: string;
database?: string;
action?: ExecuteActions;
limitRows?: number;
}

export const previewApi = api.injectEndpoints({
endpoints: (build) => ({
sendQuery: build.query({
queryFn: async ({query, database, action}: SendQueryParams, {signal}) => {
queryFn: async ({query, database, action, limitRows}: SendQueryParams, {signal}) => {
try {
const response = await window.api.sendQuery(
{query, database, action},
{query, database, action, limit_rows: limitRows},
{signal, withRetries: true},
);

Expand Down

0 comments on commit 6e1e701

Please sign in to comment.