@datalayer/core 1.1.56 → 1.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ import { IStudent } from '../../models';
2
+ /**
3
+ * What the status of a student on an item is read from.
4
+ *
5
+ * Named here by what is displayed rather than by the model it comes from: the
6
+ * concrete `IStudentItem` lives with the content, in `@datalayer/agent-runtimes`,
7
+ * and this package does not depend on the content models — see the note on
8
+ * `IStudent`. Any student item satisfies this shape, so callers pass theirs as
9
+ * they hold it.
10
+ */
11
+ export interface IStudentItemStatusData {
12
+ /** What the student worked on: an exercise, an assignment, a lesson… */
13
+ itemType?: string;
14
+ /** Whether a lesson or a dataset was gone through. */
15
+ completed?: boolean;
16
+ /** Set once the platform recorded an attempt. */
17
+ id?: string;
18
+ /** The code an exercise was answered with. */
19
+ codeStudent?: string;
20
+ /** The score of an exercise. */
21
+ score?: number;
22
+ /** What an assignment scored, and what it was out of. */
23
+ nbgradesTotalScore?: number;
24
+ nbgradesTotalPoints?: number;
25
+ /** The individual checks of an assignment. */
26
+ nbgrades?: any;
27
+ }
28
+ type Props = {
29
+ student?: IStudent;
30
+ studentItem?: IStudentItemStatusData;
31
+ };
32
+ export declare const StudentItemStatus: (props: Props) => import("react/jsx-runtime").JSX.Element;
33
+ export default StudentItemStatus;
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { StudentResultCircle } from './StudentResultCircle.js';
3
+ const getExerciseScore = (studentItem) => {
4
+ if (studentItem && studentItem.score) {
5
+ return studentItem.score;
6
+ }
7
+ return 0;
8
+ };
9
+ export const StudentItemStatus = (props) => {
10
+ const { studentItem } = props;
11
+ if (!studentItem) {
12
+ return _jsx(StudentResultCircle, { status: "none", label: "No result yet" });
13
+ }
14
+ switch (studentItem.itemType) {
15
+ case 'dataset': {
16
+ if (studentItem.completed === undefined) {
17
+ return (_jsx(StudentResultCircle, { status: "none", label: "Dataset not started" }));
18
+ }
19
+ const completed = Boolean(studentItem.completed);
20
+ return (_jsx(StudentResultCircle, { status: completed ? 'pass' : 'fail', label: completed ? 'Dataset completed' : 'Dataset not completed' }));
21
+ }
22
+ case 'lesson': {
23
+ if (studentItem.completed === undefined) {
24
+ return _jsx(StudentResultCircle, { status: "none", label: "Lesson not started" });
25
+ }
26
+ const completed = Boolean(studentItem.completed);
27
+ return (_jsx(StudentResultCircle, { status: completed ? 'pass' : 'fail', label: completed ? 'Lesson completed' : 'Lesson not completed' }));
28
+ }
29
+ case 'exercise': {
30
+ const hasResult = Boolean(studentItem.id) ||
31
+ Boolean(studentItem.codeStudent) ||
32
+ studentItem.score !== undefined;
33
+ if (!hasResult) {
34
+ return (_jsx(StudentResultCircle, { status: "none", label: "Exercise not started" }));
35
+ }
36
+ const passed = getExerciseScore(studentItem) > 0;
37
+ return (_jsx(StudentResultCircle, { status: passed ? 'pass' : 'fail', label: passed ? 'Exercise passed' : 'Exercise failed' }));
38
+ }
39
+ case 'assignment': {
40
+ const hasRecordedAttempt = Boolean(studentItem.id) ||
41
+ studentItem.nbgradesTotalScore !== undefined ||
42
+ studentItem.nbgradesTotalPoints !== undefined ||
43
+ Boolean(studentItem.nbgrades);
44
+ if (!hasRecordedAttempt) {
45
+ return (_jsx(StudentResultCircle, { status: "none", label: "Assignment not graded" }));
46
+ }
47
+ const totalScore = studentItem.nbgradesTotalScore ?? 0;
48
+ const totalPoints = studentItem.nbgradesTotalPoints ?? 0;
49
+ const nbgrades = Array.isArray(studentItem.nbgrades)
50
+ ? studentItem.nbgrades
51
+ : [];
52
+ const status = totalPoints === 0
53
+ ? 'pass'
54
+ : totalScore <= 0
55
+ ? 'fail'
56
+ : totalScore >= totalPoints
57
+ ? 'pass'
58
+ : 'partial';
59
+ const tooltip = nbgrades.length > 0
60
+ ? `Assignment graded: ${totalScore} / ${totalPoints} (${nbgrades.length} checks)`
61
+ : `Assignment graded: ${totalScore} / ${totalPoints}`;
62
+ return _jsx(StudentResultCircle, { status: status, label: tooltip });
63
+ }
64
+ default:
65
+ return _jsx(StudentResultCircle, { status: "none", label: "No result yet" });
66
+ }
67
+ };
68
+ export default StudentItemStatus;
@@ -1 +1,2 @@
1
+ export * from './StudentItemStatus';
1
2
  export * from './StudentResultCircle';
@@ -2,4 +2,5 @@
2
2
  * Copyright (c) 2023-2025 Datalayer, Inc.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
+ export * from './StudentItemStatus.js';
5
6
  export * from './StudentResultCircle.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/core",
3
- "version": "1.1.56",
3
+ "version": "1.1.57",
4
4
  "type": "module",
5
5
  "workspaces": [
6
6
  ".",