From b93413c032ab0b20ca53425484a52bbfcf1901c1 Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Wed, 31 May 2023 10:40:02 +0300 Subject: [PATCH] Rares/templates tweaks 3 (#2052) # What this PR does - Added option to expand tree view on main block click - Fixed showing contact policy for grafana alerting --- .../IntegrationCollapsibleTreeView.tsx | 8 ++-- .../Integrations/IntegrationBlock.tsx | 13 +++++- .../src/containers/AlertRules/AlertRules.tsx | 1 + .../CollapsedIntegrationRouteDisplay.tsx | 4 +- .../ExpandedIntegrationRouteDisplay.tsx | 13 ++++-- .../integration_2/Integration2.module.scss | 9 +++- .../src/pages/integration_2/Integration2.tsx | 43 +++++++++++++------ grafana-plugin/src/utils/consts.ts | 2 +- 8 files changed, 67 insertions(+), 26 deletions(-) diff --git a/grafana-plugin/src/components/IntegrationCollapsibleTreeView/IntegrationCollapsibleTreeView.tsx b/grafana-plugin/src/components/IntegrationCollapsibleTreeView/IntegrationCollapsibleTreeView.tsx index 4c212a8b..a57708d0 100644 --- a/grafana-plugin/src/components/IntegrationCollapsibleTreeView/IntegrationCollapsibleTreeView.tsx +++ b/grafana-plugin/src/components/IntegrationCollapsibleTreeView/IntegrationCollapsibleTreeView.tsx @@ -11,8 +11,8 @@ const cx = cn.bind(styles); export interface IntegrationCollapsibleItem { customIcon?: IconName; canHoverIcon: boolean; - expandedView: React.ReactNode; - collapsedView: React.ReactNode; + collapsedView: (toggle?: () => void) => React.ReactNode; // needs toggle param for toggling on click + expandedView: () => React.ReactNode; // for consistency, this is also a function isCollapsible: boolean; isExpanded?: boolean; onStateChange?(): void; @@ -116,10 +116,10 @@ const IntegrationCollapsibleTreeItem: React.FC<{ )}
- {item.expandedView} + {item.expandedView?.()}
- {item.collapsedView} + {item.collapsedView?.(onClick)}
); diff --git a/grafana-plugin/src/components/Integrations/IntegrationBlock.tsx b/grafana-plugin/src/components/Integrations/IntegrationBlock.tsx index cda84f2f..0e283d44 100644 --- a/grafana-plugin/src/components/Integrations/IntegrationBlock.tsx +++ b/grafana-plugin/src/components/Integrations/IntegrationBlock.tsx @@ -1,6 +1,7 @@ import React from 'react'; import cn from 'classnames/bind'; +import { noop } from 'lodash-es'; import Block from 'components/GBlock/Block'; @@ -13,13 +14,20 @@ interface IntegrationBlockProps { hasCollapsedBorder: boolean; heading: React.ReactNode; content: React.ReactNode; + toggle?: () => void; } -const IntegrationBlock: React.FC = ({ heading, content, hasCollapsedBorder, className }) => { +const IntegrationBlock: React.FC = ({ + heading, + content, + hasCollapsedBorder, + className, + toggle = noop, +}) => { return (
{heading && ( - + {heading} )} @@ -28,6 +36,7 @@ const IntegrationBlock: React.FC = ({ heading, content, h className={cx('integrationBlock__content', { 'integrationBlock__content--collapsedBorder': hasCollapsedBorder, })} + onClick={toggle} > {content}
diff --git a/grafana-plugin/src/containers/AlertRules/AlertRules.tsx b/grafana-plugin/src/containers/AlertRules/AlertRules.tsx index 1909db48..4bb4a088 100644 --- a/grafana-plugin/src/containers/AlertRules/AlertRules.tsx +++ b/grafana-plugin/src/containers/AlertRules/AlertRules.tsx @@ -292,6 +292,7 @@ class AlertRules extends React.Component { )} + {alertReceiveChannel.description && (
void; } const CollapsedIntegrationRouteDisplay: React.FC = observer( - ({ channelFilterId, alertReceiveChannelId, routeIndex }) => { + ({ channelFilterId, alertReceiveChannelId, routeIndex, toggle }) => { const { escalationChainStore, alertReceiveChannelStore } = useStore(); const [routeIdForDeletion, setRouteIdForDeletion] = useState(undefined); @@ -44,6 +45,7 @@ const CollapsedIntegrationRouteDisplay: React.FC
diff --git a/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx b/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx index cc6437bd..788e19f9 100644 --- a/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx +++ b/grafana-plugin/src/containers/IntegrationContainers/ExpandedIntegrationRouteDisplay/ExpandedIntegrationRouteDisplay.tsx @@ -336,18 +336,25 @@ export const RouteButtonsDisplay: React.FC = ({ {!channelFilter.is_default && ( -
+ + {alertReceiveChannel.description && ( +
+
} + severity="info" + /> +
+ )} customIcon: 'plug', canHoverIcon: false, collapsedView: null, - expandedView: , + expandedView: () => , }, { customIcon: 'layer-group', isExpanded: false, isCollapsible: false, canHoverIcon: false, - expandedView: ( + expandedView: () => ( isCollapsible: false, collapsedView: null, canHoverIcon: false, - expandedView: ( + expandedView: () => (
@@ -420,14 +433,15 @@ class Integration2 extends React.Component this.setState((prevState) => ({ newRoutes: prevState.newRoutes.filter((r) => r !== channelFilterId) })); } }, - collapsedView: ( + collapsedView: (toggle) => ( ), - expandedView: ( + expandedView: () => ( = ({ id const { alertReceiveChannelStore } = useStore(); const alertReceiveChannelCounter = alertReceiveChannelStore.counters[id]; const alertReceiveChannel = alertReceiveChannelStore.items[id]; - const isAlertManager = alertReceiveChannel.integration === DATASOURCE_ALERTING; + const isGrafanaDatasource = alertReceiveChannel.integration === DATASOURCE_GRAFANA; const hasAlerts = !!alertReceiveChannelCounter?.alerts_count; return ( = ({ id
} - content={isAlertManager || !hasAlerts ? renderContent() : null} + content={isGrafanaDatasource || !hasAlerts ? renderContent() : null} /> ); @@ -930,14 +945,14 @@ const HowToConnectComponent: React.FC<{ id: AlertReceiveChannel['id'] }> = ({ id )} - {isAlertManager && ( + {isGrafanaDatasource && ( - + Contact Point and - + Notification Policy created in Grafana Alerting @@ -974,8 +989,8 @@ const IntegrationHeader: React.FC = ({ > diff --git a/grafana-plugin/src/utils/consts.ts b/grafana-plugin/src/utils/consts.ts index 386ced4b..b7dba9fc 100644 --- a/grafana-plugin/src/utils/consts.ts +++ b/grafana-plugin/src/utils/consts.ts @@ -34,4 +34,4 @@ export const DOCS_TELEGRAM_SETUP = 'https://grafana.com/docs/oncall/latest/chat- // Make sure if you chage max-width here you also change it in responsive.css export const TABLE_COLUMN_MAX_WIDTH = 1500; -export const DATASOURCE_ALERTING = 'alertmanager'; +export const DATASOURCE_GRAFANA = 'grafana';