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