11import * as React from "react" ;
22import { Link } from "@fluentui/react" ;
3- import { MachineService } from "@hpcc-js/comms " ;
4- import { scopedLogger } from "@hpcc-js/util " ;
3+ import { Divider , Toolbar , ToolbarButton } from "@fluentui/react-components " ;
4+ import { ArrowClockwise20Regular } from "@fluentui/react-icons " ;
55import { ComponentDetails as ComponentDetailsWidget , Summary as SummaryWidget } from "src/DiskUsage" ;
66import nlsHPCC from "src/nlsHPCC" ;
77import * as Utility from "src/Utility" ;
88import { AutosizeHpccJSComponent } from "../layouts/HpccJSAdapter" ;
9- import { ReflexContainer , ReflexElement , ReflexSplitter , classNames , styles } from "../layouts/react-reflex" ;
9+ import { HolyGrail } from "../layouts/HolyGrail" ;
10+ import { SizeMe } from "../layouts/SizeMe" ;
1011import { pushUrl } from "../util/history" ;
1112import { FluentGrid , useFluentStoreState } from "./controls/Grid" ;
12-
13- const logger = scopedLogger ( "src-react/components/DiskUsage.tsx" ) ;
14-
15- const machineService = new MachineService ( { baseUrl : "" } ) ;
13+ import { FolderUsageCards } from "./cards/DiskUsageCard" ;
14+ import { useTargetClusterUsageEx } from "../hooks/diskUsage" ;
1615
1716interface SummaryProps {
1817 cluster ?: string ;
@@ -34,15 +33,17 @@ export const Summary: React.FunctionComponent<SummaryProps> = ({
3433 return < AutosizeHpccJSComponent widget = { summary } > </ AutosizeHpccJSComponent > ;
3534} ;
3635
37- interface DetailsProps {
36+ interface ClusterUsageProps {
3837 cluster : string ;
3938}
4039
41- export const Details : React . FunctionComponent < DetailsProps > = ( {
40+ export const ClusterUsage : React . FunctionComponent < ClusterUsageProps > = ( {
4241 cluster
4342} ) => {
4443
4544 const { refreshTable } = useFluentStoreState ( { } ) ;
45+ const [ refreshToken , setRefreshToken ] = React . useState ( 0 ) ;
46+ const { data : usage , refresh } = useTargetClusterUsageEx ( cluster ) ;
4647
4748 // Grid ---
4849 const columns = React . useMemo ( ( ) => {
@@ -72,51 +73,48 @@ export const Details: React.FunctionComponent<DetailsProps> = ({
7273
7374 type Columns = typeof columns ;
7475 type Row = { __hpcc_id : string } & { [ K in keyof Columns ] : string | number } ;
75- const [ data , setData ] = React . useState < Row [ ] > ( [ ] ) ;
76-
77- const refreshData = React . useCallback ( ( ) => {
78- machineService . GetTargetClusterUsageEx ( [ cluster ] )
79- . then ( response => {
80- const _data : Row [ ] = [ ] ;
81- if ( response ) {
82- response . forEach ( component => {
83- component . ComponentUsages . forEach ( cu => {
84- cu . MachineUsages . forEach ( mu => {
85- mu . DiskUsages . forEach ( ( du , i ) => {
86- _data . push ( {
87- __hpcc_id : `__usage_${ i } ` ,
88- PercentUsed : Math . round ( ( du . InUse / du . Total ) * 100 ) ,
89- Component : cu . Name ,
90- IPAddress : mu . Name ,
91- Type : du . Name ,
92- Path : du . Path ,
93- InUse : Utility . convertedSize ( du . InUse ) ,
94- Total : Utility . convertedSize ( du . Total )
95- } ) ;
96- } ) ;
97- } ) ;
76+ const data = React . useMemo < Row [ ] > ( ( ) => {
77+ const rows : Row [ ] = [ ] ;
78+ ( usage ?? [ ] ) . forEach ( component => {
79+ component . ComponentUsages . forEach ( cu => {
80+ cu . MachineUsages . forEach ( mu => {
81+ mu . DiskUsages . forEach ( ( du , i ) => {
82+ rows . push ( {
83+ __hpcc_id : `__usage_${ i } ` ,
84+ PercentUsed : Math . round ( ( du . InUse / du . Total ) * 100 ) ,
85+ Component : cu . Name ,
86+ IPAddress : mu . Name ,
87+ Type : du . Name ,
88+ Path : du . Path ,
89+ InUse : Utility . convertedSize ( du . InUse ) ,
90+ Total : Utility . convertedSize ( du . Total )
9891 } ) ;
9992 } ) ;
100- }
101- setData ( _data ) ;
102- } )
103- . catch ( err => logger . error ( err ) )
104- ;
105- } , [ cluster ] ) ;
106-
107- React . useEffect ( ( ) => {
108- refreshData ( ) ;
109- } , [ refreshData ] ) ;
110-
111- return < FluentGrid
112- data = { data }
113- primaryID = { "__hpcc_id" }
114- sort = { { attribute : "__hpcc_id" , descending : false } }
115- columns = { columns }
116- setSelection = { ( ) => null }
117- setTotal = { ( ) => null }
118- refresh = { refreshTable }
119- > </ FluentGrid > ;
93+ } ) ;
94+ } ) ;
95+ } ) ;
96+ return rows ;
97+ } , [ usage ] ) ;
98+
99+ return < HolyGrail
100+ header = {
101+ < Toolbar >
102+ < ToolbarButton appearance = "subtle" icon = { < ArrowClockwise20Regular /> } aria-label = { nlsHPCC . Refresh } onClick = { ( ) => { refresh ( ) ; setRefreshToken ( t => t + 1 ) ; } } >
103+ { nlsHPCC . Refresh }
104+ </ ToolbarButton >
105+ </ Toolbar >
106+ }
107+ main = { < SizeMe > { ( { size } ) => {
108+ return < div style = { { position : "relative" , width : "100%" , height : "100%" } } >
109+ < div style = { { position : "absolute" , width : "100%" , height : `${ size . height } px` , overflowY : "auto" } } >
110+ < Divider > { nlsHPCC . Category } </ Divider >
111+ < FolderUsageCards cluster = { cluster } refreshToken = { refreshToken } />
112+ < Divider > { nlsHPCC . Folders } </ Divider >
113+ < FluentGrid data = { data } primaryID = "__hpcc_id" sort = { { attribute : "__hpcc_id" , descending : false } } columns = { columns } setSelection = { ( ) => null } setTotal = { ( ) => null } refresh = { refreshTable } />
114+ </ div >
115+ </ div > ;
116+ } } </ SizeMe > }
117+ /> ;
120118} ;
121119
122120interface MachineUsageProps {
@@ -135,23 +133,3 @@ export const MachineUsage: React.FunctionComponent<MachineUsageProps> = ({
135133
136134 return < AutosizeHpccJSComponent widget = { summary } > </ AutosizeHpccJSComponent > ;
137135} ;
138-
139- interface ClusterUsageProps {
140- cluster : string ;
141- }
142-
143- export const ClusterUsage : React . FunctionComponent < ClusterUsageProps > = ( {
144- cluster
145- } ) => {
146- return < ReflexContainer orientation = "horizontal" >
147- < ReflexElement minSize = { 100 } size = { 100 } style = { { overflow : "hidden" } } >
148- < Summary cluster = { cluster } />
149- </ ReflexElement >
150- < ReflexSplitter style = { styles . reflexSplitter } >
151- < div className = { classNames . reflexSplitterDiv } > </ div >
152- </ ReflexSplitter >
153- < ReflexElement style = { { overflow : "hidden" } } >
154- < Details cluster = { cluster } />
155- </ ReflexElement >
156- </ ReflexContainer > ;
157- } ;
0 commit comments