Skip to content

Commit fc90098

Browse files
committed
merge: merge branch 'THU/fix_dataset_wizard_form_state_PROD-14393'
2 parents 85bcd69 + 687ccb9 commit fc90098

File tree

4 files changed

+91
-19
lines changed

4 files changed

+91
-19
lines changed

cypress/e2e/brewery/DatasetManager.cy.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('Dataset manager can be empty on start', () => {
4444
describe('Data edition in dataset manager', () => {
4545
before(() => {
4646
stub.start();
47+
stub.setOrganizations([ORGANIZATION_WITH_DEFAULT_ROLE_USER]);
4748
stub.setWorkspaces(WORKSPACES);
4849
stub.setSolutions([SOLUTION_WITH_TRANSLATED_RUN_TEMPLATES]);
4950
// we use the copy of DATASETS array to be able to reuse the same fixture
@@ -116,6 +117,48 @@ describe('Data edition in dataset manager', () => {
116117
DatasetManager.getDatasetMetadataDescription().should('contain', newDescription);
117118
DatasetManager.getDatasetMetadataTag(1).should('contain', newTag);
118119
});
120+
121+
it('correctly handles the form state even after closing and reopening the dataset creation dialog', () => {
122+
DatasetManager.ignoreDatasetTwingraphQueries();
123+
DatasetManager.switchToDatasetManagerView();
124+
125+
const stepsToCheckTwice = () => {
126+
DatasetManager.startDatasetCreation();
127+
DatasetManager.setNewDatasetName('canceledDataset');
128+
DatasetManager.getDatasetCreationNextStep().click();
129+
DatasetManager.selectNewDatasetSourceType('partially_prefilled_datasource');
130+
DatasetManager.getConfirmDatasetCreation().should('be.disabled');
131+
cy.get('[data-cy=text-input-etl_string_parameter]').type('{selectAll}{backspace}' + 'foo');
132+
DatasetManager.getConfirmDatasetCreation().should('not.be.disabled');
133+
134+
DatasetManager.getNewDatasetSourceTypeSelect().click();
135+
DatasetManager.getNewDatasetSourceTypeOptionFile().click();
136+
DatasetManager.getConfirmDatasetCreation().should('be.disabled');
137+
138+
DatasetManager.selectNewDatasetSourceType('partially_prefilled_datasource');
139+
DatasetManager.getConfirmDatasetCreation().should('not.be.disabled');
140+
141+
DatasetManager.getCancelDatasetCreation().click();
142+
DatasetManager.getDatasetCreationDialog().should('not.exist');
143+
};
144+
145+
stepsToCheckTwice();
146+
stepsToCheckTwice();
147+
});
148+
149+
it('correctly handles the form state even after closing and reopening the sub-dataset creation dialog', () => {
150+
DatasetManager.ignoreDatasetTwingraphQueries();
151+
DatasetManager.switchToDatasetManagerView();
152+
153+
const stepsToCheckTwice = () => {
154+
DatasetManager.startSubdatasetCreation();
155+
DatasetManager.getDatasetCreationNextStep().should('not.be.disabled');
156+
DatasetManager.getCancelDatasetCreation().click();
157+
};
158+
159+
stepsToCheckTwice();
160+
stepsToCheckTwice();
161+
});
119162
});
120163

121164
describe('Dataset creation', () => {
@@ -296,7 +339,7 @@ describe('Refresh dataset', () => {
296339
after(stub.stop);
297340

298341
it(
299-
'can refresh ADT and AzureStorage datasets and display en empty dataset placeholder ' +
342+
'can refresh ADT and AzureStorage datasets and display an empty dataset placeholder ' +
300343
'for the one created from scratch',
301344
() => {
302345
const refreshSuccessOptions = {

cypress/fixtures/stubbing/DatasetManager/solutions.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@ export const SOLUTION = {
1717
{
1818
id: 'etl_enum_parameter',
1919
varType: 'enum',
20-
enumValues: [
21-
{ key: 'option1', value: 'Option 1' },
22-
{ key: 'option2', value: 'Option 2' },
23-
],
20+
options: {
21+
enumValues: [
22+
{ key: 'option1', value: 'Option 1' },
23+
{ key: 'option2', value: 'Option 2' },
24+
],
25+
},
2426
},
2527
{
2628
id: 'etl_list_parameter',
2729
varType: 'list',
28-
enumValues: [
29-
{ key: 'option1', value: 'Option 1' },
30-
{ key: 'option2', value: 'Option 2' },
31-
],
30+
options: {
31+
enumValues: [
32+
{ key: 'option1', value: 'Option 1' },
33+
{ key: 'option2', value: 'Option 2' },
34+
],
35+
},
3236
},
3337
{ id: 'etl_string_parameter', varType: 'string' },
38+
{ id: 'etl_string_parameter_with_default_value', varType: 'string', defaultValue: 'is prefilled' },
3439
{ id: 'etl_date_parameter', varType: 'date' },
3540
],
3641
parameterGroups: [
@@ -39,6 +44,7 @@ export const SOLUTION = {
3944
{ id: 'listGroup', parameters: ['etl_list_parameter'] },
4045
{ id: 'stringGroup', parameters: ['etl_string_parameter'] },
4146
{ id: 'dateGroup', parameters: ['etl_date_parameter'] },
47+
{ id: 'partiallyPrefilledGroup', parameters: ['etl_string_parameter', 'etl_string_parameter_with_default_value'] },
4248
],
4349
runTemplates: [...DEFAULT_SOLUTION.runTemplates, ...CUSTOM_SUBDATASOURCES],
4450
};
@@ -70,14 +76,15 @@ export const SOLUTION_WITH_DYNAMIC_VALUES = {
7076
};
7177

7278
export const SOLUTION_WITH_TRANSLATED_RUN_TEMPLATES = {
73-
...DEFAULT_SOLUTION,
79+
...SOLUTION,
7480
runTemplates: [
7581
...DEFAULT_SOLUTION.runTemplates,
7682
{
7783
id: 'etl_run_template',
7884
labels: { en: 'ETL run template with dynamic filter', fr: 'Run template avec un filtre dynamique' },
7985
tags: ['datasource'],
8086
},
87+
{ id: 'partially_prefilled_datasource', parameterGroups: ['partiallyPrefilledGroup'], tags: ['datasource'] },
8188
{
8289
id: 'subdataset_run_template',
8390
labels: {

src/views/DatasetManager/components/CreateDatasetButton/components/DatasetCreationParameters/DatasetCreationParameters.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) Cosmo Tech.
22
// Licensed under the MIT license.
3-
import React, { useEffect, useMemo, useState } from 'react';
3+
import React, { useEffect, useMemo, useRef, useState } from 'react';
44
import { Controller, useFormContext } from 'react-hook-form';
55
import { useTranslation } from 'react-i18next';
66
import PropTypes from 'prop-types';
@@ -18,7 +18,7 @@ const clone = rfdc();
1818

1919
export const DatasetCreationParameters = ({ dataSourceRunTemplates, parentDataset, selectedRunner }) => {
2020
const { t } = useTranslation();
21-
const { resetField } = useFormContext();
21+
const { getValues, resetField } = useFormContext();
2222
const organizationId = useOrganizationId();
2323
const workspaceId = useWorkspaceId();
2424
const { datasourceParameterHelpers, getDataSourceTypeEnumValues, getUploadFileLabels, getDefaultFileTypeFilter } =
@@ -40,6 +40,7 @@ export const DatasetCreationParameters = ({ dataSourceRunTemplates, parentDatase
4040
if (dataSourceType == null) setDataSourceType(defaultDataSourceTypeKey);
4141
}, [dataSourceType, setDataSourceType, defaultDataSourceTypeKey]);
4242

43+
const defaultFormState = useRef({});
4344
const sourceParameters = useMemo(() => {
4445
const forgeParameterInput = (originalParameter) => {
4546
const parameterId = originalParameter.id;
@@ -70,6 +71,7 @@ export const DatasetCreationParameters = ({ dataSourceRunTemplates, parentDatase
7071
console.error(`VarType "${inputType}" is not supported for ETL runner parameters.`);
7172
return null;
7273
}
74+
defaultFormState.current[fieldPath] = defaultValue;
7375

7476
return (
7577
<Controller
@@ -155,6 +157,7 @@ export const DatasetCreationParameters = ({ dataSourceRunTemplates, parentDatase
155157
};
156158

157159
const runTemplate = dataSourceRunTemplates[dataSourceType];
160+
defaultFormState.current = {};
158161
return runTemplate?.parameters?.map((parameter) => forgeParameterInput(parameter));
159162
}, [
160163
organizationId,
@@ -169,6 +172,25 @@ export const DatasetCreationParameters = ({ dataSourceRunTemplates, parentDatase
169172
getDefaultFileTypeFilter,
170173
]);
171174

175+
useEffect(() => {
176+
// Do not reset form when updating an existing dataset (already done in a useEffect in UpdateDatasetDialog)
177+
if (isDatasetParametersEditionDialog) return;
178+
179+
const formValues = getValues();
180+
for (const [sourceType, parameters] of Object.entries(formValues)) {
181+
// Ignore fields that are not source types
182+
if (['name', 'tags', 'description', 'sourceType'].includes(sourceType)) continue;
183+
for (const [parameterId, parameterValue] of Object.entries(parameters)) {
184+
const escapedSourceType = SolutionsUtils.escapeRunTemplateId(sourceType);
185+
const fieldPath = `${escapedSourceType}.${parameterId}`;
186+
defaultFormState.current[fieldPath] = parameterValue;
187+
}
188+
}
189+
for (const [key, defaultValue] of Object.entries(defaultFormState.current)) {
190+
resetField(key, { defaultValue });
191+
}
192+
}, [getValues, isDatasetParametersEditionDialog, resetField, sourceParameters]);
193+
172194
const labels = useMemo(() => {
173195
return isSubDatasetCreationWizard
174196
? {

src/views/DatasetManager/components/CreateDatasetButton/components/DatasetWizard/DatasetWizard.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ export const DatasetWizard = ({ open, closeDialog, onConfirm, dataSourceRunTempl
2828
const { formState } = methods;
2929
const [activeStep, setActiveStep] = useState(0);
3030

31-
useEffect(() => {
32-
if (open) {
33-
methods.reset();
34-
setActiveStep(0);
35-
}
36-
}, [open, methods, setActiveStep]);
37-
3831
const confirm = (event) => {
3932
const values = methods.getValues();
4033
onConfirm(values);
@@ -62,6 +55,13 @@ export const DatasetWizard = ({ open, closeDialog, onConfirm, dataSourceRunTempl
6255
return `${parentDataset?.name} (subdataset)`;
6356
}, [parentDataset?.name, isSubDatasetCreationWizard]);
6457

58+
useEffect(() => {
59+
if (open) {
60+
methods.reset({ name: defaultName });
61+
setActiveStep(0);
62+
}
63+
}, [defaultName, open, methods, setActiveStep]);
64+
6565
const firstStep = (
6666
<>
6767
<Grid item xs={12}>

0 commit comments

Comments
 (0)