Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit index pattern namespace #57194

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/p
import { BaseParamType } from './base';
import { propFilter } from '../filter';
import { IMetricAggConfig } from '../metrics/metric_agg_type';
import { Field, isNestedField, KBN_FIELD_TYPES } from '../../../../../../../plugins/data/public';
import {
IndexPatternField,
indexPatterns,
KBN_FIELD_TYPES,
} from '../../../../../../../plugins/data/public';

const filterByType = propFilter('type');

Expand Down Expand Up @@ -72,7 +76,7 @@ export class FieldParamType extends BaseParamType {
};
}

this.serialize = (field: Field) => {
this.serialize = (field: IndexPatternField) => {
return field.name;
};

Expand Down Expand Up @@ -112,11 +116,11 @@ export class FieldParamType extends BaseParamType {
*/
getAvailableFields = (aggConfig: IAggConfig) => {
const fields = aggConfig.getIndexPattern().fields;
const filteredFields = fields.filter((field: Field) => {
const filteredFields = fields.filter((field: IndexPatternField) => {
const { onlyAggregatable, scriptable, filterFieldTypes } = this;

if (
(onlyAggregatable && (!field.aggregatable || isNestedField(field))) ||
(onlyAggregatable && (!field.aggregatable || indexPatterns.isNestedField(field))) ||
(!scriptable && field.scripted)
) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { IndexedArray } from 'ui/indexed_array';
import { AggTypeFieldFilters } from './field_filters';
import { AggConfig } from '../../agg_config';
import { Field } from '../../../../../../../../plugins/data/public';
import { IndexPatternField } from '../../../../../../../../plugins/data/public';

describe('AggTypeFieldFilters', () => {
let registry: AggTypeFieldFilters;
Expand All @@ -31,13 +31,13 @@ describe('AggTypeFieldFilters', () => {
});

it('should filter nothing without registered filters', async () => {
const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray<Field>;
const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray<IndexPatternField>;
const filtered = registry.filter(fields, aggConfig);
expect(filtered).toEqual(fields);
});

it('should pass all fields to the registered filter', async () => {
const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray<Field>;
const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray<IndexPatternField>;
const filter = jest.fn();
registry.addFilter(filter);
registry.filter(fields, aggConfig);
Expand All @@ -46,7 +46,7 @@ describe('AggTypeFieldFilters', () => {
});

it('should allow registered filters to filter out fields', async () => {
const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray<Field>;
const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray<IndexPatternField>;
let filtered = registry.filter(fields, aggConfig);
expect(filtered).toEqual(fields);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Field } from 'src/plugins/data/public';
import { IndexPatternField } from 'src/plugins/data/public';
import { AggConfig } from '../../agg_config';

type AggTypeFieldFilter = (field: Field, aggConfig: AggConfig) => boolean;
type AggTypeFieldFilter = (field: IndexPatternField, aggConfig: AggConfig) => boolean;

/**
* A registry to store {@link AggTypeFieldFilter} which are used to filter down
Expand All @@ -45,7 +45,7 @@ class AggTypeFieldFilters {
* @param aggConfig The aggConfig for which the returning list will be used.
* @return A filtered list of the passed fields.
*/
public filter(fields: Field[], aggConfig: AggConfig) {
public filter(fields: IndexPatternField[], aggConfig: AggConfig) {
const allFilters = Array.from(this.filters);
const allowedAggTypeFields = fields.filter(field => {
const isAggTypeFieldAllowed = allFilters.every(filter => filter(field, aggConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
*/

import React from 'react';
import { FieldList } from 'src/plugins/data/public';
import { InputControlVisDependencies } from '../plugin';

const fields: FieldList = [] as any;
const fields = [] as any;
fields.push({ name: 'myField' } as any);
fields.getByName = (name: any) => {
return fields.find(({ name: n }) => n === name);
return fields.find(({ name: n }: { name: string }) => n === name);
};

export const getDepsMock = (): InputControlVisDependencies =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { createStateStub } from './_utils';
import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions';
import { createIndexPatternsStub } from '../../np_ready/angular/context/api/__tests__/_stubs';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import { npStart } from 'ui/new_platform';

describe('context app', function() {
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(() => pluginInstance.initializeServices());
beforeEach(ngMock.module('app/discover'));
beforeEach(
ngMock.module(function createServiceStubs($provide) {
$provide.value('indexPatterns', createIndexPatternsStub());
})
);

describe('action addFilter', function() {
let addFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { StateManagementConfigProvider } from 'ui/state_management/config_provid
import { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url';
// @ts-ignore
import { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav';
import { IndexPatterns, DataPublicPluginStart } from '../../../../../plugins/data/public';
import { DataPublicPluginStart } from '../../../../../plugins/data/public';
import { Storage } from '../../../../../plugins/kibana_utils/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public';
import { createDocTableDirective } from './np_ready/angular/doc_table/doc_table';
Expand Down Expand Up @@ -125,7 +125,6 @@ export function initializeInnerAngularModule(
createLocalAppStateModule();
createLocalStorageModule();
createElasticSearchModule(data);
createIndexPatternsModule();
createPagerFactoryModule();
createDocTableModule();
initialized = true;
Expand Down Expand Up @@ -164,7 +163,6 @@ export function initializeInnerAngularModule(
'discoverGlobalState',
'discoverAppState',
'discoverLocalStorageProvider',
'discoverIndexPatterns',
'discoverEs',
'discoverDocTable',
'discoverPagerFactory',
Expand Down Expand Up @@ -299,10 +297,6 @@ function createElasticSearchModule(data: DataPublicPluginStart) {
});
}

function createIndexPatternsModule() {
lizozom marked this conversation as resolved.
Show resolved Hide resolved
angular.module('discoverIndexPatterns', []).value('indexPatterns', IndexPatterns);
}

function createPagerFactoryModule() {
angular.module('discoverPagerFactory', []).factory('pagerFactory', createPagerFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ describe('context app', function() {
let fetchAnchor;
let searchSourceStub;

beforeEach(
ngMock.module(function createServiceStubs($provide) {
$provide.value('indexPatterns', createIndexPatternsStub());
})
);

beforeEach(
ngMock.inject(function createPrivateStubs() {
searchSourceStub = createSearchSourceStub([{ _id: 'hit1' }]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ describe('context app', function() {
let fetchPredecessors;
let searchSourceStub;

beforeEach(
ngMock.module(function createServiceStubs($provide) {
$provide.value('indexPatterns', createIndexPatternsStub());
})
);

beforeEach(
ngMock.inject(function createPrivateStubs() {
searchSourceStub = createContextSearchSourceStub([], '@timestamp', MS_PER_DAY * 8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { fieldCalculator } from './lib/field_calculator';
import './discover_field';
import './discover_field_search_directive';
import './discover_index_pattern_directive';
import { FieldList } from '../../../../../../../../plugins/data/public';
import fieldChooserTemplate from './field_chooser.html';
import { IndexPatternFieldList } from '../../../../../../../../plugins/data/public';

export function createFieldChooserDirective($location, config, $route) {
return {
Expand Down Expand Up @@ -281,7 +281,7 @@ export function createFieldChooserDirective($location, config, $route) {
});
});

const fields = new FieldList(indexPattern, fieldSpecs);
const fields = new IndexPatternFieldList(indexPattern, fieldSpecs);

if (prevFields) {
fields.forEach(function(field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Field } from '../../../../../../../../../plugins/data/public';
import { IndexPatternField } from '../../../../../../../../../plugins/data/public';
import { RegistryFieldFormatEditorsProvider } from 'ui/registry/field_format_editors';
import { docTitle } from 'ui/doc_title';
import { KbnUrlProvider } from 'ui/url';
Expand All @@ -39,7 +39,7 @@ const renderFieldEditor = (
$scope,
indexPattern,
field,
{ Field, getConfig, $http, fieldFormatEditors, redirectAway }
{ getConfig, $http, fieldFormatEditors, redirectAway }
) => {
$scope.$$postDigest(() => {
const node = document.getElementById(REACT_FIELD_EDITOR_ID);
Expand All @@ -53,7 +53,7 @@ const renderFieldEditor = (
indexPattern={indexPattern}
field={field}
helpers={{
Field,
Field: IndexPatternField,
getConfig,
$http,
fieldFormatEditors,
Expand Down Expand Up @@ -135,7 +135,7 @@ uiRoutes
return;
}
} else if (this.mode === 'create') {
this.field = new Field(this.indexPattern, {
this.field = new IndexPatternField(this.indexPattern, {
scripted: true,
type: 'number',
});
Expand All @@ -158,7 +158,6 @@ uiRoutes
docTitle.change([fieldName, this.indexPattern.title]);

renderFieldEditor($scope, this.indexPattern, this.field, {
Field,
getConfig,
$http,
fieldFormatEditors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Field } from 'src/plugins/data/public';
import { IndexPatternField } from 'src/plugins/data/public';
import { VisState } from 'src/legacy/core_plugins/visualizations/public';
import { IAggConfig, AggParam } from '../legacy_imports';
import { ComboBoxGroupedOptions } from '../utils';
Expand All @@ -33,7 +33,7 @@ export interface AggParamCommonProps<T, P = AggParam> {
disabled?: boolean;
editorConfig: EditorConfig;
formIsTouched: boolean;
indexedFields?: ComboBoxGroupedOptions<Field>;
indexedFields?: ComboBoxGroupedOptions<IndexPatternField>;
showValidation: boolean;
state: VisState;
value?: T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { get, isEmpty } from 'lodash';

import { IndexPattern, Field } from 'src/plugins/data/public';
import { IndexPattern, IndexPatternField } from 'src/plugins/data/public';
import { VisState } from 'src/legacy/core_plugins/visualizations/public';
import { groupAndSortBy, ComboBoxGroupedOptions } from '../utils';
import { AggTypeState, AggParamsState } from './agg_params_state';
Expand All @@ -45,7 +45,7 @@ interface ParamInstanceBase {

export interface ParamInstance extends ParamInstanceBase {
aggParam: AggParam;
indexedFields: ComboBoxGroupedOptions<Field>;
indexedFields: ComboBoxGroupedOptions<IndexPatternField>;
paramEditor: React.ComponentType<AggParamEditorProps<unknown>>;
value: unknown;
}
Expand All @@ -65,15 +65,17 @@ function getAggParamsToRender({ agg, editorConfig, metricAggs, state }: ParamIns

// build collection of agg params components
paramsToRender.forEach((param: AggParam, index: number) => {
let indexedFields: ComboBoxGroupedOptions<Field> = [];
let fields: Field[];
let indexedFields: ComboBoxGroupedOptions<IndexPatternField> = [];
let fields: IndexPatternField[];

if (agg.schema.hideCustomLabel && param.name === 'customLabel') {
return;
}
// if field param exists, compute allowed fields
if (param.type === 'field') {
const availableFields: Field[] = (param as IFieldParamType).getAvailableFields(agg);
const availableFields: IndexPatternField[] = (param as IFieldParamType).getAvailableFields(
agg
);
fields = aggTypeFieldFilters.filter(availableFields, agg);
indexedFields = groupAndSortBy(fields, 'type', 'name');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { act } from 'react-dom/test-utils';
import { mount, shallow, ReactWrapper } from 'enzyme';
import { EuiComboBoxProps, EuiComboBox } from '@elastic/eui';

import { Field } from 'src/plugins/data/public';
import { IndexPatternField } from 'src/plugins/data/public';
import { VisState } from 'src/legacy/core_plugins/visualizations/public';
import { ComboBoxGroupedOptions } from '../../utils';
import { FieldParamEditor, FieldParamEditorProps } from './field';
Expand All @@ -41,11 +41,11 @@ describe('FieldParamEditor component', () => {
let setTouched: jest.Mock;
let onChange: jest.Mock;
let defaultProps: FieldParamEditorProps;
let indexedFields: ComboBoxGroupedOptions<Field>;
let field: Field;
let indexedFields: ComboBoxGroupedOptions<IndexPatternField>;
let field: IndexPatternField;
let option: {
label: string;
target: Field;
target: IndexPatternField;
};

beforeEach(() => {
Expand All @@ -54,7 +54,7 @@ describe('FieldParamEditor component', () => {
setTouched = jest.fn();
onChange = jest.fn();

field = { displayName: 'bytes' } as Field;
field = { displayName: 'bytes' } as IndexPatternField;
option = { label: 'bytes', target: field };
indexedFields = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import React, { useEffect } from 'react';
import { EuiComboBox, EuiComboBoxOptionProps, EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { Field } from 'src/plugins/data/public';
import { IndexPatternField } from 'src/plugins/data/public';
import { AggParam, IAggConfig, IFieldParamType } from '../../legacy_imports';
import { formatListAsProse, parseCommaSeparatedList, useValidation } from './utils';
import { AggParamEditorProps } from '../agg_param_props';
Expand All @@ -33,7 +33,7 @@ const label = i18n.translate('visDefaultEditor.controls.field.fieldLabel', {
defaultMessage: 'Field',
});

export interface FieldParamEditorProps extends AggParamEditorProps<Field> {
export interface FieldParamEditorProps extends AggParamEditorProps<IndexPatternField> {
customError?: string;
customLabel?: string;
}
Expand All @@ -50,12 +50,12 @@ function FieldParamEditor({
setValidity,
setValue,
}: FieldParamEditorProps) {
const selectedOptions: ComboBoxGroupedOptions<Field> = value
const selectedOptions: ComboBoxGroupedOptions<IndexPatternField> = value
? [{ label: value.displayName || value.name, target: value }]
: [];

const onChange = (options: EuiComboBoxOptionProps[]) => {
const selectedOption: Field = get(options, '0.target');
const selectedOption: IndexPatternField = get(options, '0.target');
if (!(aggParam.required && !selectedOption)) {
setValue(selectedOption);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import React from 'react';
import { i18n } from '@kbn/i18n';

import { Field } from 'src/plugins/data/public';
import { IndexPatternField } from 'src/plugins/data/public';
import { FieldParamEditor } from './field';
import { getCompatibleAggs } from './top_aggregate';
import { AggParamEditorProps } from '../agg_param_props';

function TopFieldParamEditor(props: AggParamEditorProps<Field>) {
function TopFieldParamEditor(props: AggParamEditorProps<IndexPatternField>) {
const compatibleAggs = getCompatibleAggs(props.agg);
let customError;

Expand Down
Loading