Fix: Dynamically add ShowWhen fields to the form watch (#28135)

pull/28264/head
Peter Holmberg 5 years ago committed by GitHub
parent 4ab90f9397
commit 87d6f90acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      public/app/features/alerting/components/NotificationChannelForm.tsx

@ -36,9 +36,22 @@ export const NotificationChannelForm: FC<Props> = ({
}) => {
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();

Loading…
Cancel
Save