@datalayer/core
Version:
**Datalayer Core**
48 lines (47 loc) • 2.67 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/
import { useMemo } from "react";
import { useTheme, Tooltip, Button } from "@primer/react";
import { Box } from "@datalayer/primer-addons";
const getExercisePoints = (studentItem) => {
if (studentItem && studentItem.points) {
return studentItem.points;
}
return 0;
};
export const StudentItemStatus = (props) => {
const { student, studentItem } = props;
const { theme } = useTheme();
const okColor = useMemo(() => theme?.colorSchemes.light.colors.success.muted, []);
const nokColor = useMemo(() => theme?.colorSchemes.light.colors.severe.muted, []);
if (student && studentItem) {
switch (studentItem.itemType) {
case ('dataset'): {
const datasetColor = studentItem?.completed ? okColor : nokColor;
return _jsx(Box, { sx: { backgroundColor: datasetColor, width: '14px', height: '14px', borderRadius: 3 }, ml: 1 });
}
case ('lesson'): {
const lessonColor = studentItem?.completed ? okColor : nokColor;
return _jsx(Box, { sx: { backgroundColor: lessonColor, width: '14px', height: '14px', borderRadius: 3 }, ml: 1 });
}
case ('exercise'): {
const exerciseColor = getExercisePoints(studentItem) > 0 ? okColor : nokColor;
return _jsx(Box, { sx: { backgroundColor: exerciseColor, width: '14px', height: '14px', borderRadius: 3 }, ml: 1 });
}
case ('assignment'):
return (_jsxs(Box, { display: "flex", children: [(studentItem.nbgradesTotalScore !== undefined) && (studentItem.nbgradesTotalPoints !== undefined) &&
_jsxs(Box, { children: [studentItem.nbgradesTotalScore, " / ", studentItem.nbgradesTotalPoints] }), studentItem.nbgrades &&
_jsx(Box, { display: "flex", ml: 3, children: studentItem?.nbgrades.map(grade => {
const gradeColor = grade.score_f === grade.points_f ? okColor : nokColor;
return (_jsx(Tooltip, { text: grade.grade_id_s, children: _jsx(Button, { variant: "invisible", children: _jsx(Box, { sx: { backgroundColor: gradeColor, width: '14px', height: '14px', borderRadius: 3 }, ml: 1 }) }) }));
}) })] }));
default:
return _jsx(_Fragment, {});
}
}
return _jsx(_Fragment, {});
};
export default StudentItemStatus;