-
Notifications
You must be signed in to change notification settings - Fork 0
feat: preview assessment from teacher dashboard #605
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
base: joyce/preview
Are you sure you want to change the base?
Changes from all commits
549fe52
527b98d
e73b729
b1eb58d
fef2852
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| import React from "react"; | ||
| import { useHistory } from "react-router-dom"; | ||
| import { useLazyQuery } from "@apollo/client"; | ||
| import { Radio, RadioGroup, Text } from "@chakra-ui/react"; | ||
|
|
||
| import { GET_TEST } from "../../../APIClients/queries/TestQueries"; | ||
| import type { TestResponse } from "../../../APIClients/types/TestClientTypes"; | ||
| import type { Grade } from "../../../APIClients/types/UserClientTypes"; | ||
| import { EyeOutlineIcon } from "../../../assets/icons"; | ||
| import * as Routes from "../../../constants/Routes"; | ||
| import type { UseCase } from "../../../types/AssessmentTypes"; | ||
| import { removeUnderscore, titleCase } from "../../../utils/GeneralUtils"; | ||
| import ActionButton from "../../common/form/ActionButton"; | ||
| import useToast from "../../common/info/useToast"; | ||
| import type { TableRow } from "../../common/table/Table"; | ||
| import { Table } from "../../common/table/Table"; | ||
|
|
||
|
|
@@ -31,6 +39,33 @@ const AssessmentsTable = ({ | |
| setTestName, | ||
| isDisabled = false, | ||
| }: AssessmentsTableProps): React.ReactElement => { | ||
| const history = useHistory(); | ||
| const { showToast } = useToast(); | ||
|
|
||
| const [previewAssessmentQuery] = useLazyQuery<{ | ||
| test: TestResponse; | ||
| }>(GET_TEST); | ||
|
|
||
| const previewAssessment = async (assessmentId: string) => { | ||
| const { data } = await previewAssessmentQuery({ | ||
|
Contributor
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: instead of checking for nullish data, we should catch exceptions here, since awaited Apollo lazy queries throw any error instead of returning it |
||
| variables: { id: assessmentId }, | ||
| }); | ||
| if (data) { | ||
| history.push({ | ||
| pathname: Routes.TEACHER_ASSESSMENT_PREVIEW_PAGE({ | ||
| assessmentId, | ||
| }), | ||
| state: data.test, | ||
| }); | ||
| } else { | ||
| showToast({ | ||
| message: | ||
| "This assessment cannot be previewed at this time. Please try again.", | ||
| status: "error", | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| const headers = ["", "Name", "Grade", "Type", "Country", "Region"]; | ||
| const rows: TableRow[] = assessments.map((assessment, i) => ({ | ||
| id: assessment.id, | ||
|
|
@@ -49,6 +84,15 @@ const AssessmentsTable = ({ | |
| assessment.curriculumCountry, | ||
| assessment.curriculumRegion, | ||
| ], | ||
| menu: ( | ||
| <ActionButton | ||
| aria-label="preview-assessment" | ||
| leftIcon={<EyeOutlineIcon boxSize={5} />} | ||
| onClick={() => previewAssessment(assessment.id)} | ||
| showDefaultToasts={false} | ||
| size="sm" | ||
| /> | ||
| ), | ||
| onClick: () => { | ||
| setTestId(assessment.id); | ||
| if (setTestName) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| import React, { type ReactElement } from "react"; | ||
| import { useHistory } from "react-router-dom"; | ||
| import { useMutation } from "@apollo/client"; | ||
| import { useLazyQuery, useMutation } from "@apollo/client"; | ||
| import { Divider, useDisclosure, VStack } from "@chakra-ui/react"; | ||
|
|
||
| import { DELETE_TEST_SESSION } from "../../../APIClients/mutations/TestSessionMutations"; | ||
| import { GET_TEST } from "../../../APIClients/queries/TestQueries"; | ||
| import { GET_TEST_SESSIONS_BY_TEACHER_ID } from "../../../APIClients/queries/TestSessionQueries"; | ||
| import type { TestResponse } from "../../../APIClients/types/TestClientTypes"; | ||
| import * as Routes from "../../../constants/Routes"; | ||
| import { TestSessionStatus } from "../../../types/TestSessionTypes"; | ||
| import { getQueryName } from "../../../utils/GeneralUtils"; | ||
| import DeleteAssessmentModal from "../../admin/assessment-status/EditStatusModals/DeleteAssessmentModal"; | ||
| import useToast from "../../common/info/useToast"; | ||
| import Popover from "../../common/popover/Popover"; | ||
| import PopoverButton from "../../common/popover/PopoverButton"; | ||
|
|
||
|
|
@@ -26,8 +29,8 @@ const TestSessionListItemPopover = ({ | |
| onOpen: openDeleteModal, | ||
| onClose: onDeleteModalClose, | ||
| } = useDisclosure(); | ||
|
|
||
| const history = useHistory(); | ||
| const { showToast } = useToast(); | ||
|
|
||
| const [deleteTestSession] = useMutation(DELETE_TEST_SESSION, { | ||
| variables: { id: session.testSessionId }, | ||
|
|
@@ -38,12 +41,40 @@ const TestSessionListItemPopover = ({ | |
| history.push(Routes.DISTRIBUTE_ASSESSMENT_PAGE, session); | ||
| }; | ||
|
|
||
| const [previewTest] = useLazyQuery<{ | ||
| test: TestResponse; | ||
| }>(GET_TEST); | ||
|
|
||
| const onPreviewTest = async () => { | ||
| const { data } = await previewTest({ | ||
|
Contributor
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. Same comment! |
||
| variables: { id: session.testId }, | ||
| }); | ||
| if (data) { | ||
| history.push({ | ||
| pathname: Routes.TEACHER_ASSESSMENT_PREVIEW_PAGE({ | ||
| assessmentId: session.testId, | ||
| }), | ||
| state: data.test, | ||
| }); | ||
| } else { | ||
| showToast({ | ||
| message: | ||
| "This assessment cannot be previewed at this time. Please try again.", | ||
| status: "error", | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Popover> | ||
| <VStack divider={<Divider />} spacing={0}> | ||
| <PopoverButton name="Edit" onClick={onEditTestSession} /> | ||
| {session.status !== TestSessionStatus.PAST && ( | ||
| <PopoverButton name="Delete" onClick={openDeleteModal} /> | ||
| <> | ||
| <PopoverButton name="Delete" onClick={openDeleteModal} /> | ||
| <Divider /> | ||
|
Contributor
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. Do we need the extra divider here? I think |
||
| <PopoverButton name="Preview" onClick={onPreviewTest} /> | ||
| </> | ||
| )} | ||
| </VStack> | ||
| <DeleteAssessmentModal | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.