Skip to content

Commit 23b3283

Browse files
adfostAdam Stafford
andauthored
Adding Bucket Policies UI to ViewBucket.tsx (#669)
* Adding ViewBucket.tsx * Update ViewBucket.tsx Co-authored-by: Adam Stafford <adam@minio.io>
1 parent 53eb59f commit 23b3283

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

portal-ui/src/screens/Console/Buckets/ViewBucket/ViewBucket.tsx

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import { CreateIcon } from "../../../../icons";
4444
import { niceBytes } from "../../../../common/utils";
4545
import { containerForHeader } from "../../Common/FormComponents/common/styleLibrary";
4646
import { setErrorSnackMessage } from "../../../../actions";
47-
import SetAccessPolicy from "./SetAccessPolicy";
4847
import SetRetentionConfig from "./SetRetentionConfig";
4948
import AddEvent from "./AddEvent";
5049
import DeleteEvent from "./DeleteEvent";
@@ -56,6 +55,9 @@ import PencilIcon from "../../Common/TableWrapper/TableActionIcons/PencilIcon";
5655
import EnableVersioningModal from "./EnableVersioningModal";
5756
import Typography from "@material-ui/core/Typography";
5857
import UsageIcon from "../../../../icons/UsageIcon";
58+
import AddPolicy from "../../Policies/AddPolicy";
59+
import SetAccessPolicy from "./SetAccessPolicy";
60+
import { Policy } from "../../Policies/types";
5961

6062
const styles = (theme: Theme) =>
6163
createStyles({
@@ -67,7 +69,6 @@ const styles = (theme: Theme) =>
6769
overflow: "auto",
6870
flexDirection: "column",
6971
},
70-
7172
addSideBar: {
7273
width: "320px",
7374
padding: "20px",
@@ -219,6 +220,8 @@ const ViewBucket = ({
219220
const [replicationRules, setReplicationRules] = useState<
220221
BucketReplicationRule[]
221222
>([]);
223+
const [bucketPolicy, setBucketPolicy] = useState<Policy[]>([]);
224+
const [loadingPolicy, setLoadingPolicy] = useState<boolean>(true);
222225
const [loadingBucket, setLoadingBucket] = useState<boolean>(true);
223226
const [loadingEvents, setLoadingEvents] = useState<boolean>(true);
224227
const [loadingVersioning, setLoadingVersioning] = useState<boolean>(true);
@@ -231,6 +234,7 @@ const ViewBucket = ({
231234
);
232235
const [curTab, setCurTab] = useState<number>(0);
233236
const [addScreenOpen, setAddScreenOpen] = useState<boolean>(false);
237+
const [policyScreenOpen, setPolicyScreenOpen] = useState<boolean>(false);
234238
const [
235239
enableEncryptionScreenOpen,
236240
setEnableEncryptionScreenOpen,
@@ -245,6 +249,7 @@ const ViewBucket = ({
245249
const [retentionConfigOpen, setRetentionConfigOpen] = useState<boolean>(
246250
false
247251
);
252+
const [policyEdit, setPolicyEdit] = useState<any>(null);
248253
const [enableVersioningOpen, setEnableVersioningOpen] = useState<boolean>(
249254
false
250255
);
@@ -369,6 +374,21 @@ const ViewBucket = ({
369374
}
370375
}, [loadingReplication, setErrorSnackMessage, bucketName]);
371376

377+
useEffect(() => {
378+
if (loadingPolicy) {
379+
api
380+
.invoke("GET", `/api/v1/bucket-policy/${bucketName}`)
381+
.then((res: any) => {
382+
setBucketPolicy(res.policies);
383+
setLoadingPolicy(false);
384+
})
385+
.catch((err: any) => {
386+
setErrorSnackMessage(err);
387+
setLoadingPolicy(false);
388+
});
389+
}
390+
}, [loadingPolicy, setErrorSnackMessage, bucketName]);
391+
372392
useEffect(() => {
373393
if (loadingSize) {
374394
api
@@ -436,6 +456,18 @@ const ViewBucket = ({
436456
setLoadingEncryption(true);
437457
};
438458

459+
const closeAddModalAndRefresh = (refresh: boolean) => {
460+
setPolicyScreenOpen(false);
461+
462+
if (refresh) {
463+
fetchPolicies();
464+
}
465+
};
466+
467+
const fetchPolicies = () => {
468+
setLoadingPolicy(true);
469+
};
470+
439471
const closeAddEventAndRefresh = () => {
440472
setAddScreenOpen(false);
441473
loadAllBucketData();
@@ -520,6 +552,14 @@ const ViewBucket = ({
520552
};
521553

522554
const tableActions = [{ type: "delete", onClick: confirmDeleteEvent }];
555+
const viewAction = (row: any) => {
556+
setPolicyScreenOpen(true);
557+
setPolicyEdit(row);
558+
};
559+
560+
const PolicyActions = [
561+
{ type: "view", onClick: viewAction },
562+
];
523563

524564
return (
525565
<Fragment>
@@ -545,6 +585,13 @@ const ViewBucket = ({
545585
closeModalAndRefresh={closeSetAccessPolicy}
546586
/>
547587
)}
588+
{policyScreenOpen && (
589+
<AddPolicy
590+
open={policyScreenOpen}
591+
closeModalAndRefresh={closeAddModalAndRefresh}
592+
policyEdit={policyEdit}
593+
/>
594+
)}
548595
{retentionConfigOpen && (
549596
<SetRetentionConfig
550597
bucketName={bucketName}
@@ -727,6 +774,7 @@ const ViewBucket = ({
727774
{canGetReplication && (
728775
<Tab label="Replication" {...a11yProps(1)} />
729776
)}
777+
<Tab label="Policies" {...a11yProps(2)} />
730778
</Tabs>
731779
</Grid>
732780
<Grid item xs={6} className={classes.actionsTray}>
@@ -811,6 +859,16 @@ const ViewBucket = ({
811859
/>
812860
</TabPanel>
813861
)}
862+
<TabPanel index={2} value={curTab}>
863+
<TableWrapper
864+
itemActions={PolicyActions}
865+
columns={[{ label: "Name", elementKey: "name" }]}
866+
isLoading={loadingEvents}
867+
records={bucketPolicy}
868+
entityName="Policies"
869+
idField="name"
870+
/>
871+
</TabPanel>
814872
</Grid>
815873
</Grid>
816874
</Grid>

0 commit comments

Comments
 (0)