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

[8.5] [Enterprise Search] Fix index delete modal (#142447) #142705

Merged
merged 1 commit into from
Oct 5, 2022
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 @@ -22,6 +22,7 @@ export const DeleteIndexModal: React.FC = () => {
deleteModalIndexName: indexName,
deleteModalIngestionMethod: ingestionMethod,
isDeleteModalVisible,
isDeleteLoading,
} = useValues(IndicesLogic);
return isDeleteModalVisible ? (
<EuiConfirmModal
Expand All @@ -35,12 +36,21 @@ export const DeleteIndexModal: React.FC = () => {
onConfirm={() => {
deleteIndex({ indexName });
}}
cancelButtonText={i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.cancelButton.title',
{
defaultMessage: 'Cancel',
}
)}
cancelButtonText={
isDeleteLoading
? i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.closeButton.title',
{
defaultMessage: 'Close',
}
)
: i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.cancelButton.title',
{
defaultMessage: 'Cancel',
}
)
}
confirmButtonText={i18n.translate(
'xpack.enterpriseSearch.content.searchIndices.deleteModal.confirmButton.title',
{
Expand All @@ -49,6 +59,7 @@ export const DeleteIndexModal: React.FC = () => {
)}
defaultFocusedButton="confirm"
buttonColor="danger"
isLoading={isDeleteLoading}
>
<p>
{i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ const DEFAULT_VALUES = {
deleteModalIndex: null,
deleteModalIndexName: '',
deleteModalIngestionMethod: IngestionMethod.API,
deleteStatus: Status.IDLE,
hasNoIndices: false,
indices: [],
isDeleteLoading: false,
isDeleteModalVisible: false,
isFirstRequest: true,
isLoading: true,
Expand Down Expand Up @@ -255,6 +257,36 @@ describe('IndicesLogic', () => {
});
});
});
describe('deleteRequest', () => {
it('should update isDeleteLoading to true on deleteIndex', () => {
IndicesLogic.actions.deleteIndex({ indexName: 'to-delete' });
expect(IndicesLogic.values).toEqual({
...DEFAULT_VALUES,
deleteStatus: Status.LOADING,
isDeleteLoading: true,
});
});
it('should update isDeleteLoading to to false on apiError', () => {
IndicesLogic.actions.deleteIndex({ indexName: 'to-delete' });
IndicesLogic.actions.deleteError({} as HttpError);

expect(IndicesLogic.values).toEqual({
...DEFAULT_VALUES,
deleteStatus: Status.ERROR,
isDeleteLoading: false,
});
});
it('should update isDeleteLoading to to false on apiSuccess', () => {
IndicesLogic.actions.deleteIndex({ indexName: 'to-delete' });
IndicesLogic.actions.deleteSuccess();

expect(IndicesLogic.values).toEqual({
...DEFAULT_VALUES,
deleteStatus: Status.SUCCESS,
isDeleteLoading: false,
});
});
});
});

describe('listeners', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ export interface IndicesValues {
deleteModalIndex: ElasticsearchViewIndex | null;
deleteModalIndexName: string;
deleteModalIngestionMethod: IngestionMethod;
deleteStatus: typeof DeleteIndexApiLogic.values.status;
hasNoIndices: boolean;
indices: ElasticsearchViewIndex[];
isDeleteLoading: boolean;
isDeleteModalVisible: boolean;
isFirstRequest: boolean;
isLoading: boolean;
Expand Down Expand Up @@ -101,7 +103,12 @@ export const IndicesLogic = kea<MakeLogicType<IndicesValues, IndicesActions>>({
DeleteIndexApiLogic,
['apiError as deleteError', 'apiSuccess as deleteSuccess', 'makeRequest as deleteIndex'],
],
values: [FetchIndicesAPILogic, ['data', 'status']],
values: [
FetchIndicesAPILogic,
['data', 'status'],
DeleteIndexApiLogic,
['status as deleteStatus'],
],
},
listeners: ({ actions, values }) => ({
apiError: (e) => flashAPIErrors(e),
Expand Down Expand Up @@ -181,6 +188,10 @@ export const IndicesLogic = kea<MakeLogicType<IndicesValues, IndicesActions>>({
() => [selectors.data],
(data) => (data?.indices ? data.indices.map(indexToViewIndex) : []),
],
isDeleteLoading: [
() => [selectors.deleteStatus],
(status: IndicesValues['deleteStatus']) => [Status.LOADING].includes(status),
],
isLoading: [
() => [selectors.status, selectors.isFirstRequest],
(status, isFirstRequest) => [Status.LOADING, Status.IDLE].includes(status) && isFirstRequest,
Expand Down