Skip to content

Commit

Permalink
feat: reopen closed tabs (#1912)
Browse files Browse the repository at this point in the history
- Add #1785 
  - Add keyboard shortcut (Alt+Shift+A) to reopen last closed tab
  • Loading branch information
wusteven815 committed Apr 11, 2024
1 parent 9b14ee0 commit c2e8714
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/code-studio/src/main/AppMainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ export class AppMainContainer extends Component<
shortcut: IRIS_GRID_SHORTCUTS.TABLE.CLEAR_ALL_FILTERS,
isGlobal: true,
},
{
action: () => {
this.sendReopenLast();
},
shortcut: GLOBAL_SHORTCUTS.REOPEN_CLOSED_PANEL,
isGlobal: true,
},
{
action: () => {
log.debug('Consume unhandled save shortcut');
Expand Down Expand Up @@ -402,6 +409,10 @@ export class AppMainContainer extends Component<
this.emitLayoutEvent(InputFilterEvent.CLEAR_ALL_FILTERS);
}

sendReopenLast(): void {
this.emitLayoutEvent(PanelEvent.REOPEN_LAST);
}

emitLayoutEvent(event: string, ...args: unknown[]): void {
const { activeTabKey } = this.state;
const layout = this.dashboardLayouts.get(activeTabKey);
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/shortcuts/GlobalShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const GLOBAL_SHORTCUTS = {
macShortcut: [MODIFIER.CMD, KEY.A],
isEditable: false,
}),
REOPEN_CLOSED_PANEL: ShortcutRegistry.createAndAdd({
id: 'GLOBAL.REOPEN_CLOSED_PANEL',
name: 'Re-open Closed Panel',
shortcut: [MODIFIER.ALT, MODIFIER.SHIFT, KEY.T],
macShortcut: [MODIFIER.OPTION, MODIFIER.SHIFT, KEY.T],
isEditable: true,
}),
LINKER: ShortcutRegistry.createAndAdd({
id: 'GLOBAL.LINKER',
name: 'Linker',
Expand Down
3 changes: 3 additions & 0 deletions packages/dashboard/src/PanelEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default Object.freeze({
// Panel was re-opened from a dehydrated state
REOPEN: 'PanelEvent.REOPEN',

// Reopen last closed panel
REOPEN_LAST: 'PanelEvent.REOPEN_LAST',

// Panel was deleted
DELETE: 'PanelEvent.DELETE',

Expand Down
8 changes: 8 additions & 0 deletions packages/dashboard/src/PanelManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class PanelManager {
// and PanelEvent.CLOSED for cleanup (delete links, add panel to closed panels list, etc)
this.handleUnmount = this.handleUnmount.bind(this);
this.handleReopen = this.handleReopen.bind(this);
this.handleReopenLast = this.handleReopenLast.bind(this);
this.handleDeleted = this.handleDeleted.bind(this);
this.handleClosed = this.handleClosed.bind(this);
this.handleControlClose = this.handleControlClose.bind(this);
Expand All @@ -106,6 +107,7 @@ class PanelManager {
eventHub.on(PanelEvent.MOUNT, this.handleMount);
eventHub.on(PanelEvent.UNMOUNT, this.handleUnmount);
eventHub.on(PanelEvent.REOPEN, this.handleReopen);
eventHub.on(PanelEvent.REOPEN_LAST, this.handleReopenLast);
eventHub.on(PanelEvent.DELETE, this.handleDeleted);
eventHub.on(PanelEvent.CLOSED, this.handleClosed);
eventHub.on(PanelEvent.CLOSE, this.handleControlClose);
Expand All @@ -118,6 +120,7 @@ class PanelManager {
eventHub.off(PanelEvent.MOUNT, this.handleMount);
eventHub.off(PanelEvent.UNMOUNT, this.handleUnmount);
eventHub.off(PanelEvent.REOPEN, this.handleReopen);
eventHub.off(PanelEvent.REOPEN_LAST, this.handleReopenLast);
eventHub.off(PanelEvent.DELETE, this.handleDeleted);
eventHub.off(PanelEvent.CLOSED, this.handleClosed);
eventHub.off(PanelEvent.CLOSE, this.handleControlClose);
Expand Down Expand Up @@ -291,6 +294,11 @@ class PanelManager {
LayoutUtils.openComponent({ root, config, replaceConfig });
}

handleReopenLast(): void {
if (this.closed.length === 0) return;
this.handleReopen(this.closed[this.closed.length - 1]);
}

handleDeleted(panelConfig: ClosedPanel): void {
log.debug2('Deleted:', panelConfig);

Expand Down

0 comments on commit c2e8714

Please sign in to comment.