8000 feat: add task page by BrunoQuaresma · Pull Request #18076 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: add task page #18076

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
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 26 additions & 2 deletions site/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @see {@link https://ui.shadcn.com/docs/components/table}
*/

import { type VariantProps, cva } from "class-variance-authority";
import * as React from "react";
import { cn } from "utils/cn";

Expand Down Expand Up @@ -60,15 +61,38 @@ const TableFooter = React.forwardRef<
/>
));

const tableRowVariants = cva(
[
"border-0 border-b border-solid border-border transition-colors",
"data-[state=selected]:bg-muted",
],
{
variants: {
hover: {
false: null,
true: cn([
"cursor-pointer hover:outline focus:outline outline-1 -outline-offset-1 outline-border-hover",
"first:rounded-t-md last:rounded-b-md",
]),
},
},
defaultVariants: {
hover: false,
},
},
);

export const TableRow = React.forwardRef<
HTMLTableRowElement,
React.HTMLAttributes<HTMLTableRowElement>
>(({ className, ...props }, ref) => (
React.HTMLAttributes<HTMLTableRowElement> &
VariantProps<typeof tableRowVariants>
>(({ className, hover, ...props }, ref) => (
<tr
ref={ref}
className={cn(
"border-0 border-b border-solid border-border transition-colors",
"data-[state=selected]:bg-muted",
tableRowVariants({ hover }),
className,
)}
{...props}
Expand Down
47 changes: 47 additions & 0 deletions site/src/modules/apps/AppStatusIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { WorkspaceAppStatus } from "api/typesGenerated";
import { Spinner } from "components/Spinner/Spinner";
import {
CircleAlertIcon,
CircleCheckIcon,
HourglassIcon,
TriangleAlertIcon,
} from "lucide-react";
import type { FC } from "react";
import { cn } from "utils/cn";

type AppStatusIconProps = {
status: WorkspaceAppStatus;
latest: boolean;
className?: string;
};

export const AppStatusIcon: FC<AppStatusIconProps> = ({
status,
latest,
className: customClassName,
}) => {
const className = cn(["size-4 shrink-0", customClassName]);

switch (status.state) {
case "complete":
return (
<CircleCheckIcon className={cn([className, "text-content-success"])} />
);
case "failure":
return (
<CircleAlertIcon className={cn([className, "text-content-warning"])} />
);
case "working":
return latest ? (
<Spinner size="sm" className="shrink-0" loading />
) : (
<HourglassIcon className={cn([className, "text-highlight-sky"])} />
);
default:
return (
<TriangleAlertIcon
className={cn([className, "text-content-secondary"])}
/>
);
}
};
8 changes: 8 additions & 0 deletions site/src/modules/tasks/tasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Workspace } from "api/typesGenerated";

export const AI_PROMPT_PARAMETER_NAME = "AI Prompt";

export type Task = {
workspace: Workspace;
prompt: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const WorkspaceAppStatus = ({
}

return (
<div className="flex flex-col">
<div className="flex flex-col text-content-secondary">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
Expand All @@ -48,7 +48,9 @@ export const WorkspaceAppStatus = ({
<TooltipContent>{status.message}</TooltipContent>
</Tooltip>
</TooltipProvider>
<s 8000 pan className="first-letter:uppercase block pl-6">{status.state}</span>
<span className="text-xs first-letter:uppercase block pl-6">
{status.state}
</span>
</div>
);
};
150 changes: 150 additions & 0 deletions site/src/pages/TaskPage/TaskPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import type { Meta, StoryObj } from "@storybook/react";
import { spyOn } from "@storybook/test";
import {
MockFailedWorkspace,
MockStartingWorkspace,
MockStoppedWorkspace,
MockWorkspace,
MockWorkspaceAgent,
MockWorkspaceApp,
MockWorkspaceAppStatus,
MockWorkspaceResource,
mockApiError,
} from "testHelpers/entities";
import { withProxyProvider } from "testHelpers/storybook";
import TaskPage, { data } from "./TaskPage";

const meta: Meta<typeof TaskPage> = {
title: "pages/TaskPage",
component: TaskPage,
parameters: {
layout: "fullscreen",
},
};

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

export const Loading: Story = {
beforeEach: () => {
spyOn(data, "fetchTask").mockImplementation(
() => new Promise((res) => 1000 * 60 * 60),
);
},
};

export const LoadingError: Story = {
beforeEach: () => {
spyOn(data, "fetchTask").mockRejectedValue(
mockApiError({
message: "Failed to load task",
detail: "You don't have permission to access this resource.",
}),
);
},
};

export const WaitingOnBuild: Story = {
beforeEach: () => {
spyOn(data, "fetchTask").mockResolvedValue({
prompt: "Create competitors page",
workspace: MockStartingWorkspace,
});
},
};

export const WaitingOnStatus: Story = {
beforeEach: () => {
spyOn(data, "fetchTask").mockResolvedValue({
prompt: "Create competitors page",
workspace: {
...MockWorkspace,
latest_app_status: null,
},
});
},
};

export const FailedBuild: Story = {
beforeEach: () => {
spyOn(data, "fetchTask").mockResolvedValue({
prompt: "Create competitors page",
workspace: MockFailedWorkspace,
});
},
};

export const TerminatedBuild: Story = {
beforeEach: () => {
spyOn(data, "fetchTask").mockResolvedValue({
prompt: "Create competitors page",
workspace: MockStoppedWorkspace,
});
},
};

export const TerminatedBuildWithStatus: Story = {
beforeEach: () => {
spyOn(data, "fetchTask").mockResolvedValue({
prompt: "Create competitors page",
workspace: {
...MockStoppedWorkspace,
latest_app_status: MockWorkspaceAppStatus,
},
});
},
};

export const Active: Story = {
decorators: [withProxyProvider()],
beforeEach: () => {
spyOn(data, "fetchTask").mockResolvedValue({
prompt: "Create competitors page",
workspace: {
...MockWorkspace,
latest_build: {
...MockWorkspace.latest_build,
resources: [
{
...MockWorkspaceResource,
agents: [
{
...MockWorkspaceAgent,
apps: [
{
...MockWorkspaceApp,
id: "cloud-code",
display_name: "Cloud Code",
icon: "https://uxwing.com/wp-content/themes/uxwing/download/brands-and-social-media/claude-ai-icon.png",
Copy link
Contributor
@hugodutka hugodutka May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't use externally hosted images.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this for many other storybook tests 😄 it has not been a problem so far

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using /icons/claude.svg

url: `${window.location.protocol}/iframe.html?viewMode=story&id=pages-terminal--ready&args=&globals=`,
external: true,
statuses: [
MockWorkspaceAppStatus,
{
...MockWorkspaceAppStatus,
id: "2",
message: "Planning changes",
state: "working",
},
],
},
{
...MockWorkspaceApp,
id: "vscode",
display_name: "VSCode",
icon: "/icon/code.svg",
},
],
},
],
},
],
},
latest_app_status: {
...MockWorkspaceAppStatus,
app_id: "cloud-code",
},
},
});
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: cloud-code -> claude-code

Loading
Loading
0