Skip to content

Commit 34f3b7b

Browse files
mistercrunchclaude
authored andcommitted
fix(CodeSyntaxHighlighter): address review feedback — i18n, stopPropagation, timeout cleanup, test fixes
- Wrap copy button titles in t() for i18n - Add e.stopPropagation() to copy button onClick to prevent bubbling - Clear existing timeout before setting new one in handleCopy - Remove unused getByRole destructuring from two HighlightedSql tests - Add Source SQL assertion to LIMIT tab test Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 4273e3c commit 34f3b7b

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎superset-frontend/packages/superset-ui-core/src/components/CodeSyntaxHighlighter/index.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import SyntaxHighlighterBase from 'react-syntax-highlighter/dist/cjs/light';
2121
import github from 'react-syntax-highlighter/dist/cjs/styles/hljs/github';
2222
import tomorrow from 'react-syntax-highlighter/dist/cjs/styles/hljs/tomorrow-night';
2323
import { css, isThemeDark, useTheme } from '@apache-superset/core/theme';
24+
import { t } from '@apache-superset/core/translation';
2425
import copyTextToClipboard from '../../utils/copy';
2526
import { Icons } from '../Icons';
2627

@@ -108,6 +109,7 @@ export const CodeSyntaxHighlighter: React.FC<CodeSyntaxHighlighterProps> = ({
108109

109110
const handleCopy = useCallback(() => {
110111
copyTextToClipboard(() => Promise.resolve(children)).then(() => {
112+
if (copyTimeoutRef.current) clearTimeout(copyTimeoutRef.current);
111113
setCopied(true);
112114
copyTimeoutRef.current = setTimeout(() => setCopied(false), 1500);
113115
});
@@ -127,8 +129,11 @@ export const CodeSyntaxHighlighter: React.FC<CodeSyntaxHighlighterProps> = ({
127129
const copyButton = showCopyButton && (
128130
<button
129131
type="button"
130-
onClick={handleCopy}
131-
title={copied ? 'Copied!' : 'Copy to clipboard'}
132+
onClick={(e: React.MouseEvent) => {
133+
e.stopPropagation();
134+
handleCopy();
135+
}}
136+
title={copied ? t('Copied!') : t('Copy to clipboard')}
132137
css={css`
133138
position: absolute;
134139
top: ${theme.sizeUnit}px;

‎superset-frontend/src/SqlLab/components/HighlightedSql/HighlightedSql.test.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test('renders a ModalTrigger component with shrink prop and maxWidth prop set to
3737
expect(getByTestId('span-modal-trigger')).toBeInTheDocument();
3838
});
3939
test('renders single SQL block with no tabs when rawSql equals sql', () => {
40-
const { getByRole, queryByRole, getByTestId, queryByText } = render(
40+
const { queryByRole, getByTestId, queryByText } = render(
4141
<HighlightedSql sql={sql} rawSql={sql} shrink maxWidth={5} />,
4242
);
4343
expect(queryByRole('dialog')).not.toBeInTheDocument();
@@ -48,7 +48,7 @@ test('renders single SQL block with no tabs when rawSql equals sql', () => {
4848
});
4949

5050
test('renders tabs when rawSql differs from sql', () => {
51-
const { getByRole, queryByRole, getByTestId, getByText } = render(
51+
const { queryByRole, getByTestId, getByText } = render(
5252
<HighlightedSql sql={sql} rawSql="SELECT * FROM foo" shrink maxWidth={5} />,
5353
);
5454
expect(queryByRole('dialog')).not.toBeInTheDocument();
@@ -59,7 +59,7 @@ test('renders tabs when rawSql differs from sql', () => {
5959
});
6060

6161
test('renders tabs when rawSql has an added LIMIT', () => {
62-
const { getByRole, queryByRole, getByTestId, getByText } = render(
62+
const { queryByRole, getByTestId, getByText } = render(
6363
<HighlightedSql
6464
sql={sql}
6565
rawSql={`${sql} LIMIT 1000`}
@@ -71,4 +71,5 @@ test('renders tabs when rawSql has an added LIMIT', () => {
7171
fireEvent.click(getByTestId('span-modal-trigger'));
7272
expect(queryByRole('dialog')).toBeInTheDocument();
7373
expect(getByText('Executed SQL')).toBeInTheDocument();
74+
expect(getByText('Source SQL')).toBeInTheDocument();
7475
});

0 commit comments

Comments
 (0)