Skip to content

Commit 4b46e74

Browse files
authored
feat(aci): Allow specific detector types to be passed to fetching hooks (#99486)
1 parent d84be0d commit 4b46e74

File tree

1 file changed

+19
-24
lines changed
  • static/app/views/detectors/hooks

1 file changed

+19
-24
lines changed

static/app/views/detectors/hooks/index.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {t} from 'sentry/locale';
22
import AlertStore from 'sentry/stores/alertStore';
3-
import type {
4-
BaseDetectorUpdatePayload,
5-
Detector,
3+
import {
4+
type BaseDetectorUpdatePayload,
5+
type Detector,
66
} from 'sentry/types/workflowEngine/detectors';
77
import type {ApiQueryKey, UseApiQueryOptions} from 'sentry/utils/queryClient';
88
import {
@@ -44,13 +44,13 @@ export const makeDetectorListQueryKey = ({
4444
{query: {query, sortBy, project: projects, per_page: limit, cursor, id: ids}},
4545
];
4646

47-
export function useDetectorsQuery(
47+
export function useDetectorsQuery<T extends Detector = Detector>(
4848
{ids, query, sortBy, projects, limit, cursor}: UseDetectorsQueryKeyOptions = {},
49-
queryOptions: Partial<UseApiQueryOptions<Detector[]>> = {}
49+
queryOptions: Partial<UseApiQueryOptions<T[]>> = {}
5050
) {
5151
const org = useOrganization();
5252

53-
return useApiQuery<Detector[]>(
53+
return useApiQuery<T[]>(
5454
makeDetectorListQueryKey({
5555
orgSlug: org.slug,
5656
query,
@@ -68,12 +68,12 @@ export function useDetectorsQuery(
6868
);
6969
}
7070

71-
export function useCreateDetector() {
71+
export function useCreateDetector<T extends Detector = Detector>() {
7272
const org = useOrganization();
7373
const api = useApi({persistInFlight: true});
7474
const queryClient = useQueryClient();
7575

76-
return useMutation<Detector, void, BaseDetectorUpdatePayload>({
76+
return useMutation<T, void, BaseDetectorUpdatePayload>({
7777
mutationFn: data =>
7878
api.requestPromise(`/organizations/${org.slug}/detectors/`, {
7979
method: 'POST',
@@ -90,16 +90,12 @@ export function useCreateDetector() {
9090
});
9191
}
9292

93-
export function useUpdateDetector() {
93+
export function useUpdateDetector<T extends Detector = Detector>() {
9494
const org = useOrganization();
9595
const api = useApi({persistInFlight: true});
9696
const queryClient = useQueryClient();
9797

98-
return useMutation<
99-
Detector,
100-
void,
101-
{detectorId: string} & Partial<BaseDetectorUpdatePayload>
102-
>({
98+
return useMutation<T, void, {detectorId: string} & Partial<BaseDetectorUpdatePayload>>({
10399
mutationFn: data =>
104100
api.requestPromise(`/organizations/${org.slug}/detectors/${data.detectorId}/`, {
105101
method: 'PUT',
@@ -127,22 +123,21 @@ const makeDetectorDetailsQueryKey = ({
127123
orgSlug: string;
128124
}): ApiQueryKey => [`/organizations/${orgSlug}/detectors/${detectorId}/`];
129125

130-
export function useDetectorQuery(detectorId: string) {
126+
export function useDetectorQuery<T extends Detector = Detector>(detectorId: string) {
131127
const org = useOrganization();
132128

133-
return useApiQuery<Detector>(
134-
makeDetectorDetailsQueryKey({orgSlug: org.slug, detectorId}),
135-
{
136-
staleTime: 0,
137-
retry: false,
138-
}
139-
);
129+
return useApiQuery<T>(makeDetectorDetailsQueryKey({orgSlug: org.slug, detectorId}), {
130+
staleTime: 0,
131+
retry: false,
132+
});
140133
}
141134

142-
export function useDetectorQueriesByIds(detectorId: string[]) {
135+
export function useDetectorQueriesByIds<T extends Detector = Detector>(
136+
detectorId: string[]
137+
) {
143138
const org = useOrganization();
144139

145-
return useApiQueries<Detector>(
140+
return useApiQueries<T>(
146141
detectorId.map(id =>
147142
makeDetectorDetailsQueryKey({orgSlug: org.slug, detectorId: id})
148143
),

0 commit comments

Comments
 (0)