Skip to content

Commit 83be638

Browse files
committed
Enhance SourceFavicon component to support optional sourceUrl prop and improve favicon retrieval logic. Update ToolExplorer styles for better layout management based on sidebar visibility.
1 parent 5b2137c commit 83be638

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

executor/apps/web/src/components/tools/add/source/dialog-sections.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChevronRight, Plus } from "lucide-react";
2-
import Image from "next/image";
32
import { Streamdown } from "streamdown";
43
import type { ReactNode } from "react";
54
import { Button } from "@/components/ui/button";
@@ -20,6 +19,7 @@ import {
2019
type SourceCatalogSort,
2120
type SourceType,
2221
} from "./dialog-helpers";
22+
import { SourceFavicon } from "../../source-favicon";
2323

2424
export function CatalogViewSection({
2525
catalogQuery,
@@ -86,15 +86,18 @@ export function CatalogViewSection({
8686
key={item.id}
8787
className="w-full max-w-full overflow-hidden flex items-start gap-2 px-2 py-2 rounded-md border border-border/50"
8888
>
89-
{item.logoUrl && (
90-
<Image
89+
{item.logoUrl ? (
90+
<img
9191
src={item.logoUrl}
9292
alt=""
93-
width={20}
94-
height={20}
9593
className="w-5 h-5 rounded shrink-0 mt-0.5 object-contain"
96-
loading="lazy"
97-
unoptimized
94+
/>
95+
) : (
96+
<SourceFavicon
97+
sourceUrl={item.originUrl || item.specUrl}
98+
fallbackType={item.sourceType ?? "openapi"}
99+
iconClassName="h-5 w-5 text-muted-foreground"
100+
imageClassName="w-5 h-5 rounded object-contain"
98101
/>
99102
)}
100103
<div className="flex-1 min-w-0 w-0 overflow-hidden">

executor/apps/web/src/components/tools/explorer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export function ToolExplorer({
380380
<div
381381
className={cn(
382382
"flex-1 min-w-0 flex flex-col",
383-
"pl-0",
383+
showSourceSidebar ? "pl-2 lg:pl-3" : "pl-0",
384384
)}
385385
>
386386
<ToolExplorerToolbar

executor/apps/web/src/components/tools/source-favicon.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { useEffect, useState } from "react";
44
import { Layers, Globe, Server } from "lucide-react";
55
import Image from "next/image";
66
import type { ToolSourceRecord } from "@/lib/types";
7-
import { getSourceFavicon } from "@/lib/tools/source-helpers";
7+
import { getSourceFavicon, getSourceFaviconUrl } from "@/lib/tools/source-helpers";
88

99
interface SourceFaviconProps {
10-
source: ToolSourceRecord;
10+
source?: ToolSourceRecord;
11+
sourceUrl?: string;
1112
iconClassName?: string;
1213
imageClassName?: string;
1314
imageSize?: number;
@@ -26,20 +27,26 @@ function DefaultSourceIcon({ type, className }: { type: ToolSourceRecord["type"]
2627

2728
export function SourceFavicon({
2829
source,
30+
sourceUrl,
2931
iconClassName = "h-4 w-4 text-muted-foreground",
3032
imageClassName,
3133
imageSize = 20,
3234
fallbackType,
3335
}: SourceFaviconProps) {
34-
const sourceFavicon = getSourceFavicon(source);
36+
const sourceFavicon = sourceUrl
37+
? getSourceFaviconUrl(sourceUrl)
38+
: source
39+
? getSourceFavicon(source)
40+
: null;
3541
const [failed, setFailed] = useState(false);
3642

3743
useEffect(() => {
3844
setFailed(false);
3945
}, [sourceFavicon]);
4046

4147
if (!sourceFavicon || failed) {
42-
return <DefaultSourceIcon type={fallbackType ?? source.type} className={iconClassName} />;
48+
const sourceType = fallbackType ?? source?.type ?? "openapi";
49+
return <DefaultSourceIcon type={sourceType} className={iconClassName} />;
4350
}
4451

4552
return (

executor/apps/web/src/lib/tools/source-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const RAW_HOSTS = new Set([
1616
"raw.github.com",
1717
]);
1818

19-
function faviconForUrl(url: string | undefined | null): string | null {
19+
export function getSourceFaviconUrl(url: string | undefined | null): string | null {
2020
if (!url) return null;
2121
try {
2222
const hostname = new URL(url).hostname;
@@ -62,7 +62,7 @@ function sourceFaviconSourceUrl(source: ToolSourceRecord): string | null {
6262

6363
export function getSourceFavicon(source: ToolSourceRecord): string | null {
6464
const sourceUrl = sourceFaviconSourceUrl(source);
65-
return sourceUrl ? faviconForUrl(sourceUrl) : null;
65+
return sourceUrl ? getSourceFaviconUrl(sourceUrl) : null;
6666
}
6767

6868
export function sourceEndpointLabel(source: ToolSourceRecord): string {

0 commit comments

Comments
 (0)