• 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

51.52
/src/features/workspace/hooks/use-mutation-archive-workspace.ts
1
import {
2
  v1DeleteWorkspaceMutation,
3
  v1ListArchivedWorkspacesQueryKey,
4
  v1ListWorkspacesQueryKey,
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 { useQueryClient } from '@tanstack/react-query'
9
import {
10
  V1ListArchivedWorkspacesResponse,
11
  V1ListWorkspacesResponse,
12
} from '@/api/generated'
13
import { useQueryActiveWorkspaceName } from '../../../hooks/use-query-active-workspace-name'
14

15
export function useMutationArchiveWorkspace() {
16
  const queryClient = useQueryClient()
61✔
17
  const invalidate = useInvalidateWorkspaceQueries()
61✔
18
  const { data: activeWorkspaceName } = useQueryActiveWorkspaceName()
61✔
19

20
  return useToastMutation({
61✔
21
    ...v1DeleteWorkspaceMutation(),
22
    onMutate: async (variables) => {
23
      // These conditions would cause the archive operation to error
24
      if (variables.path.workspace_name === 'default') return
2!
25
      if (variables.path.workspace_name === activeWorkspaceName) return
2!
26

27
      // Cancel any outgoing refetches
28
      // Prevents the refetch from overwriting the optimistic update
29
      await queryClient.cancelQueries({
2✔
30
        queryKey: v1ListWorkspacesQueryKey(),
31
      })
32
      await queryClient.cancelQueries({
2✔
33
        queryKey: v1ListArchivedWorkspacesQueryKey(),
34
      })
35

36
      // Snapshot the previous data
37
      const prevWorkspaces = queryClient.getQueryData(
2✔
38
        v1ListWorkspacesQueryKey()
39
      )
40
      const prevArchivedWorkspaces = queryClient.getQueryData(
2✔
41
        v1ListArchivedWorkspacesQueryKey()
42
      )
43

44
      if (!prevWorkspaces || !prevArchivedWorkspaces) return
2!
45

46
      // Optimistically update values in cache
47
      await queryClient.setQueryData(
×
48
        v1ListWorkspacesQueryKey(),
49
        (old: V1ListWorkspacesResponse | null) => ({
×
50
          workspaces: old
×
51
            ? [...old.workspaces].filter(
NEW
52
                (o) => o.name !== variables.path.workspace_name
×
53
              )
54
            : [],
55
        })
56
      )
UNCOV
57
      await queryClient.setQueryData(
×
58
        v1ListArchivedWorkspacesQueryKey(),
59
        (old: V1ListArchivedWorkspacesResponse | null) => ({
×
60
          workspaces: old
×
61
            ? [...old.workspaces, { name: variables.path.workspace_name }]
62
            : [],
63
        })
64
      )
65

66
      return {
×
67
        prevWorkspaces,
68
        prevArchivedWorkspaces,
69
      }
70
    },
71
    onSettled: async () => {
72
      await invalidate()
2✔
73
    },
74
    // Rollback cache updates on error
75
    onError: async (_a, _b, context) => {
76
      queryClient.setQueryData(
×
77
        v1ListWorkspacesQueryKey(),
78
        context?.prevWorkspaces
79
      )
UNCOV
80
      queryClient.setQueryData(
×
81
        v1ListArchivedWorkspacesQueryKey(),
82
        context?.prevArchivedWorkspaces
83
      )
84
    },
85
    successMsg: (variables) =>
86
      `Archived "${variables.path.workspace_name}" workspace`,
2✔
87
  })
88
}
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