refactor: utilise les méthodes de Record
parent
50fbff325d
commit
17aa426296
|
@ -1,8 +1,7 @@
|
|||
import { sumAll } from 'effect/Number'
|
||||
import { formatValue } from 'publicodes'
|
||||
import { styled } from 'styled-components'
|
||||
|
||||
import { arraySum } from '@/utils'
|
||||
|
||||
type Budget = Record<string, Record<string, number>>
|
||||
|
||||
type Props = {
|
||||
|
@ -27,7 +26,7 @@ export default function ResourcesAllocation({ selectedYear, budget }: Props) {
|
|||
]
|
||||
|
||||
const totals = quarters.reduce((total, quarter) => {
|
||||
const quarterTotal = arraySum(Object.values(budget[quarter.label]))
|
||||
const quarterTotal = sumAll(Object.values(budget[quarter.label]))
|
||||
|
||||
return {
|
||||
...total,
|
||||
|
@ -85,7 +84,7 @@ export default function ResourcesAllocation({ selectedYear, budget }: Props) {
|
|||
<td>
|
||||
{/* Total de ligne */}
|
||||
{formatValue(
|
||||
arraySum(
|
||||
sumAll(
|
||||
quarters.map((quarter) => budget[quarter.label][label] ?? 0)
|
||||
),
|
||||
{
|
||||
|
@ -114,7 +113,7 @@ export default function ResourcesAllocation({ selectedYear, budget }: Props) {
|
|||
<td>
|
||||
{/* Total du total */}
|
||||
{formatValue(
|
||||
arraySum(
|
||||
sumAll(
|
||||
quarters.map((quarter) => totals[quarter.label][total])
|
||||
),
|
||||
{
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import * as R from 'effect/Record'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { TrackPage } from '@/components/ATInternetTracking'
|
||||
|
@ -26,16 +27,7 @@ export default function Budget() {
|
|||
const years = Object.keys(budget)
|
||||
type yearType = (typeof years)[number]
|
||||
|
||||
const budgetDescriptions = years.reduce((budgetDescriptions, year) => {
|
||||
if (!budget[year].description) {
|
||||
return budgetDescriptions
|
||||
}
|
||||
|
||||
return {
|
||||
...budgetDescriptions,
|
||||
[year]: budget[year].description,
|
||||
}
|
||||
}, {}) as Record<yearType, string>
|
||||
const budgetDescriptions = R.map(budget, (year) => year.description)
|
||||
|
||||
const budgetValues = years.reduce((budgetValues, year) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
|
|
@ -235,5 +235,3 @@ export const generateUuid = () => {
|
|||
* @param x
|
||||
*/
|
||||
export const isNotNull = <T>(x: T | null): x is T => x !== null
|
||||
|
||||
export const arraySum = (arr: number[]) => arr.reduce((a, b) => a + b, 0)
|
||||
|
|
Loading…
Reference in New Issue