🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(widgets): add retry action for failed widgets (#12807)
Max Deichmannc401fe0e6364
diff --git a/web/src/__tests__/chart-loading-state.clienttest.tsx b/web/src/__tests__/chart-loading-state.clienttest.tsxindex 5a9d64f450..46e608d5af 100644--- a/web/src/__tests__/chart-loading-state.clienttest.tsx+++ b/web/src/__tests__/chart-loading-state.clienttest.tsx@@ -1,5 +1,5 @@import React from "react";-import { act, render, screen } from "@testing-library/react";+import { act, fireEvent, render, screen } from "@testing-library/react";import "@testing-library/jest-dom";import { SLOW_QUERY_HINT_TEXT } from "@langfuse/shared";import { ChartLoadingState } from "@/src/features/widgets/chart-library/ChartLoadingState";@@ -95,6 +95,23 @@ describe("ChartLoadingState", () => {expect(screen.queryByText(SLOW_QUERY_HINT_TEXT)).not.toBeInTheDocument();});+ test("renders a retry button for error states when a retry handler is provided", () => {+ const onRetry = jest.fn();++ render(+ <ChartLoadingState+ isLoading={true}+ showHintImmediately={true}+ showSpinner={false}+ onRetry={onRetry}+ />,+ );++ fireEvent.click(screen.getByRole("button", { name: "Retry" }));++ expect(onRetry).toHaveBeenCalledTimes(1);+ });+test("shows only the spinner for the first second before swapping to the loading bar", () => {const { container } = render(<ChartLoadingState isLoading={true} progress={null} />,diff --git a/web/src/features/widgets/chart-library/ChartLoadingState.tsx b/web/src/features/widgets/chart-library/ChartLoadingState.tsxindex 6f2032c7a0..3f7e7c50a8 100644--- a/web/src/features/widgets/chart-library/ChartLoadingState.tsx+++ b/web/src/features/widgets/chart-library/ChartLoadingState.tsx@@ -4,6 +4,7 @@ import { cn } from "@/src/utils/tailwind";import { SLOW_QUERY_HINT_TEXT } from "@langfuse/shared";import { type QueryProgress } from "@/src/hooks/useSSEDashboardQuery";import { QueryProgressBar } from "@/src/features/widgets/chart-library/QueryProgressBar";+import { Button } from "@/src/components/ui/button";const DEFAULT_HINT_DELAY_MS = 2000;const PROGRESS_REVEAL_DELAY_MS = 1000;@@ -20,6 +21,8 @@ type ChartLoadingStateProps = {showHintImmediately?: boolean;progress?: QueryProgress | null;layout?: "default" | "compact" | "tight";+ onRetry?: () => void;+ retryLabel?: string;};export function ChartLoadingState({@@ -34,6 +37,8 @@ export function ChartLoadingState({showHintImmediately = false,progress,layout = "default",+ onRetry,+ retryLabel = "Retry",}: ChartLoadingStateProps) {const [showHint, setShowHint] = useState(false);const [showProgressPhase, setShowProgressPhase] = useState(false);@@ -81,6 +86,7 @@ export function ChartLoadingState({const isTightProgressState = isTight && shouldShowProgress;const shouldRenderStatusTitle = !isTightProgressState;const shouldRenderHint = shouldShowHint && !isTightProgressState;+ const shouldRenderRetry = Boolean(onRetry) && shouldShowHint && !showSpinner;if (isLegacySpinnerOnlyState ||@@ -176,6 +182,16 @@ export function ChartLoadingState({)}</p>)}+ {shouldRenderRetry ? (+ <Button+ variant="outline"+ size="sm"+ onClick={onRetry}+ className="w-fit self-center"+ >+ {retryLabel}+ </Button>+ ) : null}</div></div></div>diff --git a/web/src/features/widgets/components/DashboardWidget.tsx b/web/src/features/widgets/components/DashboardWidget.tsxindex 298e073d08..d33cdf579c 100644--- a/web/src/features/widgets/components/DashboardWidget.tsx+++ b/web/src/features/widgets/components/DashboardWidget.tsx@@ -38,6 +38,7 @@ import {isV2BreakdownChart,buildWidgetOrderBy,} from "@/src/features/query/validateQuery";+import { hashKey } from "@tanstack/react-query";export interface WidgetPlacement {id: string;@@ -97,6 +98,7 @@ export function DashboardWidget({const [sortState, setSortState] = useState<OrderByState | null>(() => {return defaultSort || null;});+ const [retryCount, setRetryCount] = useState(0);// Apply defaultSort when it becomes available (after widget data loads)// but only if user hasn't interacted yet@@ -176,6 +178,18 @@ export function DashboardWidget({: ({ valid: true } as const),[widgetQuery, metricsVersion, widget.data],);+ const queryRunKey = useMemo(+ () =>+ hashKey([+ {+ projectId,+ version: metricsVersion,+ query: widgetQuery,+ },+ retryCount,+ ]),+ [metricsVersion, projectId, retryCount, widgetQuery],+ );const queryResult = useScheduledDashboardExecuteQuery({@@ -193,6 +207,7 @@ export function DashboardWidget({meta: {silentHttpCodes: [422],},+ runKey: queryRunKey,useSSE: shouldUseWidgetSSE({isV4BetaEnabled: isBetaEnabled,version: metricsVersion,@@ -222,6 +237,9 @@ export function DashboardWidget({progress: queryResult.progress,useBackendProgress: usesBackendProgress,});+ const handleRetry = useCallback(() => {+ setRetryCount((current) => current + 1);+ }, []);const transformedData = useMemo(() => {if (!widget.data || !queryResult.data) {@@ -435,6 +453,7 @@ export function DashboardWidget({showSpinner={chartLoadingState.showSpinner}showHintImmediately={chartLoadingState.showHintImmediately}hintText={chartLoadingState.hintText}+ onRetry={queryResult.isError ? handleRetry : undefined}progress={loadingProgress}layout={loadingStateLayout}className="bg-background/80 absolute inset-0 z-20 backdrop-blur-xs"