-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathReorderableTestCasesManager.tsx
77 lines (66 loc) · 2.44 KB
/
ReorderableTestCasesManager.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { FC } from 'react';
import { useFormContext, useWatch } from 'react-hook-form';
import { DragDropContext, DropResult } from '@hello-pangea/dnd';
import { ProgrammingFormData } from 'types/course/assessment/question/programming';
import useTranslation from 'lib/hooks/useTranslation';
import translations from '../../../translations';
import { rearrangeTestCases } from '../operations';
import ReorderableTestCases, {
ReorderableTestCasesProps,
} from './common/ReorderableTestCases';
export interface ReorderableTestCasesManagerProps
extends Omit<
ReorderableTestCasesProps,
'testCases' | 'hintHeader' | 'title' | 'control'
> {}
const ReorderableTestCasesManager: FC<ReorderableTestCasesManagerProps> = (
props,
) => {
const { t } = useTranslation();
const { component, disabled, lhsHeader, rhsHeader } = props;
const { control, setValue } = useFormContext<ProgrammingFormData>();
const testCases = useWatch({ control, name: 'testUi.metadata.testCases' });
const onRearrangingTestCases = (result: DropResult): void => {
rearrangeTestCases(result, testCases, setValue);
};
return (
<DragDropContext onDragEnd={onRearrangingTestCases}>
<ReorderableTestCases
component={component}
control={control}
disabled={disabled}
hintHeader={t(translations.hint)}
lhsHeader={lhsHeader}
name="testUi.metadata.testCases.public"
rhsHeader={rhsHeader}
testCases={testCases?.public ?? []}
title={t(translations.publicTestCases)}
/>
<ReorderableTestCases
component={component}
control={control}
disabled={props.disabled}
hintHeader={t(translations.hint)}
lhsHeader={lhsHeader}
name="testUi.metadata.testCases.private"
rhsHeader={rhsHeader}
subtitle={t(translations.privateTestCasesHint)}
testCases={testCases?.private ?? []}
title={t(translations.privateTestCases)}
/>
<ReorderableTestCases
component={component}
control={control}
disabled={props.disabled}
hintHeader={t(translations.hint)}
lhsHeader={lhsHeader}
name="testUi.metadata.testCases.evaluation"
rhsHeader={rhsHeader}
subtitle={t(translations.evaluationTestCasesHint)}
testCases={testCases?.evaluation ?? []}
title={t(translations.evaluationTestCases)}
/>
</DragDropContext>
);
};
export default ReorderableTestCasesManager;