feat(webui): unify the Apps catalog (#6700)

* feat(webui): unify the Apps catalog

* fix(webui): serve all channel branding locally

* fix(webui): refine Apps navigation and sidebar
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-18 15:05:57 +08:00
1 parent 5997a714f2
commit 2b232c9133
89 files changed
+1576 -1024

No files matched your search

@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from "react";
import { useEffect, useId, useRef, useState } from "react";
import { Download, Loader2, RotateCcw } from "lucide-react";
import { useTranslation } from "react-i18next";
@@ -16,6 +16,8 @@ import { Button } from "@/components/ui/button";
import type { NanobotFeatureInfo } from "@/lib/types";
import { cn } from "@/lib/utils";
const CHANNEL_ACTION_CLASS = "relative h-7 w-[38px] min-w-0 shrink-0 rounded-full border-border/70 bg-background p-0 after:absolute after:left-1/2 after:top-1/2 after:h-11 after:w-11 after:-translate-x-1/2 after:-translate-y-1/2 after:content-['']";
export function ChannelCatalogRow({
feature,
showBrandLogos,
@@ -28,7 +30,7 @@ export function ChannelCatalogRow({
}: {
feature: NanobotFeatureInfo;
showBrandLogos: boolean;
onSelect: (connect?: boolean) => void;
onSelect: (trigger: HTMLButtonElement | null, connect?: boolean) => void;
actionKey: string | null;
restartRequired?: boolean;
onAction: ChannelFeatureAction;
@@ -47,6 +49,9 @@ export function ChannelCatalogRow({
const actionsDisabled = restartRequired || isRestarting;
const showInstallRestartHint = feature.install_supported && actionsDisabled;
const installButtonRef = useRef<HTMLButtonElement | null>(null);
const toggleRef = useRef<HTMLButtonElement | null>(null);
const statusId = useId();
const failed = feature.runtime_status === "failed";
const [installHint, setInstallHint] = useState(false);
useEffect(() => {
@@ -55,17 +60,18 @@ export function ChannelCatalogRow({
return () => window.clearTimeout(timeout);
}, [installHint]);
const pointToInstall = () => {
setInstallHint(true);
installButtonRef.current?.focus();
};
const channelIdentity = (
<>
<ChannelLogo feature={feature} showBrandLogos={showBrandLogos} />
<div className="min-w-0 flex-1">
<h3 className="truncate text-[14px] font-semibold leading-5 text-foreground">
<h3 className="text-[14px] font-semibold leading-5 text-foreground [overflow-wrap:anywhere]">
{displayName}
</h3>
{failed ? (
<div id={statusId} className="mt-0.5">
<ChannelStatusBadge status="failed">{channelStatusLabel(feature, tx)}</ChannelStatusBadge>
</div>
) : null}
</div>
</>
);
@@ -86,22 +92,23 @@ export function ChannelCatalogRow({
name: displayName,
defaultValue: "View {{name}} settings",
})}
aria-haspopup="dialog"
aria-haspopup={feature.installed ? "dialog" : undefined}
aria-describedby={failed ? statusId : undefined}
disabled={actionsDisabled}
onClick={() => feature.installed ? onSelect() : pointToInstall()}
onClick={(event) => {
if (feature.installed) {
onSelect(event.currentTarget);
} else {
setInstallHint(true);
if (event.detail === 0) installButtonRef.current?.focus({ preventScroll: true });
}
}}
className="group flex min-w-0 flex-1 select-none items-center gap-3 rounded-control text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border/80"
>
{channelIdentity}
</button>
)}
{feature.runtime_status === "failed" ? (
<div className="min-w-0 shrink truncate">
<ChannelStatusBadge status={feature.runtime_status}>
{channelStatusLabel(feature, tx)}
</ChannelStatusBadge>
</div>
) : null}
<div className="flex w-16 shrink-0 items-center justify-center">
<div className="flex w-11 shrink-0 items-center justify-center">
{!feature.installed ? (
<HoverHint enabled={showInstallRestartHint}
content={t(isRestarting ? "app.system.restarting" : "settings.channels.restartBeforeInstall")}>
@@ -111,7 +118,7 @@ export function ChannelCatalogRow({
className="inline-flex rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2">
<Button ref={installButtonRef} type="button" variant="outline" size="icon"
className={cn(
"h-[22px] w-[38px] min-w-0 shrink-0 rounded-full border-border/70 bg-background p-0",
CHANNEL_ACTION_CLASS,
installHint && "border-[#2997FF]/60 bg-[#2997FF]/10 text-[#087FE7] ring-2 ring-[#2997FF]/25 ring-offset-2",
)}
disabled={actionsDisabled || anyActionBusy || !feature.install_supported}
@@ -130,7 +137,7 @@ export function ChannelCatalogRow({
) : feature.restart_pending ? (
<HoverHint content={t("settings.channels.restartRequired")}>
<Button type="button" variant="outline" size="icon"
className="h-[22px] w-[38px] min-w-0 shrink-0 rounded-full border-border/70 bg-background p-0"
className={CHANNEL_ACTION_CLASS}
aria-label={t("app.system.restart")}
aria-busy={isRestarting}
disabled={isRestarting || anyActionBusy || !onRestart}
@@ -141,12 +148,12 @@ export function ChannelCatalogRow({
</Button>
</HoverHint>
) : (
<ToggleButton checked={checked}
<ToggleButton ref={toggleRef} checked={checked}
label={checked ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
disabled={alwaysEnabled || actionsDisabled || anyActionBusy}
ariaLabel={t("settings.channels.toggleChannel", { name: displayName, defaultValue: "{{name}} channel" })}
onChange={(enabled) => {
if (enabled && feature.configured === false) onSelect(true);
if (enabled && feature.configured === false) onSelect(toggleRef.current, true);
else onAction(enabled ? "enable" : "disable", feature.name);
}} />
)}
@@ -1,5 +1,5 @@
import i18n from "i18next";
import { useMemo, type ReactNode } from "react";
import type { ReactNode } from "react";
import { useTranslation } from "react-i18next";
import {
@@ -19,7 +19,6 @@ import type {
import { channelValidationMessage } from "@/components/settings/channels/validationMessages";
import { useLogoFallback } from "@/hooks/useLogoFallback";
import { normalizeLocale } from "@/i18n/config";
import { logoFallbackUrls } from "@/lib/provider-brand";
import type { ChannelRuntimeStatus, NanobotFeatureInfo } from "@/lib/types";
import { cn } from "@/lib/utils";
@@ -154,23 +153,17 @@ export function ChannelLogo({
?? channelUiPresentation(feature.name);
const initials = presentation?.initials ?? feature.display_name.slice(0, 2).toUpperCase();
const Icon = presentation?.icon;
const logoUrls = useMemo(() => {
const fallbackUrls = logoFallbackUrls(presentation?.logoFallbackUrl ?? presentation?.logoUrl);
return presentation?.logoUrl && presentation.logoFallbackUrl
? [...new Set([presentation.logoUrl, ...fallbackUrls])]
: fallbackUrls;
}, [presentation?.logoUrl, presentation?.logoFallbackUrl]);
const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(logoUrls);
const showRemoteLogo = showBrandLogos && Boolean(logoUrl);
const showLoadedLogo = showRemoteLogo && logoLoaded;
const isLogoTile = presentation?.logoLayout === "tile" && logoUrl === presentation.logoUrl;
const brandLogoUrl = presentation?.logoUrl;
const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(brandLogoUrl ? [brandLogoUrl] : undefined);
const showLogo = showBrandLogos && Boolean(logoUrl);
const showLoadedLogo = showLogo && logoLoaded;
return (
<span
data-testid={`channel-logo-${feature.name}`}
className={cn(
"relative grid h-8 w-8 shrink-0 place-items-center overflow-hidden rounded-[9px] text-[11px] font-semibold text-muted-foreground",
showLoadedLogo ? (isLogoTile ? "bg-transparent" : "bg-white") : "bg-muted",
showLoadedLogo ? "bg-white" : "bg-muted",
)}
aria-hidden
>
@@ -180,7 +173,7 @@ export function ChannelLogo({
)}>
{Icon ? <Icon className="h-6 w-6" strokeWidth={2} /> : initials}
</span>
{showRemoteLogo ? <img
{showLogo ? <img
src={logoUrl}
alt=""
decoding="async"
@@ -188,8 +181,7 @@ export function ChannelLogo({
referrerPolicy="no-referrer"
draggable={false}
className={cn(
"absolute object-contain transition-opacity duration-150 motion-reduce:transition-none",
isLogoTile ? "h-8 w-8" : "h-6 w-6",
"absolute h-6 w-6 object-contain transition-opacity duration-150 motion-reduce:transition-none",
logoLoaded ? "opacity-100" : "opacity-0",
)}
onLoad={onLogoLoad}
@@ -23,7 +23,6 @@ import {
} from "@/components/settings/channels/ChannelIdentity";
import { Button } from "@/components/ui/button";
import { useLogoFallback } from "@/hooks/useLogoFallback";
import { logoFallbackUrls } from "@/lib/provider-brand";
import type {
NanobotChannelInstanceInfo,
NanobotFeatureInfo,
@@ -344,8 +343,8 @@ function ChannelInstanceAvatar({
}) {
const presentation = channelUiPresentation(feature.name, feature.webui);
const [avatarFailed, setAvatarFailed] = useState(false);
const fallbackLogoUrls = useMemo(() => logoFallbackUrls(presentation?.logoUrl), [presentation?.logoUrl]);
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(fallbackLogoUrls);
const brandLogoUrl = presentation?.logoUrl;
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(brandLogoUrl ? [brandLogoUrl] : undefined);
const remoteAvatarUrl = !avatarFailed ? instance.avatar_url?.trim() : "";
const imageUrl = remoteAvatarUrl || (showBrandLogos ? logoUrl : "");
const Icon = presentation?.icon;