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

Revert "Uses core FieldType instead of custom type" #7

Open
wants to merge 20 commits into
base: ts/indexPatterns
Choose a base branch
from
Open
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 packages/kbn-es-query/src/filters/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Field, IndexPattern } from 'ui/index_patterns';
import { Field, IndexPattern } from '../../../../src/legacy/ui/public/index_patterns';
import { CustomFilter, ExistsFilter, PhraseFilter, PhrasesFilter, RangeFilter } from './lib';
import { RangeFilterParams } from './lib/range_filter';

Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/kuery/ast/ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* under the License.
*/

import { StaticIndexPattern } from '../../../../../src/legacy/ui/public/index_patterns';

/**
* WARNING: these typings are incomplete
*/

import { StaticIndexPattern } from 'ui/index_patterns';

export type KueryNode = any;

export interface KueryParseOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class FilterEditorUI extends Component<Props, State> {

if (isCustomEditorOpen) {
const { index, disabled, negate } = this.props.filter.meta;
const newIndex = index || this.props.indexPatterns[0].id;
const newIndex = index || this.props.indexPatterns[0].id!;
const body = JSON.parse(queryDsl);
const filter = buildCustomFilter(newIndex, body, disabled, negate, alias, $state.store);
this.props.onSubmit(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { FilterStateStore, toggleFilterNegated } from '@kbn/es-query';
import { IndexPattern, Field } from '../../../../index';
import { mockFields, mockIndexPattern } from 'ui/index_patterns/fixtures';
import {
buildFilter,
Expand All @@ -42,6 +43,9 @@ import { phraseFilter } from './fixtures/phrase_filter';
import { phrasesFilter } from './fixtures/phrases_filter';
import { rangeFilter } from './fixtures/range_filter';

const mockedFields = mockFields as Field[];
const mockedIndexPattern = mockIndexPattern as IndexPattern;

describe('Filter editor utils', () => {
describe('getQueryDslFromFilter', () => {
it('should return query DSL without meta and $state', () => {
Expand All @@ -53,14 +57,14 @@ describe('Filter editor utils', () => {

describe('getIndexPatternFromFilter', () => {
it('should return the index pattern from the filter', () => {
const indexPattern = getIndexPatternFromFilter(phraseFilter, [mockIndexPattern]);
expect(indexPattern).toBe(mockIndexPattern);
const indexPattern = getIndexPatternFromFilter(phraseFilter, [mockedIndexPattern]);
expect(indexPattern).toBe(mockedIndexPattern);
});
});

describe('getFieldFromFilter', () => {
it('should return the field from the filter', () => {
const field = getFieldFromFilter(phraseFilter, mockIndexPattern);
const field = getFieldFromFilter(phraseFilter, mockedIndexPattern);
expect(field).not.toBeUndefined();
expect(field && field.name).toBe(phraseFilter.meta.key);
});
Expand Down Expand Up @@ -152,12 +156,12 @@ describe('Filter editor utils', () => {

describe('getFilterableFields', () => {
it('returns the list of fields from the given index pattern', () => {
const fieldOptions = getFilterableFields(mockIndexPattern);
const fieldOptions = getFilterableFields(mockedIndexPattern);
expect(fieldOptions.length).toBeGreaterThan(0);
});

it('limits the fields to the filterable fields', () => {
const fieldOptions = getFilterableFields(mockIndexPattern);
const fieldOptions = getFilterableFields(mockedIndexPattern);
const nonFilterableFields = fieldOptions.filter(field => !field.filterable);
expect(nonFilterableFields.length).toBe(0);
});
Expand All @@ -166,67 +170,72 @@ describe('Filter editor utils', () => {
describe('getOperatorOptions', () => {
it('returns range for number fields', () => {
const [field] = mockFields.filter(({ type }) => type === 'number');
const operatorOptions = getOperatorOptions(field);
const operatorOptions = getOperatorOptions(field as Field);
const rangeOperator = operatorOptions.find(operator => operator.type === 'range');
expect(rangeOperator).not.toBeUndefined();
});

it('does not return range for string fields', () => {
const [field] = mockFields.filter(({ type }) => type === 'string');
const operatorOptions = getOperatorOptions(field);
const operatorOptions = getOperatorOptions(field as Field);
const rangeOperator = operatorOptions.find(operator => operator.type === 'range');
expect(rangeOperator).toBeUndefined();
});
});

describe('isFilterValid', () => {
it('should return false if index pattern is not provided', () => {
const isValid = isFilterValid(undefined, mockFields[0], isOperator, 'foo');
const isValid = isFilterValid(undefined, mockedFields[0], isOperator, 'foo');
expect(isValid).toBe(false);
});

it('should return false if field is not provided', () => {
const isValid = isFilterValid(mockIndexPattern, undefined, isOperator, 'foo');
const isValid = isFilterValid(mockedIndexPattern, undefined, isOperator, 'foo');
expect(isValid).toBe(false);
});

it('should return false if operator is not provided', () => {
const isValid = isFilterValid(mockIndexPattern, mockFields[0], undefined, 'foo');
const isValid = isFilterValid(mockedIndexPattern, mockedFields[0], undefined, 'foo');
expect(isValid).toBe(false);
});

it('should return false for phrases filter without phrases', () => {
const isValid = isFilterValid(mockIndexPattern, mockFields[0], isOneOfOperator, []);
const isValid = isFilterValid(mockedIndexPattern, mockedFields[0], isOneOfOperator, []);
expect(isValid).toBe(false);
});

it('should return true for phrases filter with phrases', () => {
const isValid = isFilterValid(mockIndexPattern, mockFields[0], isOneOfOperator, ['foo']);
const isValid = isFilterValid(mockedIndexPattern, mockedFields[0], isOneOfOperator, ['foo']);
expect(isValid).toBe(true);
});

it('should return false for range filter without range', () => {
const isValid = isFilterValid(mockIndexPattern, mockFields[0], isBetweenOperator, undefined);
const isValid = isFilterValid(
mockedIndexPattern,
mockedFields[0],
isBetweenOperator,
undefined
);
expect(isValid).toBe(false);
});

it('should return true for range filter with from', () => {
const isValid = isFilterValid(mockIndexPattern, mockFields[0], isBetweenOperator, {
const isValid = isFilterValid(mockedIndexPattern, mockedFields[0], isBetweenOperator, {
from: 'foo',
});
expect(isValid).toBe(true);
});

it('should return true for range filter with from/to', () => {
const isValid = isFilterValid(mockIndexPattern, mockFields[0], isBetweenOperator, {
const isValid = isFilterValid(mockedIndexPattern, mockedFields[0], isBetweenOperator, {
from: 'foo',
too: 'goo',
});
expect(isValid).toBe(true);
});

it('should return true for exists filter without params', () => {
const isValid = isFilterValid(mockIndexPattern, mockFields[0], existsOperator);
const isValid = isFilterValid(mockedIndexPattern, mockedFields[0], existsOperator);
expect(isValid).toBe(true);
});
});
Expand All @@ -236,7 +245,14 @@ describe('Filter editor utils', () => {
const params = 'foo';
const alias = 'bar';
const state = FilterStateStore.APP_STATE;
const filter = buildFilter(mockIndexPattern, mockFields[0], isOperator, params, alias, state);
const filter = buildFilter(
mockedIndexPattern,
mockedFields[0],
isOperator,
params,
alias,
state
);
expect(filter.meta.negate).toBe(isOperator.negate);
expect(filter.meta.alias).toBe(alias);

Expand All @@ -251,8 +267,8 @@ describe('Filter editor utils', () => {
const alias = 'bar';
const state = FilterStateStore.APP_STATE;
const filter = buildFilter(
mockIndexPattern,
mockFields[0],
mockedIndexPattern,
mockedFields[0],
isOneOfOperator,
params,
alias,
Expand All @@ -272,8 +288,8 @@ describe('Filter editor utils', () => {
const alias = 'bar';
const state = FilterStateStore.APP_STATE;
const filter = buildFilter(
mockIndexPattern,
mockFields[0],
mockedIndexPattern,
mockedFields[0],
isBetweenOperator,
params,
alias,
Expand All @@ -292,8 +308,8 @@ describe('Filter editor utils', () => {
const alias = 'bar';
const state = FilterStateStore.APP_STATE;
const filter = buildFilter(
mockIndexPattern,
mockFields[0],
mockedIndexPattern,
mockedFields[0],
existsOperator,
params,
alias,
Expand All @@ -312,8 +328,8 @@ describe('Filter editor utils', () => {
const alias = 'bar';
const state = FilterStateStore.APP_STATE;
const filter = buildFilter(
mockIndexPattern,
mockFields[0],
mockedIndexPattern,
mockedFields[0],
doesNotExistOperator,
params,
alias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Filter, FilterStateStore } from '@kbn/es-query';
import { FilterStateManager } from './filter_state_manager';
import { FilterManager } from './filter_manager';

import { IndexPatterns } from 'ui/index_patterns';
import { getFilter } from './test_helpers/get_stub_filter';
import { StubIndexPatterns } from './test_helpers/stub_index_pattern';
import { StubState } from './test_helpers/stub_state';
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('filter_manager', () => {
appStateStub = new StubState();
globalStateStub = new StubState();
indexPatterns = new StubIndexPatterns();
filterManager = new FilterManager(indexPatterns);
filterManager = new FilterManager(indexPatterns as IndexPatterns);
readyFilters = getFiltersArray();

// FilterStateManager is tested indirectly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { FilterStateStore } from '@kbn/es-query';
import { Subscription } from 'rxjs';
import { FilterStateManager } from './filter_state_manager';

import { IndexPatterns } from 'ui/index_patterns';
import { StubState } from './test_helpers/stub_state';
import { getFilter } from './test_helpers/get_stub_filter';
import { FilterManager } from './filter_manager';
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('filter_state_manager', () => {
appStateStub = new StubState();
globalStateStub = new StubState();
const indexPatterns = new StubIndexPatterns();
filterManager = new FilterManager(indexPatterns);
filterManager = new FilterManager(indexPatterns as IndexPatterns);
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface DataSetup {
export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from './expressions';

/** @public types */
export { IndexPattern, StaticIndexPattern, StaticIndexPatternField, Field } from './index_patterns';
export { IndexPattern, StaticIndexPattern, Field } from './index_patterns';
export { Query } from './query';
export { SearchBar, SearchBarProps } from './search';
export { FilterManager, FilterStateManager, uniqFilters } from './filter/filter_manager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ export {
IndexPatternsSetup,
IndexPattern,
StaticIndexPattern,
StaticIndexPatternField,
Field,
} from './index_patterns_service';
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { IndexPatterns } from 'ui/index_patterns/index';
// @ts-ignore
import { validateIndexPattern } from 'ui/index_patterns/index';

// IndexPattern, StaticIndexPattern, StaticIndexPatternField, Field
// IndexPattern, StaticIndexPattern, Field
import * as types from 'ui/index_patterns';

const config = chrome.getUiSettingsClient();
Expand Down Expand Up @@ -86,8 +86,5 @@ export type IndexPattern = types.IndexPattern;
/** @public */
export type StaticIndexPattern = types.StaticIndexPattern;

/** @public */
export type StaticIndexPatternField = types.StaticIndexPatternField;

/** @public */
export type Field = types.Field;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import React from 'react';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import './query_bar.test.mocks';
import { QueryBar } from './query_bar';
import { IndexPattern } from '../../../index';

const noop = () => {
return;
Expand Down Expand Up @@ -63,7 +64,7 @@ const mockIndexPattern = {
searchable: true,
},
],
};
} as IndexPattern;

describe('QueryBar', () => {
const QUERY_INPUT_SELECTOR = 'InjectIntl(QueryBarInputUI)';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { QueryLanguageSwitcher } from './language_switcher';
import { QueryBarInput, QueryBarInputUI } from './query_bar_input';
import { IndexPattern } from '../../../index';

const noop = () => {
return;
Expand Down Expand Up @@ -73,7 +74,7 @@ const mockIndexPattern = {
searchable: true,
},
],
};
} as IndexPattern;

describe('QueryBarInput', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import {
getAutocompleteProvider,
} from 'ui/autocomplete_providers';
import { debounce, compact, isEqual, omit } from 'lodash';
import { IndexPattern, StaticIndexPattern } from 'ui/index_patterns';
import { PersistedLog } from 'ui/persisted_log';
import chrome from 'ui/chrome';
import { kfetch } from 'ui/kfetch';
import { Storage } from 'ui/storage';
import { localStorage } from 'ui/storage/storage_service';
import { IndexPattern, StaticIndexPattern } from '../../../../public';
import { Query } from '../index';
import { fromUser, matchPairs, toUser } from '../lib';
import { QueryLanguageSwitcher } from './language_switcher';
Expand Down Expand Up @@ -111,7 +111,7 @@ export class QueryBarInputUI extends Component<Props, State> {
indexPattern => typeof indexPattern !== 'string'
) as IndexPattern[];

const objectPatternsFromStrings = await fetchIndexPatterns(stringPatterns);
const objectPatternsFromStrings = (await fetchIndexPatterns(stringPatterns)) as IndexPattern[];

this.setState({
indexPatterns: [...objectPatterns, ...objectPatternsFromStrings],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { SearchBar } from './search_bar';

import { IndexPattern } from '../../../../public';

jest.mock('../../../filter/filter_bar', () => {
return {
FilterBar: () => <div className="filterBar"></div>,
Expand Down Expand Up @@ -65,7 +67,7 @@ const mockIndexPattern = {
searchable: true,
},
],
};
} as IndexPattern;

const kqlQuery = {
query: 'response:200',
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/core_plugins/kibana/public/context/api/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// @ts-ignore
import { SearchSourceProvider, SearchSource } from 'ui/courier';
import { IPrivate } from 'ui/private';
import { IndexPatternEnhanced, IndexPatternGetProvider } from 'ui/index_patterns/_index_pattern';
import { Filter } from '@kbn/es-query';
import { IndexPatterns, IndexPattern } from 'ui/index_patterns';
import { reverseSortDir, SortDirection } from './utils/sorting';
import { extractNanos, convertIsoToMillis } from './utils/date_conversion';
import { fetchHitsInInterval } from './utils/fetch_hits_in_interval';
Expand All @@ -42,7 +42,7 @@ const DAY_MILLIS = 24 * 60 * 60 * 1000;
// look from 1 day up to 10000 days into the past and future
const LOOKUP_OFFSETS = [0, 1, 7, 30, 365, 10000].map(days => days * DAY_MILLIS);

function fetchContextProvider(indexPatterns: IndexPatternGetProvider, Private: IPrivate) {
function fetchContextProvider(indexPatterns: IndexPatterns, Private: IPrivate) {
const SearchSourcePrivate: any = Private(SearchSourceProvider);

return {
Expand Down Expand Up @@ -112,7 +112,7 @@ function fetchContextProvider(indexPatterns: IndexPatternGetProvider, Private: I
return documents;
}

async function createSearchSource(indexPattern: IndexPatternEnhanced, filters: Filter[]) {
async function createSearchSource(indexPattern: IndexPattern, filters: Filter[]) {
return new SearchSourcePrivate()
.setParent(false)
.setField('index', indexPattern)
Expand Down
Loading