Skip to content
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

fix: fix question link #171

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,112 +14,119 @@ import type { SearchListProps } from "@cf/react/components";

export type LearningObjectiveListProps = Omit<
SearchListProps<LearningObjectiveSearchResult>,
| "renderThead"
| "renderTableRow"
| "renderListItemContent"
| "errorMessage"
| "noDataMessage"
"renderThead" | "renderTableRow" | "renderListItemContent"
> & {
currentCourse?: string;
};

export const LearningObjectiveList = forwardRef<
HTMLDivElement,
LearningObjectiveListProps
>(({ items, currentCourse = "all", ...otherProps }, ref) => {
return (
<SearchList
{...otherProps}
ref={ref}
items={items}
errorMessage={"Error fetching Learning Objectives"}
noDataMessage={"No Learning Objectives found"}
renderThead={() => (
<thead>
<tr>
<th style={{ width: "8em" }}>LO</th>
<th>Description</th>
<th style={{ width: "14em" }}>Source</th>
<th style={{ width: "14em" }}>Courses</th>
<th style={{ width: "7em" }}>Questions</th>
>(
(
{
items,
currentCourse = "all",
errorMessage = "Error fetching Learning Objectives",
noDataMessage = "No Learning Objectives found",
...otherProps
},
ref,
) => {
return (
<SearchList
{...otherProps}
ref={ref}
items={items}
errorMessage={errorMessage}
noDataMessage={noDataMessage}
renderThead={() => (
<thead>
<tr>
<th style={{ width: "8em" }}>LO</th>
<th>Description</th>
<th style={{ width: "14em" }}>Source</th>
<th style={{ width: "14em" }}>Courses</th>
<th style={{ width: "7em" }}>Questions</th>
</tr>
</thead>
)}
renderTableRow={(result) => (
<tr key={result.id}>
<td>
<Link href={result.href}>
<Typography>{result.id}</Typography>
</Link>
</td>
<Markdown component={"td"} compressed>
{result.text}
</Markdown>
<Markdown component={"td"} compressed>
{result.source}
</Markdown>
<td>
{result.courses
.filter((c) => {
if (currentCourse === "all") return true;
if (c.id === currentCourse) return true;
return false;
})
.map((c) => (
<Chip key={c.id} size="sm" sx={{ m: 0.5 }}>
{c.text}
</Chip>
))}
</td>
<Box
component={"td"}
children={result.numberOfQuestions}
sx={{
textAlign: "right",
pr: `2em !important`,
}}
/>
</tr>
</thead>
)}
renderTableRow={(result) => (
<tr key={result.id}>
<td>
<Link href={result.href}>
)}
renderListItemContent={(result) => (
<ListItemContent>
<Link href={`/modules/atpl/learning-objectives/${result.id}`}>
<Typography>{result.id}</Typography>
</Link>
</td>
<Markdown component={"td"} compressed>
{result.text}
</Markdown>
<Markdown component={"td"} compressed>
{result.source}
</Markdown>
<td>
{result.courses
.filter((c) => {
if (currentCourse === "all") return true;
if (c.id === currentCourse) return true;
return false;
})
.map((c) => (
<Chip key={c.id} size="sm" sx={{ m: 0.5 }}>
{c.text}
</Chip>
))}
</td>
<Box
component={"td"}
children={result.numberOfQuestions}
sx={{
textAlign: "right",
pr: `2em !important`,
}}
/>
</tr>
)}
renderListItemContent={(result) => (
<ListItemContent>
<Link href={`/modules/atpl/learning-objectives/${result.id}`}>
<Typography>{result.id}</Typography>
</Link>
<Typography level="body-xs" sx={{ fontSize: 10 }}>
{result.courses.map((c) => c.text).join(", ")}
</Typography>
<Typography level="body-xs" sx={{ fontSize: 10 }}>
Number of Questions {result.numberOfQuestions}
</Typography>
<Box
sx={{
mt: 1,
fontSize: "sm",
height: "7em",
overflow: "hidden",
maskImage:
"linear-gradient(to bottom, black 50%, transparent 100%)",
}}
>
<Markdown compressed>{result.text}</Markdown>
{result.source && (
<>
<Divider sx={{ width: "50%", my: 0.5 }} />
<Typography level="body-xs">source: </Typography>
<Markdown
compressed
sx={{ color: "text.tertiary", fontSize: "xs" }}
>
{result.source}
</Markdown>
</>
)}
</Box>
</ListItemContent>
)}
/>
);
});
<Typography level="body-xs" sx={{ fontSize: 10 }}>
{result.courses.map((c) => c.text).join(", ")}
</Typography>
<Typography level="body-xs" sx={{ fontSize: 10 }}>
Number of Questions {result.numberOfQuestions}
</Typography>
<Box
sx={{
mt: 1,
fontSize: "sm",
height: "7em",
overflow: "hidden",
maskImage:
"linear-gradient(to bottom, black 50%, transparent 100%)",
}}
>
<Markdown compressed>{result.text}</Markdown>
{result.source && (
<>
<Divider sx={{ width: "50%", my: 0.5 }} />
<Typography level="body-xs">source: </Typography>
<Markdown
compressed
sx={{ color: "text.tertiary", fontSize: "xs" }}
>
{result.source}
</Markdown>
</>
)}
</Box>
</ListItemContent>
)}
/>
);
},
);

