The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/alerting/NewNotificationChannelPage.tsx

82 lines
2.8 KiB

import React, { PureComponent } from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { config } from '@grafana/runtime';
import { Form } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
import { getNavModel } from 'app/core/selectors/navModel';
import { NotificationChannelDTO, StoreState } from '../../types';
import { NotificationChannelForm } from './components/NotificationChannelForm';
import { createNotificationChannel, loadNotificationTypes, testNotificationChannel } from './state/actions';
import { resetSecureField } from './state/reducers';
import {
defaultValues,
mapChannelsToSelectableValue,
transformSubmitData,
transformTestData,
} from './utils/notificationChannels';
class NewNotificationChannelPage extends PureComponent<Props> {
componentDidMount() {
this.props.loadNotificationTypes();
}
onSubmit = (data: NotificationChannelDTO) => {
this.props.createNotificationChannel(transformSubmitData({ ...defaultValues, ...data }));
};
onTestChannel = (data: NotificationChannelDTO) => {
this.props.testNotificationChannel(transformTestData({ ...defaultValues, ...data }));
};
render() {
const { navModel, notificationChannelTypes } = this.props;
return (
<Page navModel={navModel}>
<Page.Contents>
<h2 className="page-sub-heading">New notification channel</h2>
<Form onSubmit={this.onSubmit} validateOn="onChange" defaultValues={defaultValues} maxWidth={600}>
{({ register, errors, control, getValues, watch }) => {
const selectedChannel = notificationChannelTypes.find((c) => c.value === getValues().type.value);
return (
<NotificationChannelForm
selectableChannels={mapChannelsToSelectableValue(notificationChannelTypes, true)}
selectedChannel={selectedChannel}
onTestChannel={this.onTestChannel}
register={register}
errors={errors}
getValues={getValues}
control={control}
watch={watch}
imageRendererAvailable={config.rendererAvailable}
resetSecureField={this.props.resetSecureField}
secureFields={{}}
/>
);
}}
</Form>
</Page.Contents>
</Page>
);
}
}
const mapStateToProps = (state: StoreState) => ({
navModel: getNavModel(state.navIndex, 'channels'),
notificationChannelTypes: state.notificationChannel.notificationChannelTypes,
});
const mapDispatchToProps = {
createNotificationChannel,
loadNotificationTypes,
testNotificationChannel,
resetSecureField,
};
const connector = connect(mapStateToProps, mapDispatchToProps);
type Props = ConnectedProps<typeof connector>;
export default connector(NewNotificationChannelPage);