Skip to content

Commit

Permalink
Move src/legacy/utils/kbn_field_types to data plugin (#46565) (#46695)
Browse files Browse the repository at this point in the history
* Move `src/legacy/utils/kbn_field_types` to data plugin

Fix: #44186

* fix CI
  • Loading branch information
alexwizp authored Sep 26, 2019
1 parent 56e2955 commit 32efbf1
Show file tree
Hide file tree
Showing 50 changed files with 487 additions and 363 deletions.
2 changes: 1 addition & 1 deletion src/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { castEsToKbnFieldTypeName } from '../legacy/utils';
import { castEsToKbnFieldTypeName } from '../plugins/data/common';
// eslint-disable-next-line max-len
import { shouldReadFieldFromDocValues } from '../legacy/server/index_patterns/service/lib/field_capabilities/should_read_field_from_doc_values';

Expand Down
5 changes: 3 additions & 2 deletions src/fixtures/stubbed_logstash_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import TestUtilsStubIndexPatternProvider from 'test_utils/stub_index_pattern';
import stubbedLogstashFields from 'fixtures/logstash_fields';
import { getKbnFieldType } from '../legacy/utils';

import { getKbnFieldType } from '../plugins/data/common';

export default function stubbedLogstashIndexPatternService(Private) {
const StubIndexPattern = Private(TestUtilsStubIndexPatternProvider);
Expand All @@ -28,7 +29,7 @@ export default function stubbedLogstashIndexPatternService(Private) {
const fields = mockLogstashFields.map(function (field) {
const kbnType = getKbnFieldType(field.type);

if (kbnType.name === 'unknown') {
if (!kbnType || kbnType.name === 'unknown') {
throw new TypeError(`unknown type ${field.type}`);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import { i18n } from '@kbn/i18n';
// @ts-ignore
import { ObjDefine } from './obj_define';
// @ts-ignore
import { getKbnFieldType } from '../../../../../utils/kbn_field_types';
// @ts-ignore
import { FieldFormat } from '../../../../../../plugins/data/common/field_formats';
// @ts-ignore
import { shortenDottedString } from '../../../../../core_plugins/kibana/common/utils/shorten_dotted_string';
import { IndexPattern } from '../index_patterns';

import { getKbnFieldType } from '../../../../../../plugins/data/public';

export type FieldSpec = Record<string, any>;
export interface FieldType {
name: string;
Expand Down Expand Up @@ -127,9 +127,9 @@ export class Field implements FieldType {
const searchable = !!spec.searchable || scripted;
const aggregatable = !!spec.aggregatable || scripted;
const readFromDocValues = !!spec.readFromDocValues && !scripted;
const sortable = spec.name === '_score' || ((indexed || aggregatable) && type.sortable);
const sortable = spec.name === '_score' || ((indexed || aggregatable) && type && type.sortable);
const filterable =
spec.name === '_id' || scripted || ((indexed || searchable) && type.filterable);
spec.name === '_id' || scripted || ((indexed || searchable) && type && type.filterable);
const visualizable = aggregatable;

this.name = '';
Expand Down
11 changes: 4 additions & 7 deletions src/legacy/core_plugins/data/public/index_patterns/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
* under the License.
*/

// @ts-ignore
import { get } from 'lodash';
// @ts-ignore
import { KBN_FIELD_TYPES } from '../../../../utils/kbn_field_types';

import { Field, FieldType } from './fields';
import { StaticIndexPattern } from './index_patterns';
import { getFilterableKbnTypeNames } from '../../../../../plugins/data/public';

export const ILLEGAL_CHARACTERS = 'ILLEGAL_CHARACTERS';
export const CONTAINS_SPACES = 'CONTAINS_SPACES';
Expand Down Expand Up @@ -65,15 +64,13 @@ export function validateIndexPattern(indexPattern: string) {
return errors;
}

const filterableTypes = KBN_FIELD_TYPES.filter((type: any) => type.filterable).map(
(type: any) => type.name
);
const filterableTypes = getFilterableKbnTypeNames();

export function isFilterable(field: Field): boolean {
return (
field.name === '_id' ||
field.scripted ||
(field.searchable && filterableTypes.includes(field.type))
Boolean(field.searchable && filterableTypes.includes(field.type))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
import { fatalError, toastNotifications } from 'ui/notify';
import 'ui/accessibility/kbn_ui_ace_keyboard_mode';
import { castEsToKbnFieldTypeName } from '../../../../../../../legacy/utils';
import { SavedObjectsClientProvider } from 'ui/saved_objects';
import { isNumeric } from 'ui/utils/numeric';
import { canViewInApp } from './lib/in_app_url';

import { castEsToKbnFieldTypeName } from '../../../../../../../plugins/data/public';

import { getViewBreadcrumbs } from './breadcrumbs';

const location = 'SavedObject view';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
EuiFormRow,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { ES_TYPES } from '../../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../../plugins/data/common';
import { METRIC_TYPES } from '../../../common/metric_types';

export const FilterRatioAgg = props => {
Expand All @@ -56,7 +56,7 @@ export const FilterRatioAgg = props => {
const model = { ...defaults, ...props.model };
const htmlId = htmlIdGenerator();

const restrictFields = model.metric_agg === METRIC_TYPES.CARDINALITY ? [] : [ES_TYPES.NUMBER];
const restrictFields = model.metric_agg === METRIC_TYPES.CARDINALITY ? [] : [ES_FIELD_TYPES.NUMBER];

return (
<AggRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import {
EuiFormRow,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { ES_TYPES } from '../../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../../plugins/data/common';
import { Percentiles, newPercentile } from './percentile_ui';

const RESTRICT_FIELDS = [ES_TYPES.NUMBER];
const RESTRICT_FIELDS = [ES_FIELD_TYPES.NUMBER];

export class PercentileAgg extends Component {
// eslint-disable-line react/no-multi-comp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import {
EuiSpacer,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { ES_TYPES } from '../../../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../../../plugins/data/common';

const RESTRICT_FIELDS = [ES_TYPES.NUMBER];
const RESTRICT_FIELDS = [ES_FIELD_TYPES.NUMBER];

export const PercentileRankAgg = props => {
const { series, panel, fields } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ import {
EuiSpacer,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { ES_TYPES } from '../../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../../plugins/data/common';
import { METRIC_TYPES } from '../../../common/metric_types';

export function StandardAgg(props) {
const { model, panel, series, fields, uiRestrictions } = props;
const handleChange = createChangeHandler(props.onChange, model);
const handleSelectChange = createSelectHandler(handleChange);
const restrictFields = model.type === METRIC_TYPES.CARDINALITY ? [] : [ES_TYPES.NUMBER];
const restrictFields = model.type === METRIC_TYPES.CARDINALITY ? [] : [ES_FIELD_TYPES.NUMBER];

const indexPattern =
(series.override_index_pattern && series.series_index_pattern) || panel.index_pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import {
EuiSpacer,
} from '@elastic/eui';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { ES_TYPES } from '../../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../../plugins/data/common';

const RESTRICT_FIELDS = [ES_TYPES.NUMBER];
const RESTRICT_FIELDS = [ES_FIELD_TYPES.NUMBER];

const StandardDeviationAggUi = props => {
const { series, panel, fields, intl } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
EuiFormRow,
} from '@elastic/eui';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { ES_TYPES } from '../../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../../plugins/data/common';
import { PANEL_TYPES } from '../../../common/panel_types';

const isFieldTypeEnabled = (fieldRestrictions, fieldType) =>
Expand All @@ -44,7 +44,7 @@ const isFieldTypeEnabled = (fieldRestrictions, fieldType) =>
const getAggWithOptions = (field = {}, fieldTypesRestriction) => {
if (isFieldTypeEnabled(fieldTypesRestriction, field.type)) {
switch (field.type) {
case ES_TYPES.NUMBER:
case ES_FIELD_TYPES.NUMBER:
return [
{
label: i18n.translate('visTypeTimeseries.topHit.aggWithOptions.averageLabel', {
Expand All @@ -71,8 +71,8 @@ const getAggWithOptions = (field = {}, fieldTypesRestriction) => {
value: 'sum',
},
];
case ES_TYPES.KEYWORD:
case ES_TYPES.STRING:
case ES_FIELD_TYPES.KEYWORD:
case ES_FIELD_TYPES.STRING:
return [
{
label: i18n.translate('visTypeTimeseries.topHit.aggWithOptions.concatenate', {
Expand Down Expand Up @@ -102,7 +102,7 @@ const getOrderOptions = () => [
},
];

const ORDER_DATE_RESTRICT_FIELDS = [ES_TYPES.DATE];
const ORDER_DATE_RESTRICT_FIELDS = [ES_FIELD_TYPES.DATE];

const TopHitAggUi = props => {
const { fields, series, panel } = props;
Expand All @@ -120,8 +120,8 @@ const TopHitAggUi = props => {
PANEL_TYPES.METRIC,
PANEL_TYPES.MARKDOWN,
].includes(panel.type)
? [ES_TYPES.NUMBER, ES_TYPES.KEYWORD, ES_TYPES.STRING]
: [ES_TYPES.NUMBER];
? [ES_FIELD_TYPES.NUMBER, ES_FIELD_TYPES.KEYWORD, ES_FIELD_TYPES.STRING]
: [ES_FIELD_TYPES.NUMBER];

const handleChange = createChangeHandler(props.onChange, model);
const handleSelectChange = createSelectHandler(handleChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import _ from 'lodash';
import { collectionActions } from './lib/collection_actions';
import { ES_TYPES } from '../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../plugins/data/public';
import { AddDeleteButtons } from './add_delete_buttons';
import { ColorPicker } from './color_picker';
import { FieldSelect } from './aggs/field_select';
Expand Down Expand Up @@ -57,7 +57,7 @@ function newAnnotation() {
};
}

const RESTRICT_FIELDS = [ES_TYPES.DATE];
const RESTRICT_FIELDS = [ES_FIELD_TYPES.DATE];

export class AnnotationsEditor extends Component {
constructor(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { FieldSelect } from './aggs/field_select';
import { createSelectHandler } from './lib/create_select_handler';
import { createTextHandler } from './lib/create_text_handler';
import { YesNo } from './yes_no';
import { ES_TYPES } from '../../common/es_types';
import { ES_FIELD_TYPES } from '../../../../../plugins/data/public';
import { FormValidationContext } from '../contexts/form_validation_context';
import {
isGteInterval,
Expand All @@ -47,7 +47,7 @@ import { PANEL_TYPES } from '../../common/panel_types';
import { isTimerangeModeEnabled } from '../lib/check_ui_restrictions';
import { VisDataContext } from '../contexts/vis_data_context';

const RESTRICT_FIELDS = [ES_TYPES.DATE];
const RESTRICT_FIELDS = [ES_FIELD_TYPES.DATE];

const validateIntervalValue = intervalValue => {
const isAutoOrGteInterval = isGteInterval(intervalValue) || isAutoInterval(intervalValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import sinon from 'sinon';
import * as shouldReadFieldFromDocValuesNS from './should_read_field_from_doc_values';
import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values';

import { getKbnFieldType } from '../../../../../utils';
import { getKbnFieldType } from '../../../../../../plugins/data/common';
import { readFieldCapsResponse } from './field_caps_response';
import esResponse from './__fixtures__/es_field_caps_response.json';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

import { uniq } from 'lodash';
import { castEsToKbnFieldTypeName } from '../../../../../utils';
import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values';
import { FieldDescriptor } from '../..';
import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values';
import { castEsToKbnFieldTypeName } from '../../../../../../plugins/data/common';

interface FieldCapObject {
type: string;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/legacy/ui/public/field_editor/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { getKbnTypeNames } from '../../../../utils';
import { getKbnTypeNames } from '../../../../../plugins/data/public';

export const FIELD_TYPES_BY_LANG = {
painless: ['number', 'string', 'date', 'boolean'],
Expand Down
Loading

0 comments on commit 32efbf1

Please sign in to comment.