-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Onboarding] Add delete index action to search index detail page #192428
Changes from 3 commits
edb1153
fe41521
bd41dad
13ac078
5dde7ca
f4866b7
63048f4
d7ca011
7e966a6
d1c10b7
7cf8bb4
b8fd1cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* 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 { DocLinks } from '@kbn/doc-links'; | ||
|
||
class SearchIndicesDocLinks { | ||
public apiReference: string = ''; | ||
|
||
constructor() {} | ||
|
||
setDocLinks(newDocLinks: DocLinks) { | ||
this.apiReference = newDocLinks.apiReference; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joemcelroy Will we need to worry about showing different links here based on serverless and stack? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will do eventually. ATM we rely on stack URLs, waiting on @leemthompo guidance on how that will work out :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lcawl knows more about this topic than me, and I know the autogenerated API refs are coming along nicely :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have the isServerless option too IIUC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the doc link service can have two "flavours" of links so that's definitely something that already exists. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lcawl would you recommend linking to the autogenerated API refs today, or circling back in a while on that one? |
||
} | ||
} | ||
export const docLinks = new SearchIndicesDocLinks(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
], | ||
"requiredBundles": [ | ||
"kibanaReact", | ||
"esUiShared" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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, { Fragment, useEffect } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiConfirmModal } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { useDeleteIndex } from '../../hooks/api/use_delete_index'; | ||
interface DeleteIndexModelProps { | ||
onCancel: () => void; | ||
indexName: string; | ||
navigateToIndexListPage: () => void; | ||
} | ||
export const DeleteIndexModal: React.FC<DeleteIndexModelProps> = ({ | ||
onCancel, | ||
indexName, | ||
navigateToIndexListPage, | ||
}) => { | ||
const { mutate, isLoading, isSuccess } = useDeleteIndex(indexName); | ||
useEffect(() => { | ||
if (isSuccess) { | ||
navigateToIndexListPage(); | ||
} | ||
}, [navigateToIndexListPage, isSuccess]); | ||
return ( | ||
<EuiConfirmModal | ||
data-test-subj="deleteIndexActionModal" | ||
title={i18n.translate( | ||
'xpack.searchIndices.indexActionsMenu.deleteIndex.confirmModal.modalTitle', | ||
{ | ||
defaultMessage: 'Delete {index}', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the modal title should be more general and simply read 'Delete index'—especially since we are also including the index name in the body of the modal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated in 5dde7ca |
||
values: { index: indexName }, | ||
} | ||
)} | ||
onCancel={onCancel} | ||
onConfirm={() => mutate()} | ||
isLoading={isLoading} | ||
buttonColor="danger" | ||
confirmButtonDisabled={false} | ||
cancelButtonText={i18n.translate( | ||
'xpack.searchIndices.indexActionsMenu.deleteIndex.confirmModal.cancelButtonText', | ||
{ | ||
defaultMessage: 'Cancel', | ||
} | ||
)} | ||
confirmButtonText={i18n.translate( | ||
'xpack.searchIndices.indexActionsMenu.deleteIndex.confirmModal.confirmButtonText', | ||
{ | ||
defaultMessage: 'Delete index', | ||
} | ||
)} | ||
> | ||
<Fragment> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.searchIndices.indexActionsMenu.deleteIndex.deleteDescription" | ||
defaultMessage="You are about to delete this index:" | ||
/> | ||
</p> | ||
<ul> | ||
<li key={indexName}>{indexName}</li> | ||
TattdCodeMonkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ul> | ||
|
||
<p> | ||
<FormattedMessage | ||
id="xpack.searchIndices.indexActionsMenu.deleteIndex.deleteWarningDescription" | ||
defaultMessage="You can't recover a deleted index. Make sure you have appropriate backups." | ||
/> | ||
</p> | ||
</Fragment> | ||
</EuiConfirmModal> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 { AcknowledgedResponseBase } from '@elastic/elasticsearch/lib/api/types'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useKibana } from '../use_kibana'; | ||
|
||
export const useDeleteIndex = (indexName: string) => { | ||
const { http } = useKibana().services; | ||
const indices = [indexName]; | ||
const body = JSON.stringify({ | ||
indices, | ||
}); | ||
const result = useMutation({ | ||
mutationFn: async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also invalidate the index from querycache, onSuccess. see this doc https://tanstack.com/query/v4/docs/framework/react/guides/invalidations-from-mutations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated in 13ac078 |
||
const response = await http.post<AcknowledgedResponseBase>( | ||
`/api/index_management/indices/delete`, | ||
{ | ||
body, | ||
} | ||
); | ||
return response.acknowledged; | ||
}, | ||
}); | ||
return { ...result }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ export const useIndex = (indexName: string) => { | |
refetchInterval: POLLING_INTERVAL, | ||
refetchIntervalInBackground: true, | ||
refetchOnWindowFocus: 'always', | ||
retry: true, | ||
retry: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When retry is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would suggest retry to be capped to a number like 3 rather than true so that errors are bubbled to the UI when it consistently throws an error https://tanstack.com/query/latest/docs/framework/react/reference/useQuery#usequery There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated in 13ac078 |
||
queryFn: () => | ||
http.fetch<Index>(`/internal/index_management/indices/${encodeURIComponent(indexName)}`), | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would link this to current, like the other URLS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in 13ac078