fix(webui): align provider icons across compact surfaces
This commit is contained in:
1 parent
5aac672b98
commit
f4d863a148
7 files changed
+149
-9
No files matched your search
@@ -38,6 +38,7 @@ import type {
|
||||
} from "@/lib/local-preferences";
|
||||
import { providerBrand, providerDisplayLabel } from "@/lib/provider-brand";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useClient } from "@/providers/ClientProvider";
|
||||
|
||||
export function OverviewSettings({
|
||||
@@ -405,7 +406,8 @@ function OverviewValueLogo({
|
||||
showBrandLogos: boolean;
|
||||
}) {
|
||||
const brand = provider ? providerBrand(provider) : null;
|
||||
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
||||
const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
||||
const isLogoTile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl;
|
||||
|
||||
if (!provider || !showBrandLogos || !brand) return null;
|
||||
|
||||
@@ -413,7 +415,10 @@ function OverviewValueLogo({
|
||||
return (
|
||||
<span
|
||||
data-testid={`overview-logo-${provider}`}
|
||||
className="grid h-5 w-5 shrink-0 place-items-center overflow-hidden rounded-md border border-border/35 bg-background"
|
||||
className={cn(
|
||||
"grid h-5 w-5 shrink-0 place-items-center overflow-hidden rounded-md",
|
||||
logoLoaded ? (isLogoTile ? "bg-transparent" : "bg-white") : "bg-muted",
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
<img
|
||||
@@ -421,7 +426,13 @@ function OverviewValueLogo({
|
||||
alt=""
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
className="h-3.5 w-3.5 object-contain"
|
||||
referrerPolicy="no-referrer"
|
||||
draggable={false}
|
||||
className={cn(
|
||||
"object-contain",
|
||||
isLogoTile ? "h-5 w-5" : "h-3.5 w-3.5",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
onLoad={onLogoLoad}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
|
||||
@@ -501,7 +501,8 @@ export function ProviderPickerIcon({
|
||||
}) {
|
||||
const brand = providerBrand(provider);
|
||||
const Icon = PROVIDER_ICONS[provider] ?? Hexagon;
|
||||
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
||||
const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
||||
const isLogoTile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl;
|
||||
|
||||
if (unconfigured) {
|
||||
return (
|
||||
@@ -519,7 +520,10 @@ export function ProviderPickerIcon({
|
||||
return (
|
||||
<span
|
||||
data-testid={`provider-picker-logo-${provider}`}
|
||||
className="grid h-5 w-5 shrink-0 place-items-center overflow-hidden rounded-md border border-border/35 bg-background"
|
||||
className={cn(
|
||||
"grid h-5 w-5 shrink-0 place-items-center overflow-hidden rounded-md",
|
||||
logoLoaded ? (isLogoTile ? "bg-transparent" : "bg-white") : "bg-muted",
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
<img
|
||||
@@ -527,7 +531,13 @@ export function ProviderPickerIcon({
|
||||
alt=""
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
className="h-3.5 w-3.5 object-contain"
|
||||
referrerPolicy="no-referrer"
|
||||
draggable={false}
|
||||
className={cn(
|
||||
"object-contain",
|
||||
isLogoTile ? "h-5 w-5" : "h-3.5 w-3.5",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
onLoad={onLogoLoad}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
|
||||
@@ -617,13 +617,15 @@ function PresetProviderIcon({
|
||||
}) {
|
||||
const inferredProvider = provider || inferProviderFromModelName(modelDetail || label);
|
||||
const brand = providerBrand(inferredProvider);
|
||||
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
||||
const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(brand?.logoUrls);
|
||||
const isLogoTile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl;
|
||||
return (
|
||||
<span
|
||||
data-testid={testId}
|
||||
className={cn(
|
||||
"grid shrink-0 place-items-center",
|
||||
"grid shrink-0 place-items-center overflow-hidden rounded-[5px]",
|
||||
isHero ? "h-4 w-4" : "h-[18px] w-[18px]",
|
||||
logoUrl && (logoLoaded ? (isLogoTile ? "bg-transparent" : "bg-white") : "bg-muted"),
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
@@ -634,7 +636,12 @@ function PresetProviderIcon({
|
||||
draggable={false}
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
className={cn("object-contain", isHero ? "h-3.5 w-3.5" : "h-[18px] w-[18px]")}
|
||||
referrerPolicy="no-referrer"
|
||||
className={cn(
|
||||
"object-contain",
|
||||
isLogoTile ? "h-full w-full" : "h-3.5 w-3.5",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
onLoad={onLogoLoad}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
|
||||
@@ -133,6 +133,8 @@ const PROVIDER_BRAND_ALIASES: Record<string, string> = {
|
||||
minimaxAnthropic: "minimax",
|
||||
minimax_anthropic: "minimax",
|
||||
openai_codex: "openai",
|
||||
opencode_zen: "opencode",
|
||||
opencode_go: "opencode",
|
||||
"xai-grok": "xai",
|
||||
xai_grok: "xai",
|
||||
xiaomi: "xiaomi_mimo",
|
||||
@@ -164,6 +166,9 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
dashscope: brand("dashscope.aliyun.com", "#FF6A00", "DS"),
|
||||
deepseek: brand("deepseek.com", "#4D6BFE", "DS"),
|
||||
duckduckgo: brand("duckduckgo.com", "#DE5833", "DDG"),
|
||||
edenai: brand("edenai.co", "#080F35", "EA", [
|
||||
"https://cdn.prod.website-files.com/61e7d259b7746e2d1df0b68d/6a63231f5c459827c2d18d7a_eden%20ai%20logo%20light.png",
|
||||
]),
|
||||
exa: { ...brand("exa.ai", "#5B5BF6", "E"), logoLayout: "tile" },
|
||||
gemini: brand("gemini.google.com", "#4285F4", "G"),
|
||||
github_copilot: brand("github.com", "#24292F", "GH", [
|
||||
@@ -177,6 +182,9 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
jina: brand("jina.ai", "#7C3AED", "J"),
|
||||
kagi: brand("kagi.com", "#FFB319", "K"),
|
||||
keenable: brand("keenable.ai", "#0EA5E9", "K"),
|
||||
kimi_coding: brand("kimi.com", "#1783FF", "K", [
|
||||
"https://raw.githubusercontent.com/MoonshotAI/Branding-Guide/main/scenarios/04-k-only/k-only-light.svg",
|
||||
]),
|
||||
lm_studio: { ...brand("lmstudio.ai", "#111827", "LM"), logoLayout: "tile" },
|
||||
longcat: brand("longcat.ai", "#4F8CFF", "LC", [
|
||||
"https://s3plus.meituan.net/aigc-media-resources/longcat/yeqian-logo.svg",
|
||||
@@ -195,6 +203,9 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
nvidia: brand("nvidia.com", "#76B900", "NV"),
|
||||
ollama: brand("ollama.com", "#111827", "O"),
|
||||
openai: brand("openai.com", "#111827", "AI"),
|
||||
opencode: brand("opencode.ai", "#111827", "OC", [
|
||||
"https://opencode.ai/favicon-96x96-v3.png",
|
||||
]),
|
||||
openrouter: brand("openrouter.ai", "#111827", "OR", [
|
||||
"https://openrouter.ai/brand/logos/transparent/glyph/svg/glyph-grape.svg",
|
||||
]),
|
||||
|
||||
@@ -9,6 +9,17 @@ import {
|
||||
} from "@/lib/provider-brand";
|
||||
|
||||
describe("provider brand logos", () => {
|
||||
it("covers Eden AI, OpenCode variants, and Kimi Coding with their official assets", () => {
|
||||
expect(providerBrand("edenai")?.logoUrl).toContain("cdn.prod.website-files.com/");
|
||||
expect(providerBrand("opencode")?.logoUrl).toBe("https://opencode.ai/favicon-96x96-v3.png");
|
||||
expect(providerBrand("opencode_zen")).toBe(providerBrand("opencode"));
|
||||
expect(providerBrand("opencode_go")).toBe(providerBrand("opencode"));
|
||||
expect(providerBrand("kimi_coding")?.logoUrl).toBe(
|
||||
"https://raw.githubusercontent.com/MoonshotAI/Branding-Guide/main/scenarios/04-k-only/k-only-light.svg",
|
||||
);
|
||||
expect(providerBrand("kimi_coding")).not.toBe(providerBrand("moonshot"));
|
||||
});
|
||||
|
||||
it("uses multiple favicon sources before falling back to initials", () => {
|
||||
expect(faviconUrls("z.ai")).toEqual([
|
||||
"https://z.ai/favicon.ico",
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { cleanup, fireEvent, render } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { OverviewSettings } from "@/components/settings/overview/OverviewSettings";
|
||||
import { ProviderPickerIcon } from "@/components/settings/shared/ModelControls";
|
||||
import { ModelPresetBadge } from "@/components/thread/ModelPresetBadge";
|
||||
import { __clearLogoFallbackCacheForTests } from "@/hooks/useLogoFallback";
|
||||
import { providerBrand } from "@/lib/provider-brand";
|
||||
import { settingsPayload } from "@/tests/settings-test-utils";
|
||||
|
||||
describe.each(["picker", "overview", "composer", "hero"] as const)("%s provider logos", (surface) => {
|
||||
beforeEach(__clearLogoFallbackCacheForTests);
|
||||
afterEach(cleanup);
|
||||
|
||||
function renderIcon(provider: string, showBrandLogos = true) {
|
||||
const settings = settingsPayload();
|
||||
settings.agent.resolved_provider = provider;
|
||||
const view = render(surface === "picker"
|
||||
? <ProviderPickerIcon provider={provider} showBrandLogos={showBrandLogos} />
|
||||
: surface === "overview"
|
||||
? <OverviewSettings settings={settings} showBrandLogos={showBrandLogos} onSelectSection={() => {}} />
|
||||
: <ModelPresetBadge provider={provider} label={provider} isHero={surface === "hero"} />);
|
||||
const prefix = surface === "picker" ? "provider-picker" : surface === "overview" ? "overview" : "composer-model";
|
||||
return { ...view, icon: () => view.getByTestId(`${prefix}-logo-${provider}`) };
|
||||
}
|
||||
|
||||
function expectFrame(icon: HTMLElement) {
|
||||
expect(icon).toHaveClass("shrink-0", "overflow-hidden");
|
||||
expect(icon.className.split(/\s+/).some((value) => value.startsWith("border"))).toBe(false);
|
||||
if (surface === "composer") expect(icon).toHaveClass("h-[18px]", "w-[18px]");
|
||||
else if (surface === "hero") expect(icon).toHaveClass("h-4", "w-4");
|
||||
else expect(icon).toHaveClass("h-5", "w-5");
|
||||
}
|
||||
|
||||
it.each(["github_copilot", "deepseek", "kimi_coding"])("keeps %s readable on a white inset tile", (provider) => {
|
||||
const view = renderIcon(provider);
|
||||
const icon = view.icon();
|
||||
const image = icon.querySelector("img")!;
|
||||
expectFrame(icon);
|
||||
expect(icon).toHaveClass("bg-muted");
|
||||
expect(image).toHaveClass("h-3.5", "w-3.5", "opacity-0");
|
||||
fireEvent.load(image);
|
||||
expect(icon).toHaveClass("bg-white");
|
||||
expect(image).toHaveClass("opacity-100");
|
||||
});
|
||||
|
||||
it("avoids the Moonshot halo, and insets unknown fallback images", () => {
|
||||
const view = renderIcon("moonshot");
|
||||
const icon = view.icon();
|
||||
const image = icon.querySelector("img")!;
|
||||
expectFrame(icon);
|
||||
fireEvent.load(image);
|
||||
expect(icon).toHaveClass("bg-transparent");
|
||||
expect(icon).not.toHaveClass("bg-white");
|
||||
expect(image).toHaveClass(surface === "composer" || surface === "hero" ? "h-full" : "h-5");
|
||||
fireEvent.error(image);
|
||||
expect(image).toHaveAttribute("src", providerBrand("moonshot")!.logoUrls[1]);
|
||||
expect(icon).toHaveClass("bg-muted");
|
||||
expect(image).toHaveClass("h-3.5", "w-3.5", "opacity-0");
|
||||
fireEvent.load(image);
|
||||
expect(icon).toHaveClass("bg-white");
|
||||
expect(image).toHaveClass("opacity-100");
|
||||
});
|
||||
|
||||
it("falls back to initials when every URL fails", () => {
|
||||
const view = renderIcon("moonshot");
|
||||
for (const url of providerBrand("moonshot")!.logoUrls) {
|
||||
const image = view.container.querySelector("img")!;
|
||||
expect(image).toHaveAttribute("src", url);
|
||||
fireEvent.error(image);
|
||||
}
|
||||
expect(view.container).toHaveTextContent("MS");
|
||||
expect(view.container.querySelector(`img[src="${providerBrand("moonshot")!.logoUrl}"]`)).toBeNull();
|
||||
});
|
||||
|
||||
if (surface === "picker" || surface === "overview") {
|
||||
it("does not show remote logos when disabled", () => {
|
||||
const view = renderIcon("moonshot", false);
|
||||
expect(view.container.querySelector("img")).toBeNull();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves the unconfigured-provider warning", () => {
|
||||
const view = render(<ProviderPickerIcon provider="moonshot" showBrandLogos unconfigured />);
|
||||
expect(view.getByTestId("provider-picker-unconfigured-icon")).toHaveClass("text-amber-700");
|
||||
expect(view.container.querySelector("img")).toBeNull();
|
||||
cleanup();
|
||||
});
|
||||
@@ -16,6 +16,7 @@ describe("settings provider icons", () => {
|
||||
|
||||
it.each([
|
||||
"openai_codex", "anthropic", "deepseek", "gemini", "xai_grok", "longcat", "openrouter", "github_copilot",
|
||||
"edenai", "opencode", "opencode_zen", "opencode_go", "kimi_coding",
|
||||
])(
|
||||
"shows %s on a single white tile with a small inset after loading",
|
||||
(provider) => {
|
||||
|
||||
Reference in new issue
Block a user