Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move Panel into @deephaven/dashboard #2304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/dashboard-core-plugins/src/events/TabEventMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ValueOf } from '@deephaven/utils';
import type TabEvent from './TabEvent';
import { type TabEvent } from '@deephaven/dashboard';

export type TabEventType = ValueOf<typeof TabEvent>;

Expand Down
4 changes: 3 additions & 1 deletion packages/dashboard-core-plugins/src/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export { default as IrisGridEvent } from './IrisGridEvent';
export { default as MarkdownEvent } from './MarkdownEvent';
export { default as NotebookEvent } from './NotebookEvent';
export { default as PandasEvent } from './PandasEvent';
export { default as TabEvent } from './TabEvent';

// Deprecated - use TabEvent from @deephaven/dashboard
export { type TabEvent } from '@deephaven/dashboard';
Comment on lines +9 to +10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do something like this so the deprecation actually shows up in vscode

import { type TabEvent as TabEventImport } from '@deephaven/dashboard';

/**
 * @deprecated Use TabEvent from `@deephaven/dashboard`
 */
export type TabEvent = typeof TabEventImport; // Not sure why typeof is needed here

This will give the deprecation strikethrough in VSCode

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { assertNotNull, Pending } from '@deephaven/utils';
import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, NotebookEvent } from '../events';
import './CommandHistoryPanel.scss';
import Panel from './Panel';
import Panel from './CorePanel';
import { getDashboardSessionWrapper } from '../redux';

const log = Log.module('CommandHistoryPanel');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from '@deephaven/plugin';
import type { JSZipObject } from 'jszip';
import { ConsoleEvent } from '../events';
import Panel from './Panel';
import Panel from './CorePanel';
import { getDashboardSessionWrapper } from '../redux';
import './ConsolePanel.scss';

Expand Down
80 changes: 80 additions & 0 deletions packages/dashboard-core-plugins/src/panels/CorePanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { PureComponent, type ReactElement } from 'react';
import { createXComponent } from '@deephaven/components';
import { type BasePanelProps, Panel } from '@deephaven/dashboard';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should either have BasePanelProps, BasePanel or PanelProps, Panel for consistency

import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, 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;
};

