Skip to content

Commit

Permalink
feat: Tables that have names starting with underscore do not auto-lau…
Browse files Browse the repository at this point in the history
…nch from console (#1656)

- Creating a table with a name that begins with an underscore will not
open it regardless of whether "Auto Launch Panels" is checked
  - Closes #1549
- Fixes a bug where tables will not update if its variable is reassigned
while "Auto Launch Panels" is unchecked
  - Closes #1410

### Testing Instructions:

1. Run the following code with the "Auto Launch Panels" option checked:
   ```py
   from deephaven import empty_table
 
   t = empty_table(10).update("x=i")
   _t = empty_table(10).update("x=i")
   ```
2. Table `t` should open automatically but table `_t` should remain
closed
3. Clicking on the button for `_t` should open it normally
4. Run `_t = empty_table(10).update("x=i+10")`. This should update the
values in `_t` if it is open
   - Nothing should happen if `_t` is closed.

BREAKING CHANGE: Tables assigned to variable beginning with "_" will not
open automatically even if "Auto Launch Panels" is checked.
  • Loading branch information
georgecwan authored Nov 30, 2023
1 parent c0cc966 commit 21131fe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
18 changes: 15 additions & 3 deletions packages/console/src/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ interface ConsoleProps {
statusBarChildren: ReactNode;
settings: Partial<Settings>;
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;
Expand Down Expand Up @@ -471,14 +478,19 @@ export class Console extends PureComponent<ConsoleProps, ConsoleState> {
}, 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('_'))
)
);
}

Expand Down
34 changes: 29 additions & 5 deletions packages/dashboard-core-plugins/src/panels/ConsolePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -84,6 +89,8 @@ export class ConsolePanel extends PureComponent<

static TITLE = 'Console';

static contextType = LayoutManagerContext;

constructor(props: ConsolePanelProps) {
super(props);

Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 21131fe

Please sign in to comment.