1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17- import React from "react" ;
17+ import { useMemo } from "react" ;
1818import get from "lodash/get" ;
19- import styled from "styled-components" ;
19+ import { useTheme } from "styled-components" ;
2020import { niceBytes } from "../../../../common/utils" ;
2121import { Box , breakPoints , CircleIcon , SizeChart } from "mds" ;
2222import { ServerDrives } from "api/consoleApi" ;
@@ -26,159 +26,201 @@ interface ICardProps {
2626 drive : ServerDrives ;
2727}
2828
29- const driveStatusColor = ( health_status : string ) => {
30- switch ( health_status ) {
31- case "offline" :
32- return STATUS_COLORS . RED ;
33- case "ok" :
34- return STATUS_COLORS . GREEN ;
35- default :
36- return STATUS_COLORS . YELLOW ;
37- }
38- } ;
29+ const DriveInfoItem = ( { drive } : ICardProps ) => {
30+ const theme = useTheme ( ) ;
3931
40- const DataContainerMain = styled . div ( ( { theme } ) => ( {
41- flex : 1 ,
42- display : "flex" ,
43- alignItems : "center" ,
44- paddingLeft : "20px" ,
45- marginTop : "10px" ,
46- flexFlow : "row" ,
47- "& .info-label" : {
48- color : get ( theme , "mutedText" , "#87888d" ) ,
49- fontSize : "12px" ,
50- textAlign : "center" ,
51- } ,
52- "& .info-value" : {
53- fontSize : "18px" ,
54- color : get ( theme , "signalColors.main" , "#07193E" ) ,
55- display : "flex" ,
56- fontWeight : 500 ,
57- overflow : "hidden" ,
58- textOverflow : "ellipsis" ,
59- whiteSpace : "nowrap" ,
60- } ,
61- [ `@media (max-width: ${ breakPoints . sm } px)` ] : {
62- flexFlow : "column" ,
63- } ,
64- } ) ) ;
32+ const totalSpace = drive . totalSpace ?? 0 ;
33+ const usedSpace = drive . usedSpace ?? 0 ;
34+ const usedPercentage = ( usedSpace / totalSpace ) * 100 ;
35+ const availableSpace = drive . availableSpace ?? 0 ;
36+ const availablePercentage = ( availableSpace / totalSpace ) * 100 ;
6537
66- const DriveInfoItem = ( { drive } : ICardProps ) => {
67- const totalSpace = drive . totalSpace || 0 ;
68- const usedSpace = drive . usedSpace || 0 ;
38+ const driveStatusColor = useMemo ( ( ) => {
39+ switch ( drive . state ) {
40+ case "offline" :
41+ return STATUS_COLORS . RED ;
42+ case "ok" :
43+ return STATUS_COLORS . GREEN ;
44+ default :
45+ return STATUS_COLORS . YELLOW ;
46+ }
47+ } , [ drive . state ] ) ;
48+
49+ const driveStatusText = useMemo ( ( ) => {
50+ switch ( drive . state ) {
51+ case "offline" :
52+ return "Offline Drive" ;
53+ case "ok" :
54+ return "Online Drive" ;
55+ default :
56+ return "Unknown" ;
57+ }
58+ } , [ drive . state ] ) ;
6959
7060 return (
7161 < Box
7262 withBorders
7363 sx = { {
7464 display : "flex" ,
75- flex : 1 ,
65+ flexFlow : "row" ,
66+ padding : 12 ,
67+ gap : 24 ,
7668 alignItems : "center" ,
77- paddingBottom : "10px" ,
78- padding : "20px" ,
69+ [ `@media (max-width: ${ breakPoints . sm } px)` ] : {
70+ padding : 24 ,
71+ } ,
72+ [ `@media (max-width: ${ breakPoints . xs } px)` ] : {
73+ flexFlow : "column" ,
74+ alignItems : "start" ,
75+ } ,
76+ "& .info-label" : {
77+ color : get ( theme , "mutedText" , "#87888d" ) ,
78+ fontSize : 12 ,
79+ } ,
80+ "& .info-value" : {
81+ fontSize : 18 ,
82+ color : get ( theme , "signalColors.main" , "#07193E" ) ,
83+ display : "flex" ,
84+ fontWeight : 500 ,
85+ overflow : "hidden" ,
86+ textOverflow : "ellipsis" ,
87+ whiteSpace : "nowrap" ,
88+ } ,
89+ "& .drive-endpoint" : {
90+ overflow : "hidden" ,
91+ textOverflow : "ellipsis" ,
92+ whiteSpace : "normal" ,
93+ wordBreak : "break-all" ,
94+ fontWeight : 600 ,
95+ fontSize : 16 ,
96+ [ `@media (max-width: ${ breakPoints . sm } px)` ] : {
97+ fontSize : 10 ,
98+ } ,
99+ } ,
100+ "& .percentage-row" : {
101+ display : "flex" ,
102+ gap : 4 ,
103+ alignItems : "center" ,
104+ fontSize : 12 ,
105+ "& .percentage-value" : {
106+ fontWeight : 700 ,
107+ } ,
108+ } ,
79109 } }
80110 >
111+ < SizeChart
112+ chartLabel = "Used Capacity"
113+ label = { true }
114+ usedBytes = { usedSpace }
115+ totalBytes = { totalSpace }
116+ width = { "153" }
117+ height = { "153" }
118+ />
81119 < Box
82120 sx = { {
83121 display : "flex" ,
84122 flexFlow : "column" ,
85- marginLeft : "10px" ,
123+ gap : 12 ,
86124 flex : 1 ,
87125 } }
88126 >
89127 < Box
90128 sx = { {
91- fontSize : "14px" ,
92- fontWeight : 400 ,
93129 display : "flex" ,
94- alignItems : "center" ,
95-
96- "& .min-icon" : {
97- marginRight : "10px" ,
98- height : "10px" ,
99- width : "10px" ,
100- fill : driveStatusColor ( drive . state || "" ) ,
101- flexShrink : 0 ,
102- } ,
103-
104- "& .drive-endpoint" : {
105- overflow : "hidden" ,
106- textOverflow : "ellipsis" ,
107- whiteSpace : "normal" ,
108- wordBreak : "break-all" ,
109- marginRight : "8px" ,
110- fontWeight : 600 ,
111- fontSize : 16 ,
112- [ `@media (max-width: ${ breakPoints . sm } px)` ] : {
113- fontSize : 10 ,
114- } ,
130+ flexFlow : "row" ,
131+ gap : 8 ,
132+ [ `@media (max-width: ${ breakPoints . xs } px)` ] : {
133+ flexFlow : "column" ,
115134 } ,
116135 } }
117136 >
118- < div className = "drive-endpoint" > { drive . endpoint || "" } </ div >
119- { drive . state && < CircleIcon /> }
120- </ Box >
121-
122- < DataContainerMain >
123- < Box sx = { { flex : 1 } } >
124- < SizeChart
125- label = { true }
126- usedBytes = { usedSpace }
127- totalBytes = { totalSpace }
128- width = { "120" }
129- height = { "120" }
130- />
137+ < Box
138+ sx = { {
139+ flex : "1 1 60%" ,
140+ [ `@media (max-width: ${ breakPoints . xs } px)` ] : {
141+ flex : "1 1 100%" ,
142+ } ,
143+ } }
144+ >
145+ < label className = "info-label" > Drive Name</ label >
146+ < Box className = "drive-endpoint" > { drive . endpoint ?? "" } </ Box >
131147 </ Box >
132-
133148 < Box
134149 sx = { {
135- display : "flex" ,
136- gap : "5%" ,
137- alignItems : "center" ,
138- flex : 2 ,
139- flexGrow : 1 ,
150+ flex : "1 1 20%" ,
151+ [ `@media (max-width: ${ breakPoints . xs } px)` ] : {
152+ flex : "1 1 100%" ,
153+ } ,
140154 } }
141155 >
156+ < label className = "info-label" > Drive Status</ label >
142157 < Box
143158 sx = { {
144159 display : "flex" ,
145- flexFlow : "column" ,
160+ flexFlow : "row" ,
161+ alignItems : "center" ,
162+ fontSize : 12 ,
163+ fontWeight : 600 ,
164+ gap : 4 ,
165+ color : driveStatusColor ,
166+ "& .min-icon" : {
167+ height : 8 ,
168+ width : 8 ,
169+ flexShrink : 0 ,
170+ } ,
146171 } }
147172 >
148- < div className = "info-value" >
149- { niceBytes (
150- drive . totalSpace ? drive . totalSpace . toString ( ) : "0" ,
151- ) }
152- </ div >
153- < label className = "info-label" > Capacity</ label >
173+ < CircleIcon />
174+ { driveStatusText }
154175 </ Box >
155-
156- < Box
157- sx = { {
158- display : "flex" ,
159- flexFlow : "column" ,
160- } }
161- >
162- < div className = "info-value" >
163- { niceBytes ( drive . usedSpace ? drive . usedSpace . toString ( ) : "0" ) }
164- </ div >
165- < label className = "info-label" > Used</ label >
176+ </ Box >
177+ </ Box >
178+ < Box
179+ sx = { {
180+ display : "flex" ,
181+ flexFlow : "row" ,
182+ gap : 36 ,
183+ } }
184+ >
185+ < Box
186+ sx = { {
187+ display : "flex" ,
188+ flexFlow : "column" ,
189+ } }
190+ >
191+ < label className = "info-label" > Used Capacity</ label >
192+ < Box className = "info-value" > { niceBytes ( usedSpace . toString ( ) ) } </ Box >
193+ < Box className = "percentage-row" >
194+ < Box className = "percentage-value" >
195+ { usedPercentage . toFixed ( 2 ) } %
196+ </ Box >
197+ < Box > of { niceBytes ( totalSpace . toString ( ) ) } </ Box >
166198 </ Box >
167- < Box
168- sx = { {
169- display : "flex" ,
170- flexFlow : "column" ,
171- } }
172- >
173- < div className = "info-value" >
174- { niceBytes (
175- drive . availableSpace ? drive . availableSpace . toString ( ) : "0" ,
176- ) }
177- </ div >
178- < label className = "info-label" > Available</ label >
199+ </ Box >
200+ < Box
201+ sx = { {
202+ width : 1 ,
203+ backgroundColor : get ( theme , "borderColor" , "#BBBBBB" ) ,
204+ } }
205+ />
206+ < Box
207+ sx = { {
208+ display : "flex" ,
209+ flexFlow : "column" ,
210+ } }
211+ >
212+ < label className = "info-label" > Available Capacity</ label >
213+ < Box className = "info-value" >
214+ { niceBytes ( availableSpace . toString ( ) ) }
215+ </ Box >
216+ < Box className = "percentage-row" >
217+ < Box className = "percentage-value" >
218+ { availablePercentage . toFixed ( 2 ) } %
219+ </ Box >
220+ < Box > of { niceBytes ( totalSpace . toString ( ) ) } </ Box >
179221 </ Box >
180222 </ Box >
181- </ DataContainerMain >
223+ </ Box >
182224 </ Box >
183225 </ Box >
184226 ) ;
0 commit comments