/**
* Generic panel component that emits mount/unmount/focus events.
* Also wires up some triggers for common events:
* Focus, Resize, Show, Session open/close, client disconnect/reconnect.
*/
class CorePanel extends PureComponent<CorePanelProps> {
constructor(props: CorePanelProps) {
super(props);

this.handleClearAllFilters = this.handleClearAllFilters.bind(this);
this.handleSessionClosed = this.handleSessionClosed.bind(this);
this.handleSessionOpened = this.handleSessionOpened.bind(this);
}

componentDidMount(): void {
const { glEventHub } = this.props;

glEventHub.on(ConsoleEvent.SESSION_CLOSED, this.handleSessionClosed);
glEventHub.on(ConsoleEvent.SESSION_OPENED, this.handleSessionOpened);
glEventHub.on(
InputFilterEvent.CLEAR_ALL_FILTERS,
this.handleClearAllFilters
);
}

componentWillUnmount(): void {
const { glEventHub } = this.props;

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

handleClearAllFilters(...args: unknown[]): void {
const { onClearAllFilters } = this.props;
onClearAllFilters?.(...args);
}

handleSessionClosed(session: dh.IdeSession): void {
const { onSessionClose } = this.props;
onSessionClose?.(session);
}

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

render(): ReactElement {
const { children, ...otherProps } = this.props;

// eslint-disable-next-line react/jsx-props-no-spreading
return <Panel {...otherProps}>{children}</Panel>;
}
}

const XCorePanel = createXComponent(CorePanel);

export default XCorePanel;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FileExplorer, {
import React, { type ReactNode } from 'react';
import { connect, type ConnectedProps } from 'react-redux';
import type { dh } from '@deephaven/jsapi-types';
import Panel from './Panel';
import Panel from './CorePanel';
import { NotebookEvent } from '../events';
import './FileExplorerPanel.scss';
import { getDashboardSessionWrapper } from '../redux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
getTableMapForDashboard,
setDashboardFilterSets as setDashboardFilterSetsAction,
} from '../redux';
import Panel from './Panel';
import Panel from './CorePanel';
import FilterSetManager, {
type ChangeHandlerArgs,
type FilterSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import debounce from 'lodash.debounce';
import type { Container, EventEmitter } from '@deephaven/golden-layout';
import { type RootState } from '@deephaven/redux';
import Panel from './Panel';
import Panel from './CorePanel';
import InputFilter, {
type InputFilterColumn,
} from '../controls/input-filter/InputFilter';
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-core-plugins/src/panels/LogPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { type DashboardPanelProps } from '@deephaven/dashboard';
import Log from '@deephaven/log';
import { type RootState } from '@deephaven/redux';
import './LogPanel.scss';
import Panel from './Panel';
import Panel from './CorePanel';
import { getDashboardSessionWrapper } from '../redux';

const log = Log.module('LogPanel');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type * as monaco from 'monaco-editor';
import { assertNotNull } from '@deephaven/utils';
import { type RootState } from '@deephaven/redux';
import { LoadingOverlay } from '@deephaven/components';
import Panel from './Panel';
import Panel from './CorePanel';
import MarkdownContainer from '../controls/markdown/MarkdownContainer';
import MarkdownStartPage from '../controls/markdown/MarkdownStartPage';
import './MarkdownPanel.scss';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import type { Tab, CloseOptions } from '@deephaven/golden-layout';
import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, NotebookEvent } from '../events';
import { getDashboardSessionWrapper } from '../redux';
import Panel from './Panel';
import Panel from './CorePanel';
import './NotebookPanel.scss';

const MarkdownNotebook = lazy(() => import('./MarkdownNotebook'));
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-core-plugins/src/panels/WidgetPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@deephaven/components';
import type { dh } from '@deephaven/jsapi-types';
import { copyToClipboard, EMPTY_ARRAY } from '@deephaven/utils';
import Panel, { type CorePanelProps } from './Panel';
import Panel, { type CorePanelProps } from './CorePanel';
import WidgetPanelTooltip from './WidgetPanelTooltip';
import './WidgetPanel.scss';
import { type WidgetPanelDescriptor } from './WidgetPanelTypes';
Expand Down
4 changes: 3 additions & 1 deletion packages/dashboard-core-plugins/src/panels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export { default as MarkdownPanel } from './MarkdownPanel';
export { default as NotebookPanel } from './NotebookPanel';
export { default as PandasPanel } from './PandasPanel';
export * from './PandasPanel';
export { default as Panel } from './Panel';
export { default as CorePanel } from './CorePanel';
// Deprecated - use CorePanel instead
export { default as Panel } from './CorePanel';
Comment on lines +20 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about importing and renaming for the deprecated export w/ a deprecated tag.

CorePanel is what Panel used to be right? Why would someone need/want Panel from @deephaven/dashboard? dh.ui would still need the dashboard-core-components version, right? Or does nothing there need the session open/close events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deephaven.ui doesn't use the onSessionClosed or onSessionOpened props, it only needs the BasePanel

export * from './WidgetPanelTypes';
export { default as WidgetPanel, type WidgetPanelProps } from './WidgetPanel';
export { default as WidgetPanelTooltip } from './WidgetPanelTooltip';
Expand Down
2 changes: 2 additions & 0 deletions packages/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
"@deephaven/react-hooks": "file:../react-hooks",
"@deephaven/redux": "file:../redux",
"@deephaven/utils": "file:../utils",
"classnames": "^2.3.1",
"fast-deep-equal": "^3.1.3",
"lodash.ismatch": "^4.1.1",
"lodash.throttle": "^4.1.1",
"memoize-one": "^5.1.1",
"nanoid": "^5.0.7",
"prop-types": "^15.7.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import {
type ResolvableContextAction,
Tooltip,
} from '@deephaven/components';
import {
LayoutUtils,
type PanelComponent,
PanelEvent,
} from '@deephaven/dashboard';
import type {
Container,
EventEmitter,
Expand All @@ -29,15 +24,17 @@ import type {
} from '@deephaven/golden-layout';
import { assertNotNull, EMPTY_ARRAY } from '@deephaven/utils';
import Log from '@deephaven/log';
import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, InputFilterEvent, TabEvent } from '../events';
import LayoutUtils from './layout/LayoutUtils';
import { type PanelComponent } from './DashboardPlugin';
import PanelEvent from './PanelEvent';
import PanelContextMenu from './PanelContextMenu';
import RenameDialog from './RenameDialog';
import TabEvent from './TabEvent';
import './Panel.scss';

const log = Log.module('Panel');

