Skip to content

Commit f925ba7

Browse files
committed
feat: queries tab top design
1 parent 74355a4 commit f925ba7

File tree

5 files changed

+88
-13
lines changed

5 files changed

+88
-13
lines changed

src/components/ConnectToDB/ConnectToDBDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function ConnectToDBDialog({open, onClose, database, endpoint}: ConnectToDBDialo
5656
language={activeTab}
5757
text={snippet}
5858
transparentBackground={false}
59-
withCopy
59+
withClipboardButton={{alwaysVisible: true}}
6060
/>
6161
</div>
6262
{docsLink ? (

src/components/SyntaxHighlighter/YDBSyntaxHighlighter.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,17 @@
1616
position: absolute;
1717
top: 13px;
1818
right: 14px;
19+
20+
opacity: 0;
21+
22+
pointer-events: all;
23+
&_visible {
24+
opacity: 1;
25+
}
26+
}
27+
28+
.data-table__row:hover &__copy,
29+
.ydb-paginated-table__row:hover &__copy {
30+
opacity: 1;
1931
}
2032
}

src/components/SyntaxHighlighter/YDBSyntaxHighlighter.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,28 @@ async function registerLanguage(lang: Language) {
2323
}
2424
}
2525

26+
interface ClipboardButtonOptions {
27+
alwaysVisible?: boolean;
28+
copyText?: string;
29+
withLabel?: boolean;
30+
}
31+
32+
export type WithClipboardButtonProp = ClipboardButtonOptions | boolean;
33+
2634
type YDBSyntaxHighlighterProps = {
2735
text: string;
2836
language: Language;
2937
className?: string;
3038
transparentBackground?: boolean;
31-
withCopy?: boolean;
39+
withClipboardButton?: WithClipboardButtonProp;
3240
};
3341

3442
export function YDBSyntaxHighlighter({
3543
text,
3644
language,
3745
className,
3846
transparentBackground = true,
39-
withCopy,
47+
withClipboardButton,
4048
}: YDBSyntaxHighlighterProps) {
4149
const [highlighterKey, setHighlighterKey] = React.useState('');
4250

@@ -51,16 +59,27 @@ export function YDBSyntaxHighlighter({
5159
}, [language]);
5260

5361
const renderCopyButton = () => {
54-
if (withCopy) {
62+
if (withClipboardButton) {
5563
return (
56-
<div className={b('sticky-container')}>
64+
<div className={b('sticky-container')} onClick={(e) => e.stopPropagation()}>
5765
<ClipboardButton
5866
view="flat-secondary"
5967
size="s"
60-
className={b('copy')}
61-
text={text}
68+
className={b('copy', {
69+
visible:
70+
typeof withClipboardButton === 'object' &&
71+
withClipboardButton.alwaysVisible,
72+
})}
73+
text={
74+
(typeof withClipboardButton === 'object' &&
75+
withClipboardButton.copyText) ||
76+
text
77+
}
6278
>
63-
{i18n('copy')}
79+
{typeof withClipboardButton === 'object' &&
80+
withClipboardButton.withLabel === false
81+
? null
82+
: i18n('copy')}
6483
</ClipboardButton>
6584
</div>
6685
);

src/components/TruncatedQuery/TruncatedQuery.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ const b = cn('kv-truncated-query');
1010
interface TruncatedQueryProps {
1111
value?: string;
1212
maxQueryHeight?: number;
13+
hasClipboardButton?: boolean;
14+
clipboardButtonAlwaysVisible?: boolean;
1315
}
1416

15-
export const TruncatedQuery = ({value = '', maxQueryHeight = 6}: TruncatedQueryProps) => {
17+
export const TruncatedQuery = ({
18+
value = '',
19+
maxQueryHeight = 6,
20+
hasClipboardButton,
21+
clipboardButtonAlwaysVisible,
22+
}: TruncatedQueryProps) => {
1623
const lines = value.split('\n');
1724
const truncated = lines.length > maxQueryHeight;
1825

@@ -22,10 +29,37 @@ export const TruncatedQuery = ({value = '', maxQueryHeight = 6}: TruncatedQueryP
2229
'\n...\nThe request was truncated. Click on the line to show the full query on the query tab';
2330
return (
2431
<React.Fragment>
25-
<YDBSyntaxHighlighter language="yql" className={b()} text={content} />
32+
<YDBSyntaxHighlighter
33+
language="yql"
34+
className={b()}
35+
text={content}
36+
withClipboardButton={
37+
hasClipboardButton
38+
? {
39+
alwaysVisible: clipboardButtonAlwaysVisible,
40+
copyText: value,
41+
withLabel: false,
42+
}
43+
: false
44+
}
45+
/>
2646
<span className={b('message', {color: 'secondary'})}>{message}</span>
2747
</React.Fragment>
2848
);
2949
}
30-
return <YDBSyntaxHighlighter language="yql" text={value} />;
50+
return (
51+
<YDBSyntaxHighlighter
52+
language="yql"
53+
text={value}
54+
withClipboardButton={
55+
hasClipboardButton
56+
? {
57+
alwaysVisible: clipboardButtonAlwaysVisible,
58+
copyText: value,
59+
withLabel: false,
60+
}
61+
: false
62+
}
63+
/>
64+
);
3165
};

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ const queryTextColumn: Column<KeyValueRow> = {
3636
sortAccessor: (row) => Number(row.CPUTimeUs),
3737
render: ({row}) => (
3838
<div className={b('query')}>
39-
<TruncatedQuery value={row.QueryText?.toString()} maxQueryHeight={MAX_QUERY_HEIGHT} />
39+
<TruncatedQuery
40+
value={row.QueryText?.toString()}
41+
maxQueryHeight={MAX_QUERY_HEIGHT}
42+
hasClipboardButton
43+
/>
4044
</div>
4145
),
4246
sortable: false,
@@ -81,7 +85,13 @@ const oneLineQueryTextColumn: Column<KeyValueRow> = {
8185
name: TOP_QUERIES_COLUMNS_IDS.OneLineQueryText,
8286
header: TOP_QUERIES_COLUMNS_TITLES.OneLineQueryText,
8387
render: ({row}) => (
84-
<YDBSyntaxHighlighter language="yql" text={row.QueryText?.toString() || ''} />
88+
<YDBSyntaxHighlighter
89+
language="yql"
90+
text={row.QueryText?.toString() || ''}
91+
withClipboardButton={{
92+
withLabel: false,
93+
}}
94+
/>
8595
),
8696
sortable: false,
8797
width: 500,

0 commit comments

Comments
 (0)