diff options
Diffstat (limited to 'server/sonar-web/src/main/js/queries/quality-gates.ts')
-rw-r--r-- | server/sonar-web/src/main/js/queries/quality-gates.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/queries/quality-gates.ts b/server/sonar-web/src/main/js/queries/quality-gates.ts index 5b2524e4be2..acc880b1e73 100644 --- a/server/sonar-web/src/main/js/queries/quality-gates.ts +++ b/server/sonar-web/src/main/js/queries/quality-gates.ts @@ -19,6 +19,7 @@ */ import { queryOptions, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; +import { useIntl } from 'react-intl'; import { addGlobalSuccessMessage } from '~design-system'; import { BranchParameters } from '~sonar-aligned/types/branch-like'; import { @@ -238,6 +239,42 @@ export function useUpdateConditionMutation(gateName: string) { }); } +export function useUpdateOrDeleteConditionsMutation(gateName: string, isSingleMetric?: boolean) { + const queryClient = useQueryClient(); + const intl = useIntl(); + + return useMutation({ + mutationFn: ( + conditions: (Omit<Condition, 'metric'> & { metric: string | null | undefined })[], + ) => { + const promiseArr = conditions.map((condition) => + condition.metric + ? updateCondition(condition as Condition) + : deleteCondition({ id: condition.id }), + ); + + return Promise.all(promiseArr); + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: qualityQuery.list() }); + queryClient.invalidateQueries({ queryKey: qualityQuery.detail(gateName) }); + addGlobalSuccessMessage( + intl.formatMessage( + { + id: isSingleMetric + ? 'quality_gates.condition_updated' + : 'quality_gates.conditions_updated_to_the_mode', + }, + { qualityGateName: gateName }, + ), + ); + }, + onError: () => { + queryClient.invalidateQueries({ queryKey: qualityQuery.detail(gateName) }); + }, + }); +} + export function useDeleteConditionMutation(gateName: string) { const queryClient = useQueryClient(); |