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

[Backport main] (query assist) hide dot indices #1414

Merged
merged 1 commit into from
Feb 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ describe('useCatIndices', () => {
expect(result.current.data).toEqual([{ label: 'test1' }, { label: 'test2' }]);
});

it('should hide indices starting with dot', async () => {
httpMock.get.mockResolvedValueOnce([{ index: '.test1' }, { index: 'test2' }]);

const { result, waitForNextUpdate } = renderHook(() => useCatIndices());
expect(result.current.loading).toBe(true);
await waitForNextUpdate();
expect(result.current.loading).toBe(false);
expect(result.current.data).toEqual([{ label: 'test2' }]);
});

it('should handle errors', async () => {
httpMock.get.mockRejectedValueOnce('API failed');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { EuiComboBoxOptionOption } from '@elastic/eui';
import { CatIndicesResponse } from '@opensearch-project/opensearch/api/types';
import { Reducer, useReducer, useState, useEffect } from 'react';
import { Reducer, useEffect, useReducer, useState } from 'react';
import { IndexPatternAttributes } from '../../../../../../../src/plugins/data/common';
import { DSL_BASE, DSL_CAT } from '../../../../../common/constants/shared';
import { getOSDHttp } from '../../../../../common/utils';
Expand All @@ -23,7 +23,7 @@
| { type: 'failure'; error: NonNullable<State<T>['error']> };

// TODO use instantiation expressions when typescript is upgraded to >= 4.7
type GenericReducer<T = any> = Reducer<State<T>, Action<T>>;

Check warning on line 26 in public/components/event_analytics/explorer/query_assist/hooks.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
export const genericReducer: GenericReducer = (state, action) => {
switch (action.type) {
case 'request':
Expand All @@ -48,7 +48,12 @@
getOSDHttp()
.get(`${DSL_BASE}${DSL_CAT}`, { query: { format: 'json' }, signal: abortController.signal })
.then((payload: CatIndicesResponse) =>
dispatch({ type: 'success', payload: payload.map((meta) => ({ label: meta.index! })) })
dispatch({
type: 'success',
payload: payload
.filter((meta) => meta.index && !meta.index.startsWith('.'))
.map((meta) => ({ label: meta.index! })),
})
)
.catch((error) => dispatch({ type: 'failure', error }));

Expand Down
Loading