mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix wrong texts in titles when cloning templates (#63930)
This commit is contained in:
parent
8aae7be4e5
commit
fa35ed8141
@ -22,6 +22,7 @@ import { GlobalConfigForm } from './components/receivers/GlobalConfigForm';
|
|||||||
import { NewReceiverView } from './components/receivers/NewReceiverView';
|
import { NewReceiverView } from './components/receivers/NewReceiverView';
|
||||||
import { NewTemplateView } from './components/receivers/NewTemplateView';
|
import { NewTemplateView } from './components/receivers/NewTemplateView';
|
||||||
import { ReceiversAndTemplatesView } from './components/receivers/ReceiversAndTemplatesView';
|
import { ReceiversAndTemplatesView } from './components/receivers/ReceiversAndTemplatesView';
|
||||||
|
import { isDuplicating } from './components/receivers/TemplateForm';
|
||||||
import { useAlertManagerSourceName } from './hooks/useAlertManagerSourceName';
|
import { useAlertManagerSourceName } from './hooks/useAlertManagerSourceName';
|
||||||
import { useAlertManagersByPermission } from './hooks/useAlertManagerSources';
|
import { useAlertManagersByPermission } from './hooks/useAlertManagerSources';
|
||||||
import { useUnifiedAlertingSelector } from './hooks/useUnifiedAlertingSelector';
|
import { useUnifiedAlertingSelector } from './hooks/useUnifiedAlertingSelector';
|
||||||
@ -62,7 +63,7 @@ const Receivers = () => {
|
|||||||
const { id, type } = useParams<{ id?: string; type?: PageType }>();
|
const { id, type } = useParams<{ id?: string; type?: PageType }>();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isRoot = location.pathname.endsWith('/alerting/notifications');
|
const isRoot = location.pathname.endsWith('/alerting/notifications');
|
||||||
|
const isduplicatingTemplate = isDuplicating(location);
|
||||||
const configRequests = useUnifiedAlertingSelector((state) => state.amConfigs);
|
const configRequests = useUnifiedAlertingSelector((state) => state.amConfigs);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -96,7 +97,7 @@ const Receivers = () => {
|
|||||||
|
|
||||||
const disableAmSelect = !isRoot;
|
const disableAmSelect = !isRoot;
|
||||||
|
|
||||||
let pageNav = getPageNavigationModel(type, id);
|
let pageNav = getPageNavigationModel(type, id, isduplicatingTemplate);
|
||||||
|
|
||||||
if (!alertManagerSourceName) {
|
if (!alertManagerSourceName) {
|
||||||
return isRoot ? (
|
return isRoot ? (
|
||||||
@ -181,8 +182,14 @@ const Receivers = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getPageNavigationModel(type: PageType | undefined, id: string | undefined) {
|
function getPageNavigationModel(type: PageType | undefined, id: string | undefined, isDuplicatingTemplates: boolean) {
|
||||||
let pageNav: NavModelItem | undefined;
|
let pageNav: NavModelItem | undefined;
|
||||||
|
if (isDuplicatingTemplates) {
|
||||||
|
return {
|
||||||
|
text: `New template`,
|
||||||
|
subTitle: `Create a new template for your notifications`,
|
||||||
|
};
|
||||||
|
}
|
||||||
if (type === 'receivers' || type === 'templates') {
|
if (type === 'receivers' || type === 'templates') {
|
||||||
const objectText = type === 'receivers' ? 'contact point' : 'notification template';
|
const objectText = type === 'receivers' ? 'contact point' : 'notification template';
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
|
import { Location } from 'history';
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { useForm, Validate } from 'react-hook-form';
|
import { useForm, Validate } from 'react-hook-form';
|
||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
import AutoSizer from 'react-virtualized-auto-sizer';
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
@ -37,6 +39,7 @@ interface Props {
|
|||||||
alertManagerSourceName: string;
|
alertManagerSourceName: string;
|
||||||
provenance?: string;
|
provenance?: string;
|
||||||
}
|
}
|
||||||
|
export const isDuplicating = (location: Location) => location.pathname.endsWith('/duplicate');
|
||||||
|
|
||||||
export const TemplateForm: FC<Props> = ({ existing, alertManagerSourceName, config, provenance }) => {
|
export const TemplateForm: FC<Props> = ({ existing, alertManagerSourceName, config, provenance }) => {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
@ -46,6 +49,9 @@ export const TemplateForm: FC<Props> = ({ existing, alertManagerSourceName, conf
|
|||||||
|
|
||||||
const { loading, error } = useUnifiedAlertingSelector((state) => state.saveAMConfig);
|
const { loading, error } = useUnifiedAlertingSelector((state) => state.saveAMConfig);
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
const isduplicating = isDuplicating(location);
|
||||||
|
|
||||||
const submit = (values: Values) => {
|
const submit = (values: Values) => {
|
||||||
// wrap content in "define" if it's not already wrapped, in case user did not do it/
|
// wrap content in "define" if it's not already wrapped, in case user did not do it/
|
||||||
// it's not obvious that this is needed for template to work
|
// it's not obvious that this is needed for template to work
|
||||||
@ -102,10 +108,9 @@ export const TemplateForm: FC<Props> = ({ existing, alertManagerSourceName, conf
|
|||||||
? true
|
? true
|
||||||
: 'Another template with this name already exists.';
|
: 'Another template with this name already exists.';
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(submit)}>
|
<form onSubmit={handleSubmit(submit)}>
|
||||||
<h4>{existing ? 'Edit notification template' : 'Create notification template'}</h4>
|
<h4>{existing && !isduplicating ? 'Edit notification template' : 'Create notification template'}</h4>
|
||||||
{error && (
|
{error && (
|
||||||
<Alert severity="error" title="Error saving template">
|
<Alert severity="error" title="Error saving template">
|
||||||
{error.message || (error as any)?.data?.message || String(error)}
|
{error.message || (error as any)?.data?.message || String(error)}
|
||||||
|
Loading…
Reference in New Issue
Block a user