Skip to content

Commit 17d811b

Browse files
authored
Merge pull request #104 from cloudera/regenerate-issues
Fix Regenerate Issues
2 parents 7331eef + 3e1568d commit 17d811b

File tree

7 files changed

+73
-51
lines changed

7 files changed

+73
-51
lines changed

app/client/src/pages/DataGenerator/Configure.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import endsWith from 'lodash/endsWith';
22
import isEmpty from 'lodash/isEmpty';
33
import isFunction from 'lodash/isFunction';
4-
import { useEffect, useState } from 'react';
5-
import { Flex, Form, Input, Select, Typography } from 'antd';
4+
import { FunctionComponent, useEffect, useState } from 'react';
5+
import { Flex, Form, FormInstance, Input, Select, Typography } from 'antd';
66
import styled from 'styled-components';
77
import { File, WorkflowType } from './types';
88
import { useFetchModels } from '../../api/api';
@@ -49,18 +49,20 @@ export const MODEL_TYPE_OPTIONS: ModelProvidersDropdownOpts = [
4949
{ label: MODEL_PROVIDER_LABELS[ModelProviders.CAII], value: ModelProviders.CAII },
5050
];
5151

52-
const Configure = () => {
52+
const Configure: FunctionComponent = () => {
53+
const form = Form.useFormInstance();
54+
const formData = Form.useWatch((values) => values, form);
5355
const location = useLocation();
5456
const { template_name, generate_file_name } = useParams();
5557
const [wizardModeType, setWizardModeType] = useState(getWizardModeType(location));
5658

5759
useEffect(() => {
5860
if (wizardModeType === WizardModeType.DATA_AUGMENTATION) {
5961
setWizardModeType(WizardModeType.DATA_AUGMENTATION);
60-
form.setFieldValue('workflow_type', 'custom');
62+
form.setFieldValue('workflow_type', 'freeform');
6163
} else {
6264
setWizardModeType(WizardModeType.DATA_GENERATION);
63-
form.setFieldValue('workflow_type', 'freeform');
65+
form.setFieldValue('workflow_type', 'custom');
6466
}
6567
}, [location, wizardModeType]);
6668

@@ -70,8 +72,8 @@ const Configure = () => {
7072
}
7173
}, [template_name]);
7274

