1
1
import type { WebSocketMessageValue } from '$features/websockets/models' ;
2
+ import type { WorkInProgressResult } from '$shared/models' ;
2
3
3
4
import { accessToken } from '$features/auth/index.svelte' ;
4
5
import { type FetchClientResponse , type ProblemDetails , useFetchClient } from '@exceptionless/fetchclient' ;
@@ -15,11 +16,18 @@ export async function invalidateStackQueries(queryClient: QueryClient, message:
15
16
}
16
17
}
17
18
18
- // TODO: Make sure all api events have a unique query key for mutations.
19
19
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 ,
20
22
id : ( id : string | undefined ) => [ ...queryKeys . type , id ] as const ,
21
23
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 ,
23
31
type : [ 'Stack' ] as const
24
32
} ;
25
33
@@ -85,7 +93,7 @@ export function deleteMarkCritical(request: PostMarkCriticalRequest) {
85
93
const client = useFetchClient ( ) ;
86
94
await client . delete ( `stacks/${ request . route . ids ?. join ( ',' ) } /mark-critical` ) ;
87
95
} ,
88
- mutationKey : queryKeys . ids ( request . route . ids ) ,
96
+ mutationKey : queryKeys . deleteMarkCritical ( request . route . ids ) ,
89
97
onError : ( ) => {
90
98
request . route . ids ?. forEach ( ( id ) => queryClient . invalidateQueries ( { queryKey : queryKeys . id ( id ) } ) ) ;
91
99
} ,
@@ -97,13 +105,15 @@ export function deleteMarkCritical(request: PostMarkCriticalRequest) {
97
105
98
106
export function deleteStack ( request : DeleteStackRequest ) {
99
107
const queryClient = useQueryClient ( ) ;
100
- return createMutation < void , ProblemDetails , void > ( ( ) => ( {
108
+ return createMutation < WorkInProgressResult , ProblemDetails , void > ( ( ) => ( {
101
109
enabled : ( ) => ! ! accessToken . value && ! ! request . route . ids ?. length ,
102
110
mutationFn : async ( ) => {
103
111
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 ;
105
115
} ,
106
- mutationKey : queryKeys . remove ( request . route . ids ) ,
116
+ mutationKey : queryKeys . deleteStack ( request . route . ids ) ,
107
117
onError : ( ) => {
108
118
request . route . ids ?. forEach ( ( id ) => queryClient . invalidateQueries ( { queryKey : queryKeys . id ( id ) } ) ) ;
109
119
} ,
@@ -136,7 +146,7 @@ export function postAddLink(request: PostAddLinkRequest) {
136
146
const client = useFetchClient ( ) ;
137
147
await client . post ( `stacks/${ request . route . id } /add-link` , { value : url } ) ;
138
148
} ,
139
- mutationKey : queryKeys . id ( request . route . id ) ,
149
+ mutationKey : queryKeys . postAddLink ( request . route . id ) ,
140
150
onError : ( ) => {
141
151
queryClient . invalidateQueries ( { queryKey : queryKeys . id ( request . route . id ) } ) ;
142
152
} ,
@@ -154,7 +164,7 @@ export function postChangeStatus(request: PostChangeStatusRequest) {
154
164
const client = useFetchClient ( ) ;
155
165
await client . post ( `stacks/${ request . route . ids ?. join ( ',' ) } /change-status` , undefined , { params : { status } } ) ;
156
166
} ,
157
- mutationKey : queryKeys . ids ( request . route . ids ) ,
167
+ mutationKey : queryKeys . postChangeStatus ( request . route . ids ) ,
158
168
onError : ( ) => {
159
169
request . route . ids ?. forEach ( ( id ) => queryClient . invalidateQueries ( { queryKey : queryKeys . id ( id ) } ) ) ;
160
170
} ,
@@ -172,7 +182,7 @@ export function postMarkCritical(request: PostMarkCriticalRequest) {
172
182
const client = useFetchClient ( ) ;
173
183
await client . post ( `stacks/${ request . route . ids ?. join ( ',' ) } /mark-critical` ) ;
174
184
} ,
175
- mutationKey : queryKeys . ids ( request . route . ids ) ,
185
+ mutationKey : queryKeys . postMarkCritical ( request . route . ids ) ,
176
186
onError : ( ) => {
177
187
request . route . ids ?. forEach ( ( id ) => queryClient . invalidateQueries ( { queryKey : queryKeys . id ( id ) } ) ) ;
178
188
} ,
@@ -190,7 +200,7 @@ export function postMarkFixed(request: PostMarkFixedRequest) {
190
200
const client = useFetchClient ( ) ;
191
201
await client . post ( `stacks/${ request . route . ids ?. join ( ',' ) } /mark-fixed` , undefined , { params : { version } } ) ;
192
202
} ,
193
- mutationKey : queryKeys . ids ( request . route . ids ) ,
203
+ mutationKey : queryKeys . postMarkFixed ( request . route . ids ) ,
194
204
onError : ( ) => {
195
205
request . route . ids ?. forEach ( ( id ) => queryClient . invalidateQueries ( { queryKey : queryKeys . id ( id ) } ) ) ;
196
206
} ,
@@ -208,7 +218,7 @@ export function postMarkSnoozed(request: PostMarkSnoozedRequest) {
208
218
const client = useFetchClient ( ) ;
209
219
await client . post ( `stacks/${ request . route . ids ?. join ( ',' ) } /mark-snoozed` , undefined , { params : { snoozeUntilUtc : snoozeUntilUtc . toISOString ( ) } } ) ;
210
220
} ,
211
- mutationKey : queryKeys . ids ( request . route . ids ) ,
221
+ mutationKey : queryKeys . postMarkSnoozed ( request . route . ids ) ,
212
222
onError : ( ) => {
213
223
request . route . ids ?. forEach ( ( id ) => queryClient . invalidateQueries ( { queryKey : queryKeys . id ( id ) } ) ) ;
214
224
} ,
@@ -230,7 +240,7 @@ export function postPromote(request: PostPromoteRequest) {
230
240
231
241
return response ;
232
242
} ,
233
- mutationKey : queryKeys . ids ( request . route . ids ) ,
243
+ mutationKey : queryKeys . postPromote ( request . route . ids ) ,
234
244
onError : ( ) => {
235
245
request . route . ids ?. forEach ( ( id ) => queryClient . invalidateQueries ( { queryKey : queryKeys . id ( id ) } ) ) ;
236
246
} ,
@@ -248,7 +258,7 @@ export function postRemoveLink(request: PostRemoveLinkRequest) {
248
258
const client = useFetchClient ( ) ;
249
259
await client . post ( `stacks/${ request . route . id } /remove-link` , { value : url } ) ;
250
260
} ,
251
- mutationKey : queryKeys . id ( request . route . id ) ,
261
+ mutationKey : queryKeys . postRemoveLink ( request . route . id ) ,
252
262
onError : ( ) => {
253
263
queryClient . invalidateQueries ( { queryKey : queryKeys . id ( request . route . id ) } ) ;
254
264
} ,
0 commit comments