-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add duration assigment step and create task on save (#243)
- Loading branch information
1 parent
c1ce851
commit 9734180
Showing
11 changed files
with
453 additions
and
144 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { | ||
FormControl, | ||
InputLabel, | ||
Select, | ||
MenuItem, | ||
SelectChangeEvent, | ||
Input, | ||
} from "@mui/material"; | ||
import { StaticDatePicker } from "@mui/x-date-pickers"; | ||
|
||
export type AssignmentDuration = | ||
| { | ||
type: "forever"; | ||
} | ||
| { | ||
type: "minimum_number_of_collections"; | ||
minimumNumberOfCollections: number; | ||
} | ||
| { | ||
type: "until_date"; | ||
date: Date; | ||
}; | ||
|
||
interface DurationSelectionStepProps { | ||
disabled?: boolean; | ||
selectedDuration: AssignmentDuration; | ||
onDurationChange: (duration: AssignmentDuration) => void; | ||
} | ||
|
||
export const DurationSelectionStep = ({ | ||
disabled, | ||
selectedDuration, | ||
onDurationChange, | ||
}: DurationSelectionStepProps) => { | ||
const handleTypeChange = ( | ||
event: SelectChangeEvent<AssignmentDuration["type"]> | ||
) => { | ||
switch (event.target.value) { | ||
case "forever": | ||
onDurationChange({ type: "forever" }); | ||
break; | ||
case "minimum_number_of_collections": | ||
onDurationChange({ | ||
type: "minimum_number_of_collections", | ||
minimumNumberOfCollections: 1, | ||
}); | ||
break; | ||
case "until_date": | ||
onDurationChange({ type: "until_date", date: new Date() }); | ||
break; | ||
default: | ||
throw new Error("Invalid AssignmentDuration type"); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<FormControl fullWidth sx={{ my: 3 }} disabled={disabled}> | ||
<InputLabel id="para-assignment-ends-at">Ends at</InputLabel> | ||
<Select | ||
labelId="para-assignment-ends-at" | ||
label="Ends at" | ||
value={selectedDuration.type} | ||
onChange={handleTypeChange} | ||
> | ||
<MenuItem value={"forever"}> | ||
Never: The para will collected data until unassigned | ||
</MenuItem> | ||
<MenuItem value={"minimum_number_of_collections"}> | ||
Until a number of instances have been recorded | ||
</MenuItem> | ||
<MenuItem value={"until_date"}> | ||
Until a target date has been reached | ||
</MenuItem> | ||
</Select> | ||
</FormControl> | ||
|
||
{selectedDuration.type === "minimum_number_of_collections" && ( | ||
<FormControl fullWidth disabled={disabled}> | ||
<InputLabel id="para-assignment-minimum-number-of-collections"> | ||
How many times should [staff] collect data on this benchmark? | ||
</InputLabel> | ||
<Input | ||
type="number" | ||
value={selectedDuration.minimumNumberOfCollections} | ||
onChange={(e) => | ||
onDurationChange({ | ||
type: "minimum_number_of_collections", | ||
minimumNumberOfCollections: parseInt(e.target.value), | ||
}) | ||
} | ||
/> | ||
</FormControl> | ||
)} | ||
|
||
{selectedDuration.type === "until_date" && ( | ||
<> | ||
<InputLabel> | ||
Until what date should [staff] collect data on this benchmark? | ||
</InputLabel> | ||
<StaticDatePicker | ||
defaultValue={selectedDuration.date} | ||
onChange={(e) => | ||
e | ||
? onDurationChange({ | ||
type: "until_date", | ||
date: e, | ||
}) | ||
: undefined | ||
} | ||
slots={{ actionBar: () => null }} | ||
disabled={disabled} | ||
/> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.