[v11.3.x] Alerting: Fix contact points secrets validation (#95777)

Alerting: Fix contact points secrets validation (#95651)

Add new condition to the determineRequired function

(cherry picked from commit e43bec2cd8)

Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-11-04 15:10:03 +01:00
committed by GitHub
co-authored by Konrad Lalik
parent 28f9eb3221
commit e31c4fc59b
@@ -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;
}
};