mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ML] Update to use some shared common functions between ml and transform
This commit is contained in:
parent
54b62f827e
commit
ce813f012d
29 changed files with 66 additions and 107 deletions
|
@ -11,5 +11,6 @@ export { ANOMALY_SEVERITY, ANOMALY_THRESHOLD, SEVERITY_COLORS } from './constant
|
||||||
export { getSeverityColor, getSeverityType } from './util/anomaly_utils';
|
export { getSeverityColor, getSeverityType } from './util/anomaly_utils';
|
||||||
export { composeValidators, patternValidator } from './util/validators';
|
export { composeValidators, patternValidator } from './util/validators';
|
||||||
export { isRuntimeMappings, isRuntimeField } from './util/runtime_field_utils';
|
export { isRuntimeMappings, isRuntimeField } from './util/runtime_field_utils';
|
||||||
|
export { isPopulatedObject } from './util/object_utils';
|
||||||
export { extractErrorMessage } from './util/errors';
|
export { extractErrorMessage } from './util/errors';
|
||||||
export type { RuntimeMappings } from './types/fields';
|
export type { RuntimeMappings } from './types/fields';
|
||||||
|
|
18
x-pack/plugins/ml/common/util/object_utils.test.ts
Normal file
18
x-pack/plugins/ml/common/util/object_utils.test.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||||
|
* 2.0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { isPopulatedObject } from './object_utils';
|
||||||
|
|
||||||
|
describe('object_utils', () => {
|
||||||
|
test('isPopulatedObject()', () => {
|
||||||
|
expect(isPopulatedObject(0)).toBe(false);
|
||||||
|
expect(isPopulatedObject('')).toBe(false);
|
||||||
|
expect(isPopulatedObject(null)).toBe(false);
|
||||||
|
expect(isPopulatedObject({})).toBe(false);
|
||||||
|
expect(isPopulatedObject({ attribute: 'value' })).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import { isRuntimeField, isRuntimeMappings } from './runtime_field_utils';
|
import { isRuntimeField, isRuntimeMappings } from './runtime_field_utils';
|
||||||
|
|
||||||
describe('Transform: step_define type guards', () => {
|
describe('runtime_field_utiles', () => {
|
||||||
it('isRuntimeField()', () => {
|
it('isRuntimeField()', () => {
|
||||||
expect(isRuntimeField(1)).toBe(false);
|
expect(isRuntimeField(1)).toBe(false);
|
||||||
expect(isRuntimeField(null)).toBe(false);
|
expect(isRuntimeField(null)).toBe(false);
|
||||||
|
|
|
@ -7,10 +7,7 @@
|
||||||
|
|
||||||
import { estypes } from '@elastic/elasticsearch';
|
import { estypes } from '@elastic/elasticsearch';
|
||||||
import { isPopulatedObject } from './object_utils';
|
import { isPopulatedObject } from './object_utils';
|
||||||
import {
|
import { RUNTIME_FIELD_TYPES } from '../../../../../src/plugins/data/common';
|
||||||
RUNTIME_FIELD_TYPES,
|
|
||||||
RuntimeType,
|
|
||||||
} from '../../../../../src/plugins/data/common/index_patterns';
|
|
||||||
import type { RuntimeMappings } from '../types/fields';
|
import type { RuntimeMappings } from '../types/fields';
|
||||||
|
|
||||||
export function isRuntimeField(arg: unknown): arg is estypes.RuntimeField {
|
export function isRuntimeField(arg: unknown): arg is estypes.RuntimeField {
|
||||||
|
@ -25,7 +22,7 @@ export function isRuntimeField(arg: unknown): arg is estypes.RuntimeField {
|
||||||
Object.keys(arg.script).length === 1 &&
|
Object.keys(arg.script).length === 1 &&
|
||||||
arg.script.hasOwnProperty('source') &&
|
arg.script.hasOwnProperty('source') &&
|
||||||
typeof arg.script.source === 'string')))) &&
|
typeof arg.script.source === 'string')))) &&
|
||||||
RUNTIME_FIELD_TYPES.includes(arg.type as RuntimeType)
|
RUNTIME_FIELD_TYPES.includes(arg.type)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import { schema, TypeOf } from '@kbn/config-schema';
|
import { schema, TypeOf } from '@kbn/config-schema';
|
||||||
|
|
||||||
import { TRANSFORM_STATE } from '../constants';
|
import { TRANSFORM_STATE } from '../constants';
|
||||||
|
import { isRuntimeField } from '../shared_imports';
|
||||||
|
|
||||||
export const transformIdsSchema = schema.arrayOf(
|
export const transformIdsSchema = schema.arrayOf(
|
||||||
schema.object({
|
schema.object({
|
||||||
|
@ -55,25 +56,15 @@ export interface CommonResponseStatusSchema {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const runtimeMappingsSchema = schema.maybe(
|
export const runtimeMappingsSchema = schema.maybe(
|
||||||
schema.recordOf(
|
schema.object(
|
||||||
schema.string(),
|
{},
|
||||||
schema.object({
|
{
|
||||||
type: schema.oneOf([
|
unknowns: 'allow',
|
||||||
schema.literal('keyword'),
|
validate: (v: object) => {
|
||||||
schema.literal('long'),
|
if (Object.values(v).some((o) => !isRuntimeField(o))) {
|
||||||
schema.literal('double'),
|
return 'Invalid runtime field';
|
||||||
schema.literal('date'),
|
}
|
||||||
schema.literal('ip'),
|
},
|
||||||
schema.literal('boolean'),
|
}
|
||||||
]),
|
|
||||||
script: schema.maybe(
|
|
||||||
schema.oneOf([
|
|
||||||
schema.string(),
|
|
||||||
schema.object({
|
|
||||||
source: schema.string(),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
),
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { SearchResponse7 } from '../../../ml/common';
|
import type { SearchResponse7 } from '../../../ml/common';
|
||||||
|
|
||||||
import type { EsIndex } from '../types/es_index';
|
import type { EsIndex } from '../types/es_index';
|
||||||
import { isPopulatedObject } from '../utils/object_utils';
|
import { isPopulatedObject } from '../../common/shared_imports';
|
||||||
|
|
||||||
// To be able to use the type guards on the client side, we need to make sure we don't import
|
// To be able to use the type guards on the client side, we need to make sure we don't import
|
||||||
// the code of '@kbn/config-schema' but just its types, otherwise the client side code will
|
// the code of '@kbn/config-schema' but just its types, otherwise the client side code will
|
||||||
|
|
|
@ -11,4 +11,8 @@ export {
|
||||||
patternValidator,
|
patternValidator,
|
||||||
ChartData,
|
ChartData,
|
||||||
HITS_TOTAL_RELATION,
|
HITS_TOTAL_RELATION,
|
||||||
|
isPopulatedObject,
|
||||||
|
isRuntimeMappings,
|
||||||
|
isRuntimeField,
|
||||||
|
RuntimeMappings,
|
||||||
} from '../../ml/common';
|
} from '../../ml/common';
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { IndexPattern } from '../../../../../src/plugins/data/common';
|
import type { IndexPattern } from '../../../../../src/plugins/data/common';
|
||||||
|
import { isPopulatedObject } from '../shared_imports';
|
||||||
import { isPopulatedObject } from '../utils/object_utils';
|
|
||||||
|
|
||||||
// Custom minimal type guard for IndexPattern to check against the attributes used in transforms code.
|
// Custom minimal type guard for IndexPattern to check against the attributes used in transforms code.
|
||||||
export function isIndexPattern(arg: any): arg is IndexPattern {
|
export function isIndexPattern(arg: any): arg is IndexPattern {
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
import { EuiComboBoxOptionOption } from '@elastic/eui/src/components/combo_box/types';
|
import { EuiComboBoxOptionOption } from '@elastic/eui/src/components/combo_box/types';
|
||||||
import type { LatestFunctionConfig, PutTransformsRequestSchema } from '../api_schemas/transforms';
|
import type { LatestFunctionConfig, PutTransformsRequestSchema } from '../api_schemas/transforms';
|
||||||
import { isPopulatedObject } from '../utils/object_utils';
|
|
||||||
import { PivotGroupByDict } from './pivot_group_by';
|
import { PivotGroupByDict } from './pivot_group_by';
|
||||||
import { PivotAggDict } from './pivot_aggs';
|
import { PivotAggDict } from './pivot_aggs';
|
||||||
|
import { isPopulatedObject } from '../shared_imports';
|
||||||
|
|
||||||
export type IndexName = string;
|
export type IndexName = string;
|
||||||
export type IndexPattern = string;
|
export type IndexPattern = string;
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TransformState, TRANSFORM_STATE } from '../constants';
|
import { TransformState, TRANSFORM_STATE } from '../constants';
|
||||||
import { isPopulatedObject } from '../utils/object_utils';
|
|
||||||
import { TransformId } from './transform';
|
import { TransformId } from './transform';
|
||||||
|
import { isPopulatedObject } from '../shared_imports';
|
||||||
|
|
||||||
export interface TransformStats {
|
export interface TransformStats {
|
||||||
id: TransformId;
|
id: TransformId;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isPopulatedObject } from './object_utils';
|
import { isPopulatedObject } from '../shared_imports';
|
||||||
|
|
||||||
export interface ErrorResponse {
|
export interface ErrorResponse {
|
||||||
body: {
|
body: {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getNestedProperty, isPopulatedObject } from './object_utils';
|
import { getNestedProperty } from './object_utils';
|
||||||
|
|
||||||
describe('object_utils', () => {
|
describe('object_utils', () => {
|
||||||
test('getNestedProperty()', () => {
|
test('getNestedProperty()', () => {
|
||||||
|
@ -68,12 +68,4 @@ describe('object_utils', () => {
|
||||||
expect(typeof test11).toBe('number');
|
expect(typeof test11).toBe('number');
|
||||||
expect(test11).toBe(0);
|
expect(test11).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('isPopulatedObject()', () => {
|
|
||||||
expect(isPopulatedObject(0)).toBe(false);
|
|
||||||
expect(isPopulatedObject('')).toBe(false);
|
|
||||||
expect(isPopulatedObject(null)).toBe(false);
|
|
||||||
expect(isPopulatedObject({})).toBe(false);
|
|
||||||
expect(isPopulatedObject({ attribute: 'value' })).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,7 +51,3 @@ export const setNestedProperty = (obj: Record<string, any>, accessor: string, va
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isPopulatedObject = <T = Record<string, unknown>>(arg: unknown): arg is T => {
|
|
||||||
return typeof arg === 'object' && arg !== null && Object.keys(arg).length > 0;
|
|
||||||
};
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ import type { Dictionary } from '../../../common/types/common';
|
||||||
import type { EsFieldName } from '../../../common/types/fields';
|
import type { EsFieldName } from '../../../common/types/fields';
|
||||||
import type { PivotAgg, PivotSupportedAggs } from '../../../common/types/pivot_aggs';
|
import type { PivotAgg, PivotSupportedAggs } from '../../../common/types/pivot_aggs';
|
||||||
import { PIVOT_SUPPORTED_AGGS } from '../../../common/types/pivot_aggs';
|
import { PIVOT_SUPPORTED_AGGS } from '../../../common/types/pivot_aggs';
|
||||||
import { isPopulatedObject } from '../../../common/utils/object_utils';
|
|
||||||
|
|
||||||
import { getAggFormConfig } from '../sections/create_transform/components/step_define/common/get_agg_form_config';
|
import { getAggFormConfig } from '../sections/create_transform/components/step_define/common/get_agg_form_config';
|
||||||
import { PivotAggsConfigFilter } from '../sections/create_transform/components/step_define/common/filter_agg/types';
|
import { PivotAggsConfigFilter } from '../sections/create_transform/components/step_define/common/filter_agg/types';
|
||||||
|
import { isPopulatedObject } from '../../../common/shared_imports';
|
||||||
|
|
||||||
export function isPivotSupportedAggs(arg: unknown): arg is PivotSupportedAggs {
|
export function isPivotSupportedAggs(arg: unknown): arg is PivotSupportedAggs {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -9,9 +9,9 @@ import { AggName } from '../../../common/types/aggregations';
|
||||||
import { Dictionary } from '../../../common/types/common';
|
import { Dictionary } from '../../../common/types/common';
|
||||||
import { EsFieldName } from '../../../common/types/fields';
|
import { EsFieldName } from '../../../common/types/fields';
|
||||||
import { GenericAgg } from '../../../common/types/pivot_group_by';
|
import { GenericAgg } from '../../../common/types/pivot_group_by';
|
||||||
import { isPopulatedObject } from '../../../common/utils/object_utils';
|
|
||||||
import { KBN_FIELD_TYPES } from '../../../../../../src/plugins/data/common';
|
import { KBN_FIELD_TYPES } from '../../../../../../src/plugins/data/common';
|
||||||
import { PivotAggsConfigWithUiSupport } from './pivot_aggs';
|
import { PivotAggsConfigWithUiSupport } from './pivot_aggs';
|
||||||
|
import { isPopulatedObject } from '../../../common/shared_imports';
|
||||||
|
|
||||||
export enum PIVOT_SUPPORTED_GROUP_BY_AGGS {
|
export enum PIVOT_SUPPORTED_GROUP_BY_AGGS {
|
||||||
DATE_HISTOGRAM = 'date_histogram',
|
DATE_HISTOGRAM = 'date_histogram',
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
import { estypes } from '@elastic/elasticsearch';
|
||||||
import { PIVOT_SUPPORTED_AGGS } from '../../../common/types/pivot_aggs';
|
import { PIVOT_SUPPORTED_AGGS } from '../../../common/types/pivot_aggs';
|
||||||
|
|
||||||
import { PivotGroupByConfig } from '../common';
|
import { PivotGroupByConfig } from '../common';
|
||||||
|
@ -29,7 +29,6 @@ import {
|
||||||
PivotQuery,
|
PivotQuery,
|
||||||
} from './request';
|
} from './request';
|
||||||
import { LatestFunctionConfigUI } from '../../../common/types/transform';
|
import { LatestFunctionConfigUI } from '../../../common/types/transform';
|
||||||
import { RuntimeField } from '../../../../../../src/plugins/data/common/index_patterns';
|
|
||||||
|
|
||||||
const simpleQuery: PivotQuery = { query_string: { query: 'airline:AAL' } };
|
const simpleQuery: PivotQuery = { query_string: { query: 'airline:AAL' } };
|
||||||
|
|
||||||
|
@ -273,7 +272,7 @@ describe('Transform: Common', () => {
|
||||||
script: {
|
script: {
|
||||||
source: "emit(doc['bytes'].value * 2.0)",
|
source: "emit(doc['bytes'].value * 2.0)",
|
||||||
},
|
},
|
||||||
} as RuntimeField,
|
} as estypes.RuntimeField,
|
||||||
};
|
};
|
||||||
|
|
||||||
const pivotState: StepDefineExposedState = {
|
const pivotState: StepDefineExposedState = {
|
||||||
|
|
|
@ -17,7 +17,6 @@ import type {
|
||||||
PutTransformsPivotRequestSchema,
|
PutTransformsPivotRequestSchema,
|
||||||
PutTransformsRequestSchema,
|
PutTransformsRequestSchema,
|
||||||
} from '../../../common/api_schemas/transforms';
|
} from '../../../common/api_schemas/transforms';
|
||||||
import { isPopulatedObject } from '../../../common/utils/object_utils';
|
|
||||||
import { DateHistogramAgg, HistogramAgg, TermsAgg } from '../../../common/types/pivot_group_by';
|
import { DateHistogramAgg, HistogramAgg, TermsAgg } from '../../../common/types/pivot_group_by';
|
||||||
import { isIndexPattern } from '../../../common/types/index_pattern';
|
import { isIndexPattern } from '../../../common/types/index_pattern';
|
||||||
|
|
||||||
|
@ -35,6 +34,7 @@ import {
|
||||||
PivotAggsConfig,
|
PivotAggsConfig,
|
||||||
PivotGroupByConfig,
|
PivotGroupByConfig,
|
||||||
} from './';
|
} from './';
|
||||||
|
import { isPopulatedObject } from '../../../common/shared_imports';
|
||||||
|
|
||||||
export interface SimpleQuery {
|
export interface SimpleQuery {
|
||||||
query_string: {
|
query_string: {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { SimpleQuery } from '../common';
|
||||||
|
|
||||||
import { SearchItems } from './use_search_items';
|
import { SearchItems } from './use_search_items';
|
||||||
import { useIndexData } from './use_index_data';
|
import { useIndexData } from './use_index_data';
|
||||||
|
import { estypes } from '@elastic/elasticsearch';
|
||||||
|
|
||||||
jest.mock('../../shared_imports');
|
jest.mock('../../shared_imports');
|
||||||
jest.mock('../app_dependencies');
|
jest.mock('../app_dependencies');
|
||||||
|
@ -25,7 +26,6 @@ jest.mock('./use_api');
|
||||||
|
|
||||||
import { useAppDependencies } from '../__mocks__/app_dependencies';
|
import { useAppDependencies } from '../__mocks__/app_dependencies';
|
||||||
import { MlSharedContext } from '../__mocks__/shared_context';
|
import { MlSharedContext } from '../__mocks__/shared_context';
|
||||||
import { RuntimeField } from '../../../../../../src/plugins/data/common/index_patterns';
|
|
||||||
|
|
||||||
const query: SimpleQuery = {
|
const query: SimpleQuery = {
|
||||||
query_string: {
|
query_string: {
|
||||||
|
@ -40,7 +40,7 @@ const runtimeMappings = {
|
||||||
script: {
|
script: {
|
||||||
source: "emit(doc['bytes'].value * 2.0)",
|
source: "emit(doc['bytes'].value * 2.0)",
|
||||||
},
|
},
|
||||||
} as RuntimeField,
|
} as estypes.RuntimeField,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Transform: useIndexData()', () => {
|
describe('Transform: useIndexData()', () => {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
|
|
||||||
import { Privileges } from '../../../../../common/types/privileges';
|
import { Privileges } from '../../../../../common/types/privileges';
|
||||||
import { isPopulatedObject } from '../../../../../common/utils/object_utils';
|
import { isPopulatedObject } from '../../../../../common/shared_imports';
|
||||||
|
|
||||||
export interface Capabilities {
|
export interface Capabilities {
|
||||||
canGetTransform: boolean;
|
canGetTransform: boolean;
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { EuiCodeEditor } from '@elastic/eui';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
|
|
||||||
import { StepDefineFormHook } from '../step_define';
|
import { StepDefineFormHook } from '../step_define';
|
||||||
import { isRuntimeMappings } from '../step_define/common/types';
|
import { isRuntimeMappings } from '../../../../../../common/shared_imports';
|
||||||
|
|
||||||
export const AdvancedRuntimeMappingsEditor: FC<StepDefineFormHook['runtimeMappingsEditor']> = memo(
|
export const AdvancedRuntimeMappingsEditor: FC<StepDefineFormHook['runtimeMappingsEditor']> = memo(
|
||||||
({
|
({
|
||||||
|
|
|
@ -47,8 +47,8 @@ import {
|
||||||
PutTransformsPivotRequestSchema,
|
PutTransformsPivotRequestSchema,
|
||||||
} from '../../../../../../common/api_schemas/transforms';
|
} from '../../../../../../common/api_schemas/transforms';
|
||||||
import type { RuntimeField } from '../../../../../../../../../src/plugins/data/common/index_patterns';
|
import type { RuntimeField } from '../../../../../../../../../src/plugins/data/common/index_patterns';
|
||||||
import { isPopulatedObject } from '../../../../../../common/utils/object_utils';
|
|
||||||
import { isLatestTransform } from '../../../../../../common/types/transform';
|
import { isLatestTransform } from '../../../../../../common/types/transform';
|
||||||
|
import { isPopulatedObject } from '../../../../../../common/shared_imports';
|
||||||
|
|
||||||
export interface StepDetailsExposedState {
|
export interface StepDetailsExposedState {
|
||||||
created: boolean;
|
created: boolean;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import { getPivotDropdownOptions } from '../common';
|
import { getPivotDropdownOptions } from '../common';
|
||||||
import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public';
|
import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public';
|
||||||
import { FilterAggForm } from './filter_agg/components';
|
import { FilterAggForm } from './filter_agg/components';
|
||||||
import type { RuntimeField } from '../../../../../../../../../../src/plugins/data/common/index_patterns';
|
import { estypes } from '@elastic/elasticsearch';
|
||||||
|
|
||||||
describe('Transform: Define Pivot Common', () => {
|
describe('Transform: Define Pivot Common', () => {
|
||||||
test('getPivotDropdownOptions()', () => {
|
test('getPivotDropdownOptions()', () => {
|
||||||
|
@ -117,7 +117,7 @@ describe('Transform: Define Pivot Common', () => {
|
||||||
script: {
|
script: {
|
||||||
source: "emit(doc['bytes'].value * 2.0)",
|
source: "emit(doc['bytes'].value * 2.0)",
|
||||||
},
|
},
|
||||||
} as RuntimeField,
|
} as estypes.RuntimeField,
|
||||||
};
|
};
|
||||||
const optionsWithRuntimeFields = getPivotDropdownOptions(indexPattern, runtimeMappings);
|
const optionsWithRuntimeFields = getPivotDropdownOptions(indexPattern, runtimeMappings);
|
||||||
expect(optionsWithRuntimeFields).toMatchObject({
|
expect(optionsWithRuntimeFields).toMatchObject({
|
||||||
|
|
|
@ -10,12 +10,10 @@ import React from 'react';
|
||||||
import { I18nProvider } from '@kbn/i18n/react';
|
import { I18nProvider } from '@kbn/i18n/react';
|
||||||
import { FilterAggForm } from './filter_agg_form';
|
import { FilterAggForm } from './filter_agg_form';
|
||||||
import { CreateTransformWizardContext } from '../../../../wizard/wizard';
|
import { CreateTransformWizardContext } from '../../../../wizard/wizard';
|
||||||
import {
|
import { KBN_FIELD_TYPES } from '../../../../../../../../../../../../src/plugins/data/common';
|
||||||
KBN_FIELD_TYPES,
|
|
||||||
RuntimeField,
|
|
||||||
} from '../../../../../../../../../../../../src/plugins/data/common';
|
|
||||||
import { IndexPattern } from '../../../../../../../../../../../../src/plugins/data/public';
|
import { IndexPattern } from '../../../../../../../../../../../../src/plugins/data/public';
|
||||||
import { FilterTermForm } from './filter_term_form';
|
import { FilterTermForm } from './filter_term_form';
|
||||||
|
import { estypes } from '@elastic/elasticsearch';
|
||||||
|
|
||||||
describe('FilterAggForm', () => {
|
describe('FilterAggForm', () => {
|
||||||
const runtimeMappings = {
|
const runtimeMappings = {
|
||||||
|
@ -24,7 +22,7 @@ describe('FilterAggForm', () => {
|
||||||
script: {
|
script: {
|
||||||
source: "emit(doc['bytes'].value * 2.0)",
|
source: "emit(doc['bytes'].value * 2.0)",
|
||||||
},
|
},
|
||||||
} as RuntimeField,
|
} as estypes.RuntimeField,
|
||||||
};
|
};
|
||||||
|
|
||||||
const indexPattern = ({
|
const indexPattern = ({
|
||||||
|
|
|
@ -14,9 +14,11 @@ import { commonFilterAggs, filterAggsFieldSupport } from '../constants';
|
||||||
import { IndexPattern } from '../../../../../../../../../../../../src/plugins/data/public';
|
import { IndexPattern } from '../../../../../../../../../../../../src/plugins/data/public';
|
||||||
import { getFilterAggTypeConfig } from '../config';
|
import { getFilterAggTypeConfig } from '../config';
|
||||||
import type { FilterAggType, PivotAggsConfigFilter } from '../types';
|
import type { FilterAggType, PivotAggsConfigFilter } from '../types';
|
||||||
import type { RuntimeMappings } from '../../types';
|
|
||||||
import { getKibanaFieldTypeFromEsType } from '../../get_pivot_dropdown_options';
|
import { getKibanaFieldTypeFromEsType } from '../../get_pivot_dropdown_options';
|
||||||
import { isPopulatedObject } from '../../../../../../../../../common/utils/object_utils';
|
import {
|
||||||
|
isPopulatedObject,
|
||||||
|
RuntimeMappings,
|
||||||
|
} from '../../../../../../../../../common/shared_imports';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves supported filters for provided field.
|
* Resolves supported filters for provided field.
|
||||||
|
|
|
@ -26,7 +26,7 @@ import {
|
||||||
import { getDefaultAggregationConfig } from './get_default_aggregation_config';
|
import { getDefaultAggregationConfig } from './get_default_aggregation_config';
|
||||||
import { getDefaultGroupByConfig } from './get_default_group_by_config';
|
import { getDefaultGroupByConfig } from './get_default_group_by_config';
|
||||||
import type { Field, StepDefineExposedState } from './types';
|
import type { Field, StepDefineExposedState } from './types';
|
||||||
import { isRuntimeMappings } from './types';
|
import { isRuntimeMappings } from '../../../../../../../common/shared_imports';
|
||||||
|
|
||||||
const illegalEsAggNameChars = /[[\]>]/g;
|
const illegalEsAggNameChars = /[[\]>]/g;
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,7 @@ import {
|
||||||
PivotConfigDefinition,
|
PivotConfigDefinition,
|
||||||
} from '../../../../../../../common/types/transform';
|
} from '../../../../../../../common/types/transform';
|
||||||
import { LatestFunctionConfig } from '../../../../../../../common/api_schemas/transforms';
|
import { LatestFunctionConfig } from '../../../../../../../common/api_schemas/transforms';
|
||||||
|
import { isPopulatedObject, RuntimeMappings } from '../../../../../../../common/shared_imports';
|
||||||
import { isPopulatedObject } from '../../../../../../../common/utils/object_utils';
|
|
||||||
|
|
||||||
export interface ErrorMessage {
|
export interface ErrorMessage {
|
||||||
query: string;
|
query: string;
|
||||||
|
@ -36,20 +35,6 @@ export interface Field {
|
||||||
type: KBN_FIELD_TYPES;
|
type: KBN_FIELD_TYPES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace this with import once #88995 is merged
|
|
||||||
const RUNTIME_FIELD_TYPES = ['keyword', 'long', 'double', 'date', 'ip', 'boolean'] as const;
|
|
||||||
type RuntimeType = typeof RUNTIME_FIELD_TYPES[number];
|
|
||||||
|
|
||||||
export interface RuntimeField {
|
|
||||||
type: RuntimeType;
|
|
||||||
script?:
|
|
||||||
| string
|
|
||||||
| {
|
|
||||||
source: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RuntimeMappings = Record<string, RuntimeField>;
|
|
||||||
export interface StepDefineExposedState {
|
export interface StepDefineExposedState {
|
||||||
transformFunction: TransformFunction;
|
transformFunction: TransformFunction;
|
||||||
aggList: PivotAggsConfigDict;
|
aggList: PivotAggsConfigDict;
|
||||||
|
@ -72,26 +57,6 @@ export interface StepDefineExposedState {
|
||||||
isRuntimeMappingsEditorEnabled: boolean;
|
isRuntimeMappingsEditorEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isRuntimeField(arg: unknown): arg is RuntimeField {
|
|
||||||
return (
|
|
||||||
isPopulatedObject(arg) &&
|
|
||||||
((Object.keys(arg).length === 1 && arg.hasOwnProperty('type')) ||
|
|
||||||
(Object.keys(arg).length === 2 &&
|
|
||||||
arg.hasOwnProperty('type') &&
|
|
||||||
arg.hasOwnProperty('script') &&
|
|
||||||
(typeof arg.script === 'string' ||
|
|
||||||
(isPopulatedObject(arg.script) &&
|
|
||||||
Object.keys(arg.script).length === 1 &&
|
|
||||||
arg.script.hasOwnProperty('source') &&
|
|
||||||
typeof arg.script.source === 'string')))) &&
|
|
||||||
RUNTIME_FIELD_TYPES.includes(arg.type as RuntimeType)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isRuntimeMappings(arg: unknown): arg is RuntimeMappings {
|
|
||||||
return isPopulatedObject(arg) && Object.values(arg).every((d) => isRuntimeField(d));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isPivotPartialRequest(arg: unknown): arg is { pivot: PivotConfigDefinition } {
|
export function isPivotPartialRequest(arg: unknown): arg is { pivot: PivotConfigDefinition } {
|
||||||
return isPopulatedObject(arg) && arg.hasOwnProperty('pivot');
|
return isPopulatedObject(arg) && arg.hasOwnProperty('pivot');
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import {
|
||||||
} from '../step_details';
|
} from '../step_details';
|
||||||
import { WizardNav } from '../wizard_nav';
|
import { WizardNav } from '../wizard_nav';
|
||||||
import { IndexPattern } from '../../../../../../../../../src/plugins/data/public';
|
import { IndexPattern } from '../../../../../../../../../src/plugins/data/public';
|
||||||
import type { RuntimeMappings } from '../step_define/common/types';
|
import { RuntimeMappings } from '../../../../../../common/shared_imports';
|
||||||
|
|
||||||
enum KBN_MANAGEMENT_PAGE_CLASSNAME {
|
enum KBN_MANAGEMENT_PAGE_CLASSNAME {
|
||||||
DEFAULT_BODY = 'mgtPage__body',
|
DEFAULT_BODY = 'mgtPage__body',
|
||||||
|
|
|
@ -41,7 +41,6 @@ export function registerFieldHistogramsRoutes({ router, license }: RouteDependen
|
||||||
query,
|
query,
|
||||||
fields,
|
fields,
|
||||||
samplerShardSize,
|
samplerShardSize,
|
||||||
// @ts-expect-error script is not compatible with StoredScript from @elastic/elasticsearch: string is not supported
|
|
||||||
runtimeMappings
|
runtimeMappings
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isPopulatedObject } from '../../../common/utils/object_utils';
|
|
||||||
|
|
||||||
import { RouteDependencies } from '../../types';
|
import { RouteDependencies } from '../../types';
|
||||||
|
|
||||||
import { addBasePath } from '../index';
|
import { addBasePath } from '../index';
|
||||||
|
|
||||||
import { wrapError, wrapEsError } from './error_utils';
|
import { wrapError, wrapEsError } from './error_utils';
|
||||||
|
import { isPopulatedObject } from '../../../common/shared_imports';
|
||||||
|
|
||||||
const NODE_ROLES = 'roles';
|
const NODE_ROLES = 'roles';
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue