Skip to content
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
2 changes: 1 addition & 1 deletion src/fixtures/stubbed_logstash_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function stubbedLogstashIndexPatternService(Private) {
};
});

const indexPattern = new StubIndexPattern('logstash-*', 'time', fields);
const indexPattern = new StubIndexPattern('logstash-*', cfg => cfg, 'time', fields);
indexPattern.id = 'logstash-*';

return indexPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { FilterStateStore, toggleFilterNegated } from '@kbn/es-query';
import { fixtures } from '../../../../index_patterns';
import { mockFields, mockIndexPattern } from '../../../../index_patterns';
import { IndexPattern, Field } from '../../../../index';
import {
buildFilter,
Expand Down Expand Up @@ -57,7 +57,6 @@ jest.mock(
{ virtual: true }
);

const { mockFields, mockIndexPattern } = fixtures;
const mockedFields = mockFields as Field[];
const mockedIndexPattern = mockIndexPattern as IndexPattern;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '@kbn/es-query';
import { omit } from 'lodash';
import Ipv4Address from 'ui/utils/ipv4_address';
import { Field, IndexPattern, utils as indexPatternUtils } from '../../../../index_patterns';
import { Field, IndexPattern, isFilterable } from '../../../../index_patterns';
import { FILTER_OPERATORS, Operator } from './filter_operators';

export function getIndexPatternFromFilter(
Expand All @@ -58,7 +58,7 @@ export function getQueryDslFromFilter(filter: Filter) {
}

export function getFilterableFields(indexPattern: IndexPattern) {
return indexPattern.fields.filter(indexPatternUtils.isFilterable);
return indexPattern.fields.filter(isFilterable);
}

export function getOperatorOptions(field: Field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@
* under the License.
*/

export function getRoutes() {
return {
edit: '/management/kibana/index_patterns/{{id}}',
addField: '/management/kibana/index_patterns/{{id}}/create-field',
indexedFields: '/management/kibana/index_patterns/{{id}}?_a=(tab:indexedFields)',
scriptedFields: '/management/kibana/index_patterns/{{id}}?_a=(tab:scriptedFields)',
sourceFilters: '/management/kibana/index_patterns/{{id}}?_a=(tab:sourceFilters)',
import { FilterService, FilterSetup } from '.';

type FilterServiceClientContract = PublicMethodsOf<FilterService>;

const createSetupContractMock = () => {
const setupContract: jest.Mocked<FilterSetup> = {
filterManager: jest.fn() as any,
};
}

return setupContract;
};

const createMock = () => {
const mocked: jest.Mocked<FilterServiceClientContract> = {
setup: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
};

mocked.setup.mockReturnValue(createSetupContractMock());
return mocked;
};

export const filterServiceMock = {
create: createMock,
createSetupContract: createSetupContractMock,
createStartContract: createSetupContractMock,
};
7 changes: 6 additions & 1 deletion src/legacy/core_plugins/data/public/filter/filter_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import { UiSettingsClientContract } from 'src/core/public';
import { IndexPatterns } from '../index_patterns';
import { FilterManager } from './filter_manager';

/**
* FilterSearch Service
* Filter Service
* @internal
*/

Expand All @@ -37,6 +38,10 @@ export class FilterService {
};
}

public start() {
// nothing to do here yet
}

public stop() {
// nothing to do here yet
}
Expand Down
36 changes: 29 additions & 7 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,40 @@ export function plugin() {
/** @public types */
export type DataSetup = DataSetup;
export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from './expressions';

/** @public types */
export { IndexPattern, StaticIndexPattern, Field } from './index_patterns';
export { Query, QueryBar, QueryBarInput } from './query';
export { FilterBar, ApplyFiltersPopover } from './filter';
export {
Field,
FieldType,
IndexPattern,
IndexPatterns,
StaticIndexPattern,
} from './index_patterns';
export { Query, QueryBar, QueryBarInput } from './query';
export { SearchBar, SearchBarProps } from './search';

/** @public static code */
export * from '../common';
export {
FilterManager,
FilterStateManager,
uniqFilters,
onlyDisabledFiltersChanged,
} from './filter/filter_manager';

/** @public static code */
export * from '../common';
export {
CONTAINS_SPACES,
getFromSavedObject,
getRoutes,
isFilterable,
IndexPatternSelect,
IndexPatternsProvider, // LEGACY
validateIndexPattern,
ILLEGAL_CHARACTERS,
INDEX_PATTERN_ILLEGAL_CHARACTERS,
INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE,
IndexPatternAlreadyExists,
IndexPatternMissingIndices,
NoDefaultIndexPattern,
NoDefinedIndexPatterns,
mockFields,
mockIndexPattern,
} from './index_patterns';
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
* under the License.
*/

import './_get_computed_fields';
describe('Index Patterns', function () {
});
export * from './index_pattern_select';
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

import _ from 'lodash';
import React, { Component } from 'react';
import chrome from 'ui/chrome';

import { EuiComboBox } from '@elastic/eui';
import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../../core/public';

interface IndexPatternSelectProps {
onChange: (opt: any) => void;
indexPatternId: string;
placeholder: string;
fieldTypes: string[];
onNoIndexPatterns: () => void;
savedObjectsClient: SavedObjectsClientContract;
}

interface IndexPatternSelectState {
Expand All @@ -38,8 +39,12 @@ interface IndexPatternSelectState {
searchValue: string | undefined;
}

const getIndexPatterns = async (search: string, fields: string[]) => {
const resp = await chrome.getSavedObjectsClient().find({
const getIndexPatterns = async (
client: SavedObjectsClientContract,
search: string,
fields: string[]
) => {
const resp = await client.find({
type: 'index-pattern',
fields,
search: `${search}*`,
Expand All @@ -49,14 +54,22 @@ const getIndexPatterns = async (search: string, fields: string[]) => {
return resp.savedObjects;
};

const getIndexPatternTitle = async (indexPatternId: string) => {
const savedObject = await chrome.getSavedObjectsClient().get('index-pattern', indexPatternId);
const getIndexPatternTitle = async (
client: SavedObjectsClientContract,
indexPatternId: string
): Promise<SimpleSavedObject<any>> => {
const savedObject = (await client.get('index-pattern', indexPatternId)) as SimpleSavedObject<any>;
if (savedObject.error) {
throw new Error(`Unable to get index-pattern title: ${savedObject.error.message}`);
}
return savedObject.attributes.title;
};

// Takes in stateful runtime dependencies and pre-wires them to the component
export function createIndexPatternSelect(savedObjectsClient: SavedObjectsClientContract) {
return (props: any) => <IndexPatternSelect savedObjectsClient={savedObjectsClient} {...props} />;
}

export class IndexPatternSelect extends Component<IndexPatternSelectProps> {
private isMounted: boolean = false;
state: IndexPatternSelectState;
Expand Down Expand Up @@ -99,7 +112,7 @@ export class IndexPatternSelect extends Component<IndexPatternSelectProps> {

let indexPatternTitle;
try {
indexPatternTitle = await getIndexPatternTitle(indexPatternId);
indexPatternTitle = await getIndexPatternTitle(this.props.savedObjectsClient, indexPatternId);
} catch (err) {
// index pattern no longer exists
return;
Expand All @@ -118,16 +131,16 @@ export class IndexPatternSelect extends Component<IndexPatternSelectProps> {
};

debouncedFetch = _.debounce(async (searchValue: string) => {
const { fieldTypes, onNoIndexPatterns } = this.props;
const { fieldTypes, onNoIndexPatterns, savedObjectsClient } = this.props;

const savedObjectFields = ['title'];
if (fieldTypes) {
savedObjectFields.push('fields');
}
let savedObjects = await getIndexPatterns(searchValue, savedObjectFields);
let savedObjects = await getIndexPatterns(savedObjectsClient, searchValue, savedObjectFields);

if (fieldTypes) {
savedObjects = savedObjects.filter(savedObject => {
savedObjects = savedObjects.filter((savedObject: SimpleSavedObject<any>) => {
try {
const indexPatternFields = JSON.parse(savedObject.attributes.fields as any);
return indexPatternFields.some((field: any) => {
Expand All @@ -147,7 +160,7 @@ export class IndexPatternSelect extends Component<IndexPatternSelectProps> {
// We need this check to handle the case where search results come back in a different
// order than they were sent out. Only load results for the most recent search.
if (searchValue === this.state.searchValue) {
const options = savedObjects.map(indexPatternSavedObject => {
const options = savedObjects.map((indexPatternSavedObject: SimpleSavedObject<any>) => {
return {
label: indexPatternSavedObject.attributes.title,
value: indexPatternSavedObject.id,
Expand Down Expand Up @@ -185,6 +198,7 @@ export class IndexPatternSelect extends Component<IndexPatternSelectProps> {
indexPatternId, // eslint-disable-line no-unused-vars
placeholder,
onNoIndexPatterns, // eslint-disable-line no-unused-vars
savedObjectsClient, // eslint-disable-line no-unused-vars
...rest
} = this.props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/

/* eslint-disable */

// @ts-ignore
import { KbnError } from '../errors';
import { KbnError } from 'ui/errors';

/**
* when a mapping already exists for a field the user is attempting to add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import { fieldFormats } from 'ui/registry/field_formats';
import { toastNotifications } from 'ui/notify';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { FieldFormat } from '../../field_formats/field_format';
import { getKbnFieldType } from '../../../../../utils/kbn_field_types';
// @ts-ignore
import { getKbnFieldType } from '../../../utils';
import { FieldFormat } from '../../../../../ui/field_formats/field_format';
// @ts-ignore
import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string';
import { IndexPattern } from './_index_pattern';
import { shortenDottedString } from '../../../../../core_plugins/kibana/common/utils/shorten_dotted_string';
import { IndexPattern } from '../index_patterns';

export type FieldSpec = Record<string, any>;
export interface FieldType {
Expand Down Expand Up @@ -98,11 +98,11 @@ export class Field implements FieldType {
// find the type for this field, fallback to unknown type
let type = getKbnFieldType(spec.type);
if (spec.type && !type) {
const title = i18n.translate('common.ui.indexPattern.unknownFieldHeader', {
const title = i18n.translate('data.indexPatterns.unknownFieldHeader', {
values: { type: spec.type },
defaultMessage: 'Unknown field type {type}',
});
const text = i18n.translate('common.ui.indexPattern.unknownFieldErrorMessage', {
const text = i18n.translate('data.indexPatterns.unknownFieldErrorMessage', {
values: { name: spec.name, title: indexPattern.title },
defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

import { IndexedArray } from 'ui/indexed_array';
import { IndexPattern } from 'ui/index_patterns';
import { Field, FieldSpec } from './_field';
import { IndexPattern } from '../index_patterns';
import { Field, FieldSpec } from './field';

export class FieldList extends IndexedArray<Field> {
constructor(indexPattern: IndexPattern, specs: FieldSpec[], shortDotsEnable = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
* under the License.
*/

export {
ILLEGAL_CHARACTERS,
CONTAINS_SPACES,
validateIndexPattern,
} from './validate_index_pattern';
export * from './field_list';
export * from './field';
13 changes: 1 addition & 12 deletions src/legacy/core_plugins/data/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,4 @@
* under the License.
*/

export {
IndexPatternsService,
IndexPatterns,
fixtures,
utils,
// types
IndexPatternsSetup,
IndexPattern,
StaticIndexPattern,
Field,
FieldType,
} from './index_patterns_service';
export * from './index_patterns_service';
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

describe('get computed fields', function () {
describe('IndexPatterns#getComputedFields', function () {

let indexPattern;
let fn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* under the License.
*/

import { IndexPattern } from './index_pattern';
import { GetFieldsOptions, IndexPatternsApiClient } from './index_patterns_api_client';
import { IndexPattern } from './_index_pattern';

/** @internal */
export const createFieldsFetcher = (
indexPattern: IndexPattern,
apiClient: IndexPatternsApiClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IndexPattern } from './index';
import { IndexPattern } from './index_pattern';

export interface PatternCache {
get: (id: string) => IndexPattern;
Expand Down
Loading