File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { DashboardData , RootState } from '@deephaven/redux' ;
1+ import { DashboardData , PluginData , RootState } from '@deephaven/redux' ;
22import type { Action } from 'redux' ;
33import type { ThunkAction } from 'redux-thunk' ;
44import { SET_DASHBOARD_DATA } from './actionTypes' ;
5- import { getDashboardData } from './selectors' ;
5+ import { getDashboardData , getPluginDataMapForDashboard } from './selectors' ;
66
77/**
88 * Action to replace the dashboard data for a dashboard
@@ -41,3 +41,26 @@ export const updateDashboardData =
4141 ...data ,
4242 } )
4343 ) ;
44+
45+ /**
46+ * Action to update the dashboard data. Will combine the update with any existing dashboard data.
47+ * @param id The id of the dashboard to set the data on
48+ * @param pluginId The id of the plugin to set the data on
49+ * @param data The data to replace the existing plugin data with
50+ * @returns
51+ */
52+ export const setDashboardPluginData =
53+ (
54+ id : string ,
55+ pluginId : string ,
56+ data : PluginData
57+ ) : ThunkAction < unknown , RootState , undefined , Action < unknown > > =>
58+ ( dispatch , getState ) =>
59+ dispatch (
60+ setDashboardData ( id , {
61+ ...getDashboardData ( getState ( ) , id ) ,
62+ pluginDataMap : new Map (
63+ getPluginDataMapForDashboard ( getState ( ) , id )
64+ ) . set ( pluginId , data ) ,
65+ } )
66+ ) ;
Original file line number Diff line number Diff line change 1+ import { useCallback } from 'react' ;
2+ import { useDispatch , useSelector } from 'react-redux' ;
3+ import { PluginData , RootState } from '@deephaven/redux' ;
4+ import { getPluginDataForDashboard } from './selectors' ;
5+ import { setDashboardPluginData } from './actions' ;
6+
7+ /**
8+ * Custom hook that provides access to plugin data for a specific dashboard and plugin.
9+ * @param dashboardId - The ID of the dashboard.
10+ * @param pluginId - The ID of the plugin.
11+ * @returns A tuple containing the plugin data and a function to update the plugin data.
12+ */
13+ export function useDashboardPluginData (
14+ dashboardId : string ,
15+ pluginId : string
16+ ) : [ PluginData , ( data : PluginData ) => void ] {
17+ const dispatch = useDispatch ( ) ;
18+ const data = useSelector ( ( store : RootState ) =>
19+ getPluginDataForDashboard ( store , dashboardId , pluginId )
20+ ) ;
21+ const setData = useCallback (
22+ newData => dispatch ( setDashboardPluginData ( dashboardId , pluginId , newData ) ) ,
23+ [ dashboardId , pluginId , dispatch ]
24+ ) ;
25+ return [ data , setData ] ;
26+ }
27+
28+ export default { useDashboardPluginData } ;
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ Object.entries(reducers).map(([name, reducer]) =>
88export { reducers } ;
99export * from './actions' ;
1010export * from './actionTypes' ;
11+ export * from './hooks' ;
1112export * from './selectors' ;
Original file line number Diff line number Diff line change 1- import { DashboardData , RootState } from '@deephaven/redux' ;
1+ import {
2+ DashboardData ,
3+ PluginData ,
4+ PluginDataMap ,
5+ RootState ,
6+ } from '@deephaven/redux' ;
27import { ClosedPanels , OpenedPanelMap } from '../PanelManager' ;
38
49const EMPTY_MAP = new Map ( ) ;
@@ -50,3 +55,26 @@ export const getOpenedPanelMapForDashboard = (
5055) : OpenedPanelMap =>
5156 ( getDashboardData ( store , dashboardId ) . openedMap ??
5257 EMPTY_MAP ) as OpenedPanelMap ;
58+
59+ /**
60+ * @param store The redux store
61+ * @param dashboardId The dashboard ID to get data for
62+ * @returns The map of plugin IDs to data for all plugins on the dashboard
63+ */
64+ export const getPluginDataMapForDashboard = (
65+ store : RootState ,
66+ dashboardId : string
67+ ) : PluginDataMap =>
68+ getDashboardData ( store , dashboardId ) . pluginDataMap ?? EMPTY_MAP ;
69+
70+ /**
71+ * @param store The redux store
72+ * @param dashboardId The dashboard ID to get data for
73+ * @param pluginId The plugin ID to get data for
74+ * @returns The plugin data
75+ */
76+ export const getPluginDataForDashboard = (
77+ store : RootState ,
78+ dashboardId : string ,
79+ pluginId : string
80+ ) : PluginData => getPluginDataMapForDashboard ( store , dashboardId ) . get ( pluginId ) ;
Original file line number Diff line number Diff line change @@ -77,7 +77,14 @@ export interface CustomizableWorkspace {
7777export interface Workspace {
7878 data : WorkspaceData ;
7979}
80- export type DashboardData = Record < string , unknown > ;
80+
81+ export type PluginData = unknown ;
82+
83+ export type PluginDataMap = Map < string , PluginData > ;
84+
85+ export type DashboardData = Record < string , unknown > & {
86+ pluginDataMap ?: PluginDataMap ;
87+ } ;
8188
8289export type WorkspaceStorageLoadOptions = {
8390 isConsoleAvailable : boolean ;
You can’t perform that action at this time.
0 commit comments