Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Aug 22, 2022
2 parents 1a1d078 + 3f9b821 commit 847e122
Show file tree
Hide file tree
Showing 21 changed files with 803 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { mockHttpValues } from '../../../__mocks__/kea_logic';

import { nextTick } from '@kbn/test-jest-helpers';

import { deleteIndex } from './delete_index_api_logic';

describe('deleteIndexApiLogic', () => {
const { http } = mockHttpValues;
beforeEach(() => {
jest.clearAllMocks();
});
describe('deleteIndex', () => {
it('calls correct api', async () => {
const promise = Promise.resolve();
http.post.mockReturnValue(promise);
const result = deleteIndex({ indexName: 'deleteIndex' });
await nextTick();
expect(http.delete).toHaveBeenCalledWith('/internal/enterprise_search/indices/deleteIndex');
await expect(result).resolves;
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createApiLogic } from '../../../shared/api_logic/create_api_logic';
import { HttpLogic } from '../../../shared/http';

export interface DeleteIndexApiLogicArgs {
indexName: string;
}

export const deleteIndex = async ({ indexName }: DeleteIndexApiLogicArgs): Promise<void> => {
const route = `/internal/enterprise_search/indices/${indexName}`;
await HttpLogic.values.http.delete(route);
return;
};

export const DeleteIndexApiLogic = createApiLogic(['delete_index_api_logic'], deleteIndex);
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ describe('FetchIndicesApiLogic', () => {
expect(http.get).toHaveBeenCalledWith('/internal/enterprise_search/indices', {
query: { page: 1, return_hidden_indices: false, search_query: null, size: 20 },
});
await expect(result).resolves.toEqual({ isInitialRequest: true, result: 'result' });
await expect(result).resolves.toEqual({
isInitialRequest: true,
result: 'result',
returnHiddenIndices: false,
searchQuery: undefined,
});
});
it('sets initialRequest to false if page is not the first page', async () => {
const promise = Promise.resolve({ result: 'result' });
Expand All @@ -41,7 +46,12 @@ describe('FetchIndicesApiLogic', () => {
expect(http.get).toHaveBeenCalledWith('/internal/enterprise_search/indices', {
query: { page: 2, return_hidden_indices: false, search_query: null, size: 20 },
});
await expect(result).resolves.toEqual({ isInitialRequest: false, result: 'result' });
await expect(result).resolves.toEqual({
isInitialRequest: false,
result: 'result',
returnHiddenIndices: false,
searchQuery: undefined,
});
});
it('sets initialRequest to false if searchQuery is not empty', async () => {
const promise = Promise.resolve({ result: 'result' });
Expand All @@ -55,7 +65,12 @@ describe('FetchIndicesApiLogic', () => {
expect(http.get).toHaveBeenCalledWith('/internal/enterprise_search/indices', {
query: { page: 1, return_hidden_indices: false, search_query: 'a', size: 20 },
});
await expect(result).resolves.toEqual({ isInitialRequest: false, result: 'result' });
await expect(result).resolves.toEqual({
isInitialRequest: false,
result: 'result',
returnHiddenIndices: false,
searchQuery: 'a',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const fetchIndices = async ({
// We need this to determine whether to show the empty state on the indices page
const isInitialRequest = meta.page.current === 1 && !searchQuery;

return { ...response, isInitialRequest };
return { ...response, isInitialRequest, returnHiddenIndices, searchQuery };
};

export const FetchIndicesAPILogic = createApiLogic(['content', 'indices_api_logic'], fetchIndices);
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import { useActions, useValues } from 'kea';

import { EuiConfirmModal } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { IndicesLogic } from './indices_logic';

export const DeleteIndexModal: React.FC = () => {
const { closeDeleteModal, deleteIndex } = useActions(IndicesLogic);
const { deleteModalIndexName: indexName, isDeleteModalVisible } = useValues(IndicesLogic);
return isDeleteModalVisible ? (
<EuiConfirmModal
title={i18n.translate('xpack.enterpriseSearch.content.searchIndices.deleteModal.title', {
defaultMessage: 'Delete index',
})}
onCancel={() => {
closeDeleteModal();
}}
onConfirm={() => {
deleteIndex({ indexName });
}}
cancelButtonText={i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.cancelButton.title',
{
defaultMessage: 'Cancel',
}
)}
confirmButtonText={i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.confirmButton.title',
{
defaultMessage: 'Delete index',
}
)}
defaultFocusedButton="confirm"
buttonColor="danger"
>
<p>
{i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.delete.description',
{
defaultMessage:
'You are about to delete the index {indexName}. This will also delete any associated connector documents or crawlers.',
values: {
indexName,
},
}
)}
</p>
<p>
{i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.searchEngine.description',
{
defaultMessage:
'Any associated search engines will no longer be able to access any data stored in this index.',
}
)}
</p>
<p>
{i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.irrevokable.description',
{
defaultMessage:
"You can't recover a deleted index, connector or crawler configuration. Make sure you have appropriate backups.",
}
)}
</p>
</EuiConfirmModal>
) : (
<></>
);
};
Loading

0 comments on commit 847e122

Please sign in to comment.