- Notifications
You must be signed in to change notification settings - Fork1k
fix: force task to be created with latest version#19923
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -189,11 +189,12 @@ const CreateTaskForm: FC<CreateTaskFormProps> = ({ templates, onSuccess }) => { | ||
const createTaskMutation = useMutation({ | ||
mutationFn: async ({ prompt }: CreateTaskMutationFnProps) => | ||
createTaskWithLatestTemplateVersion( | ||
prompt, | ||
user.id, | ||
selectedTemplate.id, | ||
selectedPresetId, | ||
), | ||
onSuccess: async (task) => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: ["tasks"], | ||
@@ -432,3 +433,21 @@ function sortByDefault(a: Preset, b: Preset) { | ||
// Otherwise, sort alphabetically by name | ||
return a.Name.localeCompare(b.Name); | ||
} | ||
// TODO: Enforce task creation to always use the latest active template version. | ||
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. nit: this is rather FIXME than TODO :P 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. Is 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. Yeah, we have a lot of fixmes in our codebase :) PS. nit-pick! | ||
// During task creation, the active version might change between template load | ||
// and user action. Since handling this in the FE cannot guarantee correctness, | ||
// we should move the logic to the BE after the experimental phase. | ||
async function createTaskWithLatestTemplateVersion( | ||
prompt: string, | ||
userId: string, | ||
templateId: string, | ||
presetId: string | undefined, | ||
): Promise<Task> { | ||
const template = await API.getTemplate(templateId); | ||
return API.experimental.createTask(userId, { | ||
prompt, | ||
template_version_id: template.active_version_id, | ||
template_version_preset_id: presetId, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -244,7 +244,12 @@ export const CreateTaskSuccessfully: Story = { | ||
}), | ||
}, | ||
beforeEach: () => { | ||
const activeVersionId = `${MockTemplate.active_version_id}-latest`; | ||
spyOn(API, "getTemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(API, "getTemplate").mockResolvedValue({ | ||
...MockTemplate, | ||
active_version_id: activeVersionId, | ||
}); | ||
spyOn(API.experimental, "getTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
@@ -261,6 +266,17 @@ export const CreateTaskSuccessfully: Story = { | ||
await userEvent.click(submitButton); | ||
}); | ||
await step("Uses latest template version", () => { | ||
expect(API.experimental.createTask).toHaveBeenCalledWith( | ||
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. Correct me if I'm wrong, but since this is a story not a unit test, you shouldn't assert API calls on that level? Can we convert it to jest test instead? 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. We’re using Storybook as our main testing tool. At some point, Jest will only be used for testing functions or other non-component-related code. Kayla did an awesome L&L yesterday about the FE state—I’m just trying to grab the link to share here. 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. Ok, TIL! | ||
MockUserOwner.id, | ||
{ | ||
prompt: MockNewTaskData.prompt, | ||
template_version_id: `${MockTemplate.active_version_id}-latest`, | ||
template_version_preset_id: undefined, | ||
}, | ||
); | ||
}); | ||
await step("Redirects to the task page", async () => { | ||
await canvas.findByText(/task page/i); | ||
}); | ||
Uh oh!
There was an error while loading.Please reload this page.