- Notifications
You must be signed in to change notification settings - Fork1k
feat(site): allow starting task workspace from task page#19790
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+195 −25
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
0eae944
feat(site): allow starting task workspace from task page
DanielleMaywood9104bad
chore: feedback
DanielleMaywoodf5557e5
chore: fix mistake
DanielleMaywood35402f3
chore: fix test expectation
DanielleMaywood724ef0f
chore: refactor error handling
DanielleMaywoodf402e08
chore: refactor test to use parameter queries instead of spyOn
DanielleMaywoodec8b924
chore: appease the linter
DanielleMaywoodd873c31
chore: use mutation.isPending instead
DanielleMaywoodccc54eb
chore: appease formatter
DanielleMaywood2763e1d
chore: simplify apiError assignment
DanielleMaywood221f71d
chore: always show detail
DanielleMaywoodFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -11,14 +11,20 @@ import { | ||
MockWorkspaceResource, | ||
mockApiError, | ||
} from "testHelpers/entities"; | ||
import { | ||
withGlobalSnackbar, | ||
withProxyProvider, | ||
withWebSocket, | ||
} from "testHelpers/storybook"; | ||
import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
import { API } from "api/api"; | ||
import type { | ||
Workspace, | ||
WorkspaceApp, | ||
WorkspaceResource, | ||
} from "api/typesGenerated"; | ||
import { expect, spyOn, userEvent, waitFor, within } from "storybook/test"; | ||
import { reactRouterParameters } from "storybook-addon-remix-react-router"; | ||
import TaskPage, { data, WorkspaceDoesNotHaveAITaskError } from "./TaskPage"; | ||
const meta: Meta<typeof TaskPage> = { | ||
@@ -351,3 +357,117 @@ export const ActivePreview: Story = { | ||
}); | ||
}, | ||
}; | ||
export const WorkspaceStartFailure: Story = { | ||
decorators: [withGlobalSnackbar], | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
beforeEach: () => { | ||
spyOn(API, "startWorkspace").mockRejectedValue( | ||
new Error("Some unexpected error"), | ||
); | ||
}, | ||
parameters: { | ||
reactRouter: reactRouterParameters({ | ||
location: { | ||
pathParams: { | ||
username: MockStoppedWorkspace.owner_name, | ||
workspace: MockStoppedWorkspace.name, | ||
}, | ||
}, | ||
routing: { | ||
path: "/tasks/:username/:workspace", | ||
}, | ||
}), | ||
queries: [ | ||
{ | ||
key: [ | ||
"tasks", | ||
MockStoppedWorkspace.owner_name, | ||
MockStoppedWorkspace.name, | ||
], | ||
data: { | ||
prompt: "Create competitors page", | ||
workspace: MockStoppedWorkspace, | ||
}, | ||
}, | ||
{ | ||
key: ["workspace", MockStoppedWorkspace.id, "parameters"], | ||
data: { | ||
templateVersionRichParameters: [], | ||
buildParameters: [], | ||
}, | ||
}, | ||
], | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
const startButton = await canvas.findByText("Start workspace"); | ||
expect(startButton).toBeInTheDocument(); | ||
await userEvent.click(startButton); | ||
await waitFor(async () => { | ||
const errorMessage = await canvas.findByText("Some unexpected error"); | ||
expect(errorMessage).toBeInTheDocument(); | ||
}); | ||
}, | ||
}; | ||
export const WorkspaceStartFailureWithDialog: Story = { | ||
beforeEach: () => { | ||
spyOn(API, "startWorkspace").mockRejectedValue({ | ||
...mockApiError({ | ||
message: "Bad Request", | ||
detail: "Invalid build parameters provided", | ||
}), | ||
code: "ERR_BAD_REQUEST", | ||
}); | ||
}, | ||
parameters: { | ||
reactRouter: reactRouterParameters({ | ||
location: { | ||
pathParams: { | ||
username: MockStoppedWorkspace.owner_name, | ||
workspace: MockStoppedWorkspace.name, | ||
}, | ||
}, | ||
routing: { | ||
path: "/tasks/:username/:workspace", | ||
}, | ||
}), | ||
queries: [ | ||
{ | ||
key: [ | ||
"tasks", | ||
MockStoppedWorkspace.owner_name, | ||
MockStoppedWorkspace.name, | ||
], | ||
data: { | ||
prompt: "Create competitors page", | ||
workspace: MockStoppedWorkspace, | ||
}, | ||
}, | ||
{ | ||
key: ["workspace", MockStoppedWorkspace.id, "parameters"], | ||
data: { | ||
templateVersionRichParameters: [], | ||
buildParameters: [], | ||
}, | ||
}, | ||
], | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
const startButton = await canvas.findByText("Start workspace"); | ||
expect(startButton).toBeInTheDocument(); | ||
await userEvent.click(startButton); | ||
await waitFor(async () => { | ||
const body = within(canvasElement.ownerDocument.body); | ||
const dialogTitle = await body.findByText("Error building workspace"); | ||
expect(dialogTitle).toBeInTheDocument(); | ||
}); | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { API } from "api/api"; | ||
import { getErrorDetail, getErrorMessage, isApiError } from "api/errors"; | ||
import { template as templateQueryOptions } from "api/queries/templates"; | ||
import { startWorkspace } from "api/queries/workspaces"; | ||
import type { | ||
Workspace, | ||
WorkspaceAgent, | ||
WorkspaceStatus, | ||
} from "api/typesGenerated"; | ||
import isChromatic from "chromatic/isChromatic"; | ||
import { Button } from "components/Button/Button"; | ||
import { displayError } from "components/GlobalSnackbar/utils"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import { Margins } from "components/Margins/Margins"; | ||
import { ScrollArea } from "components/ScrollArea/ScrollArea"; | ||
@@ -16,10 +18,11 @@ import { ArrowLeftIcon, RotateCcwIcon } from "lucide-react"; | ||
import { AgentLogs } from "modules/resources/AgentLogs/AgentLogs"; | ||
import { useAgentLogs } from "modules/resources/useAgentLogs"; | ||
import { AI_PROMPT_PARAMETER_NAME, type Task } from "modules/tasks/tasks"; | ||
import { WorkspaceErrorDialog } from "modules/workspaces/ErrorDialog/WorkspaceErrorDialog"; | ||
import { WorkspaceBuildLogs } from "modules/workspaces/WorkspaceBuildLogs/WorkspaceBuildLogs"; | ||
import { type FC, type ReactNode, useLayoutEffect, useRef } from "react"; | ||
import { Helmet } from "react-helmet-async"; | ||
import {useMutation,useQuery, useQueryClient } from "react-query"; | ||
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; | ||
import { Link as RouterLink, useParams } from "react-router"; | ||
import type { FixedSizeList } from "react-window"; | ||
@@ -119,27 +122,7 @@ const TaskPage = () => { | ||
</div> | ||
); | ||
} else if (task.workspace.latest_build.status !== "running") { | ||
content = <WorkspaceNotRunning task={task} />; | ||
} else if (agent && ["created", "starting"].includes(agent.lifecycle_state)) { | ||
content = <TaskStartingAgent agent={agent} />; | ||
} else { | ||
@@ -174,6 +157,73 @@ const TaskPage = () => { | ||
export default TaskPage; | ||
type WorkspaceNotRunningProps = { | ||
task: Task; | ||
}; | ||
const WorkspaceNotRunning: FC<WorkspaceNotRunningProps> = ({ task }) => { | ||
const queryClient = useQueryClient(); | ||
const { data: parameters } = useQuery({ | ||
queryKey: ["workspace", task.workspace.id, "parameters"], | ||
queryFn: () => API.getWorkspaceParameters(task.workspace), | ||
}); | ||
const mutateStartWorkspace = useMutation({ | ||
...startWorkspace(task?.workspace, queryClient), | ||
onError: (error: unknown) => { | ||
if (!isApiError(error)) { | ||
displayError(getErrorMessage(error, "Failed to build workspace.")); | ||
} | ||
}, | ||
}); | ||
const apiError = isApiError(mutateStartWorkspace.error) | ||
? mutateStartWorkspace.error | ||
: undefined; | ||
return ( | ||
<Margins> | ||
<div className="w-full min-h-80 flex items-center justify-center"> | ||
<div className="flex flex-col items-center"> | ||
<h3 className="m-0 font-medium text-content-primary text-base"> | ||
Workspace is not running | ||
</h3> | ||
<span className="text-content-secondary text-sm"> | ||
Apps and previous statuses are not available | ||
</span> | ||
<div className="flex flex-row mt-4 gap-4"> | ||
<Button | ||
size="sm" | ||
disabled={mutateStartWorkspace.isPending} | ||
onClick={() => { | ||
mutateStartWorkspace.mutate({ | ||
buildParameters: parameters?.buildParameters, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Good catch—I probably would have overlooked that. | ||
}); | ||
}} | ||
> | ||
{mutateStartWorkspace.isPending | ||
? "Starting workspace..." | ||
: "Start workspace"} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
<WorkspaceErrorDialog | ||
open={apiError !== undefined} | ||
error={apiError} | ||
onClose={mutateStartWorkspace.reset} | ||
showDetail={true} | ||
workspaceOwner={task.workspace.owner_name} | ||
workspaceName={task.workspace.name} | ||
templateVersionId={task.workspace.latest_build.template_version_id} | ||
isDeleting={false} | ||
/> | ||
</Margins> | ||
); | ||
}; | ||
type TaskBuildingWorkspaceProps = { task: Task }; | ||
const TaskBuildingWorkspace: FC<TaskBuildingWorkspaceProps> = ({ task }) => { | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.