@@ -4,7 +4,7 @@ import Link from "next/link";
4
4
import { HoverCard , HoverCardTrigger , HoverCardContent } from "@/components/ui/hover-card" ;
5
5
import { CircleXIcon } from "lucide-react" ;
6
6
import { useDomain } from "@/hooks/useDomain" ;
7
- import { isServiceError } from "@/lib/utils" ;
7
+ import { unwrapServiceError } from "@/lib/utils" ;
8
8
import useCaptureEvent from "@/hooks/useCaptureEvent" ;
9
9
import { NEXT_PUBLIC_POLLING_INTERVAL_MS } from "@/lib/environment.client" ;
10
10
import { useQuery } from "@tanstack/react-query" ;
@@ -16,49 +16,43 @@ export const ErrorNavIndicator = () => {
16
16
const domain = useDomain ( ) ;
17
17
const captureEvent = useCaptureEvent ( ) ;
18
18
19
- const { data : failedRepos } = useQuery ( {
19
+ const { data : repos , isPending : isPendingRepos , isError : isErrorRepos } = useQuery ( {
20
20
queryKey : [ 'repos' , domain ] ,
21
- queryFn : ( ) => getRepos ( domain ) ,
22
- select : ( data ) => {
23
- if ( isServiceError ( data ) ) {
24
- return data ;
25
- }
26
- return data . filter ( repo => repo . repoIndexingStatus === RepoIndexingStatus . FAILED ) ;
27
- } ,
21
+ queryFn : ( ) => unwrapServiceError ( getRepos ( domain ) ) ,
22
+ select : ( data ) => data . filter ( repo => repo . repoIndexingStatus === RepoIndexingStatus . FAILED ) ,
28
23
refetchInterval : NEXT_PUBLIC_POLLING_INTERVAL_MS ,
29
- initialData : [ ] ,
30
24
} ) ;
31
25
32
- const { data : failedConnections } = useQuery ( {
26
+ const { data : connections , isPending : isPendingConnections , isError : isErrorConnections } = useQuery ( {
33
27
queryKey : [ 'connections' , domain ] ,
34
- queryFn : ( ) => getConnections ( domain ) ,
35
- select : ( data ) => {
36
- if ( isServiceError ( data ) ) {
37
- return data ;
38
- }
39
- return data . filter ( connection => connection . syncStatus === ConnectionSyncStatus . FAILED )
40
- } ,
28
+ queryFn : ( ) => unwrapServiceError ( getConnections ( domain ) ) ,
29
+ select : ( data ) => data . filter ( connection => connection . syncStatus === ConnectionSyncStatus . FAILED ) ,
41
30
refetchInterval : NEXT_PUBLIC_POLLING_INTERVAL_MS ,
42
- initialData : [ ] ,
43
31
} ) ;
44
32
45
- if ( isServiceError ( failedRepos ) || isServiceError ( failedConnections ) || ( failedRepos . length === 0 && failedConnections . length === 0 ) ) return null ;
33
+ if ( isPendingRepos || isErrorRepos || isPendingConnections || isErrorConnections ) {
34
+ return null ;
35
+ }
36
+
37
+ if ( repos . length === 0 && connections . length === 0 ) {
38
+ return null ;
39
+ }
46
40
47
41
return (
48
42
< HoverCard openDelay = { 50 } >
49
43
< HoverCardTrigger asChild onMouseEnter = { ( ) => captureEvent ( 'wa_error_nav_hover' , { } ) } >
50
44
< Link href = { `/${ domain } /connections` } onClick = { ( ) => captureEvent ( 'wa_error_nav_pressed' , { } ) } >
51
45
< div className = "flex items-center gap-2 px-3 py-1.5 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-700 rounded-full text-red-700 dark:text-red-400 text-xs font-medium hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors cursor-pointer" >
52
46
< CircleXIcon className = "h-4 w-4" />
53
- { failedRepos . length + failedConnections . length > 0 && (
54
- < span > { failedRepos . length + failedConnections . length } </ span >
47
+ { repos . length + connections . length > 0 && (
48
+ < span > { repos . length + connections . length } </ span >
55
49
) }
56
50
</ div >
57
51
</ Link >
58
52
</ HoverCardTrigger >
59
53
< HoverCardContent className = "w-80 border border-red-200 dark:border-red-800 rounded-lg" >
60
54
< div className = "flex flex-col gap-6 p-5" >
61
- { failedConnections . length > 0 && (
55
+ { connections . length > 0 && (
62
56
< div className = "flex flex-col gap-4 pb-6" >
63
57
< div className = "flex items-center gap-2" >
64
58
< div className = "h-2 w-2 rounded-full bg-red-500" > </ div >
@@ -68,7 +62,7 @@ export const ErrorNavIndicator = () => {
68
62
The following connections have failed to sync:
69
63
</ p >
70
64
< div className = "flex flex-col gap-2" >
71
- { failedConnections
65
+ { connections
72
66
. slice ( 0 , 10 )
73
67
. map ( connection => (
74
68
< Link key = { connection . name } href = { `/${ domain } /connections/${ connection . id } ` } onClick = { ( ) => captureEvent ( 'wa_error_nav_job_pressed' , { } ) } >
@@ -80,16 +74,16 @@ export const ErrorNavIndicator = () => {
80
74
</ div >
81
75
</ Link >
82
76
) ) }
83
- { failedConnections . length > 10 && (
77
+ { connections . length > 10 && (
84
78
< div className = "text-sm text-red-600/90 dark:text-red-300/90 pl-3 pt-1" >
85
- And { failedConnections . length - 10 } more...
79
+ And { connections . length - 10 } more...
86
80
</ div >
87
81
) }
88
82
</ div >
89
83
</ div >
90
84
) }
91
85
92
- { failedRepos . length > 0 && (
86
+ { repos . length > 0 && (
93
87
< div className = "flex flex-col gap-4" >
94
88
< div className = "flex items-center gap-2" >
95
89
< div className = "h-2 w-2 rounded-full bg-red-500" > </ div >
@@ -99,7 +93,7 @@ export const ErrorNavIndicator = () => {
99
93
The following repositories failed to index:
100
94
</ p >
101
95
< div className = "flex flex-col gap-2" >
102
- { failedRepos
96
+ { repos
103
97
. slice ( 0 , 10 )
104
98
. map ( repo => (
105
99
// Link to the first connection for the repo
@@ -115,9 +109,9 @@ export const ErrorNavIndicator = () => {
115
109
</ div >
116
110
</ Link >
117
111
) ) }
118
- { failedRepos . length > 10 && (
112
+ { repos . length > 10 && (
119
113
< div className = "text-sm text-red-600/90 dark:text-red-300/90 pl-3 pt-1" >
120
- And { failedRepos . length - 10 } more...
114
+ And { repos . length - 10 } more...
121
115
</ div >
122
116
) }
123
117
</ div >
0 commit comments