Skip to content

Commit 2d4de51

Browse files
authored
feat(sqllab): Show sql in the current result (#24787)
1 parent a40e9a4 commit 2d4de51

File tree

3 files changed

+77
-15
lines changed

3 files changed

+77
-15
lines changed

superset-frontend/src/SqlLab/components/HighlightedSql/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import ModalTrigger from 'src/components/ModalTrigger';
2525

2626
SyntaxHighlighter.registerLanguage('sql', sql);
2727

28-
interface HighlightedSqlProps {
28+
export interface HighlightedSqlProps {
2929
sql: string;
3030
rawSql?: string;
3131
maxWidth?: number;

superset-frontend/src/SqlLab/components/ResultSet/index.tsx

+74-14
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ import {
2727
QueryState,
2828
styled,
2929
t,
30+
tn,
3031
useTheme,
3132
usePrevious,
33+
css,
34+
getNumberFormatter,
3235
} from '@superset-ui/core';
3336
import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace';
3437
import {
@@ -42,6 +45,9 @@ import { mountExploreUrl } from 'src/explore/exploreUtils';
4245
import { postFormData } from 'src/explore/exploreUtils/formData';
4346
import ProgressBar from 'src/components/ProgressBar';
4447
import Loading from 'src/components/Loading';
48+
import Card from 'src/components/Card';
49+
import Label from 'src/components/Label';
50+
import { Tooltip } from 'src/components/Tooltip';
4551
import FilterableTable from 'src/components/FilterableTable';
4652
import CopyToClipboard from 'src/components/CopyToClipboard';
4753
import { addDangerToast } from 'src/components/MessageToasts/actions';
@@ -55,6 +61,7 @@ import {
5561
reRunQuery,
5662
} from 'src/SqlLab/actions/sqlLab';
5763
import { URL_PARAMS } from 'src/constants';
64+
import Icons from 'src/components/Icons';
5865
import ExploreCtasResultsButton from '../ExploreCtasResultsButton';
5966
import ExploreResultsButton from '../ExploreResultsButton';
6067
import HighlightedSql from '../HighlightedSql';
@@ -76,6 +83,7 @@ export interface ResultSetProps {
7683
query: QueryResponse;
7784
search?: boolean;
7885
showSql?: boolean;
86+
showSqlInline?: boolean;
7987
visualize?: boolean;
8088
user: UserWithPermissionsAndRoles;
8189
defaultQueryLimit: number;
@@ -110,7 +118,7 @@ const MonospaceDiv = styled.div`
110118

111119
const ReturnedRows = styled.div`
112120
font-size: ${({ theme }) => theme.typography.sizes.s}px;
113-
line-height: ${({ theme }) => theme.gridUnit * 6}px;
121+
line-height: 1;
114122
`;
115123

116124
const ResultSetControls = styled.div`
@@ -124,10 +132,8 @@ const ResultSetButtons = styled.div`
124132
padding-right: ${({ theme }) => 2 * theme.gridUnit}px;
125133
`;
126134

127-
const LimitMessage = styled.span`
128-
color: ${({ theme }) => theme.colors.secondary.light1};
129-
margin-left: ${({ theme }) => theme.gridUnit * 2}px;
130-
`;
135+
const ROWS_CHIP_WIDTH = 100;
136+
const GAP = 8;
131137

132138
const ResultSet = ({
133139
cache = false,
@@ -138,6 +144,7 @@ const ResultSet = ({
138144
query,
139145
search = true,
140146
showSql = false,
147+
showSqlInline = false,
141148
visualize = true,
142149
user,
143150
defaultQueryLimit,
@@ -296,7 +303,7 @@ const ResultSet = ({
296303

297304
const renderRowsReturned = () => {
298305
const { results, rows, queryLimit, limitingFactor } = query;
299-
let limitMessage;
306+
let limitMessage = '';
300307
const limitReached = results?.displayLimitReached;
301308
const limit = queryLimit || results.query.limit;
302309
const isAdmin = !!user?.roles?.Admin;
@@ -339,7 +346,7 @@ const ResultSet = ({
339346
{ rows },
340347
);
341348
}
342-
349+
const formattedRowCount = getNumberFormatter()(rows);
343350
const rowsReturnedMessage = t('%(rows)d rows returned', {
344351
rows,
345352
});
@@ -349,10 +356,27 @@ const ResultSet = ({
349356
return (
350357
<ReturnedRows>
351358
{!limitReached && !shouldUseDefaultDropdownAlert && (
352-
<span title={tooltipText}>
353-
{rowsReturnedMessage}
354-
<LimitMessage>{limitMessage}</LimitMessage>
355-
</span>
359+
<Tooltip
360+
id="sqllab-rowcount-tooltip"
361+
title={tooltipText}
362+
placement="left"
363+
>
364+
<Label
365+
css={css`
366+
line-height: ${theme.typography.sizes.l}px;
367+
`}
368+
>
369+
{limitMessage && (
370+
<Icons.ExclamationCircleOutlined
371+
css={css`
372+
font-size: ${theme.typography.sizes.m}px;
373+
margin-right: ${theme.gridUnit}px;
374+
`}
375+
/>
376+
)}
377+
{tn('%s row', '%s rows', rows, formattedRowCount)}
378+
</Label>
379+
</Tooltip>
356380
)}
357381
{!limitReached && shouldUseDefaultDropdownAlert && (
358382
<div ref={calculateAlertRefHeight}>
@@ -413,7 +437,12 @@ const ResultSet = ({
413437
}
414438

415439
if (showSql) {
416-
sql = <HighlightedSql sql={query.sql} />;
440+
sql = (
441+
<HighlightedSql
442+
sql={query.sql}
443+
{...(showSqlInline && { maxLines: 1, maxWidth: 60 })}
444+
/>
445+
);
417446
}
418447

419448
if (query.state === QueryState.STOPPED) {
@@ -501,8 +530,39 @@ const ResultSet = ({
501530
return (
502531
<ResultContainer>
503532
{renderControls()}
504-
{renderRowsReturned()}
505-
{sql}
533+
{showSql && showSqlInline ? (
534+
<div
535+
css={css`
536+
display: flex;
537+
justify-content: space-between;
538+
gap: ${GAP}px;
539+
`}
540+
>
541+
<Card
542+
css={[
543+
css`
544+
height: 28px;
545+
width: calc(100% - ${ROWS_CHIP_WIDTH + GAP}px);
546+
code {
547+
width: 100%;
548+
overflow: hidden;
549+
white-space: nowrap !important;
550+
text-overflow: ellipsis;
551+
display: block;
552+
}
553+
`,
554+
]}
555+
>
556+
{sql}
557+
</Card>
558+
{renderRowsReturned()}
559+
</div>
560+
) : (
561+
<>
562+
{renderRowsReturned()}
563+
{sql}
564+
</>
565+
)}
506566
<FilterableTable
507567
data={data}
508568
orderedColumnKeys={results.columns.map(col => col.column_name)}

superset-frontend/src/SqlLab/components/SouthPane/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ const SouthPane = ({
189189
database={databases[latestQuery.dbId]}
190190
displayLimit={displayLimit}
191191
defaultQueryLimit={defaultQueryLimit}
192+
showSql
193+
showSqlInline
192194
/>
193195
);
194196
}

0 commit comments

Comments
 (0)