Skip to content

Commit 242fe0c

Browse files
authored
Merge pull request #388 from qa-guru/QAGDEV-723
QAGDEV-723 - [FE] Прикрепления тестов к заданиям v8
2 parents d736c33 + 30281f7 commit 242fe0c

File tree

26 files changed

+259
-174
lines changed

26 files changed

+259
-174
lines changed

src/features/admin-panel/tests-admin/components/create-test-form.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,17 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
5656

5757
const [getTestAnswers] = useTestAnswerByQuestionLazyQuery();
5858

59-
// Загружаем данные существующего теста для редактирования
6059
useEffect(() => {
6160
if (existingTest) {
6261
setTestName(existingTest.testName || "");
6362
setSuccessThreshold(existingTest.successThreshold || 70);
6463

65-
// Загружаем вопросы и ответы с правильностью
6664
const loadQuestionsWithAnswers = async () => {
6765
const loadedQuestions: QuestionForm[] = [];
6866

6967
for (const question of existingTest.testQuestions || []) {
7068
if (!question?.id) continue;
7169

72-
// Получаем полную информацию об ответах для каждого вопроса
7370
const { data: answersData } = await getTestAnswers({
7471
variables: { questionId: question.id },
7572
});
@@ -95,7 +92,6 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
9592
}
9693

9794
setQuestions(loadedQuestions);
98-
// Открываем первый вопрос по умолчанию
9995
if (loadedQuestions.length > 0) {
10096
setExpandedQuestion(`question-0`);
10197
}
@@ -124,7 +120,6 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
124120
);
125121
setQuestions(updatedQuestions);
126122

127-
// Если удаляем активный вопрос, открываем предыдущий или следующий
128123
if (expandedQuestion === `question-${questionIndex}`) {
129124
if (updatedQuestions.length > 0) {
130125
const newIndex = questionIndex > 0 ? questionIndex - 1 : 0;
@@ -194,7 +189,7 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
194189
const handleSave = () => {
195190
const validationError = validateForm();
196191
if (validationError) {
197-
alert(validationError); // Можно заменить на более красивое уведомление
192+
alert(validationError);
198193
return;
199194
}
200195

@@ -208,7 +203,6 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
208203

209204
return (
210205
<Box>
211-
{/* Основная информация о тесте */}
212206
<Card sx={{ mb: 4 }}>
213207
<CardHeader
214208
title="Основная информация"
@@ -243,7 +237,6 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
243237
</CardContent>
244238
</Card>
245239

246-
{/* Секция вопросов */}
247240
<Card>
248241
<CardHeader
249242
title={
@@ -467,7 +460,6 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
467460
</CardContent>
468461
</Card>
469462

470-
{/* Кнопки действий */}
471463
<Box sx={{ display: "flex", justifyContent: "flex-end", gap: 2, mt: 4 }}>
472464
<Button onClick={onCancel} disabled={isLoading} size="large">
473465
Отмена

src/features/admin-panel/tests-admin/containers/create-test-container.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
3636
const [error, setError] = useState<string | null>(null);
3737
const [success, setSuccess] = useState<string | null>(null);
3838

39-
// Загружаем существующий тест для редактирования
4039
const {
4140
data: existingTestData,
4241
loading: loadingTest,
@@ -64,11 +63,9 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
6463
setError(null);
6564
setSuccess(null);
6665

67-
// Сначала сохраняем вопросы и ответы
6866
const savedQuestions = [];
6967

7068
for (const question of questions) {
71-
// Сохраняем вопрос
7269
const questionResult = await updateTestQuestion({
7370
variables: {
7471
input: {
@@ -81,7 +78,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
8178
const questionId = questionResult.data?.updateTestQuestion?.id;
8279
if (!questionId) throw new Error("Не удалось сохранить вопрос");
8380

84-
// Сохраняем ответы для этого вопроса
8581
for (const answer of question.answers) {
8682
await updateTestAnswer({
8783
variables: {
@@ -98,7 +94,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
9894
savedQuestions.push({ id: questionId });
9995
}
10096

101-
// Затем сохраняем тестовую группу
10297
const testGroupInput: TestGroupInput = {
10398
id: testId || undefined,
10499
testName,
@@ -118,7 +113,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
118113
setSuccess(`Тест успешно создан! ID: ${savedTestId}`);
119114
}
120115

121-
// Через 2 секунды перенаправляем обратно к списку тестов
122116
setTimeout(() => {
123117
navigate("/tests");
124118
}, 2000);
@@ -138,7 +132,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
138132
return (
139133
<Container maxWidth="lg">
140134
<Box sx={{ py: 3 }}>
141-
{/* Breadcrumbs и навигация */}
142135
<Box sx={{ mb: 3 }}>
143136
<Breadcrumbs>
144137
<Link
@@ -155,7 +148,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
155148
</Breadcrumbs>
156149
</Box>
157150

158-
{/* Заголовок страницы */}
159151
<Box
160152
sx={{
161153
display: "flex",
@@ -178,7 +170,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
178170
</Typography>
179171
</Box>
180172

181-
{/* Сообщения об ошибках и успехе */}
182173
{error && (
183174
<Alert severity="error" sx={{ mb: 3 }}>
184175
{error}
@@ -191,7 +182,6 @@ const CreateTestContainer: FC<CreateTestContainerProps> = ({ testId }) => {
191182
</Alert>
192183
)}
193184

194-
{/* Форма создания/редактирования */}
195185
<Paper sx={{ p: 3 }}>
196186
<CreateTestForm
197187
existingTest={existingTest}

src/features/admin-panel/tests-admin/create-test-form.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,18 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
5858
const [updateTestAnswer] = useUpdateTestAnswerMutation();
5959
const [getTestAnswers] = useTestAnswerByQuestionLazyQuery();
6060

61-
// Загружаем данные существующего теста для редактирования
6261
useEffect(() => {
6362
if (existingTestData?.testTestGroupsById) {
6463
const test = existingTestData.testTestGroupsById;
6564
setTestName(test.testName || "");
6665
setSuccessThreshold(test.successThreshold || 70);
6766

68-
// Загружаем вопросы и ответы с правильностью
6967
const loadQuestionsWithAnswers = async () => {
7068
const loadedQuestions: QuestionForm[] = [];
7169

7270
for (const question of test.testQuestions || []) {
7371
if (!question?.id) continue;
7472

75-
// Получаем полную информацию об ответах для каждого вопроса
7673
const { data: answersData } = await getTestAnswers({
7774
variables: { questionId: question.id },
7875
});
@@ -204,11 +201,9 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
204201
if (!validateForm()) return;
205202

206203
try {
207-
// Сначала сохраняем вопросы и ответы
208204
const savedQuestions: { id: string }[] = [];
209205

210206
for (const question of questions) {
211-
// Сохраняем вопрос
212207
const questionResult = await updateTestQuestion({
213208
variables: {
214209
input: {
@@ -221,7 +216,6 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
221216
const questionId = questionResult.data?.updateTestQuestion?.id;
222217
if (!questionId) throw new Error("Не удалось сохранить вопрос");
223218

224-
// Сохраняем ответы для этого вопроса
225219
for (const answer of question.answers) {
226220
await updateTestAnswer({
227221
variables: {
@@ -238,7 +232,6 @@ const CreateTestForm: FC<CreateTestFormProps> = ({
238232
savedQuestions.push({ id: questionId });
239233
}
240234

241-
// Затем сохраняем тестовую группу
242235
const testGroupInput: TestGroupInput = {
243236
id: testId || undefined,
244237
testName,

src/features/admin-panel/tests-admin/test-attempt-detail-view.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const TestAttemptDetailView: FC = () => {
7575

7676
return (
7777
<Box>
78-
{/* Хлебные крошки */}
7978
<Breadcrumbs sx={{ mb: 3 }}>
8079
<Link
8180
component="button"
@@ -88,7 +87,6 @@ const TestAttemptDetailView: FC = () => {
8887
<Typography color="text.primary">Попытка {attempt.id}</Typography>
8988
</Breadcrumbs>
9089

91-
{/* Заголовок */}
9290
<Box
9391
sx={{
9492
display: "flex",
@@ -109,7 +107,6 @@ const TestAttemptDetailView: FC = () => {
109107
</Button>
110108
</Box>
111109

112-
{/* Основная информация о попытке */}
113110
<Grid container spacing={3} sx={{ mb: 3 }}>
114111
<Grid item xs={12} md={6}>
115112
<Card>
@@ -217,7 +214,6 @@ const TestAttemptDetailView: FC = () => {
217214
</Grid>
218215
</Grid>
219216

220-
{/* Детали по вопросам */}
221217
<Card>
222218
<CardContent>
223219
<Typography variant="h6" gutterBottom>

src/features/admin-panel/tests-admin/test-attempt-detail.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const TestAttemptDetail: FC = () => {
7575

7676
return (
7777
<Box>
78-
{/* Хлебные крошки */}
7978
<Breadcrumbs sx={{ mb: 3 }}>
8079
<Link
8180
component="button"
@@ -88,7 +87,6 @@ const TestAttemptDetail: FC = () => {
8887
<Typography color="text.primary">Попытка {attempt.id}</Typography>
8988
</Breadcrumbs>
9089

91-
{/* Заголовок */}
9290
<Box
9391
sx={{
9492
display: "flex",
@@ -109,7 +107,6 @@ const TestAttemptDetail: FC = () => {
109107
</Button>
110108
</Box>
111109

112-
{/* Основная информация о попытке */}
113110
<Grid container spacing={3} sx={{ mb: 3 }}>
114111
<Grid item xs={12} md={6}>
115112
<Card>

src/features/admin-panel/tests-admin/test-attempts-list.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ const TestAttemptsList: FC = () => {
9494
attemptsData?.testAttemptsAll?.items?.filter((attempt) => {
9595
if (!attempt) return false;
9696

97-
// Фильтр по поиску (можно добавить поиск по ID попытки)
9897
if (searchTerm && !attempt.id?.includes(searchTerm)) return false;
9998

10099
return true;
@@ -153,7 +152,6 @@ const TestAttemptsList: FC = () => {
153152
</Button>
154153
</Box>
155154

156-
{/* Фильтры и поиск */}
157155
<Card sx={{ mb: 3 }}>
158156
<CardContent>
159157
<Grid container spacing={2} alignItems="center">
@@ -202,7 +200,6 @@ const TestAttemptsList: FC = () => {
202200
</CardContent>
203201
</Card>
204202

205-
{/* Статистика */}
206203
<Card sx={{ mb: 3 }}>
207204
<CardContent>
208205
<Grid container spacing={2}>
@@ -238,7 +235,6 @@ const TestAttemptsList: FC = () => {
238235
</CardContent>
239236
</Card>
240237

241-
{/* Таблица попыток */}
242238
<TableContainer component={Paper}>
243239
<Table>
244240
<TableHead>
@@ -316,7 +312,6 @@ const TestAttemptsList: FC = () => {
316312
</Table>
317313
</TableContainer>
318314

319-
{/* Пагинация */}
320315
{pagination && (
321316
<Box sx={{ display: "flex", justifyContent: "center", mt: 3 }}>
322317
<Pagination

src/features/edit-training/containers/select-tests.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ const SelectTests: FC<SelectTestsProps> = ({
6464
onChange={(e) => field.onChange(e.target.value)}
6565
displayEmpty
6666
>
67-
<MenuItem value="">
68-
<em>Без теста</em>
69-
</MenuItem>
7067
{tests.map((test) => (
7168
<MenuItem key={test?.id} value={test?.id || ""}>
7269
<Box

src/features/edit-training/views/edit-lecture/edit-lecture.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,6 @@ const EditLecture: FC<IEditLecture> = ({
260260
/>
261261
</StyledInfoStack>
262262
</StyledPaper>
263-
<StyledPaper>
264-
<StyledInfoStack>
265-
<Typography variant="h3">Тест для лекции</Typography>
266-
<SelectTests
267-
name="testGroupId"
268-
control={control}
269-
helperText="Выберите тест, который будет доступен студентам после изучения материалов лекции"
270-
/>
271-
</StyledInfoStack>
272-
</StyledPaper>
273263
<StyledPaper>
274264
<StyledInfoStack>
275265
<Typography variant="h3">Материалы урока</Typography>
@@ -294,6 +284,16 @@ const EditLecture: FC<IEditLecture> = ({
294284
/>
295285
</StyledInfoStack>
296286
</StyledPaper>
287+
<StyledPaper>
288+
<StyledInfoStack>
289+
<Typography variant="h3">Тест для лекции</Typography>
290+
<SelectTests
291+
name="testGroupId"
292+
control={control}
293+
helperText="Выберите тест, который будет доступен студентам после изучения материалов лекции"
294+
/>
295+
</StyledInfoStack>
296+
</StyledPaper>
297297
</StyledPaperStack>
298298
<StyledButtonsStack>
299299
<Box>

src/features/lecture-detail/views/homework-section/homework-section.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const HomeworkSection: FC<IHomeworkSection> = ({
1515
view,
1616
onKanbanView,
1717
onListView,
18+
testGroup,
19+
trainingId,
20+
lectureId,
1821
}) => {
1922
const hasHomework = lectureHomeWork?.length > 0;
2023

@@ -30,7 +33,11 @@ const HomeworkSection: FC<IHomeworkSection> = ({
3033
const homework = (
3134
<>
3235
<LectureHomework lectureHomeWork={lectureHomeWork} />
33-
<Homework />
36+
<Homework
37+
testGroup={testGroup}
38+
trainingId={trainingId}
39+
lectureId={lectureId}
40+
/>
3441
<HomeworksViewSwitcher
3542
onKanbanView={onKanbanView}
3643
onListView={onListView}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import { TestGroupDto } from "api/graphql/generated/graphql";
2+
13
export interface IHomeworkSection {
24
lectureHomeWork: string;
35
view: string;
46
onKanbanView: () => void;
57
onListView: () => void;
8+
testGroup?: TestGroupDto;
9+
trainingId?: string;
10+
lectureId?: string;
611
}

0 commit comments

Comments
 (0)