Skip to content

Commit 6746459

Browse files
author
Keivan Vosoughi
committed
Test
1 parent c9d8f28 commit 6746459

File tree

3 files changed

+74
-40
lines changed

3 files changed

+74
-40
lines changed

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

Lines changed: 12 additions & 5 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,7 +49,14 @@ export const MODEL_TYPE_OPTIONS: ModelProvidersDropdownOpts = [
4949
{ label: MODEL_PROVIDER_LABELS[ModelProviders.CAII], value: ModelProviders.CAII },
5050
];
5151

52-
const Configure = () => {
52+
interface Props {
53+
form: FormInstance;
54+
formData: FormInstance;
55+
}
56+
57+
const Configure: FunctionComponent<Props> = ({ form, formData }) => {
58+
console.log('Configure --> form', form);
59+
console.log('Configure --> formData', formData);
5360
const location = useLocation();
5461
const { template_name, generate_file_name } = useParams();
5562
const [wizardModeType, setWizardModeType] = useState(getWizardModeType(location));
@@ -70,8 +77,8 @@ const Configure = () => {
7077
}
7178
}, [template_name]);
7279

73-
const form = Form.useFormInstance();
74-
const formData = Form.useWatch((values) => values, form);
80+
81+
// let formData = Form.useWatch((values) => values, form);
7582
const { setIsStepValid } = useWizardCtx();
7683
const { data } = useFetchModels();
7784
const [selectedFiles, setSelectedFiles] = useState(

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

Lines changed: 46 additions & 31 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-
},
9770

98-
];
9971

10072
/**
10173
* Wizard component for Synthetic Data Generation workflow
@@ -104,11 +76,21 @@ const DataGenerator: FunctionComponent<Props> = () => {
10476
const [current, setCurrent] = useState(0);
10577
const [maxStep, setMaxStep] = useState(0);
10678
const [isStepValid, setIsStepValid] = useState<boolean>(false);
79+
const [form] = Form.useForm<FormInstance>();
10780

10881
// Data passed from listing table to prepopulate form
10982
const location = useLocation();
11083
const { generate_file_name } = useParams();
111-
const initialData = location?.state?.data;
84+
const initialData = {
85+
examples: [],
86+
example_path: null,
87+
doc_paths: [],
88+
input_paths: [],
89+
num_questions: 20,
90+
topics: [],
91+
workflow_type: WorkflowType.FREE_FORM_DATA_GENERATION,
92+
};
93+
const formData = useRef(initialData || { num_questions: 20, topics: [] });
11294
const mutation = useMutation({
11395
mutationFn: fetchDatasetDetails
11496
});
@@ -146,6 +128,10 @@ const DataGenerator: FunctionComponent<Props> = () => {
146128
...initialData,
147129
...(mutation?.data?.dataset as any)
148130
});
131+
formData.current = {
132+
...initialData,
133+
...(mutation?.data?.dataset as any)
134+
};
149135
console.log('------> form', form.getFieldsValue());
150136
}
151137
}, [mutation.data]);
@@ -181,9 +167,38 @@ const DataGenerator: FunctionComponent<Props> = () => {
181167
}
182168

183169

184-
const formData = useRef(initialData || { num_questions: 20, topics: [] });
185170

186-
const [form] = Form.useForm<FormInstance>();
171+
172+
173+
const steps: WizardStepConfig[] = [
174+
{
175+
title: 'Configure',
176+
key: DataGenWizardSteps.CONFIGURE,
177+
content: <Configure form={form} formData={formData}/>,
178+
required: true,
179+
},
180+
{
181+
title: 'Examples',
182+
key: DataGenWizardSteps.EXAMPLES,
183+
content: <Examples form={form} formData={formData} />
184+
},
185+
{
186+
title: 'Prompt',
187+
key: DataGenWizardSteps.PROMPT,
188+
content: <Prompt form={form} formData={formData}/>,
189+
},
190+
{
191+
title: 'Summary',
192+
key: DataGenWizardSteps.SUMMARY,
193+
content: <Summary/>
194+
},
195+
{
196+
title: 'Finish',
197+
key: DataGenWizardSteps.FINISH,
198+
content: <Finish/>
199+
},
200+
201+
];
187202

188203
const onStepChange = (value: number) => {
189204
setCurrent(value);

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,20 @@ const StyledContainer = styled.div`
5050
5151
`;
5252

53-
54-
const Examples: FunctionComponent = () => {
55-
const form = Form.useFormInstance();
56-
const { template_name, generate_file_name } = useParams();
53+
interface Props {
54+
form: FormInstance;
55+
formData: FormInstance;
56+
}
57+
58+
const Examples: FunctionComponent<Props> = ({ form, formData }) => {
59+
console.log('Examples --> form', form);
60+
console.log('Examples --> formData', formData);
61+
const { generate_file_name } = useParams();
5762
const [records, setRecords] = useState<Record<string, string>[]>([]);
5863
const workflowType = form.getFieldValue('workflow_type');
5964

6065
console.log('Examples >>> form:', form.getFieldsValue());
66+
console.log('examples:', form.getFieldValue('examples'));
6167

6268
const mutation = useMutation({
6369
mutationFn: fetchFileContent
@@ -99,6 +105,12 @@ const Examples: FunctionComponent = () => {
99105
setRecords(examples);
100106
}
101107
}, [restore_mutation.data]);
108+
109+
useEffect(() => {
110+
if (generate_file_name) {
111+
setRecords(form.getFieldValue('examples'));
112+
}
113+
}, [generate_file_name]);
102114

103115
const onRestoreDefaults = async() => {
104116
const useCase = form.getFieldValue('use_case');

0 commit comments

Comments
 (0)