11import { css } from '@emotion/css' ;
22import React , { FC , useMemo , useState } from 'react' ;
33import { FormProvider , useForm , UseFormWatch } from 'react-hook-form' ;
4- import { useDispatch } from 'react-redux' ;
4+ import { useDispatch , useSelector } from 'react-redux' ;
55import { Link } from 'react-router-dom' ;
66
77import { GrafanaTheme2 } from '@grafana/data' ;
88import { Button , ConfirmModal , CustomScrollbar , PageToolbar , Spinner , useStyles2 } from '@grafana/ui' ;
99import { useAppNotification } from 'app/core/copy/appNotification' ;
1010import { useCleanup } from 'app/core/hooks/useCleanup' ;
1111import { useQueryParams } from 'app/core/hooks/useQueryParams' ;
12+ import { getPerconaSettings } from 'app/percona/shared/core/selectors' ;
1213import { RuleWithLocation } from 'app/types/unified-alerting' ;
1314
1415import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector' ;
@@ -23,6 +24,7 @@ import { DetailsStep } from './DetailsStep';
2324import { GrafanaEvaluationBehavior } from './GrafanaEvaluationBehavior' ;
2425import { NotificationsStep } from './NotificationsStep' ;
2526import { RuleInspector } from './RuleInspector' ;
27+ import { TemplateStep } from './TemplateStep/TemplateStep' ;
2628import { QueryAndAlertConditionStep } from './query-and-alert-condition/QueryAndAlertConditionStep' ;
2729
2830type Props = {
@@ -35,6 +37,7 @@ export const AlertRuleForm: FC<Props> = ({ existing }) => {
3537 const notifyApp = useAppNotification ( ) ;
3638 const [ queryParams ] = useQueryParams ( ) ;
3739 const [ showEditYaml , setShowEditYaml ] = useState ( false ) ;
40+ const { result } = useSelector ( getPerconaSettings ) ;
3841
3942 const returnTo : string = ( queryParams [ 'returnTo' ] as string | undefined ) ?? '/alerting/list' ;
4043 const [ showDeleteModal , setShowDeleteModal ] = useState < boolean > ( false ) ;
@@ -47,9 +50,12 @@ export const AlertRuleForm: FC<Props> = ({ existing }) => {
4750 ...getDefaultFormValues ( ) ,
4851 queries : getDefaultQueries ( ) ,
4952 ...( queryParams [ 'defaults' ] ? JSON . parse ( queryParams [ 'defaults' ] as string ) : { } ) ,
50- type : RuleFormType . grafana ,
53+ // @PERCONA
54+ // Set templated as default
55+ type : result && ! ! result . alertingEnabled ? RuleFormType . templated : RuleFormType . grafana ,
56+ group : result && ! ! result . alertingEnabled ? 'default-alert-group' : '' ,
5157 } ;
52- } , [ existing , queryParams ] ) ;
58+ } , [ existing , queryParams , result ] ) ;
5359
5460 const formAPI = useForm < RuleFormValues > ( {
5561 mode : 'onSubmit' ,
@@ -63,6 +69,7 @@ export const AlertRuleForm: FC<Props> = ({ existing }) => {
6369 const dataSourceName = watch ( 'dataSourceName' ) ;
6470
6571 const showStep2 = Boolean ( type && ( type === RuleFormType . grafana || ! ! dataSourceName ) ) ;
72+ const showTemplateStep = type === RuleFormType . templated ;
6673
6774 const submitState = useUnifiedAlertingSelector ( ( state ) => state . ruleForm . saveRule ) || initialAsyncRequestState ;
6875 useCleanup ( ( state ) => state . unifiedAlerting . ruleForm . saveRule ) ;
@@ -152,6 +159,8 @@ export const AlertRuleForm: FC<Props> = ({ existing }) => {
152159 < CustomScrollbar autoHeightMin = "100%" hideHorizontalTrack = { true } >
153160 < div className = { styles . contentInner } >
154161 < QueryAndAlertConditionStep editingExistingRule = { ! ! existing } />
162+ { /* @PERCONA */ }
163+ { showTemplateStep && < TemplateStep /> }
155164 { showStep2 && (
156165 < >
157166 { type === RuleFormType . grafana ? < GrafanaEvaluationBehavior /> : < CloudEvaluationBehavior /> }
0 commit comments