Skip to content

Commit

Permalink
Convert getWebsiteIconUrl util to use Brandfetch api (#5712)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilluminate authored Feb 3, 2025
1 parent c4d69cc commit 50f44b8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions clients/admin-ui/cypress/e2e/action-center.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ describe("Action center", () => {
const monitorKey = result
.attr("data-testid")
.replace("monitor-result-", "");
// property icon
cy.wrap(result).find(".ant-list-item-meta-avatar").should("exist");
// linked title
cy.wrap(result)
.contains("assets detected")
Expand Down
16 changes: 16 additions & 0 deletions clients/admin-ui/src/features/common/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getKeysFromMap,
getOptionsFromMap,
getPII,
getWebsiteIconUrl,
} from "~/features/common/utils";

// TODO: add tests for the other utils functions
Expand Down Expand Up @@ -84,3 +85,18 @@ describe(getOptionsFromMap.name, () => {
expect(result).toEqual([]);
});
});

describe(getWebsiteIconUrl.name, () => {
it("should return the icon URL", () => {
const result = getWebsiteIconUrl("example.com");
expect(result).toEqual(
"https://cdn.brandfetch.io/example.com/icon/theme/light/fallback/404/h/24/w/24?c=1idbRjELpikqQ1PLiqb",
);
});
it("should return the icon URL with a custom size", () => {
const result = getWebsiteIconUrl("example.com", 56);
expect(result).toEqual(
"https://cdn.brandfetch.io/example.com/icon/theme/light/fallback/404/h/56/w/56?c=1idbRjELpikqQ1PLiqb",
);
});
});
4 changes: 2 additions & 2 deletions clients/admin-ui/src/features/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ export const getOptionsFromMap = <T = string>(
value: key,
}));

export const getWebsiteIconUrl = (hostname: string) => {
return `https://icons.duckduckgo.com/ip3/${hostname}.ico`;
export const getWebsiteIconUrl = (domain: string, size = 24) => {
return `https://cdn.brandfetch.io/${domain}/icon/theme/light/fallback/404/h/${size}/w/${size}?c=1idbRjELpikqQ1PLiqb`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,23 @@ export const MonitorResult = ({
<List.Item data-testid={`monitor-result-${key}`} {...props}>
<Skeleton avatar title={false} loading={showSkeleton} active>
<List.Item.Meta
avatar={!!iconUrl && <Avatar src={iconUrl} size="small" />}
avatar={
<Avatar
src={iconUrl}
size="small"
icon={<Icons.Wikis />}
style={{
backgroundColor: "transparent",
color: "var(--ant-color-text)",
}}
/>
}
title={
<NextLink
href={`${ACTION_CENTER_ROUTE}/${key}`}
className="whitespace-nowrap"
>
{`${totalUpdates} assets detected${property ? `on ${property}` : ""}`}
{`${totalUpdates} assets detected${property ? ` on ${property}` : ""}`}
{!!warning && (
<Tooltip
title={typeof warning === "string" ? warning : undefined}
Expand Down

0 comments on commit 50f44b8

Please sign in to comment.