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