Skip to content

Commit

Permalink
Merge pull request #1592 from flanksource/1561-Failed-to-fetch-checks…
Browse files Browse the repository at this point in the history
…-data-when-a-health-check-graph-doesnt-return-values

1561-Failed-to-fetch-checks-data-when-a-health-check-graph-doesnt-return-values
  • Loading branch information
moshloop authored Jan 4, 2024
2 parents 75806d7 + 6e72383 commit ce2ef7e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/api/query-hooks/health.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export function useGetCheckDetails(checkId?: string) {
return useQuery({
queryKey: ["check", "details", checkId],
queryFn: async () => {
console.log("checkId", checkId);
const res = await getHealthCheckDetails(checkId!);
return res;
},
enabled: !!checkId
enabled: checkId !== undefined
});
}
5 changes: 5 additions & 0 deletions src/api/query-hooks/playbooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export function useGetPlaybooksToRun(
{
cacheTime: 0,
staleTime: 0,
enabled:
// if any of the params are undefined, don't run the query
params.check_id !== undefined ||
params.component_id !== undefined ||
params.config_id !== undefined,
...options
}
);
Expand Down
16 changes: 11 additions & 5 deletions src/components/Canary/CanaryPopup/CheckDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { calculateDefaultTimeRangeValue } from "./Utils/calculateDefaultTimeRang
import { PopupTabs } from "./tabs";
import { getUptimePercentage } from "./utils";
import CheckRelationships from "./CheckRelationships";
import { useSearchParams } from "react-router-dom";

const CanaryStatusChart = React.lazy(() =>
import("../CanaryStatusChart").then(({ CanaryStatusChart }) => ({
Expand All @@ -36,10 +37,15 @@ export function CheckDetails({ check, ...rest }: CheckDetailsProps) {
const containerRef = useRef<HTMLDivElement>(null);
const statsRef = useRef<HTMLDivElement>(null);

const timeRange = useMemo(
() => calculateDefaultTimeRangeValue(check),
[check]
);
const [searchParams] = useSearchParams({
timeRange: calculateDefaultTimeRangeValue(check)
});

const timeRange = useMemo(() => {
return (
searchParams.get("timeRange") ?? calculateDefaultTimeRangeValue(check)
);
}, [searchParams, check]);

const { data } = useCanaryGraphQuery(timeRange, check);

Expand Down Expand Up @@ -145,7 +151,7 @@ export function CheckDetails({ check, ...rest }: CheckDetailsProps) {
/>
</div>
<div className="w-full h-52 overflow-visible">
<Suspense fallback={<div>Loading..</div>}>
<Suspense fallback={<div>Loading...</div>}>
<CanaryStatusChart timeRange={timeRange} check={check} />
</Suspense>
</div>
Expand Down
16 changes: 13 additions & 3 deletions src/components/Canary/CanaryStatusChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export function CanaryStatusChart({
[dateFormatFn]
);

// we need to list this up
const { data: graphData } = useCanaryGraphQuery(timeRange, check);
// we need to lift this up
const { data: graphData, isLoading } = useCanaryGraphQuery(timeRange, check);

const data = useMemo(() => (graphData?.status ?? []).reverse(), [graphData]);

Expand All @@ -94,8 +94,18 @@ export function CanaryStatusChart({
setDateFormatFn(() => (date: string | Date) => updatedFormat(date));
}, [timeRange]);

if (isLoading) {
return (
<Loading className="flex flex-1 h-full items-center justify-center" />
);
}

if (!data?.length) {
return <Loading />;
return (
<div className="flex flex-1 h-full items-center justify-center text-gray-500 text-sm">
No data available
</div>
);
}

return (
Expand Down

0 comments on commit ce2ef7e

Please sign in to comment.