/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiGlobalToastList, EuiHealth, EuiSpacer, EuiText, EuiTitle, } from '@elastic/eui'; import { Toast } from '@elastic/eui/src/components/toast/global_toast_list'; import React, { useContext, useEffect, useState } from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { ChannelItemType } from '../../../../../models/interfaces'; import { ContentPanel } from '../../../../components/ContentPanel'; import { CoreServicesContext } from '../../../../components/coreServices'; import { ModalConsumer } from '../../../../components/Modal'; import { ServicesContext } from '../../../../services'; import { BREADCRUMBS, ROUTES, } from '../../../../utils/constants'; import { renderTime } from '../../../../utils/helpers'; import { ListItemType } from '../../types'; import { MuteChannelModal } from '../modals/MuteChannelModal'; import { ChannelDetailItems } from './ChannelDetailItems'; import { ChannelDetailsActions } from './ChannelDetailsActions'; import { ChannelSettingsDetails } from './ChannelSettingsDetails'; interface ChannelDetailsProps extends RouteComponentProps<{ id: string }> {} export function ChannelDetails(props: ChannelDetailsProps) { const coreContext = useContext(CoreServicesContext)!; const servicesContext = useContext(ServicesContext)!; const id = props.match.params.id; const [channel, setChannel] = useState(); const [toasts, setToasts] = useState([]); useEffect(() => { coreContext.chrome.setBreadcrumbs([ BREADCRUMBS.NOTIFICATIONS, BREADCRUMBS.CHANNELS, ]); refresh(); }, []); const refresh = async () => { servicesContext.notificationService .getChannel(id) .then(async (response) => { if (response.config_type === 'email') { const channel = await servicesContext.notificationService.getEmailConfigDetails( response ); if (channel.email?.invalid_ids?.length) { coreContext.notifications.toasts.addDanger( 'The sender and/or some recipient groups might have been deleted.' ); } return channel; } return response; }) .then((response) => { setChannel(response); coreContext.chrome.setBreadcrumbs([ BREADCRUMBS.NOTIFICATIONS, BREADCRUMBS.CHANNELS, { text: response?.name || '', href: `${BREADCRUMBS.CHANNEL_DETAILS.href}/${id}`, }, ]); }) .catch((error) => { const newToast: Toast = { id: 'channel-not-found-toast', title: 'Channel not found', color: 'danger', iconType: 'alert', text: ( <> The channel might have been deleted. View Notifications dashboard ), }; setToasts([...toasts, newToast]); }); }; const nameList: Array = [ { title: 'Channel name', description: channel?.name || '-', }, { title: 'Description', description: channel?.description || '-', }, { title: 'Last updated', description: renderTime(channel?.last_updated_time_ms || NaN), }, ]; return ( <> { setToasts(toasts.filter((toast) => toast.id !== removedToast.id)); }} toastLifeTimeMs={60000} />

{channel?.name || '-'}

{channel?.is_enabled === undefined ? null : channel.is_enabled ? ( Active ) : ( Muted )}
{channel && } {channel && ( {({ onShow }) => ( { if (!channel) return; if (channel.is_enabled) { onShow(MuteChannelModal, { selected: [channel], setSelected: (selected: ChannelItemType[]) => setChannel(selected[0]), }); } else { const newChannel = { ...channel, is_enabled: true }; servicesContext.notificationService .updateConfig(channel.config_id, newChannel) .then((resp) => { coreContext.notifications.toasts.addSuccess( `Channel ${channel.name} successfully unmuted.` ); setChannel(newChannel); }); } }} > {channel?.is_enabled ? 'Mute channel' : 'Unmute channel'} )} )}
); }