Skip to content

Commit

Permalink
Remove the editor config provider registry (#56501)
Browse files Browse the repository at this point in the history
* Remove the editor_config_providers

* Remove unused translations

* Fix eslint errors

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
sulemanof and elasticmachine authored Feb 5, 2020
1 parent 2bb4673 commit 367086b
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 603 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import { Field } from 'src/plugins/data/public';
import { VisState } from 'src/legacy/core_plugins/visualizations/public';
import { IAggConfig, AggParam, EditorConfig } from '../legacy_imports';
import { IAggConfig, AggParam } from '../legacy_imports';
import { ComboBoxGroupedOptions } from '../utils';
import { EditorConfig } from './utils';

// NOTE: we cannot export the interface with export { InterfaceName }
// as there is currently a bug on babel typescript transform plugin for it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ const mockEditorConfig = {
};

jest.mock('ui/new_platform');
jest.mock('ui/vis/config', () => ({
editorConfigProviders: {
getConfigForAgg: jest.fn(() => mockEditorConfig),
},
jest.mock('./utils', () => ({
getEditorConfig: jest.fn(() => mockEditorConfig),
}));
jest.mock('./agg_params_helper', () => ({
getAggParamsToRender: jest.fn(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ import { i18n } from '@kbn/i18n';
import useUnmount from 'react-use/lib/useUnmount';

import { IndexPattern } from 'src/plugins/data/public';
import {
IAggConfig,
AggGroupNames,
editorConfigProviders,
FixedParam,
TimeIntervalParam,
EditorParamConfig,
} from '../legacy_imports';
import { IAggConfig, AggGroupNames } from '../legacy_imports';

import { DefaultEditorAggSelect } from './agg_select';
import { DefaultEditorAggParam } from './agg_param';
Expand All @@ -46,6 +39,7 @@ import {
initAggParamsState,
} from './agg_params_state';
import { DefaultEditorCommonProps } from './agg_common_props';
import { EditorParamConfig, TimeIntervalParam, FixedParam, getEditorConfig } from './utils';

const FIXED_VALUE_PROP = 'fixedValue';
const DEFAULT_PROP = 'default';
Expand Down Expand Up @@ -93,10 +87,12 @@ function DefaultEditorAggParams({
values: { schema: agg.schema.title },
})
: '';

const editorConfig = useMemo(() => editorConfigProviders.getConfigForAgg(indexPattern, agg), [
const aggTypeName = agg.type?.name;
const fieldName = agg.params?.field?.name;
const editorConfig = useMemo(() => getEditorConfig(indexPattern, aggTypeName, fieldName), [
indexPattern,
agg,
aggTypeName,
fieldName,
]);
const params = useMemo(() => getAggParamsToRender({ agg, editorConfig, metricAggs, state }), [
agg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@

import { IndexPattern, Field } from 'src/plugins/data/public';
import { VisState } from 'src/legacy/core_plugins/visualizations/public';
import {
IAggConfig,
IAggType,
AggGroupNames,
BUCKET_TYPES,
IndexedArray,
EditorConfig,
} from '../legacy_imports';
import { IAggConfig, IAggType, AggGroupNames, BUCKET_TYPES, IndexedArray } from '../legacy_imports';
import {
getAggParamsToRender,
getAggTypeOptions,
isInvalidParamsTouched,
} from './agg_params_helper';
import { FieldParamEditor, OrderByParamEditor } from './controls';
import { EditorConfig } from './utils';

jest.mock('../utils', () => ({
groupAndSortBy: jest.fn(() => ['indexedFields']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import {
AggParam,
IFieldParamType,
IAggType,
EditorConfig,
} from '../legacy_imports';
import { EditorConfig } from './utils';

interface ParamInstanceBase {
agg: IAggConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import { VisState } from 'src/legacy/core_plugins/visualizations/public';
import { IAggConfig, AggParam, EditorConfig } from '../../legacy_imports';
import { IAggConfig, AggParam } from '../../legacy_imports';
import { EditorConfig } from '../utils';

export const aggParamCommonPropsMock = {
agg: {} as IAggConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function TimeIntervalParamEditor({

const onChange = (opts: EuiComboBoxOptionProps[]) => {
const selectedOpt: ComboBoxOption = get(opts, '0');
setValue(selectedOpt ? selectedOpt.key : selectedOpt);
setValue(selectedOpt ? selectedOpt.key : '');

if (selectedOpt) {
agg.write();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { IndexPattern } from 'src/plugins/data/public';

/**
* A hidden parameter can be hidden from the UI completely.
*/
interface Param {
hidden?: boolean;
help?: string;
}

/**
* A fixed parameter has a fixed value for a specific field.
* It can optionally also be hidden.
*/
export type FixedParam = Partial<Param> & {
fixedValue: any;
};

/**
* Numeric interval parameters must always be set in the editor to a multiple of
* the specified base. It can optionally also be hidden.
*/
export type NumericIntervalParam = Partial<Param> & {
base: number;
};

/**
* Time interval parameters must always be set in the editor to a multiple of
* the specified base. It can optionally also be hidden.
*/
export type TimeIntervalParam = Partial<Param> & {
default: string;
timeBase: string;
};

export type EditorParamConfig = NumericIntervalParam | TimeIntervalParam | FixedParam | Param;

export interface EditorConfig {
[paramName: string]: EditorParamConfig;
}

export function getEditorConfig(
indexPattern: IndexPattern,
aggTypeName: string,
fieldName: string
): EditorConfig {
const aggRestrictions = indexPattern.getAggregationRestrictions();

if (!aggRestrictions || !aggTypeName || !fieldName) {
return {};
}

// Exclude certain param options for terms:
// otherBucket, missingBucket, orderBy, orderAgg
if (aggTypeName === 'terms') {
return {
otherBucket: {
hidden: true,
},
missingBucket: {
hidden: true,
},
};
}

const fieldAgg = aggRestrictions[aggTypeName] && aggRestrictions[aggTypeName][fieldName];

if (!fieldAgg) {
return {};
}

// Set interval and base interval for histograms based on agg restrictions
if (aggTypeName === 'histogram') {
const interval = fieldAgg.interval;
return interval
? {
intervalBase: {
fixedValue: interval,
},
interval: {
base: interval,
help: i18n.translate('visDefaultEditor.editorConfig.histogram.interval.helpText', {
defaultMessage: 'Must be a multiple of configuration interval: {interval}',
values: { interval },
}),
},
}
: {};
}

// Set date histogram time zone based on agg restrictions
if (aggTypeName === 'date_histogram') {
// Interval is deprecated on date_histogram rollups, but may still be present
// See https://github.com/elastic/kibana/pull/36310
const interval = fieldAgg.calendar_interval || fieldAgg.fixed_interval;
return {
useNormalizedEsInterval: {
fixedValue: false,
},
interval: {
default: interval,
timeBase: interval,
help: i18n.translate(
'visDefaultEditor.editorConfig.dateHistogram.customInterval.helpText',
{
defaultMessage: 'Must be a multiple of configuration interval: {interval}',
values: { interval },
}
),
},
};
}

return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

export { editorConfigProviders, EditorConfigProviderRegistry } from './editor_config_providers';
export * from './types';
export * from './editor_config';
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ export { getDocLink } from 'ui/documentation_links';
export { documentationLinks } from 'ui/documentation_links/documentation_links';
export { move } from 'ui/utils/collection';
export * from 'ui/vis/lib';
export * from 'ui/vis/config';
Loading

0 comments on commit 367086b

Please sign in to comment.