import { useId, type ReactNode } from "react"; import { Trans, useTranslation } from "react-i18next"; import { ChevronDown, CircleCheckBig, FolderOpen, Info, Loader2 } from "lucide-react"; import { Browser } from "@wailsio/runtime"; import { Debug as DebugSvc } from "@bindings/services"; import type { DebugBundleResult } from "@bindings/services/models.js"; import { Button } from "@/components/buttons/Button"; import { DialogActions } from "@/components/dialog/DialogActions"; import { DialogDescription } from "@/components/dialog/DialogDescription"; import { DialogHeading } from "@/components/dialog/DialogHeading"; import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from "@/components/DropdownMenu"; import FancyToggleSwitch from "@/components/switches/FancyToggleSwitch"; import HelpText from "@/components/typography/HelpText.tsx"; import { Input } from "@/components/inputs/Input"; import { Label } from "@/components/typography/Label"; import { SquareIcon } from "@/components/SquareIcon"; import { Tooltip } from "@/components/Tooltip"; import { cn } from "@/lib/cn"; import { formatRemaining } from "@/lib/formatters"; import type { AnonymizeLevel, DebugStage } from "@/contexts/DebugBundleContext"; import { useDebugBundleContext } from "@/contexts/DebugBundleContext"; import { SectionGroup, SettingsBottomBar } from "@/modules/settings/SettingsSection.tsx"; const SUPPORT_DOCS_URL = "https://docs.netbird.io/help/report-bug-issues"; export function SettingsTroubleshooting() { const { t } = useTranslation(); const durationId = useId(); const { anonymizeLevel, setAnonymizeLevel, systemInfo, setSystemInfo, upload, setUpload, trace, setTrace, capture, setCapture, traceMinutes, setTraceMinutes, capturePackets, setCapturePackets, run, stage, cancel, reset, } = useDebugBundleContext(); if (stage.kind === "done") { return ( ); } if (stage.kind !== "idle") { return ; } return (
} > {t("settings.troubleshooting.anonymize.help")}
setAnonymizeLevel(v as AnonymizeLevel)} > {t("settings.troubleshooting.anonymize.none")} {t("settings.troubleshooting.anonymize.default")} {t("settings.troubleshooting.anonymize.strict")}
{t("settings.troubleshooting.duration.help")}
setTraceMinutes( Math.max(1, Math.min(30, Number(e.target.value) || 1)), ) } customSuffix={t("settings.troubleshooting.duration.suffix")} disabled={!capture} />
); } function CenteredPanel({ children }: Readonly<{ children: ReactNode }>) { return (
{children}
); } function ProgressSection({ stage, onCancel, }: Readonly<{ stage: DebugStage; onCancel: () => void }>) { const { t } = useTranslation(); const cancelling = stage.kind === "cancelling"; return (
{stageLabel(stage, t)} {t("settings.troubleshooting.progress.description")}
{stage.kind === "capturing" && (
{formatRemaining(stage.remainingSec)}
)}
); } function DoneResult({ result, uploaded, onClose, }: Readonly<{ result: DebugBundleResult; uploaded: boolean; onClose: () => void; }>) { const { t } = useTranslation(); const showKey = uploaded && Boolean(result.uploadedKey); const uploadFailed = uploaded && !result.uploadedKey; const onRevealPath = () => { if (!result.path) return; DebugSvc.RevealFile(result.path).catch((err: unknown) => console.error("reveal debug bundle file", err), ); }; return (
{showKey ? t("settings.troubleshooting.done.uploadedTitle") : t("settings.troubleshooting.done.savedTitle")} {showKey ? ( { e.preventDefault(); Browser.OpenURL(SUPPORT_DOCS_URL).catch(() => globalThis.open(SUPPORT_DOCS_URL, "_blank"), ); }} className={"text-netbird hover:underline"} > {/* content is provided by */} ), }} /> ) : ( t("settings.troubleshooting.done.savedDescription") )}
{showKey && } {result.path && !showKey && ( } /> )} {uploadFailed && (
{result.uploadFailureReason ? t("settings.troubleshooting.uploadFailedWithReason", { reason: result.uploadFailureReason, }) : t("settings.troubleshooting.uploadFailed")}
)}
{showKey ? ( ) : ( result.path && ( ) )}
); } const stageLabel = ( stage: DebugStage, t: (key: string, options?: Record) => string, ): string => { switch (stage.kind) { case "reconnecting": return t("settings.troubleshooting.stage.reconnecting"); case "capturing": return t("settings.troubleshooting.stage.capturing"); case "bundling": return t("settings.troubleshooting.stage.bundling"); case "uploading": return t("settings.troubleshooting.stage.uploading"); case "cancelling": return t("settings.troubleshooting.stage.cancelling"); default: return ""; } };