From e21eda9413e3d0efb227f49431a29aafa57b50ec Mon Sep 17 00:00:00 2001 From: Konrad Lalik Date: Wed, 13 Aug 2025 16:54:40 +0200 Subject: [PATCH] Alerting: Auto refresh contact points in the rule form (#109539) --- .../ContactPointSelector.tsx | 5 ++++- .../hooks/v0alpha1/useContactPoints.tsx | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/grafana-alerting/src/grafana/contactPoints/components/ContactPointSelector/ContactPointSelector.tsx b/packages/grafana-alerting/src/grafana/contactPoints/components/ContactPointSelector/ContactPointSelector.tsx index 56dacd8dca5..674dbc76dd3 100644 --- a/packages/grafana-alerting/src/grafana/contactPoints/components/ContactPointSelector/ContactPointSelector.tsx +++ b/packages/grafana-alerting/src/grafana/contactPoints/components/ContactPointSelector/ContactPointSelector.tsx @@ -17,7 +17,10 @@ export type ContactPointSelectorProps = CustomComboBoxProps; * @TODO make ComboBox accept a ReactNode so we can use icons and such */ function ContactPointSelector(props: ContactPointSelectorProps) { - const { currentData: contactPoints, isLoading } = useListContactPoints(); + const { currentData: contactPoints, isLoading } = useListContactPoints( + {}, + { refetchOnFocus: true, refetchOnMountOrArgChange: true } + ); // Create a mapping of options with their corresponding contact points const contactPointOptions = chain(contactPoints?.items) diff --git a/packages/grafana-alerting/src/grafana/contactPoints/hooks/v0alpha1/useContactPoints.tsx b/packages/grafana-alerting/src/grafana/contactPoints/hooks/v0alpha1/useContactPoints.tsx index 25d1ab9a6bf..e72577e91d0 100644 --- a/packages/grafana-alerting/src/grafana/contactPoints/hooks/v0alpha1/useContactPoints.tsx +++ b/packages/grafana-alerting/src/grafana/contactPoints/hooks/v0alpha1/useContactPoints.tsx @@ -15,6 +15,16 @@ type ListContactPointsHookResult = TypedUseQueryHookResult< ReturnType >; +// Type for the options that can be passed to the hook +// Based on the pattern used for mutation options in this file +type ListContactPointsQueryArgs = Parameters< + typeof alertingAPI.endpoints.listReceiver.useQuery +>[0]; + +type ListContactPointsQueryOptions = Parameters< + typeof alertingAPI.endpoints.listReceiver.useQuery +>[1]; + /** * useListContactPoints is a hook that fetches a list of contact points * @@ -22,9 +32,15 @@ type ListContactPointsHookResult = TypedUseQueryHookResult< * to ensure that the returned ContactPoints are correctly typed in the data.items array. * * It automatically uses the configured namespace for the query. + * + * @param queryOptions - Optional query options that will be passed to the underlying useListReceiverQuery hook. + * These options can include refetchOnFocus, refetchOnMountOrArgChange, skip, etc. */ -export function useListContactPoints() { - return alertingAPI.useListReceiverQuery({}); +export function useListContactPoints( + queryArgs: ListContactPointsQueryArgs = {}, + queryOptions: ListContactPointsQueryOptions = {} +) { + return alertingAPI.useListReceiverQuery(queryArgs, queryOptions); } // type narrowing mutations requires us to define a few helper types