Skip to content

Commit

Permalink
[ES|QL] Hides system indices (#166909)
Browse files Browse the repository at this point in the history
## Summary

Closes #166874

Hides indices starting with . (and considered as system from the
autocomplete)

<img width="785" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/9c4cce79-c844-41b6-a30e-06dad49f7c52">


Followed the exact pattern that the dataview management page is using.
  • Loading branch information
stratoula authored Sep 25, 2023
1 parent 5b24da7 commit 93ce988
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
31 changes: 29 additions & 2 deletions packages/kbn-text-based-editor/src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { parseErrors, parseWarning, getInlineEditorText, getWrappedInPipesCode } from './helpers';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import {
parseErrors,
parseWarning,
getInlineEditorText,
getWrappedInPipesCode,
getIndicesForAutocomplete,
} from './helpers';

describe('helpers', function () {
describe('parseErrors', function () {
Expand Down Expand Up @@ -159,4 +165,25 @@ describe('helpers', function () {
expect(code).toEqual('FROM index1 | keep field1, field2 | order field1');
});
});

describe('getIndicesForAutocomplete', function () {
it('should not return system indices', async function () {
const dataViewsMock = dataViewPluginMocks.createStartContract();
const updatedDataViewsMock = {
...dataViewsMock,
getIndices: jest.fn().mockResolvedValue([
{
name: '.system1',
title: 'system1',
},
{
name: 'logs',
title: 'logs',
},
]),
};
const indices = await getIndicesForAutocomplete(updatedDataViewsMock);
expect(indices).toStrictEqual(['logs']);
});
});
});
10 changes: 10 additions & 0 deletions packages/kbn-text-based-editor/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useRef } from 'react';
import useDebounce from 'react-use/lib/useDebounce';
import { monaco } from '@kbn/monaco';
import { i18n } from '@kbn/i18n';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';

export interface MonacoError {
message: string;
Expand Down Expand Up @@ -172,3 +173,12 @@ export const getWrappedInPipesCode = (code: string, isWrapped: boolean): string
});
return codeNoLines.join(isWrapped ? ' | ' : '\n| ');
};

export const getIndicesForAutocomplete = async (dataViews: DataViewsPublicPluginStart) => {
const indices = await dataViews.getIndices({
showAllIndices: false,
pattern: '*',
isRollupIndex: () => false,
});
return indices.filter((index) => !index.name.startsWith('.')).map((i) => i.name);
};
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
getDocumentationSections,
MonacoError,
getWrappedInPipesCode,
getIndicesForAutocomplete,
} from './helpers';
import { EditorFooter } from './editor_footer';
import { ResizableButton } from './resizable_button';
Expand Down Expand Up @@ -371,12 +372,7 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({

const getSourceIdentifiers: ESQLCustomAutocompleteCallbacks['getSourceIdentifiers'] =
useCallback(async () => {
const indices = await dataViews.getIndices({
showAllIndices: false,
pattern: '*',
isRollupIndex: () => false,
});
return indices.map((i) => i.name);
return await getIndicesForAutocomplete(dataViews);
}, [dataViews]);

const getFieldsIdentifiers: ESQLCustomAutocompleteCallbacks['getFieldsIdentifiers'] = useCallback(
Expand Down

0 comments on commit 93ce988

Please sign in to comment.