From 772ef1626fc933be146b7caa00f35bd61fb646a5 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 23 Nov 2021 13:28:15 -0500 Subject: [PATCH] fix: use better type assertion for initialAsyncRequestState (#42087) (#42137) (cherry picked from commit ca7a62682e52e59f4ae12bc25fff0707c657dd2f) Co-authored-by: Gilles De Mey --- public/app/features/alerting/unified/AmRoutes.tsx | 4 ++++ .../unified/components/admin/AlertmanagerConfig.tsx | 2 +- public/app/features/alerting/unified/utils/redux.ts | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/public/app/features/alerting/unified/AmRoutes.tsx b/public/app/features/alerting/unified/AmRoutes.tsx index cc1effb81d1..bb237b25834 100644 --- a/public/app/features/alerting/unified/AmRoutes.tsx +++ b/public/app/features/alerting/unified/AmRoutes.tsx @@ -58,6 +58,10 @@ const AmRoutes: FC = () => { useCleanup((state) => state.unifiedAlerting.saveAMConfig); const handleSave = (data: Partial) => { + if (!result) { + return; + } + const newData = formAmRouteToAmRoute( alertManagerSourceName, { diff --git a/public/app/features/alerting/unified/components/admin/AlertmanagerConfig.tsx b/public/app/features/alerting/unified/components/admin/AlertmanagerConfig.tsx index ec78d1c79c1..662d97a1c5d 100644 --- a/public/app/features/alerting/unified/components/admin/AlertmanagerConfig.tsx +++ b/public/app/features/alerting/unified/components/admin/AlertmanagerConfig.tsx @@ -55,7 +55,7 @@ export default function AlertmanagerConfig(): JSX.Element { const loading = isDeleting || isLoadingConfig || isSaving; const onSubmit = (values: FormValues) => { - if (alertManagerSourceName) { + if (alertManagerSourceName && config) { dispatch( updateAlertManagerConfigAction({ newConfig: JSON.parse(values.configJSON), diff --git a/public/app/features/alerting/unified/utils/redux.ts b/public/app/features/alerting/unified/utils/redux.ts index 068c3c4f920..b2c50b2658e 100644 --- a/public/app/features/alerting/unified/utils/redux.ts +++ b/public/app/features/alerting/unified/utils/redux.ts @@ -13,8 +13,13 @@ export interface AsyncRequestState { requestId?: string; } -export const initialAsyncRequestState: AsyncRequestState = Object.freeze({ +export const initialAsyncRequestState: Pick< + AsyncRequestState, + 'loading' | 'dispatched' | 'result' | 'error' +> = Object.freeze({ loading: false, + result: undefined, + error: undefined, dispatched: false, });