Skip to content

Commit 5fd82ca

Browse files
bexsoftBenjamin Perez
andauthored
Added delete bucket lifecycle rule capability (#1547)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net> Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 829404b commit 5fd82ca

13 files changed

+793
-97
lines changed

models/lifecycle_rule_type.go

Lines changed: 0 additions & 95 deletions
This file was deleted.

portal-ui/src/screens/Console/Buckets/BucketDetails/BucketLifecyclePanel.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import SecureComponent, {
4242
} from "../../../../common/SecureComponent/SecureComponent";
4343
import { IAM_SCOPES } from "../../../../common/SecureComponent/permissions";
4444
import RBIconButton from "./SummaryItems/RBIconButton";
45+
import DeleteBucketLifecycleRule from "./DeleteBucketLifecycleRule";
4546

4647
const styles = (theme: Theme) =>
4748
createStyles({
@@ -73,6 +74,9 @@ const BucketLifecyclePanel = ({
7374
const [editLifecycleOpen, setEditLifecycleOpen] = useState<boolean>(false);
7475
const [selectedLifecycleRule, setSelectedLifecycleRule] =
7576
useState<LifeCycleItem | null>(null);
77+
const [deleteLifecycleOpen, setDeleteLifecycleOpen] =
78+
useState<boolean>(false);
79+
const [selectedID, setSelectedID] = useState<string | null>(null);
7680

7781
const bucketName = match.params["bucketName"];
7882

@@ -99,6 +103,7 @@ const BucketLifecyclePanel = ({
99103
})
100104
.catch((err: ErrorResponseHandler) => {
101105
console.error(err);
106+
setLifecycleRecords([]);
102107
setLoadingLifecycle(false);
103108
});
104109
} else {
@@ -127,6 +132,15 @@ const BucketLifecyclePanel = ({
127132
}
128133
};
129134

135+
const closeDelLCRefresh = (refresh: boolean) => {
136+
setDeleteLifecycleOpen(false);
137+
setSelectedID(null);
138+
139+
if (refresh) {
140+
setLoadingLifecycle(true);
141+
}
142+
};
143+
130144
const expirationRender = (expiration: any) => {
131145
if (expiration.days) {
132146
return `${expiration.days} day${expiration.days > 1 ? "s" : ""}`;
@@ -194,6 +208,14 @@ const BucketLifecyclePanel = ({
194208
setEditLifecycleOpen(true);
195209
},
196210
},
211+
{
212+
type: "delete",
213+
onClick(valueToDelete: string): any {
214+
setSelectedID(valueToDelete);
215+
setDeleteLifecycleOpen(true);
216+
},
217+
sendOnlyId: true,
218+
},
197219
];
198220

199221
return (
@@ -213,6 +235,14 @@ const BucketLifecyclePanel = ({
213235
closeModalAndRefresh={closeAddLCAndRefresh}
214236
/>
215237
)}
238+
{deleteLifecycleOpen && selectedID && (
239+
<DeleteBucketLifecycleRule
240+
id={selectedID}
241+
bucket={bucketName}
242+
deleteOpen={deleteLifecycleOpen}
243+
onCloseAndRefresh={closeDelLCRefresh}
244+
/>
245+
)}
216246
<Grid container>
217247
<Grid item xs={12} className={classes.actionsTray}>
218248
<PanelTitle>Lifecycle Rules</PanelTitle>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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, useEffect } from "react";
18+
import { connect } from "react-redux";
19+
import { DialogContentText } from "@mui/material";
20+
import { Theme } from "@mui/material/styles";
21+
import createStyles from "@mui/styles/createStyles";
22+
import withStyles from "@mui/styles/withStyles";
23+
import { modalBasic } from "../../Common/FormComponents/common/styleLibrary";
24+
import { ErrorResponseHandler } from "../../../../common/types";
25+
import { setErrorSnackMessage } from "../../../../actions";
26+
import { ConfirmDeleteIcon } from "../../../../icons";
27+
import ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog";
28+
import api from "../../../../common/api";
29+
30+
interface IDeleteLifecycleRule {
31+
deleteOpen: boolean;
32+
onCloseAndRefresh: (refresh: boolean) => any;
33+
bucket: string;
34+
id: string;
35+
setErrorSnackMessage: typeof setErrorSnackMessage;
36+
}
37+
38+
const styles = (theme: Theme) =>
39+
createStyles({
40+
...modalBasic,
41+
});
42+
43+
const DeleteBucketLifecycleRule = ({
44+
onCloseAndRefresh,
45+
deleteOpen,
46+
bucket,
47+
id,
48+
setErrorSnackMessage,
49+
}: IDeleteLifecycleRule) => {
50+
const [deletingRule, setDeletingRule] = useState<boolean>(false);
51+
52+
useEffect(() => {
53+
if (deletingRule) {
54+
api
55+
.invoke("DELETE", `/api/v1/buckets/${bucket}/lifecycle/${id}`)
56+
.then((res) => {
57+
setDeletingRule(false);
58+
onCloseAndRefresh(true);
59+
})
60+
.catch((err: ErrorResponseHandler) => {
61+
setDeletingRule(false);
62+
setErrorSnackMessage(err);
63+
});
64+
}
65+
}, [deletingRule, bucket, id, onCloseAndRefresh, setErrorSnackMessage]);
66+
67+
const onConfirmDelete = () => {
68+
setDeletingRule(true);
69+
};
70+
71+
return (
72+
<ConfirmDialog
73+
title={`Delete Lifecycle Rule`}
74+
confirmText={"Delete"}
75+
isOpen={deleteOpen}
76+
isLoading={deletingRule}
77+
onConfirm={onConfirmDelete}
78+
titleIcon={<ConfirmDeleteIcon />}
79+
onClose={() => onCloseAndRefresh(false)}
80+
confirmationContent={
81+
<DialogContentText>
82+
Are you sure you want to delete the <strong>{id}</strong> rule?
83+
</DialogContentText>
84+
}
85+
/>
86+
);
87+
};
88+
89+
const connector = connect(null, {
90+
setErrorSnackMessage,
91+
});
92+
93+
export default withStyles(styles)(connector(DeleteBucketLifecycleRule));

portal-ui/src/screens/Console/Buckets/BucketDetails/EditLifecycleConfiguration.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ const EditLifecycleConfiguration = ({
141141
}, [ilmType, expiryDays, transitionDays, storageClass]);
142142

143143
useEffect(() => {
144-
console.log("lifecycle::", lifecycle);
145144
if (lifecycle.status === "Enabled") {
146145
setEnabled(true);
147146
}

restapi/embedded_spec.go

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

restapi/operations/console_api.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)