diff --git a/src/plugins/workspace/public/components/delete_workspace_modal/delete_workspace_modal.tsx b/src/plugins/workspace/public/components/delete_workspace_modal/delete_workspace_modal.tsx new file mode 100644 index 000000000000..d1f29a140718 --- /dev/null +++ b/src/plugins/workspace/public/components/delete_workspace_modal/delete_workspace_modal.tsx @@ -0,0 +1,71 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React, { useState } from 'react'; +import { + EuiButton, + EuiButtonEmpty, + EuiFieldText, + EuiModal, + EuiModalBody, + EuiModalFooter, + EuiModalHeader, + EuiModalHeaderTitle, + EuiSpacer, + EuiText, +} from '@elastic/eui'; + +interface DeleteWorkspaceModalProps { + selectedItems: string[]; + onClose: () => void; + onConfirm: () => void; +} + +export function DeleteWorkspaceModal(props: DeleteWorkspaceModalProps) { + const [value, setValue] = useState(''); + const { onClose, onConfirm, selectedItems } = props; + + return ( + + + Delete workspace + + + +
+

The following workspace will be permanently deleted. This action cannot be undone.

+
    + {selectedItems.map((item) => ( +
  • {item}
  • + ))} +
+ + + To confirm your action, type delete. + + setValue(e.target.value)} + /> +
+
+ + + Cancel + + Delete + + +
+ ); +} diff --git a/src/plugins/workspace/public/components/delete_workspace_modal/index.ts b/src/plugins/workspace/public/components/delete_workspace_modal/index.ts new file mode 100644 index 000000000000..3466e180c54a --- /dev/null +++ b/src/plugins/workspace/public/components/delete_workspace_modal/index.ts @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export * from './delete_workspace_modal'; diff --git a/src/plugins/workspace/public/components/workspace_overview.tsx b/src/plugins/workspace/public/components/workspace_overview.tsx index 76986f141784..b0eabce71555 100644 --- a/src/plugins/workspace/public/components/workspace_overview.tsx +++ b/src/plugins/workspace/public/components/workspace_overview.tsx @@ -3,17 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React from 'react'; +import React, { useState } from 'react'; import { EuiPageHeader, EuiButton, EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui'; import { useObservable } from 'react-use'; import { of } from 'rxjs'; import { i18n } from '@osd/i18n'; -import { PATHS } from '../../common/constants'; import { ApplicationStart } from '../../../../core/public'; +import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public'; +import { DeleteWorkspaceModal } from './delete_workspace_modal'; +import { PATHS } from '../../common/constants'; import { WORKSPACE_APP_ID, WORKSPACE_ID_IN_SESSION_STORAGE } from '../../common/constants'; -import { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public'; - export const WorkspaceOverview = () => { const { services: { workspaces, application, notifications }, @@ -23,6 +23,43 @@ export const WorkspaceOverview = () => { workspaces ? workspaces.client.currentWorkspace$ : of(null) ); + const workspaceId = currentWorkspace?.id; + const workspaceName = currentWorkspace?.name; + const [deleteWorkspaceModalVisible, setDeleteWorkspaceModalVisible] = useState(false); + + const deleteWorkspace = async () => { + if (workspaceId) { + let result; + try { + result = await workspaces?.client.delete(workspaceId); + } catch (error) { + notifications?.toasts.addDanger({ + title: i18n.translate('workspace.delete.failed', { + defaultMessage: 'Failed to delete workspace', + }), + text: error instanceof Error ? error.message : JSON.stringify(error), + }); + return setDeleteWorkspaceModalVisible(false); + } + if (result?.success) { + notifications?.toasts.addSuccess({ + title: i18n.translate('workspace.delete.success', { + defaultMessage: 'Delete workspace successfully', + }), + }); + } else { + notifications?.toasts.addDanger({ + title: i18n.translate('workspace.delete.failed', { + defaultMessage: 'Failed to delete workspace', + }), + text: result?.error, + }); + } + } + setDeleteWorkspaceModalVisible(false); + await application.navigateToApp('home'); + }; + const onUpdateWorkspaceClick = () => { if (!currentWorkspace || !currentWorkspace.id) { notifications?.toasts.addDanger({ @@ -42,11 +79,22 @@ export const WorkspaceOverview = () => { setDeleteWorkspaceModalVisible(true)}> + Delete + , + Update, Delete, Update, ]} /> + {deleteWorkspaceModalVisible && ( + setDeleteWorkspaceModalVisible(false)} + selectedItems={workspaceName ? [workspaceName] : []} + /> + )}

Workspace