Skip to content

Commit

Permalink
[ML] Transform: Fix advanced editor initialization. (#59006) (#59114)
Browse files Browse the repository at this point in the history
Fixes regression introduced by #58015 to correctly initialize the transform wizard advanced editor with the current configuration.
  • Loading branch information
walterra authored Mar 3, 2020
1 parent c251f2f commit 5a41051
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ export const StepDefineForm: FC<Props> = React.memo(({ overrides = {}, onChange
xJson: advancedEditorConfig,
} = useXJsonMode(stringifiedPivotConfig);

useEffect(() => {
setAdvancedEditorConfig(stringifiedPivotConfig);
}, [setAdvancedEditorConfig, stringifiedPivotConfig]);

// source config
const stringifiedSourceConfig = JSON.stringify(previewRequest.source.query, null, 2);
const [
Expand Down Expand Up @@ -797,6 +801,7 @@ export const StepDefineForm: FC<Props> = React.memo(({ overrides = {}, onChange
>
<EuiPanel grow={false} paddingSize="none">
<EuiCodeEditor
data-test-subj="transformAdvancedPivotEditor"
mode={xJsonMode}
width="100%"
value={advancedEditorConfig}
Expand Down
29 changes: 29 additions & 0 deletions x-pack/test/functional/apps/transform/creation_index_pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ export default function({ getService }: FtrProviderContext) {
return `user-${this.transformId}`;
},
expected: {
pivotAdvancedEditorValue: {
group_by: {
'category.keyword': {
terms: {
field: 'category.keyword',
},
},
order_date: {
date_histogram: {
field: 'order_date',
calendar_interval: '1m',
},
},
},
aggregations: {
'products.base_price.avg': {
avg: {
field: 'products.base_price',
},
},
},
},
pivotPreview: {
column: 0,
values: [`Men's Accessories`],
Expand Down Expand Up @@ -152,6 +174,13 @@ export default function({ getService }: FtrProviderContext) {
await transform.wizard.assertAdvancedPivotEditorSwitchCheckState(false);
});

it('displays the advanced configuration', async () => {
await transform.wizard.enabledAdvancedPivotEditor();
await transform.wizard.assertAdvancedPivotEditorContent(
testData.expected.pivotAdvancedEditorValue
);
});

it('loads the pivot preview', async () => {
await transform.wizard.assertPivotPreviewLoaded();
});
Expand Down
14 changes: 14 additions & 0 deletions x-pack/test/functional/services/transform_ui/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export function TransformWizardProvider({ getService }: FtrProviderContext) {
const aceEditor = getService('aceEditor');
const testSubjects = getService('testSubjects');
const comboBox = getService('comboBox');
const retry = getService('retry');
Expand Down Expand Up @@ -273,6 +274,12 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) {
await this.assertAggregationEntryExists(index, expectedLabel);
},

async assertAdvancedPivotEditorContent(expectedValue: Record<string, any>) {
const advancedEditorString = await aceEditor.getValue('transformAdvancedPivotEditor');
const advancedEditorValue = JSON.parse(advancedEditorString);
expect(advancedEditorValue).to.eql(expectedValue);
},

async assertAdvancedPivotEditorSwitchExists() {
await testSubjects.existOrFail(`transformAdvancedPivotEditorSwitch`, { allowHidden: true });
},
Expand All @@ -287,6 +294,13 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) {
);
},

async enabledAdvancedPivotEditor() {
await this.assertAdvancedPivotEditorSwitchCheckState(false);
await testSubjects.click('transformAdvancedPivotEditorSwitch');
await this.assertAdvancedPivotEditorSwitchCheckState(true);
await testSubjects.existOrFail('transformAdvancedPivotEditor');
},

async assertTransformIdInputExists() {
await testSubjects.existOrFail('transformIdInput');
},
Expand Down

0 comments on commit 5a41051

Please sign in to comment.