TimeRange: Additional keyboard shortcut t = to complement t + for zoom in (#115022)

feat(time-range): additional keyboard shortcut "t =" for zoom in
This commit is contained in:
Jesse David Peterson
2025-12-09 14:35:43 -04:00
committed by GitHub
parent 4b999cd943
commit 1013d74f13
3 changed files with 42 additions and 0 deletions
@@ -236,6 +236,10 @@ export class KeybindingSrv {
appEvents.publish(new ZoomOutEvent({ scale: 0.5, updateUrl }));
});
this.bind('t =', () => {
appEvents.publish(new ZoomOutEvent({ scale: 0.5, updateUrl }));
});
this.bind('t -', () => {
appEvents.publish(new ZoomOutEvent({ scale: 2, updateUrl }));
});
@@ -269,6 +269,13 @@ describe('setupKeyboardShortcuts', () => {
expect(tPlusBinding).toBeDefined();
});
it('should setup t = zoom in shortcut', () => {
setupKeyboardShortcuts(mockScene);
const tEqualsBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't =');
expect(tEqualsBinding).toBeDefined();
});
it('should setup t - zoom out shortcut with keypress type', () => {
setupKeyboardShortcuts(mockScene);
@@ -302,9 +309,11 @@ describe('setupKeyboardShortcuts', () => {
setupKeyboardShortcuts(mockScene);
const tPlusBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't +');
const tEqualsBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't =');
const tMinusBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't -');
expect(tPlusBinding).toBeUndefined();
expect(tEqualsBinding).toBeUndefined();
expect(tMinusBinding).toBeUndefined();
});
});
@@ -364,6 +373,28 @@ describe('setupKeyboardShortcuts', () => {
expect(newSpan).toBe(3 * 60 * 60 * 1000); // 3 hours in milliseconds
});
it('should zoom in (scale 0.5) when t = is pressed', () => {
setupKeyboardShortcuts(mockScene);
const tEqualsBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't =');
const handler = tEqualsBinding![0].onTrigger;
handler();
// Scale 0.5 should result in 3 hour span (half of 6)
expect(mockTimeRange.onTimeRangeChange).toHaveBeenCalledWith(
expect.objectContaining({
from: expect.any(Object),
to: expect.any(Object),
raw: expect.any(Object),
})
);
const call = mockTimeRange.onTimeRangeChange.mock.calls[0][0];
const newSpan = call.to.valueOf() - call.from.valueOf();
expect(newSpan).toBe(3 * 60 * 60 * 1000); // 3 hours in milliseconds
});
it('should keep center point when zooming in', () => {
setupKeyboardShortcuts(mockScene);
@@ -138,6 +138,13 @@ export function setupKeyboardShortcuts(scene: DashboardScene) {
},
});
keybindings.addBinding({
key: 't =',
onTrigger: () => {
handleZoom(scene, 0.5);
},
});
keybindings.addBinding({
key: 't -',
type: 'keypress', // NOTE: Because some browsers/OS identify minus symbol differently.