bito-code-review[bot] commented on code in PR #39460:
URL: https://github.com/apache/superset/pull/39460#discussion_r3416860064
##########
superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx:
##########
@@ -16,51 +16,51 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { PureComponent } from 'react';
+import { useCallback, useEffect } from 'react';
import { HeaderProps } from '../Header/types';
type UndoRedoKeyListenersProps = {
onUndo: HeaderProps['onUndo'];
onRedo: HeaderProps['onRedo'];
};
-class UndoRedoKeyListeners extends PureComponent<UndoRedoKeyListenersProps> {
- constructor(props: UndoRedoKeyListenersProps) {
- super(props);
- this.handleKeydown = this.handleKeydown.bind(this);
- }
+function UndoRedoKeyListeners({ onUndo, onRedo }: UndoRedoKeyListenersProps) {
+ const handleKeydown = useCallback(
+ (event: KeyboardEvent) => {
+ const controlOrCommand = event.ctrlKey || event.metaKey;
+ if (controlOrCommand) {
+ const key = event.key.toLowerCase();
+ // Fall back to keyCode (90 = Z, 89 = Y) so undo/redo still work on
+ // non-Latin keyboard layouts where event.key is a different glyph.
+ const isZ = key === 'z' || event.keyCode === 90;
+ const isY = key === 'y' || event.keyCode === 89;
+ const isUndo = isZ && !event.shiftKey;
+ const isRedo = isY || (isZ && event.shiftKey);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Use event.code instead of deprecated keyCode</b></div>
<div id="fix">
Replace deprecated `event.keyCode === 90`/`89` fallbacks with `event.code
=== 'KeyZ'`/`'KeyY'` for layout-independent key detection. Also update the
`fireEvent.keyDown` calls in UndoRedoKeyListeners.test.tsx at lines 65 and 75
to include `code: 'KeyZ'` and `code: 'KeyY'` respectively.
</div>
</div>
<small><i>Code Review Run #5f0b04</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]