Skip to content

Commit

Permalink
WIP: Have paras updated in modal, still need to update BenchmarkAssig…
Browse files Browse the repository at this point in the history
…nees displayed after paras updated
  • Loading branch information
canjalal committed Feb 5, 2025
1 parent 8ac4c6b commit 0204132
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/backend/routers/iep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ test("basic flow - add/get goals, benchmarks, tasks", async (t) => {
const gotBenchmark = await trpc.iep.getBenchmark.query({
benchmark_id: benchmark2Id,
});
t.is(gotBenchmark[0].description, "benchmark 2");
t.deepEqual(gotBenchmark[0].due_date, new Date("2023-12-31"));
t.is(gotBenchmark[0].trial_count, 5);
t.is(gotBenchmark.description, "benchmark 2");
t.deepEqual(gotBenchmark.due_date, new Date("2023-12-31"));
t.is(gotBenchmark.trial_count, 5);

// TODO: Don't query db directly and use an API method instead. Possibly create a getTasks method later
t.truthy(
Expand Down
31 changes: 29 additions & 2 deletions src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,35 @@ export const iep = router({
const result = await req.ctx.db
.selectFrom("benchmark")
.where("benchmark.benchmark_id", "=", benchmark_id)
.selectAll()
.execute();
.select((eb) => [
"benchmark.benchmark_id",
"benchmark.status",
"benchmark.description",
"benchmark.instructions",
"benchmark.materials",
"benchmark.metric_name",
"benchmark.setup",
"benchmark.frequency",
"benchmark.number_of_trials",
"benchmark.attempts_per_trial",
"benchmark.trial_count",
"benchmark.baseline_level",
"benchmark.current_level",
"benchmark.target_level",
"benchmark.created_at",
"benchmark.due_date",
"benchmark.goal_id",
jsonArrayFrom(
eb
.selectFrom("user")
.innerJoin("task", "task.assignee_id", "user.user_id")
.whereRef("task.benchmark_id", "=", "benchmark.benchmark_id")
.orderBy("user.first_name")
.selectAll()
).as("assignees"),
])
.executeTakeFirstOrThrow();

return result;
}),

Expand Down
4 changes: 2 additions & 2 deletions src/components/benchmarks/BenchmarkAssignees.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Box, Button, Stack } from "@mui/material";
import { BenchmarkWithAssignees } from "@/types/global";
import { format } from "date-fns";

import $button from "@/components/design_system/button/Button.module.css";
import { Benchmark } from "@/types/global";

const BenchmarkAssignees = ({
benchmark,
onAssign,
}: {
benchmark: BenchmarkWithAssignees;
benchmark: Benchmark;
onAssign: () => void;
}) => {
const { assignees, due_date, trial_count } = benchmark;
Expand Down
34 changes: 22 additions & 12 deletions src/components/benchmarks/BenchmarkAssignmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DialogContent,
DialogActions,
} from "@mui/material";
import { useState, useRef } from "react";
import { useState, useRef, useEffect } from "react";
import $benchmark from "./BenchmarkAssignmentModal.module.css";
import $button from "@/components/design_system/button/Button.module.css";

Expand Down Expand Up @@ -50,9 +50,19 @@ export const BenchmarkAssignmentModal = (
const [currentModalSelection, setCurrentModalSelection] =
useState<Step>("PARA_SELECTION");
const { data: myParas } = trpc.case_manager.getMyParas.useQuery();
const { data: benchmark } = trpc.iep.getBenchmark.useQuery({
benchmark_id: props.benchmark_id,
});
const { data: benchmark, isError: benchmarkFetchError } =
trpc.iep.getBenchmark.useQuery({
benchmark_id: props.benchmark_id,
});

useEffect(() => {
const paraIds =
benchmark?.assignees
.map(({ assignee_id }) => assignee_id)
.filter((ele) => ele !== null) ?? [];

setSelectedParaIds(paraIds);
}, [benchmark]);

const [errorMessage, setErrorMessage] = useState<string>("");

Expand Down Expand Up @@ -125,6 +135,11 @@ export const BenchmarkAssignmentModal = (
}
};

// does this matter to prevent error typed values?
if (benchmarkFetchError) {
return <div>Oops! Error fetching benchmark</div>;
}

return (
<Dialog
open={props.isOpen}
Expand All @@ -140,14 +155,9 @@ export const BenchmarkAssignmentModal = (
<DialogContent>
<Box className={$benchmark.benchmarkDescriptionBox}>
<p className={$benchmark.benchmarkTitle}>Benchmark</p>
{benchmark?.map((thisBenchmark) => (
<p
className={$benchmark.benchmarkDescription}
key="thisBenchmark.description"
>
{thisBenchmark.description}
</p>
))}
<p className={$benchmark.benchmarkDescription}>
{benchmark?.description}
</p>
</Box>
{currentModalSelection === "PARA_SELECTION" && (
<Box>
Expand Down
13 changes: 9 additions & 4 deletions src/components/benchmarks/BenchmarkListElement.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BenchmarkWithAssignees } from "@/types/global";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Divider from "@mui/material/Divider";
Expand All @@ -10,9 +9,10 @@ import Typography from "@mui/material/Typography";

import { BenchmarkAssignmentModal } from "./BenchmarkAssignmentModal";
import BenchmarkAssignees from "./BenchmarkAssignees";
import { Benchmark } from "@/types/global";

interface BenchmarkProps {
benchmark: BenchmarkWithAssignees;
benchmark: Benchmark;
index?: number;
}

Expand Down Expand Up @@ -47,6 +47,11 @@ const Info = ({ description, children }: InfoProps) => {

const BenchmarkListElement = ({ benchmark, index }: BenchmarkProps) => {
const [isAssignmentModalOpen, setIsAssignmentModalOpen] = useState(false);

const closeModal = () => {
setIsAssignmentModalOpen(false);
};

return (
<Box
sx={{
Expand All @@ -67,7 +72,7 @@ const BenchmarkListElement = ({ benchmark, index }: BenchmarkProps) => {
display="block"
gutterBottom
>
#{(index ?? 0) + 1} created on {format(benchmark.created_at, "P")}
#{(index ?? 0) + 1} created on {format(benchmark?.created_at, "P")}
</Typography>
<Box sx={{ display: "flex", justifyContent: "space-between" }}>
<Box sx={{ display: "flex" }}>
Expand Down Expand Up @@ -170,7 +175,7 @@ const BenchmarkListElement = ({ benchmark, index }: BenchmarkProps) => {
</Box>
<BenchmarkAssignmentModal
isOpen={isAssignmentModalOpen}
onClose={() => setIsAssignmentModalOpen(false)}
onClose={closeModal}
benchmark_id={benchmark.benchmark_id}
/>
</Box>
Expand Down
7 changes: 2 additions & 5 deletions src/types/global.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { RouterOutputs } from "@/client/lib/trpc";
import { SelectableForTable } from "zapatos/schema";

export type Goal = SelectableForTable<"goal">;
export type Benchmark = SelectableForTable<"benchmark">;
export type Benchmark = RouterOutputs["iep"]["getBenchmark"];
export type User = SelectableForTable<"user">;
export type ChangeEvent = React.ChangeEvent<HTMLInputElement>;
export type FormEvent = React.FormEvent<HTMLFormElement>;

export type SortProperty = "first_name" | "created_at";
export type SortDirection = "asc" | "desc";

export interface BenchmarkWithAssignees extends Benchmark {
assignees: User[];
}

export interface TaskData {
task_id: string;
first_name: string;
Expand Down

0 comments on commit 0204132

Please sign in to comment.