Skip to content

Commit 24b142d

Browse files
authored
fix(check-server): invalidate workload list with the group and refactor (#1190)
* fix(check-server): invalidate workload list with the group * chore: move stopping to handle status from the api * refactor: remove type assertions that are not needed anymore
1 parent eb74871 commit 24b142d

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

renderer/src/common/hooks/use-check-server-status.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export function useCheckServerStatus() {
5050

5151
if (isServerReady) {
5252
await queryClient.invalidateQueries({
53-
queryKey: getApiV1BetaWorkloadsQueryKey({ query: { all: true } }),
53+
queryKey: getApiV1BetaWorkloadsQueryKey({
54+
query: { all: true, group: groupName },
55+
}),
5456
})
5557

5658
// Also invalidate the specific server query to ensure form updates

renderer/src/features/mcp-servers/components/actions-mcp-server.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ function getStatusText(status: CoreWorkload['status']) {
77
if (status === 'running') return 'Running'
88
if (status === 'starting') return 'Starting'
99
if (status === 'stopped') return 'Stopped'
10+
if (status === 'stopping') return 'Stopping'
1011
if (status === 'error') return 'Error'
1112
// add it for UI purposes, the BE cannot handle it for mvp
1213
if (status === 'updating') return 'Updating'
13-
if (status === 'stopping') return 'Stopping'
1414
if (status === 'deleting') return 'Deleting'
1515
if (status === 'restarting') return 'Restarting'
1616
return 'Unknown'

renderer/src/features/mcp-servers/hooks/use-mutation-restart-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function useMutationRestartServerAtStartup() {
119119
return statusResponses.map((response, index) => ({
120120
name: names[index],
121121
status: response.status || 'unknown',
122-
})) as CoreWorkload[]
122+
}))
123123
},
124124
serverNames,
125125
'running'

renderer/src/features/mcp-servers/hooks/use-mutation-update-workload.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const useMutationUpdateWorkload = () => {
1616
query: { all: true, group: body.group },
1717
})
1818
await queryClient.cancelQueries({ queryKey })
19-
const previousServersList = queryClient.getQueryData(queryKey)
19+
const previousServersList =
20+
queryClient.getQueryData<V1WorkloadListResponse>(queryKey)
2021

2122
queryClient.setQueryData(queryKey, (old: V1WorkloadListResponse) => {
2223
const newWorkloads = old?.workloads?.map((server) =>
@@ -29,15 +30,16 @@ export const useMutationUpdateWorkload = () => {
2930
})
3031
return { queryKey, previousServersList }
3132
},
32-
onError: (_error, _variables, context) => {
33-
if (context?.queryKey && context?.previousServersList) {
34-
queryClient.setQueryData(context?.queryKey, context.previousServersList)
33+
onError: (_error, _variables, onMutateResult) => {
34+
if (onMutateResult?.queryKey && onMutateResult?.previousServersList) {
35+
queryClient.setQueryData(
36+
onMutateResult?.queryKey,
37+
onMutateResult.previousServersList
38+
)
3539
}
3640
},
37-
onSettled: async (_data, _error, variables, cachedResult) => {
38-
const workloads =
39-
(cachedResult?.previousServersList as V1WorkloadListResponse)
40-
?.workloads ?? []
41+
onSettled: async (_data, _error, variables, onMutateResult) => {
42+
const workloads = onMutateResult?.previousServersList?.workloads ?? []
4143
// Only refetch workloads without cached data, as servers may be temporarily unavailable during restart.
4244
if (
4345
!workloads.some((workload) => workload.name === variables.path.name)

0 commit comments

Comments
 (0)