import React, { useState, ChangeEvent } from 'react'; import { Drawer, Stack, Input, Tag, EmptySearchResult } from '@grafana/ui'; import cn from 'classnames/bind'; import { observer } from 'mobx-react'; import { Block } from 'components/GBlock/Block'; import { IntegrationLogo } from 'components/IntegrationLogo/IntegrationLogo'; import { Text } from 'components/Text/Text'; import { ApiSchemas } from 'network/oncall-api/api.types'; import { useStore } from 'state/useStore'; import { StackSize } from 'utils/consts'; import { IntegrationForm } from './IntegrationForm'; import styles from './IntegrationFormContainer.module.scss'; const cx = cn.bind(styles); interface IntegrationFormContainerProps { id: ApiSchemas['AlertReceiveChannel']['id'] | 'new'; isTableView?: boolean; onHide: () => void; onSubmit: () => Promise; navigateToAlertGroupLabels: (id: ApiSchemas['AlertReceiveChannel']['id']) => void; } export const IntegrationFormContainer = observer((props: IntegrationFormContainerProps) => { const store = useStore(); const { id, onHide, onSubmit, isTableView = true, navigateToAlertGroupLabels } = props; const { alertReceiveChannelStore } = store; const [filterValue, setFilterValue] = useState(''); const [showNewIntegrationForm, setShowNewIntegrationForm] = useState(false); const [selectedOption, setSelectedOption] = useState(undefined); const [showIntegrationsListDrawer, setshowIntegrationsListDrawer] = useState(id === 'new'); const { alertReceiveChannelOptions } = alertReceiveChannelStore; const options = alertReceiveChannelOptions ? alertReceiveChannelOptions.filter((option: ApiSchemas['AlertReceiveChannelIntegrationOptions']) => { if (option.value === 'grafana_alerting' && !window.grafanaBootData.settings.unifiedAlertingEnabled) { return false; } // don't allow creating direct paging integrations if (option.value === 'direct_paging') { return false; } return ( option.display_name.toLowerCase().includes(filterValue.toLowerCase()) && !option.value.toLowerCase().startsWith('legacy_') ); }) : []; return ( <> {showIntegrationsListDrawer && (
Integration receives alerts on an unique API URL, interprets them using set of templates tailored for monitoring system and starts escalations.
) => setFilterValue(e.currentTarget.value)} />
)} {(showNewIntegrationForm || !showIntegrationsListDrawer) && (
)} ); function onBackClick(): void { setShowNewIntegrationForm(false); setshowIntegrationsListDrawer(true); } function onBlockClick(option: ApiSchemas['AlertReceiveChannelIntegrationOptions']): void { setSelectedOption(option); setShowNewIntegrationForm(true); setshowIntegrationsListDrawer(false); } function getTitle(): string { if (!isTableView) { return 'Integration Settings'; } return id === 'new' ? `New ${selectedOption?.display_name} integration` : `Edit integration`; } }); const IntegrationBlocks: React.FC<{ options: Array; onBlockClick: (option: ApiSchemas['AlertReceiveChannelIntegrationOptions']) => void; }> = ({ options, onBlockClick }) => { return (
{options.length ? ( options.map((alertReceiveChannelChoice) => { return ( onBlockClick(alertReceiveChannelChoice)} key={alertReceiveChannelChoice.value} className={cx('card', { card_featured: alertReceiveChannelChoice.featured })} >
{alertReceiveChannelChoice.display_name} {alertReceiveChannelChoice.featured && alertReceiveChannelChoice.featured_tag_name && ( )} {alertReceiveChannelChoice.short_description}
); }) ) : ( Could not find anything matching your query )}
); };