-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add pluginDataMap to redux, add useDashboardPluginData hook (#1737
- Loading branch information
Showing
5 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useCallback } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { PluginData, RootState } from '@deephaven/redux'; | ||
import { getPluginDataForDashboard } from './selectors'; | ||
import { setDashboardPluginData } from './actions'; | ||
|
||
/** | ||
* Custom hook that provides access to plugin data for a specific dashboard and plugin. | ||
* @param dashboardId - The ID of the dashboard. | ||
* @param pluginId - The ID of the plugin. | ||
* @returns A tuple containing the plugin data and a function to update the plugin data. | ||
*/ | ||
export function useDashboardPluginData( | ||
dashboardId: string, | ||
pluginId: string | ||
): [PluginData, (data: PluginData) => void] { | ||
const dispatch = useDispatch(); | ||
const data = useSelector((store: RootState) => | ||
getPluginDataForDashboard(store, dashboardId, pluginId) | ||
); | ||
const setData = useCallback( | ||
newData => dispatch(setDashboardPluginData(dashboardId, pluginId, newData)), | ||
[dashboardId, pluginId, dispatch] | ||
); | ||
return [data, setData]; | ||
} | ||
|
||
export default { useDashboardPluginData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters