[data views] Rename a bunch of index pattern code references to data views (#112770)
* rename a bunch of index pattern references to data views
This commit is contained in:
parent
1adb492e15
commit
4b71c435a9
|
@ -59,9 +59,7 @@ const createDashboardAppStateServices = () => {
|
|||
const defaults = makeDefaultServices();
|
||||
const indexPatterns = {} as IndexPatternsContract;
|
||||
const defaultIndexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IIndexPattern;
|
||||
indexPatterns.ensureDefaultIndexPattern = jest
|
||||
.fn()
|
||||
.mockImplementation(() => Promise.resolve(true));
|
||||
indexPatterns.ensureDefaultDataView = jest.fn().mockImplementation(() => Promise.resolve(true));
|
||||
indexPatterns.getDefault = jest
|
||||
.fn()
|
||||
.mockImplementation(() => Promise.resolve(defaultIndexPattern));
|
||||
|
|
|
@ -51,7 +51,7 @@ export const loadSavedDashboardState = async ({
|
|||
notifications.toasts.addWarning(getDashboard60Warning());
|
||||
return;
|
||||
}
|
||||
await indexPatterns.ensureDefaultIndexPattern();
|
||||
await indexPatterns.ensureDefaultDataView();
|
||||
let savedDashboard: DashboardSavedObject | undefined;
|
||||
try {
|
||||
savedDashboard = (await savedDashboards.get(savedDashboardId)) as DashboardSavedObject;
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
*/
|
||||
|
||||
import { stubFieldSpecMap, stubLogstashFieldSpecMap } from './field.stub';
|
||||
import { createStubIndexPattern } from './data_views/index_pattern.stub';
|
||||
export { createStubIndexPattern } from './data_views/index_pattern.stub';
|
||||
import { createStubDataView } from './data_views/data_view.stub';
|
||||
export {
|
||||
createStubDataView,
|
||||
createStubDataView as createStubIndexPattern,
|
||||
} from './data_views/data_view.stub';
|
||||
import { SavedObject } from '../../../../core/types';
|
||||
import { IndexPatternAttributes } from '../types';
|
||||
import { DataViewAttributes } from '../types';
|
||||
|
||||
export const stubIndexPattern = createStubIndexPattern({
|
||||
export const stubDataView = createStubDataView({
|
||||
spec: {
|
||||
id: 'logstash-*',
|
||||
fields: stubFieldSpecMap,
|
||||
|
@ -21,7 +24,9 @@ export const stubIndexPattern = createStubIndexPattern({
|
|||
},
|
||||
});
|
||||
|
||||
export const stubIndexPatternWithoutTimeField = createStubIndexPattern({
|
||||
export const stubIndexPattern = stubDataView;
|
||||
|
||||
export const stubDataViewWithoutTimeField = createStubDataView({
|
||||
spec: {
|
||||
id: 'logstash-*',
|
||||
fields: stubFieldSpecMap,
|
||||
|
@ -29,7 +34,9 @@ export const stubIndexPatternWithoutTimeField = createStubIndexPattern({
|
|||
},
|
||||
});
|
||||
|
||||
export const stubLogstashIndexPattern = createStubIndexPattern({
|
||||
export const stubIndexPatternWithoutTimeField = stubDataViewWithoutTimeField;
|
||||
|
||||
export const stubLogstashDataView = createStubDataView({
|
||||
spec: {
|
||||
id: 'logstash-*',
|
||||
title: 'logstash-*',
|
||||
|
@ -38,9 +45,11 @@ export const stubLogstashIndexPattern = createStubIndexPattern({
|
|||
},
|
||||
});
|
||||
|
||||
export function stubbedSavedObjectIndexPattern(
|
||||
export const stubLogstashIndexPattern = stubLogstashDataView;
|
||||
|
||||
export function stubbedSavedObjectDataView(
|
||||
id: string | null = null
|
||||
): SavedObject<IndexPatternAttributes> {
|
||||
): SavedObject<DataViewAttributes> {
|
||||
return {
|
||||
id: id ?? '',
|
||||
type: 'index-pattern',
|
||||
|
@ -53,3 +62,5 @@ export function stubbedSavedObjectIndexPattern(
|
|||
references: [],
|
||||
};
|
||||
}
|
||||
|
||||
export const stubbedSavedObjectIndexPattern = stubbedSavedObjectDataView;
|
|
@ -6,18 +6,18 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { IndexPattern } from './data_view';
|
||||
import { DataView } from './data_view';
|
||||
import { DataViewSpec } from '../types';
|
||||
import { FieldFormatsStartCommon } from '../../../../field_formats/common';
|
||||
import { fieldFormatsMock } from '../../../../field_formats/common/mocks';
|
||||
|
||||
/**
|
||||
* Create a custom stub index pattern. Use it in your unit tests where an {@link IndexPattern} expected.
|
||||
* Create a custom stub index pattern. Use it in your unit tests where an {@link DataView} expected.
|
||||
* @param spec - Serialized index pattern object
|
||||
* @param opts - Specify index pattern options
|
||||
* @param deps - Optionally provide dependencies, you can provide a custom field formats implementation, by default a dummy mock is used
|
||||
*
|
||||
* @returns - an {@link IndexPattern} instance
|
||||
* @returns - an {@link DataView} instance
|
||||
*
|
||||
*
|
||||
* @example
|
||||
|
@ -32,7 +32,7 @@ import { fieldFormatsMock } from '../../../../field_formats/common/mocks';
|
|||
*
|
||||
* ```
|
||||
*/
|
||||
export const createStubIndexPattern = ({
|
||||
export const createStubDataView = ({
|
||||
spec,
|
||||
opts,
|
||||
deps,
|
||||
|
@ -45,12 +45,10 @@ export const createStubIndexPattern = ({
|
|||
deps?: {
|
||||
fieldFormats?: FieldFormatsStartCommon;
|
||||
};
|
||||
}): IndexPattern => {
|
||||
const indexPattern = new IndexPattern({
|
||||
}): DataView =>
|
||||
new DataView({
|
||||
spec,
|
||||
metaFields: opts?.metaFields ?? ['_id', '_type', '_source'],
|
||||
shortDotsEnable: opts?.shortDotsEnable,
|
||||
fieldFormats: deps?.fieldFormats ?? fieldFormatsMock,
|
||||
});
|
||||
return indexPattern;
|
||||
};
|
|
@ -18,7 +18,7 @@ import { fieldFormatsMock } from '../../../../field_formats/common/mocks';
|
|||
import { FieldFormat } from '../../../../field_formats/common';
|
||||
import { RuntimeField } from '../types';
|
||||
import { stubLogstashFields } from '../field.stub';
|
||||
import { stubbedSavedObjectIndexPattern } from '../index_pattern.stub';
|
||||
import { stubbedSavedObjectIndexPattern } from '../data_view.stub';
|
||||
|
||||
class MockFieldFormatter {}
|
||||
|
|
@ -170,7 +170,7 @@ export class DataView implements IIndexPattern {
|
|||
|
||||
// Date value returned in "_source" could be in any number of formats
|
||||
// Use a docvalue for each date field to ensure standardized formats when working with date fields
|
||||
// indexPattern.flattenHit will override "_source" values when the same field is also defined in "fields"
|
||||
// dataView.flattenHit will override "_source" values when the same field is also defined in "fields"
|
||||
const docvalueFields = reject(this.fields.getByType('date'), 'scripted').map((dateField) => {
|
||||
return {
|
||||
field: dateField.name,
|
||||
|
|
|
@ -11,7 +11,7 @@ import { DataViewsService, DataView } from '.';
|
|||
import { fieldFormatsMock } from '../../../../field_formats/common/mocks';
|
||||
|
||||
import { UiSettingsCommon, SavedObjectsClientCommon, SavedObject } from '../types';
|
||||
import { stubbedSavedObjectIndexPattern } from '../index_pattern.stub';
|
||||
import { stubbedSavedObjectIndexPattern } from '../data_view.stub';
|
||||
|
||||
const createFieldsFetcher = jest.fn().mockImplementation(() => ({
|
||||
getFieldsForWildcard: jest.fn().mockImplementation(() => {
|
|
@ -77,9 +77,9 @@ export class DataViewsService {
|
|||
private fieldFormats: FieldFormatsStartCommon;
|
||||
private onNotification: OnNotification;
|
||||
private onError: OnError;
|
||||
private indexPatternCache: ReturnType<typeof createDataViewCache>;
|
||||
private dataViewCache: ReturnType<typeof createDataViewCache>;
|
||||
|
||||
ensureDefaultIndexPattern: EnsureDefaultDataView;
|
||||
ensureDefaultDataView: EnsureDefaultDataView;
|
||||
|
||||
constructor({
|
||||
uiSettings,
|
||||
|
@ -96,12 +96,9 @@ export class DataViewsService {
|
|||
this.fieldFormats = fieldFormats;
|
||||
this.onNotification = onNotification;
|
||||
this.onError = onError;
|
||||
this.ensureDefaultIndexPattern = createEnsureDefaultDataView(
|
||||
uiSettings,
|
||||
onRedirectNoIndexPattern
|
||||
);
|
||||
this.ensureDefaultDataView = createEnsureDefaultDataView(uiSettings, onRedirectNoIndexPattern);
|
||||
|
||||
this.indexPatternCache = createDataViewCache();
|
||||
this.dataViewCache = createDataViewCache();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,9 +187,9 @@ export class DataViewsService {
|
|||
clearCache = (id?: string) => {
|
||||
this.savedObjectsCache = null;
|
||||
if (id) {
|
||||
this.indexPatternCache.clear(id);
|
||||
this.dataViewCache.clear(id);
|
||||
} else {
|
||||
this.indexPatternCache.clearAll();
|
||||
this.dataViewCache.clearAll();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -505,12 +502,11 @@ export class DataViewsService {
|
|||
|
||||
get = async (id: string): Promise<DataView> => {
|
||||
const indexPatternPromise =
|
||||
this.indexPatternCache.get(id) ||
|
||||
this.indexPatternCache.set(id, this.getSavedObjectAndInit(id));
|
||||
this.dataViewCache.get(id) || this.dataViewCache.set(id, this.getSavedObjectAndInit(id));
|
||||
|
||||
// don't cache failed requests
|
||||
indexPatternPromise.catch(() => {
|
||||
this.indexPatternCache.clear(id);
|
||||
this.dataViewCache.clear(id);
|
||||
});
|
||||
|
||||
return indexPatternPromise;
|
||||
|
@ -580,7 +576,7 @@ export class DataViewsService {
|
|||
)) as SavedObject<DataViewAttributes>;
|
||||
|
||||
const createdIndexPattern = await this.initFromSavedObject(response);
|
||||
this.indexPatternCache.set(createdIndexPattern.id!, Promise.resolve(createdIndexPattern));
|
||||
this.dataViewCache.set(createdIndexPattern.id!, Promise.resolve(createdIndexPattern));
|
||||
if (this.savedObjectsCache) {
|
||||
this.savedObjectsCache.push(response as SavedObject<IndexPatternListSavedObjectAttrs>);
|
||||
}
|
||||
|
@ -668,7 +664,7 @@ export class DataViewsService {
|
|||
indexPattern.version = samePattern.version;
|
||||
|
||||
// Clear cache
|
||||
this.indexPatternCache.clear(indexPattern.id!);
|
||||
this.dataViewCache.clear(indexPattern.id!);
|
||||
|
||||
// Try the save again
|
||||
return this.updateSavedObject(indexPattern, saveAttempts, ignoreErrors);
|
||||
|
@ -682,7 +678,7 @@ export class DataViewsService {
|
|||
* @param indexPatternId: Id of kibana Index Pattern to delete
|
||||
*/
|
||||
async delete(indexPatternId: string) {
|
||||
this.indexPatternCache.clear(indexPatternId);
|
||||
this.dataViewCache.clear(indexPatternId);
|
||||
return this.savedObjectsClient.delete(DATA_VIEW_SAVED_OBJECT_TYPE, indexPatternId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { IndexPattern } from './data_view';
|
||||
import { DataView } from './data_view';
|
||||
|
||||
import { fieldFormatsMock } from '../../../../field_formats/common/mocks';
|
||||
import { flattenHitWrapper } from './flatten_hit';
|
||||
import { stubbedSavedObjectIndexPattern } from '../index_pattern.stub';
|
||||
import { stubbedSavedObjectIndexPattern } from '../data_view.stub';
|
||||
|
||||
class MockFieldFormatter {}
|
||||
|
||||
|
@ -24,7 +24,7 @@ function create(id: string) {
|
|||
attributes: { timeFieldName, fields, title },
|
||||
} = stubbedSavedObjectIndexPattern(id);
|
||||
|
||||
return new IndexPattern({
|
||||
return new DataView({
|
||||
spec: {
|
||||
id,
|
||||
type,
|
||||
|
@ -41,7 +41,7 @@ function create(id: string) {
|
|||
}
|
||||
|
||||
describe('flattenHit', () => {
|
||||
let indexPattern: IndexPattern;
|
||||
let indexPattern: DataView;
|
||||
|
||||
// create an indexPattern instance for each test
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -103,11 +103,11 @@ function decorateFlattenedWrapper(hit: Record<string, any>, metaFields: Record<s
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export function flattenHitWrapper(indexPattern: DataView, metaFields = {}, cache = new WeakMap()) {
|
||||
export function flattenHitWrapper(dataView: DataView, metaFields = {}, cache = new WeakMap()) {
|
||||
return function cachedFlatten(hit: Record<string, any>, deep = false) {
|
||||
const decorateFlattened = decorateFlattenedWrapper(hit, metaFields);
|
||||
const cached = cache.get(hit);
|
||||
const flattened = cached || flattenHit(indexPattern, hit, deep);
|
||||
const flattened = cached || flattenHit(dataView, hit, deep);
|
||||
if (!cached) {
|
||||
cache.set(hit, { ...flattened });
|
||||
}
|
||||
|
|
|
@ -15,24 +15,24 @@ const partialFormattedCache = new WeakMap();
|
|||
|
||||
// Takes a hit, merges it with any stored/scripted fields, and with the metaFields
|
||||
// returns a formatted version
|
||||
export function formatHitProvider(indexPattern: DataView, defaultFormat: any) {
|
||||
export function formatHitProvider(dataView: DataView, defaultFormat: any) {
|
||||
function convert(
|
||||
hit: Record<string, any>,
|
||||
val: any,
|
||||
fieldName: string,
|
||||
type: FieldFormatsContentType = 'html'
|
||||
) {
|
||||
const field = indexPattern.fields.getByName(fieldName);
|
||||
const format = field ? indexPattern.getFormatterForField(field) : defaultFormat;
|
||||
const field = dataView.fields.getByName(fieldName);
|
||||
const format = field ? dataView.getFormatterForField(field) : defaultFormat;
|
||||
|
||||
return format.convert(val, type, { field, hit, indexPattern });
|
||||
return format.convert(val, type, { field, hit, indexPattern: dataView });
|
||||
}
|
||||
|
||||
function formatHit(hit: Record<string, any>, type: string = 'html') {
|
||||
if (type === 'text') {
|
||||
// formatHit of type text is for react components to get rid of <span ng-non-bindable>
|
||||
// since it's currently just used at the discover's doc view table, caching is not necessary
|
||||
const flattened = indexPattern.flattenHit(hit);
|
||||
const flattened = dataView.flattenHit(hit);
|
||||
const result: Record<string, any> = {};
|
||||
for (const [key, value] of Object.entries(flattened)) {
|
||||
result[key] = convert(hit, value, key, type);
|
||||
|
@ -53,7 +53,7 @@ export function formatHitProvider(indexPattern: DataView, defaultFormat: any) {
|
|||
const cache: Record<string, any> = {};
|
||||
formattedCache.set(hit, cache);
|
||||
|
||||
_.forOwn(indexPattern.flattenHit(hit), function (val: any, fieldName?: string) {
|
||||
_.forOwn(dataView.flattenHit(hit), function (val: any, fieldName?: string) {
|
||||
// sync the formatted and partial cache
|
||||
if (!fieldName) {
|
||||
return;
|
||||
|
@ -77,7 +77,7 @@ export function formatHitProvider(indexPattern: DataView, defaultFormat: any) {
|
|||
partialFormattedCache.set(hit, partials);
|
||||
}
|
||||
|
||||
const val = fieldName === '_source' ? hit._source : indexPattern.flattenHit(hit)[fieldName];
|
||||
const val = fieldName === '_source' ? hit._source : dataView.flattenHit(hit)[fieldName];
|
||||
return convert(hit, val, fieldName);
|
||||
};
|
||||
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
export class DuplicateDataViewError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'DuplicateIndexPatternError';
|
||||
this.name = 'DuplicateDataViewError';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { FieldSpec, IndexPatternField } from '.';
|
||||
import { FieldSpec, DataViewField } from '.';
|
||||
|
||||
export const createIndexPatternFieldStub = ({ spec }: { spec: FieldSpec }): IndexPatternField => {
|
||||
return new IndexPatternField(spec);
|
||||
export const createIndexPatternFieldStub = ({ spec }: { spec: FieldSpec }): DataViewField => {
|
||||
return new DataViewField(spec);
|
||||
};
|
||||
|
||||
export const stubFieldSpecMap: Record<string, FieldSpec> = {
|
||||
|
@ -71,7 +71,7 @@ export const stubFieldSpecMap: Record<string, FieldSpec> = {
|
|||
},
|
||||
};
|
||||
|
||||
export const stubFields: IndexPatternField[] = Object.values(stubFieldSpecMap).map((spec) =>
|
||||
export const stubFields: DataViewField[] = Object.values(stubFieldSpecMap).map((spec) =>
|
||||
createIndexPatternFieldStub({ spec })
|
||||
);
|
||||
|
||||
|
@ -404,6 +404,6 @@ export const stubLogstashFieldSpecMap: Record<string, FieldSpec> = {
|
|||
},
|
||||
};
|
||||
|
||||
export const stubLogstashFields: IndexPatternField[] = Object.values(stubLogstashFieldSpecMap).map(
|
||||
export const stubLogstashFields: DataViewField[] = Object.values(stubLogstashFieldSpecMap).map(
|
||||
(spec) => createIndexPatternFieldStub({ spec })
|
||||
);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { IndexPatternField } from './index_pattern_field';
|
||||
import { IndexPatternField } from './data_view_field';
|
||||
import { IndexPattern } from '..';
|
||||
import { KBN_FIELD_TYPES } from '../../../common';
|
||||
import { FieldSpec, RuntimeField } from '../types';
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import { findIndex } from 'lodash';
|
||||
import { IFieldType } from './types';
|
||||
import { DataViewField } from './index_pattern_field';
|
||||
import { DataViewField } from './data_view_field';
|
||||
import { FieldSpec, DataViewFieldMap } from '../types';
|
||||
import { DataView } from '../data_views';
|
||||
|
||||
|
|
|
@ -9,4 +9,4 @@
|
|||
export * from './types';
|
||||
export { isFilterable, isNestedField } from './utils';
|
||||
export * from './field_list';
|
||||
export * from './index_pattern_field';
|
||||
export * from './data_view_field';
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
export { DataViewMissingIndices } from './errors';
|
||||
export { getTitle } from './get_title';
|
||||
export { isDefault } from './is_default';
|
||||
|
||||
export * from './types';
|
||||
export { validateDataView } from './validate_index_pattern';
|
||||
export { validateDataView } from './validate_data_view';
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* 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 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { IIndexPattern } from '../..';
|
||||
|
||||
export const isDefault = (indexPattern: IIndexPattern) => {
|
||||
// Default index patterns don't have `type` defined.
|
||||
return !indexPattern.type;
|
||||
};
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import { CONTAINS_SPACES_KEY, ILLEGAL_CHARACTERS_KEY, ILLEGAL_CHARACTERS_VISIBLE } from './types';
|
||||
|
||||
import { validateDataView } from './validate_index_pattern';
|
||||
import { validateDataView } from './validate_data_view';
|
||||
|
||||
describe('Index Pattern Utils', () => {
|
||||
describe('Validation', () => {
|
|
@ -7,4 +7,4 @@
|
|||
*/
|
||||
|
||||
export * from './fields/fields.mocks';
|
||||
export * from './data_views/index_pattern.stub';
|
||||
export * from './data_views/data_view.stub';
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
*/
|
||||
|
||||
export * from './data_views/field.stub';
|
||||
export * from './data_views/index_pattern.stub';
|
||||
export * from './data_views/data_view.stub';
|
||||
export * from './es_query/stubs';
|
||||
|
|
|
@ -10,15 +10,15 @@ import { CoreSetup } from 'kibana/public';
|
|||
import { FieldFormatsStartCommon } from '../../../../field_formats/common';
|
||||
import { getFieldFormatsRegistry } from '../../../../field_formats/public/mocks';
|
||||
import * as commonStubs from '../../../common/stubs';
|
||||
import { IndexPattern, IndexPatternSpec } from '../../../common';
|
||||
import { DataView, DataViewSpec } from '../../../common';
|
||||
import { coreMock } from '../../../../../core/public/mocks';
|
||||
/**
|
||||
* Create a custom stub index pattern. Use it in your unit tests where an {@link IndexPattern} expected.
|
||||
* Create a custom stub index pattern. Use it in your unit tests where an {@link DataView} expected.
|
||||
* @param spec - Serialized index pattern object
|
||||
* @param opts - Specify index pattern options
|
||||
* @param deps - Optionally provide dependencies, you can provide a custom field formats implementation, by default client side registry with real formatters implementation is used
|
||||
*
|
||||
* @returns - an {@link IndexPattern} instance
|
||||
* @returns - an {@link DataView} instance
|
||||
*
|
||||
* @remark - This is a client side version, a browser-agnostic version is available in {@link commonStubs | common}.
|
||||
* The main difference is that client side version by default uses client side field formats service, where common version uses a dummy field formats mock.
|
||||
|
@ -35,12 +35,12 @@ import { coreMock } from '../../../../../core/public/mocks';
|
|||
*
|
||||
* ```
|
||||
*/
|
||||
export const createStubIndexPattern = ({
|
||||
export const createStubDataView = ({
|
||||
spec,
|
||||
opts,
|
||||
deps,
|
||||
}: {
|
||||
spec: IndexPatternSpec;
|
||||
spec: DataViewSpec;
|
||||
opts?: {
|
||||
shortDotsEnable?: boolean;
|
||||
metaFields?: string[];
|
||||
|
@ -49,8 +49,8 @@ export const createStubIndexPattern = ({
|
|||
fieldFormats?: FieldFormatsStartCommon;
|
||||
core?: CoreSetup;
|
||||
};
|
||||
}): IndexPattern => {
|
||||
return commonStubs.createStubIndexPattern({
|
||||
}): DataView => {
|
||||
return commonStubs.createStubDataView({
|
||||
spec,
|
||||
opts,
|
||||
deps: {
|
|
@ -6,16 +6,16 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { http } from './index_patterns_api_client.test.mock';
|
||||
import { IndexPatternsApiClient } from './index_patterns_api_client';
|
||||
import { http } from './data_views_api_client.test.mock';
|
||||
import { DataViewsApiClient } from './data_views_api_client';
|
||||
|
||||
describe('IndexPatternsApiClient', () => {
|
||||
let fetchSpy: jest.SpyInstance;
|
||||
let indexPatternsApiClient: IndexPatternsApiClient;
|
||||
let indexPatternsApiClient: DataViewsApiClient;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchSpy = jest.spyOn(http, 'fetch').mockImplementation(() => Promise.resolve({}));
|
||||
indexPatternsApiClient = new IndexPatternsApiClient(http);
|
||||
indexPatternsApiClient = new DataViewsApiClient(http);
|
||||
});
|
||||
|
||||
test('uses the right URI to fetch fields for time patterns', async function () {
|
|
@ -10,13 +10,13 @@ import { HttpSetup } from 'src/core/public';
|
|||
import { DataViewMissingIndices } from '../../../common/data_views/lib';
|
||||
import {
|
||||
GetFieldsOptions,
|
||||
IIndexPatternsApiClient,
|
||||
IDataViewsApiClient,
|
||||
GetFieldsOptionsTimePattern,
|
||||
} from '../../../common/data_views/types';
|
||||
|
||||
const API_BASE_URL: string = `/api/index_patterns/`;
|
||||
|
||||
export class IndexPatternsApiClient implements IIndexPatternsApiClient {
|
||||
export class DataViewsApiClient implements IDataViewsApiClient {
|
||||
private http: HttpSetup;
|
||||
|
||||
constructor(http: HttpSetup) {
|
|
@ -8,4 +8,4 @@
|
|||
|
||||
export * from '../../../common/data_views/data_views';
|
||||
export * from './redirect_no_index_pattern';
|
||||
export * from './index_patterns_api_client';
|
||||
export * from './data_views_api_client';
|
||||
|
|
|
@ -12,7 +12,6 @@ export {
|
|||
ILLEGAL_CHARACTERS_VISIBLE,
|
||||
ILLEGAL_CHARACTERS,
|
||||
validateDataView,
|
||||
isDefault,
|
||||
} from '../../common/data_views/lib';
|
||||
export { flattenHitWrapper, formatHitProvider, onRedirectNoIndexPattern } from './data_views';
|
||||
|
||||
|
@ -22,7 +21,7 @@ export {
|
|||
IndexPatternsService,
|
||||
IndexPatternsContract,
|
||||
IndexPattern,
|
||||
IndexPatternsApiClient,
|
||||
DataViewsApiClient,
|
||||
DataViewsService,
|
||||
DataViewsContract,
|
||||
DataView,
|
||||
|
|
|
@ -45,7 +45,6 @@ import {
|
|||
CONTAINS_SPACES_KEY,
|
||||
ILLEGAL_CHARACTERS_VISIBLE,
|
||||
ILLEGAL_CHARACTERS,
|
||||
isDefault,
|
||||
validateDataView,
|
||||
flattenHitWrapper,
|
||||
} from './data_views';
|
||||
|
@ -58,7 +57,6 @@ export const indexPatterns = {
|
|||
CONTAINS_SPACES_KEY,
|
||||
ILLEGAL_CHARACTERS_VISIBLE,
|
||||
ILLEGAL_CHARACTERS,
|
||||
isDefault,
|
||||
isFilterable,
|
||||
isNestedField,
|
||||
validate: validateDataView,
|
||||
|
|
|
@ -22,9 +22,9 @@ import { SearchService } from './search/search_service';
|
|||
import { QueryService } from './query';
|
||||
import { createIndexPatternSelect } from './ui/index_pattern_select';
|
||||
import {
|
||||
IndexPatternsService,
|
||||
DataViewsService,
|
||||
onRedirectNoIndexPattern,
|
||||
IndexPatternsApiClient,
|
||||
DataViewsApiClient,
|
||||
UiSettingsPublicToCommon,
|
||||
} from './data_views';
|
||||
import {
|
||||
|
@ -145,10 +145,10 @@ export class DataPublicPlugin
|
|||
setOverlays(overlays);
|
||||
setUiSettings(uiSettings);
|
||||
|
||||
const indexPatterns = new IndexPatternsService({
|
||||
const indexPatterns = new DataViewsService({
|
||||
uiSettings: new UiSettingsPublicToCommon(uiSettings),
|
||||
savedObjectsClient: new SavedObjectsClientPublicToCommon(savedObjects.client),
|
||||
apiClient: new IndexPatternsApiClient(http),
|
||||
apiClient: new DataViewsApiClient(http),
|
||||
fieldFormats,
|
||||
onNotification: (toastInputFields) => {
|
||||
notifications.toasts.add(toastInputFields);
|
||||
|
|
|
@ -7,4 +7,4 @@
|
|||
*/
|
||||
|
||||
export * from '../common/stubs';
|
||||
export { createStubIndexPattern } from './data_views/data_views/index_pattern.stub';
|
||||
export { createStubDataView } from './data_views/data_views/data_view.stub';
|
||||
|
|
|
@ -23,11 +23,7 @@ import { METRIC_TYPE } from '@kbn/analytics';
|
|||
import classNames from 'classnames';
|
||||
import { DiscoverNoResults } from '../no_results';
|
||||
import { LoadingSpinner } from '../loading_spinner/loading_spinner';
|
||||
import {
|
||||
esFilters,
|
||||
IndexPatternField,
|
||||
indexPatterns as indexPatternsUtils,
|
||||
} from '../../../../../../../data/public';
|
||||
import { esFilters, IndexPatternField } from '../../../../../../../data/public';
|
||||
import { DiscoverSidebarResponsive } from '../sidebar';
|
||||
import { DiscoverLayoutProps } from './types';
|
||||
import { SEARCH_FIELDS_FROM_SOURCE } from '../../../../../../common';
|
||||
|
@ -79,7 +75,7 @@ export function DiscoverLayout({
|
|||
}, [dataState.fetchStatus]);
|
||||
|
||||
const timeField = useMemo(() => {
|
||||
return indexPatternsUtils.isDefault(indexPattern) ? indexPattern.timeFieldName : undefined;
|
||||
return indexPattern.type !== 'rollup' ? indexPattern.timeFieldName : undefined;
|
||||
}, [indexPattern]);
|
||||
|
||||
const [isSidebarClosed, setIsSidebarClosed] = useState(false);
|
||||
|
|
|
@ -106,7 +106,7 @@ exports[`Discover IndexPattern Management renders correctly 1`] = `
|
|||
}
|
||||
}
|
||||
selectedIndexPattern={
|
||||
IndexPattern {
|
||||
DataView {
|
||||
"allowNoIndex": false,
|
||||
"deleteFieldFormat": [Function],
|
||||
"fieldAttrs": Object {},
|
||||
|
|
|
@ -59,7 +59,7 @@ export function DiscoverMainRoute({ services, history }: DiscoverMainProps) {
|
|||
const savedSearchId = id;
|
||||
|
||||
async function loadDefaultOrCurrentIndexPattern(usedSavedSearch: SavedSearch) {
|
||||
await data.indexPatterns.ensureDefaultIndexPattern();
|
||||
await data.indexPatterns.ensureDefaultDataView();
|
||||
const { appStateContainer } = getState({ history, uiSettings: config });
|
||||
const { index } = appStateContainer.getState();
|
||||
const ip = await loadIndexPattern(index || '', data.indexPatterns, config);
|
||||
|
|
|
@ -10,7 +10,6 @@ import { SORT_DEFAULT_ORDER_SETTING } from '../../../../../common';
|
|||
import { IndexPattern, ISearchSource } from '../../../../../../data/common';
|
||||
import { SortOrder } from '../../../../saved_searches/types';
|
||||
import { DiscoverServices } from '../../../../build_services';
|
||||
import { indexPatterns as indexPatternsUtils } from '../../../../../../data/public';
|
||||
import { getSortForSearchSource } from '../components/doc_table';
|
||||
|
||||
/**
|
||||
|
@ -52,8 +51,7 @@ export function updateSearchSource(
|
|||
// document-like response.
|
||||
.setPreferredSearchStrategyId('default');
|
||||
|
||||
// this is not the default index pattern, it determines that it's not of type rollup
|
||||
if (indexPatternsUtils.isDefault(indexPattern)) {
|
||||
if (indexPattern.type !== 'rollup') {
|
||||
// Set the date range filter fields from timeFilter using the absolute format. Search sessions requires that it be converted from a relative range
|
||||
searchSource.setField('filter', data.query.timefilter.timefilter.createFilter(indexPattern));
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import { coreMock } from '../../../../core/public/mocks';
|
|||
import { dataPluginMock, createSearchSourceMock } from '../../../../plugins/data/public/mocks';
|
||||
import { createStubIndexPattern } from '../../../../plugins/data/common/stubs';
|
||||
import { SavedObjectAttributes, SimpleSavedObject } from 'kibana/public';
|
||||
import { IndexPattern } from '../../../data/common';
|
||||
import { DataView } from '../../../data/common';
|
||||
import { savedObjectsDecoratorRegistryMock } from './decorators/registry.mock';
|
||||
|
||||
describe('Saved Object', () => {
|
||||
|
@ -725,7 +725,7 @@ describe('Saved Object', () => {
|
|||
type: 'dashboard',
|
||||
afterESResp: afterESRespCallback,
|
||||
searchSource: true,
|
||||
indexPattern: { id: indexPatternId } as IndexPattern,
|
||||
indexPattern: { id: indexPatternId } as DataView,
|
||||
};
|
||||
|
||||
stubESResponse(
|
||||
|
@ -752,7 +752,7 @@ describe('Saved Object', () => {
|
|||
return savedObject.init!().then(() => {
|
||||
expect(afterESRespCallback).toHaveBeenCalled();
|
||||
const index = savedObject.searchSource!.getField('index');
|
||||
expect(index instanceof IndexPattern).toBe(true);
|
||||
expect(index instanceof DataView).toBe(true);
|
||||
expect(index!.id).toEqual(indexPatternId);
|
||||
});
|
||||
});
|
||||
|
@ -765,7 +765,7 @@ describe('Saved Object', () => {
|
|||
type: 'dashboard',
|
||||
afterESResp: afterESRespCallback,
|
||||
searchSource: false,
|
||||
indexPattern: { id: indexPatternId } as IndexPattern,
|
||||
indexPattern: { id: indexPatternId } as DataView,
|
||||
};
|
||||
|
||||
stubESResponse(getMockedDocResponse(indexPatternId));
|
||||
|
|
|
@ -162,7 +162,7 @@ export class VisualizePlugin
|
|||
pluginsStart.data.indexPatterns.clearCache();
|
||||
// make sure a default index pattern exists
|
||||
// if not, the page will be redirected to management and visualize won't be rendered
|
||||
await pluginsStart.data.indexPatterns.ensureDefaultIndexPattern();
|
||||
await pluginsStart.data.indexPatterns.ensureDefaultDataView();
|
||||
|
||||
appMounted();
|
||||
|
||||
|
|
|
@ -233,10 +233,10 @@ export class LensPlugin {
|
|||
const getPresentationUtilContext = () =>
|
||||
startServices().plugins.presentationUtil.ContextProvider;
|
||||
|
||||
const ensureDefaultIndexPattern = async () => {
|
||||
const ensureDefaultDataView = async () => {
|
||||
// make sure a default index pattern exists
|
||||
// if not, the page will be redirected to management and visualize won't be rendered
|
||||
await startServices().plugins.data.indexPatterns.ensureDefaultIndexPattern();
|
||||
await startServices().plugins.data.indexPatterns.ensureDefaultDataView();
|
||||
};
|
||||
|
||||
core.application.register({
|
||||
|
@ -261,7 +261,7 @@ export class LensPlugin {
|
|||
const frameStart = this.editorFrameService!.start(coreStart, deps);
|
||||
|
||||
this.stopReportManager = stopReportManager;
|
||||
await ensureDefaultIndexPattern();
|
||||
await ensureDefaultDataView();
|
||||
return mountApp(core, params, {
|
||||
createEditorFrame: frameStart.createInstance,
|
||||
attributeService: getLensAttributeService(coreStart, deps),
|
||||
|
|
Loading…
Reference in a new issue