11import React , { FC , useEffect , useState } from 'react' ;
22import { HomeworkViewModel , AccountDataDto , MentorToAssignedStudentsDTO } from '../../api' ;
33import Grid from "@material-ui/core/Grid" ;
4- import { Autocomplete , Chip } from "@mui/material" ;
4+ import { Autocomplete , Chip , Stack , Typography } from "@mui/material" ;
55import TextField from "@material-ui/core/TextField" ;
66import ApiSingleton from "../../api/ApiSingleton" ;
77import ErrorsHandler from "../Utils/ErrorsHandler" ;
@@ -107,6 +107,12 @@ const CourseFilter: FC<ICourseFilterProps> = (props) => {
107107 . filter ( x => x !== undefined )
108108 . map ( x => x . name + ' ' + x . surname )
109109
110+ const studentsWithMultipleReviewers = new Set (
111+ state . selectedStudents
112+ . map ( x => x . userId ! )
113+ . filter ( x => getAssignedMentors ( x ) . length > 0 )
114+ )
115+
110116 return (
111117 < div >
112118 { isLoading ? (
@@ -138,7 +144,7 @@ const CourseFilter: FC<ICourseFilterProps> = (props) => {
138144 placeholder = { state . selectedHomeworks . length === 0 ? "Все задания" : "" }
139145 />
140146 ) }
141- noOptionsText = { 'На курсе больше нет заданий' }
147+ noOptionsText = { 'Больше нет заданий для выбора ' }
142148 value = { state . selectedHomeworks }
143149 onChange = { ( _ , values ) => {
144150 setState ( ( prevState ) => ( {
@@ -159,46 +165,48 @@ const CourseFilter: FC<ICourseFilterProps> = (props) => {
159165 ) : (
160166 < Grid container spacing = { 2 } style = { { marginTop : '12px' } } >
161167 < Grid item xs = { 12 } sm = { 12 } >
162- < Autocomplete
163- multiple
164- fullWidth
165- options = { state . courseStudents }
166- getOptionLabel = { ( option : AccountDataDto ) => {
167- const assignedMentors = getAssignedMentors ( option . userId ! )
168- const suffix = assignedMentors . length > 0 ? " — преподаватель " + assignedMentors [ 0 ] + "" : ""
169- return option . surname + ' ' + option . name + suffix ;
170- } }
171- getOptionKey = { ( option : AccountDataDto ) => option . userId ?? "" }
172- filterSelectedOptions
173- isOptionEqualToValue = { ( option , value ) => option . userId === value . userId }
174- renderInput = { ( params ) => (
175- < TextField
176- { ...params }
177- variant = "outlined"
178- label = { state . selectedStudents . length === 0 ? "" : `Студенты (${ state . selectedStudents . length } )` }
179- placeholder = { state . selectedStudents . length === 0 ? "Все студенты" : "" }
180- /> ) }
181- renderTags = { ( value , getTagProps ) =>
182- value . map ( ( option , index ) => {
183- const hasAssignedStudents = getAssignedMentors ( option . userId ! ) . length > 0
184- return (
168+ < Stack direction = { "column" } >
169+ < Autocomplete
170+ multiple
171+ fullWidth
172+ options = { state . courseStudents }
173+ getOptionLabel = { ( option : AccountDataDto ) => {
174+ const assignedMentors = getAssignedMentors ( option . userId ! )
175+ const suffix = assignedMentors . length > 0 ? " — преподаватель " + assignedMentors [ 0 ] + "" : ""
176+ return option . surname + ' ' + option . name + suffix ;
177+ } }
178+ getOptionKey = { ( option : AccountDataDto ) => option . userId ?? "" }
179+ filterSelectedOptions
180+ isOptionEqualToValue = { ( option , value ) => option . userId === value . userId }
181+ renderInput = { ( params ) => (
182+ < TextField
183+ { ...params }
184+ variant = "outlined"
185+ label = { state . selectedStudents . length === 0 ? "" : `Студенты (${ state . selectedStudents . length } )` }
186+ placeholder = { state . selectedStudents . length === 0 ? "Все студенты" : "" }
187+ /> ) }
188+ renderTags = { ( value , getTagProps ) =>
189+ value . map ( ( option , index ) =>
185190 < Chip
186191 label = { option . surname + ' ' + option . name }
187192 { ...getTagProps ( { index} ) }
188- color = { hasAssignedStudents ? "info" : "default" }
189- />
190- ) ;
191- } )
192- }
193- noOptionsText = { 'На курсе нет студентов' }
194- value = { state . selectedStudents }
195- onChange = { ( _ , values ) => {
196- setState ( ( prevState ) => ( {
197- ...prevState ,
198- selectedStudents : values
199- } ) ) ;
200- } }
201- />
193+ style = { studentsWithMultipleReviewers . has ( option . userId ! ) ? { color : "#3f51b5" } : undefined }
194+ /> )
195+ }
196+ noOptionsText = { 'Больше нет студентов для выбора' }
197+ value = { state . selectedStudents }
198+ onChange = { ( _ , values ) => {
199+ setState ( ( prevState ) => ( {
200+ ...prevState ,
201+ selectedStudents : values
202+ } ) ) ;
203+ } }
204+ />
205+ { studentsWithMultipleReviewers . size > 0 &&
206+ < Typography align = "center" variant = { "caption" } color = { "#3f51b5" } >
207+ Синим выделены студенты, закрепленные за несколькими преподавателями
208+ </ Typography > }
209+ </ Stack >
202210 </ Grid >
203211 </ Grid >
204212
0 commit comments