• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stacklok / codegate-ui / 13325211149

14 Feb 2025 08:17AM UTC coverage: 68.625% (+0.02%) from 68.603%
13325211149

Pull #315

github

web-flow
Merge 7bf78fe19 into 0805f21ad
Pull Request #315: chore: configure prettier & apply formatting

364 of 590 branches covered (61.69%)

Branch coverage included in aggregate %.

360 of 519 new or added lines in 99 files covered. (69.36%)

5 existing lines in 4 files now uncovered.

769 of 1061 relevant lines covered (72.48%)

71.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.55
/src/features/workspace/hooks/use-mutation-restore-workspace.ts
1
import {
2
  v1ListArchivedWorkspacesQueryKey,
3
  v1ListWorkspacesQueryKey,
4
  v1RecoverWorkspaceMutation,
5
} from '@/api/generated/@tanstack/react-query.gen'
6
import { useToastMutation } from '@/hooks/use-toast-mutation'
7
import { useInvalidateWorkspaceQueries } from './use-invalidate-workspace-queries'
8
import {
9
  V1ListWorkspacesResponse,
10
  V1ListArchivedWorkspacesResponse,
11
} from '@/api/generated'
12
import { useQueryClient } from '@tanstack/react-query'
13

14
export function useMutationRestoreWorkspace() {
15
  const invalidate = useInvalidateWorkspaceQueries()
48✔
16
  const queryClient = useQueryClient()
48✔
17

18
  return useToastMutation({
48✔
19
    ...v1RecoverWorkspaceMutation(),
20
    onMutate: async (variables) => {
21
      // Cancel any outgoing refetches
22
      // Prevents the refetch from overwriting the optimistic update
23
      await queryClient.cancelQueries({
2✔
24
        queryKey: v1ListWorkspacesQueryKey(),
25
      })
26
      await queryClient.cancelQueries({
2✔
27
        queryKey: v1ListArchivedWorkspacesQueryKey(),
28
      })
29

30
      // Snapshot the previous data
31
      const prevWorkspaces = queryClient.getQueryData(
2✔
32
        v1ListWorkspacesQueryKey()
33
      )
34
      const prevArchivedWorkspaces = queryClient.getQueryData(
2✔
35
        v1ListArchivedWorkspacesQueryKey()
36
      )
37

38
      if (!prevWorkspaces || !prevArchivedWorkspaces) return
2!
39

40
      // Optimistically update values in cache
41
      queryClient.setQueryData(
×
42
        v1ListArchivedWorkspacesQueryKey(),
43
        (old: V1ListWorkspacesResponse) => ({
×
44
          workspaces: [...old.workspaces].filter(
NEW
45
            (o) => o.name !== variables.path.workspace_name
×
46
          ),
47
        })
48
      )
49
      // Optimistically add the workspace to the non-archived list
50
      queryClient.setQueryData(
×
51
        v1ListWorkspacesQueryKey(),
52
        (old: V1ListArchivedWorkspacesResponse) => ({
×
53
          workspaces: [
54
            ...old.workspaces,
55
            { name: variables.path.workspace_name },
56
          ],
57
        })
58
      )
59

60
      return {
×
61
        prevWorkspaces,
62
        prevArchivedWorkspaces,
63
      }
64
    },
65
    onSettled: async () => {
66
      await invalidate()
2✔
67
    },
68
    // Rollback cache updates on error
69
    onError: async (_a, _b, context) => {
70
      queryClient.setQueryData(
×
71
        v1ListWorkspacesQueryKey(),
72
        context?.prevWorkspaces
73
      )
UNCOV
74
      queryClient.setQueryData(
×
75
        v1ListArchivedWorkspacesQueryKey(),
76
        context?.prevArchivedWorkspaces
77
      )
78
    },
79
    successMsg: (variables) =>
80
      `Restored "${variables.path.workspace_name}" workspace`,
2✔
81
  })
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc