From 7924f195aae3eba8edd702c42728806258156bba Mon Sep 17 00:00:00 2001 From: Fred KISSIE Date: Fri, 21 Nov 2025 04:47:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84handle=20empty=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- messages/en-US.json | 3 ++- src/components/LogAnalyticsData.tsx | 31 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/messages/en-US.json b/messages/en-US.json index 6d617279..90097860 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -2154,5 +2154,6 @@ "niceIdUpdateErrorDescription": "An error occurred while updating the Nice ID.", "niceIdCannotBeEmpty": "Nice ID cannot be empty", "enterIdentifier": "Enter identifier", - "identifier": "Identifier" + "identifier": "Identifier", + "noData": "No Data" } diff --git a/src/components/LogAnalyticsData.tsx b/src/components/LogAnalyticsData.tsx index 7eafda95..f6845742 100644 --- a/src/components/LogAnalyticsData.tsx +++ b/src/components/LogAnalyticsData.tsx @@ -11,7 +11,7 @@ import { useQuery } from "@tanstack/react-query"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useState } from "react"; import { Card, CardContent, CardHeader } from "./ui/card"; -import { RefreshCw, XIcon } from "lucide-react"; +import { LoaderIcon, RefreshCw, XIcon } from "lucide-react"; import { DateRangePicker, type DateTimeValue } from "./DateTimePicker"; import { Button } from "./ui/button"; import { cn } from "@app/lib/cn"; @@ -74,7 +74,8 @@ export function LogAnalyticsData(props: AnalyticsContentProps) { const { data: stats, isFetching: isFetchingAnalytics, - refetch: refreshAnalytics + refetch: refreshAnalytics, + isLoading: isLoadingAnalytics // only `true` when there is no data yet } = useQuery( logQueries.requestAnalytics({ orgId: props.orgId, @@ -296,6 +297,7 @@ export function LogAnalyticsData(props: AnalyticsContentProps) { @@ -310,6 +312,7 @@ type TopCountriesListProps = { count: number; }[]; total: number; + isLoading: boolean; }; function TopCountriesList(props: TopCountriesListProps) { @@ -331,13 +334,27 @@ function TopCountriesList(props: TopCountriesListProps) { return (
-
-
{t("countries")}
-
{t("total")}
-
%
-
+ {props.countries.length > 0 && ( +
+
{t("countries")}
+
{t("total")}
+
%
+
+ )} {/* `aspect-475/335` is the same aspect ratio as the world map component */}
    + {props.countries.length === 0 && ( +
    + {props.isLoading ? ( + <> + {" "} + {t("loading")} + + ) : ( + t("noData") + )} +
    + )} {props.countries.map((country) => { const percent = country.count / props.total; return (