@@ -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" ;
3131import { setErrorSnackMessage } from "../../../../actions" ;
3232import { ErrorResponseHandler } from "../../../../common/types" ;
3333import api from "../../../../common/api" ;
3434import TableWrapper from "../../Common/TableWrapper/TableWrapper" ;
3535import 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
3742interface ITenantVolumesProps {
3843 classes : any ;
3944 setErrorSnackMessage : typeof setErrorSnackMessage ;
4045 match : any ;
46+ loadingTenant : boolean ;
47+ setTenantDetailsLoad : typeof setTenantDetailsLoad ;
4148}
4249
4350const 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+
149192const mapDispatchToProps = {
150193 setErrorSnackMessage,
151194} ;
152195
153- const connector = connect ( null , mapDispatchToProps ) ;
196+ const connector = connect ( mapState , mapDispatchToProps ) ;
154197
155198export default withStyles ( styles ) ( connector ( TenantVolumes ) ) ;
0 commit comments