From 87d6f90acb27e11ee8e009687e5998a14d071db5 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Tue, 13 Oct 2020 09:11:15 +0200 Subject: [PATCH] Fix: Dynamically add ShowWhen fields to the form watch (#28135) --- .../components/NotificationChannelForm.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/public/app/features/alerting/components/NotificationChannelForm.tsx b/public/app/features/alerting/components/NotificationChannelForm.tsx index 28b23697838..7820e942b41 100644 --- a/public/app/features/alerting/components/NotificationChannelForm.tsx +++ b/public/app/features/alerting/components/NotificationChannelForm.tsx @@ -36,9 +36,22 @@ export const NotificationChannelForm: FC = ({ }) => { const styles = getStyles(useTheme()); + /* + Finds fields that have dependencies on other fields and removes duplicates. + Needs to be prefixed with settings. + */ + const fieldsToWatch = + new Set( + selectedChannel?.options + .filter(o => o.showWhen.field) + .map(option => { + return `settings.${option.showWhen.field}`; + }) + ) || []; + useEffect(() => { - watch(['type', 'settings.priority', 'sendReminder', 'uploadImage']); - }, []); + watch(['type', 'sendReminder', 'uploadImage', ...fieldsToWatch]); + }, [fieldsToWatch]); const currentFormValues = getValues();