@@ -44,7 +44,6 @@ import { CreateIcon } from "../../../../icons";
44
44
import { niceBytes } from "../../../../common/utils" ;
45
45
import { containerForHeader } from "../../Common/FormComponents/common/styleLibrary" ;
46
46
import { setErrorSnackMessage } from "../../../../actions" ;
47
- import SetAccessPolicy from "./SetAccessPolicy" ;
48
47
import SetRetentionConfig from "./SetRetentionConfig" ;
49
48
import AddEvent from "./AddEvent" ;
50
49
import DeleteEvent from "./DeleteEvent" ;
@@ -56,6 +55,9 @@ import PencilIcon from "../../Common/TableWrapper/TableActionIcons/PencilIcon";
56
55
import EnableVersioningModal from "./EnableVersioningModal" ;
57
56
import Typography from "@material-ui/core/Typography" ;
58
57
import UsageIcon from "../../../../icons/UsageIcon" ;
58
+ import AddPolicy from "../../Policies/AddPolicy" ;
59
+ import SetAccessPolicy from "./SetAccessPolicy" ;
60
+ import { Policy } from "../../Policies/types" ;
59
61
60
62
const styles = ( theme : Theme ) =>
61
63
createStyles ( {
@@ -67,7 +69,6 @@ const styles = (theme: Theme) =>
67
69
overflow : "auto" ,
68
70
flexDirection : "column" ,
69
71
} ,
70
-
71
72
addSideBar : {
72
73
width : "320px" ,
73
74
padding : "20px" ,
@@ -219,6 +220,8 @@ const ViewBucket = ({
219
220
const [ replicationRules , setReplicationRules ] = useState <
220
221
BucketReplicationRule [ ]
221
222
> ( [ ] ) ;
223
+ const [ bucketPolicy , setBucketPolicy ] = useState < Policy [ ] > ( [ ] ) ;
224
+ const [ loadingPolicy , setLoadingPolicy ] = useState < boolean > ( true ) ;
222
225
const [ loadingBucket , setLoadingBucket ] = useState < boolean > ( true ) ;
223
226
const [ loadingEvents , setLoadingEvents ] = useState < boolean > ( true ) ;
224
227
const [ loadingVersioning , setLoadingVersioning ] = useState < boolean > ( true ) ;
@@ -231,6 +234,7 @@ const ViewBucket = ({
231
234
) ;
232
235
const [ curTab , setCurTab ] = useState < number > ( 0 ) ;
233
236
const [ addScreenOpen , setAddScreenOpen ] = useState < boolean > ( false ) ;
237
+ const [ policyScreenOpen , setPolicyScreenOpen ] = useState < boolean > ( false ) ;
234
238
const [
235
239
enableEncryptionScreenOpen ,
236
240
setEnableEncryptionScreenOpen ,
@@ -245,6 +249,7 @@ const ViewBucket = ({
245
249
const [ retentionConfigOpen , setRetentionConfigOpen ] = useState < boolean > (
246
250
false
247
251
) ;
252
+ const [ policyEdit , setPolicyEdit ] = useState < any > ( null ) ;
248
253
const [ enableVersioningOpen , setEnableVersioningOpen ] = useState < boolean > (
249
254
false
250
255
) ;
@@ -369,6 +374,21 @@ const ViewBucket = ({
369
374
}
370
375
} , [ loadingReplication , setErrorSnackMessage , bucketName ] ) ;
371
376
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
+
372
392
useEffect ( ( ) => {
373
393
if ( loadingSize ) {
374
394
api
@@ -436,6 +456,18 @@ const ViewBucket = ({
436
456
setLoadingEncryption ( true ) ;
437
457
} ;
438
458
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
+
439
471
const closeAddEventAndRefresh = ( ) => {
440
472
setAddScreenOpen ( false ) ;
441
473
loadAllBucketData ( ) ;
@@ -520,6 +552,14 @@ const ViewBucket = ({
520
552
} ;
521
553
522
554
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
+ ] ;
523
563
524
564
return (
525
565
< Fragment >
@@ -545,6 +585,13 @@ const ViewBucket = ({
545
585
closeModalAndRefresh = { closeSetAccessPolicy }
546
586
/>
547
587
) }
588
+ { policyScreenOpen && (
589
+ < AddPolicy
590
+ open = { policyScreenOpen }
591
+ closeModalAndRefresh = { closeAddModalAndRefresh }
592
+ policyEdit = { policyEdit }
593
+ />
594
+ ) }
548
595
{ retentionConfigOpen && (
549
596
< SetRetentionConfig
550
597
bucketName = { bucketName }
@@ -727,6 +774,7 @@ const ViewBucket = ({
727
774
{ canGetReplication && (
728
775
< Tab label = "Replication" { ...a11yProps ( 1 ) } />
729
776
) }
777
+ < Tab label = "Policies" { ...a11yProps ( 2 ) } />
730
778
</ Tabs >
731
779
</ Grid >
732
780
< Grid item xs = { 6 } className = { classes . actionsTray } >
@@ -811,6 +859,16 @@ const ViewBucket = ({
811
859
/>
812
860
</ TabPanel >
813
861
) }
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 >
814
872
</ Grid >
815
873
</ Grid >
816
874
</ Grid >
0 commit comments