From ec2d3307fdecbc3c1bc3cbec02aad41054da526f Mon Sep 17 00:00:00 2001 From: Enzo Martellucci <52219496+EnxDev@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:53:16 +0200 Subject: [PATCH] refactor: Migrate UndoRedoKeyListeners to typescript (#30654) --- .../{index.jsx => index.tsx} | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) rename superset-frontend/src/dashboard/components/UndoRedoKeyListeners/{index.jsx => index.tsx} (75%) diff --git a/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.jsx b/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx similarity index 75% rename from superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.jsx rename to superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx index c8bff40366d06..89dd62694ed51 100644 --- a/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.jsx +++ b/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx @@ -17,15 +17,15 @@ * under the License. */ import { PureComponent } from 'react'; -import PropTypes from 'prop-types'; +import { HeaderProps } from '../Header/types'; -const propTypes = { - onUndo: PropTypes.func.isRequired, - onRedo: PropTypes.func.isRequired, +type UndoRedoKeyListenersProps = { + onUndo: HeaderProps['onUndo']; + onRedo: HeaderProps['onRedo']; }; -class UndoRedoKeyListeners extends PureComponent { - constructor(props) { +class UndoRedoKeyListeners extends PureComponent { + constructor(props: UndoRedoKeyListenersProps) { super(props); this.handleKeydown = this.handleKeydown.bind(this); } @@ -38,15 +38,17 @@ class UndoRedoKeyListeners extends PureComponent { document.removeEventListener('keydown', this.handleKeydown); } - handleKeydown(event) { + handleKeydown(event: KeyboardEvent) { const controlOrCommand = event.ctrlKey || event.metaKey; if (controlOrCommand) { const isZChar = event.key === 'z' || event.keyCode === 90; const isYChar = event.key === 'y' || event.keyCode === 89; - const isEditingMarkdown = - document && document.querySelector('.dashboard-markdown--editing'); - const isEditingTitle = - document && document.querySelector('.editable-title--editing'); + const isEditingMarkdown = document?.querySelector( + '.dashboard-markdown--editing', + ); + const isEditingTitle = document?.querySelector( + '.editable-title--editing', + ); if (!isEditingMarkdown && !isEditingTitle && (isZChar || isYChar)) { event.preventDefault(); @@ -61,6 +63,4 @@ class UndoRedoKeyListeners extends PureComponent { } } -UndoRedoKeyListeners.propTypes = propTypes; - export default UndoRedoKeyListeners;