Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/course/assignments/assignment-student-list.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { useIntl } from "react-intl";67// CoCalc libraries8import { AppRedux, useMemo } from "@cocalc/frontend/app-framework";9import ScrollableList from "@cocalc/frontend/components/scrollable-list";10import { search_match, search_split, trunc_middle } from "@cocalc/util/misc";11import { StudentAssignmentInfo, StudentAssignmentInfoHeader } from "../common";12import {13AssignmentRecord,14CourseStore,15IsGradingMap,16NBgraderRunInfo,17SortDescription,18} from "../store";19import * as util from "../util";2021interface StudentListForAssignmentProps {22frame_id?: string;23name: string;24redux: AppRedux;25assignment: AssignmentRecord;26students: any;27user_map: any;28background?: string;29active_student_sort: SortDescription;30active_feedback_edits: IsGradingMap;31nbgrader_run_info?: NBgraderRunInfo;32search: string;33}3435export function StudentListForAssignment({36frame_id,37name,38redux,39assignment,40students,41user_map,42background,43active_student_sort,44active_feedback_edits,45nbgrader_run_info,46search,47}: StudentListForAssignmentProps) {48const intl = useIntl();4950const student_list: string[] = useMemo(() => {51const v0 = util.parse_students(students, user_map, redux, intl);52const store = get_store();5354// Remove deleted students or students not matching the search55const terms = search_split(search);56const v1: any[] = [];57for (const x of v0) {58if (x.deleted) continue;59if (60terms.length > 0 &&61!search_match(store.get_student_name(x.student_id).toLowerCase(), terms)62) {63continue;64}65v1.push(x);66}6768v1.sort(util.pick_student_sorter(active_student_sort.toJS()));6970if (active_student_sort.get("is_descending")) {71v1.reverse();72}7374return v1.map((x) => x.student_id);75}, [76assignment,77students,78user_map,79background,80active_student_sort,81active_feedback_edits,82nbgrader_run_info,83search,84]);8586function get_store(): CourseStore {87return redux.getStore(name) as any;88}8990function is_peer_graded(): boolean {91const peer_info = assignment.get("peer_grade");92return peer_info ? peer_info.get("enabled") : false;93}9495function render_student_info(student_id: string) {96const store = get_store();97const student = store.get_student(student_id);98if (student == null) return; // no such student99const key = util.assignment_identifier(100assignment.get("assignment_id"),101student_id,102);103const edited_feedback = active_feedback_edits.get(key);104return (105<StudentAssignmentInfo106key={student_id}107title={trunc_middle(store.get_student_name(student_id), 40)}108name={name}109student={student}110assignment={assignment}111grade={store.get_grade(assignment.get("assignment_id"), student_id)}112nbgrader_scores={store.get_nbgrader_scores(113assignment.get("assignment_id"),114student_id,115)}116nbgrader_score_ids={store.get_nbgrader_score_ids(117assignment.get("assignment_id"),118)}119comments={store.get_comments(120assignment.get("assignment_id"),121student_id,122)}123info={store.student_assignment_info(124student_id,125assignment.get("assignment_id"),126)}127is_editing={!!edited_feedback}128nbgrader_run_info={nbgrader_run_info}129/>130);131}132133function render_students() {134return (135<ScrollableList136virtualize137rowCount={student_list.length}138rowRenderer={({ key }) => render_student_info(key)}139rowKey={(index) => student_list[index]}140cacheId={`course-assignment-${assignment.get(141"assignment_id",142)}-${name}-${frame_id}`}143/>144);145}146147return (148<div style={{ height: "70vh", display: "flex", flexDirection: "column" }}>149<StudentAssignmentInfoHeader150key="header"151title="Student"152peer_grade={is_peer_graded()}153/>154{render_students()}155</div>156);157}158159160