From e43bec2cd8b836c6919ddf700917addb8747239c Mon Sep 17 00:00:00 2001 From: Konrad Lalik Date: Mon, 4 Nov 2024 13:15:48 +0100 Subject: [PATCH] Alerting: Fix contact points secrets validation (#95651) Add new condition to the determineRequired function --- .../components/receivers/form/fields/OptionField.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx b/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx index b28228c4ab0..dd50cfa81bb 100644 --- a/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx @@ -294,14 +294,17 @@ const validateOption = (value: string, validationRule: string, required: boolean }; const determineRequired = (option: NotificationChannelOption, getValues: any, pathIndex: string) => { + const secureFields = getValues(`${pathIndex}secureFields`); + const secureSettings = getValues(`${pathIndex}secureSettings`); + if (!option.dependsOn) { return option.required ? 'Required' : false; } - if (isEmpty(getValues(`${pathIndex}secureFields`))) { - const dependentOn = getValues(`${pathIndex}secureSettings.${option.dependsOn}`); - return !Boolean(dependentOn) && option.required ? 'Required' : false; + if (isEmpty(secureFields) || !secureFields[option.dependsOn]) { + const dependentOn = Boolean(secureSettings[option.dependsOn]); + return !dependentOn && option.required ? 'Required' : false; } else { - const dependentOn: boolean = getValues(`${pathIndex}secureFields.${option.dependsOn}`); + const dependentOn = Boolean(secureFields[option.dependsOn]); return !dependentOn && option.required ? 'Required' : false; } };