Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions packages/dashboard-core-plugins/src/ConsoleEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { makeEventFunctions } from '@deephaven/golden-layout';
import { type dh } from '@deephaven/jsapi-types';
import { ConsoleEvent } from './events';

/**
* Represents a Core (Community) console session. Mirrors the
* `CommonConsoleSession` interface used in Enterprise (without the
* Enterprise-only `QueryInfo` field).
*/
export interface CoreConsoleSession {
language: string;
session: dh.IdeSession;
sessionId: string;
/** Function closing the console session and client connection */
close: () => void;
}

const sessionOpenedFns = makeEventFunctions<[session: CoreConsoleSession]>(
ConsoleEvent.SESSION_OPENED
);

/**
* Listen for session opened events
* @param eventEmitter The event emitter to listen on
* @param session The session that was opened
*/
export const listenForSessionOpened = sessionOpenedFns.listen;

/**
* Emit a session opened event
* @param eventEmitter The event emitter to emit the event on
* @param session The session that was opened
*/
export const emitSessionOpened = sessionOpenedFns.emit;

/**
* Use a session opened event listener
* @param eventEmitter The event emitter to listen on
* @param session The session that was opened
*/
export const useSessionOpenedListener = sessionOpenedFns.useListener;

const sessionClosedFns = makeEventFunctions<[session: dh.IdeSession]>(
ConsoleEvent.SESSION_CLOSED
);

/**
* Listen for session closed events
* @param eventEmitter The event emitter to listen on
* @param session The session that was closed
*/
export const listenForSessionClosed = sessionClosedFns.listen;

/**
* Emit a session closed event
* @param eventEmitter The event emitter to emit the event on
* @param session The session that was closed
*/
export const emitSessionClosed = sessionClosedFns.emit;

/**
* Use a session closed event listener
* @param eventEmitter The event emitter to listen on
* @param session The session that was closed
*/
export const useSessionClosedListener = sessionClosedFns.useListener;
1 change: 1 addition & 0 deletions packages/dashboard-core-plugins/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './useGridLinker';
export * from './useLoadTablePlugin';
export * from './useTablePlugin';

export * from './ConsoleEvents';
export * from './events';
export * from './panels';
export * from './redux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getCommandHistoryStorage, type RootState } from '@deephaven/redux';
import { assertNotNull, Pending } from '@deephaven/utils';
import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, NotebookEvent } from '../events';
import { type CoreConsoleSession } from '../ConsoleEvents';
import './CommandHistoryPanel.scss';
import Panel from './CorePanel';
import { getDashboardSessionWrapper } from '../redux';
Expand Down Expand Up @@ -110,10 +111,11 @@ class CommandHistoryPanel extends Component<
this.container.current?.restoreScrollPosition();
}

