diff --git a/packages/console/src/Console.tsx b/packages/console/src/Console.tsx index 0edcf19086..538a9d99c7 100644 --- a/packages/console/src/Console.tsx +++ b/packages/console/src/Console.tsx @@ -60,7 +60,14 @@ interface ConsoleProps { statusBarChildren: ReactNode; settings: Partial; focusCommandHistory: () => void; - openObject: (object: VariableDefinition) => void; + + /** + * @param object The object to open + * @param forceOpen If true, always open the object. If false, only update existing panels + */ + openObject: (object: VariableDefinition, forceOpen?: boolean) => void; + + /** Closes all panels containing the object */ closeObject: (object: VariableDefinition) => void; session: IdeSession; language: string; @@ -471,14 +478,19 @@ export class Console extends PureComponent { }, Console.LOG_THROTTLE); openUpdatedItems(changes: VariableChanges): void { + log.debug('openUpdatedItems', changes); const { isAutoLaunchPanelsEnabled } = this.state; - if (changes == null || !isAutoLaunchPanelsEnabled) { + if (changes == null) { return; } const { openObject } = this.props; [...changes.created, ...changes.updated].forEach(object => - openObject(object) + openObject( + object, + isAutoLaunchPanelsEnabled && + (object.title === undefined || !object.title.startsWith('_')) + ) ); } diff --git a/packages/dashboard-core-plugins/src/panels/ConsolePanel.tsx b/packages/dashboard-core-plugins/src/panels/ConsolePanel.tsx index f0dd70f29e..15563d65b8 100644 --- a/packages/dashboard-core-plugins/src/panels/ConsolePanel.tsx +++ b/packages/dashboard-core-plugins/src/panels/ConsolePanel.tsx @@ -11,7 +11,12 @@ import { HeapUsage, ObjectIcon, } from '@deephaven/console'; -import { DashboardPanelProps, PanelEvent } from '@deephaven/dashboard'; +import { + DashboardPanelProps, + LayoutManagerContext, + LayoutUtils, + PanelEvent, +} from '@deephaven/dashboard'; import type { IdeSession, VariableDefinition } from '@deephaven/jsapi-types'; import { SessionWrapper } from '@deephaven/jsapi-utils'; import Log from '@deephaven/log'; @@ -84,6 +89,8 @@ export class ConsolePanel extends PureComponent< static TITLE = 'Console'; + static contextType = LayoutManagerContext; + constructor(props: ConsolePanelProps) { super(props); @@ -235,18 +242,35 @@ export class ConsolePanel extends PureComponent< this.updateDimensions(); } - handleOpenObject(object: VariableDefinition): void { + handleOpenObject(object: VariableDefinition, forceOpen = true): void { const { sessionWrapper } = this.props; const { session } = sessionWrapper; - this.openWidget(object, session); + const { root } = this.context; + const oldPanelId = + object.title != null ? this.getItemId(object.title, false) : null; + if ( + forceOpen || + (oldPanelId != null && + LayoutUtils.getStackForRoot( + root, + { id: oldPanelId }, + false, + false, + false + ) != null) + ) { + this.openWidget(object, session); + } } handleCloseObject(object: VariableDefinition): void { const { title } = object; if (title !== undefined) { const id = this.getItemId(title, false); - const { glEventHub } = this.props; - glEventHub.emit(PanelEvent.CLOSE, id); + if (id != null) { + const { glEventHub } = this.props; + glEventHub.emit(PanelEvent.CLOSE, id); + } } }