forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PMM-12741 Move creation of templated alerts to separate page
- Loading branch information
1 parent
7560424
commit a2f0113
Showing
24 changed files
with
176 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
public/app/features/alerting/unified/components/rule-editor/rule-types/TemplatedAlert.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...cona/integrated-alerting/components/AlertRuleFromTemplate/AlertRuleFromTemplate.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { css } from '@emotion/css'; | ||
|
||
import { GrafanaTheme2 } from '@grafana/data'; | ||
|
||
export const getStyles = (theme: GrafanaTheme2) => ({ | ||
buttonSpinner: css` | ||
margin-right: ${theme.spacing(1)}; | ||
`, | ||
}); |
100 changes: 100 additions & 0 deletions
100
...pp/percona/integrated-alerting/components/AlertRuleFromTemplate/AlertRuleFromTemplate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { FC, useMemo } from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { Button, HorizontalGroup, Spinner, useStyles2 } from '@grafana/ui'; | ||
import { AppChromeUpdate } from 'app/core/components/AppChrome/AppChromeUpdate'; | ||
import { Page } from 'app/core/components/Page/Page'; | ||
import { useAppNotification } from 'app/core/copy/appNotification'; | ||
import { useQueryParams } from 'app/core/hooks/useQueryParams'; | ||
import { useUnifiedAlertingSelector } from 'app/features/alerting/unified/hooks/useUnifiedAlertingSelector'; | ||
import { saveRuleFormAction } from 'app/features/alerting/unified/state/actions'; | ||
import { RuleFormType, RuleFormValues } from 'app/features/alerting/unified/types/rule-form'; | ||
import { initialAsyncRequestState } from 'app/features/alerting/unified/utils/redux'; | ||
import { getDefaultFormValues, getDefaultQueries, MINUTE } from 'app/features/alerting/unified/utils/rule-form'; | ||
import { useDispatch } from 'app/types'; | ||
|
||
import { TemplateStep } from '../TemplateStep/TemplateStep'; | ||
|
||
import { getStyles } from './AlertRuleFromTemplate.styles'; | ||
|
||
export const AlertRuleFromTemplate: FC = () => { | ||
const dispatch = useDispatch(); | ||
const notifyApp = useAppNotification(); | ||
const [queryParams] = useQueryParams(); | ||
const evaluateEvery = MINUTE; | ||
const returnTo = !queryParams['returnTo'] ? '/alerting/list' : String(queryParams['returnTo']); | ||
const defaultValues: RuleFormValues = useMemo(() => { | ||
return { | ||
...getDefaultFormValues(), | ||
condition: 'C', | ||
queries: getDefaultQueries(), | ||
evaluateEvery: evaluateEvery, | ||
type: RuleFormType.templated, | ||
}; | ||
}, [evaluateEvery]); | ||
const methods = useForm({ | ||
mode: 'onSubmit', | ||
defaultValues, | ||
shouldFocusError: true, | ||
}); | ||
const styles = useStyles2(getStyles); | ||
const submitState = useUnifiedAlertingSelector((state) => state.ruleForm.saveRule) || initialAsyncRequestState; | ||
|
||
const submit = (values: RuleFormValues) => { | ||
dispatch( | ||
saveRuleFormAction({ | ||
values: { | ||
...defaultValues, | ||
...values, | ||
annotations: | ||
values.annotations | ||
?.map(({ key, value }) => ({ key: key.trim(), value: value.trim() })) | ||
.filter(({ key, value }) => !!key && !!value) ?? [], | ||
labels: | ||
values.labels | ||
?.map(({ key, value }) => ({ key: key.trim(), value: value.trim() })) | ||
.filter(({ key }) => !!key) ?? [], | ||
}, | ||
redirectOnSave: returnTo, | ||
initialAlertRuleName: defaultValues.name, | ||
evaluateEvery: evaluateEvery, | ||
}) | ||
); | ||
}; | ||
|
||
const onInvalid = () => { | ||
notifyApp.error('There are errors in the form. Please correct them and try again!'); | ||
}; | ||
|
||
const actionButtons = ( | ||
<HorizontalGroup height="auto" justify="flex-end"> | ||
<Button | ||
variant="primary" | ||
type="button" | ||
size="sm" | ||
onClick={methods.handleSubmit((values) => submit(values), onInvalid)} | ||
disabled={submitState.loading} | ||
> | ||
{submitState.loading && <Spinner className={styles.buttonSpinner} inline={true} />} | ||
Save rule and exit | ||
</Button> | ||
<Link to={returnTo}> | ||
<Button variant="secondary" disabled={submitState.loading} type="button" size="sm"> | ||
Cancel | ||
</Button> | ||
</Link> | ||
</HorizontalGroup> | ||
); | ||
|
||
return ( | ||
<FormProvider {...methods}> | ||
<AppChromeUpdate actions={actionButtons} /> | ||
<Page navId="integrated-alerting-new-from-template"> | ||
<TemplateStep /> | ||
</Page> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
export default AlertRuleFromTemplate; |
1 change: 1 addition & 0 deletions
1
public/app/percona/integrated-alerting/components/AlertRuleFromTemplate/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './AlertRuleFromTemplate'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.