Skip to content

fix(site): fix render crash when no embedded apps are defined for task #19215

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 1 commit into from
Aug 7, 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
134 changes: 134 additions & 0 deletions site/src/pages/TaskPage/TaskApps.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import type { Meta, StoryObj } from "@storybook/react";
import type { WorkspaceApp } from "api/typesGenerated";
import {
MockTasks,
MockWorkspace,
MockWorkspaceAgent,
MockWorkspaceApp,
} from "testHelpers/entities";
import { withProxyProvider } from "testHelpers/storybook";
import { TaskApps } from "./TaskApps";

const meta: Meta<typeof TaskApps> = {
title: "pages/TaskPage/TaskApps",
component: TaskApps,
decorators: [withProxyProvider()],
parameters: {
layout: "fullscreen",
},
};

export default meta;
type Story = StoryObj<typeof TaskApps>;

const mockAgentNoApps = {
...MockWorkspaceAgent,
apps: [],
};

const mockExternalApp: WorkspaceApp = {
...MockWorkspaceApp,
external: true,
};

const mockEmbeddedApp: WorkspaceApp = {
...MockWorkspaceApp,
external: false,
};

const taskWithNoApps = {
...MockTasks[0],
workspace: {
...MockWorkspace,
latest_build: {
...MockWorkspace.latest_build,
resources: [
{
...MockWorkspace.latest_build.resources[0],
agents: [mockAgentNoApps],
},
],
},
},
};

export const NoEmbeddedApps: Story = {
args: {
task: taskWithNoApps,
},
};

export const WithExternalAppsOnly: Story = {
args: {
task: {
...MockTasks[0],
workspace: {
...MockWorkspace,
latest_build: {
...MockWorkspace.latest_build,
resources: [
{
...MockWorkspace.latest_build.resources[0],
agents: [
{
...MockWorkspaceAgent,
apps: [mockExternalApp],
},
],
},
],
},
},
},
},
};

export const WithEmbeddedApps: Story = {
args: {
task: {
...MockTasks[0],
workspace: {
...MockWorkspace,
latest_build: {
...MockWorkspace.latest_build,
resources: [
{
...MockWorkspace.latest_build.resources[0],
agents: [
{
...MockWorkspaceAgent,
apps: [mockEmbeddedApp],
},
],
},
],
},
},
},
},
};

export const WithMixedApps: Story = {
args: {
task: {
...MockTasks[0],
workspace: {
...MockWorkspace,
latest_build: {
...MockWorkspace.latest_build,
resources: [
{
...MockWorkspace.latest_build.resources[0],
agents: [
{
...MockWorkspaceAgent,
apps: [mockEmbeddedApp, mockExternalApp],
},
],
},
],
},
},
},
},
};
158 changes: 96 additions & 62 deletions site/src/pages/TaskPage/TaskApps.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WorkspaceApp } from "api/typesGenerated";
import type { WorkspaceAgent, WorkspaceApp } from "api/typesGenerated";
import { Button } from "components/Button/Button";
import {
DropdownMenu,
Expand All @@ -8,13 +8,15 @@ import {
} from "components/DropdownMenu/DropdownMenu";
import { ExternalImage } from "components/ExternalImage/ExternalImage";
import { InfoTooltip } from "components/InfoTooltip/InfoTooltip";
import { Link } from "components/Link/Link";
import { ChevronDownIcon, LayoutGridIcon } from "lucide-react";
import { useAppLink } from "modules/apps/useAppLink";
import type { Task } from "modules/tasks/tasks";
import type React from "react";
import { type FC, useState } from "react";
import { Link as RouterLink } from "react-router-dom";
import { cn } from "utils/cn";
import { docs } from "utils/docs";
import { TaskAppIFrame } from "./TaskAppIframe";

type TaskAppsProps = {
Expand All @@ -37,25 +39,9 @@ export const TaskApps: FC<TaskAppsProps> = ({ task }) => {
const embeddedApps = apps.filter((app) => !app.external);
const externalApps = apps.filter((app) => app.external);

const [activeAppId, setActiveAppId] = useState<string>(() => {
const appId = embeddedApps[0]?.id;
if (!appId) {
throw new Error("No apps found in task");
}
return appId;
});

const activeApp = apps.find((app) => app.id === activeAppId);
if (!activeApp) {
throw new Error(`Active app with ID ${activeAppId} not found in task`);
}

const agent = agents.find((a) =>
a.apps.some((app) => app.id === activeAppId),
const [activeAppId, setActiveAppId] = useState<string | undefined>(
embeddedApps[0]?.id,
);
if (!agent) {
throw new Error(`Agent for app ${activeAppId} not found in task workspace`);
}

return (
<main className="flex flex-col">
Expand All @@ -76,56 +62,104 @@ export const TaskApps: FC<TaskAppsProps> = ({ task }) => {
</div>

{externalApps.length > 0 && (
<div className="ml-auto">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button size="sm" variant="subtle">
Open locally
<ChevronDownIcon />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
{externalApps.map((app) => {
const link = useAppLink(app, {
agent,
workspace: task.workspace,
});

return (
<DropdownMenuItem key={app.id} asChild>
<RouterLink to={link.href}>
{app.icon ? (
<ExternalImage src={app.icon} />
) : (
<LayoutGridIcon />
)}
{link.label}
</RouterLink>
</DropdownMenuItem>
);
})}
</DropdownMenuContent>
</DropdownMenu>
</div>
<TaskExternalAppsDropdown
task={task}
agents={agents}
externalApps={externalApps}
/>
)}
</div>

<div className="flex-1">
{embeddedApps.map((app) => {
return (
<TaskAppIFrame
key={app.id}
active={activeAppId === app.id}
app={app}
task={task}
/>
);
})}
</div>
{embeddedApps.length > 0 ? (
<div className="flex-1">
{embeddedApps.map((app) => {
return (
<TaskAppIFrame
key={app.id}
active={activeAppId === app.id}
app={app}
task={task}
/>
);
})}
</div>
) : (
<div className="mx-auto my-auto flex flex-col items-center">
<h3 className="font-medium text-content-primary text-base">
No embedded apps found.
</h3>

<span className="text-content-secondary text-sm">
<Link
href={docs("/ai-coder/tasks")}
target="_blank"
rel="noreferrer"
>
Learn how to configure apps
</Link>{" "}
for your tasks.
</span>
</div>
)}
</main>
);
};

type TaskExternalAppsDropdownProps = {
task: Task;
agents: WorkspaceAgent[];
externalApps: WorkspaceApp[];
};

const TaskExternalAppsDropdown: FC<TaskExternalAppsDropdownProps> = ({
task,
agents,
externalApps,
}) => {
return (
<div className="ml-auto">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button size="sm" variant="subtle">
Open locally
<ChevronDownIcon />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
{externalApps.map((app) => {
const agent = agents.find((agent) =>
agent.apps.some((a) => a.id === app.id),
);
if (!agent) {
throw new Error(
`Agent for app ${app.id} not found in task workspace`,
);
}

const link = useAppLink(app, {
agent,
workspace: task.workspace,
});

return (
<DropdownMenuItem key={app.id} asChild>
<RouterLink to={link.href}>
{app.icon ? (
<ExternalImage src={app.icon} />
) : (
<LayoutGridIcon />
)}
{link.label}
</RouterLink>
</DropdownMenuItem>
);
})}
</DropdownMenuContent>
</DropdownMenu>
</div>
);
};

type TaskAppTabProps = {
task: Task;
app: WorkspaceApp;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy