Skip to content

Commit

Permalink
fix: Double clicking a file causes the loader to flash incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrunyon committed Mar 30, 2023
1 parent f1f3abf commit 6c3b509
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
53 changes: 35 additions & 18 deletions packages/dashboard-core-plugins/src/ConsolePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useListener,
} from '@deephaven/dashboard';
import { FileUtils } from '@deephaven/file-explorer';
import { CloseOptions } from '@deephaven/golden-layout';
import { CloseOptions, isComponent } from '@deephaven/golden-layout';
import Log from '@deephaven/log';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useDispatch } from 'react-redux';
Expand Down Expand Up @@ -168,7 +168,7 @@ export function ConsolePlugin(
if (createIfNecessary as boolean) {
return shortid.generate();
}
return null;
return undefined;
},
[openFileMap, previewFileMap]
);
Expand Down Expand Up @@ -463,31 +463,46 @@ export function ConsolePlugin(
return;
}

const [previewTabId] = Array.from(previewFileMap.values());
let panelId = null;
let stack = null;
// By this point, the user has double clicked the panel

const [previewTabName] = Array.from(previewFileMap.keys());
const previewTabId = previewFileMap.get(previewTabName);
let panelId: string | undefined;
if (previewTabId != null) {
panelId = previewTabId;
stack = LayoutUtils.getStackForConfig(layout.root, {

const stack = LayoutUtils.getStackForConfig(layout.root, {
component: NotebookPanel.COMPONENT,
id: panelId,
});
}
if (stack == null) {

const item = LayoutUtils.getContentItemInStack(stack, {
component: NotebookPanel.COMPONENT,
id: previewTabId,
});
if (item && isComponent(item)) {
item.container.emit(NotebookEvent.PROMOTE_FROM_PREVIEW);
deletePreviewFileMapEntry(previewTabName);
addOpenFileMapEntry(previewTabName, previewTabId);
}
} else {
panelId = getPanelIdForFileMetadata(fileMetadata);
stack = LayoutUtils.getStackForComponentTypes(layout.root, [
const stack = LayoutUtils.getStackForComponentTypes(layout.root, [
NotebookPanel.COMPONENT,
]);

const config = makeConfig({
id: panelId,
settings,
fileMetadata,
session,
sessionLanguage,
isPreview: !shouldFocus,
});

LayoutUtils.openComponentInStack(stack, config);
}
const config = makeConfig({
id: panelId,
settings,
fileMetadata,
session,
sessionLanguage,
isPreview: !shouldFocus,
});
LayoutUtils.openComponentInStack(stack, config);

if (shouldFocus) {
// Focus the tab we just opened if we're supposed to
focusPanelById(panelId);
Expand All @@ -502,6 +517,8 @@ export function ConsolePlugin(
layout.root,
makeConfig,
previewFileMap,
deletePreviewFileMapEntry,
addOpenFileMapEntry,
]
);

Expand Down
2 changes: 2 additions & 0 deletions packages/dashboard-core-plugins/src/events/NotebookEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class NotebookEvent {
static SEND_TO_NOTEBOOK = 'NotebookEvent.sendToNotebook';

static UNREGISTER_FILE = 'NotebookEvent.unregisterFile';

static PROMOTE_FROM_PREVIEW = 'NotebookEvent.promoteFromPreview';
}

export default NotebookEvent;
13 changes: 13 additions & 0 deletions packages/dashboard-core-plugins/src/panels/NotebookPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
this.handleTabBlur = this.handleTabBlur.bind(this);
this.handleTransformLinkUri = this.handleTransformLinkUri.bind(this);
this.handleOverwrite = this.handleOverwrite.bind(this);
this.handlePreviewPromotion = this.handlePreviewPromotion.bind(this);
this.getDropdownOverflowActions = this.getDropdownOverflowActions.bind(
this
);
Expand Down Expand Up @@ -287,6 +288,10 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
if (tab != null) this.initTab(tab);
this.initNotebookContent();
glEventHub.on(NotebookEvent.RENAME_FILE, this.handleRenameFile);
glContainer.on(
NotebookEvent.PROMOTE_FROM_PREVIEW,
this.handlePreviewPromotion
);
glContainer.on('tabClicked', this.handlePanelTabClick);
}

Expand Down Expand Up @@ -320,6 +325,10 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {

const { fileMetadata, isPreview } = this.state;
glEventHub.off(NotebookEvent.RENAME_FILE, this.handleRenameFile);
glContainer.off(
NotebookEvent.PROMOTE_FROM_PREVIEW,
this.handlePreviewPromotion
);
glContainer.off('tabClicked', this.handlePanelTabClick);
glEventHub.emit(NotebookEvent.UNREGISTER_FILE, fileMetadata, isPreview);
}
Expand Down Expand Up @@ -513,6 +522,10 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
}
}

handlePreviewPromotion() {
this.removePreviewStatus();
}

getSettings = memoize(
(
initialSettings: editor.IStandaloneEditorConstructionOptions,
Expand Down

0 comments on commit 6c3b509

Please sign in to comment.