mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[App Search] Filter Elasticsearch index based engines from meta engine creation (#128503)
* Filter elasticsearch index based engines for the meta engine creation * Add tests for the filtering cases Co-authored-by: Aurélien FOUCRET <aurelien.foucret@elastic.co>
This commit is contained in:
parent
f981d53b6f
commit
5e847ac074
4 changed files with 42 additions and 4 deletions
|
@ -104,6 +104,7 @@ describe('MetaEngineCreationLogic', () => {
|
|||
describe('listeners', () => {
|
||||
describe('fetchIndexedEngineNames', () => {
|
||||
beforeEach(() => {
|
||||
mount();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
|
@ -124,6 +125,22 @@ describe('MetaEngineCreationLogic', () => {
|
|||
expect(MetaEngineCreationLogic.actions.setIndexedEngineNames).toHaveBeenCalledWith(['foo']);
|
||||
});
|
||||
|
||||
it('filters out elasticsearch type engines', async () => {
|
||||
jest.spyOn(MetaEngineCreationLogic.actions, 'setIndexedEngineNames');
|
||||
http.get.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
results: [
|
||||
{ name: 'foo', type: 'default' },
|
||||
{ name: 'elasticsearch-engine', type: 'elasticsearch' },
|
||||
],
|
||||
meta: { page: { total_pages: 1 } },
|
||||
})
|
||||
);
|
||||
MetaEngineCreationLogic.actions.fetchIndexedEngineNames();
|
||||
await nextTick();
|
||||
expect(MetaEngineCreationLogic.actions.setIndexedEngineNames).toHaveBeenCalledWith(['foo']);
|
||||
});
|
||||
|
||||
it('if there are remaining pages it should call fetchIndexedEngineNames recursively with an incremented page', async () => {
|
||||
jest.spyOn(MetaEngineCreationLogic.actions, 'fetchIndexedEngineNames');
|
||||
http.get.mockReturnValueOnce(
|
||||
|
|
|
@ -16,7 +16,7 @@ import { HttpLogic } from '../../../shared/http';
|
|||
import { KibanaLogic } from '../../../shared/kibana';
|
||||
import { ENGINE_PATH } from '../../routes';
|
||||
import { formatApiName } from '../../utils/format_api_name';
|
||||
import { EngineDetails } from '../engine/types';
|
||||
import { EngineDetails, EngineTypes } from '../engine/types';
|
||||
|
||||
import { META_ENGINE_CREATION_SUCCESS_MESSAGE } from './constants';
|
||||
|
||||
|
@ -100,7 +100,9 @@ export const MetaEngineCreationLogic = kea<
|
|||
}
|
||||
|
||||
if (response) {
|
||||
const engineNames = response.results.map((result) => result.name);
|
||||
const engineNames = response.results
|
||||
.filter(({ type }) => type !== EngineTypes.elasticsearch)
|
||||
.map((result) => result.name);
|
||||
actions.setIndexedEngineNames([...values.indexedEngineNames, ...engineNames]);
|
||||
|
||||
if (page < response.meta.page.total_pages) {
|
||||
|
|
|
@ -109,6 +109,24 @@ describe('SourceEnginesLogic', () => {
|
|||
selectableEngineNames: ['source-engine-1', 'source-engine-2'],
|
||||
});
|
||||
});
|
||||
|
||||
it('sets indexedEngines filters out elasticsearch type engines', () => {
|
||||
mount();
|
||||
|
||||
SourceEnginesLogic.actions.setIndexedEngines([
|
||||
{ name: 'source-engine-1' },
|
||||
{ name: 'source-engine-2' },
|
||||
{ name: 'source-engine-elasticsearch', type: 'elasticsearch' },
|
||||
] as EngineDetails[]);
|
||||
|
||||
expect(SourceEnginesLogic.values).toEqual({
|
||||
...DEFAULT_VALUES,
|
||||
indexedEngines: [{ name: 'source-engine-1' }, { name: 'source-engine-2' }],
|
||||
// Selectors
|
||||
indexedEngineNames: ['source-engine-1', 'source-engine-2'],
|
||||
selectableEngineNames: ['source-engine-1', 'source-engine-2'],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('onSourceEnginesFetch', () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ import { flashAPIErrors, flashSuccessToast } from '../../../shared/flash_message
|
|||
import { HttpLogic } from '../../../shared/http';
|
||||
import { recursivelyFetchEngines } from '../../utils/recursively_fetch_engines';
|
||||
import { EngineLogic } from '../engine';
|
||||
import { EngineDetails } from '../engine/types';
|
||||
import { EngineDetails, EngineTypes } from '../engine/types';
|
||||
|
||||
import { ADD_SOURCE_ENGINES_SUCCESS_MESSAGE, REMOVE_SOURCE_ENGINE_SUCCESS_MESSAGE } from './i18n';
|
||||
|
||||
|
@ -88,7 +88,8 @@ export const SourceEnginesLogic = kea<
|
|||
indexedEngines: [
|
||||
[],
|
||||
{
|
||||
setIndexedEngines: (_, { indexedEngines }) => indexedEngines,
|
||||
setIndexedEngines: (_, { indexedEngines }) =>
|
||||
indexedEngines.filter(({ type }) => type !== EngineTypes.elasticsearch),
|
||||
},
|
||||
],
|
||||
selectedEngineNamesToAdd: [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue