The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/alerting/unified/components/notification-policies/ContactPointSelector.tsx

55 lines
1.7 KiB

import React from 'react';
import { SelectableValue } from '@grafana/data';
import { Select, SelectCommonProps, Text, Stack } from '@grafana/ui';
import {
RECEIVER_META_KEY,
RECEIVER_PLUGIN_META_KEY,
useContactPointsWithStatus,
} from '../contact-points/useContactPoints';
import { ReceiverConfigWithMetadata } from '../contact-points/utils';
export const ContactPointSelector = (props: SelectCommonProps<string>) => {
const { contactPoints, isLoading, error } = useContactPointsWithStatus();
// TODO error handling
if (error) {
return <span>Failed to load contact points</span>;
}
const options: Array<SelectableValue<string>> = contactPoints.map((contactPoint) => {
return {
label: contactPoint.name,
value: contactPoint.name,
component: () => <ReceiversSummary receivers={contactPoint.grafana_managed_receiver_configs} />,
};
});
return <Select options={options} isLoading={isLoading} {...props} />;
};
interface ReceiversProps {
receivers: ReceiverConfigWithMetadata[];
}
const ReceiversSummary = ({ receivers }: ReceiversProps) => {
return (
<Stack direction="row">
{receivers.map((receiver, index) => (
<Stack key={receiver.uid ?? index} direction="row" gap={0.5}>
{receiver[RECEIVER_PLUGIN_META_KEY]?.icon && (
<img
width="16px"
src={receiver[RECEIVER_PLUGIN_META_KEY]?.icon}
alt={receiver[RECEIVER_PLUGIN_META_KEY]?.title}
/>
)}
<Text key={index} variant="bodySmall" color="secondary">
{receiver[RECEIVER_META_KEY].name ?? receiver[RECEIVER_PLUGIN_META_KEY]?.title ?? receiver.type}
</Text>
</Stack>
))}
</Stack>
);
};