From a1e59a92b02168442481bc1efbea48f96c8986d1 Mon Sep 17 00:00:00 2001 From: Tom Ratcliffe Date: Wed, 12 Feb 2025 15:12:11 +0000 Subject: [PATCH] Alerting: Allow collapsing of rule sections and fix Grafana configure link (#100290) --- .../components/DataSourceSection.tsx | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/public/app/features/alerting/unified/rule-list/components/DataSourceSection.tsx b/public/app/features/alerting/unified/rule-list/components/DataSourceSection.tsx index 9df0aa641b3..11f4f5cbf01 100644 --- a/public/app/features/alerting/unified/rule-list/components/DataSourceSection.tsx +++ b/public/app/features/alerting/unified/rule-list/components/DataSourceSection.tsx @@ -1,14 +1,16 @@ import { css } from '@emotion/css'; import { PropsWithChildren, ReactNode } from 'react'; +import { useToggle } from 'react-use'; import { GrafanaTheme2 } from '@grafana/data'; -import { LinkButton, Stack, Text, useStyles2 } from '@grafana/ui'; +import { IconButton, LinkButton, Stack, Text, useStyles2 } from '@grafana/ui'; import { Trans, t } from 'app/core/internationalization'; -import { RulesSourceIdentifier } from 'app/types/unified-alerting'; +import { GrafanaRulesSourceSymbol, RulesSourceIdentifier } from 'app/types/unified-alerting'; import { RulesSourceApplication } from 'app/types/unified-alerting-dto'; import { Spacer } from '../../components/Spacer'; import { WithReturnButton } from '../../components/WithReturnButton'; +import { isAdmin } from '../../utils/misc'; import { DataSourceIcon } from './Namespace'; import { LoadingIndicator } from './RuleGroup'; @@ -32,7 +34,17 @@ export const DataSourceSection = ({ description = null, }: DataSourceSectionProps) => { const styles = useStyles2(getStyles); - + const [isCollapsed, toggleCollapsed] = useToggle(false); + const configureLink = (() => { + if (uid === GrafanaRulesSourceSymbol) { + const userIsAdmin = isAdmin(); + if (!userIsAdmin) { + return; + } + return '/alerting/admin'; + } + return `/connections/datasources/edit/${String(uid)}`; + })(); return (
@@ -41,7 +53,13 @@ export const DataSourceSection = ({
{loader ?? ( + {application && } + {name} @@ -52,19 +70,21 @@ export const DataSourceSection = ({ )} - - Configure - - } - /> + {configureLink && ( + + Configure + + } + /> + )} )}
-
{children}
+ {!isCollapsed &&
{children}
}
);