handleSessionOpened(
session: dh.IdeSession,
{ language, sessionId }: { language: string; sessionId: string }
): void {
handleSessionOpened({
session,
language,
sessionId,
}: CoreConsoleSession): void {
this.setState(
{
session,
Expand Down
37 changes: 23 additions & 14 deletions packages/dashboard-core-plugins/src/panels/CorePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import React, { PureComponent, type ReactElement } from 'react';
import { createXComponent } from '@deephaven/components';
import { type BasePanelProps, BasePanel } from '@deephaven/dashboard';
import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, InputFilterEvent } from '../events';
import {
type CoreConsoleSession,
listenForSessionClosed,
listenForSessionOpened,
} from '../ConsoleEvents';
import { InputFilterEvent } from '../events';

export type CorePanelProps = BasePanelProps & {
onClearAllFilters?: (...args: unknown[]) => void;
onSessionClose?: (session: dh.IdeSession) => void;
onSessionOpen?: (
session: dh.IdeSession,
{ language, sessionId }: { language: string; sessionId: string }
) => void;
onSessionOpen?: (session: CoreConsoleSession) => void;
};

/**
Expand All @@ -28,8 +30,14 @@ class CorePanel extends PureComponent<CorePanelProps> {
componentDidMount(): void {
const { glEventHub } = this.props;

glEventHub.on(ConsoleEvent.SESSION_CLOSED, this.handleSessionClosed);
glEventHub.on(ConsoleEvent.SESSION_OPENED, this.handleSessionOpened);
this.stopListenForSessionClosed = listenForSessionClosed(
glEventHub,
this.handleSessionClosed
);
this.stopListenForSessionOpened = listenForSessionOpened(
glEventHub,
this.handleSessionOpened
);
glEventHub.on(
InputFilterEvent.CLEAR_ALL_FILTERS,
this.handleClearAllFilters
Expand All @@ -39,14 +47,18 @@ class CorePanel extends PureComponent<CorePanelProps> {
componentWillUnmount(): void {
const { glEventHub } = this.props;

glEventHub.off(ConsoleEvent.SESSION_CLOSED, this.handleSessionClosed);
glEventHub.off(ConsoleEvent.SESSION_OPENED, this.handleSessionOpened);
this.stopListenForSessionClosed?.();
this.stopListenForSessionOpened?.();
glEventHub.off(
InputFilterEvent.CLEAR_ALL_FILTERS,
this.handleClearAllFilters
);
}

stopListenForSessionClosed?: () => void;

stopListenForSessionOpened?: () => void;

handleClearAllFilters(...args: unknown[]): void {
const { onClearAllFilters } = this.props;
onClearAllFilters?.(...args);
Expand All @@ -57,12 +69,9 @@ class CorePanel extends PureComponent<CorePanelProps> {
onSessionClose?.(session);
}

handleSessionOpened(
session: dh.IdeSession,
params: { language: string; sessionId: string }
): void {
handleSessionOpened(session: CoreConsoleSession): void {
const { onSessionOpen } = this.props;
onSessionOpen?.(session, params);
onSessionOpen?.(session);
}

render(): ReactElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { connect, type ConnectedProps } from 'react-redux';
import type { dh } from '@deephaven/jsapi-types';
import Panel from './CorePanel';
import { NotebookEvent } from '../events';
import { type CoreConsoleSession } from '../ConsoleEvents';
import './FileExplorerPanel.scss';
import { getDashboardSessionWrapper } from '../redux';

Expand Down Expand Up @@ -224,10 +225,7 @@ export class FileExplorerPanel extends React.Component<
glEventHub.emit(NotebookEvent.RENAME_FILE, oldName, newName);
}

handleSessionOpened(
session: dh.IdeSession,
{ language }: { language: string }
): void {
handleSessionOpened({ session, language }: CoreConsoleSession): void {
this.setState({
session,
language,
Expand Down
3 changes: 2 additions & 1 deletion packages/dashboard-core-plugins/src/panels/LogPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Log from '@deephaven/log';
import { type RootState } from '@deephaven/redux';
import './LogPanel.scss';
import Panel from './CorePanel';
import { type CoreConsoleSession } from '../ConsoleEvents';
import { getDashboardSessionWrapper } from '../redux';

const log = Log.module('LogPanel');
Expand Down Expand Up @@ -72,7 +73,7 @@ class LogPanel extends PureComponent<LogPanelProps, LogPanelState> {
}
}

handleSessionOpened(session: dh.IdeSession): void {
handleSessionOpened({ session }: CoreConsoleSession): void {
log.debug('Session opened', [session]);
this.setState({ session });
}
Expand Down
6 changes: 2 additions & 4 deletions packages/dashboard-core-plugins/src/panels/NotebookPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { assertNotNull, Pending, PromiseUtils } from '@deephaven/utils';
import type { Tab, CloseOptions } from '@deephaven/golden-layout';
import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, NotebookEvent } from '../events';
import { type CoreConsoleSession } from '../ConsoleEvents';
import { getDashboardSessionWrapper } from '../redux';
import Panel from './CorePanel';
import './NotebookPanel.scss';
Expand Down Expand Up @@ -1068,10 +1069,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
this.runCommand(this.notebook.getSelectedCommand());
}

handleSessionOpened(
session: dh.IdeSession,
{ language }: { language: string }
): void {
handleSessionOpened({ session, language }: CoreConsoleSession): void {
this.setState({
session,
sessionLanguage: language,
Expand Down
Loading