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

[Improvements] Make office hours wait time analytics available to students #305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 20 additions & 3 deletions frontend/components/Course/Analytics/Analytics.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Link from "next/link";
import { useState } from "react";
import { useContext, useState } from "react";
import { Segment, Grid, Dropdown } from "semantic-ui-react";
import { Course, Queue } from "../../../types";
import Averages from "./Heatmaps/Averages";
import SummaryCards from "./Cards/SummaryCards";
import { AuthUserContext } from "../../../context/auth";
import { useStaff } from "../../../hooks/data-fetching/course";

interface AnalyticsProps {
course: Course;
Expand All @@ -23,6 +25,15 @@ const Analytics = ({ course, queues }: AnalyticsProps) => {
};
});

const { user: initialUser } = useContext(AuthUserContext);
if (!initialUser) {
throw new Error(
"Invariant broken, withAuth must be used with component"
);
}

const { staff: isStaff } = useStaff(course.id, initialUser);

return (
<Grid.Row>
{queueId ? (
Expand All @@ -36,8 +47,14 @@ const Analytics = ({ course, queues }: AnalyticsProps) => {
setQueueId(value as number);
}}
/>
<SummaryCards courseId={course.id} queueId={queueId} />
<Averages courseId={course.id} queueId={queueId} />
{isStaff && (
<SummaryCards courseId={course.id} queueId={queueId} />
)}
<Averages
courseId={course.id}
queueId={queueId}
isStaff={isStaff}
/>
</>
) : (
<Segment basic>
Expand Down
94 changes: 60 additions & 34 deletions frontend/components/Course/Analytics/Heatmaps/Averages.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
import { Tab, Segment, Header } from "semantic-ui-react";
import { useHeatmapData } from "../../../../hooks/data-fetching/analytics";
import { Metric } from "../../../../types";
import { HeatmapSeries, Metric } from "../../../../types";
import Heatmap from "./Heatmap";

interface AveragesProps {
courseId: number;
queueId: number;
isStaff: boolean;
}

export default function Averages({ courseId, queueId }: AveragesProps) {
const QuestionsPerInstructorPane = (
questionsData: HeatmapSeries[],
questionsValidating: boolean
) => {
return {
menuItem: "Questions per Instructor",
render: () => {
if (questionsData) {
return (
<Heatmap
series={questionsData}
chartTitle="Average Questions per Instructor"
/>
);
}
if (questionsValidating) {
return <div>Loading...</div>;
}
return <div>Error loading data</div>;
},
};
};

const StudentWaitTimesPane = (
waitTimesData: HeatmapSeries[],
waitValidating: boolean
) => {
return {
menuItem: "Student Wait Times",
render: () => {
if (waitTimesData) {
return (
<Heatmap
series={waitTimesData}
chartTitle="Average Student Wait Times in Minutes"
/>
);
}
if (waitValidating) return <div>Loading...</div>;
return <div>Error loading data</div>;
},
};
};

export default function Averages({
courseId,
queueId,
isStaff,
}: AveragesProps) {
const { data: questionsData, isValidating: questionsValidating } =
useHeatmapData(courseId, queueId, Metric.HEATMAP_QUESTIONS);
const { data: waitTimesData, isValidating: waitValidating } =
Expand All @@ -20,38 +69,15 @@ export default function Averages({ courseId, queueId }: AveragesProps) {
<Tab
menu={{ secondary: true, pointing: true }}
panes={[
{
menuItem: "Questions per Instructor",
render: () => {
if (questionsData) {
return (
<Heatmap
series={questionsData}
chartTitle="Average Questions per Instructor"
/>
);
}
if (questionsValidating) {
return <div>Loading...</div>;
}
return <div>Error loading data</div>;
},
},
{
menuItem: "Student Wait Times",
render: () => {
if (waitTimesData) {
return (
<Heatmap
series={waitTimesData}
chartTitle="Average Student Wait Times in Minutes"
/>
);
}
if (waitValidating) return <div>Loading...</div>;
return <div>Error loading data</div>;
},
},
...(isStaff
? [
QuestionsPerInstructorPane(
questionsData || [],
questionsValidating
),
]
: []),
StudentWaitTimesPane(waitTimesData || [], waitValidating),
]}
/>
</Segment>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Course/CourseSidebarNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const CourseSidebarNav = (props: CourseSidebarProps) => {
/>
</Link>
)}
{staff && (
{!course.archived && (
<Link
href="/courses/[course]/analytics"
as={`/courses/${courseId}/analytics`}
Expand Down
6 changes: 1 addition & 5 deletions frontend/pages/courses/[course]/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Grid } from "semantic-ui-react";
import { NextPageContext } from "next";
import CourseWrapper from "../../../components/Course/CourseWrapper";
import { withAuth } from "../../../context/auth";
import staffCheck from "../../../utils/staffcheck";
import { withProtectPage } from "../../../utils/protectpage";
import { doMultipleSuccessRequests } from "../../../utils/fetch";
import { isLeadershipRole } from "../../../utils/enums";
import nextRedirect from "../../../utils/redirect";
Expand Down Expand Up @@ -69,6 +67,4 @@ AnalyticsPage.getInitialProps = async (
};
};

export default withProtectPage(withAuth(AnalyticsPage), (user, ctx) => {
return staffCheck(user, ctx);
});
export default withAuth(AnalyticsPage);
Loading