From 596d189cc7fa080a6ec798c500d9b89f3a164aaa Mon Sep 17 00:00:00 2001 From: Francis Li Date: Thu, 23 Jan 2025 17:33:54 -0800 Subject: [PATCH] Fix BenchmarkAssignmentModal, add comments on next steps --- src/backend/routers/iep.ts | 3 +++ .../benchmarks/BenchmarkAssignmentModal.tsx | 22 +++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/backend/routers/iep.ts b/src/backend/routers/iep.ts index e28f9e59..2d82bc8f 100644 --- a/src/backend/routers/iep.ts +++ b/src/backend/routers/iep.ts @@ -237,6 +237,9 @@ export const iep = router({ .mutation(async (req) => { const { benchmark_id, para_ids } = req.input; + // TODO: instead of throwing an error if a task already exists, + // just add/remove existing tasks as needed. + const existingTasks = await req.ctx.db .selectFrom("task") .where("benchmark_id", "=", benchmark_id) diff --git a/src/components/benchmarks/BenchmarkAssignmentModal.tsx b/src/components/benchmarks/BenchmarkAssignmentModal.tsx index 56e4b37c..ddfd3a83 100644 --- a/src/components/benchmarks/BenchmarkAssignmentModal.tsx +++ b/src/components/benchmarks/BenchmarkAssignmentModal.tsx @@ -57,6 +57,7 @@ export const BenchmarkAssignmentModal = ( const [errorMessage, setErrorMessage] = useState(""); const assignTaskToPara = trpc.iep.assignTaskToParas.useMutation(); + const updateBenchmark = trpc.iep.updateBenchmark.useMutation(); const handleParaToggle = (paraId: string) => () => { setErrorMessage(""); @@ -95,18 +96,21 @@ export const BenchmarkAssignmentModal = ( } else { // Reached end, save try { + // maybe invoke these two in parallel? await assignTaskToPara.mutateAsync({ benchmark_id: props.benchmark_id, para_ids: selectedParaIds, - // this should be written to benchmarks: - // due_date: - // assignmentDuration.type === "until_date" - // ? assignmentDuration.date - // : undefined, - // trial_count: - // assignmentDuration.type === "minimum_number_of_collections" - // ? assignmentDuration.minimumNumberOfCollections - // : undefined, + }); + await updateBenchmark.mutateAsync({ + benchmark_id: props.benchmark_id, + due_date: + assignmentDuration.type === "until_date" + ? assignmentDuration.date + : undefined, + trial_count: + assignmentDuration.type === "minimum_number_of_collections" + ? assignmentDuration.minimumNumberOfCollections + : undefined, }); handleClose(); } catch (err) {