LearningObjectiveList.displayName = "LearningObjectiveList";
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ import type { SearchListProps } from "@cf/react/components";

export type QuestionListProps = Omit<
SearchListProps<QuestionSearchResult>,
| "renderThead"
| "renderTableRow"
| "renderListItemContent"
| "errorMessage"
| "noDataMessage"
"renderThead" | "renderTableRow" | "renderListItemContent"
>;

export const QuestionList = forwardRef<HTMLDivElement, QuestionListProps>(
({ items, ...otherProps }, ref) => {
(
{
items,
errorMessage = "Error fetching questions",
noDataMessage = "No questions found",
...otherProps
},
ref,
) => {
return (
<SearchList
{...otherProps}
ref={ref}
items={items}
errorMessage={"Error fetching questions"}
noDataMessage={"No questions found"}
errorMessage={errorMessage}
noDataMessage={noDataMessage}
renderThead={() => (
<thead>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ export const QuestionMetaComponent: FunctionComponent<
<Typography level="h3" sx={{ mt: 2 }}>
Learning Objectives
</Typography>
<LearningObjectiveList items={learningObjectives.items} />
<LearningObjectiveList
items={learningObjectives.items}
noDataMessage="No connected Learning Objectives"
/>
<Typography level="h3" sx={{ mt: 2 }}>
Related Questions
</Typography>
<QuestionList items={relatedQuestions.items} />
<QuestionList
items={relatedQuestions.items}
noDataMessage="No related questions"
/>
<Typography level="h3" sx={{ mt: 2 }}>
External References
</Typography>
Expand Down
7 changes: 6 additions & 1 deletion libs/next/tests/src/containers/test-study/test-study.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from "react";
import { useRouter } from "next/router";
import { default as AccessAlarmsOutlinedIcon } from "@mui/icons-material/AccessAlarmsOutlined";
import { default as AppsOutlinedIcon } from "@mui/icons-material/AppsOutlined";
import { default as ChevronLeftIcon } from "@mui/icons-material/ChevronLeft";
Expand Down Expand Up @@ -43,6 +44,7 @@ import { TestLoading } from "../../components/test-loading";
import { useTestProgress } from "../../hooks/use-test-progress";
import { useTestHotkeys } from "../../hooks/use-test-progress-hotkeys";
import { useTestProgressTime } from "../../hooks/use-test-progress-time";
import type { QuestionBankName } from "@cf/core/question-bank";
import type { DrawingPoints } from "@cf/react/components";

type DrawingPointsMap = Record<string, DrawingPoints[]>;
Expand All @@ -67,6 +69,7 @@ export const TestStudy = container<Props>(
useTestProgressTime({ testId });

const theme = useTheme();
const router = useRouter();
const test = useTestProgress((state) => state.tests[testId]);
const goToQuestion = useTestProgress((s) => s.goToTestQuestion);
const goToPreviousQuestion = useTestProgress((s) => s.goToPreviousQuestion);
Expand All @@ -86,6 +89,8 @@ export const TestStudy = container<Props>(
const status = test.mode === "exam" ? "in-progress" : "both";
const currentQuestion = test.currentQuestionIndex + 1;
const totalQuestions = test.questions.length;
// TODO this should not be done here.
const questionBank = router.query["questionBank"] as QuestionBankName;

useBugReportDebugData("test-study-current-question", () => question);
useBugReportDebugData("test-study-test", () => test);
Expand Down Expand Up @@ -301,7 +306,7 @@ export const TestStudy = container<Props>(
variant="outlined"
target="_blank"
startDecorator={<OpenInNewIcon />}
href={`../../questions/${question.templateId}`}
href={`/modules/${questionBank}/questions/${question.templateId}`}
children="Explore Question"
/>
<Divider sx={{ my: 2 }}>Explanation</Divider>
Expand Down
Loading