Alerting: Render folder selector in options for Alert List Panel only when having Grafana datasource (#70816)

Render folder selector in options for Alert List Panel only when no datasource is selected or when Grafana is selected as the datasource
This commit is contained in:
Sonia Aguilar 2023-06-28 15:38:32 +02:00 committed by GitHub
parent 1206cf3dfa
commit 519e840f97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,8 @@ import {
} from 'app/core/components/Select/ReadonlyFolderPicker/ReadonlyFolderPicker';
import { PermissionLevelString } from 'app/types';
import { GRAFANA_DATASOURCE_NAME } from '../../../features/alerting/unified/utils/datasource';
import { AlertList } from './AlertList';
import { alertListPanelMigrationHandler } from './AlertListMigrationHandler';
import { GroupBy } from './GroupByWithLoading';
@ -244,6 +246,27 @@ const unifiedAlertList = new PanelPlugin<UnifiedAlertListOptions>(UnifiedAlertLi
category: ['Filter'],
})
.addCustomEditor({
path: 'datasource',
name: 'Datasource',
description: 'Filter alerts from selected datasource',
id: 'datasource',
defaultValue: null,
editor: function RenderDatasourcePicker(props) {
return (
<DataSourcePicker
{...props}
type={['prometheus', 'loki', 'grafana']}
noDefault
current={props.value}
onChange={(ds) => props.onChange(ds.name)}
onClear={() => props.onChange(null)}
/>
);
},
category: ['Filter'],
})
.addCustomEditor({
showIf: (options) => options.datasource === GRAFANA_DATASOURCE_NAME || !Boolean(options.datasource),
path: 'folder',
name: 'Folder',
description: 'Filter for alerts in the selected folder (only for Grafana alerts)',
@ -265,26 +288,6 @@ const unifiedAlertList = new PanelPlugin<UnifiedAlertListOptions>(UnifiedAlertLi
},
category: ['Filter'],
})
.addCustomEditor({
path: 'datasource',
name: 'Datasource',
description: 'Filter alerts from selected datasource',
id: 'datasource',
defaultValue: null,
editor: function RenderDatasourcePicker(props) {
return (
<DataSourcePicker
{...props}
type={['prometheus', 'loki', 'grafana']}
noDefault
current={props.value}
onChange={(ds) => props.onChange(ds.name)}
onClear={() => props.onChange(null)}
/>
);
},
category: ['Filter'],
})
.addBooleanSwitch({
path: 'stateFilter.firing',
name: 'Alerting / Firing',