1
1
import React , { FC , useEffect , useState } from 'react' ;
2
2
import { HomeworkViewModel , AccountDataDto , MentorToAssignedStudentsDTO } from '../../api' ;
3
3
import Grid from "@material-ui/core/Grid" ;
4
- import { Autocomplete , Chip } from "@mui/material" ;
4
+ import { Autocomplete , Chip , Stack , Typography } from "@mui/material" ;
5
5
import TextField from "@material-ui/core/TextField" ;
6
6
import ApiSingleton from "../../api/ApiSingleton" ;
7
7
import ErrorsHandler from "../Utils/ErrorsHandler" ;
@@ -107,6 +107,12 @@ const CourseFilter: FC<ICourseFilterProps> = (props) => {
107
107
. filter ( x => x !== undefined )
108
108
. map ( x => x . name + ' ' + x . surname )
109
109
110
+ const studentsWithMultipleReviewers = new Set (
111
+ state . selectedStudents
112
+ . map ( x => x . userId ! )
113
+ . filter ( x => getAssignedMentors ( x ) . length > 0 )
114
+ )
115
+
110
116
return (
111
117
< div >
112
118
{ isLoading ? (
@@ -138,7 +144,7 @@ const CourseFilter: FC<ICourseFilterProps> = (props) => {
138
144
placeholder = { state . selectedHomeworks . length === 0 ? "Все задания" : "" }
139
145
/>
140
146
) }
141
- noOptionsText = { 'На курсе больше нет заданий' }
147
+ noOptionsText = { 'Больше нет заданий для выбора ' }
142
148
value = { state . selectedHomeworks }
143
149
onChange = { ( _ , values ) => {
144
150
setState ( ( prevState ) => ( {
@@ -159,46 +165,48 @@ const CourseFilter: FC<ICourseFilterProps> = (props) => {
159
165
) : (
160
166
< Grid container spacing = { 2 } style = { { marginTop : '12px' } } >
161
167
< 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 ) =>
185
190
< Chip
186
191
label = { option . surname + ' ' + option . name }
187
192
{ ...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 >
202
210
</ Grid >
203
211
</ Grid >
204
212
0 commit comments