Skip to content

Commit 76dd0c2

Browse files
committed
Delete Pod UI
1 parent e374772 commit 76dd0c2

File tree

2 files changed

+147
-4
lines changed

2 files changed

+147
-4
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2022 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import React, { useState } from "react";
18+
import { DialogContentText } from "@mui/material";
19+
import InputBoxWrapper from "../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
20+
import Grid from "@mui/material/Grid";
21+
import { connect } from "react-redux";
22+
import { setErrorSnackMessage } from "../../../../actions";
23+
import { ErrorResponseHandler } from "../../../../common/types";
24+
import useApi from "../../Common/Hooks/useApi";
25+
import ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog";
26+
import { ConfirmDeleteIcon } from "../../../../icons";
27+
import { IStoragePVCs } from "../../Storage/types";
28+
29+
interface IDeletePVC {
30+
deleteOpen: boolean;
31+
selectedPVC: IStoragePVCs;
32+
closeDeleteModalAndRefresh: (refreshList: boolean) => any;
33+
setErrorSnackMessage: typeof setErrorSnackMessage;
34+
}
35+
36+
const DeletePVC = ({
37+
deleteOpen,
38+
selectedPVC,
39+
closeDeleteModalAndRefresh,
40+
setErrorSnackMessage,
41+
}: IDeletePVC) => {
42+
const [retypePVC, setRetypePVC] = useState("");
43+
44+
const onDelSuccess = () => closeDeleteModalAndRefresh(true);
45+
const onDelError = (err: ErrorResponseHandler) => setErrorSnackMessage(err);
46+
const onClose = () => closeDeleteModalAndRefresh(false);
47+
48+
const [deleteLoading, invokeDeleteApi] = useApi(onDelSuccess, onDelError);
49+
50+
const onConfirmDelete = () => {
51+
if (retypePVC !== selectedPVC.name) {
52+
setErrorSnackMessage({
53+
errorMessage: "PVC name is incorrect",
54+
detailedError: "",
55+
});
56+
return;
57+
}
58+
invokeDeleteApi(
59+
"DELETE",
60+
`/api/v1/namespaces/${selectedPVC.namespace}/tenants/${selectedPVC.tenant}/pvc/${selectedPVC.name}`
61+
);
62+
};
63+
64+
return (
65+
<ConfirmDialog
66+
title={`Delete PVC`}
67+
confirmText={"Delete"}
68+
isOpen={deleteOpen}
69+
titleIcon={<ConfirmDeleteIcon />}
70+
isLoading={deleteLoading}
71+
onConfirm={onConfirmDelete}
72+
onClose={onClose}
73+
confirmButtonProps={{
74+
disabled: retypePVC !== selectedPVC.name || deleteLoading,
75+
}}
76+
confirmationContent={
77+
<DialogContentText>
78+
To continue please type <b>{selectedPVC.name}</b> in the box.
79+
<Grid item xs={12}>
80+
<InputBoxWrapper
81+
id="retype-PVC"
82+
name="retype-PVC"
83+
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
84+
setRetypePVC(event.target.value);
85+
}}
86+
label=""
87+
value={retypePVC}
88+
/>
89+
</Grid>
90+
</DialogContentText>
91+
}
92+
/>
93+
);
94+
};
95+
96+
const connector = connect(null, {
97+
setErrorSnackMessage,
98+
});
99+
100+
export default connector(DeletePVC);

portal-ui/src/screens/Console/Tenants/TenantDetails/VolumesSummary.tsx

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ import {
2727
searchField,
2828
tableStyles,
2929
} from "../../Common/FormComponents/common/styleLibrary";
30-
import { IPVCsResponse, IStoragePVCs } from "../../Storage/types";
30+
import { IStoragePVCs } from "../../Storage/types";
3131
import { setErrorSnackMessage } from "../../../../actions";
3232
import { ErrorResponseHandler } from "../../../../common/types";
3333
import api from "../../../../common/api";
3434
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
3535
import SearchIcon from "../../../../icons/SearchIcon";
36+
import withSuspense from "../../Common/Components/withSuspense";
37+
import { setTenantDetailsLoad } from "../actions";
38+
import { AppState } from "../../../../store";
39+
40+
const DeletePVC = withSuspense(React.lazy(() => import("./DeletePVC")));
3641

