-
Notifications
You must be signed in to change notification settings - Fork 14
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate benchmark assignment modal from trpc #489
Draft
nickvisut
wants to merge
11
commits into
main
Choose a base branch
from
separate-benchmark-assignment-modal-from-trpc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
526bc66
Pull out ParaSelectionStep from BenchmarkAssignmentModal
canjalal 18ea301
Rename BenchmarkAssignmentModal to BenchmarkAssignment
canjalal 3ac8514
Make new BenchmarkAssignmentModal component that is only for UI
canjalal 4f45f88
Merge branch 'main' into separate-benchmark-assignment-modal-from-trpc
canjalal 31c9d14
WIP get benchmark assignees
nickvisut f4327f5
WIP clean up a bit
nickvisut ca43a3d
WIP again
nickvisut 8223eb7
WIP got rid of error in iep.ts
nickvisut e507b87
WIP: try removing map in BenchmarkAssignmentModal
canjalal 90665c3
WIP fix getBenchmark query
nickvisut 00c7a87
fix gotBenchmark test
nickvisut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -94,7 +94,7 @@ 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.is(gotBenchmark.description, "benchmark 2"); | ||
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. 👏 |
||
|
||
// TODO: Don't query db directly and use an API method instead. Possibly create a getTasks method later | ||
t.truthy( | ||
|
This file contains 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
This file contains 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,4 +1,12 @@ | ||
import { createTRPCReact } from "@trpc/react-query"; | ||
import { | ||
createTRPCReact, | ||
type inferReactQueryProcedureOptions, | ||
} from "@trpc/react-query"; | ||
import type { inferRouterInputs, inferRouterOutputs } from "@trpc/server"; | ||
import { AppRouter } from "@/backend/routers/_app"; | ||
|
||
export type ReactQueryOptions = inferReactQueryProcedureOptions<AppRouter>; | ||
export type RouterInputs = inferRouterInputs<AppRouter>; | ||
export type RouterOutputs = inferRouterOutputs<AppRouter>; | ||
|
||
export const trpc = createTRPCReact<AppRouter>(); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { trpc } from "@/client/lib/trpc"; | ||
import { useState, useRef } from "react"; | ||
|
||
import { AssignmentDuration } from "./Duration-Selection-Step"; | ||
import { BenchmarkAssignmentModal } from "@/components/benchmarks/BenchmarkAssignmentModal"; | ||
|
||
interface BenchmarkAssignmentProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
benchmark_id: string; | ||
} | ||
|
||
export const STEPS = ["PARA_SELECTION", "DURATION_SELECTION"]; | ||
export type Step = (typeof STEPS)[number]; | ||
|
||
export const BenchmarkAssignment = (props: BenchmarkAssignmentProps) => { | ||
const [selectedParaIds, setSelectedParaIds] = useState<string[]>([]); | ||
const nextButtonRef = useRef<HTMLButtonElement>(null); | ||
const [assignmentDuration, setAssignmentDuration] = | ||
useState<AssignmentDuration>({ type: "forever" }); | ||
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, | ||
}); // maybe it should include assignments, or have a flag to include assignments | ||
|
||
const [errorMessage, setErrorMessage] = useState<string>(""); | ||
|
||
const assignTaskToPara = trpc.iep.assignTaskToParas.useMutation(); | ||
|
||
const handleParaToggle = (paraId: string) => () => { | ||
setErrorMessage(""); | ||
setSelectedParaIds((prev) => { | ||
if (prev.includes(paraId)) { | ||
return prev.filter((id) => id !== paraId); | ||
} else { | ||
return [...prev, paraId]; | ||
} | ||
}); | ||
}; | ||
|
||
const handleClose = () => { | ||
props.onClose(); | ||
setSelectedParaIds([]); | ||
setErrorMessage(""); | ||
setCurrentModalSelection("PARA_SELECTION"); | ||
}; | ||
|
||
const handleBack = () => { | ||
const currentStepIndex = STEPS.indexOf(currentModalSelection); | ||
const previousStep = STEPS[currentStepIndex - 1]; | ||
if (previousStep) { | ||
setCurrentModalSelection(previousStep); | ||
} | ||
}; | ||
|
||
const handleNext = async () => { | ||
if (nextButtonRef.current) { | ||
nextButtonRef.current.blur(); | ||
} | ||
const currentStepIndex = STEPS.indexOf(currentModalSelection); | ||
const nextStep = STEPS[currentStepIndex + 1]; | ||
if (nextStep) { | ||
setCurrentModalSelection(nextStep); | ||
} else { | ||
// Reached end, save | ||
try { | ||
await assignTaskToPara.mutateAsync({ | ||
benchmark_id: props.benchmark_id, | ||
para_ids: selectedParaIds, | ||
due_date: | ||
assignmentDuration.type === "until_date" | ||
? assignmentDuration.date | ||
: undefined, | ||
trial_count: | ||
assignmentDuration.type === "minimum_number_of_collections" | ||
? assignmentDuration.minimumNumberOfCollections | ||
: undefined, | ||
}); | ||
handleClose(); | ||
} catch (err) { | ||
// TODO: issue #450 | ||
console.log(err); | ||
if (err instanceof Error) { | ||
setErrorMessage(err.message); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<BenchmarkAssignmentModal | ||
isOpen={props.isOpen} | ||
handleClose={handleClose} | ||
benchmark={benchmark} | ||
myParas={myParas} | ||
currentModalSelection={currentModalSelection} | ||
errorMessage={errorMessage} | ||
selectedParaIds={selectedParaIds} | ||
handleParaToggle={handleParaToggle} | ||
assignmentDuration={assignmentDuration} | ||
setAssignmentDuration={setAssignmentDuration} | ||
isAssignTaskToParaLoading={assignTaskToPara.isLoading} | ||
handleBack={handleBack} | ||
handleNext={handleNext} | ||
nextButtonRef={nextButtonRef} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to add this script!