Alerting: Auto refresh contact points in the rule form (#109539)

This commit is contained in:
Konrad Lalik 2025-08-13 16:54:40 +02:00 committed by GitHub
parent 384ec28dfd
commit e21eda9413
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 3 deletions

View File

@ -17,7 +17,10 @@ export type ContactPointSelectorProps = CustomComboBoxProps<ContactPoint>;
* @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)

View File

@ -15,6 +15,16 @@ type ListContactPointsHookResult = TypedUseQueryHookResult<
ReturnType<typeof fetchBaseQuery>
>;
// 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<ListContactPointsHookResult>
>[0];
type ListContactPointsQueryOptions = Parameters<
typeof alertingAPI.endpoints.listReceiver.useQuery<ListContactPointsHookResult>
>[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<ListContactPointsHookResult>({});
export function useListContactPoints(
queryArgs: ListContactPointsQueryArgs = {},
queryOptions: ListContactPointsQueryOptions = {}
) {
return alertingAPI.useListReceiverQuery<ListContactPointsHookResult>(queryArgs, queryOptions);
}
// type narrowing mutations requires us to define a few helper types