Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(ui-v4): add top banner (#12266)

Hassieb Pakzad61c2def79225
diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
index 40f8e9451d..b3c412d912 100644
--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
@@ -9,7 +9,7 @@ import Head from "next/head";
import { SidebarProvider, SidebarInset } from "@/src/components/ui/sidebar";
import { AppSidebar } from "@/src/components/nav/app-sidebar";
import { Toaster } from "@/src/components/ui/sonner";
-import { PaymentBannerProvider } from "@/src/features/payment-banner";
+import { TopBannerProvider } from "@/src/features/top-banner";
import { ResizableContent } from "../components/ResizableContent";
import { ThemeToggle } from "@/src/features/theming/ThemeToggle";
import type { Session } from "next-auth";
@@ -37,6 +37,18 @@ const PaymentBanner = dynamic(
},
);
+const V4BetaEnabledBanner = dynamic(
+ () =>
+ import("@/src/features/events/components/V4BetaEnabledBanner").then(
+ (mod) => ({
+ default: mod.V4BetaEnabledBanner,
+ }),
+ ),
+ {
+ ssr: false,
+ },
+);
+
/** Grouped navigation structure returned by processNavigation */
type GroupedNavigation = {
ungrouped: NavigationItem[];
@@ -112,10 +124,11 @@ export function AuthenticatedLayout({
<link rel="apple-touch-icon" href={metadata.appleTouchIconPath} />
</Head>
- <PaymentBannerProvider>
+ <TopBannerProvider>
<SidebarProvider>
<div className="flex h-dvh w-full flex-col">
<PaymentBanner />
+ <V4BetaEnabledBanner />
<div className="flex min-h-0 flex-1 pt-banner-offset">
<AppSidebar
navItems={navigation.mainNavigation}
@@ -130,7 +143,7 @@ export function AuthenticatedLayout({
</div>
</div>
</SidebarProvider>
- </PaymentBannerProvider>
+ </TopBannerProvider>
</>
);
}
diff --git a/web/src/features/events/components/V4BetaEnabledBanner.tsx b/web/src/features/events/components/V4BetaEnabledBanner.tsx
new file mode 100644
index 0000000000..7d7ec0ec11
--- /dev/null
+++ b/web/src/features/events/components/V4BetaEnabledBanner.tsx
@@ -0,0 +1,91 @@
+import { useEffect, useRef } from "react";
+import Link from "next/link";
+import { Sparkles, X } from "lucide-react";
+import { useSession } from "next-auth/react";
+import { Button } from "@/src/components/ui/button";
+import useLocalStorage from "@/src/components/useLocalStorage";
+import {
+ useTopBanner,
+ useTopBannerRegistration,
+} from "@/src/features/top-banner";
+import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
+
+const CHANGELOG_URL = "https://langfuse.com/changelog"; // TODO: update after changelog release
+const DISMISSED_STORAGE_KEY = "v4-beta-enabled-banner:v1:dismissed";
+const V4_BETA_BANNER_ID = "v4-beta-enabled-banner";
+const V4_BETA_BANNER_ORDER = 20;
+
+export function V4BetaEnabledBanner() {
+ const session = useSession();
+ const { isBetaEnabled } = useV4Beta();
+ const { getTopBannerOffset } = useTopBanner();
+ const [isDismissed, setIsDismissed] = useLocalStorage<boolean>(
+ DISMISSED_STORAGE_KEY,
+ false,
+ );
+ const bannerRef = useRef<HTMLDivElement>(null);
+
+ const isAuthenticated = session.status === "authenticated";
+ const isVisible = isAuthenticated && isBetaEnabled && !isDismissed;
+ const topOffset = getTopBannerOffset(V4_BETA_BANNER_ORDER);
+
+ useEffect(() => {
+ if (!isAuthenticated || isBetaEnabled || !isDismissed) {
+ return;
+ }
+
+ setIsDismissed(false);
+ }, [isAuthenticated, isBetaEnabled, isDismissed, setIsDismissed]);
+
+ useTopBannerRegistration({
+ bannerId: V4_BETA_BANNER_ID,
+ order: V4_BETA_BANNER_ORDER,
+ isVisible,
+ elementRef: bannerRef,
+ });
+
+ if (!isVisible) {
+ return null;
+ }
+
+ const dismissBanner = () => {
+ setIsDismissed(true);
+ };
+
+ return (
+ <div
+ ref={bannerRef}
+ className="fixed left-0 right-0 z-50 border-b bg-light-blue text-foreground"
+ style={{ top: `${topOffset}px` }}
+ role="status"
+ aria-live="polite"
+ >
+ <div className="flex items-center gap-3 px-4 py-1.5">
+ <Sparkles className="h-4 w-4 shrink-0" />
+ <p className="flex-1 text-sm">
+ <span className="font-semibold">v4 Beta is enabled.</span> You&apos;re
+ using Langfuse&apos;s new observation-centric architecture for faster
+ charts and APIs.{" "}
+ <Link
+ href={CHANGELOG_URL}
+ target="_blank"
+ className="font-medium underline underline-offset-2"
+ >
+ Read the blog post
+ </Link>
+ .
+ </p>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-6 w-6 p-0"
+ onClick={dismissBanner}
+ aria-label="Dismiss v4 beta banner"
+ title="Dismiss"
+ >
+ <X className="h-4 w-4" />
+ </Button>
+ </div>
+ </div>
+ );
+}
diff --git a/web/src/features/payment-banner/PaymentBanner.tsx b/web/src/features/payment-banner/PaymentBanner.tsx
index a28b758426..652d96ae65 100644
--- a/web/src/features/payment-banner/PaymentBanner.tsx
+++ b/web/src/features/payment-banner/PaymentBanner.tsx
@@ -1,21 +1,23 @@
-import { useEffect, useRef, useMemo } from "react";
+import { useMemo, useRef } from "react";
import { useSession } from "next-auth/react";
import { AlertCircle, CreditCard } from "lucide-react";
import Link from "next/link";
import { Button } from "@/src/components/ui/button";
import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";
import { useIsCloudBillingAvailable } from "@/src/ee/features/billing/utils/isCloudBilling";
-import { usePaymentBannerHeight } from "./PaymentBannerContext";
+import { useTopBannerRegistration } from "@/src/features/top-banner";
import { cn } from "@/src/utils/tailwind";
import { env } from "@/src/env.mjs";
import { hasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess";
import { cva } from "class-variance-authority";
+const PAYMENT_BANNER_ID = "payment-banner";
+const PAYMENT_BANNER_ORDER = 10;
+
export function PaymentBanner() {
const session = useSession();
const { organization } = useQueryProjectOrOrganization();
const isCloudBilling = useIsCloudBillingAvailable();
- const { setBannerHeight } = usePaymentBannerHeight();
const bannerRef = useRef<HTMLDivElement>(null);
const subscriptionStatus = useMemo(() => {
@@ -34,52 +36,28 @@ export function PaymentBanner() {
return organization?.cloudConfig?.stripe?.subscriptionStatus;
}, [isCloudBilling, session.status, organization]);
- // Update banner height when component mounts/unmounts or when visibility changes
- useEffect(() => {
- if (!bannerRef.current) {
- setBannerHeight(0);
- return;
+ const canManageBilling = useMemo(() => {
+ if (!organization) {
+ return false;
}
+ return hasOrganizationAccess({
+ session: session.data,
+ organizationId: organization.id,
+ scope: "langfuseCloudBilling:CRUD",
+ });
+ }, [organization, session.data]);
+
+ const hasBillingIssue =
+ subscriptionStatus === "past_due" || subscriptionStatus === "unpaid";
+ const isVisible = Boolean(
+ organization && hasBillingIssue && canManageBilling,
+ );
- const updateHeight = () => {
- if (bannerRef.current) {
- setBannerHeight(bannerRef.current.offsetHeight);
- } else {
- setBannerHeight(0);
- }
- };
-
- // Update height initially
- updateHeight();
-
- // Use ResizeObserver to track height changes
- const resizeObserver = new ResizeObserver(updateHeight);
- resizeObserver.observe(bannerRef.current);
-
- return () => {
- resizeObserver.disconnect();
- setBannerHeight(0);
- };
- }, [setBannerHeight, subscriptionStatus]);
-
- if (!organization) {
- return null;
- }
-
- if (!subscriptionStatus) {
- return null;
- }
-
- // Only show for past_due or unpaid
- if (subscriptionStatus !== "past_due" && subscriptionStatus !== "unpaid") {
- return null;
- }
-
- // Check if user has billing access (OWNER only)
- const canManageBilling = hasOrganizationAccess({
- session: session.data,
- organizationId: organization.id,
- scope: "langfuseCloudBilling:CRUD",
+ useTopBannerRegistration({
+ bannerId: PAYMENT_BANNER_ID,
+ order: PAYMENT_BANNER_ORDER,
+ isVisible,
+ elementRef: bannerRef,
});
// Determine severity styling
@@ -104,7 +82,7 @@ export function PaymentBanner() {
},
);
- if (!canManageBilling) {
+ if (!isVisible || !organization) {
return null;
}
@@ -120,24 +98,20 @@ export function PaymentBanner() {
<div className="flex flex-col gap-0.5 sm:flex-row sm:items-center sm:gap-2">
<span className="text-sm font-semibold">Billing Issue:</span>
<span className="text-sm">
- {canManageBilling
- ? `We have problems collecting subscription payment for your organization '${organization.name}'. Please update your payment information to continue using Langfuse.`
- : `We have problems collecting subscription payment for your organization '${organization.name}'. Please notify your organization administrator to avoid service interruption.`}
+ {`We have problems collecting subscription payment for your organization '${organization.name}'. Please update your payment information to continue using Langfuse.`}
</span>
</div>
</div>
<div className="flex items-center gap-2">
- {canManageBilling && (
- <Button size="sm" variant="ghost" asChild>
- <Link
- href={`${basePath}/organization/${organization.id}/settings/billing`}
- >
- <CreditCard className="mr-2 h-4 w-4" />
- Update Payment
- </Link>
- </Button>
- )}
+ <Button size="sm" variant="ghost" asChild>
+ <Link
+ href={`${basePath}/organization/${organization.id}/settings/billing`}
+ >
+ <CreditCard className="mr-2 h-4 w-4" />
+ Update Payment
+ </Link>
+ </Button>
</div>
</div>
);
diff --git a/web/src/features/payment-banner/PaymentBannerContext.tsx b/web/src/features/payment-banner/PaymentBannerContext.tsx
deleted file mode 100644
index a53d3d8595..0000000000
--- a/web/src/features/payment-banner/PaymentBannerContext.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import {
- createContext,
- useContext,
- useEffect,
- useState,
- type ReactNode,
-} from "react";
-
-interface PaymentBannerContextValue {
- bannerHeight: number;
- setBannerHeight: (height: number) => void;
-}
-
-const PaymentBannerContext = createContext<PaymentBannerContextValue | null>(
- null,
-);
-
-export function PaymentBannerProvider({ children }: { children: ReactNode }) {
- const [bannerHeight, setBannerHeight] = useState(0);
-
- useEffect(() => {
- // Note: CSS vars allow us to reduce re-renders of child-components and correct
- // CSS animations. Prefer using the CSS var over consuming the hook below to adjust layouts.
- // Example:
- // - <div className="h-[calc(100svh-var(--banner-height,0px))]"> --> correct height calculation
- document.documentElement.style.setProperty(
- "--banner-height",
- `${bannerHeight}px`,
- );
- }, [bannerHeight]);
-
- return (
- <PaymentBannerContext.Provider value={{ bannerHeight, setBannerHeight }}>
- {children}
- </PaymentBannerContext.Provider>
- );
-}
-
-export function usePaymentBannerHeight() {
- const context = useContext(PaymentBannerContext);
- if (!context) {
- throw new Error(
- "usePaymentBannerHeight must be used within PaymentBannerProvider",
- );
- }
- return context;
-}
diff --git a/web/src/features/payment-banner/index.ts b/web/src/features/payment-banner/index.ts
index cc7d7a3edb..10490a1c70 100644
--- a/web/src/features/payment-banner/index.ts
+++ b/web/src/features/payment-banner/index.ts
@@ -1,5 +1 @@
export { PaymentBanner } from "./PaymentBanner";
-export {
- PaymentBannerProvider,
- usePaymentBannerHeight,
-} from "./PaymentBannerContext";
diff --git a/web/src/features/top-banner/TopBannerContext.tsx b/web/src/features/top-banner/TopBannerContext.tsx
new file mode 100644
index 0000000000..1e25f754a8
--- /dev/null
+++ b/web/src/features/top-banner/TopBannerContext.tsx
@@ -0,0 +1,118 @@
+import {
+ createContext,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+ type ReactNode,
+} from "react";
+
+type TopBannerEntry = {
+ height: number;
+ order: number;
+};
+
+interface TopBannerContextValue {
+ bannerHeight: number;
+ setTopBannerHeight: (bannerId: string, height: number, order: number) => void;
+ getTopBannerOffset: (order: number) => number;
+}
+
+const TopBannerContext = createContext<TopBannerContextValue | null>(null);
+
+export function TopBannerProvider({ children }: { children: ReactNode }) {
+ const [topBannerHeights, setTopBannerHeights] = useState<
+ Record<string, TopBannerEntry>
+ >({});
+
+ const setTopBannerHeight = useCallback(
+ (bannerId: string, height: number, order: number) => {
+ setTopBannerHeights((prev) => {
+ if (height <= 0) {
+ if (!(bannerId in prev)) {
+ return prev;
+ }
+ const next = { ...prev };
+ delete next[bannerId];
+ return next;
+ }
+
+ const current = prev[bannerId];
+ if (current && current.height === height && current.order === order) {
+ return prev;
+ }
+
+ return {
+ ...prev,
+ [bannerId]: { height, order },
+ };
+ });
+ },
+ [],
+ );
+
+ const orderedTopBanners = useMemo(
+ () =>
+ Object.entries(topBannerHeights)
+ .map(([id, entry]) => ({
+ id,
+ ...entry,
+ }))
+ .sort((a, b) => a.order - b.order || a.id.localeCompare(b.id)),
+ [topBannerHeights],
+ );
+
+ const bannerHeight = useMemo(
+ () =>
+ orderedTopBanners.reduce((totalHeight, banner) => {
+ return totalHeight + banner.height;
+ }, 0),
+ [orderedTopBanners],
+ );
+
+ const getTopBannerOffset = useCallback(
+ (targetOrder: number) => {
+ let offset = 0;
+ for (const banner of orderedTopBanners) {
+ if (banner.order >= targetOrder) {
+ break;
+ }
+ offset += banner.height;
+ }
+ return offset;
+ },
+ [orderedTopBanners],
+ );
+
+ useEffect(() => {
+ // Note: CSS vars allow us to reduce re-renders of child-components and correct
+ // CSS animations. Prefer using the CSS var over consuming the hook below to adjust layouts.
+ // Example:
+ // - <div className="h-[calc(100svh-var(--banner-height,0px))]"> --> correct height calculation
+ document.documentElement.style.setProperty(
+ "--banner-height",
+ `${bannerHeight}px`,
+ );
+ }, [bannerHeight]);
+
+ return (
+ <TopBannerContext.Provider
+ value={{
+ bannerHeight,
+ setTopBannerHeight,
+ getTopBannerOffset,
+ }}
+ >
+ {children}
+ </TopBannerContext.Provider>
+ );
+}
+
+export function useTopBanner() {
+ const context = useContext(TopBannerContext);
+ if (!context) {
+ throw new Error("useTopBanner must be used within TopBannerProvider");
+ }
+ return context;
+}
diff --git a/web/src/features/top-banner/index.ts b/web/src/features/top-banner/index.ts
new file mode 100644
index 0000000000..c4351dec84
--- /dev/null
+++ b/web/src/features/top-banner/index.ts
@@ -0,0 +1,2 @@
+export { TopBannerProvider, useTopBanner } from "./TopBannerContext";
+export { useTopBannerRegistration } from "./useTopBannerRegistration";
diff --git a/web/src/features/top-banner/useTopBannerRegistration.ts b/web/src/features/top-banner/useTopBannerRegistration.ts
new file mode 100644
index 0000000000..a4791b356e
--- /dev/null
+++ b/web/src/features/top-banner/useTopBannerRegistration.ts
@@ -0,0 +1,43 @@
+import { useEffect, type RefObject } from "react";
+import { useTopBanner } from "./TopBannerContext";
+
+type UseTopBannerRegistrationParams<T extends HTMLElement> = {
+ bannerId: string;
+ order: number;
+ isVisible: boolean;
+ elementRef: RefObject<T | null>;
+};
+
+export function useTopBannerRegistration<T extends HTMLElement>({
+ bannerId,
+ order,
+ isVisible,
+ elementRef,
+}: UseTopBannerRegistrationParams<T>) {
+ const { setTopBannerHeight } = useTopBanner();
+
+ useEffect(() => {
+ if (!isVisible || !elementRef.current) {
+ setTopBannerHeight(bannerId, 0, order);
+ return;
+ }
+
+ const updateHeight = () => {
+ if (elementRef.current) {
+ setTopBannerHeight(bannerId, elementRef.current.offsetHeight, order);
+ } else {
+ setTopBannerHeight(bannerId, 0, order);
+ }
+ };
+
+ updateHeight();
+
+ const resizeObserver = new ResizeObserver(updateHeight);
+ resizeObserver.observe(elementRef.current);
+
+ return () => {
+ resizeObserver.disconnect();
+ setTopBannerHeight(bannerId, 0, order);
+ };
+ }, [bannerId, order, isVisible, setTopBannerHeight, elementRef]);
+}