@@ -12,7 +12,7 @@ import PCModalContent from './PCModalContent';
1212import { ExampleType , File , QuestionSolution , WorkflowType } from './types' ;
1313import FileSelectorButton from './FileSelectorButton' ;
1414
15- import { fetchFileContent , getExampleType , useGetExamplesByUseCase } from './hooks' ;
15+ import { fetchExamplesByUseCase , fetchFileContent , getExampleType , useGetExamplesByUseCase } from './hooks' ;
1616import { useState } from 'react' ;
1717import FreeFormExampleTable from './FreeFormExampleTable' ;
1818import { L } from 'vitest/dist/chunks/reporters.DTtkbAtP.js' ;
@@ -54,14 +54,27 @@ const Examples: FunctionComponent = () => {
5454 const form = Form . useFormInstance ( ) ;
5555 const [ records , setRecords ] = useState < Record < string , string > [ ] > ( [ ] ) ;
5656 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);
5960
6061 const mutation = useMutation ( {
6162 mutationFn : fetchFileContent
6263 } ) ;
6364
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+
6476 useEffect ( ( ) => {
77+ console . log ( '------------------> useEffect 1' ) ;
6578 const example_path = form . getFieldValue ( 'example_path' ) ;
6679 if ( ! isEmpty ( example_path ) ) {
6780 mutation . mutate ( {
@@ -70,21 +83,37 @@ const Examples: FunctionComponent = () => {
7083 }
7184 } , [ form . getFieldValue ( 'example_path' ) , form . getFieldValue ( 'workflow_type' ) ] ) ;
7285
73- useEffect ( ( ) => {
74- console . log ( '------------------> useEffect' )
86+ useEffect ( ( ) => {
87+ console . log ( '------------------> useEffect 2' , mutation . data ) ;
7588 if ( ! isEmpty ( mutation . data ) ) {
89+ console . log ( '------------------> 1' ) ;
7690 form . setFieldValue ( 'examples' , mutation . data ) ;
7791 if ( ! isEqual ( mutation . data , records ) ) {
7892 setRecords ( mutation . data ) ;
7993 }
8094
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' , [ ] ) ;
82107 form . setFieldValue ( 'examples' , examples ) ;
83108 setRecords ( examples ) ;
84109 }
85- } , [ mutation . data , examples ] ) ;
86-
110+ } , [ restore_mutation . data ] ) ;
87111
112+ const onRestoreDefaults = async ( ) => {
113+ console . log ( '------------------> onRestoreDefaults' ) ;
114+ const useCase = form . getFieldValue ( 'use_case' ) ;
115+ restore_mutation . mutate ( useCase ) ;
116+ }
88117
89118 const onAddFiles = ( files : File [ ] ) => {
90119 if ( ! isEmpty ( files ) ) {
@@ -104,16 +133,21 @@ const Examples: FunctionComponent = () => {
104133 span : 10
105134 } ;
106135
107- const showEmptyState = workflowType === WorkflowType . FREE_FORM_DATA_GENERATION &&
136+ const showEmptyState = ( workflowType === WorkflowType . FREE_FORM_DATA_GENERATION &&
108137 isEmpty ( mutation . data ) &&
109- records . length === 0 ;
138+ records . length === 0 ) ||
139+ ( form . getFieldValue ( 'use_case' ) === 'custom' &&
140+ isEmpty ( form . getFieldValue ( 'examples' ) ) ) ;
110141
111142 console . log ( 'examples' , form . getFieldValue ( 'examples' ) ) ;
112143 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 ) ;
113147
114148 return (
115149 < Container >
116- { examplesLoading && < Loading /> }
150+ { mutation ?. isPending || restore_mutation . isPending && < Loading /> }
117151 < Header align = 'center' justify = 'space-between' >
118152 < StyledTitle level = { 3 } >
119153 < Space >
@@ -149,8 +183,8 @@ const Examples: FunctionComponent = () => {
149183 < ModalButtonGroup gap = { 8 } justify = 'end' >
150184 < Button onClick = { ( ) => Modal . destroyAll ( ) } > { 'Cancel' } </ Button >
151185 < Button
152- onClick = { ( ) => {
153- refetch ( ) ;
186+ onClick = { async ( ) => {
187+ await onRestoreDefaults ( ) ;
154188 Modal . destroyAll ( ) ;
155189 } }
156190 type = 'primary'
0 commit comments