From 57b75c4cbe72a77262e044b7df2bf270f9d426bb Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 3 Jun 2020 18:27:17 +0200 Subject: [PATCH] [ML] fix switch between advanced editor --- .../step_define/common/filter_agg/config.ts | 16 +++++++++++++--- .../components/step_define/step_define_form.tsx | 13 ++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/config.ts b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/config.ts index 30e5d7d00d2c64..8345839a076d03 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/config.ts +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/config.ts @@ -74,11 +74,11 @@ export function getFilterAggConfig( */ export function getFilterAggTypeConfig( filterAggType: FilterAggConfigUnion['filterAgg'] | FilterAggType, - config?: { [key: string]: any } + esConfig?: { [key: string]: any } ): FilterAggConfigUnion['aggTypeConfig'] | FilterAggConfigBase['aggTypeConfig'] { switch (filterAggType) { case FILTERS.TERM: - const value = typeof config === 'object' ? Object.values(config)[0] : undefined; + const value = typeof esConfig === 'object' ? Object.values(esConfig)[0] : undefined; return { FilterAggFormComponent: FilterTermForm, @@ -101,9 +101,19 @@ export function getFilterAggTypeConfig( }, } as FilterAggConfigTerm['aggTypeConfig']; case FILTERS.RANGE: + const esFilterRange = typeof esConfig === 'object' ? Object.values(esConfig)[0] : undefined; + return { FilterAggFormComponent: FilterRangeForm, - filterAggConfig: typeof config === 'object' ? Object.values(config)[0] : undefined, + filterAggConfig: + typeof esFilterRange === 'object' + ? { + from: esFilterRange.gte ?? esFilterRange.gt, + to: esFilterRange.lte ?? esFilterRange.lt, + includeFrom: esFilterRange.gte !== undefined, + includeTo: esFilterRange.lts !== undefined, + } + : undefined, getEsAggConfig(fieldName) { if (fieldName === undefined || !this.filterAggConfig) { throw new Error(`Config ${FILTERS.RANGE} is not completed`); diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx index b7cf0ae9fb109a..e0b350542a8f8c 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx @@ -36,6 +36,7 @@ import { PivotGroupByDict, PivotGroupByConfigDict, PivotSupportedGroupByAggs, + PivotAggsConfig, } from '../../../../common'; import { useDocumentationLinks } from '../../../../hooks/use_documentation_links'; import { useIndexData } from '../../../../hooks/use_index_data'; @@ -52,7 +53,7 @@ import { SourceSearchBar } from '../source_search_bar'; import { StepDefineExposedState } from './common'; import { useStepDefineForm } from './hooks/use_step_define_form'; -import { PivotSupportedAggs } from '../../../../common/pivot_aggs'; +import { getAggConfigFromEsAgg } from '../../../../common/pivot_aggs'; export interface StepDefineFormProps { overrides?: StepDefineExposedState; @@ -153,14 +154,8 @@ export const StepDefineForm: FC = React.memo((props) => { Object.entries(pivot.aggregations).forEach((d) => { const aggName = d[0]; const aggConfig = d[1] as PivotAggDict; - const aggConfigKeys = Object.keys(aggConfig); - const agg = aggConfigKeys[0] as PivotSupportedAggs; - newAggList[aggName] = { - ...aggConfig[agg], - agg, - aggName, - dropDownName: '', - }; + + newAggList[aggName] = getAggConfigFromEsAgg(aggConfig, aggName) as PivotAggsConfig; }); } stepDefineForm.pivotConfig.actions.setAggList(newAggList);