Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Refactor Capacity Card and extract CapacityBody and CapacityItem to D… #301

Merged
merged 1 commit into from
Apr 3, 2019

Conversation

rawagner
Copy link
Contributor

@rawagner rawagner commented Apr 2, 2019

…ashboard folder

@rawagner
Copy link
Contributor Author

rawagner commented Apr 2, 2019

@gnehapk @cloudbehl FYI

@coveralls
Copy link

coveralls commented Apr 2, 2019

Pull Request Test Coverage Report for Build 1004

  • 45 of 50 (90.0%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 87.253%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Dashboard/Capacity/CapacityItem.js 28 29 96.55%
src/selectors/prometheus/selectors.js 4 8 50.0%
Totals Coverage Status
Change from base Build 1222: -0.2%
Covered Lines: 3064
Relevant Lines: 3358

💛 - Coveralls

};

export const CapacityItem = ({ idSuffix, title, used, total, unit, formatValue, LoadingComponent }) => {
if (!Number.isNaN(parseFloat(used)) && !Number.isNaN(parseFloat(total))) {
Copy link
Contributor

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

Copy link
Contributor Author

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">
Copy link
Contributor

@atiratree atiratree Apr 3, 2019

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.

Copy link
Contributor Author

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}`}
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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

@rawagner rawagner force-pushed the capacity_dashboard branch 2 times, most recently from 148df78 to f54cf49 Compare April 3, 2019 09:07
if (Number.isNaN(parseFloat(value))) {
return null;
}
return Number(value);
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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 ?

Copy link
Contributor

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;
}
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added isLoading prop and Not Available state.
capacity

<h6>{description}</h6>
<div>
<DonutChart
id={prefixedId('donut-chart', id)}
Copy link
Contributor

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.

@rawagner rawagner force-pushed the capacity_dashboard branch 5 times, most recently from d4cf9ad to 6959d51 Compare April 3, 2019 13:50
@@ -20,6 +20,8 @@ export const parseUrl = url => {
}
};

export const parseNumber = value => (!Number.isNaN(parseFloat(value)) && !Number.isNaN(Number(value)) ? Number(value) : null);
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@rawagner rawagner force-pushed the capacity_dashboard branch from 6959d51 to fea3c33 Compare April 3, 2019 14:15
@atiratree atiratree merged commit e98b86f into kubevirt:master Apr 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants