All files / src/app/teacher-page/page/assignments/data-analytics DataAnalyticsPage.jsx

0% Statements 0/16
0% Branches 0/2
0% Functions 0/4
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135                                                                                                                                                                                                                                                                             
import React, { useEffect, useMemo } from "react";
import { useLocation, useParams } from "react-router-dom";
import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box";
import AppBar from "@mui/material/AppBar";
import Toolbar from "@mui/material/Toolbar";
import TabsComponent from "@/utils/components/TabsComponent";
import AssignmentSummary from "./assignment-summary/AssignmentSummary";
import ItemAnalysis from "./item-analysis/ItemAnalysis";
import AssignmentSummaryMock from "./assignment-summary/AssignmentSummaryMock";
import ItemAnalysisMock from "./item-analysis/ItemAnalysisMock";
import IndividualAnswers from "./individual-answers/IndividualAnswers";
import FeatureAccessGate from "@/utils/components/feature-access/FeatureAccessGate";
import { useDispatch, useSelector } from "react-redux";
import { _fetchSpecificClassByCode } from "@/store/slices/teacher/TeacherSpecificClass";
import BasicBreadcrumbs from "@/utils/components/breadcrumbs/basic-breadcrumbs/BasicBreadcrumbs";
import getCurrentSemesterYear from "@/utils/helpers/getCurrentSemesterYear";
import useFeatureFlag from "@/utils/hooks/useFeatureFlag";
import { TEACHER_ITEM_ANALYSIS_FEATURE_KEY } from "@/utils/features/featureAccess";
import {
    isTeacherMadeAssignmentAnalyticsEnabled,
    TEACHER_MADE_TESTS_LIMIT_10_KEY,
} from "@/utils/features/teacherMadeAssignmentQuota";
 
const AnalysisPage = () => {
    const { specificClassData } = useSelector((state) => state.TeacherSpecificClass);
    const { currentYear } = getCurrentSemesterYear();
    const { classCode, assignmentTitle } = useParams();
    const { isFeatureEnabled, features } = useFeatureFlag("teacher");
 
    const dispatch = useDispatch();
    const location = useLocation();
 
    const summaryEnabled = isTeacherMadeAssignmentAnalyticsEnabled(features);
    const itemAnalysisEnabled = isFeatureEnabled(TEACHER_ITEM_ANALYSIS_FEATURE_KEY);
 
    const tabContents = useMemo(
        () => [
            {
                id: "teacher-analytics-tab-assignment-summary",
                label: "Assignment Summary",
                locked: !summaryEnabled,
                component: (
                    <Box sx={{ mt: 5, mb: 10 }}>
                        <FeatureAccessGate
                            id="teacher-analytics-summary-gate"
                            enabled={summaryEnabled}
                            featureKey={TEACHER_MADE_TESTS_LIMIT_10_KEY}
                            title="Assignment analytics are locked"
                            featureLabel="Assignment Summary"
                            minPlan="intermediate"
                            mockContent={<AssignmentSummaryMock />}
                            blurMinHeight={420}
                        >
                            <AssignmentSummary />
                        </FeatureAccessGate>
                    </Box>
                ),
            },
            {
                id: "teacher-analytics-tab-item-analysis",
                label: "Item Analysis",
                locked: !itemAnalysisEnabled,
                component: (
                    <Box sx={{ mt: 5, mb: 10 }}>
                        <FeatureAccessGate
                            id="teacher-analytics-item-analysis-gate"
                            featureKey={TEACHER_ITEM_ANALYSIS_FEATURE_KEY}
                            title="Item analysis is locked"
                            featureLabel="Item Analysis"
                            minPlan="intermediate"
                            mockContent={<ItemAnalysisMock />}
                            blurMinHeight={400}
                        >
                            <ItemAnalysis />
                        </FeatureAccessGate>
                    </Box>
                ),
            },
            {
                id: "teacher-analytics-tab-individual-answers",
                label: "Individual Answers",
                component: (
                    <Box sx={{ mt: 5, mb: 10 }}>
                        <IndividualAnswers />
                    </Box>
                ),
            },
        ],
        [summaryEnabled, itemAnalysisEnabled]
    );
 
    const breadcrumb = [
        {
            name: "Classes",
            isLink: true,
            path: "/teacher/classes",
        },
        {
            name: specificClassData?.title,
            isLink: true,
            path: `/teacher/classes/${classCode}`,
        },
        {
            name: assignmentTitle,
            isLink: false,
        },
    ];
 
    useEffect(() => {
        dispatch(_fetchSpecificClassByCode(classCode));
    }, [location, dispatch, classCode]);
 
    return (
        <React.Fragment>
            <AppBar position="relative" color="primary">
                {specificClassData && (
                    <Toolbar sx={{ display: "flex", justifyContent: "space-between" }}>
                        <Typography variant="h6">
                            {`${currentYear}-${specificClassData.semester}: ${specificClassData.title} (${specificClassData.section})`}
                        </Typography>
                        <Typography variant="h6">Class code: {specificClassData.class_code}</Typography>
                    </Toolbar>
                )}
            </AppBar>
            <BasicBreadcrumbs links={breadcrumb} />
            <Box sx={{ padding: "2%" }}>
                <TabsComponent tabContents={tabContents} />
            </Box>
        </React.Fragment>
    );
};
 
export default AnalysisPage;