[Logs UI] Fix the LogStream story to work with KIPs (#100862)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Felix Stürmer 2021-06-04 19:13:35 +02:00 committed by GitHub
parent 7b4b713237
commit 081cf98f61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 21 deletions

View file

@ -3,10 +3,11 @@ import { defer, of, Subject } from 'rxjs';
import { delay } from 'rxjs/operators';
import { I18nProvider } from '@kbn/i18n/react';
import { KBN_FIELD_TYPES } from '../../../../../../src/plugins/data/public';
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { LOG_ENTRIES_SEARCH_STRATEGY } from '../../../common/search_strategies/log_entries/log_entries';
import { createIndexPatternMock, createIndexPatternsMock } from '../../hooks/use_kibana_index_patterns.mock';
import { DEFAULT_SOURCE_CONFIGURATION } from '../../test_utils/source_configuration';
import { generateFakeEntries, ENTRIES_EMPTY } from '../../test_utils/entries';
@ -18,6 +19,45 @@ export const startTimestamp = 1595145600000;
export const endTimestamp = startTimestamp + 15 * 60 * 1000;
export const dataMock = {
indexPatterns: createIndexPatternsMock(500, [
createIndexPatternMock({
id: 'some-test-id',
title: 'mock-index-pattern-*',
timeFieldName: '@timestamp',
fields: [
{
name: '@timestamp',
type: KBN_FIELD_TYPES.DATE,
searchable: true,
aggregatable: true,
},
{
name: 'event.dataset',
type: KBN_FIELD_TYPES.STRING,
searchable: true,
aggregatable: true,
},
{
name: 'host.name',
type: KBN_FIELD_TYPES.STRING,
searchable: true,
aggregatable: true,
},
{
name: 'log.level',
type: KBN_FIELD_TYPES.STRING,
searchable: true,
aggregatable: true,
},
{
name: 'message',
type: KBN_FIELD_TYPES.STRING,
searchable: true,
aggregatable: true,
},
],
})
]),
search: {
search: ({ params }, options) => {
return defer(() => {
@ -68,10 +108,16 @@ export const dataMock = {
};
export const fetch = function (url, params) {
export const fetch = async function (url, params) {
switch (url) {
case '/api/infra/log_source_configurations/default':
return DEFAULT_SOURCE_CONFIGURATION;
case '/api/infra/log_source_configurations/default/status':
return {
data: {
logIndexStatus: 'available',
}
};
default:
return {};
}

View file

@ -21,7 +21,7 @@ import { Pick2 } from '../../common/utility_types';
type MockIndexPattern = Pick<
IndexPattern,
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName'
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName' | 'getComputedFields'
>;
export type MockIndexPatternSpec = Pick<
IIndexPattern,
@ -35,23 +35,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
mockIndexPatterns: MockIndexPatternSpec[];
}> = ({ asyncDelay, children, mockIndexPatterns }) => {
const indexPatterns = useMemo(
() =>
createIndexPatternsMock(
asyncDelay,
mockIndexPatterns.map(({ id, title, type = undefined, fields, timeFieldName }) => {
const indexPatternFields = fields.map((fieldSpec) => new IndexPatternField(fieldSpec));
return {
id,
title,
type,
getTimeField: () => indexPatternFields.find(({ name }) => name === timeFieldName),
isTimeBased: () => timeFieldName != null,
getFieldByName: (fieldName) =>
indexPatternFields.find(({ name }) => name === fieldName),
};
})
),
() => createIndexPatternsMock(asyncDelay, mockIndexPatterns.map(createIndexPatternMock)),
[asyncDelay, mockIndexPatterns]
);
@ -71,7 +55,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
);
};
const createIndexPatternsMock = (
export const createIndexPatternsMock = (
asyncDelay: number,
indexPatterns: MockIndexPattern[]
): {
@ -93,3 +77,36 @@ const createIndexPatternsMock = (
},
};
};
export const createIndexPatternMock = ({
id,
title,
type = undefined,
fields,
timeFieldName,
}: MockIndexPatternSpec): MockIndexPattern => {
const indexPatternFields = fields.map((fieldSpec) => new IndexPatternField(fieldSpec));
return {
id,
title,
type,
getTimeField: () => indexPatternFields.find(({ name }) => name === timeFieldName),
isTimeBased: () => timeFieldName != null,
getFieldByName: (fieldName) => indexPatternFields.find(({ name }) => name === fieldName),
getComputedFields: () => ({
docvalueFields: [],
runtimeFields: indexPatternFields.reduce((accumulatedRuntimeFields, field) => {
if (field.runtimeField != null) {
return {
...accumulatedRuntimeFields,
[field.name]: field.runtimeField,
};
}
return accumulatedRuntimeFields;
}, {}),
scriptFields: {},
storedFields: [],
}),
};
};