Skip to content

Commit

Permalink
[ML] fix switch between advanced editor
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Jun 3, 2020
1 parent 66308fa commit 57b75c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -153,14 +154,8 @@ export const StepDefineForm: FC<StepDefineFormProps> = 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);
Expand Down

0 comments on commit 57b75c4

Please sign in to comment.