Skip to content

Commit 5b572c3

Browse files
authored
feat: DH-14431: Add shortcuts to cycle dashboards (#2470)
Part of DH-14431. Introduces keyboard navigation shortcuts to cycle between dashboards. `Cmd/Ctrl + .`: to cycle the active dashboard forward `Cmd/Ctrl + ,`: to cycle the active dashboard backward Changes: - Add shortcuts to cycle dashboard to `NavigationShortcuts.ts` - Registered the shortcuts as global context actions - Add `handleCycleDashboardForward` and `handleCycleDashboardBackward` to manage cycling
1 parent 395bfe7 commit 5b572c3

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

packages/code-studio/src/main/AppMainContainer.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ import {
104104
} from '../settings/SettingsUtils';
105105
import EmptyDashboard from './EmptyDashboard';
106106

107+
enum CycleDirection {
108+
Next,
109+
Previous,
110+
}
111+
107112
const log = Log.module('AppMainContainer');
108113

109114
type InputFileFormat =
@@ -268,6 +273,20 @@ export class AppMainContainer extends Component<
268273
shortcut: NAVIGATION_SHORTCUTS.CYCLE_TO_PREVIOUS_TAB,
269274
isGlobal: true,
270275
},
276+
{
277+
action: () => {
278+
this.handleCycleDashboardForward();
279+
},
280+
shortcut: NAVIGATION_SHORTCUTS.CYCLE_TO_NEXT_DASHBOARD,
281+
isGlobal: true,
282+
},
283+
{
284+
action: () => {
285+
this.handleCycleDashboardBackward();
286+
},
287+
shortcut: NAVIGATION_SHORTCUTS.CYCLE_TO_PREVIOUS_DASHBOARD,
288+
isGlobal: true,
289+
},
271290
{
272291
action: () => {
273292
this.sendReopenLast();
@@ -464,6 +483,35 @@ export class AppMainContainer extends Component<
464483
this.emitLayoutEvent(PanelEvent.REOPEN_LAST);
465484
}
466485

486+
cycleDashboard(direction: CycleDirection): void {
487+
const { tabs, activeTabKey } = this.state;
488+
489+
if (tabs.length <= 1) {
490+
return;
491+
}
492+
493+
const currentIndex = tabs.findIndex(tab => tab.key === activeTabKey);
494+
if (currentIndex === -1) {
495+
return;
496+
}
497+
498+
const targetIndex =
499+
direction === CycleDirection.Next
500+
? (currentIndex + 1) % tabs.length
501+
: (currentIndex - 1 + tabs.length) % tabs.length;
502+
503+
const targetTab = tabs[targetIndex];
504+
this.handleTabSelect(targetTab.key);
505+
}
506+
507+
handleCycleDashboardForward(): void {
508+
this.cycleDashboard(CycleDirection.Next);
509+
}
510+
511+
handleCycleDashboardBackward(): void {
512+
this.cycleDashboard(CycleDirection.Previous);
513+
}
514+
467515
getActiveEventHub(): EventHub {
468516
const { activeTabKey } = this.state;
469517
const layout = this.dashboardLayouts.get(activeTabKey);

packages/components/src/shortcuts/NavigationShortcuts.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ const NAVIGATION_SHORTCUTS = {
3030
macShortcut: [MODIFIER.CMD, MODIFIER.SHIFT, KEY.SEMICOLON],
3131
isEditable: true,
3232
}),
33+
CYCLE_TO_NEXT_DASHBOARD: ShortcutRegistry.createAndAdd({
34+
id: 'NAVIGATION.CYCLE_TO_NEXT_DASHBOARD',
35+
name: 'Cycle To Next Dashboard',
36+
shortcut: [MODIFIER.CTRL, KEY.PERIOD],
37+
macShortcut: [MODIFIER.CMD, KEY.PERIOD],
38+
isEditable: true,
39+
}),
40+
CYCLE_TO_PREVIOUS_DASHBOARD: ShortcutRegistry.createAndAdd({
41+
id: 'NAVIGATION.CYCLE_TO_PREVIOUS_DASHBOARD',
42+
name: 'Cycle To Previous Dashboard',
43+
shortcut: [MODIFIER.CTRL, KEY.COMMA],
44+
macShortcut: [MODIFIER.CMD, KEY.COMMA],
45+
isEditable: true,
46+
}),
3347
};
3448

3549
export default NAVIGATION_SHORTCUTS;

0 commit comments

Comments
 (0)