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

stacklok / codegate-ui / 13031292266

29 Jan 2025 12:27PM CUT coverage: 68.733% (+1.7%) from 67.071%
13031292266

Pull #220

github

web-flow
Merge 04fad425d into 25a531eba
Pull Request #220: feat(muxes): model overrides matcher

387 of 673 branches covered (57.5%)

Branch coverage included in aggregate %.

41 of 60 new or added lines in 8 files covered. (68.33%)

2 existing lines in 1 file now uncovered.

844 of 1118 relevant lines covered (75.49%)

63.88 hits per line

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

0.0
/src/components/react-query-provider.tsx
1
import { V1ListActiveWorkspacesResponse } from "@/api/generated";
2
import { v1ListActiveWorkspacesQueryKey } from "@/api/generated/@tanstack/react-query.gen";
3
import {
4
  QueryCacheNotifyEvent,
5
  QueryClient,
6
  QueryClientProvider as VendorQueryClientProvider,
7
} from "@tanstack/react-query";
8
import { ReactNode, useState, useEffect } from "react";
9

10
/**
11
 * Responsible for determining whether a queryKey attached to a queryCache event
12
 * is for the "list active workspaces" query.
13
 */
14
function isActiveWorkspacesQueryKey(queryKey: unknown): boolean {
15
  return (
×
16
    Array.isArray(queryKey) &&
×
17
    queryKey[0]._id === v1ListActiveWorkspacesQueryKey()[0]?._id
18
  );
19
}
20

21
/**
22
 * Responsible for extracting the incoming active workspace name from the deeply
23
 * nested payload attached to a queryCache event.
24
 */
25
function getWorkspaceName(event: QueryCacheNotifyEvent): string | null {
26
  if ("action" in event === false || "data" in event.action === false)
×
27
    return null;
×
28
  return (
×
29
    (event.action.data as V1ListActiveWorkspacesResponse | undefined | null)
×
30
      ?.workspaces[0]?.name ?? null
31
  );
32
}
33

34
export function QueryClientProvider({ children }: { children: ReactNode }) {
35
  const [activeWorkspaceName, setActiveWorkspaceName] = useState<string | null>(
×
36
    null,
37
  );
38

39
  const [queryClient] = useState(() => new QueryClient());
×
40

41
  useEffect(() => {
×
42
    const queryCache = queryClient.getQueryCache();
×
43
    const unsubscribe = queryCache.subscribe((event) => {
×
44
      if (
×
45
        event.type === "updated" &&
×
46
        event.action.type === "success" &&
47
        isActiveWorkspacesQueryKey(event.query.options.queryKey)
48
      ) {
49
        const newWorkspaceName: string | null = getWorkspaceName(event);
×
50
        if (
×
51
          newWorkspaceName === activeWorkspaceName ||
×
52
          newWorkspaceName === null
53
        )
54
          return;
×
55

56
        setActiveWorkspaceName(newWorkspaceName);
×
57

58
        void queryClient.invalidateQueries({
×
59
          refetchType: "all",
60
          // Avoid a continuous loop
61
          predicate(query) {
62
            return !isActiveWorkspacesQueryKey(query.queryKey);
×
63
          },
64
        });
65
      }
66
    });
67

68
    return () => {
×
69
      return unsubscribe();
×
70
    };
71
  }, [activeWorkspaceName, queryClient]);
72

73
  return (
74
    <VendorQueryClientProvider client={queryClient}>
75
      {children}
76
    </VendorQueryClientProvider>
77
  );
78
}
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