-
Notifications
You must be signed in to change notification settings - Fork 30
Refactor Capacity Card and extract CapacityBody and CapacityItem to D… #301
Conversation
@gnehapk @cloudbehl FYI |
Pull Request Test Coverage Report for Build 1004
💛 - Coveralls |
}; | ||
|
||
export const CapacityItem = ({ idSuffix, title, used, total, unit, formatValue, LoadingComponent }) => { | ||
if (!Number.isNaN(parseFloat(used)) && !Number.isNaN(parseFloat(total))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this component probably shouldn't do the parsing and expect numbers instead. We could maybe do this in getCapacityStats
. Then we can check for null here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parsing moved to getCapacityStats
and CapacityItem
is checking for null
}</span>`; | ||
|
||
const LoadingCapacityItem = ({ idSuffix, title, LoadingComponent }) => ( | ||
<div className="kubevirt-capacity__item"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this layout is already present in CapacityItem
. Can you please put some ifs there and do the loading design there? Current approach would make the layout duplicated and harder to modify in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
<h6>{`${availableNice} ${unit} available out of ${totalNice} ${unit}`}</h6> | ||
<div> | ||
<DonutChart | ||
id={`donut-chart-${idSuffix}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that the idSuffix is useful (lazy approach). But I would prefer the id part was configurable as well. Can you either create idPrefix prop with donut-chart
value as a default or add just an id prop which is more conventional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also there is a function called prefixedId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop renamed to id
and Im using prefixedId
now
148df78
to
f54cf49
Compare
if (Number.isNaN(parseFloat(value))) { | ||
return null; | ||
} | ||
return Number(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect whitespaces in the value? Number is more stronger so it could still return NaN
. We can just use the parseFloat value if we want to be more lenient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about whitespaces...i would say no and stick with the Number for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw https://stackoverflow.com/questions/12227594/which-is-better-numberx-or-parsefloatx. Each one of them has it's quirks. Can we check for NaN of both parseFloat
and Number
?
maybe it would be worth to also make a generic parsing function out of it. It would return number or null only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a number-like value is returned, not a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, still better to check against Number('') === 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new function in utils
- parseNumber
is using combination of parseFloat
/Number
/Number.isNaN
. WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
tooltip = { contents: pfGetUtilizationDonutTooltipContents }; | ||
primaryTitle = `${percentageUsed.toString()}%`; | ||
secondaryTitle = USED; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move at least the description = <LoadingComponent />
to else branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved
let tooltip; | ||
let primaryTitle = LOADING; | ||
let secondaryTitle = CAPACITY; | ||
if (used != null && total != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, on the secod look, I would rather pass isLoading from above and check that we already got the response (presence of response.data? in ClusterOverview/Capacity). This way the component can distinguish between three cases.
- loading (no response - pass isLoading boolean)
- loaded with wrong response (used/total is null) - we could show
Not Available
label for example - loaded correctly (show the data)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about the prometheus format when there is no data yet or if prometheus can return invalid response.
@rawagner thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suomiy I think that no data
can happen if prometheus didnt scrape the endpoint yet. Not sure about the invalid response. Anyways I will add Not Available
state too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<h6>{description}</h6> | ||
<div> | ||
<DonutChart | ||
id={prefixedId('donut-chart', id)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just didn't want to force the donut-chart
part on the consumer. Nevertheless it probably doesn't matter that much.
d4cf9ad
to
6959d51
Compare
src/utils/utils.js
Outdated
@@ -20,6 +20,8 @@ export const parseUrl = url => { | |||
} | |||
}; | |||
|
|||
export const parseNumber = value => (!Number.isNaN(parseFloat(value)) && !Number.isNaN(Number(value)) ? Number(value) : null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can reuse the result of Number(value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
6959d51
to
fea3c33
Compare
…ashboard folder