Skip to content
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

Open
wants to merge 1 commit into
base: feat/TAPC-2358-svp-dashboard
Choose a base branch
from

Conversation

Eric-ciccotti
Copy link
Contributor

@Eric-ciccotti Eric-ciccotti commented Jan 31, 2025

Question Answer
Branch? feat/TAPC-2358-svp-dashboard
Bug fix? no
New feature? yes
Breaking change? no
Tickets Fix #TAPC-1779
License BSD 3-Clause
  • Try to keep pull requests small so they can be easily reviewed.
  • Commits are signed-off
  • Only FR translations have been updated
  • Branch is up-to-date with target branch
  • Lint has passed locally
  • Standalone app was ran and tested locally
  • Ticket reference is mentioned in linked commits (internal only)
  • Breaking change is mentioned in relevant commits

Description

KPI view percentage consumption for savings plan

@Eric-ciccotti Eric-ciccotti requested review from a team as code owners January 31, 2025 14:04
@Eric-ciccotti Eric-ciccotti requested review from tibs245, aboungnaseng-ovhcloud, sidlynx, seven-amid, qpavy and ghyenne and removed request for a team January 31, 2025 14:04
@Eric-ciccotti Eric-ciccotti changed the title feat(pci.savings-plan): feat(pci.savings-plan): view percentage consumption Jan 31, 2025
const { t } = useTranslation('dashboard');
const data = [
const computedUsagePercent = calculateAverageUtilization(consumption);
Copy link
Contributor

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

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

import { SavingsPlanConsumption } from '@/types/savingsPlanConsumption.type';

export const calculateAverageUtilization = (
consumption: SavingsPlanConsumption | null,
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 the null value should be handled by the caller

Copy link
Contributor Author

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);

Copy link
Contributor

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

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

Copy link
Contributor Author

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 = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const calculateAverageUtilization = (
export const calculateAverageUsage = (

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

utilizationValues.reduce((sum, value) => sum + value, 0) /
utilizationValues.length;

return Number(averageUtilization.toFixed(2));
Copy link
Contributor

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

Copy link
Contributor Author

@Eric-ciccotti Eric-ciccotti Jan 31, 2025

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 ?

Copy link
Contributor

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

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

import { SavingsPlanConsumption } from '@/types/savingsPlanConsumption.type';

describe('calculateAverageUtilization', () => {
it('should return null when consumption is null', () => {
Copy link
Contributor

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

Copy link
Contributor Author

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]>
@Eric-ciccotti Eric-ciccotti force-pushed the feat/TAPC-1779-view-percentage-consumption branch from 9121f2f to 1edad29 Compare January 31, 2025 16:48
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants