-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pci.savings-plan): view percentage consumption #15236
base: feat/TAPC-2358-svp-dashboard
Are you sure you want to change the base?
feat(pci.savings-plan): view percentage consumption #15236
Conversation
const { t } = useTranslation('dashboard'); | ||
const data = [ | ||
const computedUsagePercent = calculateAverageUtilization(consumption); |
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.
should be wrapped in a useMemo
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
import { SavingsPlanConsumption } from '@/types/savingsPlanConsumption.type'; | ||
|
||
export const calculateAverageUtilization = ( | ||
consumption: SavingsPlanConsumption | 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.
I think the null value should be handled by the caller
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.
there ? const computedUsagePercent = calculateAverageUtilization(consumption);
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.
yes
export const calculateAverageUtilization = ( | ||
consumption: SavingsPlanConsumption | null, | ||
): number | null => { | ||
if (!consumption?.flavors || consumption.flavors.length === 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.
the test on flavors length is already handled line 19
Does consumption.flavors
could be null ? If so I think you could handle this case line 10 with || []
This would simplifies the readability
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.
flavors couln't be null you right, I'll fix it
@@ -0,0 +1,27 @@ | |||
import { SavingsPlanConsumption } from '@/types/savingsPlanConsumption.type'; | |||
|
|||
export const calculateAverageUtilization = ( |
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.
export const calculateAverageUtilization = ( | |
export const calculateAverageUsage = ( |
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
utilizationValues.reduce((sum, value) => sum + value, 0) / | ||
utilizationValues.length; | ||
|
||
return Number(averageUtilization.toFixed(2)); |
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.
Fixing digits should be handled by the display layer and shouldn't be converted back to number or it could lead to errors due to IEE-754
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.
what do you suggest, it this should be fixed into the render ?
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.
Yes, the .toFixed should inside the react component
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
import { SavingsPlanConsumption } from '@/types/savingsPlanConsumption.type'; | ||
|
||
describe('calculateAverageUtilization', () => { | ||
it('should return null when consumption is 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.
As a global improvement, you could iterate over an array of 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.
you right, done
ref: TAPC-1779 Signed-off-by: Eric Ciccotti <[email protected]>
9121f2f
to
1edad29
Compare
Quality Gate passedIssues Measures |
feat/TAPC-2358-svp-dashboard
Description
KPI view percentage consumption for savings plan