1- import { useEffect , useState } from 'react' ;
1+ import { useEffect , useState , useCallback } from 'react' ;
22import { useDispatch , useSelector } from 'react-redux' ;
33import { useDashboardActions , useDashboardStore } from '@perses-dev/dashboards' ;
44import { dashboardsOpened , dashboardsPersesPanelExternallyAdded } from '../../../store/actions' ;
@@ -20,20 +20,23 @@ export function useExternalPanelAddition({
2020 const dashboardStore = useDashboardStore ( ) ;
2121 const [ externallyAddedPanel , setExternallyAddedPanel ] = useState ( null ) ;
2222
23- const addPanelExternally = ( panelDefinition : any ) : void => {
24- // Simulate opening a panel to add the pane so that we can use it to programatically
25- // add a panel to the dashboard from an external source (AI assistant).
26- if ( ! isEditMode ) {
27- onEditButtonClick ( ) ;
28- }
29- openAddPanel ( ) ;
30- // Wrap the panelDefinition with the groupId structure
31- const change = {
32- groupId : 0 ,
33- panelDefinition,
34- } ;
35- setExternallyAddedPanel ( change ) ;
36- } ;
23+ const addPanelExternally = useCallback (
24+ ( panelDefinition : any ) : void => {
25+ // Simulate opening a panel to add the pane so that we can use it to programatically
26+ // add a panel to the dashboard from an external source (AI assistant).
27+ if ( ! isEditMode ) {
28+ onEditButtonClick ( ) ;
29+ }
30+ openAddPanel ( ) ;
31+ // Wrap the panelDefinition with the groupId structure
32+ const change = {
33+ groupId : 0 ,
34+ panelDefinition,
35+ } ;
36+ setExternallyAddedPanel ( change ) ;
37+ } ,
38+ [ isEditMode , onEditButtonClick , openAddPanel ] ,
39+ ) ;
3740
3841 useEffect ( ( ) => {
3942 // Listen for external panel addition requests
@@ -55,7 +58,14 @@ export function useExternalPanelAddition({
5558 // Clear the externally added panel after applying changes
5659 setExternallyAddedPanel ( null ) ;
5760 }
58- } , [ externallyAddedPanel , addPersesPanelExternally ] ) ;
61+ } , [
62+ dispatch ,
63+ dashboardStore . panelGroupOrder ,
64+ dashboardStore . panelEditor ,
65+ externallyAddedPanel ,
66+ addPanelExternally ,
67+ addPersesPanelExternally ,
68+ ] ) ;
5969
6070 // Advertise when custom dashboard is opened/closed
6171 useEffect ( ( ) => {
0 commit comments