fix(webui): align model provider logos with Apps (NAN-131)
This commit is contained in:
1 parent
a3686d5eba
commit
eac2364898
4 files changed
+157
-26
No files matched your search
@@ -758,7 +758,7 @@ export function ModelsSettings({
|
||||
{presetConfigured ? (
|
||||
<ProviderIcon provider={provider} showBrandLogos={showBrandLogos} />
|
||||
) : (
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center">
|
||||
<span className="grid h-9 w-9 shrink-0 place-items-center">
|
||||
<ProviderPickerIcon provider={provider} showBrandLogos={showBrandLogos} unconfigured />
|
||||
</span>
|
||||
)}
|
||||
|
||||
@@ -1184,7 +1184,7 @@ export function ProvidersSettings({
|
||||
className="group settings-list-row flex w-full items-center justify-between gap-4 py-2.5 text-left transition-colors settings-hover"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-3">
|
||||
<span className="grid h-10 w-10 shrink-0 place-items-center rounded-control bg-muted text-muted-foreground">
|
||||
<span className="grid h-9 w-9 shrink-0 place-items-center rounded-[10px] bg-muted text-muted-foreground">
|
||||
<Plus className="h-5 w-5" aria-hidden />
|
||||
</span>
|
||||
<span className="truncate text-[14px] font-medium text-foreground">
|
||||
@@ -1272,41 +1272,45 @@ export function ProviderIcon({
|
||||
}) {
|
||||
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 showRemoteLogo = showBrandLogos && Boolean(logoUrl);
|
||||
const showLoadedLogo = showRemoteLogo && logoLoaded;
|
||||
|
||||
if (showBrandLogos && logoUrl) {
|
||||
return (
|
||||
return (
|
||||
<span
|
||||
data-testid={`provider-logo-${provider}`}
|
||||
className={cn(
|
||||
"relative grid h-9 w-9 shrink-0 place-items-center overflow-hidden rounded-[10px] text-[12px] font-semibold text-muted-foreground",
|
||||
showLoadedLogo ? "bg-transparent" : "bg-muted",
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
<span
|
||||
data-testid={`provider-logo-${provider}`}
|
||||
className="grid h-8 w-8 shrink-0 place-items-center overflow-hidden rounded-control border border-border/45 bg-background"
|
||||
className={cn(
|
||||
"transition-opacity duration-150 motion-reduce:transition-none",
|
||||
showLoadedLogo ? "opacity-0" : "opacity-100",
|
||||
)}
|
||||
>
|
||||
{showBrandLogos && brand
|
||||
? brand.initials
|
||||
: <Icon className="h-5 w-5" strokeWidth={2} />}
|
||||
</span>
|
||||
{showRemoteLogo ? (
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt=""
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
className="h-6 w-6 object-contain"
|
||||
referrerPolicy="no-referrer"
|
||||
draggable={false}
|
||||
className={cn(
|
||||
"absolute h-full w-full object-contain transition-opacity duration-150 motion-reduce:transition-none",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
onLoad={onLogoLoad}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (showBrandLogos && brand) {
|
||||
return (
|
||||
<span
|
||||
data-testid={`provider-logo-fallback-${provider}`}
|
||||
className="grid h-8 w-8 shrink-0 place-items-center rounded-control text-[11px] font-semibold text-white"
|
||||
style={{ backgroundColor: brand.color }}
|
||||
aria-hidden
|
||||
>
|
||||
{brand.initials}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center rounded-control bg-muted text-foreground/82 dark:bg-muted/70">
|
||||
<Icon className="h-5 w-5" strokeWidth={2} aria-hidden />
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { cleanup, fireEvent, render } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { ProviderIcon } from "@/components/settings/models/ProviderSettings";
|
||||
import { __clearLogoFallbackCacheForTests } from "@/hooks/useLogoFallback";
|
||||
import { providerBrand } from "@/lib/provider-brand";
|
||||
|
||||
describe("settings provider icons", () => {
|
||||
beforeEach(__clearLogoFallbackCacheForTests);
|
||||
afterEach(cleanup);
|
||||
|
||||
function expectFootprint(icon: Element) {
|
||||
expect(icon).toHaveClass("h-9", "w-9", "shrink-0", "overflow-hidden", "rounded-[10px]");
|
||||
expect(icon.className.split(/\s+/).some((value) => value.startsWith("border"))).toBe(false);
|
||||
}
|
||||
|
||||
it.each(["openai_codex", "anthropic", "deepseek", "gemini", "xai_grok"])(
|
||||
"shows %s as a single full-size logo after loading",
|
||||
(provider) => {
|
||||
const { container } = render(<ProviderIcon provider={provider} showBrandLogos />);
|
||||
const icon = container.firstElementChild!;
|
||||
const image = icon.querySelector("img")!;
|
||||
const fallback = icon.querySelector("span")!;
|
||||
|
||||
expectFootprint(icon);
|
||||
expect(icon).toHaveClass("bg-muted");
|
||||
expect(fallback).toHaveTextContent(providerBrand(provider)!.initials);
|
||||
expect(fallback).toHaveClass("opacity-100");
|
||||
expect(image).toHaveClass("h-full", "w-full", "object-contain", "opacity-0");
|
||||
expect(image).toHaveAttribute("alt", "");
|
||||
|
||||
fireEvent.load(image);
|
||||
|
||||
expectFootprint(icon);
|
||||
expect(icon).toHaveClass("bg-transparent");
|
||||
expect(icon).not.toHaveClass("bg-muted");
|
||||
expect(icon).not.toHaveAttribute("style");
|
||||
expect(fallback).toHaveClass("opacity-0");
|
||||
expect(image).toHaveClass("opacity-100");
|
||||
expect(image).not.toHaveClass("invert", "grayscale");
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps its placeholder through alternate URLs and complete image failure", () => {
|
||||
const { container } = render(<ProviderIcon provider="openai_codex" showBrandLogos />);
|
||||
const icon = container.firstElementChild!;
|
||||
const fallback = icon.querySelector("span")!;
|
||||
|
||||
for (const url of providerBrand("openai_codex")!.logoUrls) {
|
||||
const image = icon.querySelector("img")!;
|
||||
expect(image).toHaveAttribute("src", url);
|
||||
expect(image).toHaveClass("opacity-0");
|
||||
fireEvent.error(image);
|
||||
expect(container.firstElementChild).toBe(icon);
|
||||
expectFootprint(icon);
|
||||
expect(icon).toHaveClass("bg-muted");
|
||||
expect(fallback).toHaveClass("opacity-100");
|
||||
}
|
||||
|
||||
expect(icon.querySelector("img")).toBeNull();
|
||||
expect(fallback).toHaveTextContent("AI");
|
||||
expect(icon).toHaveAttribute("aria-hidden", "true");
|
||||
});
|
||||
|
||||
it("respects disabled brand logos without changing footprint, including cached logos", () => {
|
||||
const { container, rerender } = render(<ProviderIcon provider="openai_codex" showBrandLogos />);
|
||||
const icon = container.firstElementChild!;
|
||||
fireEvent.load(icon.querySelector("img")!);
|
||||
|
||||
rerender(<ProviderIcon provider="openai_codex" showBrandLogos={false} />);
|
||||
expect(container.firstElementChild).toBe(icon);
|
||||
expectFootprint(icon);
|
||||
expect(icon).toHaveClass("bg-muted");
|
||||
expect(icon.querySelector("img")).toBeNull();
|
||||
expect(icon.querySelector("svg")).not.toBeNull();
|
||||
expect(icon).not.toHaveTextContent("AI");
|
||||
|
||||
rerender(<ProviderIcon provider="openai_codex" showBrandLogos />);
|
||||
expectFootprint(icon);
|
||||
expect(icon).toHaveClass("bg-transparent");
|
||||
expect(icon.querySelector("img")).toHaveClass("opacity-100");
|
||||
});
|
||||
|
||||
it("uses the same footprint for unknown and custom providers", () => {
|
||||
const { container, rerender } = render(<ProviderIcon provider="custom" showBrandLogos />);
|
||||
expectFootprint(container.firstElementChild!);
|
||||
expect(container.querySelector("img")).toBeNull();
|
||||
expect(container.querySelector("svg")).not.toBeNull();
|
||||
|
||||
rerender(<ProviderIcon provider="my-provider" showBrandLogos />);
|
||||
expectFootprint(container.firstElementChild!);
|
||||
expect(container.querySelector("img")).toBeNull();
|
||||
expect(container.querySelector("svg")).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
import { requestMutationMock, jsonResponse, settingsPayload, renderSettingsView, installSettingsViewTestHooks } from "@/tests/settings-test-utils";
|
||||
@@ -14,6 +15,37 @@ async function chooseProviderToConfigure(label: string) {
|
||||
describe("Settings providers", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
it("keeps provider labels and keyboard configuration accessible with decorative logos", async () => {
|
||||
const user = userEvent.setup();
|
||||
const payload: SettingsPayload = {
|
||||
...settingsPayload(),
|
||||
providers: [{
|
||||
name: "openai_codex",
|
||||
label: "OpenAI Codex",
|
||||
configured: true,
|
||||
auth_type: "oauth",
|
||||
api_key_required: false,
|
||||
api_key_hint: null,
|
||||
api_base: null,
|
||||
model_catalog: "builtin",
|
||||
oauth_account: "test-account",
|
||||
oauth_login_supported: true,
|
||||
}],
|
||||
};
|
||||
renderSettingsView({ initialSection: "models", initialSettings: payload });
|
||||
|
||||
const provider = await screen.findByRole("button", { name: "OpenAI Codex", exact: true });
|
||||
expect(within(provider).getByText("Configure")).toBeInTheDocument();
|
||||
expect(within(provider).queryByRole("img")).not.toBeInTheDocument();
|
||||
provider.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(await screen.findByRole("dialog", { name: "OpenAI Codex" })).toBeInTheDocument();
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(provider).toHaveFocus();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
it("signs in to the xAI Grok provider", async () => {
|
||||
const base = settingsPayload();
|
||||
|
||||
Reference in new issue
Block a user