73-
const form = Form.useFormInstance();
74-
const formData = Form.useWatch((values) => values, form);
75+
76+
// let formData = Form.useWatch((values) => values, form);
7577
const { setIsStepValid } = useWizardCtx();
7678
const { data } = useFetchModels();
7779
const [selectedFiles, setSelectedFiles] = useState(

app/client/src/pages/DataGenerator/DataGenerator.tsx

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,7 @@ const WizardFooter = styled(Flex)`
6767
6868
`;
6969

70-
const steps: WizardStepConfig[] = [
71-
{
72-
title: 'Configure',
73-
key: DataGenWizardSteps.CONFIGURE,
74-
content: <Configure/>,
75-
required: true,
76-
},
77-
{
78-
title: 'Examples',
79-
key: DataGenWizardSteps.EXAMPLES,
80-
content: <Examples/>
81-
},
82-
{
83-
title: 'Prompt',
84-
key: DataGenWizardSteps.PROMPT,
85-
content: <Prompt/>,
86-
},
87-
{
88-
title: 'Summary',
89-
key: DataGenWizardSteps.SUMMARY,
90-
content: <Summary/>
91-
},
92-
{
93-
title: 'Finish',
94-
key: DataGenWizardSteps.FINISH,
95-
content: <Finish/>
96-
},
97-
98-
];
70+
9971

10072
/**
10173
* Wizard component for Synthetic Data Generation workflow
@@ -105,10 +77,12 @@ const DataGenerator: FunctionComponent<Props> = () => {
10577
const [maxStep, setMaxStep] = useState(0);
10678
const [isStepValid, setIsStepValid] = useState<boolean>(false);
10779

80+
10881
// Data passed from listing table to prepopulate form
10982
const location = useLocation();
11083
const { generate_file_name } = useParams();
11184
const initialData = location?.state?.data;
85+
11286
const mutation = useMutation({
11387
mutationFn: fetchDatasetDetails
11488
});
@@ -118,14 +92,21 @@ const DataGenerator: FunctionComponent<Props> = () => {
11892
if (generate_file_name && !mutation.data) {
11993
mutation.mutate(generate_file_name);
12094
}
95+
}, [generate_file_name]);
96+
97+
useEffect(() => {
12198
if (mutation.data && mutation?.data?.dataset) {
122-
form.setFieldsValue({
99+
const dataset = mutation?.data?.dataset as any;
100+
const values = {
123101
...initialData,
124-
...(mutation?.data?.dataset as any)
125-
});
102+
...dataset,
103+
workflow_type: dataset.technique === 'freeform' ?
104+
WorkflowType.FREE_FORM_DATA_GENERATION : WorkflowType.CUSTOM_DATA_GENERATION
105+
}
106+
form.setFieldsValue(values);
107+
formData.current = values;
126108
}
127-
128-
}, [generate_file_name]);
109+
}, [mutation.data]);
129110

130111

131112
if (initialData?.technique) {
@@ -157,11 +138,43 @@ const DataGenerator: FunctionComponent<Props> = () => {
157138
initialData.doc_paths = [];
158139
}
159140

160-
161141
const formData = useRef(initialData || { num_questions: 20, topics: [] });
162142

163143
const [form] = Form.useForm<FormInstance>();
164144

145+
146+
147+
148+
const steps: WizardStepConfig[] = [
149+
{
150+
title: 'Configure',
151+
key: DataGenWizardSteps.CONFIGURE,
152+
content: <Configure />,
153+
required: true,
154+
},
155+
{
156+
title: 'Examples',
157+
key: DataGenWizardSteps.EXAMPLES,
158+
content: <Examples />
159+
},
160+
{
161+
title: 'Prompt',
162+
key: DataGenWizardSteps.PROMPT,
163+
content: <Prompt />,
164+
},
165+
{
166+
title: 'Summary',
167+
key: DataGenWizardSteps.SUMMARY,
168+
content: <Summary/>
169+
},
170+
{
171+
title: 'Finish',
172+
key: DataGenWizardSteps.FINISH,
173+
content: <Finish/>
174+
},
175+
176+
];
177+
165178
const onStepChange = (value: number) => {
166179
setCurrent(value);
167180
};
@@ -173,7 +186,7 @@ const DataGenerator: FunctionComponent<Props> = () => {
173186
}
174187
};
175188

176-
const prev = () => setCurrent(Math.max(0, current - 1))
189+
const prev = () => setCurrent(Math.max(0, current - 1));
177190

178191
return (
179192
<WizardCtx.Provider value={{ setIsStepValid }}>

app/client/src/pages/DataGenerator/Examples.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import FreeFormExampleTable from './FreeFormExampleTable';
1818
import { L } from 'vitest/dist/chunks/reporters.DTtkbAtP.js';
1919
import Loading from '../Evaluator/Loading';
2020
import { isEqual, set } from 'lodash';
21+
import { useParams } from 'react-router-dom';
2122

2223
const { Title, Text } = Typography;
2324
const Container = styled.div`
@@ -52,6 +53,7 @@ const StyledContainer = styled.div`
5253

5354
const Examples: FunctionComponent = () => {
5455
const form = Form.useFormInstance();
56+
const { generate_file_name } = useParams();
5557
const [records, setRecords] = useState<Record<string, string>[]>([]);
5658
const workflowType = form.getFieldValue('workflow_type');
5759

@@ -64,9 +66,13 @@ const Examples: FunctionComponent = () => {
6466
});
6567

6668
useEffect(() => {
67-
const useCase = form.getFieldValue('use_case');
68-
restore_mutation.mutate(useCase);
69-
}, [form.getFieldValue('use_case')]);
69+
if (isEmpty(generate_file_name)) {
70+
const useCase = form.getFieldValue('use_case');
71+
restore_mutation.mutate(useCase);
72+
} else {
73+
setRecords(form.getFieldValue('examples'));
74+
}
75+
}, [form.getFieldValue('use_case'), generate_file_name]);
7076

7177

7278
useEffect(() => {
@@ -95,6 +101,12 @@ const Examples: FunctionComponent = () => {
95101
setRecords(examples);
96102
}
97103
}, [restore_mutation.data]);
104+
105+
useEffect(() => {
106+
if (generate_file_name) {
107+
setRecords(form.getFieldValue('examples'));
108+
}
109+
}, [generate_file_name]);
98110

99111
const onRestoreDefaults = async() => {
100112
const useCase = form.getFieldValue('use_case');

app/client/src/pages/DataGenerator/Prompt.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ const Prompt = () => {
226226
}
227227
};
228228
}
229-
console.log('mutation data:', mutation);
230229

231230
return (
232231
<Row gutter={[50,0]}>

app/client/src/pages/DataGenerator/UseCaseSelector.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const UseCaseSelector: FunctionComponent<Props> = ({ form }) => {
2626
}, [useCasesReq.data]);
2727

2828
const onChange = (value: string) => {
29-
console.log('value', value);
3029
form.setFieldValue('use_case', value);
3130
if (value !== 'custom') {
3231
form.setFieldValue('example_path', null);

app/client/src/pages/DataGenerator/hooks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ export const fetchExamplesByUseCase = async (use_case: string) => {
280280
}
281281

282282
export const useGetExamplesByUseCase = (use_case: string) => {
283-
console.log('------------------> useGetExamplesByUseCase', use_case);
284283
const { data, isLoading, isError, error, isFetching, refetch } = useQuery(
285284
{
286285
queryKey: ['fetchUseCaseTopics', fetchExamplesByUseCase],

app/client/src/pages/Home/TemplatesSection.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ const StyledContainer = styled.div`
2828

2929
const TemplatesSection: React.FC = () => {
3030
const useCasesReq = useGetUseCases();
31-
console.log("useCasesReq", useCasesReq);
3231
if (useCasesReq.isLoading) {
3332
return <Container><Loading /></Container>;
3433
}
3534

3635
const useCases: Template[] = get(useCasesReq, 'data.usecases', []);
37-
console.log("useCases", useCases);
3836

3937

4038
return (

0 commit comments

Comments
 (0)