@@ -22,6 +22,7 @@ import { superuser } from "superuser";
2222import ContainerHeader from './ContainerHeader.jsx' ;
2323import Containers from './Containers.jsx' ;
2424import Images from './Images.jsx' ;
25+ import Volumes from './Volumes.jsx' ;
2526import * as client from './client.js' ;
2627import detect_quadlets from './detect-quadlets.py' ;
2728import rest from './rest.js' ;
@@ -46,7 +47,7 @@ class Application extends React.Component {
4647 constructor ( props ) {
4748 super ( props ) ;
4849 this . state = {
49- // currently connected services per user: { con, uid, name, dbus: { client, subscription }, imagesLoaded, containersLoaded, podsLoaded, quadletsLoaded }
50+ // currently connected services per user: { con, uid, name, dbus: { client, subscription }, imagesLoaded, containersLoaded, podsLoaded, quadletsLoaded, volumesLoaded }
5051 // start with dummy state to wait for initialization
5152 users : [ { con : null , uid : 0 , name : _ ( "system" ) , dbus : null } , { con : null , uid : null , name : _ ( "user" ) , dbus : null } ] ,
5253 images : null ,
@@ -60,6 +61,7 @@ class Application extends React.Component {
6061 quadletContainers : { } ,
6162 // { "$uid-$name-pod.service": { source_path, name } }
6263 quadletPods : { } ,
64+ volumes : null ,
6365 textFilter : "" ,
6466 ownerFilter : "all" ,
6567 dropDownValue : 'Everything' ,
@@ -196,6 +198,30 @@ class Application extends React.Component {
196198 . catch ( e => console . warn ( "initContainers uid" , con . uid , "getContainers failed:" , e . toString ( ) ) ) ;
197199 }
198200
201+ initVolumes ( con ) {
202+ return client . getVolumes ( con )
203+ . then ( volumesList => {
204+ console . log ( volumesList ) ;
205+ this . setState ( prevState => {
206+ const copyVolumes = { } ;
207+ Object . entries ( prevState . volumes || { } ) . forEach ( ( [ id , volume ] ) => {
208+ if ( volume . uid !== con . uid )
209+ copyVolumes [ id ] = volume ;
210+ } ) ;
211+
212+ for ( const volume of volumesList || [ ] ) {
213+ volume . uid = con . uid ;
214+ volume . key = makeKey ( con . uid , volume . Name ) ;
215+ copyVolumes [ volume . key ] = volume ;
216+ }
217+
218+ const users = prevState . users . map ( u => u . uid === con . uid ? { ...u , volumesLoaded : true } : u ) ;
219+ return { volumes : copyVolumes , users } ;
220+ } ) ;
221+ } )
222+ . catch ( ex => console . warn ( "Failed to fetch volumes for uid" , con . uid , ":" , JSON . stringify ( ex ) ) ) ;
223+ }
224+
199225 updateImages ( con ) {
200226 client . getImages ( con )
201227 . then ( reply => {
@@ -418,6 +444,24 @@ class Application extends React.Component {
418444 }
419445 }
420446
447+ handleVolumeEvent ( event , con ) {
448+ console . log ( event , con ) ;
449+ switch ( event . Action ) {
450+ case 'create' :
451+ this . initVolumes ( con ) ;
452+ break ;
453+ case 'remove' :
454+ this . setState ( prevState => {
455+ const volumes = { ...prevState . volumes } ;
456+ delete volumes [ makeKey ( con . uid , event . Actor . Attributes . name ) ] ;
457+ return { volumes } ;
458+ } ) ;
459+ break ;
460+ default :
461+ console . warn ( 'Unhandled event type ' , event . Type , event . Action ) ;
462+ }
463+ }
464+
421465 handleEvent ( event , con ) {
422466 switch ( event . Type ) {
423467 case 'container' :
@@ -429,6 +473,9 @@ class Application extends React.Component {
429473 case 'pod' :
430474 this . handlePodEvent ( event , con ) ;
431475 break ;
476+ case 'volume' :
477+ this . handleVolumeEvent ( event , con ) ;
478+ break ;
432479 default :
433480 console . warn ( 'Unhandled event type ' , event . Type ) ;
434481 }
@@ -638,7 +685,7 @@ class Application extends React.Component {
638685 const reply = await client . getInfo ( con ) ;
639686 this . setState ( prevState => {
640687 const users = prevState . users . filter ( u => u . uid !== uid ) ;
641- users . push ( { con, uid, name : username , containersLoaded : false , podsLoaded : false , imagesLoaded : false , quadletsLoaded : false } ) ;
688+ users . push ( { con, uid, name : username , containersLoaded : false , podsLoaded : false , imagesLoaded : false , quadletsLoaded : false , volumesLoaded : false } ) ;
642689 // keep a nice sort order for dialogs
643690 users . sort ( compareUser ) ;
644691 debug ( "init uid" , uid , "username" , username , "new users:" , users ) ;
@@ -660,6 +707,7 @@ class Application extends React.Component {
660707 this . updateImages ( con ) ;
661708 this . initContainers ( con ) ;
662709 this . initQuadlets ( con ) ;
710+ this . initVolumes ( con ) ;
663711 this . subscribeDaemonReload ( con ) ;
664712 this . updatePods ( con ) ;
665713
@@ -878,6 +926,7 @@ class Application extends React.Component {
878926 const loadingContainers = this . state . users . find ( u => u . con && ! u . containersLoaded ) ;
879927 const loadingPods = this . state . users . find ( u => u . con && ! u . podsLoaded ) ;
880928 const loadingQuadlets = this . state . users . find ( u => u . con && ! u . quadletsLoaded ) ;
929+ const loadingVolumes = this . state . users . find ( u => u . con && ! u . volumesLoaded ) ;
881930
882931 const imageList = (
883932 < Images
@@ -912,6 +961,16 @@ class Application extends React.Component {
912961 />
913962 ) ;
914963
964+ const volumeList = (
965+ < Volumes
966+ key = "volumeList"
967+ users = { this . state . users }
968+ textFilter = { this . state . textFilter }
969+ ownerFilter = { this . state . ownerFilter }
970+ volumes = { loadingVolumes ? null : this . state . volumes }
971+ />
972+ ) ;
973+
915974 const notificationList = (
916975 < AlertGroup isToast >
917976 { this . state . notifications . map ( ( notification , index ) => {
@@ -953,6 +1012,7 @@ class Application extends React.Component {
9531012 < PageSection hasBodyWrapper = { false } className = 'ct-pagesection-mobile' >
9541013 < Stack hasGutter >
9551014 { imageList }
1015+ { volumeList }
9561016 { containerList }
9571017 </ Stack >
9581018 </ PageSection >
0 commit comments