Skip to content

Commit 8b92bfb

Browse files
committed
OU-1264: address review comments
1 parent 38b1290 commit 8b92bfb

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

web/src/components/dashboards/perses/ExternalPanelAddition.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ import { ReactElement, useEffect, useState, useCallback } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import { useDashboardActions, useDashboardStore } from '@perses-dev/dashboards';
44
import { dashboardsOpened, dashboardsPersesPanelExternallyAdded } from '../../../store/actions';
5+
import type { RootState } from '../../../store';
56

67
interface 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.
1415
export 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(() => {

web/src/components/ols-tool-ui/helpers/AddToDashboardButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { PanelDefinition } from '@perses-dev/core';
1010
import { InfoTooltip } from '@perses-dev/components';
1111

1212
import { dashboardsAddPersesPanelExternally } from '../../../store/actions';
13+
import type { RootState } from '../../../store';
1314

1415
export const HeaderIconButton: StyledComponent<IconButtonProps & { theme?: Theme }> = styled(
1516
IconButton,
@@ -60,7 +61,9 @@ export const AddToDashboardButton: React.FC<AddToDashboardButtonProps> = ({
6061
}) => {
6162
const dispatch = useDispatch();
6263
const { t } = useTranslation(process.env.I18N_NAMESPACE);
63-
const isDashboardOpen: boolean = useSelector((s: any) => s.plugins?.mcp?.dashboards?.isOpened);
64+
const isDashboardOpen: boolean = useSelector(
65+
(s: RootState) => s.plugins?.mcp?.dashboards?.isOpened,
66+
);
6467
const addToPersesDashboard = React.useCallback(() => {
6568
const panelDefinition = createPanelDefinition(query, name, description);
6669
dispatch(dashboardsAddPersesPanelExternally(panelDefinition));

0 commit comments

Comments
 (0)