Skip to content

Commit

Permalink
(query assist) hide dot indices (opensearch-project#1413)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <joshuali925@gmail.com>
  • Loading branch information
joshuali925 authored Feb 6, 2024
1 parent 2d41847 commit 7442e6f
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 7442e6f

Please sign in to comment.