Skip to content

Commit a9ba437

Browse files
committed
Added unique mutation keys
1 parent fa32fd9 commit a9ba437

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

src/Exceptionless.Web/ClientApp/src/lib/features/events/api.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export async function invalidatePersistentEventQueries(queryClient: QueryClient,
3131

3232
export const queryKeys = {
3333
count: () => [...queryKeys.type, 'count'] as const,
34+
deleteEvent: (ids: string[] | undefined) => [...queryKeys.type, 'delete', ...(ids ?? [])] as const,
3435
id: (id: string | undefined) => [...queryKeys.type, id] as const,
3536
projectsCount: (id: string | undefined) => [...queryKeys.type, 'projects', id] as const,
36-
remove: (ids: string[] | undefined) => [...queryKeys.type, 'remove', ...(ids ?? [])] as const,
3737
stacks: (id: string | undefined) => [...queryKeys.type, 'stacks', id] as const,
3838
stacksCount: (id: string | undefined) => [...queryKeys.stacks(id), 'count'] as const,
3939
type: ['PersistentEvent'] as const
@@ -130,7 +130,7 @@ export function deleteEvent(request: DeleteEventsRequest) {
130130

131131
return response.data as WorkInProgressResult;
132132
},
133-
mutationKey: queryKeys.remove(request.route.ids),
133+
mutationKey: queryKeys.deleteEvent(request.route.ids),
134134
onError: () => {
135135
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
136136
},

src/Exceptionless.Web/ClientApp/src/lib/features/projects/api.svelte.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export async function invalidateProjectQueries(queryClient: QueryClient, message
2222
}
2323

2424
export const queryKeys = {
25+
deletePromotedTab: (id: string | undefined) => [...queryKeys.id(id), 'demote-tab'] as const,
2526
id: (id: string | undefined) => [...queryKeys.type, id] as const,
2627
organization: (id: string | undefined) => [...queryKeys.type, 'organization', id] as const,
28+
postPromotedTab: (id: string | undefined) => [...queryKeys.id(id), 'promote-tab'] as const,
2729
type: ['Project'] as const
2830
};
2931

@@ -69,7 +71,7 @@ export function deletePromotedTab(request: deletePromotedTabRequest) {
6971

7072
return response.ok;
7173
},
72-
mutationKey: queryKeys.id(request.route.id),
74+
mutationKey: queryKeys.deletePromotedTab(request.route.id),
7375
onError: () => {
7476
queryClient.invalidateQueries({ queryKey: queryKeys.id(request.route.id) });
7577
},
@@ -139,7 +141,7 @@ export function postPromotedTab(request: PostPromotedTabRequest) {
139141

140142
return response.ok;
141143
},
142-
mutationKey: queryKeys.id(request.route.id),
144+
mutationKey: queryKeys.postPromotedTab(request.route.id),
143145
onError: () => {
144146
queryClient.invalidateQueries({ queryKey: queryKeys.id(request.route.id) });
145147
},

src/Exceptionless.Web/ClientApp/src/lib/features/stacks/api.svelte.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { WebSocketMessageValue } from '$features/websockets/models';
2+
import type { WorkInProgressResult } from '$shared/models';
23

34
import { accessToken } from '$features/auth/index.svelte';
45
import { type FetchClientResponse, type ProblemDetails, useFetchClient } from '@exceptionless/fetchclient';
@@ -15,11 +16,18 @@ export async function invalidateStackQueries(queryClient: QueryClient, message:
1516
}
1617
}
1718

18-
// TODO: Make sure all api events have a unique query key for mutations.
1919
export const queryKeys = {
20+
deleteMarkCritical: (ids: string[] | undefined) => [...queryKeys.ids(ids), 'mark-not-critical'] as const,
21+
deleteStack: (ids: string[] | undefined) => [...queryKeys.ids(ids), 'delete'] as const,
2022
id: (id: string | undefined) => [...queryKeys.type, id] as const,
2123
ids: (ids: string[] | undefined) => [...queryKeys.type, ...(ids ?? [])] as const,
22-
remove: (ids: string[] | undefined) => [...queryKeys.type, 'remove', ...(ids ?? [])] as const,
24+
postAddLink: (id: string | undefined) => [...queryKeys.id(id), 'add-link'] as const,
25+
postChangeStatus: (ids: string[] | undefined) => [...queryKeys.ids(ids), 'change-status'] as const,
26+
postMarkCritical: (ids: string[] | undefined) => [...queryKeys.ids(ids), 'mark-critical'] as const,
27+
postMarkFixed: (ids: string[] | undefined) => [...queryKeys.ids(ids), 'mark-fixed'] as const,
28+
postMarkSnoozed: (ids: string[] | undefined) => [...queryKeys.ids(ids), 'mark-snoozed'] as const,
29+
postPromote: (ids: string[] | undefined) => [...queryKeys.ids(ids), 'promote'] as const,
30+
postRemoveLink: (id: string | undefined) => [...queryKeys.id(id), 'remove-link'] as const,
2331
type: ['Stack'] as const
2432
};
2533

@@ -85,7 +93,7 @@ export function deleteMarkCritical(request: PostMarkCriticalRequest) {
8593
const client = useFetchClient();
8694
await client.delete(`stacks/${request.route.ids?.join(',')}/mark-critical`);
8795
},
88-
mutationKey: queryKeys.ids(request.route.ids),
96+
mutationKey: queryKeys.deleteMarkCritical(request.route.ids),
8997
onError: () => {
9098
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
9199
},
@@ -97,13 +105,15 @@ export function deleteMarkCritical(request: PostMarkCriticalRequest) {
97105

98106
export function deleteStack(request: DeleteStackRequest) {
99107
const queryClient = useQueryClient();
100-
return createMutation<void, ProblemDetails, void>(() => ({
108+
return createMutation<WorkInProgressResult, ProblemDetails, void>(() => ({
101109
enabled: () => !!accessToken.value && !!request.route.ids?.length,
102110
mutationFn: async () => {
103111
const client = useFetchClient();
104-
await client.delete(`stacks/${request.route.ids?.join(',')}`);
112+
const response = await client.delete(`stacks/${request.route.ids?.join(',')}`);
113+
114+
return response.data as WorkInProgressResult;
105115
},
106-
mutationKey: queryKeys.remove(request.route.ids),
116+
mutationKey: queryKeys.deleteStack(request.route.ids),
107117
onError: () => {
108118
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
109119
},
@@ -136,7 +146,7 @@ export function postAddLink(request: PostAddLinkRequest) {
136146
const client = useFetchClient();
137147
await client.post(`stacks/${request.route.id}/add-link`, { value: url });
138148
},
139-
mutationKey: queryKeys.id(request.route.id),
149+
mutationKey: queryKeys.postAddLink(request.route.id),
140150
onError: () => {
141151
queryClient.invalidateQueries({ queryKey: queryKeys.id(request.route.id) });
142152
},
@@ -154,7 +164,7 @@ export function postChangeStatus(request: PostChangeStatusRequest) {
154164
const client = useFetchClient();
155165
await client.post(`stacks/${request.route.ids?.join(',')}/change-status`, undefined, { params: { status } });
156166
},
157-
mutationKey: queryKeys.ids(request.route.ids),
167+
mutationKey: queryKeys.postChangeStatus(request.route.ids),
158168
onError: () => {
159169
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
160170
},
@@ -172,7 +182,7 @@ export function postMarkCritical(request: PostMarkCriticalRequest) {
172182
const client = useFetchClient();
173183
await client.post(`stacks/${request.route.ids?.join(',')}/mark-critical`);
174184
},
175-
mutationKey: queryKeys.ids(request.route.ids),
185+
mutationKey: queryKeys.postMarkCritical(request.route.ids),
176186
onError: () => {
177187
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
178188
},
@@ -190,7 +200,7 @@ export function postMarkFixed(request: PostMarkFixedRequest) {
190200
const client = useFetchClient();
191201
await client.post(`stacks/${request.route.ids?.join(',')}/mark-fixed`, undefined, { params: { version } });
192202
},
193-
mutationKey: queryKeys.ids(request.route.ids),
203+
mutationKey: queryKeys.postMarkFixed(request.route.ids),
194204
onError: () => {
195205
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
196206
},
@@ -208,7 +218,7 @@ export function postMarkSnoozed(request: PostMarkSnoozedRequest) {
208218
const client = useFetchClient();
209219
await client.post(`stacks/${request.route.ids?.join(',')}/mark-snoozed`, undefined, { params: { snoozeUntilUtc: snoozeUntilUtc.toISOString() } });
210220
},
211-
mutationKey: queryKeys.ids(request.route.ids),
221+
mutationKey: queryKeys.postMarkSnoozed(request.route.ids),
212222
onError: () => {
213223
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
214224
},
@@ -230,7 +240,7 @@ export function postPromote(request: PostPromoteRequest) {
230240

231241
return response;
232242
},
233-
mutationKey: queryKeys.ids(request.route.ids),
243+
mutationKey: queryKeys.postPromote(request.route.ids),
234244
onError: () => {
235245
request.route.ids?.forEach((id) => queryClient.invalidateQueries({ queryKey: queryKeys.id(id) }));
236246
},
@@ -248,7 +258,7 @@ export function postRemoveLink(request: PostRemoveLinkRequest) {
248258
const client = useFetchClient();
249259
await client.post(`stacks/${request.route.id}/remove-link`, { value: url });
250260
},
251-
mutationKey: queryKeys.id(request.route.id),
261+
mutationKey: queryKeys.postRemoveLink(request.route.id),
252262
onError: () => {
253263
queryClient.invalidateQueries({ queryKey: queryKeys.id(request.route.id) });
254264
},

src/Exceptionless.Web/ClientApp/src/lib/features/users/api.svelte.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const queryKeys = {
2424
id: (id: string | undefined) => [...queryKeys.type, id] as const,
2525
idEmailAddress: (id?: string) => [...queryKeys.id(id), 'email-address'] as const,
2626
me: () => [...queryKeys.type, 'me'] as const,
27+
patchUser: (id: string | undefined) => [...queryKeys.id(id), 'patch'] as const,
28+
postEmailAddress: (id: string | undefined) => [...queryKeys.idEmailAddress(id), 'update'] as const,
2729
type: ['User'] as const
2830
};
2931

@@ -68,7 +70,7 @@ export function patchUser(request: PatchUserRequest) {
6870
const response = await client.patchJSON<User>(`users/${request.route.id}`, data);
6971
return response.data!;
7072
},
71-
mutationKey: queryKeys.id(request.route.id),
73+
mutationKey: queryKeys.patchUser(request.route.id),
7274
onError: () => {
7375
queryClient.invalidateQueries({ queryKey: queryKeys.id(request.route.id) });
7476
},
@@ -92,7 +94,7 @@ export function postEmailAddress(request: PostEmailAddressRequest) {
9294
const response = await client.postJSON<UpdateEmailAddressResult>(`users/${request.route.id}/email-address/${data.email_address}`);
9395
return response.data!;
9496
},
95-
mutationKey: queryKeys.idEmailAddress(request.route.id),
97+
mutationKey: queryKeys.postEmailAddress(request.route.id),
9698
onSuccess: (data, variables) => {
9799
const partialUserData: Partial<User> = { email_address: variables.email_address, is_email_address_verified: data.is_verified };
98100

0 commit comments

Comments
 (0)