From ec14530574c6578a88fc10ebfc7b0ec8bf9ef9ad Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Sat, 18 Apr 2026 10:33:00 -0700 Subject: [PATCH] fix(dashboard): modernize UndoRedo shortcut + cancel SliceAdder debounce - UndoRedoKeyListeners now normalizes event.key and uses shiftKey so Ctrl/Cmd+Shift+Z triggers redo instead of undo. Drops deprecated event.keyCode checks. - SliceAdder cancels the debounced search handler on unmount to avoid post-unmount state updates and stray /api/v1/chart fetches. --- .../src/dashboard/components/SliceAdder.tsx | 7 +++++++ .../dashboard/components/UndoRedoKeyListeners/index.tsx | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/dashboard/components/SliceAdder.tsx b/superset-frontend/src/dashboard/components/SliceAdder.tsx index f6c176d9bf8..7475d005e00 100644 --- a/superset-frontend/src/dashboard/components/SliceAdder.tsx +++ b/superset-frontend/src/dashboard/components/SliceAdder.tsx @@ -260,6 +260,13 @@ function SliceAdder({ [fetchSlices, searchUpdated, sortBy, userIdForFetch], ); + useEffect( + () => () => { + handleChange.cancel(); + }, + [handleChange], + ); + const handleSelect = useCallback( (newSortBy: keyof Slice) => { setSortBy(newSortBy); diff --git a/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx b/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx index 7417dcdbf63..81b5f3127e3 100644 --- a/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx +++ b/superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx @@ -29,8 +29,9 @@ function UndoRedoKeyListeners({ onUndo, onRedo }: UndoRedoKeyListenersProps) { (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 key = event.key.toLowerCase(); + const isUndo = key === 'z' && !event.shiftKey; + const isRedo = key === 'y' || (key === 'z' && event.shiftKey); const isEditingMarkdown = document?.querySelector( '.dashboard-markdown--editing', ); @@ -38,9 +39,9 @@ function UndoRedoKeyListeners({ onUndo, onRedo }: UndoRedoKeyListenersProps) { '.editable-title--editing', ); - if (!isEditingMarkdown && !isEditingTitle && (isZChar || isYChar)) { + if (!isEditingMarkdown && !isEditingTitle && (isUndo || isRedo)) { event.preventDefault(); - const func = isZChar ? onUndo : onRedo; + const func = isUndo ? onUndo : onRedo; func(); } }