3742
interface ITenantVolumesProps {
3843
classes: any;
3944
setErrorSnackMessage: typeof setErrorSnackMessage;
4045
match: any;
46+
loadingTenant: boolean;
47+
setTenantDetailsLoad: typeof setTenantDetailsLoad;
4148
}
4249

4350
const styles = (theme: Theme) =>
@@ -55,10 +62,13 @@ const TenantVolumes = ({
5562
classes,
5663
setErrorSnackMessage,
5764
match,
65+
loadingTenant,
5866
}: ITenantVolumesProps) => {
5967
const [records, setRecords] = useState<IStoragePVCs[]>([]);
6068
const [filter, setFilter] = useState("");
6169
const [loading, setLoading] = useState<boolean>(true);
70+
const [selectedPVC, setSelectedPVC] = useState<any>(null);
71+
const [deleteOpen, setDeleteOpen] = useState<boolean>(false);
6272

6373
const tenantName = match.params["tenantName"];
6474
const tenantNamespace = match.params["tenantNamespace"];
@@ -70,7 +80,7 @@ const TenantVolumes = ({
7080
"GET",
7181
`/api/v1/namespaces/${tenantNamespace}/tenants/${tenantName}/pvcs`
7282
)
73-
.then((res: IPVCsResponse) => {
83+
.then((res: IStoragePVCs) => {
7484
let volumes = get(res, "pvcs", []);
7585
setRecords(volumes ? volumes : []);
7686
setLoading(false);
@@ -82,12 +92,41 @@ const TenantVolumes = ({
8292
}
8393
}, [loading, setErrorSnackMessage, tenantName, tenantNamespace]);
8494

95+
const confirmDeletePVC = (pvcItem: IStoragePVCs) => {
96+
const delPvc = {
97+
...pvcItem,
98+
tenant: tenantName,
99+
namespace: tenantNamespace,
100+
};
101+
delPvc.tenant = tenantName;
102+
delPvc.namespace = tenantNamespace;
103+
setSelectedPVC(delPvc);
104+
setDeleteOpen(true);
105+
};
106+
85107
const filteredRecords: IStoragePVCs[] = records.filter((elementItem) =>
86108
elementItem.name.includes(filter)
87109
);
88110

111+
const closeDeleteModalAndRefresh = (reloadData: boolean) => {
112+
setDeleteOpen(false);
113+
};
114+
115+
useEffect(() => {
116+
if (loadingTenant) {
117+
setLoading(true);
118+
}
119+
}, [loadingTenant]);
120+
89121
return (
90122
<Fragment>
123+
{deleteOpen && (
124+
<DeletePVC
125+
deleteOpen={deleteOpen}
126+
selectedPVC={selectedPVC}
127+
closeDeleteModalAndRefresh={closeDeleteModalAndRefresh}
128+
/>
129+
)}
91130
<h1 className={classes.sectionTitle}>Volumes</h1>
92131
<Grid item xs={12} className={classes.actionsTray}>
93132
<TextField
@@ -114,7 +153,7 @@ const TenantVolumes = ({
114153
</Grid>
115154
<Grid item xs={12} className={classes.tableBlock}>
116155
<TableWrapper
117-
itemActions={[]}
156+
itemActions={[{ type: "delete", onClick: confirmDeletePVC }]}
118157
columns={[
119158
{
120159
label: "Name",
@@ -146,10 +185,14 @@ const TenantVolumes = ({
146185
);
147186
};
148187

188+
const mapState = (state: AppState) => ({
189+
loadingTenant: state.tenants.tenantDetails.loadingTenant,
190+
});
191+
149192
const mapDispatchToProps = {
150193
setErrorSnackMessage,
151194
};
152195

153-
const connector = connect(null, mapDispatchToProps);
196+
const connector = connect(mapState, mapDispatchToProps);
154197

155198
export default withStyles(styles)(connector(TenantVolumes));

0 commit comments

Comments
 (0)