mirror of
https://github.com/apache/superset.git
synced 2026-05-21 15:55:10 +00:00
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.
This commit is contained in:
@@ -260,6 +260,13 @@ function SliceAdder({
|
||||
[fetchSlices, searchUpdated, sortBy, userIdForFetch],
|
||||
);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
handleChange.cancel();
|
||||
},
|
||||
[handleChange],
|
||||
);
|
||||
|
||||
const handleSelect = useCallback(
|
||||
(newSortBy: keyof Slice) => {
|
||||
setSortBy(newSortBy);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user