"use client"; import Link from "next/link"; import { HoverCard, HoverCardTrigger, HoverCardContent } from "@/components/ui/hover-card"; import { CircleXIcon } from "lucide-react"; import { useDomain } from "@/hooks/useDomain"; import { getConnectionFailedRepos, getConnections } from "@/actions"; import { useState, useEffect } from "react"; import { isServiceError } from "@/lib/utils"; enum ConnectionErrorType { SYNC_FAILED = "SYNC_FAILED", REPO_INDEXING_FAILED = "REPO_INDEXING_FAILED", } interface Error { connectionId?: number; connectionName?: string; errorType: ConnectionErrorType; numRepos?: number; } export const ErrorNavIndicator = () => { const domain = useDomain(); const [errors, setErrors] = useState([]); useEffect(() => { const fetchErrors = async () => { const connections = await getConnections(domain); const errors: Error[] = []; if (!isServiceError(connections)) { for (const connection of connections) { if (connection.syncStatus === 'FAILED') { errors.push({ connectionId: connection.id, connectionName: connection.name, errorType: ConnectionErrorType.SYNC_FAILED }); } const failedRepos = await getConnectionFailedRepos(connection.id, domain); if (!isServiceError(failedRepos) && failedRepos.length > 0) { errors.push({ connectionId: connection.id, connectionName: connection.name, numRepos: failedRepos.length, errorType: ConnectionErrorType.REPO_INDEXING_FAILED }); } } } setErrors(prevErrors => { // Only update if the errors have actually changed const errorsChanged = prevErrors.length !== errors.length || prevErrors.some((error, idx) => error.connectionId !== errors[idx]?.connectionId || error.connectionName !== errors[idx]?.connectionName || error.errorType !== errors[idx]?.errorType ); return errorsChanged ? errors : prevErrors; }); }; fetchErrors(); }, [domain]); if (errors.length === 0) return null; return (
{errors.reduce((acc, error) => acc + (error.numRepos || 0), 0) > 0 && ( {errors.reduce((acc, error) => acc + (error.numRepos || 0), 0)} )}
{errors.filter(e => e.errorType === 'SYNC_FAILED').length > 0 && (

Connection Sync Issues

The following connections have failed to sync:

{errors .filter(e => e.errorType === 'SYNC_FAILED') .slice(0, 10) .map(error => (
{error.connectionName}
))} {errors.filter(e => e.errorType === 'SYNC_FAILED').length > 10 && (
And {errors.filter(e => e.errorType === 'SYNC_FAILED').length - 10} more...
)}
)} {errors.filter(e => e.errorType === 'REPO_INDEXING_FAILED').length > 0 && (

Repository Indexing Issues

The following connections have repositories that failed to index:

{errors .filter(e => e.errorType === 'REPO_INDEXING_FAILED') .slice(0, 10) .map(error => (
{error.connectionName} {error.numRepos}
))} {errors.filter(e => e.errorType === 'REPO_INDEXING_FAILED').length > 10 && (
And {errors.filter(e => e.errorType === 'REPO_INDEXING_FAILED').length - 10} more...
)}
)}
); };