Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: redirect to the task page after creation#18626

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
BrunoQuaresma merged 5 commits intomainfrombq/go-to-task-page
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
45 changes: 26 additions & 19 deletionssite/src/pages/TasksPage/TasksPage.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import { expect, spyOn, userEvent, waitFor, within } from "@storybook/test";
import { API } from "api/api";
import { MockUsers } from "pages/UsersPage/storybookData/users";
import { reactRouterParameters } from "storybook-addon-remix-react-router";
import {
MockTemplate,
MockTemplateVersionExternalAuthGithub,
Expand DownExpand Up@@ -132,6 +133,23 @@ const newTaskData = {

export const CreateTaskSuccessfully: Story = {
decorators: [withProxyProvider()],
parameters: {
reactRouter: reactRouterParameters({
location: {
path: "/tasks",
},
routing: [
{
path: "/tasks",
useStoryElement: true,
},
{
path: "/tasks/:ownerName/:workspaceName",
element: <h1>Task page</h1>,
},
],
}),
},
beforeEach: () => {
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]);
spyOn(data, "fetchTasks")
Expand All@@ -150,10 +168,8 @@ export const CreateTaskSuccessfully: Story = {
await userEvent.click(submitButton);
});

await step("Verify task in the table", async () => {
await canvas.findByRole("row", {
name: new RegExp(newTaskData.prompt, "i"),
});
await step("Redirects to the task page", async () => {
await canvas.findByText(/task page/i);
});
},
};
Expand DownExpand Up@@ -187,7 +203,7 @@ export const CreateTaskError: Story = {
},
};

export constWithExternalAuth: Story = {
export constWithAuthenticatedExternalAuth: Story = {
decorators: [withProxyProvider()],
beforeEach: () => {
spyOn(data, "fetchTasks")
Expand All@@ -201,26 +217,17 @@ export const WithExternalAuth: Story = {
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);

await step("Run task", async () => {
const prompt = await canvas.findByLabelText(/prompt/i);
await userEvent.type(prompt, newTaskData.prompt);
const submitButton = canvas.getByRole("button", { name: /run task/i });
await waitFor(() => expect(submitButton).toBeEnabled());
await userEvent.click(submitButton);
});

await step("Verify task in the table", async () => {
await canvas.findByRole("row", {
name: new RegExp(newTaskData.prompt, "i"),
});
});

await step("Does not render external auth", async () => {
expect(
canvas.queryByText(/external authentication/),
).not.toBeInTheDocument();
});
},
parameters: {
chromatic: {
disableSnapshot: true,
},
},
};

export const MissingExternalAuth: Story = {
Expand Down
19 changes: 14 additions & 5 deletionssite/src/pages/TasksPage/TasksPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,7 +52,7 @@ import { generateWorkspaceName } from "modules/workspaces/generateWorkspaceName"
import { type FC, type ReactNode, useState } from "react";
import { Helmet } from "react-helmet-async";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { Link as RouterLink } from "react-router-dom";
import { Link as RouterLink, useNavigate } from "react-router-dom";
import TextareaAutosize from "react-textarea-autosize";
import { pageTitle } from "utils/page";
import { relativeTime } from "utils/time";
Expand DownExpand Up@@ -163,6 +163,7 @@ const TaskFormSection: FC<{
filter: TasksFilter;
onFilterChange: (filter: TasksFilter) => void;
}> = ({ showFilter, filter, onFilterChange }) => {
const navigate = useNavigate();
const {
data: templates,
error,
Expand DownExpand Up@@ -190,7 +191,14 @@ const TaskFormSection: FC<{
}
return (
<>
<TaskForm templates={templates} />
<TaskForm
templates={templates}
onSuccess={(task) => {
navigate(
`/tasks/${task.workspace.owner_name}/${task.workspace.name}`,
);
}}
/>
{showFilter && (
<TasksFilter filter={filter} onFilterChange={onFilterChange} />
)}
Expand All@@ -202,9 +210,10 @@ type CreateTaskMutationFnProps = { prompt: string; templateId: string };

type TaskFormProps = {
templates: Template[];
onSuccess: (task: Task) => void;
};

const TaskForm: FC<TaskFormProps> = ({ templates }) => {
const TaskForm: FC<TaskFormProps> = ({ templates, onSuccess }) => {
const { user } = useAuthenticated();
const queryClient = useQueryClient();
const [selectedTemplateId, setSelectedTemplateId] = useState<string>(
Expand All@@ -229,10 +238,11 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => {
const createTaskMutation = useMutation({
mutationFn: async ({ prompt, templateId }: CreateTaskMutationFnProps) =>
data.createTask(prompt, user.id, templateId),
onSuccess: async () => {
onSuccess: async (task) => {
await queryClient.invalidateQueries({
queryKey: ["tasks"],
});
onSuccess(task);
},
});

Expand All@@ -249,7 +259,6 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => {
prompt,
templateId: templateID,
});
form.reset();
} catch (error) {
const message = getErrorMessage(error, "Error creating task");
const detail = getErrorDetail(error) ?? "Please try again";
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp