Skip to content

Commit

Permalink
(query assist) hide dot indices (#1413) (#1414)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7442e6f)

Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 3733eeb commit eb1440e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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 Down Expand Up @@ -48,7 +48,12 @@ export const useCatIndices = () => {
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

0 comments on commit eb1440e

Please sign in to comment.