From 6f63def2835366ca11324fcdade2fd0089ed7d15 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Tue, 20 Aug 2024 17:02:35 +0200 Subject: [PATCH] Alerting: Fix long Alertmanager names overflowing the window (#92023) fix long names overflowing the window --- .../unified/components/AlertManagerPicker.tsx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/public/app/features/alerting/unified/components/AlertManagerPicker.tsx b/public/app/features/alerting/unified/components/AlertManagerPicker.tsx index 75bc97f6512..9087ef4f269 100644 --- a/public/app/features/alerting/unified/components/AlertManagerPicker.tsx +++ b/public/app/features/alerting/unified/components/AlertManagerPicker.tsx @@ -1,8 +1,8 @@ import { css } from '@emotion/css'; -import { useMemo } from 'react'; +import { useMemo, ComponentProps } from 'react'; import { GrafanaTheme2, SelectableValue } from '@grafana/data'; -import { InlineField, Select, useStyles2 } from '@grafana/ui'; +import { InlineField, Select, SelectMenuOptions, useStyles2 } from '@grafana/ui'; import { useAlertmanager } from '../state/AlertmanagerContext'; import { AlertManagerDataSource, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource'; @@ -12,15 +12,15 @@ interface Props { } function getAlertManagerLabel(alertManager: AlertManagerDataSource) { - return alertManager.name === GRAFANA_RULES_SOURCE_NAME ? 'Grafana' : alertManager.name.slice(0, 37); + return alertManager.name === GRAFANA_RULES_SOURCE_NAME ? 'Grafana' : alertManager.name; } export const AlertManagerPicker = ({ disabled = false }: Props) => { const styles = useStyles2(getStyles); const { selectedAlertmanager, availableAlertManagers, setSelectedAlertmanager } = useAlertmanager(); - const options: Array> = useMemo(() => { - return availableAlertManagers.map((ds) => ({ + const options = useMemo(() => { + return availableAlertManagers.map>((ds) => ({ label: getAlertManagerLabel(ds), value: ds.name, imgUrl: ds.imgUrl, @@ -44,10 +44,10 @@ export const AlertManagerPicker = ({ disabled = false }: Props) => { } }} options={options} - maxMenuHeight={500} noOptionsMessage="No datasources found" value={selectedAlertmanager} getOptionLabel={(o) => o.label} + components={{ Option: CustomOption }} /> ); @@ -58,3 +58,11 @@ const getStyles = (theme: GrafanaTheme2) => ({ margin: 0, }), }); + +// custom option that overwrites the default "white-space: nowrap" for Alertmanager names that are really long +const CustomOption = (props: ComponentProps) => ( +
{label}
} + /> +);