export type CorePanelProps = {
export type BasePanelProps = {
/**
* Reference to the component panel.
* Will wait until it is set before emitting mount/unmount events.
Expand All @@ -52,14 +49,8 @@ export type CorePanelProps = {
onBlur?: FocusEventHandler<HTMLDivElement>;
onTab?: (tab: Tab) => void;
onTabClicked?: (e: MouseEvent) => void;
onClearAllFilters?: (...args: unknown[]) => void;
onHide?: (...args: unknown[]) => void;
onResize?: (...args: unknown[]) => void;
onSessionClose?: (session: dh.IdeSession) => void;
onSessionOpen?: (
session: dh.IdeSession,
{ language, sessionId }: { language: string; sessionId: string }
) => void;
onBeforeShow?: (...args: unknown[]) => void;
onShow?: (...args: unknown[]) => void;
onTabBlur?: (...args: unknown[]) => void;
Expand All @@ -83,18 +74,15 @@ interface PanelState {
* Also wires up some triggers for common events:
* Focus, Resize, Show, Session open/close, client disconnect/reconnect.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove session open/close. And client disconnect/reconnect?

*/
class Panel extends PureComponent<CorePanelProps, PanelState> {
constructor(props: CorePanelProps) {
class Panel extends PureComponent<BasePanelProps, PanelState> {
constructor(props: BasePanelProps) {
super(props);

this.handleClearAllFilters = this.handleClearAllFilters.bind(this);
this.handleCopyPanel = this.handleCopyPanel.bind(this);
this.handleFocus = this.handleFocus.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this.handleHide = this.handleHide.bind(this);
this.handleResize = this.handleResize.bind(this);
this.handleSessionClosed = this.handleSessionClosed.bind(this);
this.handleSessionOpened = this.handleSessionOpened.bind(this);
this.handleBeforeShow = this.handleBeforeShow.bind(this);
this.handleShow = this.handleShow.bind(this);
this.handleTabBlur = this.handleTabBlur.bind(this);
Expand Down Expand Up @@ -124,14 +112,8 @@ class Panel extends PureComponent<CorePanelProps, PanelState> {
glContainer.on('hide', this.handleHide);
glContainer.on('tab', this.handleTab);
glContainer.on('tabClicked', this.handleTabClicked);
glEventHub.on(ConsoleEvent.SESSION_CLOSED, this.handleSessionClosed);
glEventHub.on(ConsoleEvent.SESSION_OPENED, this.handleSessionOpened);
glEventHub.on(TabEvent.focus, this.handleTabFocus);
glEventHub.on(TabEvent.blur, this.handleTabBlur);
glEventHub.on(
InputFilterEvent.CLEAR_ALL_FILTERS,
this.handleClearAllFilters
);

glEventHub.emit(PanelEvent.MOUNT, componentPanel ?? this);

Expand All @@ -150,14 +132,8 @@ class Panel extends PureComponent<CorePanelProps, PanelState> {
glContainer.off('hide', this.handleHide);
glContainer.off('tab', this.handleTab);
glContainer.off('tabClicked', this.handleTabClicked);
glEventHub.off(ConsoleEvent.SESSION_CLOSED, this.handleSessionClosed);
glEventHub.off(ConsoleEvent.SESSION_OPENED, this.handleSessionOpened);
glEventHub.off(TabEvent.focus, this.handleTabFocus);
glEventHub.off(TabEvent.blur, this.handleTabBlur);
glEventHub.off(
InputFilterEvent.CLEAR_ALL_FILTERS,
this.handleClearAllFilters
);

glEventHub.emit(PanelEvent.UNMOUNT, componentPanel ?? this);
}
Expand All @@ -183,11 +159,6 @@ class Panel extends PureComponent<CorePanelProps, PanelState> {
onTabClicked?.(e);
}

handleClearAllFilters(...args: unknown[]): void {
const { onClearAllFilters } = this.props;
onClearAllFilters?.(...args);
}

handleFocus(event: FocusEvent<HTMLDivElement>): void {
const { componentPanel, glEventHub } = this.props;
glEventHub.emit(PanelEvent.FOCUS, componentPanel ?? this);
Expand All @@ -211,19 +182,6 @@ class Panel extends PureComponent<CorePanelProps, PanelState> {
onResize?.(...args);
}

handleSessionClosed(session: dh.IdeSession): void {
const { onSessionClose } = this.props;
onSessionClose?.(session);
}

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

handleBeforeShow(...args: unknown[]): void {
const { onBeforeShow } = this.props;
onBeforeShow?.(...args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import {
setWorkspace as setWorkspaceAction,
} from '@deephaven/redux';
import { connect } from 'react-redux';
import {
type ClosedPanel,
LayoutUtils,
PanelEvent,
} from '@deephaven/dashboard';
import { type ClosedPanel } from './PanelManager';
import { LayoutUtils } from './layout';
import { PanelEvent } from './PanelEvent';

interface PanelContextMenuProps {
additionalActions: ResolvableContextAction[];
Expand Down
3 changes: 3 additions & 0 deletions packages/dashboard/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export { default as DashboardUtils } from './DashboardUtils';
export * from './LazyDashboard';
export * from './layout';
export * from './redux';
export { type BasePanelProps } from './Panel';
export { default as Panel } from './Panel';
export * from './PanelManager';
export * from './PanelEvent';
export { default as PanelErrorBoundary } from './PanelErrorBoundary';
export { default as PanelManager } from './PanelManager';
export { default as TabEvent } from './TabEvent';
Loading