diff --git a/src/components/IntegrationContactPoint/IntegrationContactPoint.tsx b/src/components/IntegrationContactPoint/IntegrationContactPoint.tsx index c386482ffb..7454403a72 100644 --- a/src/components/IntegrationContactPoint/IntegrationContactPoint.tsx +++ b/src/components/IntegrationContactPoint/IntegrationContactPoint.tsx @@ -1,7 +1,18 @@ import React, { useEffect, useReducer } from 'react'; import { SelectableValue } from '@grafana/data'; -import { Button, Drawer, HorizontalGroup, Icon, IconButton, Select, Tooltip, VerticalGroup } from '@grafana/ui'; +import { + Button, + Drawer, + HorizontalGroup, + Icon, + IconButton, + Input, + RadioButtonGroup, + Select, + Tooltip, + VerticalGroup, +} from '@grafana/ui'; import cn from 'classnames/bind'; import { observer } from 'mobx-react'; @@ -22,6 +33,7 @@ interface IntegrationContactPointState { isLoading: boolean; isDrawerOpen: boolean; isConnectOpen: boolean; + isExistingContactPoint: boolean; allContactPoints: Array<{ name: string; uid: string; contact_points: string[] }>; // dropdown selected values @@ -49,6 +61,7 @@ const IntegrationContactPoint: React.FC<{ selectedAlertManager, selectedContactPoint, isConnectOpen, + isExistingContactPoint, }, setState, ] = useReducer( @@ -59,6 +72,7 @@ const IntegrationContactPoint: React.FC<{ { isLoading: false, isDrawerOpen: false, + isExistingContactPoint: true, contactPointOptions: [], dataSourceOptions: [], allContactPoints: [], @@ -78,6 +92,17 @@ const IntegrationContactPoint: React.FC<{ })(); }, []); + const radioOptions = [ + { + label: 'Connect existing Contact point', + value: 'existing', + }, + { + label: 'Create a new one', + value: 'new', + }, + ]; + return ( setState({ isConnectOpen: !isConnectOpen })} > - - Connect existing contact point + + + Grafana Alerting Contact point + + + {isConnectOpen ? : } - {isConnectOpen && ( - - - - - - - {isLoading && } - - - )} + {renderConnectSection()} - - - If you didn't find relevant Alerting Contact point, you can{' '} - - create a new one - - - )} @@ -204,6 +190,68 @@ const IntegrationContactPoint: React.FC<{ /> ); + function renderConnectSection() { + if (!isConnectOpen) { + return null; + } + + return ( + + { + setState({ + isExistingContactPoint: radioValue === 'existing', + contactPointOptions: [], + selectedAlertManager: null, + selectedContactPoint: null, + }); + }} + /> + + + ) : ( + { + const value = (target as HTMLInputElement).value; + setState({ selectedContactPoint: value }); + }} + /> + )} + + + + + {isLoading && } + + + ); + } + function renderActions(item: ContactPoint) { return ( @@ -286,15 +334,19 @@ const IntegrationContactPoint: React.FC<{ function onContactPointConnect() { setState({ isLoading: true }); - alertReceiveChannelStore - .connectContactPoint(id, selectedAlertManager, selectedContactPoint) + + (isExistingContactPoint + ? alertReceiveChannelStore.connectContactPoint(id, selectedAlertManager, selectedContactPoint) + : alertReceiveChannelStore.createContactPoint(id, selectedAlertManager, selectedContactPoint) + ) .then(() => { closeDrawer(); openNotification('A new contact point has been connected to your integration'); alertReceiveChannelStore.updateConnectedContactPoints(id); }) - .catch(() => { - openErrorNotification('An error has occurred. Please try again.'); + .catch((ex) => { + const error = ex.response?.data?.detail ?? 'An error has occurred. Please try again.'; + openErrorNotification(error); }) .finally(() => setState({ isLoading: false })); } diff --git a/src/pages/integration/Integration.module.scss b/src/pages/integration/Integration.module.scss index a20bf9662a..14a17809e6 100644 --- a/src/pages/integration/Integration.module.scss +++ b/src/pages/integration/Integration.module.scss @@ -225,6 +225,9 @@ $LARGE-MARGIN: 24px; border: var(--border-weak); border-radius: var(--border-radius); } + &__connect-toggler { + width: 100%; + } &__connect-toggler:hover { cursor: pointer; }