Skip to content

Commit 4870171

Browse files
authored
feat: Double click notebook tab to remove its preview status (#1190)
Something I noticed while working on #1189 is that we didn't support double clicking the tab to promote from preview to normal state like VSCode does. This PR lets you double click the tab of a notebook in preview to change it from preview state to normal state. Tested double clicking preview notebook, non-preview notebook, and opening other notebooks in preview after promoting via double click
1 parent 1a0ff8d commit 4870171

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

packages/dashboard-core-plugins/src/panels/NotebookPanel.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Wrapper for the Notebook for use in a golden layout container
2-
import React, { Component, MouseEvent, ReactElement } from 'react';
2+
import React, { Component, ReactElement } from 'react';
33
import ReactDOM from 'react-dom';
44
import memoize from 'memoize-one';
55
import { connect } from 'react-redux';
@@ -176,7 +176,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
176176
this.handleLinkClick = this.handleLinkClick.bind(this);
177177
this.handleLoadSuccess = this.handleLoadSuccess.bind(this);
178178
this.handleLoadError = this.handleLoadError.bind(this);
179-
this.handlePanelTabClick = this.handlePanelTabClick.bind(this);
179+
this.handleTabClick = this.handleTabClick.bind(this);
180180
this.handleRenameFile = this.handleRenameFile.bind(this);
181181
this.handleResize = this.handleResize.bind(this);
182182
this.handleRunCommand = this.handleRunCommand.bind(this);
@@ -283,7 +283,6 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
283283
if (tab != null) this.initTab(tab);
284284
this.initNotebookContent();
285285
glEventHub.on(NotebookEvent.RENAME_FILE, this.handleRenameFile);
286-
glContainer.on('tabClicked', this.handlePanelTabClick);
287286
}
288287

289288
componentDidUpdate(
@@ -312,11 +311,10 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
312311
this.debouncedSavePanelState.flush();
313312
this.pending.cancel();
314313

315-
const { glContainer, glEventHub } = this.props;
314+
const { glEventHub } = this.props;
316315

317316
const { fileMetadata, isPreview } = this.state;
318317
glEventHub.off(NotebookEvent.RENAME_FILE, this.handleRenameFile);
319-
glContainer.off('tabClicked', this.handlePanelTabClick);
320318
glEventHub.emit(NotebookEvent.UNREGISTER_FILE, fileMetadata, isPreview);
321319
}
322320

@@ -736,7 +734,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
736734
/**
737735
* @param event The click event from clicking on the link
738736
*/
739-
handleLinkClick(event: MouseEvent<HTMLAnchorElement>) {
737+
handleLinkClick(event: React.MouseEvent<HTMLAnchorElement>) {
740738
const { notebooksUrl, session, sessionLanguage } = this.props;
741739
const { href } = event.currentTarget;
742740
if (!href || !href.startsWith(notebooksUrl)) {
@@ -960,9 +958,12 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
960958
});
961959
}
962960

963-
handlePanelTabClick(): void {
964-
log.debug('handlePanelTabClick');
961+
handleTabClick(e: MouseEvent): void {
962+
log.debug('handle NotebookPanel tab click');
965963
this.focus();
964+
if (e.detail === 2) {
965+
this.removePreviewStatus();
966+
}
966967
}
967968

968969
/**
@@ -1173,6 +1174,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
11731174
onTab={this.handleTab}
11741175
onResize={this.handleResize}
11751176
onShow={this.handleShow}
1177+
onTabClicked={this.handleTabClick}
11761178
onTabFocus={this.handleTabFocus}
11771179
onTabBlur={this.handleTabBlur}
11781180
onSessionOpen={this.handleSessionOpened}

packages/dashboard-core-plugins/src/panels/Panel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface PanelProps {
4040
onFocus: FocusEventHandler<HTMLDivElement>;
4141
onBlur: FocusEventHandler<HTMLDivElement>;
4242
onTab: (tab: Tab) => void;
43-
onTabClicked: (...args: unknown[]) => void;
43+
onTabClicked: (e: MouseEvent) => void;
4444
onClearAllFilters: (...args: unknown[]) => void;
4545
onHide: (...args: unknown[]) => void;
4646
onResize: (...args: unknown[]) => void;
@@ -180,9 +180,9 @@ class Panel extends PureComponent<PanelProps, PanelState> {
180180
onTab(tab);
181181
}
182182

183-
handleTabClicked(...args: unknown[]): void {
183+
handleTabClicked(e: MouseEvent): void {
184184
const { onTabClicked } = this.props;
185-
onTabClicked(...args);
185+
onTabClicked(e);
186186
}
187187

188188
handleClearAllFilters(...args: unknown[]): void {

packages/golden-layout/src/controls/Tab.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ export default class Tab {
236236
isComponent(this.contentItem)
237237
) {
238238
this.header.parent.setActiveContentItem(this.contentItem);
239-
this.contentItem.container.emit('tabClicked');
240239
} else if (
241240
isComponent(this.contentItem) &&
242241
!this.contentItem.container._contentElement[0].contains(
@@ -246,10 +245,10 @@ export default class Tab {
246245
// if no focus inside put focus onto the container
247246
// so focusin always fires for tabclicks
248247
this.contentItem.container._contentElement.focus();
248+
}
249249

250-
// still emit tab clicked event, so panels can also
251-
// do it's own focus handling if desired
252-
this.contentItem.container.emit('tabClicked');
250+
if (isComponent(this.contentItem)) {
251+
this.contentItem.container.emit('tabClicked', event);
253252
}
254253

255254
// might have been called from the dropdown

0 commit comments

Comments
 (0)