Skip to content

fix: hide app icon if not found #16684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion site/src/modules/resources/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
const preferredPathBase = proxy.preferredPathAppURL;
const appsHost = proxy.preferredWildcardHostname;
const [fetchingSessionToken, setFetchingSessionToken] = useState(false);
const [iconError, setIconError] = useState(false);

const theme = useTheme();
const username = workspace.owner_name;
Expand Down Expand Up @@ -67,7 +68,9 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
// To avoid bugs in the healthcheck code locking users out of apps, we no
// longer block access to apps if they are unhealthy/initializing.
let canClick = true;
let icon = <BaseIcon app={app} />;
let icon = !iconError && (
<BaseIcon app={app} onIconPathError={() => setIconError(true)} />
);

let primaryTooltip = "";
if (app.health === "initializing") {
Expand Down
9 changes: 8 additions & 1 deletion site/src/modules/resources/AppLink/BaseIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import type { FC } from "react";

interface BaseIconProps {
app: WorkspaceApp;
onIconPathError?: () => void;
}

export const BaseIcon: FC<BaseIconProps> = ({ app }) => {
export const BaseIcon: FC<BaseIconProps> = ({ app, onIconPathError }) => {
return app.icon ? (
<img
alt={`${app.display_name} Icon`}
src={app.icon}
style={{ pointerEvents: "none" }}
onError={() => {
console.warn(
`Application icon for "${app.id}" has invalid source "${app.icon}".`,
);
onIconPathError?.();
}}
/>
) : (
<ComputerIcon />
Expand Down
37 changes: 37 additions & 0 deletions site/src/pages/WorkspacePage/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,43 @@ export const Running: Story = {
},
};

export const AppIcons: Story = {
args: {
...Running.args,
workspace: {
...Mocks.MockWorkspace,
latest_build: {
...Mocks.MockWorkspace.latest_build,
resources: [
{
...Mocks.MockWorkspaceResource,
agents: [
{
...Mocks.MockWorkspaceAgent,
apps: [
{
...Mocks.MockWorkspaceApp,
id: "test-app-1",
slug: "test-app-1",
display_name: "Default Icon",
},
{
...Mocks.MockWorkspaceApp,
id: "test-app-2",
slug: "test-app-2",
display_name: "Broken Icon",
icon: "/foobar/broken.png",
},
],
},
],
},
],
},
},
},
};

export const Favorite: Story = {
args: {
...Running.args,
Expand Down
Loading