@@ -2,22 +2,23 @@ import { ReactElement, useEffect, useState, useCallback } from 'react';
22import { useDispatch , useSelector } from 'react-redux' ;
33import { useDashboardActions , useDashboardStore } from '@perses-dev/dashboards' ;
44import { dashboardsOpened , dashboardsPersesPanelExternallyAdded } from '../../../store/actions' ;
5+ import type { RootState } from '../../../store' ;
56
67interface ExternalPanelAdditionProps {
78 isEditMode : boolean ;
89 onEditButtonClick : ( ) => void ;
910}
1011
1112// Effect-only component that registers hooks related to exposing adding panels
12- // from external intergrations .
13+ // from external integrations .
1314// See components/ols-tool-ui/helpers/AddToDashboardButton.tsx for example use.
1415export function ExternalPanelAddition ( {
1516 isEditMode,
1617 onEditButtonClick,
1718} : ExternalPanelAdditionProps ) : ReactElement | null {
1819 const dispatch = useDispatch ( ) ;
1920 const addPersesPanelExternally : any = useSelector (
20- ( s : any ) => s . plugins ?. mcp ?. dashboards ?. addPersesPanelExternally ,
21+ ( s : RootState ) => s . plugins ?. mcp ?. dashboards ?. addPersesPanelExternally ,
2122 ) ;
2223 const { openAddPanel } = useDashboardActions ( ) ;
2324 const dashboardStore = useDashboardStore ( ) ;
@@ -48,16 +49,16 @@ export function ExternalPanelAddition({
4849 if ( addPersesPanelExternally && ! queuedPanel ) {
4950 queuePanelAddition ( addPersesPanelExternally ) ;
5051 }
52+ } , [ queuedPanel , queuePanelAddition , addPersesPanelExternally ] ) ;
5153
54+ useEffect ( ( ) => {
5255 // Apply externally added panel
5356 if ( queuedPanel ) {
5457 try {
55- const groupId = dashboardStore . panelGroupOrder [ 0 ] ;
56- queuedPanel . groupId = groupId ;
57-
5858 // Use the temporary panelEditor to add changes to the dashboard.
5959 const panelEditor = dashboardStore . panelEditor ;
60- panelEditor . applyChanges ( queuedPanel ) ;
60+ const groupId = dashboardStore . panelGroupOrder [ 0 ] ;
61+ panelEditor . applyChanges ( { ...queuedPanel , groupId } ) ;
6162 panelEditor . close ( ) ;
6263 } finally {
6364 // Clear the externally added panel after applying changes.
@@ -68,14 +69,7 @@ export function ExternalPanelAddition({
6869 dispatch ( dashboardsPersesPanelExternallyAdded ( ) ) ;
6970 }
7071 }
71- } , [
72- dispatch ,
73- dashboardStore . panelGroupOrder ,
74- dashboardStore . panelEditor ,
75- queuePanelAddition ,
76- queuedPanel ,
77- addPersesPanelExternally ,
78- ] ) ;
72+ } , [ dispatch , dashboardStore . panelGroupOrder , dashboardStore . panelEditor , queuedPanel ] ) ;
7973
8074 // Advertise when a dashboard is opened/closed
8175 useEffect ( ( ) => {
0 commit comments