Skip to content

Commit

Permalink
Query string input - load index patterns instead of saved objects (#8…
Browse files Browse the repository at this point in the history
…4457)

* load index patterns instead of saved objects
* remove getFromSavedObject
* add test
  • Loading branch information
mattkime authored Dec 6, 2020
1 parent 058f28a commit 2c7a85d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ indexPatterns: {
isFilterable: typeof isFilterable;
isNestedField: typeof isNestedField;
validate: typeof validateIndexPattern;
getFromSavedObject: typeof getFromSavedObject;
flattenHitWrapper: typeof flattenHitWrapper;
formatHitProvider: typeof formatHitProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ describe('IndexPatterns', () => {
expect(indexPatterns.refreshFields).toBeCalled();
});

test('find', async () => {
const search = 'kibana*';
const size = 10;
await indexPatterns.find('kibana*', size);

expect(savedObjectsClient.find).lastCalledWith({
type: 'index-pattern',
fields: ['title'],
search,
searchFields: ['title'],
perPage: size,
});
});

test('createAndSave', async () => {
const title = 'kibana-*';
indexPatterns.createSavedObject = jest.fn();
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/plugins/data/common/index_patterns/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

export { IndexPatternMissingIndices } from './errors';
export { getTitle } from './get_title';
export { getFromSavedObject } from './get_from_saved_object';
export { isDefault } from './is_default';

export * from './types';
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ import {
ILLEGAL_CHARACTERS,
isDefault,
validateIndexPattern,
getFromSavedObject,
flattenHitWrapper,
formatHitProvider,
} from './index_patterns';
Expand All @@ -252,7 +251,6 @@ export const indexPatterns = {
isFilterable,
isNestedField,
validate: validateIndexPattern,
getFromSavedObject,
flattenHitWrapper,
formatHitProvider,
};
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export {
ILLEGAL_CHARACTERS_VISIBLE,
ILLEGAL_CHARACTERS,
validateIndexPattern,
getFromSavedObject,
isDefault,
} from '../../common/index_patterns/lib';
export { flattenHitWrapper, formatHitProvider, onRedirectNoIndexPattern } from './index_patterns';
Expand Down
43 changes: 20 additions & 23 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import { Required } from '@kbn/utility-types';
import * as Rx from 'rxjs';
import { SavedObject } from 'kibana/server';
import { SavedObject as SavedObject_2 } from 'src/core/server';
import { SavedObject as SavedObject_3 } from 'src/core/public';
import { SavedObjectReference } from 'src/core/types';
import { SavedObjectsClientContract } from 'src/core/public';
import { SavedObjectsFindResponse } from 'kibana/server';
Expand Down Expand Up @@ -1336,7 +1335,6 @@ export const indexPatterns: {
isFilterable: typeof isFilterable;
isNestedField: typeof isNestedField;
validate: typeof validateIndexPattern;
getFromSavedObject: typeof getFromSavedObject;
flattenHitWrapper: typeof flattenHitWrapper;
formatHitProvider: typeof formatHitProvider;
};
Expand Down Expand Up @@ -2436,27 +2434,26 @@ export const UI_SETTINGS: {
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:220:23 - (ae-forgotten-export) The symbol "datatableToCSV" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:246:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:246:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:246:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:246:27 - (ae-forgotten-export) The symbol "getFromSavedObject" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:246:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:246:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:409:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:409:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:409:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:409:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:411:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:421:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:423:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:424:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:428:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:429:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:432:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:433:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:436:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:245:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:245:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:245:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:245:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:245:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:407:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:407:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:407:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:407:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:409:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:410:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:419:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:420:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:421:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:426:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:427:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:430:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:431:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:434:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:45:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/search/session/session_service.ts:46:5 - (ae-forgotten-export) The symbol "UrlGeneratorStateMapping" needs to be exported by the entry point index.d.ts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,26 @@
* under the License.
*/
import { isEmpty } from 'lodash';
import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public';
import { indexPatterns, IndexPatternAttributes } from '../..';
import { IndexPatternsContract } from '../..';

export async function fetchIndexPatterns(
savedObjectsClient: SavedObjectsClientContract,
indexPatternStrings: string[],
uiSettings: IUiSettingsClient
indexPatternsService: IndexPatternsContract,
indexPatternStrings: string[]
) {
if (!indexPatternStrings || isEmpty(indexPatternStrings)) {
return [];
}

const searchString = indexPatternStrings.map((string) => `"${string}"`).join(' | ');
const indexPatternsFromSavedObjects = await savedObjectsClient.find<IndexPatternAttributes>({
type: 'index-pattern',
fields: ['title', 'fields'],
search: searchString,
searchFields: ['title'],
});

const exactMatches = indexPatternsFromSavedObjects.savedObjects.filter((savedObject) => {
return indexPatternStrings.includes(savedObject.attributes.title);
});

const defaultIndex = uiSettings.get('defaultIndex');
const exactMatches = (await indexPatternsService.find(searchString)).filter((ip) =>
indexPatternStrings.includes(ip.title)
);

const allMatches =
exactMatches.length === indexPatternStrings.length
? exactMatches
: [
...exactMatches,
await savedObjectsClient.get<IndexPatternAttributes>('index-pattern', defaultIndex),
];
: [...exactMatches, await indexPatternsService.getDefault()];

return allMatches.map(indexPatterns.getFromSavedObject);
return allMatches;
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,16 @@ describe('QueryStringInput', () => {
});

it('Should accept index pattern strings and fetch the full object', () => {
const patternStrings = ['logstash-*'];
mockFetchIndexPatterns.mockClear();
mount(
wrapQueryStringInputInContext({
query: kqlQuery,
onSubmit: noop,
indexPatterns: ['logstash-*'],
indexPatterns: patternStrings,
disableAutoFocus: true,
})
);

expect(mockFetchIndexPatterns).toHaveBeenCalledWith(
startMock.savedObjects.client,
['logstash-*'],
startMock.uiSettings
);
expect(mockFetchIndexPatterns.mock.calls[0][1]).toStrictEqual(patternStrings);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ export default class QueryStringInputUI extends Component<Props, State> {
const currentAbortController = this.fetchIndexPatternsAbortController;

const objectPatternsFromStrings = (await fetchIndexPatterns(
this.services.savedObjects!.client,
stringPatterns,
this.services.uiSettings!
this.services.data.indexPatterns,
stringPatterns
)) as IIndexPattern[];

if (!currentAbortController.signal.aborted) {
Expand Down

0 comments on commit 2c7a85d

Please sign in to comment.