diff --git a/src/plugins/credential_management/public/components/create_credential_wizard/create_credential_wizard.tsx b/src/plugins/credential_management/public/components/create_credential_wizard/create_credential_wizard.tsx index 366c5831322b..e60a470ff0f2 100644 --- a/src/plugins/credential_management/public/components/create_credential_wizard/create_credential_wizard.tsx +++ b/src/plugins/credential_management/public/components/create_credential_wizard/create_credential_wizard.tsx @@ -5,7 +5,6 @@ import React from 'react'; import { FormattedMessage } from '@osd/i18n/react'; - import { withRouter, RouteComponentProps } from 'react-router-dom'; import { EuiHorizontalRule, diff --git a/src/plugins/credential_management/public/components/edit_credential/edit_credential.tsx b/src/plugins/credential_management/public/components/edit_credential/edit_credential.tsx index 9ef8e459bce5..0f849725dd82 100644 --- a/src/plugins/credential_management/public/components/edit_credential/edit_credential.tsx +++ b/src/plugins/credential_management/public/components/edit_credential/edit_credential.tsx @@ -5,7 +5,6 @@ import React from 'react'; import { FormattedMessage } from '@osd/i18n/react'; - import { withRouter, RouteComponentProps } from 'react-router-dom'; import { EuiHorizontalRule, @@ -20,6 +19,10 @@ import { EuiButton, EuiPageContent, EuiFieldPassword, + EuiFlexItem, + EuiToolTip, + EuiButtonIcon, + EuiConfirmModal, } from '@elastic/eui'; import { DocLinksStart } from 'src/core/public'; import { getCreateBreadcrumbs } from '../breadcrumbs'; @@ -27,6 +30,7 @@ import { CredentialManagmentContextValue } from '../../types'; // TODO: Add Header https://github.com/opensearch-project/OpenSearch-Dashboards/issues/2051 import { context as contextType } from '../../../../opensearch_dashboards_react/public'; import { CredentialEditPageItem } from '../types'; +import * as localizedContent from '../text_content/text_content'; interface EditCredentialState { credentialName: string; @@ -36,6 +40,7 @@ interface EditCredentialState { dual: boolean; toasts: EuiGlobalToastListToast[]; docLinks: DocLinksStart; + isVisible: boolean; } export interface EditCredentialProps extends RouteComponentProps { @@ -61,17 +66,89 @@ export class EditCredentialComponent extends React.Component< dual: true, toasts: [], docLinks: context.services.docLinks, + isVisible: false, }; } + confirmDelete = async () => { + const { savedObjects } = this.context.services; + try { + await savedObjects.client.delete('credential', this.props.credential.id); + this.props.history.push(''); + } catch (e) { + const deleteCredentialFailMsg = ( + + ); + this.setState((prevState) => ({ + toasts: prevState.toasts.concat([ + { + title: deleteCredentialFailMsg, + id: deleteCredentialFailMsg.props.id, + color: 'warning', + iconType: 'alert', + }, + ]), + })); + } + }; + + delelteButtonRender() { + return ( + <> +
+ + + + + +
+ + {this.state.isVisible ? ( + { + this.setState({ isVisible: false }); + }} + onConfirm={this.confirmDelete} + cancelButtonText={localizedContent.cancelButtonOnDeleteCancelText} + confirmButtonText={localizedContent.confirmButtonOnDeleteComfirmText} + defaultFocusedButton="confirm" + > +

{localizedContent.deleteCredentialDescribeMsg}

+

{localizedContent.deleteCredentialConfirmMsg}

+

{localizedContent.deleteCredentialWarnMsg}

+
+ ) : null} + + ); + } + // TODO: Add rendering spanner https://github.com/opensearch-project/OpenSearch-Dashboards/issues/2050 renderContent() { const options = [ - { value: 'username_password_credential', text: 'Username and Password Credential' }, + { + value: 'username_password_credential', + text: 'Username and Password Credential', + }, { value: 'no_auth', text: 'No Auth' }, ]; return ( + {this.delelteButtonRender()} { + this.setState({ isVisible: true }); + }; + updateCredential = async () => { const { savedObjects } = this.context.services; try { - // TODO: Add rendering spanner https://github.com/opensearch-project/OpenSearch-Dashboards/issues/2050 await savedObjects.client.update('credential', this.props.credential.id, { title: this.state.credentialName, credentialMaterials: { diff --git a/src/plugins/credential_management/public/components/text_content/text_content.ts b/src/plugins/credential_management/public/components/text_content/text_content.ts new file mode 100644 index 000000000000..f9543cee8243 --- /dev/null +++ b/src/plugins/credential_management/public/components/text_content/text_content.ts @@ -0,0 +1,56 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { i18n } from '@osd/i18n'; + +export const deleteCredentialDescribeMsg = i18n.translate( + 'credentialManagement.textContent.deleteCredentialDescribeMsg', + { + defaultMessage: + 'This will also delete their credential materials. All data sources using this credential will be invalid for access, and they must choose new credentials.', + } +); + +export const deleteCredentialConfirmMsg = i18n.translate( + 'credentialManagement.textContent.deleteCredentialConfirmMsg', + { + defaultMessage: 'To confirm deletion, click delete button.', + } +); + +export const deleteCredentialWarnMsg = i18n.translate( + 'credentialManagement.textContent.deleteCredentialWarnMsg', + { + defaultMessage: 'Note: this action is irrevocable!', + } +); + +export const deleteButtonOnConfirmText = i18n.translate( + 'credentialManagement.textContent.deleteButtonOnConfirmText', + { + defaultMessage: 'Delete credential permanently?', + } +); + +export const deleteCredentialButtonDescription = i18n.translate( + 'credentialManagement.textContent.deleteCredentialButtonDescription', + { + defaultMessage: 'Remove this credential', + } +); + +export const cancelButtonOnDeleteCancelText = i18n.translate( + 'credentialManagement.textContent.cancelButtonOnDeleteCancelText', + { + defaultMessage: 'Cancel', + } +); + +export const confirmButtonOnDeleteComfirmText = i18n.translate( + 'credentialManagement.textContent.confirmButtonOnDeleteComfirmText', + { + defaultMessage: 'Delete', + } +);