1
- import { FC } from 'react' ;
2
- import { useFormContext , useWatch } from 'react-hook-form' ;
1
+ import { ElementType , FC } from 'react' ;
2
+ import { Control , UseFormSetValue , useWatch } from 'react-hook-form' ;
3
3
import { DragDropContext , DropResult } from '@hello-pangea/dnd' ;
4
4
import { Container } from '@mui/material' ;
5
5
import { ProgrammingFormData } from 'types/course/assessment/question/programming' ;
6
6
7
+ import { ReorderableTestCaseProps } from 'course/assessment/question/programming/components/common/ReorderableTestCase' ;
7
8
import ReorderableTestCases from 'course/assessment/question/programming/components/common/ReorderableTestCases' ;
8
9
import {
9
10
deleteTestCase ,
@@ -14,17 +15,25 @@ import useTranslation from 'lib/hooks/useTranslation';
14
15
import translations from '../../translations' ;
15
16
16
17
import LockableSection from './LockableSection' ;
18
+ import { QuestionPrototypeFormData } from './types' ;
17
19
18
20
interface TestCasesManagerProps {
21
+ control : Control < QuestionPrototypeFormData > ;
22
+ setValue : UseFormSetValue < QuestionPrototypeFormData > ;
19
23
lockStates : { [ key : string ] : boolean } ;
20
24
onToggleLock : ( key : string ) => void ;
25
+ component ?: ElementType < ReorderableTestCaseProps > ;
21
26
}
22
27
23
28
const TestCasesManager : FC < TestCasesManagerProps > = ( props ) => {
24
29
const { t } = useTranslation ( ) ;
25
- const { lockStates, onToggleLock } = props ;
30
+ const { component, lockStates, onToggleLock } = props ;
31
+
32
+ // Cast fields to ProgrammingFormData to satisfy helper components' type assertions
33
+ const control = props . control as unknown as Control < ProgrammingFormData > ;
34
+ const setValue =
35
+ props . setValue as unknown as UseFormSetValue < ProgrammingFormData > ;
26
36
27
- const { control, setValue } = useFormContext < ProgrammingFormData > ( ) ;
28
37
const testCases = useWatch ( { control, name : 'testUi.metadata.testCases' } ) ;
29
38
30
39
const onRearrangingTestCases = ( result : DropResult ) : void => {
@@ -48,6 +57,7 @@ const TestCasesManager: FC<TestCasesManagerProps> = (props) => {
48
57
>
49
58
< Container disableGutters maxWidth = { false } >
50
59
< ReorderableTestCases
60
+ component = { component }
51
61
control = { control }
52
62
disabled = { lockStates [ publicTestCasesName ] }
53
63
hintHeader = { t ( translations . hint ) }
@@ -70,6 +80,7 @@ const TestCasesManager: FC<TestCasesManagerProps> = (props) => {
70
80
>
71
81
< Container disableGutters maxWidth = { false } >
72
82
< ReorderableTestCases
83
+ component = { component }
73
84
control = { control }
74
85
disabled = { lockStates [ privateTestCasesName ] }
75
86
hintHeader = { t ( translations . hint ) }
@@ -93,6 +104,7 @@ const TestCasesManager: FC<TestCasesManagerProps> = (props) => {
93
104
>
94
105
< Container disableGutters maxWidth = { false } >
95
106
< ReorderableTestCases
107
+ component = { component }
96
108
control = { control }
97
109
disabled = { lockStates [ evaluationTestCasesName ] }
98
110
hintHeader = { t ( translations . hint ) }
0 commit comments