Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
],
"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 120,
"editor.cursorWidth": 3,
"editor.cursorBlinking": "solid",
"editor.formatOnSave": true,
"[javascript][typescript][json][jsonc][tsx][jsx][css]": {
"editor.formatOnSave": true
Expand Down
33 changes: 29 additions & 4 deletions app/_components/dashboard-link.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import Link from "next/link";

const DASHBOARD_BASE_URL =
process.env.NEXT_PUBLIC_DASHBOARD_URL || "https://api.arcade.dev";
process.env.NEXT_PUBLIC_DASHBOARD_URL || "https://app.arcade.dev";

const normalizePath = (value: string): string =>
value.replace(/\/+$/, "").replace(/^\/+/, "");

const resolveDashboardPrefix = (): string => {
const baseUrl = DASHBOARD_BASE_URL.toLowerCase();
const explicitPrefix = process.env.NEXT_PUBLIC_DASHBOARD_PATH_PREFIX;

if (explicitPrefix !== undefined) {
return normalizePath(explicitPrefix);
}

if (baseUrl.includes("/dashboard") || baseUrl.includes("app.arcade.dev")) {
return "";
}

return "dashboard";
};

const DASHBOARD_PATH_PREFIX = resolveDashboardPrefix();
const BASE_URL = DASHBOARD_BASE_URL.replace(/\/+$/, "");

export const getDashboardUrl = (path = "") =>
path
? `${DASHBOARD_BASE_URL}/dashboard/${path}`
: `${DASHBOARD_BASE_URL}/dashboard`;
[
BASE_URL,
DASHBOARD_PATH_PREFIX,
path ? normalizePath(path) : "",
]
.filter(Boolean)
.join("/");

type DashboardLinkProps = {
path?: string;
Expand Down
27 changes: 20 additions & 7 deletions app/_components/posthog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { useEffect } from "react";

function createNoopPosthogClient() {
return {
capture: () => {},
identify: () => {},
reset: () => {},
// biome-ignore lint/suspicious/noExplicitAny: Minimal no-op client for disabled analytics
} as any;
}

export const PostHog = ({ children }: { children: React.ReactNode }) => {
const pathname = usePathname();
const isEnabled = Boolean(process.env.NEXT_PUBLIC_POSTHOG_KEY);

useEffect(() => {
if (process.env.NEXT_PUBLIC_POSTHOG_KEY) {
if (isEnabled) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host:
process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://us.i.posthog.com",
Expand All @@ -34,18 +44,21 @@ export const PostHog = ({ children }: { children: React.ReactNode }) => {
},
});
} else {
// biome-ignore lint/suspicious/noConsole: This is ok for PostHog
console.warn("Analytics is disabled because no key is set");
// No key: keep analytics fully disabled and avoid noisy console errors.
}
}, []);
}, [isEnabled]);

// Track page views when pathname changes
// biome-ignore lint/correctness/useExhaustiveDependencies: pathname is required for route change tracking
useEffect(() => {
if (process.env.NEXT_PUBLIC_POSTHOG_KEY) {
if (isEnabled) {
posthog?.capture("$pageview");
}
}, [pathname]);
}, [pathname, isEnabled]);

return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
return (
<PostHogProvider client={isEnabled ? posthog : createNoopPosthogClient()}>
{children}
</PostHogProvider>
);
};
28 changes: 28 additions & 0 deletions app/_components/scope-picker.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, expect, it } from "vitest";

import { getRequiredScopes, getSelectedToolNames } from "./scope-picker";

describe("scope picker helpers", () => {
const tools = [
{ name: "SendEmail", scopes: ["scope.send", " scope.send "] },
{ name: "ListEmails", scopes: ["scope.read", ""] },
];

it("filters selected tools to known names only", () => {
const selected = new Set(["SendEmail", "UnknownTool"]);

expect(getSelectedToolNames(tools, selected)).toEqual(["SendEmail"]);
});

it("builds required scopes for selected tools", () => {
const selected = new Set(["SendEmail", "ListEmails"]);

expect(getRequiredScopes(tools, selected)).toEqual(["scope.read", "scope.send"]);
});

it("returns empty scopes when no valid tools selected", () => {
const selected = new Set(["UnknownTool"]);

expect(getRequiredScopes(tools, selected)).toEqual([]);
});
});
Loading