Skip to content

Commit

Permalink
Merge pull request #90 from Gurubase/task/analytics
Browse files Browse the repository at this point in the history
Task/analytics
  • Loading branch information
aralyekta authored Feb 7, 2025
2 parents 16252cf + 0bbf9ad commit 41ff7d2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,7 @@ import { useState, useEffect } from "react";
import { useStatCards, useHistogram, useTableData } from "@/hooks/useAnalytics";
import { METRIC_TYPES } from "@/services/analyticsService";
import { useRouter, useSearchParams } from "next/navigation";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger
} from "@/components/ui/tooltip";
import { SolarInfoCircleBold } from "@/components/Icons";

const HeaderTooltip = ({ text }) => {
return (
<div className="ml-2">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="cursor-pointer">
<SolarInfoCircleBold className="h-4 w-4 text-gray-200" />
</div>
</TooltipTrigger>
<TooltipContent>
<p className="text-[12px] font-medium">{text}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
);
};
import { HeaderTooltip } from "@/components/ui/header-tooltip";

const MetricSection = ({
title,
Expand Down Expand Up @@ -218,7 +193,7 @@ const AnalyticsContent = ({ customGuru, initialInterval }) => {

<MetricSection
title="Unable to Answers"
tooltipText="Questions that cannot be answered. The reason could be that the question is unrelated to the Guru, or the Gurus data source is insufficient to generate an answer."
tooltipText="Questions that cannot be answered. The reason could be that the question is unrelated to the Guru, or the Guru's data source is insufficient to generate an answer."
metricType={METRIC_TYPES.OUT_OF_CONTEXT}
interval={interval}
guruType={guruType}
Expand Down
80 changes: 19 additions & 61 deletions src/gurubase-frontend/src/components/NewGuru.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import {
TooltipProvider,
TooltipTrigger
} from "./ui/tooltip";
import { HeaderTooltip } from "@/components/ui/header-tooltip";

const formSchema = z.object({
guruName: z
Expand Down Expand Up @@ -1771,22 +1772,11 @@ export default function NewGuru({
<FormItem className="flex-1">
<div className="flex items-center space-x-2">
<FormLabel>Codebase Indexing</FormLabel>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div>
<SolarInfoCircleBold className="h-4 w-4 text-gray-200" />
</div>
</TooltipTrigger>
<TooltipContent>
<p>
Provide a link to a GitHub repository to index its
codebase. The Guru can then use this codebase to generate
answers based on it.
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
<HeaderTooltip
text={
"Provide a link to a GitHub repository to index its codebase. The Guru can then use this codebase to generate answers based on it."
}
/>
</div>
<div className="relative">
<FormControl>
Expand Down Expand Up @@ -1905,22 +1895,13 @@ export default function NewGuru({
<FormLabel>
Guru Name <span className="text-red-500">*</span>
</FormLabel>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div>
<SolarInfoCircleBold className="h-4 w-4 text-gray-200" />
</div>
</TooltipTrigger>
<TooltipContent>
<p>
{isEditMode
? "Guru name cannot be changed"
: "Enter the name of your AI guru"}
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
<HeaderTooltip
text={
isEditMode
? "Guru name cannot be changed"
: "Enter the name of your AI guru"
}
/>
</div>
<FormControl>
<Input
Expand Down Expand Up @@ -1955,18 +1936,7 @@ export default function NewGuru({
<FormLabel>
Guru Logo <span className="text-red-500">*</span>
</FormLabel>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div>
<SolarInfoCircleBold className="h-4 w-4 text-gray-200" />
</div>
</TooltipTrigger>
<TooltipContent>
<p>{"Guru logo"}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
<HeaderTooltip text={"Guru logo"} />
</div>
<FormControl>
<div className="flex items-center space-x-4">
Expand Down Expand Up @@ -2053,23 +2023,11 @@ export default function NewGuru({
<FormLabel>
Topics <span className="text-red-500">*</span>
</FormLabel>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div>
<SolarInfoCircleBold className="h-4 w-4 text-gray-200" />
</div>
</TooltipTrigger>
<TooltipContent className="max-w-[280px]">
<p>
Add comma-separated topics related to this Guru,
e.g., &quot;programming, microservices,
containers&quot;. This helps the AI understand the
Guru&apos;s expertise and context.
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
<HeaderTooltip
text={
'Add comma-separated topics related to this Guru, e.g., "programming, microservices, containers". This helps the AI understand the Guru\'s expertise and context.'
}
/>
</div>
<FormControl>
<Input
Expand Down
63 changes: 63 additions & 0 deletions src/gurubase-frontend/src/components/ui/header-tooltip.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use client";

import { useState, useEffect } from "react";
import { SolarInfoCircleBold } from "@/components/Icons";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger
} from "@/components/ui/tooltip";

export const HeaderTooltip = ({ text }) => {
const [isOpen, setIsOpen] = useState(false);

useEffect(() => {
const handleClickOutside = (event) => {
if (!event.target.closest("[data-tooltip-trigger]")) {
setIsOpen(false);
}
};

// Handle both touch and click events
document.addEventListener("click", handleClickOutside);
document.addEventListener("touchend", handleClickOutside);

return () => {
document.removeEventListener("click", handleClickOutside);
document.removeEventListener("touchend", handleClickOutside);
};
}, []);

const handleInteraction = (e) => {
e.preventDefault();
e.stopPropagation();

// Check if it's a mobile device
const isMobile = window.matchMedia("(max-width: 768px)").matches;
if (isMobile) {
setIsOpen(!isOpen);
}
};

return (
<div className="ml-2">
<TooltipProvider>
<Tooltip open={isOpen} onOpenChange={setIsOpen}>
<TooltipTrigger
asChild
data-tooltip-trigger
onClick={handleInteraction}
onTouchEnd={handleInteraction}>
<div>
<SolarInfoCircleBold className="h-4 w-4 text-gray-200" />
</div>
</TooltipTrigger>
<TooltipContent side="top" align="center" className="z-50">
<p className="text-[12px] font-medium max-w-[400px]">{text}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
);
};

0 comments on commit 41ff7d2

Please sign in to comment.