66 type DashboardPluginComponentProps ,
77 LayoutUtils ,
88 PanelEvent ,
9+ type PanelId ,
910 updateDashboardData ,
1011 useListener ,
1112} from '@deephaven/dashboard' ;
@@ -16,6 +17,7 @@ import {
1617 DropdownFilterPanel ,
1718 FilterSetManagerPanel ,
1819 InputFilterPanel ,
20+ type WidgetId ,
1921} from './panels' ;
2022
2123const log = Log . module ( 'FilterPlugin' ) ;
@@ -25,6 +27,9 @@ type Column = {
2527 type : string ;
2628} ;
2729
30+ // A panel or widget can have columns for filters
31+ export type FilterColumnSourceId = PanelId | WidgetId ;
32+
2833export type FilterChangeEvent = Column & {
2934 value : string ;
3035 timestamp : number ;
@@ -41,7 +46,9 @@ export function FilterPlugin(props: FilterPluginProps): JSX.Element | null {
4146 assertIsDashboardPluginProps ( props ) ;
4247 const { id : localDashboardId , layout, registerComponent } = props ;
4348 const dispatch = useDispatch ( ) ;
44- const [ panelColumns ] = useState ( ( ) => new Map < Component , Column [ ] > ( ) ) ;
49+ const [ panelColumns ] = useState (
50+ ( ) => new Map < FilterColumnSourceId , Column [ ] > ( )
51+ ) ;
4552 const [ panelFilters ] = useState (
4653 ( ) => new Map < Component , FilterChangeEvent [ ] > ( )
4754 ) ;
@@ -92,13 +99,13 @@ export function FilterPlugin(props: FilterPluginProps): JSX.Element | null {
9299
93100 /**
94101 * Handler for the COLUMNS_CHANGED event.
95- * @param panel The component that's emitting the filter change
102+ * @param sourceId The id of the component that's emitting the filter change
96103 * @param columns The columns in this panel
97104 */
98105 const handleColumnsChanged = useCallback (
99- ( panel : Component , columns : Column | Column [ ] ) => {
100- log . debug2 ( 'handleColumnsChanged' , panel , columns ) ;
101- panelColumns . set ( panel , ( [ ] as Column [ ] ) . concat ( columns ) ) ;
106+ ( sourceId : FilterColumnSourceId , columns : Column | Column [ ] ) => {
107+ log . debug2 ( 'handleColumnsChanged' , sourceId , columns ) ;
108+ panelColumns . set ( sourceId , ( [ ] as Column [ ] ) . concat ( columns ) ) ;
102109 sendUpdate ( ) ;
103110 } ,
104111 [ panelColumns , sendUpdate ]
@@ -130,9 +137,12 @@ export function FilterPlugin(props: FilterPluginProps): JSX.Element | null {
130137 const handlePanelUnmount = useCallback (
131138 panel => {
132139 log . debug2 ( 'handlePanelUnmount' , panel ) ;
133- panelColumns . delete ( panel ) ;
140+ const panelId = LayoutUtils . getIdFromPanel ( panel ) ;
141+ if ( panelId != null ) {
142+ panelColumns . delete ( panelId ) ;
143+ }
134144 panelFilters . delete ( panel ) ;
135- panelTables . delete ( LayoutUtils . getIdFromPanel ( panel ) ) ;
145+ panelTables . delete ( panelId ) ;
136146 sendUpdate ( ) ;
137147 } ,
138148 [ panelColumns , panelFilters , panelTables , sendUpdate ]
0 commit comments