Skip to content

Commit bc720d1

Browse files
authored
feat: Pass through additional actions from WidgetPanel (#2224)
- additionalActions was only a prop on Panel - Add it as a prop on WidgetPanel and pass it through
1 parent 611ec2c commit bc720d1

2 files changed

Lines changed: 44 additions & 59 deletions

File tree

packages/dashboard-core-plugins/src/panels/Panel.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import memoize from 'memoize-one';
1111
import {
1212
ContextAction,
1313
ContextActions,
14+
createXComponent,
1415
LoadingOverlay,
1516
Tooltip,
1617
} from '@deephaven/components';
@@ -31,7 +32,7 @@ import './Panel.scss';
3132

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

34-
interface PanelProps {
35+
export type CorePanelProps = {
3536
/**
3637
* Reference to the component panel.
3738
* Will wait until it is set before emitting mount/unmount events.
@@ -65,7 +66,7 @@ interface PanelProps {
6566
isLoaded?: boolean;
6667
isClonable?: boolean;
6768
isRenamable?: boolean;
68-
}
69+
};
6970

7071
interface PanelState {
7172
title?: string | null;
@@ -77,8 +78,8 @@ interface PanelState {
7778
* Also wires up some triggers for common events:
7879
* Focus, Resize, Show, Session open/close, client disconnect/reconnect.
7980
*/
80-
class Panel extends PureComponent<PanelProps, PanelState> {
81-
constructor(props: PanelProps) {
81+
class Panel extends PureComponent<CorePanelProps, PanelState> {
82+
constructor(props: CorePanelProps) {
8283
super(props);
8384

8485
this.handleClearAllFilters = this.handleClearAllFilters.bind(this);
@@ -379,4 +380,6 @@ class Panel extends PureComponent<PanelProps, PanelState> {
379380
}
380381
}
381382

382-
export default Panel;
383+
const XPanel = createXComponent(Panel);
384+
385+
export default XPanel;

packages/dashboard-core-plugins/src/panels/WidgetPanel.tsx

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,22 @@
1-
import React, { PureComponent, ReactElement, ReactNode } from 'react';
1+
import React, { PureComponent, ReactElement } from 'react';
22
import classNames from 'classnames';
33
import memoize from 'memoize-one';
4-
import { ContextActions, createXComponent } from '@deephaven/components';
5-
import { PanelComponent } from '@deephaven/dashboard';
6-
import type { Container, EventEmitter } from '@deephaven/golden-layout';
7-
import { copyToClipboard } from '@deephaven/utils';
8-
import Panel from './Panel';
4+
import {
5+
ContextAction,
6+
ContextActions,
7+
createXComponent,
8+
} from '@deephaven/components';
9+
import type { dh } from '@deephaven/jsapi-types';
10+
import { copyToClipboard, EMPTY_ARRAY } from '@deephaven/utils';
11+
import Panel, { CorePanelProps } from './Panel';
912
import WidgetPanelTooltip from './WidgetPanelTooltip';
1013
import './WidgetPanel.scss';
1114
import { WidgetPanelDescriptor } from './WidgetPanelTypes';
1215

13-
export type WidgetPanelProps = {
14-
children: ReactNode;
15-
16+
export type WidgetPanelProps = CorePanelProps & {
1617
descriptor: WidgetPanelDescriptor;
17-
componentPanel?: PanelComponent;
18-
19-
glContainer: Container;
20-
glEventHub: EventEmitter;
21-
22-
className?: string;
23-
errorMessage?: string;
24-
isClonable?: boolean;
25-
isDisconnected?: boolean;
26-
isLoading?: boolean;
27-
isLoaded?: boolean;
28-
isRenamable?: boolean;
2918
showTabTooltip?: boolean;
30-
31-
renderTabTooltip?: () => ReactNode;
32-
33-
onFocus?: () => void;
34-
onBlur?: () => void;
35-
onHide?: () => void;
36-
onClearAllFilters?: () => void;
37-
onResize?: () => void;
38-
onSessionClose?: (...args: unknown[]) => void;
39-
onSessionOpen?: (...args: unknown[]) => void;
40-
onShow?: () => void;
41-
onTabBlur?: () => void;
42-
onTabFocus?: () => void;
43-
onTabClicked?: () => void;
19+
isDisconnected?: boolean;
4420
};
4521

4622
interface WidgetPanelState {
@@ -68,7 +44,6 @@ class WidgetPanel extends PureComponent<WidgetPanelProps, WidgetPanelState> {
6844
super(props);
6945

7046
this.handleSessionClosed = this.handleSessionClosed.bind(this);
71-
this.handleSessionOpened = this.handleSessionOpened.bind(this);
7247
this.handleCopyName = this.handleCopyName.bind(this);
7348

7449
this.state = {
@@ -119,28 +94,29 @@ class WidgetPanel extends PureComponent<WidgetPanelProps, WidgetPanelState> {
11994
: undefined
12095
);
12196

122-
getCachedActions = memoize((descriptor: WidgetPanelDescriptor) => [
123-
{
124-
title: `Copy ${descriptor.displayType ?? descriptor.type} Name`,
125-
group: ContextActions.groups.medium,
126-
order: 20,
127-
action: this.handleCopyName,
128-
},
129-
]);
97+
getCachedActions = memoize(
98+
(
99+
descriptor: WidgetPanelDescriptor,
100+
propsAdditionalActions: readonly ContextAction[] = EMPTY_ARRAY
101+
) => [
102+
...propsAdditionalActions,
103+
{
104+
title: `Copy ${descriptor.displayType ?? descriptor.type} Name`,
105+
group: ContextActions.groups.medium,
106+
order: 20,
107+
action: this.handleCopyName,
108+
},
109+
]
110+
);
130111

131-
handleSessionClosed(...args: unknown[]): void {
112+
handleSessionClosed(session: dh.IdeSession): void {
132113
const { onSessionClose } = this.props;
133114
// The session has closed and we won't be able to reconnect, as this widget isn't persisted
134115
this.setState({
135116
isPanelDisconnected: true,
136117
isWaitingForReconnect: false,
137118
});
138-
onSessionClose?.(...args);
139-
}
140-
141-
handleSessionOpened(...args: unknown[]): void {
142-
const { onSessionOpen } = this.props;
143-
onSessionOpen?.(...args);
119+
onSessionClose?.(session);
144120
}
145121

146122
render(): ReactElement {
@@ -164,10 +140,13 @@ class WidgetPanel extends PureComponent<WidgetPanelProps, WidgetPanelState> {
164140
onFocus,
165141
onBlur,
166142
onResize,
143+
onSessionOpen,
167144
onShow,
168145
onTabBlur,
169146
onTabFocus,
170147
onTabClicked,
148+
149+
additionalActions: propsAdditionalActions,
171150
} = this.props;
172151

173152
const { isPanelDisconnected, isWidgetDisconnected, isPanelInactive } =
@@ -177,7 +156,10 @@ class WidgetPanel extends PureComponent<WidgetPanelProps, WidgetPanelState> {
177156
renderTabTooltip ??
178157
this.getCachedRenderTabTooltip(showTabTooltip, descriptor);
179158

180-
const additionalActions = this.getCachedActions(descriptor);
159+
const additionalActions = this.getCachedActions(
160+
descriptor,
161+
propsAdditionalActions
162+
);
181163

182164
return (
183165
<Panel
@@ -196,7 +178,7 @@ class WidgetPanel extends PureComponent<WidgetPanelProps, WidgetPanelState> {
196178
onResize={onResize}
197179
onShow={onShow}
198180
onSessionClose={this.handleSessionClosed}
199-
onSessionOpen={this.handleSessionOpened}
181+
onSessionOpen={onSessionOpen}
200182
onTabBlur={onTabBlur}
201183
onTabFocus={onTabFocus}
202184
onTabClicked={onTabClicked}
@@ -215,6 +197,6 @@ class WidgetPanel extends PureComponent<WidgetPanelProps, WidgetPanelState> {
215197
}
216198
}
217199

218-
const XWidgetPanel = createXComponent(WidgetPanel);
200+
const XWidgetPanel = createXComponent<WidgetPanelProps>(WidgetPanel);
219201

220202
export default XWidgetPanel;

0 commit comments

Comments
 (0)