From 17aa426296744053452c4bb8b82dfaa19eaf1587 Mon Sep 17 00:00:00 2001 From: Alice Dahan Date: Thu, 10 Oct 2024 16:47:29 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20utilise=20les=20m=C3=A9thodes=20de?= =?UTF-8?q?=20Record?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/source/pages/budget/ResourcesAllocation.tsx | 9 ++++----- site/source/pages/budget/index.tsx | 12 ++---------- site/source/utils/index.ts | 2 -- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/site/source/pages/budget/ResourcesAllocation.tsx b/site/source/pages/budget/ResourcesAllocation.tsx index 6f2666c2b..a74f28292 100644 --- a/site/source/pages/budget/ResourcesAllocation.tsx +++ b/site/source/pages/budget/ResourcesAllocation.tsx @@ -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> 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) { {/* 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) { {/* Total du total */} {formatValue( - arraySum( + sumAll( quarters.map((quarter) => totals[quarter.label][total]) ), { diff --git a/site/source/pages/budget/index.tsx b/site/source/pages/budget/index.tsx index 987977582..ac26d5feb 100644 --- a/site/source/pages/budget/index.tsx +++ b/site/source/pages/budget/index.tsx @@ -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 + const budgetDescriptions = R.map(budget, (year) => year.description) const budgetValues = years.reduce((budgetValues, year) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/site/source/utils/index.ts b/site/source/utils/index.ts index 5b89e3bd1..95bad6fdd 100644 --- a/site/source/utils/index.ts +++ b/site/source/utils/index.ts @@ -235,5 +235,3 @@ export const generateUuid = () => { * @param x */ export const isNotNull = (x: T | null): x is T => x !== null - -export const arraySum = (arr: number[]) => arr.reduce((a, b) => a + b, 0)