@@ -12,7 +12,7 @@ import PCModalContent from './PCModalContent';
12
12
import { ExampleType , File , QuestionSolution , WorkflowType } from './types' ;
13
13
import FileSelectorButton from './FileSelectorButton' ;
14
14
15
- import { fetchFileContent , getExampleType , useGetExamplesByUseCase } from './hooks' ;
15
+ import { fetchExamplesByUseCase , fetchFileContent , getExampleType , useGetExamplesByUseCase } from './hooks' ;
16
16
import { useState } from 'react' ;
17
17
import FreeFormExampleTable from './FreeFormExampleTable' ;
18
18
import { L } from 'vitest/dist/chunks/reporters.DTtkbAtP.js' ;
@@ -54,14 +54,27 @@ const Examples: FunctionComponent = () => {
54
54
const form = Form . useFormInstance ( ) ;
55
55
const [ records , setRecords ] = useState < Record < string , string > [ ] > ( [ ] ) ;
56
56
const workflowType = form . getFieldValue ( 'workflow_type' ) ;
57
- const { examples, isLoading : examplesLoading , refetch } =
58
- useGetExamplesByUseCase ( form . getFieldValue ( 'use_case' ) ) ;
57
+ // const { examples, isLoading: examplesLoading } =
58
+ // useGetExamplesByUseCase(form.getFieldValue('use_case'));
59
+ // console.log('------------------> examples', examples);
59
60
60
61
const mutation = useMutation ( {
61
62
mutationFn : fetchFileContent
62
63
} ) ;
63
64
65
+ const restore_mutation = useMutation ( {
66
+ mutationFn : fetchExamplesByUseCase
67
+ } ) ;
68
+
69
+ useEffect ( ( ) => {
70
+ console . log ( '------------------> useEffect 0' ) ;
71
+ const useCase = form . getFieldValue ( 'use_case' ) ;
72
+ restore_mutation . mutate ( useCase ) ;
73
+ } , [ form . getFieldValue ( 'use_case' ) ] ) ;
74
+
75
+
64
76
useEffect ( ( ) => {
77
+ console . log ( '------------------> useEffect 1' ) ;
65
78
const example_path = form . getFieldValue ( 'example_path' ) ;
66
79
if ( ! isEmpty ( example_path ) ) {
67
80
mutation . mutate ( {
@@ -70,21 +83,37 @@ const Examples: FunctionComponent = () => {
70
83
}
71
84
} , [ form . getFieldValue ( 'example_path' ) , form . getFieldValue ( 'workflow_type' ) ] ) ;
72
85
73
- useEffect ( ( ) => {
74
- console . log ( '------------------> useEffect' )
86
+ useEffect ( ( ) => {
87
+ console . log ( '------------------> useEffect 2' , mutation . data ) ;
75
88
if ( ! isEmpty ( mutation . data ) ) {
89
+ console . log ( '------------------> 1' ) ;
76
90
form . setFieldValue ( 'examples' , mutation . data ) ;
77
91
if ( ! isEqual ( mutation . data , records ) ) {
78
92
setRecords ( mutation . data ) ;
79
93
}
80
94
81
- } else if ( Array . isArray ( examples ) && ! isEqual ( examples , records ) ) {
95
+ }
96
+ // else if (Array.isArray(examples) && !isEqual(examples, records)) {
97
+ // console.log('------------------> 2');
98
+ // form.setFieldValue('examples', examples);
99
+ // setRecords(examples);
100
+ // }
101
+ } , [ mutation . data ] ) ;
102
+
103
+ useEffect ( ( ) => {
104
+ console . log ( '------------------> useEffect 3' , restore_mutation . data ) ;
105
+ if ( ! isEmpty ( restore_mutation . data ) ) {
106
+ const examples = get ( restore_mutation . data , 'examples' , [ ] ) ;
82
107
form . setFieldValue ( 'examples' , examples ) ;
83
108
setRecords ( examples ) ;
84
109
}
85
- } , [ mutation . data , examples ] ) ;
86
-
110
+ } , [ restore_mutation . data ] ) ;
87
111
112
+ const onRestoreDefaults = async ( ) => {
113
+ console . log ( '------------------> onRestoreDefaults' ) ;
114
+ const useCase = form . getFieldValue ( 'use_case' ) ;
115
+ restore_mutation . mutate ( useCase ) ;
116
+ }
88
117
89
118
const onAddFiles = ( files : File [ ] ) => {
90
119
if ( ! isEmpty ( files ) ) {
@@ -104,16 +133,21 @@ const Examples: FunctionComponent = () => {
104
133
span : 10
105
134
} ;
106
135
107
- const showEmptyState = workflowType === WorkflowType . FREE_FORM_DATA_GENERATION &&
136
+ const showEmptyState = ( workflowType === WorkflowType . FREE_FORM_DATA_GENERATION &&
108
137
isEmpty ( mutation . data ) &&
109
- records . length === 0 ;
138
+ records . length === 0 ) ||
139
+ ( form . getFieldValue ( 'use_case' ) === 'custom' &&
140
+ isEmpty ( form . getFieldValue ( 'examples' ) ) ) ;
110
141
111
142
console . log ( 'examples' , form . getFieldValue ( 'examples' ) ) ;
112
143
console . log ( 'records' , records ) ;
144
+ console . log ( 'use_case' , form . getFieldValue ( 'use_case' ) ) ;
145
+ console . log ( 'example_path' , form . getFieldValue ( 'example_path' ) ) ;
146
+ console . log ( 'mutation' , mutation ) ;
113
147
114
148
return (
115
149
< Container >
116
- { examplesLoading && < Loading /> }
150
+ { mutation ?. isPending || restore_mutation . isPending && < Loading /> }
117
151
< Header align = 'center' justify = 'space-between' >
118
152
< StyledTitle level = { 3 } >
119
153
< Space >
@@ -149,8 +183,8 @@ const Examples: FunctionComponent = () => {
149
183
< ModalButtonGroup gap = { 8 } justify = 'end' >
150
184
< Button onClick = { ( ) => Modal . destroyAll ( ) } > { 'Cancel' } </ Button >
151
185
< Button
152
- onClick = { ( ) => {
153
- refetch ( ) ;
186
+ onClick = { async ( ) => {
187
+ await onRestoreDefaults ( ) ;
154
188
Modal . destroyAll ( ) ;
155
189
} }
156
190
type = 'primary'
0 commit comments