1- import React , { PureComponent , ReactElement , ReactNode } from 'react' ;
1+ import React , { PureComponent , ReactElement } from 'react' ;
22import classNames from 'classnames' ;
33import 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' ;
912import WidgetPanelTooltip from './WidgetPanelTooltip' ;
1013import './WidgetPanel.scss' ;
1114import { 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
4622interface 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
220202export default XWidgetPanel ;
0 commit comments