@@ -4,7 +4,7 @@ import Link from "next/link";
44import { HoverCard , HoverCardTrigger , HoverCardContent } from "@/components/ui/hover-card" ;
55import { CircleXIcon } from "lucide-react" ;
66import { useDomain } from "@/hooks/useDomain" ;
7- import { isServiceError } from "@/lib/utils" ;
7+ import { unwrapServiceError } from "@/lib/utils" ;
88import useCaptureEvent from "@/hooks/useCaptureEvent" ;
99import { NEXT_PUBLIC_POLLING_INTERVAL_MS } from "@/lib/environment.client" ;
1010import { useQuery } from "@tanstack/react-query" ;
@@ -16,49 +16,43 @@ export const ErrorNavIndicator = () => {
1616 const domain = useDomain ( ) ;
1717 const captureEvent = useCaptureEvent ( ) ;
1818
19- const { data : failedRepos } = useQuery ( {
19+ const { data : repos , isPending : isPendingRepos , isError : isErrorRepos } = useQuery ( {
2020 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 ) ,
2823 refetchInterval : NEXT_PUBLIC_POLLING_INTERVAL_MS ,
29- initialData : [ ] ,
3024 } ) ;
3125
32- const { data : failedConnections } = useQuery ( {
26+ const { data : connections , isPending : isPendingConnections , isError : isErrorConnections } = useQuery ( {
3327 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 ) ,
4130 refetchInterval : NEXT_PUBLIC_POLLING_INTERVAL_MS ,
42- initialData : [ ] ,
4331 } ) ;
4432
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+ }
4640
4741 return (
4842 < HoverCard openDelay = { 50 } >
4943 < HoverCardTrigger asChild onMouseEnter = { ( ) => captureEvent ( 'wa_error_nav_hover' , { } ) } >
5044 < Link href = { `/${ domain } /connections` } onClick = { ( ) => captureEvent ( 'wa_error_nav_pressed' , { } ) } >
5145 < 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" >
5246 < 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 >
5549 ) }
5650 </ div >
5751 </ Link >
5852 </ HoverCardTrigger >
5953 < HoverCardContent className = "w-80 border border-red-200 dark:border-red-800 rounded-lg" >
6054 < div className = "flex flex-col gap-6 p-5" >
61- { failedConnections . length > 0 && (
55+ { connections . length > 0 && (
6256 < div className = "flex flex-col gap-4 pb-6" >
6357 < div className = "flex items-center gap-2" >
6458 < div className = "h-2 w-2 rounded-full bg-red-500" > </ div >
@@ -68,7 +62,7 @@ export const ErrorNavIndicator = () => {
6862 The following connections have failed to sync:
6963 </ p >
7064 < div className = "flex flex-col gap-2" >
71- { failedConnections
65+ { connections
7266 . slice ( 0 , 10 )
7367 . map ( connection => (
7468 < Link key = { connection . name } href = { `/${ domain } /connections/${ connection . id } ` } onClick = { ( ) => captureEvent ( 'wa_error_nav_job_pressed' , { } ) } >
@@ -80,16 +74,16 @@ export const ErrorNavIndicator = () => {
8074 </ div >
8175 </ Link >
8276 ) ) }
83- { failedConnections . length > 10 && (
77+ { connections . length > 10 && (
8478 < 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...
8680 </ div >
8781 ) }
8882 </ div >
8983 </ div >
9084 ) }
9185
92- { failedRepos . length > 0 && (
86+ { repos . length > 0 && (
9387 < div className = "flex flex-col gap-4" >
9488 < div className = "flex items-center gap-2" >
9589 < div className = "h-2 w-2 rounded-full bg-red-500" > </ div >
@@ -99,7 +93,7 @@ export const ErrorNavIndicator = () => {
9993 The following repositories failed to index:
10094 </ p >
10195 < div className = "flex flex-col gap-2" >
102- { failedRepos
96+ { repos
10397 . slice ( 0 , 10 )
10498 . map ( repo => (
10599 // Link to the first connection for the repo
@@ -115,9 +109,9 @@ export const ErrorNavIndicator = () => {
115109 </ div >
116110 </ Link >
117111 ) ) }
118- { failedRepos . length > 10 && (
112+ { repos . length > 10 && (
119113 < 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...
121115 </ div >
122116 ) }
123117 </ div >
0 commit comments