Skip to content

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

feat(cloud): improve upgrade ui (#3331)

Marc Klingencc60d506a7ae
diff --git a/web/src/components/layouts/header.tsx b/web/src/components/layouts/header.tsx
index 9a42e8d32c..9246499889 100644
--- a/web/src/components/layouts/header.tsx
+++ b/web/src/components/layouts/header.tsx
@@ -35,6 +35,7 @@ import {
createOrganizationRoute,
createProjectRoute,
} from "@/src/features/setup/setupRoutes";
+import { isCloudPlan, planLabels } from "@langfuse/shared";
export default function Header({
level = "h2",
@@ -170,8 +171,17 @@ const BreadcrumbComponent = ({
<BreadcrumbList>
{organization && (
<DropdownMenu>
- <DropdownMenuTrigger className="flex items-center gap-1">
+ <DropdownMenuTrigger className="flex items-center gap-1 text-sm text-primary">
{organization?.name ?? "Organization"}
+ {isCloudPlan(organization?.plan) &&
+ organization.id !== env.NEXT_PUBLIC_DEMO_ORG_ID && (
+ <Badge
+ className="ml-1 px-1 py-0 text-xs font-normal"
+ variant="secondary"
+ >
+ {planLabels[organization.plan]}
+ </Badge>
+ )}
<ChevronDownIcon className="h-4 w-4" />
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
@@ -265,7 +275,7 @@ const BreadcrumbComponent = ({
<Slash />
</BreadcrumbSeparator>
<DropdownMenu>
- <DropdownMenuTrigger className="flex items-center gap-1">
+ <DropdownMenuTrigger className="flex items-center gap-1 text-primary">
{project?.name ?? "Project"}
<ChevronDownIcon className="h-4 w-4" />
</DropdownMenuTrigger>
diff --git a/web/src/components/layouts/layout.tsx b/web/src/components/layouts/layout.tsx
index f73616d3f9..f4235299eb 100644
--- a/web/src/components/layouts/layout.tsx
+++ b/web/src/components/layouts/layout.tsx
@@ -33,6 +33,7 @@ import { EnvLabel } from "@/src/components/EnvLabel";
import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";
import { useOrgEntitlements } from "@/src/features/entitlements/hooks";
import { useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization";
+import { hasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess";
const signOutUser = async () => {
localStorage.clear();
@@ -164,6 +165,21 @@ export default function Layout(props: PropsWithChildren) {
}))
)
return null;
+ if (
+ route.organizationRbacScope !== undefined &&
+ !cloudAdmin &&
+ (!organization ||
+ !hasOrganizationAccess({
+ organizationId: organization.id,
+ scope: route.organizationRbacScope,
+ session: session.data,
+ }))
+ )
+ return null;
+
+ // check show function
+ if (route.show && !route.show({ organization: organization ?? undefined }))
+ return null;
// apply to children as well
const children: (NavigationItem | null)[] =
@@ -520,7 +536,7 @@ export default function Layout(props: PropsWithChildren) {
env.NEXT_PUBLIC_DEMO_PROJECT_ID &&
routerProjectId === env.NEXT_PUBLIC_DEMO_PROJECT_ID &&
Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) ? (
- <div className="flex w-full items-center border-b border-dark-yellow bg-light-yellow px-4 py-2 lg:sticky lg:top-0 lg:z-40">
+ <div className="flex w-full items-center border-b border-dark-yellow bg-light-yellow px-4 py-2 lg:sticky lg:top-0 lg:z-40">
<div className="flex flex-1 flex-wrap gap-1">
<div className="flex items-center gap-1">
<Info className="h-4 w-4" />
diff --git a/web/src/components/layouts/routes.tsx b/web/src/components/layouts/routes.tsx
index 0e5dd34219..90f4d97d6b 100644
--- a/web/src/components/layouts/routes.tsx
+++ b/web/src/components/layouts/routes.tsx
@@ -13,18 +13,22 @@ import {
TerminalIcon,
Lightbulb,
Grid2X2,
+ Sparkle,
} from "lucide-react";
import { LangfuseIcon } from "@/src/components/LangfuseLogo";
import { type ReactNode } from "react";
import { VersionLabel } from "@/src/components/VersionLabel";
import { type Entitlement } from "@/src/features/entitlements/constants/entitlements";
import { type UiCustomizationOption } from "@/src/ee/features/ui-customization/useUiCustomization";
+import { type User } from "next-auth";
+import { type OrganizationScope } from "@/src/features/rbac/constants/organizationAccessRights";
export type Route = {
name: string;
featureFlag?: Flag;
label?: string | ReactNode;
projectRbacScope?: ProjectScope;
+ organizationRbacScope?: OrganizationScope;
icon?: LucideIcon | typeof LangfuseIcon; // ignored for nested routes
pathname?: string; // link, ignored if children
children?: Array<Route>; // folder
@@ -32,6 +36,9 @@ export type Route = {
newTab?: boolean; // open in new tab
entitlement?: Entitlement; // entitlement required
customizableHref?: UiCustomizationOption; // key of useUiCustomization object to use to replace the href
+ show?: (p: {
+ organization: User["organizations"][number] | undefined;
+ }) => boolean;
};
export const ROUTES: Route[] = [
@@ -125,6 +132,24 @@ export const ROUTES: Route[] = [
pathname: `/project/[projectId]/datasets`,
icon: Database,
},
+ {
+ name: "Upgrade",
+ icon: Sparkle,
+ pathname: "/project/[projectId]/settings/billing",
+ bottom: true,
+ entitlement: "cloud-billing",
+ organizationRbacScope: "langfuseCloudBilling:CRUD",
+ show: ({ organization }) => organization?.plan === "cloud:hobby",
+ },
+ {
+ name: "Upgrade",
+ icon: Sparkle,
+ pathname: "/organization/[organizationId]/settings/billing",
+ bottom: true,
+ entitlement: "cloud-billing",
+ organizationRbacScope: "langfuseCloudBilling:CRUD",
+ show: ({ organization }) => organization?.plan === "cloud:hobby",
+ },
{
name: "Settings",
pathname: "/project/[projectId]/settings",
diff --git a/web/src/features/organizations/components/ProjectOverview.tsx b/web/src/features/organizations/components/ProjectOverview.tsx
index 3599f4da9d..befc57bdbf 100644
--- a/web/src/features/organizations/components/ProjectOverview.tsx
+++ b/web/src/features/organizations/components/ProjectOverview.tsx
@@ -85,7 +85,7 @@ const SingleOrganizationProjectOverview = ({
level={level}
status={orgId === env.NEXT_PUBLIC_DEMO_ORG_ID ? "Demo Org" : undefined}
label={
- isCloudPlan(org.plan)
+ isCloudPlan(org.plan) && level === "h3"
? {
text: planLabels[org.plan],
href: `/organization/${org.id}/settings/billing`,
diff --git a/web/src/pages/project/[projectId]/settings/billing.ts b/web/src/pages/project/[projectId]/settings/billing.ts
new file mode 100644
index 0000000000..f6a61a155b
--- /dev/null
+++ b/web/src/pages/project/[projectId]/settings/billing.ts
@@ -0,0 +1,17 @@
+import { useQueryProject } from "@/src/features/projects/hooks";
+import { useRouter } from "next/router";
+import { useEffect } from "react";
+
+export default function ProjectBillingRedirect() {
+ const router = useRouter();
+
+ const { organization } = useQueryProject();
+
+ useEffect(() => {
+ if (organization) {
+ router.replace(`/organization/${organization.id}/settings/billing`);
+ }
+ }, [organization, router]);
+
+ return "Redirecting...";
+}
diff --git a/web/src/pages/project/[projectId]/settings/index.tsx b/web/src/pages/project/[projectId]/settings/index.tsx
index 3a780a76cf..092ea32267 100644
--- a/web/src/pages/project/[projectId]/settings/index.tsx
+++ b/web/src/pages/project/[projectId]/settings/index.tsx
@@ -24,6 +24,7 @@ import { SettingsDangerZone } from "@/src/components/SettingsDangerZone";
export default function SettingsPage() {
const { project, organization } = useQueryProject();
const router = useRouter();
+ const showBillingSettings = useHasOrgEntitlement("cloud-billing");
if (!project || !organization) return null;
return (
<div className="lg:container">
@@ -108,6 +109,12 @@ export default function SettingsPage() {
slug: "integrations",
content: <Integrations projectId={project.id} />,
},
+ {
+ title: "Billing",
+ slug: "billing",
+ href: `/organization/${organization.id}/settings/billing`,
+ show: showBillingSettings,
+ },
{
title: "Organization Settings",
slug: "organization",