diff --git a/public/app/features/alerting/unified/components/rule-editor/DashboardAnnotationField.tsx b/public/app/features/alerting/unified/components/rule-editor/DashboardAnnotationField.tsx
index 7b935a67f86..1cbd423a3bf 100644
--- a/public/app/features/alerting/unified/components/rule-editor/DashboardAnnotationField.tsx
+++ b/public/app/features/alerting/unified/components/rule-editor/DashboardAnnotationField.tsx
@@ -27,7 +27,7 @@ const DashboardAnnotationField = ({
const styles = useStyles2(getStyles);
const dashboardLink = makeDashboardLink(dashboard?.uid || dashboardUid);
- const panelLink = makePanelLink(dashboard?.uid || dashboardUid, panel?.id.toString() || panelId);
+ const panelLink = makePanelLink(dashboard?.uid || dashboardUid, panel?.id?.toString() || panelId);
return (
{dashboard && (
diff --git a/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.tsx b/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.tsx
index e8127bec171..b78338b093a 100644
--- a/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.tsx
+++ b/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.tsx
@@ -1,4 +1,5 @@
import { css, cx } from '@emotion/css';
+import { noop } from 'lodash';
import React, { CSSProperties, useCallback, useMemo, useState } from 'react';
import { useDebounce } from 'react-use';
import AutoSizer from 'react-virtualized-auto-sizer';
@@ -20,7 +21,7 @@ import {
import { dashboardApi } from '../../api/dashboardApi';
export interface PanelDTO {
- id: number;
+ id?: number;
title?: string;
type: string;
}
@@ -73,11 +74,12 @@ export const DashboardPicker = ({ dashboardUid, panelId, isOpen, onChange, onDis
const filteredPanels =
dashboardResult?.dashboard?.panels
- ?.filter((panel): panel is PanelDTO => typeof panel.id === 'number' && typeof panel.type === 'string')
?.filter((panel) => panel.title?.toLowerCase().includes(panelFilter.toLowerCase()))
.sort(panelSort) ?? [];
- const currentPanel = dashboardResult?.dashboard?.panels?.find((panel) => panel.id.toString() === selectedPanelId);
+ const currentPanel: PanelDTO | undefined = dashboardResult?.dashboard?.panels?.find(
+ (panel: PanelDTO) => isValidPanelIdentifier(panel) && panel.id?.toString() === selectedPanelId
+ );
const selectedDashboardIndex = useMemo(() => {
return filteredDashboards.map((dashboard) => dashboard.uid).indexOf(selectedDashboardUid ?? '');
@@ -128,27 +130,34 @@ export const DashboardPicker = ({ dashboardUid, panelId, isOpen, onChange, onDis
const PanelRow = ({ index, style }: { index: number; style: CSSProperties }) => {
const panel = filteredPanels[index];
const panelTitle = panel.title || '
';
- const isSelected = selectedPanelId === panel.id.toString();
+ const isSelected = panel.id && selectedPanelId === panel.id?.toString();
const isAlertingCompatible = panel.type === 'graph' || panel.type === 'timeseries';
+ const disabled = !isValidPanelIdentifier(panel);
return (
);
};
@@ -169,7 +178,7 @@ export const DashboardPicker = ({ dashboardUid, panelId, isOpen, onChange, onDis
Dashboard: {dashboardResult?.dashboard.title} ({dashboardResult?.dashboard.uid}) in folder{' '}
{dashboardResult?.meta.folderTitle ?? 'General'}
- {Boolean(currentPanel) && (
+ {currentPanel && (